From patchwork Mon Aug 16 00:12:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12437525 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74D81C4338F for ; Mon, 16 Aug 2021 00:22:36 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3203C6137D for ; Mon, 16 Aug 2021 00:22:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3203C6137D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Mime-Version: Message-Id:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=ueHtAhzOpI0y7nacG++UzW0xBkA9JyuEopKrbzzNrLE=; b=lGB by9BdAF+VUXmG6BhPqnovfEZUQO1pmc+bwULGTs8peSlFP9OwHe/bo7Qt4yxXFkoV5Z3mkSYBcetJ UCjFuEc3gXkYBFUlMQ+/GhqkajNLCGCJ1XF3s1Amuwa8Kz6k2hBXCHVqYn896/5WuM8hnQpdPmngZ B5/aMiGKPpsGrAdH4NPqqc9GwXw4gUDajvSn8HFXY6wN0eOLAD0cTBlGtOQSxDVDTDg1AdwKWz3ao YVmTaGV+hGGDjqpxvJBdD8wfmEY1mKRamS50ecqNb9pn6Y0ZUq7qiz/B2Fr/zatvLq2usJKocjdtT wTn2xzrqcyF3PoDhZkXtKFtInjZuckg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mFQMH-00FoG3-PK; Mon, 16 Aug 2021 00:20:07 +0000 Received: from mail-io1-xd49.google.com ([2607:f8b0:4864:20::d49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mFQFJ-00FlKn-Ef for linux-arm-kernel@lists.infradead.org; Mon, 16 Aug 2021 00:12:55 +0000 Received: by mail-io1-xd49.google.com with SMTP id g14-20020a6be60e000000b005b62a0c2a41so1147926ioh.2 for ; Sun, 15 Aug 2021 17:12:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=F1Y2ySdU0qjQ/StQ1vR0ljtsbrXHDEZds9hmCSWeblg=; b=YcIkqrtnhORfqMQT0ShO4+KDFWoE1MjJea43Id/Vgb1S7RsPZL/xQQxfRS0DOXF8aa 1uPDKwX9ByY5tMfkADf2SLiHa9FBzqehpAN4eW2U/aOwB13l6UGFDvS/c7ErHcpK1WlU xE+VeUjHHNw3qXydHD+ImzixbQRKIM5GssHpzrEEbfeYH5uAoxJADmH3VT0eh2pzQHJd Oaeu4jDRxoe5StYHRUo2RwbOineqAti8tOQAIGi3RqLDURfN3j6ipgMkXV59i8eM6zlB 0rUm9v6qZsDAx5K7lvqrLPKuf/uON4DMsB/U0wgoWtLmle/tKkVoFMyutxtZL6JElcGa vR4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=F1Y2ySdU0qjQ/StQ1vR0ljtsbrXHDEZds9hmCSWeblg=; b=Q9zvs+BYaoJVsDjti7yGnpdH8LK1qGTCO1GfUAQQT1qbNfjm5WhEa0EgdBz3ILeo7X OjZFTYH/LvClkYY65p//UxJ0NEhxJjpOtmAMwbGV3qG0NzEJ1S5Tq6RLeX0rUnNTpcl6 Fulyo3o+BjJAno68i+3RKxm1WVM9Nq36tK8ERP5uXAx03j8x5DmTZpunFJyli9AwTavX Z3u9eG+QAJHo4rX3LK/1IKEm9uPO6cskLlcfSK98TjbMdIN+qfNFw5hH787TkxbPPK79 LHcX1tV/oGfiyk3v1YnsY5p3N1d2Pid4XBgq/F+yvxkd85S2JAnENpzhldBv7tQXHkFR qgPA== X-Gm-Message-State: AOAM532RbBy5X77+4OnqN+SuEtJGAHujMhtfBt/ktYbLtCf97Ko1Hfi1 yhLvZQJS3yFvGogY8fGyIaLjnZPtvz4= X-Google-Smtp-Source: ABdhPJzV58r8h0YFfNOivf1Fn8bXACngdOE1Ug6pupFWuSHobJwQrkpGDE51X8HKwmWt2BX0OShiuEIguSk= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a6b:296:: with SMTP id 144mr8121137ioc.114.1629072772063; Sun, 15 Aug 2021 17:12:52 -0700 (PDT) Date: Mon, 16 Aug 2021 00:12:37 +0000 Message-Id: <20210816001246.3067312-1-oupton@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog Subject: [PATCH v7 0/9] selftests: KVM: Test offset-based counter controls From: Oliver Upton To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Cc: Paolo Bonzini , Sean Christopherson , Marc Zyngier , Peter Shier , Jim Mattson , David Matlack , Ricardo Koller , Jing Zhang , Raghavendra Rao Anata , James Morse , Alexandru Elisei , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, Andrew Jones , Will Deacon , Catalin Marinas , Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210815_171253_579166_710C4BD9 X-CRM114-Status: GOOD ( 16.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This series implements new tests for the x86 and arm64 counter migration changes that I've mailed out. These are sent separately as a dependent change since there are cross-arch dependencies here. Patch 1 yanks the pvclock headers into the tools/ directory so we can make use of them within a KVM selftest guest. Patch 2 tests the new capabilities of the KVM_*_CLOCK ioctls, ensuring that the kernel accounts for elapsed time when restoring the KVM clock. Patches 3-4 add some device attribute helpers and clean up some mistakes in the assertions thereof. Patch 5 implements a test for the KVM_VCPU_TSC_OFFSET attribute, asserting that manipulation of the offset results in correct TSC values within the guest. Patch 6 adds a helper to check if KVM supports a given register in the KVM_*_REG ioctls. Patch 7 adds basic arm64 support to the counter offset test, checking that the virtual counter-timer offset works correctly. Patch 8 does the same for the physical counter-timer offset. Patch 9 adds a benchmark for physical counter offsetting, since most implementations available right now will rely on emulation. This series applies cleanly to kvm/queue at the following commit: 3e0b8bd99ab ("KVM: MMU: change tracepoints arguments to kvm_page_fault") Tests were ran against the respective architecture changes on the following systems: - Haswell (x86) - Ampere Mt. Jade (non-ECV, nVHE and VHE) - ARM Base RevC FVP (ECV, nVHE and VHE) *NOTE*: Though this tests changes between both x86 and arm64, these tests check for capabilities and skip if missing, so its OK if they're merged in trees that lack the patches for both architectures. v6: https://lore.kernel.org/r/20210804085819.846610-1-oupton@google.com v6 -> v7: - adapted to UAPI renaming for physical counter offsetting on arm64 Oliver Upton (9): tools: arch: x86: pull in pvclock headers selftests: KVM: Add test for KVM_{GET,SET}_CLOCK selftests: KVM: Fix kvm device helper ioctl assertions selftests: KVM: Add helpers for vCPU device attributes selftests: KVM: Introduce system counter offset test selftests: KVM: Add helper to check for register presence selftests: KVM: Add support for aarch64 to system_counter_offset_test selftests: KVM: Test physical counter offsetting selftests: KVM: Add counter emulation benchmark tools/arch/x86/include/asm/pvclock-abi.h | 48 ++++ tools/arch/x86/include/asm/pvclock.h | 103 +++++++++ tools/testing/selftests/kvm/.gitignore | 3 + tools/testing/selftests/kvm/Makefile | 4 + .../kvm/aarch64/counter_emulation_benchmark.c | 207 +++++++++++++++++ .../selftests/kvm/include/aarch64/processor.h | 24 ++ .../testing/selftests/kvm/include/kvm_util.h | 13 ++ tools/testing/selftests/kvm/lib/kvm_util.c | 63 +++++- .../kvm/system_counter_offset_test.c | 211 ++++++++++++++++++ .../selftests/kvm/x86_64/kvm_clock_test.c | 204 +++++++++++++++++ 10 files changed, 877 insertions(+), 3 deletions(-) create mode 100644 tools/arch/x86/include/asm/pvclock-abi.h create mode 100644 tools/arch/x86/include/asm/pvclock.h create mode 100644 tools/testing/selftests/kvm/aarch64/counter_emulation_benchmark.c create mode 100644 tools/testing/selftests/kvm/system_counter_offset_test.c create mode 100644 tools/testing/selftests/kvm/x86_64/kvm_clock_test.c