From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 986F3C43334 for ; Sat, 4 Jun 2022 01:21:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349916AbiFDBVK (ORCPT ); Fri, 3 Jun 2022 21:21:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349904AbiFDBVE (ORCPT ); Fri, 3 Jun 2022 21:21:04 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB40856747 for ; Fri, 3 Jun 2022 18:21:02 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id om5-20020a17090b3a8500b001df42f1cbaaso8053100pjb.5 for ; Fri, 03 Jun 2022 18:21:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=Es6Hr0vsBiuO2l+ZC4ANogFQnImDp4bB4meXusroIVo=; b=njUGNgodrQvV516LxtQT86zB8HOXOboHg5ttENGNlletzErC96wkV0OoCyJDUmFu56 r8m8ED1x0nxUDSRAnlgnTcGcu2CFEK7NUat7NVWIHihkio8UmBxEuAoRE91qmkFKaK+L MxoxRFyfQVhR2k4rsL0E77LtfIcHD5OvXjieAAdxEtws1/Q8gdC9aY9+GA/Jw61hgk7r ksCEwcqQvP1zV8vBx9WQW3x7CMw1la/BnDlWswD2yHwkeuZm8mZYaHjfGv8vhTMW577i 16vipFFYeHL20PP64sg66a55Spq2aewvphUCqq0pF1yaZZ7YHcjshzTUAqWL7VeQ0rwh 5sLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=Es6Hr0vsBiuO2l+ZC4ANogFQnImDp4bB4meXusroIVo=; b=gdPIEzXAUUOzmGdGRBE5lAdGwXShJaGQwzkTSD5MNVEQES/wV5v+R0TyVVmRn1eYF7 5/txS7fPCl7S7XaQSL4CxdM7VIWnbZDngYC1wzwHE3hzmTYdIokfMD/kkpEm8sJtM2WD wD1Mtwe+vsX8mhpEtMU0XLLIhfkyAj0+tQ11XnyJQfsByCHQfqzq8bidRERc0Q7eMkQN Gf0csg3lKJ4xU/SFufuj+5xRbQtaf/jz1YFCAYYVyn9zBiDL8wnvgE63cL+l9UB9bTmW E8wYgyPgZuPWNGC9yIQ5Ro00PRUSGdU6SM0WAVg6ElNfLTliQWkh2HiUXx5Lm4mBiq8+ pf2A== X-Gm-Message-State: AOAM530LDhnKHQxmlyL9x/nNMGrLmetQv+jR9EQOEJujqrJ9McfwOkh/ AY+jwDAMkRqzBI6eVu4VWc355HCPaUw= X-Google-Smtp-Source: ABdhPJy8pHaHwIxvawFrAb/4mbIxTluL+iM5Cy9jUBF0/tRU63dRzjbqgzCyfU8C8+FtDJnjiBtqhVv6RtM= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6a00:2410:b0:51b:c954:8e55 with SMTP id z16-20020a056a00241000b0051bc9548e55mr10588234pfh.22.1654305662360; Fri, 03 Jun 2022 18:21:02 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:17 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-2-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 01/42] KVM: selftests: Set KVM's supported CPUID as vCPU's CPUID during recreate From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" On x86-64, set KVM's supported CPUID as the vCPU's CPUID when recreating a VM+vCPU to deduplicate code for state save/restore tests, and to provide symmetry of sorts with respect to vm_create_with_one_vcpu(). The extra KVM_SET_CPUID2 call is wasteful for Hyper-V, but ultimately is nothing more than an expensive nop, and overriding the vCPU's CPUID with the Hyper-V CPUID information is the only known scenario where a state save/restore test wouldn't need/want the default CPUID. Opportunistically use __weak for the default vm_compute_max_gfn(), it's provided by tools' compiler.h. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/kvm_util_base.h | 9 +++++++++ tools/testing/selftests/kvm/lib/kvm_util.c | 10 ++++++++-- tools/testing/selftests/kvm/lib/x86_64/processor.c | 9 +++++++++ tools/testing/selftests/kvm/x86_64/amx_test.c | 1 - tools/testing/selftests/kvm/x86_64/smm_test.c | 1 - tools/testing/selftests/kvm/x86_64/state_test.c | 1 - .../selftests/kvm/x86_64/vmx_preemption_timer_test.c | 2 -- 7 files changed, 26 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/te= sting/selftests/kvm/include/kvm_util_base.h index 0eaf0c9b7612..93661d26ac4e 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -681,6 +681,15 @@ static inline struct kvm_vcpu *vm_vcpu_add(struct kvm_= vm *vm, uint32_t vcpu_id, return vm_arch_vcpu_add(vm, vcpu_id, guest_code); } =20 +/* Re-create a vCPU after restarting a VM, e.g. for state save/restore tes= ts. */ +struct kvm_vcpu *vm_arch_vcpu_recreate(struct kvm_vm *vm, uint32_t vcpu_id= ); + +static inline struct kvm_vcpu *vm_vcpu_recreate(struct kvm_vm *vm, + uint32_t vcpu_id) +{ + return vm_arch_vcpu_recreate(vm, vcpu_id); +} + void virt_arch_pgd_alloc(struct kvm_vm *vm); =20 static inline void virt_pgd_alloc(struct kvm_vm *vm) diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/sel= ftests/kvm/lib/kvm_util.c index f0300767df16..d73d9eba2585 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -391,11 +391,17 @@ void kvm_vm_restart(struct kvm_vm *vmp) } } =20 +__weak struct kvm_vcpu *vm_arch_vcpu_recreate(struct kvm_vm *vm, + uint32_t vcpu_id) +{ + return __vm_vcpu_add(vm, vcpu_id); +} + struct kvm_vcpu *vm_recreate_with_one_vcpu(struct kvm_vm *vm) { kvm_vm_restart(vm); =20 - return __vm_vcpu_add(vm, 0); + return vm_vcpu_recreate(vm, 0); } =20 /* @@ -1812,7 +1818,7 @@ void *addr_gva2hva(struct kvm_vm *vm, vm_vaddr_t gva) return addr_gpa2hva(vm, addr_gva2gpa(vm, gva)); } =20 -unsigned long __attribute__((weak)) vm_compute_max_gfn(struct kvm_vm *vm) +unsigned long __weak vm_compute_max_gfn(struct kvm_vm *vm) { return ((1ULL << vm->pa_bits) >> vm->page_shift) - 1; } diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index a871723f7ee1..ea246a87c446 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -664,6 +664,15 @@ struct kvm_vcpu *vm_arch_vcpu_add(struct kvm_vm *vm, u= int32_t vcpu_id, return vcpu; } =20 +struct kvm_vcpu *vm_arch_vcpu_recreate(struct kvm_vm *vm, uint32_t vcpu_id) +{ + struct kvm_vcpu *vcpu =3D __vm_vcpu_add(vm, vcpu_id); + + vcpu_set_cpuid(vcpu, kvm_get_supported_cpuid()); + + return vcpu; +} + /* * Allocate an instance of struct kvm_cpuid2 * diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/= selftests/kvm/x86_64/amx_test.c index dab4ca16a2df..95f59653dbce 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -425,7 +425,6 @@ int main(int argc, char *argv[]) =20 /* Restore state in a new VM. */ vcpu =3D vm_recreate_with_one_vcpu(vm); - vcpu_set_cpuid(vcpu, kvm_get_supported_cpuid()); vcpu_load_state(vcpu, state); run =3D vcpu->run; kvm_x86_state_cleanup(state); diff --git a/tools/testing/selftests/kvm/x86_64/smm_test.c b/tools/testing/= selftests/kvm/x86_64/smm_test.c index 3cd1da388b52..e89139ce68dd 100644 --- a/tools/testing/selftests/kvm/x86_64/smm_test.c +++ b/tools/testing/selftests/kvm/x86_64/smm_test.c @@ -205,7 +205,6 @@ int main(int argc, char *argv[]) kvm_vm_release(vm); =20 vcpu =3D vm_recreate_with_one_vcpu(vm); - vcpu_set_cpuid(vcpu, kvm_get_supported_cpuid()); vcpu_load_state(vcpu, state); run =3D vcpu->run; kvm_x86_state_cleanup(state); diff --git a/tools/testing/selftests/kvm/x86_64/state_test.c b/tools/testin= g/selftests/kvm/x86_64/state_test.c index 0bcd78cf7c79..ea878c963065 100644 --- a/tools/testing/selftests/kvm/x86_64/state_test.c +++ b/tools/testing/selftests/kvm/x86_64/state_test.c @@ -214,7 +214,6 @@ int main(int argc, char *argv[]) =20 /* Restore state in a new VM. */ vcpu =3D vm_recreate_with_one_vcpu(vm); - vcpu_set_cpuid(vcpu, kvm_get_supported_cpuid()); vcpu_load_state(vcpu, state); run =3D vcpu->run; kvm_x86_state_cleanup(state); diff --git a/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c= b/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c index 99e57b0cc2c9..771b54b227d5 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c @@ -237,8 +237,6 @@ int main(int argc, char *argv[]) =20 /* Restore state in a new VM. */ vcpu =3D vm_recreate_with_one_vcpu(vm); - - vcpu_set_cpuid(vcpu, kvm_get_supported_cpuid()); vcpu_load_state(vcpu, state); run =3D vcpu->run; kvm_x86_state_cleanup(state); --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD7D4CCA473 for ; Sat, 4 Jun 2022 01:21:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349983AbiFDBVO (ORCPT ); Fri, 3 Jun 2022 21:21:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349913AbiFDBVF (ORCPT ); Fri, 3 Jun 2022 21:21:05 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5A8E56412 for ; Fri, 3 Jun 2022 18:21:04 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id b9-20020a656689000000b003f672946300so4551738pgw.16 for ; Fri, 03 Jun 2022 18:21:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=Ef9NGJEN3v8+dZtpOXtIrU7XxEz/BHhv08MiJDUgRvk=; b=NqTkm9aiu/jY2yArYk7P8rLKZzgX000yDMy3OYEoD/ChfzJ2I5EZEZl0Aeaju3IMGU hk+TnJUK2bvOooDQBPh8+OKX5a9eV2qWC5rgXWzgJpMmODHgLp5OuowY0PVv3tyal/r3 emfoeaSFEIfy+Jl+dAcbr4LDWEIsiUOy5vruy70ZMRWGTOkWaKxUnsqchPkKfAyRsNmW BqPq3DsbTiop8d4QgHcjxy8nK7hAxeM+j2rb1Ref7S19OupbYpM8eKV4aHtdXHwLe6+E /VcdGi0wzTibxPlOMZ0EtI47W2PzcskJ+ym9Wg1cUqz9TggtTmpko26zLAzklSzZzbQe 8VPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=Ef9NGJEN3v8+dZtpOXtIrU7XxEz/BHhv08MiJDUgRvk=; b=EcT4wjegwRKm3ILNzsrEvrx+nrXPsU5sqPAdWRCr1QT2pkPLHJPpeKviaYxWBp3CUH RNwQq0OYo6s0fzVGZAlQqlogxisEDHVZYL9tPBsI/GhhfdBbjfwHqCZ+6O9cig/UaMbv vCXzyZMO7Fic0hC7YYhYsM7EDDpyt6K1VGjrowUlttwjG9NikMKxTi8hTsKtzIvfHVfv 3h95cr28e5EurKp5jjMrlFYzCkPxQhPlsSE0OYztuPrbIpG6GA7Pp2kpg5g0+4mnntBu j8ev6zHjOhBcSuD4+Q38DBHJ+JiBofaFMssOPljyW9Q9XFFNl/xS9X+hWlwtY2hVx6Hq j0fw== X-Gm-Message-State: AOAM530D28mkrIdsCD0leAIIunUAkV+PUQYTYUBYYpx5IGtkgM9MGUIR 8X6zDgqzSGFdfMFiePuVgOAl97/UFss= X-Google-Smtp-Source: ABdhPJwTUT06O1kcyD2PlmvyTpYrwbs5Kg1SWAbFWikJZN+i+bpk2KOi2XjVhWUHtpD92hInXU/OtUbkBgM= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a62:8101:0:b0:51b:b859:7043 with SMTP id t1-20020a628101000000b0051bb8597043mr12784875pfd.25.1654305664077; Fri, 03 Jun 2022 18:21:04 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:18 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-3-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 02/42] KVM: sefltests: Use CPUID_XSAVE and CPUID_OSXAVE instead of X86_FEATURE_* From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rename X86_FEATURE_* macros to CPUID_* in the AMX and CR4/CPUID sync tests to free up the X86_FEATURE_* names for KVM-Unit-Tests style CPUID automagic where the function, leaf, register, and bit for the feature is embedded in its macro value. No functional change intended. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/x86_64/processor.h | 4 ++++ tools/testing/selftests/kvm/x86_64/amx_test.c | 9 +++------ tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c | 7 ++----- .../selftests/kvm/x86_64/svm_nested_soft_inject_test.c | 3 +-- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index 974d08746b39..e47eba48744e 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -48,6 +48,7 @@ #define CPUID_SMX (1ul << 6) #define CPUID_PCID (1ul << 17) #define CPUID_XSAVE (1ul << 26) +#define CPUID_OSXSAVE (1ul << 27) =20 /* CPUID.7.EBX */ #define CPUID_FSGSBASE (1ul << 0) @@ -62,6 +63,9 @@ /* CPUID.0x8000_0001.EDX */ #define CPUID_GBPAGES (1ul << 26) =20 +/* CPUID.0x8000_000A.EDX */ +#define CPUID_NRIPS BIT(3) + /* Page table bitfield declarations */ #define PTE_PRESENT_MASK BIT_ULL(0) #define PTE_WRITABLE_MASK BIT_ULL(1) diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/= selftests/kvm/x86_64/amx_test.c index 95f59653dbce..7127873bb0cb 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -25,9 +25,6 @@ # error This test is 64-bit only #endif =20 -#define X86_FEATURE_XSAVE (1 << 26) -#define X86_FEATURE_OSXSAVE (1 << 27) - #define NUM_TILES 8 #define TILE_SIZE 1024 #define XSAVE_SIZE ((NUM_TILES * TILE_SIZE) + PAGE_SIZE) @@ -128,9 +125,9 @@ static inline void check_cpuid_xsave(void) eax =3D 1; ecx =3D 0; cpuid(&eax, &ebx, &ecx, &edx); - if (!(ecx & X86_FEATURE_XSAVE)) + if (!(ecx & CPUID_XSAVE)) GUEST_ASSERT(!"cpuid: no CPU xsave support!"); - if (!(ecx & X86_FEATURE_OSXSAVE)) + if (!(ecx & CPUID_OSXSAVE)) GUEST_ASSERT(!"cpuid: no OS xsave support!"); } =20 @@ -333,7 +330,7 @@ int main(int argc, char *argv[]) vm =3D vm_create_with_one_vcpu(&vcpu, guest_code); =20 entry =3D kvm_get_supported_cpuid_entry(1); - TEST_REQUIRE(entry->ecx & X86_FEATURE_XSAVE); + TEST_REQUIRE(entry->ecx & CPUID_XSAVE); =20 TEST_REQUIRE(kvm_get_cpuid_max_basic() >=3D 0xd); =20 diff --git a/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c b/too= ls/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c index a80940ac420f..8b0bb36205d9 100644 --- a/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c +++ b/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c @@ -19,9 +19,6 @@ #include "kvm_util.h" #include "processor.h" =20 -#define X86_FEATURE_XSAVE (1<<26) -#define X86_FEATURE_OSXSAVE (1<<27) - static inline bool cr4_cpuid_is_sync(void) { int func, subfunc; @@ -36,7 +33,7 @@ static inline bool cr4_cpuid_is_sync(void) =20 cr4 =3D get_cr4(); =20 - return (!!(ecx & X86_FEATURE_OSXSAVE)) =3D=3D (!!(cr4 & X86_CR4_OSXSAVE)); + return (!!(ecx & CPUID_OSXSAVE)) =3D=3D (!!(cr4 & X86_CR4_OSXSAVE)); } =20 static void guest_code(void) @@ -70,7 +67,7 @@ int main(int argc, char *argv[]) struct ucall uc; =20 entry =3D kvm_get_supported_cpuid_entry(1); - TEST_REQUIRE(entry->ecx & X86_FEATURE_XSAVE); + TEST_REQUIRE(entry->ecx & CPUID_XSAVE); =20 /* Tell stdout not to buffer its content */ setbuf(stdout, NULL); diff --git a/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test= .c b/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c index 1c3f457aa3aa..051f70167074 100644 --- a/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c +++ b/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c @@ -19,7 +19,6 @@ #include "test_util.h" =20 #define INT_NR 0x20 -#define X86_FEATURE_NRIPS BIT(3) =20 static_assert(ATOMIC_INT_LOCK_FREE =3D=3D 2, "atomic int is not lockless"); =20 @@ -204,7 +203,7 @@ int main(int argc, char *argv[]) nested_svm_check_supported(); =20 cpuid =3D kvm_get_supported_cpuid_entry(0x8000000a); - TEST_ASSERT(cpuid->edx & X86_FEATURE_NRIPS, + TEST_ASSERT(cpuid->edx & CPUID_NRIPS, "KVM with nSVM is supposed to unconditionally advertise nRIP Save\n"= ); =20 atomic_init(&nmi_stage, 0); --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C8FAC43334 for ; Sat, 4 Jun 2022 01:21:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244011AbiFDBVT (ORCPT ); Fri, 3 Jun 2022 21:21:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349926AbiFDBVH (ORCPT ); Fri, 3 Jun 2022 21:21:07 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BB8B56412 for ; Fri, 3 Jun 2022 18:21:06 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id i16-20020a170902cf1000b001540b6a09e3so5073017plg.0 for ; Fri, 03 Jun 2022 18:21:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=IKDfTMW8z6x1o9d3XMOVC9AQI4eSdqQ0otx03wJYtxQ=; b=Od6hxSW62PBi61ZXthZrMmAqkeZSt42HLHE2Kot3JR9flrDgza6wNiQWrG/Sjx770J 6KY9HaGJFgMdS1SoYPRLrvj4enzaNNvdXnpCeTtNGGJ1P9DaGgQbK8EPHZWNLkmth6kz UPJs+ppYg1HqaIHRQyH2f0OMMBJSXDuN5jiLu3fm7xniwfHshp7rsUaceD0U9+Tbrm2M FbQNq4TrWxNft5BJ17LRYVMBYDd1aIwV9ec0i1QIlY/7+B/nVGM5yDXsBNkEQ28KEJg+ iNNVp/2502CU4eCU0i8a6Z667lMLJyOx/LR/oP2eoAo2+BlD3FyczcU5VFKXJCdYlBVU /uxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=IKDfTMW8z6x1o9d3XMOVC9AQI4eSdqQ0otx03wJYtxQ=; b=uX5/kda3uSoEHidQYSaqFt4MKKWY38u8Y6y5SawoJ4O04200ERsbhiK8ya8/P3RhHN 6wUMNxy4XNkr9c0dM/MY0ZbOAcEumdMbiXEnQ/vVhFUkLay/s1pEAOga88bcxCQjTCOt kTzcl0dnSQZjYhH+bxfo9dKEuUBmH2dKs7ZmvVTSFEtfYSSobIRy6h8jSH3FQfMq9SLm ZRvuCdWoj70pIjjI6Fntam3bLd04lfPNR8+sl9dbjrqC4z5wdOsx9OyAOAp6Xi56+uiF ttYs2Lv6rQ+edn25I60JJ10GW2vCz29jrOWjpOWHiPQdWzwu7pC2Y/2XN1QVyN8maj87 JQoQ== X-Gm-Message-State: AOAM532kKctFRLdNhLUHOCi66iqdkJU2Usc+EnFNjkA4Ve77MiiZU0AI swAL28hwpGKJpU98mRIUNkjijh6l6jQ= X-Google-Smtp-Source: ABdhPJy8xFm/duZUsZp4C2gpysaAkfZsELFznaiXB/8A6P4POd+k4Rdwo27dAkU5FjMJWGZvK8JM/2Ef2Dg= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90a:178f:b0:1e3:3ba:c185 with SMTP id q15-20020a17090a178f00b001e303bac185mr4615pja.1.1654305665559; Fri, 03 Jun 2022 18:21:05 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:19 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-4-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 03/42] KVM: selftests: Add framework to query KVM CPUID bits From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add X86_FEATURE_* magic in the style of KVM-Unit-Tests' implementation, where the CPUID function, index, output register, and output bit position are embedded in the macro value. Add kvm_cpu_has() to query KVM's supported CPUID and use it set_sregs_test, which is the most prolific user of manual feature querying. Opportunstically rename calc_cr4_feature_bits() to calc_supported_cr4_feature_bits() to better capture how the CR4 bits are chosen. Link: https://lore.kernel.org/all/20210422005626.564163-1-ricarkol@google.c= om Suggested-by: Paolo Bonzini Suggested-by: Jim Mattson Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/x86_64/processor.h | 106 ++++++++++++++++-- .../selftests/kvm/lib/x86_64/processor.c | 22 ++++ .../selftests/kvm/x86_64/set_sregs_test.c | 28 ++--- 3 files changed, 128 insertions(+), 28 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index e47eba48744e..59ae869814b7 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -43,23 +43,96 @@ #define X86_CR4_SMAP (1ul << 21) #define X86_CR4_PKE (1ul << 22) =20 +/* Note, these are ordered alphabetically to match kvm_cpuid_entry2. Eww.= */ +enum cpuid_output_regs { + KVM_CPUID_EAX, + KVM_CPUID_EBX, + KVM_CPUID_ECX, + KVM_CPUID_EDX +}; + +/* + * Pack the information into a 64-bit value so that each X86_FEATURE_XXX c= an be + * passed by value with no overhead. + */ +struct kvm_x86_cpu_feature { + u32 function; + u16 index; + u8 reg; + u8 bit; +}; +#define KVM_X86_CPU_FEATURE(fn, idx, gpr, __bit) \ +({ \ + struct kvm_x86_cpu_feature feature =3D { \ + .function =3D fn, \ + .index =3D idx, \ + .reg =3D KVM_CPUID_##gpr, \ + .bit =3D __bit, \ + }; \ + \ + feature; \ +}) + +/* + * Basic Leafs, a.k.a. Intel defined + */ +#define X86_FEATURE_MWAIT KVM_X86_CPU_FEATURE(0x1, 0, ECX, 3) +#define X86_FEATURE_VMX KVM_X86_CPU_FEATURE(0x1, 0, ECX, 5) +#define X86_FEATURE_SMX KVM_X86_CPU_FEATURE(0x1, 0, ECX, 6) +#define X86_FEATURE_PCID KVM_X86_CPU_FEATURE(0x1, 0, ECX, 17) +#define X86_FEATURE_MOVBE KVM_X86_CPU_FEATURE(0x1, 0, ECX, 22) +#define X86_FEATURE_TSC_DEADLINE_TIMER KVM_X86_CPU_FEATURE(0x1, 0, ECX, 24) +#define X86_FEATURE_XSAVE KVM_X86_CPU_FEATURE(0x1, 0, ECX, 26) +#define X86_FEATURE_OSXSAVE KVM_X86_CPU_FEATURE(0x1, 0, ECX, 27) +#define X86_FEATURE_RDRAND KVM_X86_CPU_FEATURE(0x1, 0, ECX, 30) +#define X86_FEATURE_MCE KVM_X86_CPU_FEATURE(0x1, 0, EDX, 7) +#define X86_FEATURE_APIC KVM_X86_CPU_FEATURE(0x1, 0, EDX, 9) +#define X86_FEATURE_CLFLUSH KVM_X86_CPU_FEATURE(0x1, 0, EDX, 19) +#define X86_FEATURE_XMM KVM_X86_CPU_FEATURE(0x1, 0, EDX, 25) +#define X86_FEATURE_XMM2 KVM_X86_CPU_FEATURE(0x1, 0, EDX, 26) +#define X86_FEATURE_FSGSBASE KVM_X86_CPU_FEATURE(0x7, 0, EBX, 0) +#define X86_FEATURE_TSC_ADJUST KVM_X86_CPU_FEATURE(0x7, 0, EBX, 1) +#define X86_FEATURE_HLE KVM_X86_CPU_FEATURE(0x7, 0, EBX, 4) +#define X86_FEATURE_SMEP KVM_X86_CPU_FEATURE(0x7, 0, EBX, 7) +#define X86_FEATURE_INVPCID KVM_X86_CPU_FEATURE(0x7, 0, EBX, 10) +#define X86_FEATURE_RTM KVM_X86_CPU_FEATURE(0x7, 0, EBX, 11) +#define X86_FEATURE_SMAP KVM_X86_CPU_FEATURE(0x7, 0, EBX, 20) +#define X86_FEATURE_PCOMMIT KVM_X86_CPU_FEATURE(0x7, 0, EBX, 22) +#define X86_FEATURE_CLFLUSHOPT KVM_X86_CPU_FEATURE(0x7, 0, EBX, 23) +#define X86_FEATURE_CLWB KVM_X86_CPU_FEATURE(0x7, 0, EBX, 24) +#define X86_FEATURE_UMIP KVM_X86_CPU_FEATURE(0x7, 0, ECX, 2) +#define X86_FEATURE_PKU KVM_X86_CPU_FEATURE(0x7, 0, ECX, 3) +#define X86_FEATURE_LA57 KVM_X86_CPU_FEATURE(0x7, 0, ECX, 16) +#define X86_FEATURE_RDPID KVM_X86_CPU_FEATURE(0x7, 0, ECX, 22) +#define X86_FEATURE_SHSTK KVM_X86_CPU_FEATURE(0x7, 0, ECX, 7) +#define X86_FEATURE_IBT KVM_X86_CPU_FEATURE(0x7, 0, EDX, 20) +#define X86_FEATURE_SPEC_CTRL KVM_X86_CPU_FEATURE(0x7, 0, EDX, 26) +#define X86_FEATURE_ARCH_CAPABILITIES KVM_X86_CPU_FEATURE(0x7, 0, EDX, 29) +#define X86_FEATURE_PKS KVM_X86_CPU_FEATURE(0x7, 0, ECX, 31) + +/* + * Extended Leafs, a.k.a. AMD defined + */ +#define X86_FEATURE_SVM KVM_X86_CPU_FEATURE(0x80000001, 0, ECX, 2) +#define X86_FEATURE_NX KVM_X86_CPU_FEATURE(0x80000001, 0, EDX, 20) +#define X86_FEATURE_GBPAGES KVM_X86_CPU_FEATURE(0x80000001, 0, EDX, 26) +#define X86_FEATURE_RDTSCP KVM_X86_CPU_FEATURE(0x80000001, 0, EDX, 27) +#define X86_FEATURE_LM KVM_X86_CPU_FEATURE(0x80000001, 0, EDX, 29) +#define X86_FEATURE_RDPRU KVM_X86_CPU_FEATURE(0x80000008, 0, EBX, 4) +#define X86_FEATURE_AMD_IBPB KVM_X86_CPU_FEATURE(0x80000008, 0, EBX, 12) +#define X86_FEATURE_NPT KVM_X86_CPU_FEATURE(0x8000000A, 0, EDX, 0) +#define X86_FEATURE_LBRV KVM_X86_CPU_FEATURE(0x8000000A, 0, EDX, 1) +#define X86_FEATURE_NRIPS KVM_X86_CPU_FEATURE(0x8000000A, 0, EDX, 3) +#define X86_FEATURE_TSCRATEMSR KVM_X86_CPU_FEATURE(0x8000000A, 0,= EDX, 4) +#define X86_FEATURE_PAUSEFILTER KVM_X86_CPU_FEATURE(0x8000000A, 0,= EDX, 10) +#define X86_FEATURE_PFTHRESHOLD KVM_X86_CPU_FEATURE(0x8000000A, 0,= EDX, 12) +#define X86_FEATURE_VGIF KVM_X86_CPU_FEATURE(0x8000000A, 0, EDX, 16) + /* CPUID.1.ECX */ #define CPUID_VMX (1ul << 5) -#define CPUID_SMX (1ul << 6) -#define CPUID_PCID (1ul << 17) #define CPUID_XSAVE (1ul << 26) #define CPUID_OSXSAVE (1ul << 27) =20 -/* CPUID.7.EBX */ -#define CPUID_FSGSBASE (1ul << 0) -#define CPUID_SMEP (1ul << 7) -#define CPUID_SMAP (1ul << 20) - -/* CPUID.7.ECX */ -#define CPUID_UMIP (1ul << 2) -#define CPUID_PKU (1ul << 3) -#define CPUID_LA57 (1ul << 16) - /* CPUID.0x8000_0001.EDX */ #define CPUID_GBPAGES (1ul << 26) =20 @@ -488,6 +561,15 @@ static inline void vcpu_xcrs_set(struct kvm_vcpu *vcpu= , struct kvm_xcrs *xcrs) } =20 struct kvm_cpuid2 *kvm_get_supported_cpuid(void); + +bool kvm_cpuid_has(const struct kvm_cpuid2 *cpuid, + struct kvm_x86_cpu_feature feature); + +static inline bool kvm_cpu_has(struct kvm_x86_cpu_feature feature) +{ + return kvm_cpuid_has(kvm_get_supported_cpuid(), feature); +} + struct kvm_cpuid2 *vcpu_get_cpuid(struct kvm_vcpu *vcpu); =20 static inline int __vcpu_set_cpuid(struct kvm_vcpu *vcpu, diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index ea246a87c446..e60afab6b88f 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -735,6 +735,28 @@ struct kvm_cpuid2 *kvm_get_supported_cpuid(void) return cpuid; } =20 +bool kvm_cpuid_has(const struct kvm_cpuid2 *cpuid, + struct kvm_x86_cpu_feature feature) +{ + const struct kvm_cpuid_entry2 *entry; + int i; + + for (i =3D 0; i < cpuid->nent; i++) { + entry =3D &cpuid->entries[i]; + + /* + * The output registers in kvm_cpuid_entry2 are in alphabetical + * order, but kvm_x86_cpu_feature matches that mess, so yay + * pointer shenanigans! + */ + if (entry->function =3D=3D feature.function && + entry->index =3D=3D feature.index) + return (&entry->eax)[feature.reg] & BIT(feature.bit); + } + + return false; +} + uint64_t kvm_get_feature_msr(uint64_t msr_index) { struct { diff --git a/tools/testing/selftests/kvm/x86_64/set_sregs_test.c b/tools/te= sting/selftests/kvm/x86_64/set_sregs_test.c index dd344439ad33..2bb08bf2125d 100644 --- a/tools/testing/selftests/kvm/x86_64/set_sregs_test.c +++ b/tools/testing/selftests/kvm/x86_64/set_sregs_test.c @@ -43,36 +43,32 @@ static void test_cr4_feature_bit(struct kvm_vcpu *vcpu,= struct kvm_sregs *orig, TEST_ASSERT(!memcmp(&sregs, orig, sizeof(sregs)), "KVM modified sregs"); } =20 -static uint64_t calc_cr4_feature_bits(struct kvm_vm *vm) +static uint64_t calc_supported_cr4_feature_bits(void) { - struct kvm_cpuid_entry2 *cpuid_1, *cpuid_7; uint64_t cr4; =20 - cpuid_1 =3D kvm_get_supported_cpuid_entry(1); - cpuid_7 =3D kvm_get_supported_cpuid_entry(7); - cr4 =3D X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE | X86_CR4_PGE | X86_CR4_PCE | X86_CR4_OSFXSR | X86_CR4_OSXMMEXCPT; - if (cpuid_7->ecx & CPUID_UMIP) + if (kvm_cpu_has(X86_FEATURE_UMIP)) cr4 |=3D X86_CR4_UMIP; - if (cpuid_7->ecx & CPUID_LA57) + if (kvm_cpu_has(X86_FEATURE_LA57)) cr4 |=3D X86_CR4_LA57; - if (cpuid_1->ecx & CPUID_VMX) + if (kvm_cpu_has(X86_FEATURE_VMX)) cr4 |=3D X86_CR4_VMXE; - if (cpuid_1->ecx & CPUID_SMX) + if (kvm_cpu_has(X86_FEATURE_SMX)) cr4 |=3D X86_CR4_SMXE; - if (cpuid_7->ebx & CPUID_FSGSBASE) + if (kvm_cpu_has(X86_FEATURE_FSGSBASE)) cr4 |=3D X86_CR4_FSGSBASE; - if (cpuid_1->ecx & CPUID_PCID) + if (kvm_cpu_has(X86_FEATURE_PCID)) cr4 |=3D X86_CR4_PCIDE; - if (cpuid_1->ecx & CPUID_XSAVE) + if (kvm_cpu_has(X86_FEATURE_XSAVE)) cr4 |=3D X86_CR4_OSXSAVE; - if (cpuid_7->ebx & CPUID_SMEP) + if (kvm_cpu_has(X86_FEATURE_SMEP)) cr4 |=3D X86_CR4_SMEP; - if (cpuid_7->ebx & CPUID_SMAP) + if (kvm_cpu_has(X86_FEATURE_SMAP)) cr4 |=3D X86_CR4_SMAP; - if (cpuid_7->ecx & CPUID_PKU) + if (kvm_cpu_has(X86_FEATURE_PKU)) cr4 |=3D X86_CR4_PKE; =20 return cr4; @@ -99,7 +95,7 @@ int main(int argc, char *argv[]) =20 vcpu_sregs_get(vcpu, &sregs); =20 - sregs.cr4 |=3D calc_cr4_feature_bits(vm); + sregs.cr4 |=3D calc_supported_cr4_feature_bits(); cr4 =3D sregs.cr4; =20 rc =3D _vcpu_sregs_set(vcpu, &sregs); --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0600C43334 for ; Sat, 4 Jun 2022 01:21:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349993AbiFDBVW (ORCPT ); Fri, 3 Jun 2022 21:21:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349904AbiFDBVK (ORCPT ); Fri, 3 Jun 2022 21:21:10 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC2D95674D for ; Fri, 3 Jun 2022 18:21:07 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id om5-20020a17090b3a8500b001df42f1cbaaso8053100pjb.5 for ; Fri, 03 Jun 2022 18:21:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=lREshGWquZfBEtYBUkE28FoLZlAZCU5tdVBzH/ZOWRY=; b=ftn8Ddo8JpTu6+Gk9x/UhN9nOArl6VdD2w1pzA5HLc3fBiXRouIx9s5El5rqnc+jhu cbjfmOScRMZRwlUHlT8Q4H3+QKJD1d9hKxRhP+j7hcYu5k7vRkx1OgM7LiglnLIAQ5Ph yzqIzaazMExB4dK2yrCqabLaI1J4HNnrdJ6gLGJ59vYwyClkn9VFZ2vsheeJn6JvC2dO D5hTRFbDZ4PXuSe6ofCKkDhHSEj+zDP/hHzpxsC66Tpy+lfFFHivHQeE/kbE/ppQbwCh EnSBmLeoZ0kln+RgNm4vPAXzQJYc+qKpNoY8YZ0ts+8dwFreNa1V4W2oCoToykEWhDe2 O3tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=lREshGWquZfBEtYBUkE28FoLZlAZCU5tdVBzH/ZOWRY=; b=U3rq4igkJy+qSA909PFk2iwWWaR3OlBy7GvLTEjuffdHOg54ytfmTONnmx3RvY3OuK xGIkcLG1fJq+9awOKaVXzCMeOr+eB/jmHhrqhGhmENqJhKeD50dpsKbZLlQsdXM/Vmw3 GwPYNt2DL8zgQX4AxrYt7FSkc4N2eIgyXwVoDmBEqNwBO3F9AUVz5P9horKv1HAHrZ63 XR266GTNXHS4C1YmVgxx67q2EBMPj65XvKQ9toak2aXhfXNaiUnPsY97mKxJF82MuUMg uI9YLT0NCtHjWs5B0O3DDyYTQjHo+XcjdXpmE+T7x4pP/vPFsvXuyyAULVUS5LA8aPsB j9bw== X-Gm-Message-State: AOAM530IgzD0zrPm8BQiCzekixZGE6nrdCWQsSiRUGMSTGw9tuci92P9 9CaEppDgPXAwlRCKkcn4kqkUCwF2MiA= X-Google-Smtp-Source: ABdhPJyhYgCAxSQU/gKQDofAmbxl4N3GVumvmrnJPX0i/eqa2iLFdtnAVR6GQEK6d4qDudAHSQ9QfHGOaAs= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6a00:1901:b0:518:916e:4a85 with SMTP id y1-20020a056a00190100b00518916e4a85mr12703010pfi.65.1654305667281; Fri, 03 Jun 2022 18:21:07 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:20 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-5-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 04/42] KVM: selftests: Use kvm_cpu_has() in the SEV migration test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use kvm_cpu_has() in the SEV migration test instead of open coding equivalent functionality using kvm_get_supported_cpuid_entry(). No functional change intended. Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/x86_64/processor.h | 2 ++ .../selftests/kvm/x86_64/sev_migrate_tests.c | 13 ++----------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index 59ae869814b7..24ffa7c238ff 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -127,6 +127,8 @@ struct kvm_x86_cpu_feature { #define X86_FEATURE_PAUSEFILTER KVM_X86_CPU_FEATURE(0x8000000A, 0,= EDX, 10) #define X86_FEATURE_PFTHRESHOLD KVM_X86_CPU_FEATURE(0x8000000A, 0,= EDX, 12) #define X86_FEATURE_VGIF KVM_X86_CPU_FEATURE(0x8000000A, 0, EDX, 16) +#define X86_FEATURE_SEV KVM_X86_CPU_FEATURE(0x8000001F, 0, EAX, 1) +#define X86_FEATURE_SEV_ES KVM_X86_CPU_FEATURE(0x8000001F, 0, EAX, 3) =20 /* CPUID.1.ECX */ #define CPUID_VMX (1ul << 5) diff --git a/tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c b/tools= /testing/selftests/kvm/x86_64/sev_migrate_tests.c index 76ba6fc80e37..56a5932165ce 100644 --- a/tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c +++ b/tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c @@ -393,23 +393,14 @@ static void test_sev_move_copy(void) kvm_vm_free(sev_vm); } =20 -#define X86_FEATURE_SEV (1 << 1) -#define X86_FEATURE_SEV_ES (1 << 3) - int main(int argc, char *argv[]) { - struct kvm_cpuid_entry2 *cpuid; - TEST_REQUIRE(kvm_has_cap(KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM)); TEST_REQUIRE(kvm_has_cap(KVM_CAP_VM_COPY_ENC_CONTEXT_FROM)); =20 - cpuid =3D kvm_get_supported_cpuid_entry(0x80000000); - TEST_REQUIRE(cpuid->eax >=3D 0x8000001f); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SEV)); =20 - cpuid =3D kvm_get_supported_cpuid_entry(0x8000001f); - TEST_REQUIRE(cpuid->eax & X86_FEATURE_SEV); - - have_sev_es =3D !!(cpuid->eax & X86_FEATURE_SEV_ES); + have_sev_es =3D kvm_cpu_has(X86_FEATURE_SEV_ES); =20 if (kvm_check_cap(KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM)) { test_sev_migrate_from(/* es=3D */ false); --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62BBAC433EF for ; Sat, 4 Jun 2022 01:21:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347920AbiFDBV1 (ORCPT ); Fri, 3 Jun 2022 21:21:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349955AbiFDBVL (ORCPT ); Fri, 3 Jun 2022 21:21:11 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9272556744 for ; Fri, 3 Jun 2022 18:21:09 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id h11-20020a65638b000000b003fad8e1cc9bso4577517pgv.2 for ; Fri, 03 Jun 2022 18:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=LPv7oBU6RNJoN5QvwpKNebafNcFCPuc5KjEJfxiNbCo=; b=lhVfUjEenKVM1DQzzVSzeGKdnF74DLtq6X3Sa8cHIyM65TtbEluU83ObJiYlxvM7qq yJzpjmB7EnFhU6Am63zXWI6170S9fzgrcmDg/Bg0yGhzykYl3BNrc9ZuQomdpFRPodo/ 9Y6ncjnES3taOQkA4kOrFxvya6YHK9IaJcoVVZiUp2/NuHCLqT0RDoOoVVV7wGwNxCvy pKL5uHzlVQyicjzqocPKxA736a4X6wRzI0bLuRSdFvsKV55vp46arzmCzUFPO66ifuPf vZmV9BGNPe9MC+oTbFZ8cJlwc9h0nD5iDamcAyA7112rlIJPLO+mSW7JTi92JjdW+73f +Zmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=LPv7oBU6RNJoN5QvwpKNebafNcFCPuc5KjEJfxiNbCo=; b=bZT8AYz5pE8LE1pDQtOjs5zxpBU3y3NrdprVpEp+uIIE9cwIfqmbtX9vyCBNo0qqpa uRqAe9eMQz+QUfEhzlqPhl7MQyIzfExGm2GWbTl3uqE9s2UMU7xOIT36yWHiKQUFnYOy 1oezOOsM/6w+xUTFJbTJJXmDZ4hPzQoBo76y9dZNrEIBpEQoFYOMtFBR1KNcs2V3TYQW 3mKzVR4ejH6DduCTBawBdFsdtPcc2SbiGmyn8PPip4wDLXTWRJG+l/HetXZ0+vnb3GXz KEBP7R/ZTJDVX+ab0vkzTbbA1Ls9urQ3gY336P/FprrRt0mhjQGeikY1aKmdcwv8KTk4 5Ahw== X-Gm-Message-State: AOAM532wmbo4Wlh6CbWsgVxoENwxkascfRlschCyJ2STHfd5SfXvc+I/ o7YO5Go2pM7cCL4TUQPTWo5dpkQxON4= X-Google-Smtp-Source: ABdhPJyOrThN4h2bxAD3aYKHXCFrO9u67esXjrR5pW51yppYVXUUWF4zPPLGwPQw6Dn2mvoFK4DRAlkrUVw= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6a00:2187:b0:50c:ef4d:ef3b with SMTP id h7-20020a056a00218700b0050cef4def3bmr12510879pfi.83.1654305669056; Fri, 03 Jun 2022 18:21:09 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:21 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-6-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 05/42] KVM: selftests: Use kvm_cpu_has() for nested SVM checks From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use kvm_cpu_has() to check for nested SVM support, and drop the helpers now that their functionality is trivial to implement. No functional change intended. Signed-off-by: Sean Christopherson --- .../testing/selftests/kvm/include/x86_64/svm_util.h | 2 -- tools/testing/selftests/kvm/lib/x86_64/svm.c | 13 ------------- .../testing/selftests/kvm/x86_64/hyperv_svm_test.c | 2 +- tools/testing/selftests/kvm/x86_64/smm_test.c | 2 +- tools/testing/selftests/kvm/x86_64/state_test.c | 2 +- .../testing/selftests/kvm/x86_64/svm_int_ctl_test.c | 2 +- .../kvm/x86_64/svm_nested_soft_inject_test.c | 2 +- .../testing/selftests/kvm/x86_64/svm_vmcall_test.c | 2 +- 8 files changed, 6 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/svm_util.h b/tools/= testing/selftests/kvm/include/x86_64/svm_util.h index 136ba6a5d027..f48806d26989 100644 --- a/tools/testing/selftests/kvm/include/x86_64/svm_util.h +++ b/tools/testing/selftests/kvm/include/x86_64/svm_util.h @@ -51,8 +51,6 @@ struct svm_test_data { struct svm_test_data *vcpu_alloc_svm(struct kvm_vm *vm, vm_vaddr_t *p_svm_= gva); void generic_svm_setup(struct svm_test_data *svm, void *guest_rip, void *g= uest_rsp); void run_guest(struct vmcb *vmcb, uint64_t vmcb_gpa); -bool nested_svm_supported(void); -void nested_svm_check_supported(void); =20 static inline bool cpu_has_svm(void) { diff --git a/tools/testing/selftests/kvm/lib/x86_64/svm.c b/tools/testing/s= elftests/kvm/lib/x86_64/svm.c index 37e9c0a923e0..6d445886e16c 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/svm.c +++ b/tools/testing/selftests/kvm/lib/x86_64/svm.c @@ -164,19 +164,6 @@ void run_guest(struct vmcb *vmcb, uint64_t vmcb_gpa) : "r15", "memory"); } =20 -bool nested_svm_supported(void) -{ - struct kvm_cpuid_entry2 *entry =3D - kvm_get_supported_cpuid_entry(0x80000001); - - return entry->ecx & CPUID_SVM; -} - -void nested_svm_check_supported(void) -{ - TEST_REQUIRE(nested_svm_supported()); -} - /* * Open SEV_DEV_PATH if available, otherwise exit the entire program. * diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c b/tools/t= esting/selftests/kvm/x86_64/hyperv_svm_test.c index c5cd9835dbd6..ea507510a62f 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_svm_test.c @@ -127,7 +127,7 @@ int main(int argc, char *argv[]) struct ucall uc; int stage; =20 - TEST_REQUIRE(nested_svm_supported()); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SVM)); =20 /* Create VM */ vm =3D vm_create_with_one_vcpu(&vcpu, guest_code); diff --git a/tools/testing/selftests/kvm/x86_64/smm_test.c b/tools/testing/= selftests/kvm/x86_64/smm_test.c index e89139ce68dd..6b8108bdcead 100644 --- a/tools/testing/selftests/kvm/x86_64/smm_test.c +++ b/tools/testing/selftests/kvm/x86_64/smm_test.c @@ -154,7 +154,7 @@ int main(int argc, char *argv[]) vcpu_set_msr(vcpu, MSR_IA32_SMBASE, SMRAM_GPA); =20 if (kvm_check_cap(KVM_CAP_NESTED_STATE)) { - if (nested_svm_supported()) + if (kvm_cpu_has(X86_FEATURE_SVM)) vcpu_alloc_svm(vm, &nested_gva); else if (nested_vmx_supported()) vcpu_alloc_vmx(vm, &nested_gva); diff --git a/tools/testing/selftests/kvm/x86_64/state_test.c b/tools/testin= g/selftests/kvm/x86_64/state_test.c index ea878c963065..fe110ce31106 100644 --- a/tools/testing/selftests/kvm/x86_64/state_test.c +++ b/tools/testing/selftests/kvm/x86_64/state_test.c @@ -170,7 +170,7 @@ int main(int argc, char *argv[]) vcpu_regs_get(vcpu, ®s1); =20 if (kvm_check_cap(KVM_CAP_NESTED_STATE)) { - if (nested_svm_supported()) + if (kvm_cpu_has(X86_FEATURE_SVM)) vcpu_alloc_svm(vm, &nested_gva); else if (nested_vmx_supported()) vcpu_alloc_vmx(vm, &nested_gva); diff --git a/tools/testing/selftests/kvm/x86_64/svm_int_ctl_test.c b/tools/= testing/selftests/kvm/x86_64/svm_int_ctl_test.c index 9c68a47b69e1..dc32c347281a 100644 --- a/tools/testing/selftests/kvm/x86_64/svm_int_ctl_test.c +++ b/tools/testing/selftests/kvm/x86_64/svm_int_ctl_test.c @@ -90,7 +90,7 @@ int main(int argc, char *argv[]) struct kvm_vm *vm; struct ucall uc; =20 - nested_svm_check_supported(); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SVM)); =20 vm =3D vm_create_with_one_vcpu(&vcpu, l1_guest_code); =20 diff --git a/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test= .c b/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c index 051f70167074..3c21b997fe3a 100644 --- a/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c +++ b/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c @@ -200,7 +200,7 @@ int main(int argc, char *argv[]) /* Tell stdout not to buffer its content */ setbuf(stdout, NULL); =20 - nested_svm_check_supported(); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SVM)); =20 cpuid =3D kvm_get_supported_cpuid_entry(0x8000000a); TEST_ASSERT(cpuid->edx & CPUID_NRIPS, diff --git a/tools/testing/selftests/kvm/x86_64/svm_vmcall_test.c b/tools/t= esting/selftests/kvm/x86_64/svm_vmcall_test.c index e6d7191866a5..46ce1bda6599 100644 --- a/tools/testing/selftests/kvm/x86_64/svm_vmcall_test.c +++ b/tools/testing/selftests/kvm/x86_64/svm_vmcall_test.c @@ -39,7 +39,7 @@ int main(int argc, char *argv[]) vm_vaddr_t svm_gva; struct kvm_vm *vm; =20 - nested_svm_check_supported(); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SVM)); =20 vm =3D vm_create_with_one_vcpu(&vcpu, l1_guest_code); =20 --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC62EC43334 for ; Sat, 4 Jun 2022 01:21:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350064AbiFDBVb (ORCPT ); Fri, 3 Jun 2022 21:21:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349962AbiFDBVN (ORCPT ); Fri, 3 Jun 2022 21:21:13 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80DDB56751 for ; Fri, 3 Jun 2022 18:21:11 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id h10-20020a170902f54a00b00166449db7f8so3122344plf.9 for ; Fri, 03 Jun 2022 18:21:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=+jT04UMM2+8DeMl3bML3CIzXE/iqEmlJ78JJb5NF3co=; b=DX/Xg+K+dHp3epVqcNgGy8QkmMVAfJyZFm7N0b/6xAdj/8rZWJt2OXkMVasGJpyvSa 9Y7tCxPr3dlpflxsiMKK+il1oTr0b9smUFE7sEn2U3tDDslrXoQKEng0dnIEeFdDd7wq HqpH2BDWmBESLicd8x8WwIELbicOavyg89c0+CJl9RqDxhpVkjlIyAPOwL574k5fNcs8 1SDqlo0l49EpFo4ei4h3dYgq8MWkHxCmoENhgBJtl2xR3N8gLY+jz9UuA1qttRW732hl kRZJg/Vvxan1oTIaUbT2IIDpKsco5CsTni6iPbjADpkp+vLX0vnYgXy8xpX88dulo+z9 7WSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=+jT04UMM2+8DeMl3bML3CIzXE/iqEmlJ78JJb5NF3co=; b=ueHOuCbD+rCxI6cET3bxOtxoWiS44EgMx3WgzMrDoIonnMuge3BEfqRPlpeeyauBsS clXf1wuIZHaYwRYzSXDsUHsF8inqGZi5D3Z0K+EwARWwa0qvrBiweCT7js2YubmaQRs/ 41jlMMa19K+j5dVdkzulPYTBDdsHdPf09/beNn6L1KZgilpl7U8CWJgymVYiQr8JqEGS q9hamLFiej+39ibs8WqIz68GXrlt1mFDDYP92XvcDbOPbPLptq/Ih/pvHX3vMBK6DDJq 2zlMbN7dayk/eLA3OdXLKhHFDvlxz1g7HGfmeXoZhCvV1/+bXUbjryJ6eqbXT3/jRJXc Ja0Q== X-Gm-Message-State: AOAM530s12FRTFCTL+HF7Qmt49vBntS6y9EWo92ve8PWNCuSFDgyt62V MPcjPQqz0znqFJ7iyl8ddXeGNHIFwOc= X-Google-Smtp-Source: ABdhPJx3we3tRlTMsPFNwBMofFlvHEJoG6Kntis8HGldiQSu2dqM/ztME4yqJyr+iMsRTTgkr7hJxt8bSpk= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:f54c:b0:163:f64a:612c with SMTP id h12-20020a170902f54c00b00163f64a612cmr12828546plf.22.1654305670879; Fri, 03 Jun 2022 18:21:10 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:22 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-7-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 06/42] KVM: selftests: Use kvm_cpu_has() for nested VMX checks From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use kvm_cpu_has() to check for nested VMX support, and drop the helpers now that their functionality is trivial to implement. No functional change intended. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/x86_64/vmx.h | 3 --- tools/testing/selftests/kvm/lib/x86_64/vmx.c | 12 ------------ tools/testing/selftests/kvm/x86_64/evmcs_test.c | 2 +- tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c | 4 ++-- tools/testing/selftests/kvm/x86_64/smm_test.c | 2 +- tools/testing/selftests/kvm/x86_64/state_test.c | 2 +- .../selftests/kvm/x86_64/triple_fault_event_test.c | 2 +- .../selftests/kvm/x86_64/vmx_apic_access_test.c | 2 +- .../kvm/x86_64/vmx_close_while_nested_test.c | 2 +- .../selftests/kvm/x86_64/vmx_dirty_log_test.c | 2 +- .../kvm/x86_64/vmx_invalid_nested_guest_state.c | 2 +- .../kvm/x86_64/vmx_nested_tsc_scaling_test.c | 2 +- .../selftests/kvm/x86_64/vmx_preemption_timer_test.c | 2 +- .../selftests/kvm/x86_64/vmx_set_nested_state_test.c | 2 +- .../selftests/kvm/x86_64/vmx_tsc_adjust_test.c | 2 +- 15 files changed, 14 insertions(+), 29 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/vmx.h b/tools/testi= ng/selftests/kvm/include/x86_64/vmx.h index 583ceb0d1457..fe0ebb790b49 100644 --- a/tools/testing/selftests/kvm/include/x86_64/vmx.h +++ b/tools/testing/selftests/kvm/include/x86_64/vmx.h @@ -604,9 +604,6 @@ bool prepare_for_vmx_operation(struct vmx_pages *vmx); void prepare_vmcs(struct vmx_pages *vmx, void *guest_rip, void *guest_rsp); bool load_vmcs(struct vmx_pages *vmx); =20 -bool nested_vmx_supported(void); -void nested_vmx_check_supported(void); - void nested_pg_map(struct vmx_pages *vmx, struct kvm_vm *vm, uint64_t nested_paddr, uint64_t paddr); void nested_map(struct vmx_pages *vmx, struct kvm_vm *vm, diff --git a/tools/testing/selftests/kvm/lib/x86_64/vmx.c b/tools/testing/s= elftests/kvm/lib/x86_64/vmx.c index 3ba8278c5086..6d4dee220fbf 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/vmx.c +++ b/tools/testing/selftests/kvm/lib/x86_64/vmx.c @@ -372,18 +372,6 @@ void prepare_vmcs(struct vmx_pages *vmx, void *guest_r= ip, void *guest_rsp) init_vmcs_guest_state(guest_rip, guest_rsp); } =20 -bool nested_vmx_supported(void) -{ - struct kvm_cpuid_entry2 *entry =3D kvm_get_supported_cpuid_entry(1); - - return entry->ecx & CPUID_VMX; -} - -void nested_vmx_check_supported(void) -{ - TEST_REQUIRE(nested_vmx_supported()); -} - void nested_pg_map(struct vmx_pages *vmx, struct kvm_vm *vm, uint64_t nested_paddr, uint64_t paddr) { diff --git a/tools/testing/selftests/kvm/x86_64/evmcs_test.c b/tools/testin= g/selftests/kvm/x86_64/evmcs_test.c index 8dda527cc080..d762cadb0ee9 100644 --- a/tools/testing/selftests/kvm/x86_64/evmcs_test.c +++ b/tools/testing/selftests/kvm/x86_64/evmcs_test.c @@ -208,7 +208,7 @@ int main(int argc, char *argv[]) =20 vm =3D vm_create_with_one_vcpu(&vcpu, guest_code); =20 - TEST_REQUIRE(nested_vmx_supported()); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX)); TEST_REQUIRE(kvm_has_cap(KVM_CAP_NESTED_STATE)); TEST_REQUIRE(kvm_has_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)); =20 diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c b/tools/test= ing/selftests/kvm/x86_64/hyperv_cpuid.c index cbd4a7d36189..c406b95cba9b 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c @@ -148,7 +148,7 @@ int main(int argc, char *argv[]) test_hv_cpuid(hv_cpuid_entries, false); free(hv_cpuid_entries); =20 - if (!nested_vmx_supported() || + if (!kvm_cpu_has(X86_FEATURE_VMX) || !kvm_has_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)) { print_skip("Enlightened VMCS is unsupported"); goto do_sys; @@ -168,7 +168,7 @@ int main(int argc, char *argv[]) test_hv_cpuid_e2big(vm, NULL); =20 hv_cpuid_entries =3D kvm_get_supported_hv_cpuid(); - test_hv_cpuid(hv_cpuid_entries, nested_vmx_supported()); + test_hv_cpuid(hv_cpuid_entries, kvm_cpu_has(X86_FEATURE_VMX)); =20 out: kvm_vm_free(vm); diff --git a/tools/testing/selftests/kvm/x86_64/smm_test.c b/tools/testing/= selftests/kvm/x86_64/smm_test.c index 6b8108bdcead..40581704f129 100644 --- a/tools/testing/selftests/kvm/x86_64/smm_test.c +++ b/tools/testing/selftests/kvm/x86_64/smm_test.c @@ -156,7 +156,7 @@ int main(int argc, char *argv[]) if (kvm_check_cap(KVM_CAP_NESTED_STATE)) { if (kvm_cpu_has(X86_FEATURE_SVM)) vcpu_alloc_svm(vm, &nested_gva); - else if (nested_vmx_supported()) + else if (kvm_cpu_has(X86_FEATURE_VMX)) vcpu_alloc_vmx(vm, &nested_gva); } =20 diff --git a/tools/testing/selftests/kvm/x86_64/state_test.c b/tools/testin= g/selftests/kvm/x86_64/state_test.c index fe110ce31106..35e96d7a6ba1 100644 --- a/tools/testing/selftests/kvm/x86_64/state_test.c +++ b/tools/testing/selftests/kvm/x86_64/state_test.c @@ -172,7 +172,7 @@ int main(int argc, char *argv[]) if (kvm_check_cap(KVM_CAP_NESTED_STATE)) { if (kvm_cpu_has(X86_FEATURE_SVM)) vcpu_alloc_svm(vm, &nested_gva); - else if (nested_vmx_supported()) + else if (kvm_cpu_has(X86_FEATURE_VMX)) vcpu_alloc_vmx(vm, &nested_gva); } =20 diff --git a/tools/testing/selftests/kvm/x86_64/triple_fault_event_test.c b= /tools/testing/selftests/kvm/x86_64/triple_fault_event_test.c index 5a202ecb8ea0..af68f60a51e8 100644 --- a/tools/testing/selftests/kvm/x86_64/triple_fault_event_test.c +++ b/tools/testing/selftests/kvm/x86_64/triple_fault_event_test.c @@ -46,7 +46,7 @@ int main(void) vm_vaddr_t vmx_pages_gva; struct ucall uc; =20 - nested_vmx_check_supported(); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX)); =20 TEST_REQUIRE(kvm_has_cap(KVM_CAP_X86_TRIPLE_FAULT_EVENT)); =20 diff --git a/tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c b/to= ols/testing/selftests/kvm/x86_64/vmx_apic_access_test.c index ccb05ef7234e..59e8e8c8a8f5 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_apic_access_test.c @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) struct kvm_vcpu *vcpu; struct kvm_vm *vm; =20 - nested_vmx_check_supported(); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX)); =20 vm =3D vm_create_with_one_vcpu(&vcpu, l1_guest_code); =20 diff --git a/tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test= .c b/tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test.c index 40c77bb706a1..92760eeeee97 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_close_while_nested_test.c @@ -51,7 +51,7 @@ int main(int argc, char *argv[]) struct kvm_vcpu *vcpu; struct kvm_vm *vm; =20 - nested_vmx_check_supported(); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX)); =20 vm =3D vm_create_with_one_vcpu(&vcpu, l1_guest_code); =20 diff --git a/tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c b/tool= s/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c index 215ffa0589d4..a81964c85747 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_dirty_log_test.c @@ -77,7 +77,7 @@ int main(int argc, char *argv[]) struct ucall uc; bool done =3D false; =20 - nested_vmx_check_supported(); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX)); =20 /* Create VM */ vm =3D vm_create_with_one_vcpu(&vcpu, l1_guest_code); diff --git a/tools/testing/selftests/kvm/x86_64/vmx_invalid_nested_guest_st= ate.c b/tools/testing/selftests/kvm/x86_64/vmx_invalid_nested_guest_state.c index 683f4f0a1616..a714c260481f 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_invalid_nested_guest_state.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_invalid_nested_guest_state.c @@ -58,7 +58,7 @@ int main(int argc, char *argv[]) struct kvm_run *run; struct ucall uc; =20 - nested_vmx_check_supported(); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX)); =20 vm =3D vm_create_with_one_vcpu(&vcpu, l1_guest_code); =20 diff --git a/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test= .c b/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c index ff4644038c55..8edba1eee889 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_nested_tsc_scaling_test.c @@ -150,7 +150,7 @@ int main(int argc, char *argv[]) uint64_t l1_tsc_freq =3D 0; uint64_t l2_tsc_freq =3D 0; =20 - nested_vmx_check_supported(); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX)); TEST_REQUIRE(kvm_has_cap(KVM_CAP_TSC_CONTROL)); stable_tsc_check_supported(); =20 diff --git a/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c= b/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c index 771b54b227d5..afae65249bc5 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_preemption_timer_test.c @@ -167,7 +167,7 @@ int main(int argc, char *argv[]) * AMD currently does not implement any VMX features, so for now we * just early out. */ - nested_vmx_check_supported(); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX)); =20 TEST_REQUIRE(kvm_has_cap(KVM_CAP_NESTED_STATE)); =20 diff --git a/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c= b/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c index b564b86dfc1d..66cb2d0054e6 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c @@ -273,7 +273,7 @@ int main(int argc, char *argv[]) * AMD currently does not implement set_nested_state, so for now we * just early out. */ - nested_vmx_check_supported(); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX)); =20 vm =3D vm_create_with_one_vcpu(&vcpu, NULL); =20 diff --git a/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c b/too= ls/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c index e32bfb102699..2aecb21d4bda 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_tsc_adjust_test.c @@ -127,7 +127,7 @@ int main(int argc, char *argv[]) vm_vaddr_t vmx_pages_gva; struct kvm_vcpu *vcpu; =20 - nested_vmx_check_supported(); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX)); =20 vm =3D vm_create_with_one_vcpu(&vcpu, (void *) l1_guest_code); =20 --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB560C433EF for ; Sat, 4 Jun 2022 01:21:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350069AbiFDBVf (ORCPT ); Fri, 3 Jun 2022 21:21:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349992AbiFDBVP (ORCPT ); Fri, 3 Jun 2022 21:21:15 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A46D56773 for ; Fri, 3 Jun 2022 18:21:13 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id y66-20020a62ce45000000b0051bb4d19f5fso4429744pfg.18 for ; Fri, 03 Jun 2022 18:21:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=atPH1T2TubvL7PAUqYl19amHcm0CJWgBwICdsU+Bjlo=; b=Ofqb0/p28Y+xQw2Geh7UqeeARknTFRH6VFOMGeh3GBpGmEaYOLeRT99sUVTrluzUEu viaobvJ8WbVGFkTlT+xSQJNNdtFvN0PGqVgVBdtMAF9uj97ABSFfWWOXHumtxxxgzAgL a4XjV13y6LQNvUv2QpoCmScdURHN8aME53QSFfOXxJm5Xt1GgHFK1bHuHfn5MsAqzOQq JGb9VfWBZ7Euv0q4fbeuwYH02Uw/5DgGAhVvKsm66No4/B/fCZX8GqNUQm5m/jreQdhS ckWjgtdB+ScnTKd6BC0U4hRPgn+zFPZsfP2wCcfLLh/zOfwluUTTwvC2KMOC8fVUaUIJ QLkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=atPH1T2TubvL7PAUqYl19amHcm0CJWgBwICdsU+Bjlo=; b=pwDRDYJVBDiypZVv51YphqFxEQnhpmsjZR19rzMQO4xz1ZryQJkFZ6cK6cKOawN28T PhqmLcq+Rral29VHAFYA24w0+FqaHAc2kNvAU9Bk45g2NmIVfLzPT/wMhu+rtLctSkcH PvwuZ26ZwJI9bN7X/uv3k77ABnoGbuMu+g2PwxCv0sx+MJ7he9IIkmz5WLx1b5bxH1A/ RenS5gdqKfZyuXf5TSqF+wpzVJ5PoCZbEBHIlmvqbX5urFCgxewpjyW6lyMu4K92b/12 6xsuotZ7gx4dHZs1m6KCylkdyIVB4Ed1cy3qaFIo4Gl+FWaKbVjRr/DvnO6sv/M9hpn4 1zyA== X-Gm-Message-State: AOAM531azJbc/Rqaza3X4zq/weL81U+MqKJFqT2hel/ofb0glU6nEvSP EQeb6gYmv3V8WYqKNGZTHrK4JbN29TQ= X-Google-Smtp-Source: ABdhPJwlu3BFfGOsEZTkFbArnW/+qTHVi9kD4VrBqV1cmLxB2QxCNybzYbcemWsOSmfFNZ73q9jca3eAio0= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90a:249:b0:1e0:a8a3:3c6c with SMTP id t9-20020a17090a024900b001e0a8a33c6cmr4680pje.0.1654305672782; Fri, 03 Jun 2022 18:21:12 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:23 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-8-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 07/42] KVM: selftests: Use kvm_cpu_has() to query PDCM in PMU selftest From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use kvm_cpu_has() in the PMU test to query PDCM support instead of open coding equivalent functionality using kvm_get_supported_cpuid_index(). No functional change intended. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/x86_64/processor.h | 1 + tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index 24ffa7c238ff..ff8b92c435f5 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -79,6 +79,7 @@ struct kvm_x86_cpu_feature { #define X86_FEATURE_MWAIT KVM_X86_CPU_FEATURE(0x1, 0, ECX, 3) #define X86_FEATURE_VMX KVM_X86_CPU_FEATURE(0x1, 0, ECX, 5) #define X86_FEATURE_SMX KVM_X86_CPU_FEATURE(0x1, 0, ECX, 6) +#define X86_FEATURE_PDCM KVM_X86_CPU_FEATURE(0x1, 0, ECX, 15) #define X86_FEATURE_PCID KVM_X86_CPU_FEATURE(0x1, 0, ECX, 17) #define X86_FEATURE_MOVBE KVM_X86_CPU_FEATURE(0x1, 0, ECX, 22) #define X86_FEATURE_TSC_DEADLINE_TIMER KVM_X86_CPU_FEATURE(0x1, 0, ECX, 24) diff --git a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c b/tools= /testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c index eb592fae44ef..667d48e8c1e0 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c @@ -17,7 +17,6 @@ #include "kvm_util.h" #include "vmx.h" =20 -#define X86_FEATURE_PDCM (1<<15) #define PMU_CAP_FW_WRITES (1ULL << 13) #define PMU_CAP_LBR_FMT 0x3f =20 @@ -55,7 +54,6 @@ static void guest_code(void) int main(int argc, char *argv[]) { struct kvm_cpuid2 *cpuid; - struct kvm_cpuid_entry2 *entry_1_0; struct kvm_cpuid_entry2 *entry_a_0; struct kvm_vm *vm; struct kvm_vcpu *vcpu; @@ -70,11 +68,10 @@ int main(int argc, char *argv[]) vm =3D vm_create_with_one_vcpu(&vcpu, guest_code); cpuid =3D kvm_get_supported_cpuid(); =20 + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_PDCM)); + TEST_REQUIRE(kvm_get_cpuid_max_basic() >=3D 0xa); - - entry_1_0 =3D kvm_get_supported_cpuid_index(1, 0); entry_a_0 =3D kvm_get_supported_cpuid_index(0xa, 0); - TEST_REQUIRE(entry_1_0->ecx & X86_FEATURE_PDCM); =20 eax.full =3D entry_a_0->eax; __TEST_REQUIRE(eax.split.version_id, "PMU is not supported by the vCPU"); --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0195DC43334 for ; Sat, 4 Jun 2022 01:21:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349976AbiFDBVn (ORCPT ); Fri, 3 Jun 2022 21:21:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349969AbiFDBVT (ORCPT ); Fri, 3 Jun 2022 21:21:19 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C214A56FBB for ; Fri, 3 Jun 2022 18:21:15 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id c4-20020a170902d48400b001640bfb2b4fso5023186plg.20 for ; Fri, 03 Jun 2022 18:21:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=BA15XsheYEg2aJwndseGbrJZhwtEML96CqjQ+kb/wmc=; b=pPg2GFynxJngy+MLWHKeeUywc6H75gORal2taO+4fJyiNin0QbwtyXbwOxCtAUBoiT dFdouR4tc8CTdLYE5TaQGK7vlQaBHmGRvsPnF7I/T4lBnYNuxyqaiP+SBTphQQD1S5M0 5mwD6GwTgw7YD/K1VPFfxJWvKIM/lxbL+yJpFD8vw1Eo0WV6W2+HgtJqmZ/I5ux7haNB HtjeXhHrrKvwzAg45NoWE/hkXnFxm8zqpq9/lFlYaSHgkMi2vn9dA9d3mEySTwOzvvTN p7H64hKVoTF4U2CBSAKitNmz+VhW19tpBfpY8ZqBAh79MeR3B/m2Ms87vCQBQ3M00PWf MpWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=BA15XsheYEg2aJwndseGbrJZhwtEML96CqjQ+kb/wmc=; b=j4lRMvdPLlAdX5Y1BwefIdaUbSfj3Dxgi93PjEqaRJjUUbZFsE1ph7kVpE8N1R0ktS SvRXkwcgXFfAC99/4d5pIy8Dokceqz33M2j8YpZVOtXbCNSXQQrAsBuE7q7ogrhoTdA8 min6a6nEhZcy7jP+WqUrjQfwP7MI6k2vC703Kekz9P4+U7dlaUROXKmEtqQzWm7ymdS+ L5CusTM3gq457VmGkdMl+sOo9ClAfAlPr4ZItvrdtSoMwOuz+ONKighXPO8oMQnjVrEz pHU05PE6YUZW7TqbGBIpvDjBYvtR/9IUlLOQoLXk2Yb2FjE+YceE1Z3INBch5TtMAmqy EX/A== X-Gm-Message-State: AOAM53205knVmDWkObSQo/Dx7m1oTYmPpAh40O3fMVtvwZeoDdirhiiB JoOXxqtTespI0xE4JVevUci0MXGR6tI= X-Google-Smtp-Source: ABdhPJyPZ/NncXaFRCaRVYlwKuiZebsFuq49zH3xfw/IDANHmcw54YxaqbW3ck7+4hi69zLqIeS7zAuvBV4= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90a:178f:b0:1e3:3ba:c185 with SMTP id q15-20020a17090a178f00b001e303bac185mr4620pja.1.1654305674746; Fri, 03 Jun 2022 18:21:14 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:24 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-9-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 08/42] KVM: selftests: Drop redundant vcpu_set_cpuid() from PMU selftest From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Drop a redundant vcpu_set_cpuid() from the PMU test. The vCPU's CPUID is set to KVM's supported CPUID by vm_create_with_one_vcpu(), which was also true back when the helper was named vm_create_default(). Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c b/tools= /testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c index 667d48e8c1e0..dc3869d5aff0 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c @@ -53,7 +53,6 @@ static void guest_code(void) =20 int main(int argc, char *argv[]) { - struct kvm_cpuid2 *cpuid; struct kvm_cpuid_entry2 *entry_a_0; struct kvm_vm *vm; struct kvm_vcpu *vcpu; @@ -66,7 +65,6 @@ int main(int argc, char *argv[]) =20 /* Create VM */ vm =3D vm_create_with_one_vcpu(&vcpu, guest_code); - cpuid =3D kvm_get_supported_cpuid(); =20 TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_PDCM)); =20 @@ -77,7 +75,6 @@ int main(int argc, char *argv[]) __TEST_REQUIRE(eax.split.version_id, "PMU is not supported by the vCPU"); =20 /* testcase 1, set capabilities when we have PDCM bit */ - vcpu_set_cpuid(vcpu, cpuid); vcpu_set_msr(vcpu, MSR_IA32_PERF_CAPABILITIES, PMU_CAP_FW_WRITES); =20 /* check capabilities can be retrieved with KVM_GET_MSR */ --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C86C6C43334 for ; Sat, 4 Jun 2022 01:21:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347810AbiFDBVs (ORCPT ); Fri, 3 Jun 2022 21:21:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349980AbiFDBVU (ORCPT ); Fri, 3 Jun 2022 21:21:20 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A24A56771 for ; Fri, 3 Jun 2022 18:21:17 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id 15-20020a63020f000000b003fca9ebc5cbso4351969pgc.22 for ; Fri, 03 Jun 2022 18:21:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=2CIyo9+62gy+JEf6/FTcvhLOqsH6XI1aGgGR7RbhZy8=; b=e/CoQ6N1BLk/odGMKewDlRxYI9eMw5DUZwQ0JyS1vL18okZj3CyJgGnGtyTa2MGbpw /VBTEUVkRpuD3RR08dlwZJKxo5jSx8Dfu99Mm3BuLrUFYhBONNkNQMYHbekj0lbFLIGf 0LYhWpkFcjJZtEx+x2uLF/aPiev/CqY6CENPXAUCoolt+k3jRjcD0s3AQ6jgPOzWbOAp xIBrdWIWguF3/dR+ph5HhbQjExv4LNXd3d/Ezrday3GwFjdZ5JwahHQzyHLIZvQfBkUd 42np6xTe3W40uvhVw/bBPakuMvqndav7GibHDa9oQqF/50egSBsiGwRTfmI9OnYOYRhJ pqSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=2CIyo9+62gy+JEf6/FTcvhLOqsH6XI1aGgGR7RbhZy8=; b=mP6GcK8xmbkU+5HKO8/AyHywhMEn8t2OP7U8q+HxpjI96fw/qMNi5O9fFlWq4+0KJs Olwr6bwcmQBcB5X/DAFRrV1BR6e2Dp5yxE8k5C9zRqLBY0s1k69RS80ZMo6jB9LwoKoF CSP4xKP7cOfrh7ZEp+4YC/O779DtkLySRBgK8A6IH51+ygNrLFsZhub9+x8Ly/Fg02hw ktlh3nhJXvN63HmFhk2DwWUykmw5QOQYexQRQ61IFnZFi1z6+LGmH5cWGGPrs/FK4ZlK mNsIOtJQogiw+sQyb0PAvHHxPb/BxLhxkKYiTx4XxH/GgTJbsQ6z+l2Z8+bNUfQDDOaS TiPg== X-Gm-Message-State: AOAM533Wx0JBqcQ2/ln6DJUubpxjpuFZ3evjwhqH/oqXqzWQ244sUkNE RpG7BlNfLHNXmwT9wzTXGs3Rfj80TFc= X-Google-Smtp-Source: ABdhPJyEpE1eRHJzScLoumLROn6x7qNvOlhYu2NSqd5gJxBk6thivXmfFul7gtdrANkMicJfmvZmO2zR11g= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:f34c:b0:163:fa4f:2ff5 with SMTP id q12-20020a170902f34c00b00163fa4f2ff5mr12474825ple.174.1654305676584; Fri, 03 Jun 2022 18:21:16 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:25 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-10-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 09/42] KVM: selftests: Use kvm_cpu_has() for XSAVES in XSS MSR test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use kvm_cpu_has() in the XSS MSR test instead of open coding equivalent functionality using kvm_get_supported_cpuid_index(). No functional change intended. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/x86_64/processor.h | 1 + tools/testing/selftests/kvm/x86_64/xss_msr_test.c | 8 +------- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index ff8b92c435f5..7992c665be1f 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -110,6 +110,7 @@ struct kvm_x86_cpu_feature { #define X86_FEATURE_SPEC_CTRL KVM_X86_CPU_FEATURE(0x7, 0, EDX, 26) #define X86_FEATURE_ARCH_CAPABILITIES KVM_X86_CPU_FEATURE(0x7, 0, EDX, 29) #define X86_FEATURE_PKS KVM_X86_CPU_FEATURE(0x7, 0, ECX, 31) +#define X86_FEATURE_XSAVES KVM_X86_CPU_FEATURE(0xD, 1, EAX, 3) =20 /* * Extended Leafs, a.k.a. AMD defined diff --git a/tools/testing/selftests/kvm/x86_64/xss_msr_test.c b/tools/test= ing/selftests/kvm/x86_64/xss_msr_test.c index 4e2e08059b95..e0ddf47362e7 100644 --- a/tools/testing/selftests/kvm/x86_64/xss_msr_test.c +++ b/tools/testing/selftests/kvm/x86_64/xss_msr_test.c @@ -14,11 +14,8 @@ =20 #define MSR_BITS 64 =20 -#define X86_FEATURE_XSAVES (1<<3) - int main(int argc, char *argv[]) { - struct kvm_cpuid_entry2 *entry; bool xss_in_msr_list; struct kvm_vm *vm; struct kvm_vcpu *vcpu; @@ -28,10 +25,7 @@ int main(int argc, char *argv[]) /* Create VM */ vm =3D vm_create_with_one_vcpu(&vcpu, NULL); =20 - TEST_REQUIRE(kvm_get_cpuid_max_basic() >=3D 0xd); - - entry =3D kvm_get_supported_cpuid_index(0xd, 1); - TEST_REQUIRE(entry->eax & X86_FEATURE_XSAVES); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_XSAVES)); =20 xss_val =3D vcpu_get_msr(vcpu, MSR_IA32_XSS); TEST_ASSERT(xss_val =3D=3D 0, --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50651C43334 for ; Sat, 4 Jun 2022 01:21:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350046AbiFDBVy (ORCPT ); Fri, 3 Jun 2022 21:21:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349994AbiFDBVV (ORCPT ); Fri, 3 Jun 2022 21:21:21 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E36ED59950 for ; Fri, 3 Jun 2022 18:21:18 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id c4-20020a170902d48400b001640bfb2b4fso5023186plg.20 for ; Fri, 03 Jun 2022 18:21:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=XW8X4yFH4HS4z3rUG15HQfdjk7kNLByZNrfMhtmxpRE=; b=e2VxzPqm17DRBcWDrjDQGwvn9Ur6tC1K+Hz6fpuitm+bhqnyDsG2O95bjfc4rnfuHy jMEMKypFP/Mp5Xev+IETFjOO/v6tmaU7KrbkeMt+1oSAsdFjBxhCR74icaueNrLLPF2b m/cT+s2yTX/KPrc4BsQmIA58X/J0VT4ZmL4G0WfQk67n7+OttGHfaIEREefevXN2SCCf GJYCZ4jGL9LMYVYwuqubyRFO5xwHXgOE6xO5oMAt9vt9pFesC98vJjulB1dL0x58dgm0 xoVEqB9p3qfSE2hNRn0E25wIZPUwV7MUkyxy6yeC4c0Gw/I6qnmrmBqmxvagWwzAL66a Rz/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=XW8X4yFH4HS4z3rUG15HQfdjk7kNLByZNrfMhtmxpRE=; b=5BZhwwfe4dxvhAi55UYY7y9UxYGlLoZV+tn/tuIOL1hdDONPQXWm3P8E1DQjIP66Oh OOTTai+e+DM3hL5NnyTsoJctclieSl+Q/Mdhx3fBYYVHK8J8IDc1xP81qtgtDEfLcJ7x s3iffQHPxTer2OgpsepEy8uaUKQ3I/z5ALzz/fNrc24DCpWt3iO/NuGqpu+a/cAltFBo lIomo7qMAooN0jN/uTucHkCYbfrBs639bwZbDTSOVtUJpHgysRaddxCqKVpMIFc+duOY VhgWifKfvpeDWiZeatvWGMGpl+U3Um5BWjSs0VGebF1qoM2CpkbEvSavIoeXHgkFJXSW K5pg== X-Gm-Message-State: AOAM532iSaoT6of8PrR/4DoSgoW5bmFyYILftclAjuwSa4oKsckKCGDX fTBAgERvtslrE+MKIDxriFNKzcf1AiQ= X-Google-Smtp-Source: ABdhPJwS6/Wc62GmdJJolayUMi2VNNRN0ZwS575KfBKS/8lb9cFXlunYK4TeD0ZyJQpI7ToITKfewO9y+Fw= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:aa7:8d0f:0:b0:518:d867:bae8 with SMTP id j15-20020aa78d0f000000b00518d867bae8mr12417491pfe.13.1654305678379; Fri, 03 Jun 2022 18:21:18 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:26 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-11-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 10/42] KVM: selftests: Check for _both_ XTILE data and cfg in AMX test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Check for _both_ XTILE data and cfg support in the AMX test instead of checking for _either_ feature. Practically speaking, no sane CPU or vCPU will support one but not the other, but the effective "or" behavior is subtle and technically incorrect. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/x86_64/amx_test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/= selftests/kvm/x86_64/amx_test.c index 7127873bb0cb..dcad838953d0 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -335,7 +335,8 @@ int main(int argc, char *argv[]) TEST_REQUIRE(kvm_get_cpuid_max_basic() >=3D 0xd); =20 entry =3D kvm_get_supported_cpuid_index(0xd, 0); - TEST_REQUIRE(entry->eax & XFEATURE_MASK_XTILE); + TEST_REQUIRE(entry->eax & XFEATURE_MASK_XTILECFG); + TEST_REQUIRE(entry->eax & XFEATURE_MASK_XTILEDATA); =20 /* Get xsave/restore max size */ xsave_restore_size =3D entry->ecx; --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0802BC433EF for ; Sat, 4 Jun 2022 01:22:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350078AbiFDBV5 (ORCPT ); Fri, 3 Jun 2022 21:21:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345496AbiFDBVi (ORCPT ); Fri, 3 Jun 2022 21:21:38 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C99F59965 for ; Fri, 3 Jun 2022 18:21:21 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id s10-20020a170902a50a00b00162359521c9so5015725plq.23 for ; Fri, 03 Jun 2022 18:21:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=3sb/I+ky1JUZTKaqAwigyM/L21YMBjQUFYwkaqETcv4=; b=m6nIko5GCN3MOxn/8rcQefG9rFEuGTTHfAsk4eI3uveGvlXGDq1hay6ZxQBAbKs7IY 00hMab/FhZgS/YwhoLpoeuFZQ72xuwew7oLn+CW4USqq4RBNqvn+NaYfUrUK8wn2vLq4 j+oWljM3i/T8gZQyijdTvsB2g/woL8QVyiEzPjKil5pn93meNbvXLxWhkcWaUf5QFcDu ydqz4lHjgSI2Q6i8KvdooE8lwGqdO+BKvFn5gzv7iuvakdXOsxkt54t2/qCQxclTeQHC FlgOqR2WQiN0+BhNfTV6H2nzPhfZM88AT4rL+C2NjTFRIFOZYyO61LMMuAUtlNcF0dpN sMQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=3sb/I+ky1JUZTKaqAwigyM/L21YMBjQUFYwkaqETcv4=; b=vBmeLq7ymLnErXRDkqKCOeaQkaZJ6BmILvyDQTY/G5UA18TKdG0SKxvPHorEpvMuHe HaYSmF6vuyqYs50G2DO88sANnEHOPk2SkwaEGNan42e/7dfEvRF+tFE9Wl8gU6lSL6a3 s0SC3pOS7sfIfv5XFTUbINrlYQnAWwzt9tq/dKwJlmTrdyBdxFgOihgOL8QWVn2zxiod G0+Misy+c8FZy4OR7hW1AzQ20pXXTuowal6NooAfY9cTtvReTG+SbATAh7c6mVG3bi3o gnCO37eyG56+MeI11dya5aNDbnmT1O5l7HA1GlZFbCK7fQu2NAOTK8gF/rFHz7UqpcOU y6mA== X-Gm-Message-State: AOAM531TwnPsb4jCaBrveZXqa+PC6oV/t47dp6W0LROs8rDf+9ERcjJd +y19/zfPBzhwmKTZ4NRuHe1Od9McQME= X-Google-Smtp-Source: ABdhPJwggjyOrjjIEMfnYF+4t5wXwGHaL4T2Qx0MyDWttr2/bgfgifikToGLp0dn0s8C1TcZHCw6lynqfBY= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6a00:319b:b0:51b:c5ec:62ba with SMTP id bj27-20020a056a00319b00b0051bc5ec62bamr11397413pfb.1.1654305680195; Fri, 03 Jun 2022 18:21:20 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:27 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-12-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 11/42] KVM: selftests: Use kvm_cpu_has() in AMX test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use kvm_cpu_has() in the AMX test instead of open coding equivalent functionality using kvm_get_supported_cpuid_entry() and kvm_get_supported_cpuid_index(). No functional change intended. Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/x86_64/processor.h | 3 +++ tools/testing/selftests/kvm/x86_64/amx_test.c | 17 ++++++----------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index 7992c665be1f..9a7ce6b047f1 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -107,9 +107,12 @@ struct kvm_x86_cpu_feature { #define X86_FEATURE_RDPID KVM_X86_CPU_FEATURE(0x7, 0, ECX, 22) #define X86_FEATURE_SHSTK KVM_X86_CPU_FEATURE(0x7, 0, ECX, 7) #define X86_FEATURE_IBT KVM_X86_CPU_FEATURE(0x7, 0, EDX, 20) +#define X86_FEATURE_AMX_TILE KVM_X86_CPU_FEATURE(0x7, 0, EDX, 24) #define X86_FEATURE_SPEC_CTRL KVM_X86_CPU_FEATURE(0x7, 0, EDX, 26) #define X86_FEATURE_ARCH_CAPABILITIES KVM_X86_CPU_FEATURE(0x7, 0, EDX, 29) #define X86_FEATURE_PKS KVM_X86_CPU_FEATURE(0x7, 0, ECX, 31) +#define X86_FEATURE_XTILECFG KVM_X86_CPU_FEATURE(0xD, 0, EAX, 17) +#define X86_FEATURE_XTILEDATA KVM_X86_CPU_FEATURE(0xD, 0, EAX, 18) #define X86_FEATURE_XSAVES KVM_X86_CPU_FEATURE(0xD, 1, EAX, 3) =20 /* diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/= selftests/kvm/x86_64/amx_test.c index dcad838953d0..bcf535646321 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -312,13 +312,12 @@ void guest_nm_handler(struct ex_regs *regs) =20 int main(int argc, char *argv[]) { - struct kvm_cpuid_entry2 *entry; struct kvm_regs regs1, regs2; struct kvm_vcpu *vcpu; struct kvm_vm *vm; struct kvm_run *run; struct kvm_x86_state *state; - int xsave_restore_size =3D 0; + int xsave_restore_size; vm_vaddr_t amx_cfg, tiledata, xsavedata; struct ucall uc; u32 amx_offset; @@ -329,17 +328,13 @@ int main(int argc, char *argv[]) /* Create VM */ vm =3D vm_create_with_one_vcpu(&vcpu, guest_code); =20 - entry =3D kvm_get_supported_cpuid_entry(1); - TEST_REQUIRE(entry->ecx & CPUID_XSAVE); - - TEST_REQUIRE(kvm_get_cpuid_max_basic() >=3D 0xd); - - entry =3D kvm_get_supported_cpuid_index(0xd, 0); - TEST_REQUIRE(entry->eax & XFEATURE_MASK_XTILECFG); - TEST_REQUIRE(entry->eax & XFEATURE_MASK_XTILEDATA); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_XSAVE)); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_AMX_TILE)); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_XTILECFG)); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_XTILEDATA)); =20 /* Get xsave/restore max size */ - xsave_restore_size =3D entry->ecx; + xsave_restore_size =3D kvm_get_supported_cpuid_index(0xd, 0)->ecx; =20 run =3D vcpu->run; vcpu_regs_get(vcpu, ®s1); --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 700E3C433EF for ; Sat, 4 Jun 2022 01:22:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349980AbiFDBWO (ORCPT ); Fri, 3 Jun 2022 21:22:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350097AbiFDBVl (ORCPT ); Fri, 3 Jun 2022 21:21:41 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 229A859B87 for ; Fri, 3 Jun 2022 18:21:22 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id d13-20020a170902728d00b001635c985770so5055088pll.2 for ; Fri, 03 Jun 2022 18:21:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=6XC7JtZ5cEAXk5roBNccLsZKMYfOaGpCtF/bFJA0Fvo=; b=C8VjAHSs/NC3zH1Ez2SVvAJLV75TFs4IgqG/Uqd2yVHN/PiTpbOsT0TwqgF3ovuEJZ i/X43LnEjMzlMZ4UCbl8WFzaovu48WCXOcTfgw0lvGDfPUFb/Z2MsKBQWl0ZWe2CtxuI Gy64CJS+I2uVzQM1u+P7Kv6uQY1/3uxKo5n72lsIdb9BUngXinakqUdkT2G2hW8F1Ubk 8qst0I2Jj//MyaFNEpO1jFEM9eRL4NxZAbvbEFCEZJqndX45Tl7L1rNN81VIL7DhHJgC GhnM5r6t8qZRXPEUK8Jgt5sWVoHGDxBw/I7ON5XJnXrLRRqGGNuq39epsyjkSBrzy21Y W6qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=6XC7JtZ5cEAXk5roBNccLsZKMYfOaGpCtF/bFJA0Fvo=; b=iVBKEIb08XJaPVCbk3CCH+EjxBmk4DKPpWWmf4JvIKStewT3IzleZC97XOTnHCIQi6 t38LeuuL5Qd3gcTfOs8FgLUgcodCdvNOxCtqse9DWROHfzuJ25xYN1TbBjEVzILd/lsu tikDxodBiDyFxZyfu6QGX7vj7Q9TOEtVWQZb0/Pkt1FEZjNiNEfceLazwU/p1hhW6JHZ rs4pt0AkbG0/1KSfsTR0ELB6vqjmbgno4TL4TTejVtZ8t5EN/EtatU6Cz3XKqogZWLTh kVWlCHQV0emwPTV3Mu/hpKg391CYQjAADw+dxDt86TvW6LnTrc4X0BX7m4qr6EgG7+Sg R0Vw== X-Gm-Message-State: AOAM53029dxy6dsORZSMSf7021Q7VrfaDJaKb9v9ooUDEFZltGCq3gMl ToovKuIVVuxZO9S492jX6fbEGMgGDo4= X-Google-Smtp-Source: ABdhPJyO/2uj1pfmTeJyJWMIF8PZP2K9Ng5q4hQn0vYEwPUxsXeARv+oplb9rNxrEkjwBbDvbxk4dxoSMi0= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:903:2287:b0:164:83cf:bb15 with SMTP id b7-20020a170903228700b0016483cfbb15mr12544224plh.49.1654305681851; Fri, 03 Jun 2022 18:21:21 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:28 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-13-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 12/42] KVM: selftests: Use kvm_cpu_has() for XSAVE in cr4_cpuid_sync_test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use kvm_cpu_has() in the CR4/CPUID sync test instead of open coding equivalent functionality using kvm_get_supported_cpuid_entry(). No functional change intended. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c b/too= ls/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c index 8b0bb36205d9..092fedbe6f52 100644 --- a/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c +++ b/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c @@ -63,11 +63,9 @@ int main(int argc, char *argv[]) struct kvm_run *run; struct kvm_vm *vm; struct kvm_sregs sregs; - struct kvm_cpuid_entry2 *entry; struct ucall uc; =20 - entry =3D kvm_get_supported_cpuid_entry(1); - TEST_REQUIRE(entry->ecx & CPUID_XSAVE); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_XSAVE)); =20 /* Tell stdout not to buffer its content */ setbuf(stdout, NULL); --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AD62C43334 for ; Sat, 4 Jun 2022 01:22:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350187AbiFDBWe (ORCPT ); Fri, 3 Jun 2022 21:22:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350156AbiFDBWG (ORCPT ); Fri, 3 Jun 2022 21:22:06 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9AC85997A for ; Fri, 3 Jun 2022 18:21:36 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id s10-20020a170902a50a00b00162359521c9so5015780plq.23 for ; Fri, 03 Jun 2022 18:21:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=Q6jiJ1aOlB4Q05bHH1ZFB2hdrPIp9AfEUSu7/w240Y4=; b=KgbygI/vzVuigftSIpxOF/RP0xC4SuwPBrdHaJbujeDODCoyp31R84p1TXEk9qXcGT OkCt1KnDW6Jdu30WquxirBTjKPas9yZ584QIo/+dWNiaBt0DdySunLYTIdmigWbTQz8p r4nMlPCX+QUp2ppFxvCqTSt9lME3fen1zSjeutdnR6OdxLAuhSKcQEQpGU6pmPpBodr/ o+rtyoxfY5kYYfxCXIzNnKamFQBJe1Cnbx+vggNzvT4P9rISxjnkP8Ur4GRdhsUEkXce +PhfgnbWZUl1ASVuxG34dgjY4GBKCrNm2cU5ORYetBk2zi0c1c9lp6XjD7OJY2u/+q2T +qLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=Q6jiJ1aOlB4Q05bHH1ZFB2hdrPIp9AfEUSu7/w240Y4=; b=uzkt2HqfYVOiUFrrWxar6hb5qCTEsWjGSKJn0PUvVIowxaQqPmh/ajjhnfIf5h2zeP wm7gC6EdkPoZ47HbWM7dSHkIxGB4ntGEJsLlsmO5MNP3V1ni18tMhgqlF7g1kmnrmbxL GWCA1aZpLpxUccAMHhf3MY6ltaM931iFDeFAJ7otERiGkHw/VfxazJwnnWMV6T//wYw6 J7GTYoe9uZWiMk6eQmQW6icT5C/E+GIlbsTk8R7M7ws9beJjNc75uBMKMeahS28aXySH mojOCJzzYxKNF8jmXIVuLbajBU4e6iSUsTt3ULM91dDaAZlFHof867TMlodk6MutsPmT RM0g== X-Gm-Message-State: AOAM532H5MAKQNNXWn3CLpuqYIu2q5soY5FKDXfjg9aVzzOvkEKF/4Qv Lg98AsHRN8FHi+WWbfsA7Lt+JOtEpKo= X-Google-Smtp-Source: ABdhPJwUPtDy1Jv5+WRl4sT0qLarIF4vY6xMsjglors72WbxpaNAHO+VPvAz7CMjdxSrv4/LG9mUcYT2PTY= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a63:6bc7:0:b0:3fd:1b8d:d114 with SMTP id g190-20020a636bc7000000b003fd1b8dd114mr5764548pgc.308.1654305683428; Fri, 03 Jun 2022 18:21:23 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:29 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-14-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 13/42] KVM: selftests: Remove the obsolete/dead MMU role test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove the MMU role test, which was made obsolete by KVM commit feb627e8d6f6 ("KVM: x86: Forbid KVM_SET_CPUID{,2} after KVM_RUN"). The ongoing costs of keeping the test updated far outweigh any benefits, e.g. the test _might_ be useful as an example or for documentation purposes, but otherwise the test is dead weight. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/.gitignore | 1 - tools/testing/selftests/kvm/Makefile | 1 - .../selftests/kvm/include/x86_64/processor.h | 3 - .../selftests/kvm/x86_64/mmu_role_test.c | 137 ------------------ 4 files changed, 142 deletions(-) delete mode 100644 tools/testing/selftests/kvm/x86_64/mmu_role_test.c diff --git a/tools/testing/selftests/kvm/.gitignore b/tools/testing/selftes= ts/kvm/.gitignore index dd5c88c11059..0ab0e255d292 100644 --- a/tools/testing/selftests/kvm/.gitignore +++ b/tools/testing/selftests/kvm/.gitignore @@ -27,7 +27,6 @@ /x86_64/hyperv_svm_test /x86_64/max_vcpuid_cap_test /x86_64/mmio_warning_test -/x86_64/mmu_role_test /x86_64/platform_info_test /x86_64/pmu_event_filter_test /x86_64/set_boot_cpu_id diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests= /kvm/Makefile index 27e432273180..9a256c1f1bdf 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -56,7 +56,6 @@ TEST_GEN_PROGS_x86_64 +=3D x86_64/hyperv_svm_test TEST_GEN_PROGS_x86_64 +=3D x86_64/kvm_clock_test TEST_GEN_PROGS_x86_64 +=3D x86_64/kvm_pv_test TEST_GEN_PROGS_x86_64 +=3D x86_64/mmio_warning_test -TEST_GEN_PROGS_x86_64 +=3D x86_64/mmu_role_test TEST_GEN_PROGS_x86_64 +=3D x86_64/platform_info_test TEST_GEN_PROGS_x86_64 +=3D x86_64/pmu_event_filter_test TEST_GEN_PROGS_x86_64 +=3D x86_64/set_boot_cpu_id diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index 9a7ce6b047f1..a5e7b7bdec41 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -140,9 +140,6 @@ struct kvm_x86_cpu_feature { #define CPUID_XSAVE (1ul << 26) #define CPUID_OSXSAVE (1ul << 27) =20 -/* CPUID.0x8000_0001.EDX */ -#define CPUID_GBPAGES (1ul << 26) - /* CPUID.0x8000_000A.EDX */ #define CPUID_NRIPS BIT(3) =20 diff --git a/tools/testing/selftests/kvm/x86_64/mmu_role_test.c b/tools/tes= ting/selftests/kvm/x86_64/mmu_role_test.c deleted file mode 100644 index 9fd82580a382..000000000000 --- a/tools/testing/selftests/kvm/x86_64/mmu_role_test.c +++ /dev/null @@ -1,137 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 - -#include "kvm_util.h" -#include "processor.h" - -#define MMIO_GPA 0x100000000ull - -static void guest_code(void) -{ - (void)READ_ONCE(*((uint64_t *)MMIO_GPA)); - (void)READ_ONCE(*((uint64_t *)MMIO_GPA)); - - GUEST_ASSERT(0); -} - -static void guest_pf_handler(struct ex_regs *regs) -{ - /* PFEC =3D=3D RSVD | PRESENT (read, kernel). */ - GUEST_ASSERT(regs->error_code =3D=3D 0x9); - GUEST_DONE(); -} - -static void mmu_role_test(u32 *cpuid_reg, u32 evil_cpuid_val) -{ - u32 good_cpuid_val =3D *cpuid_reg; - struct kvm_vcpu *vcpu; - struct kvm_run *run; - struct kvm_vm *vm; - uint64_t cmd; - - /* Create VM */ - vm =3D vm_create_with_one_vcpu(&vcpu, guest_code); - run =3D vcpu->run; - - /* Map 1gb page without a backing memlot. */ - __virt_pg_map(vm, MMIO_GPA, MMIO_GPA, X86_PAGE_SIZE_1G); - - vcpu_run(vcpu); - - /* Guest access to the 1gb page should trigger MMIO. */ - TEST_ASSERT(run->exit_reason =3D=3D KVM_EXIT_MMIO, - "Unexpected exit reason: %u (%s), expected MMIO exit (1gb page w/o m= emslot)\n", - run->exit_reason, exit_reason_str(run->exit_reason)); - - TEST_ASSERT(run->mmio.len =3D=3D 8, "Unexpected exit mmio size =3D %u", r= un->mmio.len); - - TEST_ASSERT(run->mmio.phys_addr =3D=3D MMIO_GPA, - "Unexpected exit mmio address =3D 0x%llx", run->mmio.phys_addr); - - /* - * Effect the CPUID change for the guest and re-enter the guest. Its - * access should now #PF due to the PAGE_SIZE bit being reserved or - * the resulting GPA being invalid. Note, kvm_get_supported_cpuid() - * returns the struct that contains the entry being modified. Eww. - */ - *cpuid_reg =3D evil_cpuid_val; - vcpu_set_cpuid(vcpu, kvm_get_supported_cpuid()); - - /* - * Add a dummy memslot to coerce KVM into bumping the MMIO generation. - * KVM does not "officially" support mucking with CPUID after KVM_RUN, - * and will incorrectly reuse MMIO SPTEs. Don't delete the memslot! - * KVM x86 zaps all shadow pages on memslot deletion. - */ - vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, - MMIO_GPA << 1, 10, 1, 0); - - /* Set up a #PF handler to eat the RSVD #PF and signal all done! */ - vm_init_descriptor_tables(vm); - vcpu_init_descriptor_tables(vcpu); - vm_install_exception_handler(vm, PF_VECTOR, guest_pf_handler); - - vcpu_run(vcpu); - - cmd =3D get_ucall(vcpu, NULL); - TEST_ASSERT(cmd =3D=3D UCALL_DONE, - "Unexpected guest exit, exit_reason=3D%s, ucall.cmd =3D %lu\n", - exit_reason_str(run->exit_reason), cmd); - - /* - * Restore the happy CPUID value for the next test. Yes, changes are - * indeed persistent across VM destruction. - */ - *cpuid_reg =3D good_cpuid_val; - - kvm_vm_free(vm); -} - -int main(int argc, char *argv[]) -{ - struct kvm_cpuid_entry2 *entry; - int opt; - - /* - * All tests are opt-in because TDP doesn't play nice with reserved #PF - * in the GVA->GPA translation. The hardware page walker doesn't let - * software change GBPAGES or MAXPHYADDR, and KVM doesn't manually walk - * the GVA on fault for performance reasons. - */ - bool do_gbpages =3D false; - bool do_maxphyaddr =3D false; - - setbuf(stdout, NULL); - - while ((opt =3D getopt(argc, argv, "gm")) !=3D -1) { - switch (opt) { - case 'g': - do_gbpages =3D true; - break; - case 'm': - do_maxphyaddr =3D true; - break; - case 'h': - default: - printf("usage: %s [-g (GBPAGES)] [-m (MAXPHYADDR)]\n", argv[0]); - break; - } - } - - __TEST_REQUIRE(do_gbpages || do_maxphyaddr, "No sub-tests selected"); - - entry =3D kvm_get_supported_cpuid_entry(0x80000001); - TEST_REQUIRE(entry->edx & CPUID_GBPAGES); - - if (do_gbpages) { - pr_info("Test MMIO after toggling CPUID.GBPAGES\n\n"); - mmu_role_test(&entry->edx, entry->edx & ~CPUID_GBPAGES); - } - - if (do_maxphyaddr) { - pr_info("Test MMIO after changing CPUID.MAXPHYADDR\n\n"); - entry =3D kvm_get_supported_cpuid_entry(0x80000008); - mmu_role_test(&entry->eax, (entry->eax & ~0xff) | 0x20); - } - - return 0; -} --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3C73CCA47D for ; Sat, 4 Jun 2022 01:22:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350127AbiFDBWj (ORCPT ); Fri, 3 Jun 2022 21:22:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348549AbiFDBWN (ORCPT ); Fri, 3 Jun 2022 21:22:13 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8369A5A14D for ; Fri, 3 Jun 2022 18:21:39 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-30047b94aa8so80842897b3.1 for ; Fri, 03 Jun 2022 18:21:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=OE2dMTW1WZzsKCBPt600JzxUAoLzhxXCvLG8xb+mJtQ=; b=UORouyZwzAzUMWgkV4CowdjZaiMPkLHIlh3mNBtOULPqM9d9+8SaBazYYdKdmT1HUD pEmDREOxLR5K2IWIYFtSPF+zmv0nRlDAGZvvu8FuLMfh9XommYsgMypoo6F4yvOvdpY8 TaY1i3So48BBMR6mfteyLhtqB7mIHi+XGyuGT2xH4t8BMKJGaXA5gSIlkUl4QNwUyUE2 vmWFuoX7AGTuEve+jcSNaDzpney0u+uFs2fRYgylkTeTSMC1OSfYYPPxB56UBRvVH9ie pVI3AOxZgjO9o9m8hqCJtlKtKDzsLylY4mk0cT95f/NXlyJ7CXDDpv+YRJlci6Zkgs7+ ESOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=OE2dMTW1WZzsKCBPt600JzxUAoLzhxXCvLG8xb+mJtQ=; b=6w7fTbkMxJJIrf1hLYv73HQvjJzQJTUfmbdMw9ytGnQn8MSt8oozd1NjXd/92mU+K5 r0UFh5zJ+8A7yBTWbOx8QnQbvQiMNlShJvsZgT7EORog9US+t6Hj/E1KyNAn/66GGSN6 i3slk49CpPUDKd9yUG/tWlsOcYBWkkqUDuZ0SqAE+QK+RZfCNPVsZcJM0K+vQ+DHwScV WvVU7Z6snoCoBq0zpk/Cn9TmAFW673v+LgUkfOQ9J6ZvYu3zTQPN7qqsTL919m36ZFYn yiSlOS9vJxKeF1SrMJYnoW3x2EfTf/jHRQXEbJqWdu0860cKBFVL6lrgxpmpYzs7Qdd3 Ifiw== X-Gm-Message-State: AOAM530saEyPU63sNQf/+IW030oa5RerZXuWRvv/Qah7H8bs8c+sbYq6 zbcQ2mZHyPrfBiRMxn857hKd5zHwdPo= X-Google-Smtp-Source: ABdhPJxUnFU8pppx/0XWONy/KqI0nhKfPpx+GukdQA7cXborW9JQLI/bh82Obd1W2WDMVCPsTNZ7GYgxouY= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a25:8303:0:b0:65c:c9f7:3dbc with SMTP id s3-20020a258303000000b0065cc9f73dbcmr12894969ybk.259.1654305685297; Fri, 03 Jun 2022 18:21:25 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:30 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-15-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 14/42] KVM: selftests: Use kvm_cpu_has() for KVM's PV steal time From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use kvm_cpu_has() in the stea-ltime test instead of open coding equivalent functionality using kvm_get_supported_cpuid_entry(). Opportunistically define all of KVM's paravirt CPUID-based features. No functional change intended. Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/x86_64/processor.h | 22 +++++++++++++++++++ tools/testing/selftests/kvm/steal_time.c | 4 +--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index a5e7b7bdec41..4701798736cf 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -135,6 +135,28 @@ struct kvm_x86_cpu_feature { #define X86_FEATURE_SEV KVM_X86_CPU_FEATURE(0x8000001F, 0, EAX, 1) #define X86_FEATURE_SEV_ES KVM_X86_CPU_FEATURE(0x8000001F, 0, EAX, 3) =20 +/* + * KVM defined paravirt features. + */ +#define X86_FEATURE_KVM_CLOCKSOURCE KVM_X86_CPU_FEATURE(0x40000001, 0, EAX= , 0) +#define X86_FEATURE_KVM_NOP_IO_DELAY KVM_X86_CPU_FEATURE(0x40000001, 0, EA= X, 1) +#define X86_FEATURE_KVM_MMU_OP KVM_X86_CPU_FEATURE(0x40000001, 0, EAX, 2) +#define X86_FEATURE_KVM_CLOCKSOURCE2 KVM_X86_CPU_FEATURE(0x40000001, 0, EA= X, 3) +#define X86_FEATURE_KVM_ASYNC_PF KVM_X86_CPU_FEATURE(0x40000001, 0, EAX, 4) +#define X86_FEATURE_KVM_STEAL_TIME KVM_X86_CPU_FEATURE(0x40000001, 0, EAX,= 5) +#define X86_FEATURE_KVM_PV_EOI KVM_X86_CPU_FEATURE(0x40000001, 0, EAX, 6) +#define X86_FEATURE_KVM_PV_UNHALT KVM_X86_CPU_FEATURE(0x40000001, 0, EAX, = 7) +/* Bit 8 apparently isn't used?!?! */ +#define X86_FEATURE_KVM_PV_TLB_FLUSH KVM_X86_CPU_FEATURE(0x40000001, 0, EA= X, 9) +#define X86_FEATURE_KVM_ASYNC_PF_VMEXIT KVM_X86_CPU_FEATURE(0x40000001, 0,= EAX, 10) +#define X86_FEATURE_KVM_PV_SEND_IPI KVM_X86_CPU_FEATURE(0x40000001, 0, EAX= , 11) +#define X86_FEATURE_KVM_POLL_CONTROL KVM_X86_CPU_FEATURE(0x40000001, 0, EA= X, 12) +#define X86_FEATURE_KVM_PV_SCHED_YIELD KVM_X86_CPU_FEATURE(0x40000001, 0, = EAX, 13) +#define X86_FEATURE_KVM_ASYNC_PF_INT KVM_X86_CPU_FEATURE(0x40000001, 0, EA= X, 14) +#define X86_FEATURE_KVM_MSI_EXT_DEST_ID KVM_X86_CPU_FEATURE(0x40000001, 0,= EAX, 15) +#define X86_FEATURE_KVM_HC_MAP_GPA_RANGE KVM_X86_CPU_FEATURE(0x40000001, 0= , EAX, 16) +#define X86_FEATURE_KVM_MIGRATION_CONTROL KVM_X86_CPU_FEATURE(0x40000001, = 0, EAX, 17) + /* CPUID.1.ECX */ #define CPUID_VMX (1ul << 5) #define CPUID_XSAVE (1ul << 26) diff --git a/tools/testing/selftests/kvm/steal_time.c b/tools/testing/selft= ests/kvm/steal_time.c index d122f1e05cdd..5769d0cab4f5 100644 --- a/tools/testing/selftests/kvm/steal_time.c +++ b/tools/testing/selftests/kvm/steal_time.c @@ -60,9 +60,7 @@ static void guest_code(int cpu) =20 static bool is_steal_time_supported(struct kvm_vcpu *vcpu) { - struct kvm_cpuid_entry2 *cpuid =3D kvm_get_supported_cpuid_entry(KVM_CPUI= D_FEATURES); - - return cpuid && (cpuid->eax & KVM_FEATURE_STEAL_TIME); + return kvm_cpu_has(X86_FEATURE_KVM_STEAL_TIME); } =20 static void steal_time_init(struct kvm_vcpu *vcpu, uint32_t i) --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05C82C43334 for ; Sat, 4 Jun 2022 01:22:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350212AbiFDBWn (ORCPT ); Fri, 3 Jun 2022 21:22:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350115AbiFDBWR (ORCPT ); Fri, 3 Jun 2022 21:22:17 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCD7456771 for ; Fri, 3 Jun 2022 18:21:40 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id j23-20020aa78017000000b005180c6e4ef2so4710010pfi.12 for ; Fri, 03 Jun 2022 18:21:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=Vy11JEwxDol9yQABs4uZhD4BvSA+Z1desEZgyJ4yEtQ=; b=aDZjX+PI5EStIvuZnD6AeuIEtDn0K15jv1n9s425Z/XP24yXpXu4jn7lWOooIO/n8r 5DKDTUf92SxVFCU8BZAajz9rSi+tMZ9MrkWRltJ0oZwB1kvf8frh41tafEj1Nq6AC/dk WaVx3K0U0wD1B7ZYXYMUtP+f41O9M0WVCA+5qg1NQtay3KdnTnVKLw3/L4yNISa0OGHK v3FYDHFIGuYAASAnudgDAdQZ6xqIh9yyCdjUkSuq7kkQnPiE0jLWhAmR+dTm+2DBr+Kq Y5wV/0m7vMLNlVteRGGSI/U/P3tiMlwGJWeDztpXvxbptehRyh9zeDm5toiDeeht6aHW HDZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=Vy11JEwxDol9yQABs4uZhD4BvSA+Z1desEZgyJ4yEtQ=; b=WCa9oOREXCPWPgKKNOTc6RdCM58UMojPZ8o8EwoQd5h6xQF1ikwQVH3eetM1+L48Bt 78m/RCgZZ6Ooa0V+VTNZnKNqVKR4fQNpZ2SRhbAffSgExAHsE+OgFJBSjygOTNINdB2e KqlhF1Eat0/Um8tKcm3+jBQgOQdDOTSbrRMqPfGbbaqr56h2jGWJGwo6zlzYkt6QdPqO otCFims2fOXdOIIVTsLQ35E+b9K2hgVcpL1wamfivtcXJjGLGcvAEbGeHb6nR6bWtI02 sCsYIn9GM1O2d7qqKX8TCw+gPC8KPrLTLw5ds49pAQrADXBQGtsd7L6+YJGPs+y9Kz4p zfTA== X-Gm-Message-State: AOAM532/x7WWS9XrUipdvejQ7n+IrNQZrE3CF4sk5yNUjsWVdB05ahAx thlvkEB9u1SxFGKtxss6AHmT/n8tugw= X-Google-Smtp-Source: ABdhPJwfWI7j5d/X8xCz5NqbiIFJDxY9H895jE9GkwASlCmqB2nwKTHmG66Glb8OWebvZ6a4IRXsPvj/TSA= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a62:f806:0:b0:51b:6ea0:43cd with SMTP id d6-20020a62f806000000b0051b6ea043cdmr12794825pfh.28.1654305686771; Fri, 03 Jun 2022 18:21:26 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:31 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-16-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 15/42] KVM: selftests: Use kvm_cpu_has() for nSVM soft INT injection test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use kvm_cpu_has() to query for NRIPS support instead of open coding equivalent functionality using kvm_get_supported_cpuid_entry(). Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/x86_64/processor.h | 3 --- .../selftests/kvm/x86_64/svm_nested_soft_inject_test.c | 7 ++----- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index 4701798736cf..f4345961d447 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -162,9 +162,6 @@ struct kvm_x86_cpu_feature { #define CPUID_XSAVE (1ul << 26) #define CPUID_OSXSAVE (1ul << 27) =20 -/* CPUID.0x8000_000A.EDX */ -#define CPUID_NRIPS BIT(3) - /* Page table bitfield declarations */ #define PTE_PRESENT_MASK BIT_ULL(0) #define PTE_WRITABLE_MASK BIT_ULL(1) diff --git a/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test= .c b/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c index 3c21b997fe3a..edf7f2378c76 100644 --- a/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c +++ b/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c @@ -195,16 +195,13 @@ static void run_test(bool is_nmi) =20 int main(int argc, char *argv[]) { - struct kvm_cpuid_entry2 *cpuid; - /* Tell stdout not to buffer its content */ setbuf(stdout, NULL); =20 TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SVM)); =20 - cpuid =3D kvm_get_supported_cpuid_entry(0x8000000a); - TEST_ASSERT(cpuid->edx & CPUID_NRIPS, - "KVM with nSVM is supposed to unconditionally advertise nRIP Save\n"= ); + TEST_ASSERT(kvm_cpu_has(X86_FEATURE_NRIPS), + "KVM with nSVM is supposed to unconditionally advertise nRIP Save"); =20 atomic_init(&nmi_stage, 0); =20 --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C454C433EF for ; Sat, 4 Jun 2022 01:22:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349971AbiFDBWU (ORCPT ); Fri, 3 Jun 2022 21:22:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350136AbiFDBVt (ORCPT ); Fri, 3 Jun 2022 21:21:49 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB3E65677E for ; Fri, 3 Jun 2022 18:21:28 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id om5-20020a17090b3a8500b001df42f1cbaaso8053100pjb.5 for ; Fri, 03 Jun 2022 18:21:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=+P9ebQR/o0N4C3OJ9m1Uv8l25raaSyZTreScin4zTKM=; b=LKIbb7OzdyJNTyYLfYa5SqAKhGy8qCh/O8ZXDuyyuUn2JQb/TaGQGYvnsoHpUZ82VQ SBwcQGkKi3WqixgHwvzhrqaIjm/LdWchr1nQ4XU4XHbXelGsfBjOZS2oxSbSEs2fAdvA suW06y+VZvHX6qayFRKROkAQOT2xUvw7iJg2N8YcIuJx//fHrwUkZ0nglvW3rjWAR5go eS/ewvyA3u4QKpc9FicF31a0IT87S31bCuPShM1rwISP2RUh/biOZXHOmEGkHYAefHvX IylApBv8j4D3iDwHWbG9jyyPtBvxFNnvm9qlIRjfwnRCsa9pR5f81q11D49hkB8Xrs4G KJEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=+P9ebQR/o0N4C3OJ9m1Uv8l25raaSyZTreScin4zTKM=; b=GPb2HOcItM406pcnwCSXWB9xS1hpU4I0ZCus0O4fcOBUNMh1mAxvl5iu6hnjAZagQy a1pE006+rU1rLYyPLvvnuwKYMCmCTLqkT4wJnest9egLFYPOYOdVytqNC2zw3N7cwBVE W59G2pnr8Qjx0SJLAnpNevhNnrKB3iOcIWChkehT+mgq9jMNndZAVOgyaYeQXW/bmPvr m2Ro6AteEnQ8zeM9wVkeaR9aOSMp+LrjYHi8Oty+MkkQyN6DzVtIiSfwZECva2JgyOJU gRzOBHjw0fmVMPFS9H8MCIrdtpxtF6cXGTiopicjkK+HtJJD1Olv4mWUqIgEjrQf6fVu 3Vgw== X-Gm-Message-State: AOAM5323TAIJz9+JmDr+EbVORGaEyK4p7RN4BohyC2aHsHTjl33+Yv6g ZZobG94mdoFehW6HgLzwxEGCtEhUV5g= X-Google-Smtp-Source: ABdhPJxgvfD6FG8SsCElziqkiQTRREee4CpL7ZM72hJxwAc8WaSmO41wFuyeAtBhDVauiLb88jmLzQl5Kvk= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6a00:c84:b0:518:e0f6:f1af with SMTP id a4-20020a056a000c8400b00518e0f6f1afmr12773907pfv.47.1654305688234; Fri, 03 Jun 2022 18:21:28 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:32 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-17-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 16/42] KVM: selftests: Verify that kvm_cpuid2.entries layout is unchanged by KVM From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the CPUID test, verify that KVM doesn't modify the kvm_cpuid2.entries layout, i.e. that the order of entries and their flags is identical between what the test provides via KVM_SET_CPUID2 and what KVM returns via KVM_GET_CPUID2. Asserting that the layouts match simplifies the test as there's no need to iterate over both arrays. Signed-off-by: Sean Christopherson --- .../testing/selftests/kvm/x86_64/cpuid_test.c | 53 ++++++++----------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/cpuid_test.c b/tools/testin= g/selftests/kvm/x86_64/cpuid_test.c index 4aa784932597..dac5b1ebb512 100644 --- a/tools/testing/selftests/kvm/x86_64/cpuid_test.c +++ b/tools/testing/selftests/kvm/x86_64/cpuid_test.c @@ -79,41 +79,34 @@ static bool is_cpuid_mangled(struct kvm_cpuid_entry2 *e= ntrie) return false; } =20 -static void check_cpuid(struct kvm_cpuid2 *cpuid, struct kvm_cpuid_entry2 = *entrie) -{ - int i; - - for (i =3D 0; i < cpuid->nent; i++) { - if (cpuid->entries[i].function =3D=3D entrie->function && - cpuid->entries[i].index =3D=3D entrie->index) { - if (is_cpuid_mangled(entrie)) - return; - - TEST_ASSERT(cpuid->entries[i].eax =3D=3D entrie->eax && - cpuid->entries[i].ebx =3D=3D entrie->ebx && - cpuid->entries[i].ecx =3D=3D entrie->ecx && - cpuid->entries[i].edx =3D=3D entrie->edx, - "CPUID 0x%x.%x differ: 0x%x:0x%x:0x%x:0x%x vs 0x%x:0x%x:0x%x:0x%x", - entrie->function, entrie->index, - cpuid->entries[i].eax, cpuid->entries[i].ebx, - cpuid->entries[i].ecx, cpuid->entries[i].edx, - entrie->eax, entrie->ebx, entrie->ecx, entrie->edx); - return; - } - } - - TEST_ASSERT(false, "CPUID 0x%x.%x not found", entrie->function, entrie->i= ndex); -} - static void compare_cpuids(struct kvm_cpuid2 *cpuid1, struct kvm_cpuid2 *c= puid2) { + struct kvm_cpuid_entry2 *e1, *e2; int i; =20 - for (i =3D 0; i < cpuid1->nent; i++) - check_cpuid(cpuid2, &cpuid1->entries[i]); + TEST_ASSERT(cpuid1->nent =3D=3D cpuid2->nent, + "CPUID nent mismatch: %d vs. %d", cpuid1->nent, cpuid2->nent); =20 - for (i =3D 0; i < cpuid2->nent; i++) - check_cpuid(cpuid1, &cpuid2->entries[i]); + for (i =3D 0; i < cpuid1->nent; i++) { + e1 =3D &cpuid1->entries[i]; + e2 =3D &cpuid2->entries[i]; + + TEST_ASSERT(e1->function =3D=3D e2->function && + e1->index =3D=3D e2->index && e1->flags =3D=3D e2->flags, + "CPUID entries[%d] mismtach: 0x%x.%d.%x vs. 0x%x.%d.%x\n", + i, e1->function, e1->index, e1->flags, + e2->function, e2->index, e2->flags); + + if (is_cpuid_mangled(e1)) + continue; + + TEST_ASSERT(e1->eax =3D=3D e2->eax && e1->ebx =3D=3D e2->ebx && + e1->ecx =3D=3D e2->ecx && e1->edx =3D=3D e2->edx, + "CPUID 0x%x.%x differ: 0x%x:0x%x:0x%x:0x%x vs 0x%x:0x%x:0x%x:0x%x", + e1->function, e1->index, + e1->eax, e1->ebx, e1->ecx, e1->edx, + e2->eax, e2->ebx, e2->ecx, e2->edx); + } } =20 static void run_vcpu(struct kvm_vcpu *vcpu, int stage) --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E72E3C43334 for ; Sat, 4 Jun 2022 01:22:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350097AbiFDBWv (ORCPT ); Fri, 3 Jun 2022 21:22:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350138AbiFDBWS (ORCPT ); Fri, 3 Jun 2022 21:22:18 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CB7A5A080 for ; Fri, 3 Jun 2022 18:21:43 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 85-20020a250358000000b0065b9b24987aso8218762ybd.4 for ; Fri, 03 Jun 2022 18:21:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=2nzbG4tOFbNPVrwFNrAhbiBqvXzlQFgyph9XzwhODew=; b=JyPTO7S9D1Qyxfuxm2wrOYMchzpd60OlVQByfMkAGcam3znmhaD3zoczzLDVVr0C9S qoSNGV6v/IemASXnU8UqOVKWoq4VVVYnurAkfT2nI23amuPpsBE3aVKnr/ouZZZlo0Cb U6cfLAR7fPcYOxLUXzXyfpMAYHSIan/Q2eDbLDFWk5PHr48VMy7aKnbR++YuZkKHLsKH 31CWtiqMFuWTFO6m72mhZiqNNfej02HaffOHgBrxNu/jvFd9NqZol6SO3V58GLKdjNtn MGhP9Z14TfdJ9Hw/uLCryOdyalO3M5pZgeLCJg4VBemR1DiJWXWeVKmJtMWIjsqcTeP8 Ztiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=2nzbG4tOFbNPVrwFNrAhbiBqvXzlQFgyph9XzwhODew=; b=eloef7cNA7paQpUP1uGhYcxc4AdEm1SEt8/BQU58a/dBgrSfGF+uB5AXc0Zbd4s5rH 85NMseqY6z0oxWFyCMCPZ+u5RqgjVNOB3R5DJqto2AwdGkXp6CNpPcuxWuG07JIJL5Zm STYB+6uEVqsFBV3lg6VXBiEN6Uz+GIwERbrm5EgPvWfMmgHq8poCA7ACg461cYdYNsqu ukCdpeFxYocPmYp+gVCNd/dgo0dr7sU2I083zkyIBhREnDyUwxNzfckMyoRK5ojK06Pk PxNcjtM3zIMUcJ3OSORa1sLZ9JYOXVCsgtYKkxzsi2UujUdhWwn2opupFXw9Fyz2TJEy O4UA== X-Gm-Message-State: AOAM530mk2Pft/2aa4lH0txONhtZ3fcjOLeLjYc4YGgdACi9pUh5F6vp NcaLt2dz9xJ0mDAxK/bA3SEcwvERbnA= X-Google-Smtp-Source: ABdhPJz+dJP7G5HiCv9u07R08uVr6zUs40URy8kUmDodPyb9db0BanFmrMqLJBXE1jWDg/Czhir0IYXPJBs= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6902:100d:b0:660:514a:8787 with SMTP id w13-20020a056902100d00b00660514a8787mr11183750ybt.583.1654305690058; Fri, 03 Jun 2022 18:21:30 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:33 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-18-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 17/42] KVM: selftests: Split out kvm_cpuid2_size() from allocate_kvm_cpuid2() From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Split out the computation of the effective size of a kvm_cpuid2 struct from allocate_kvm_cpuid2(), and modify both to take an arbitrary number of entries. Future commits will add caching of a vCPU's CPUID model, and will (a) be able to precisely size the entries array, and (b) will need to know the effective size of the struct in order to copy to/from the cache. Expose the helpers so that the Hyper-V Features test can use them in the (somewhat distant) future. The Hyper-V test very, very subtly relies on propagating CPUID info across vCPU instances, and will need to make a copy of the previous vCPU's CPUID information when it switches to using the per-vCPU cache. Alternatively, KVM could provide helpers to duplicate and/or copy a kvm_cpuid2 instance, but each is literally a single line of code if the helpers are exposed, and it's not like the size of kvm_cpuid2 is secret knowledge. Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/x86_64/processor.h | 23 +++++++++ .../selftests/kvm/lib/x86_64/processor.c | 48 +++---------------- 2 files changed, 30 insertions(+), 41 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index f4345961d447..6b6a72693289 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -593,6 +593,29 @@ static inline bool kvm_cpu_has(struct kvm_x86_cpu_feat= ure feature) return kvm_cpuid_has(kvm_get_supported_cpuid(), feature); } =20 +static inline size_t kvm_cpuid2_size(int nr_entries) +{ + return sizeof(struct kvm_cpuid2) + + sizeof(struct kvm_cpuid_entry2) * nr_entries; +} + +/* + * Allocate a "struct kvm_cpuid2* instance, with the 0-length arrary of + * entries sized to hold @nr_entries. The caller is responsible for freei= ng + * the struct. + */ +static inline struct kvm_cpuid2 *allocate_kvm_cpuid2(int nr_entries) +{ + struct kvm_cpuid2 *cpuid; + + cpuid =3D malloc(kvm_cpuid2_size(nr_entries)); + TEST_ASSERT(cpuid, "-ENOMEM when allocating kvm_cpuid2"); + + cpuid->nent =3D nr_entries; + + return cpuid; +} + struct kvm_cpuid2 *vcpu_get_cpuid(struct kvm_vcpu *vcpu); =20 static inline int __vcpu_set_cpuid(struct kvm_vcpu *vcpu, diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index e60afab6b88f..05eac8134119 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -16,6 +16,8 @@ #define DEFAULT_CODE_SELECTOR 0x8 #define DEFAULT_DATA_SELECTOR 0x10 =20 +#define MAX_NR_CPUID_ENTRIES 100 + vm_vaddr_t exception_handlers; =20 static void regs_dump(FILE *stream, struct kvm_regs *regs, uint8_t indent) @@ -673,40 +675,6 @@ struct kvm_vcpu *vm_arch_vcpu_recreate(struct kvm_vm *= vm, uint32_t vcpu_id) return vcpu; } =20 -/* - * Allocate an instance of struct kvm_cpuid2 - * - * Input Args: None - * - * Output Args: None - * - * Return: A pointer to the allocated struct. The caller is responsible - * for freeing this struct. - * - * Since kvm_cpuid2 uses a 0-length array to allow a the size of the - * array to be decided at allocation time, allocation is slightly - * complicated. This function uses a reasonable default length for - * the array and performs the appropriate allocation. - */ -static struct kvm_cpuid2 *allocate_kvm_cpuid2(void) -{ - struct kvm_cpuid2 *cpuid; - int nent =3D 100; - size_t size; - - size =3D sizeof(*cpuid); - size +=3D nent * sizeof(struct kvm_cpuid_entry2); - cpuid =3D malloc(size); - if (!cpuid) { - perror("malloc"); - abort(); - } - - cpuid->nent =3D nent; - - return cpuid; -} - /* * KVM Supported CPUID Get * @@ -726,7 +694,7 @@ struct kvm_cpuid2 *kvm_get_supported_cpuid(void) if (cpuid) return cpuid; =20 - cpuid =3D allocate_kvm_cpuid2(); + cpuid =3D allocate_kvm_cpuid2(MAX_NR_CPUID_ENTRIES); kvm_fd =3D open_kvm_dev_path_or_exit(); =20 kvm_ioctl(kvm_fd, KVM_GET_SUPPORTED_CPUID, cpuid); @@ -782,7 +750,7 @@ struct kvm_cpuid2 *vcpu_get_cpuid(struct kvm_vcpu *vcpu) int max_ent; int rc =3D -1; =20 - cpuid =3D allocate_kvm_cpuid2(); + cpuid =3D allocate_kvm_cpuid2(MAX_NR_CPUID_ENTRIES); max_ent =3D cpuid->nent; =20 for (cpuid->nent =3D 1; cpuid->nent <=3D max_ent; cpuid->nent++) { @@ -1279,7 +1247,7 @@ struct kvm_cpuid2 *kvm_get_supported_hv_cpuid(void) if (cpuid) return cpuid; =20 - cpuid =3D allocate_kvm_cpuid2(); + cpuid =3D allocate_kvm_cpuid2(MAX_NR_CPUID_ENTRIES); kvm_fd =3D open_kvm_dev_path_or_exit(); =20 kvm_ioctl(kvm_fd, KVM_GET_SUPPORTED_HV_CPUID, cpuid); @@ -1298,9 +1266,7 @@ void vcpu_set_hv_cpuid(struct kvm_vcpu *vcpu) cpuid_sys =3D kvm_get_supported_cpuid(); cpuid_hv =3D kvm_get_supported_hv_cpuid(); =20 - cpuid_full =3D malloc(sizeof(*cpuid_full) + - (cpuid_sys->nent + cpuid_hv->nent) * - sizeof(struct kvm_cpuid_entry2)); + cpuid_full =3D allocate_kvm_cpuid2(cpuid_sys->nent + cpuid_hv->nent); if (!cpuid_full) { perror("malloc"); abort(); @@ -1327,7 +1293,7 @@ struct kvm_cpuid2 *vcpu_get_supported_hv_cpuid(struct= kvm_vcpu *vcpu) { static struct kvm_cpuid2 *cpuid; =20 - cpuid =3D allocate_kvm_cpuid2(); + cpuid =3D allocate_kvm_cpuid2(MAX_NR_CPUID_ENTRIES); =20 vcpu_ioctl(vcpu, KVM_GET_SUPPORTED_HV_CPUID, cpuid); =20 --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83D67CCA473 for ; Sat, 4 Jun 2022 01:23:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350010AbiFDBXP (ORCPT ); Fri, 3 Jun 2022 21:23:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350141AbiFDBWU (ORCPT ); Fri, 3 Jun 2022 21:22:20 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C35AE5A165 for ; Fri, 3 Jun 2022 18:21:45 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id i9-20020a632209000000b003facc62e253so4568781pgi.11 for ; Fri, 03 Jun 2022 18:21:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=OcXgy1m5p5sqn5wtDZ8wsO+JIR/leVCIH38Z60Ex5X4=; b=Z8BeYbpBnk3fRT+oQoXDJIV45+AAITMcG1fwWAtBHOhg971zT2buQ6HI6BIKj2wC4/ 5w8AawZqQB6En7PwH5jvqut0cyGrrCva1yZEMQXtU67i2jdnTEGczz3V1OyJGORkGcar GgG149Xh5k7BCNT3L9GEJ+8ptOZUfjhPBZQFzN3tggB2ewGEVIMkdSTl61wPQ6oQ6Ey4 +C1QY2sFHpQmEkFWNxgNPqf7WhoEg+lE8N32drHCJZnhQuCl3VmW8QX6+Z8I5BQ1ispN 8J99b+NSskjcu60lRTA6NnpsYZ6Huu15UOCkGUI6XfgfnIke3JMHx0spUo7tiUmN240h E9XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=OcXgy1m5p5sqn5wtDZ8wsO+JIR/leVCIH38Z60Ex5X4=; b=gj4cxIz2VL4zEJNx9nqJehzxnZ7DLMRSlm2UF8Sw4Py4SJAs0IADGr/+jkqMa6U9L0 8+Bv0hu1ep2RqyKC4xWjVB32Wm2dkpWskbzuwyCb5VcbJljdDNxIwlgv90YQ3LEs8+yT ij7xRz7tlJX4voozjNg/WDKR0U3EJ+RNqxn5qbWHvmy3vWdXg6zu/sJOS3DoSivsq+UG DNbh0tpTWzaXhu2I2gdhwxBHhY+TTx0jko3hssQmjLXfqE3wkHr5BIMNIgb6usbA1ffU AOGfestpziGLpqyuJYZKlgdGBMjcmyq/kTBu0yMszR3i6jyBkih1nNVLyplzqgUglbPg FSug== X-Gm-Message-State: AOAM531v3ZHywgWusMTyTcl20jSWRK41kCWB4LiNKWNQkVFXJ1bQTeDc pXUP9JVF3Bra8r7vWttXxxzd8KgXWU0= X-Google-Smtp-Source: ABdhPJy3JyTuuK0XewhL2Xaj/9GIODFtqH7peEmVOOTMI1SCPuhwfK5fzQ025pMsZDm/GGGk7P6eLTxTADk= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:7005:b0:163:ffe7:32eb with SMTP id y5-20020a170902700500b00163ffe732ebmr12771281plk.18.1654305691734; Fri, 03 Jun 2022 18:21:31 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:34 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-19-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 18/42] KVM: selftests: Cache CPUID in struct kvm_vcpu From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Cache a vCPU's CPUID information in "struct kvm_vcpu" to allow fixing the mess where tests, often unknowingly, modify the global/static "cpuid" allocated by kvm_get_supported_cpuid(). Add vcpu_init_cpuid() to handle stuffing an entirely different CPUID model, e.g. during vCPU creation or when switching to the Hyper-V enabled CPUID model. Automatically refresh the cache on vcpu_set_cpuid() so that any adjustments made by KVM are always reflected in the cache. Drop vcpu_get_cpuid() entirely to force tests to use the cache, and to allow adding e.g. vcpu_get_cpuid_entry() in the future without creating a conflicting set of APIs where vcpu_get_cpuid() does KVM_GET_CPUID2, but vcpu_get_cpuid_entry() does not. Opportunistically convert the VMX nested state test and KVM PV test to manipulating the vCPU's CPUID (because it's easy), but use vcpu_init_cpuid() for the Hyper-V features test and "emulator error" test to effectively retain their current behavior as they're less trivial to convert. Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/kvm_util_base.h | 5 +++ .../selftests/kvm/include/x86_64/processor.h | 25 +++++++---- tools/testing/selftests/kvm/lib/kvm_util.c | 7 ++++ .../selftests/kvm/lib/x86_64/processor.c | 42 +++++++++---------- .../testing/selftests/kvm/x86_64/cpuid_test.c | 18 ++++---- .../kvm/x86_64/emulator_error_test.c | 2 +- .../selftests/kvm/x86_64/hyperv_features.c | 2 +- .../selftests/kvm/x86_64/kvm_pv_test.c | 6 +-- .../kvm/x86_64/vmx_set_nested_state_test.c | 6 +-- .../selftests/kvm/x86_64/xapic_state_test.c | 4 +- 10 files changed, 68 insertions(+), 49 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/te= sting/selftests/kvm/include/kvm_util_base.h index 93661d26ac4e..0eeae1dfbe63 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -50,6 +50,9 @@ struct kvm_vcpu { int fd; struct kvm_vm *vm; struct kvm_run *run; +#ifdef __x86_64__ + struct kvm_cpuid2 *cpuid; +#endif struct kvm_dirty_gfn *dirty_gfns; uint32_t fetch_index; uint32_t dirty_gfns_count; @@ -690,6 +693,8 @@ static inline struct kvm_vcpu *vm_vcpu_recreate(struct = kvm_vm *vm, return vm_arch_vcpu_recreate(vm, vcpu_id); } =20 +void vcpu_arch_free(struct kvm_vcpu *vcpu); + void virt_arch_pgd_alloc(struct kvm_vm *vm); =20 static inline void virt_pgd_alloc(struct kvm_vm *vm) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index 6b6a72693289..f170fd5f8726 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -616,18 +616,29 @@ static inline struct kvm_cpuid2 *allocate_kvm_cpuid2(= int nr_entries) return cpuid; } =20 -struct kvm_cpuid2 *vcpu_get_cpuid(struct kvm_vcpu *vcpu); +void vcpu_init_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid); =20 -static inline int __vcpu_set_cpuid(struct kvm_vcpu *vcpu, - struct kvm_cpuid2 *cpuid) +static inline int __vcpu_set_cpuid(struct kvm_vcpu *vcpu) { - return __vcpu_ioctl(vcpu, KVM_SET_CPUID2, cpuid); + int r; + + TEST_ASSERT(vcpu->cpuid, "Must do vcpu_init_cpuid() first"); + r =3D __vcpu_ioctl(vcpu, KVM_SET_CPUID2, vcpu->cpuid); + if (r) + return r; + + /* On success, refresh the cache to pick up adjustments made by KVM. */ + vcpu_ioctl(vcpu, KVM_GET_CPUID2, vcpu->cpuid); + return 0; } =20 -static inline void vcpu_set_cpuid(struct kvm_vcpu *vcpu, - struct kvm_cpuid2 *cpuid) +static inline void vcpu_set_cpuid(struct kvm_vcpu *vcpu) { - vcpu_ioctl(vcpu, KVM_SET_CPUID2, cpuid); + TEST_ASSERT(vcpu->cpuid, "Must do vcpu_init_cpuid() first"); + vcpu_ioctl(vcpu, KVM_SET_CPUID2, vcpu->cpuid); + + /* Refresh the cache to pick up adjustments made by KVM. */ + vcpu_ioctl(vcpu, KVM_GET_CPUID2, vcpu->cpuid); } =20 struct kvm_cpuid_entry2 * diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/sel= ftests/kvm/lib/kvm_util.c index d73d9eba2585..6a7949c8ba5d 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -475,6 +475,11 @@ kvm_userspace_memory_region_find(struct kvm_vm *vm, ui= nt64_t start, return ®ion->region; } =20 +__weak void vcpu_arch_free(struct kvm_vcpu *vcpu) +{ + +} + /* * VM VCPU Remove * @@ -504,6 +509,8 @@ static void vm_vcpu_rm(struct kvm_vm *vm, struct kvm_vc= pu *vcpu) TEST_ASSERT(!ret, __KVM_SYSCALL_ERROR("close()", ret)); =20 list_del(&vcpu->list); + + vcpu_arch_free(vcpu); free(vcpu); } =20 diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index 05eac8134119..c252c7463970 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -649,7 +649,7 @@ struct kvm_vcpu *vm_arch_vcpu_add(struct kvm_vm *vm, ui= nt32_t vcpu_id, DEFAULT_GUEST_STACK_VADDR_MIN); =20 vcpu =3D __vm_vcpu_add(vm, vcpu_id); - vcpu_set_cpuid(vcpu, kvm_get_supported_cpuid()); + vcpu_init_cpuid(vcpu, kvm_get_supported_cpuid()); vcpu_setup(vm, vcpu); =20 /* Setup guest general purpose registers */ @@ -670,11 +670,17 @@ struct kvm_vcpu *vm_arch_vcpu_recreate(struct kvm_vm = *vm, uint32_t vcpu_id) { struct kvm_vcpu *vcpu =3D __vm_vcpu_add(vm, vcpu_id); =20 - vcpu_set_cpuid(vcpu, kvm_get_supported_cpuid()); + vcpu_init_cpuid(vcpu, kvm_get_supported_cpuid()); =20 return vcpu; } =20 +void vcpu_arch_free(struct kvm_vcpu *vcpu) +{ + if (vcpu->cpuid) + free(vcpu->cpuid); +} + /* * KVM Supported CPUID Get * @@ -744,31 +750,23 @@ uint64_t kvm_get_feature_msr(uint64_t msr_index) return buffer.entry.data; } =20 -struct kvm_cpuid2 *vcpu_get_cpuid(struct kvm_vcpu *vcpu) +void vcpu_init_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid) { - struct kvm_cpuid2 *cpuid; - int max_ent; - int rc =3D -1; + TEST_ASSERT(cpuid !=3D vcpu->cpuid, "@cpuid can't be the vCPU's CPUID"); =20 - cpuid =3D allocate_kvm_cpuid2(MAX_NR_CPUID_ENTRIES); - max_ent =3D cpuid->nent; - - for (cpuid->nent =3D 1; cpuid->nent <=3D max_ent; cpuid->nent++) { - rc =3D __vcpu_ioctl(vcpu, KVM_GET_CPUID2, cpuid); - if (!rc) - break; - - TEST_ASSERT(rc =3D=3D -1 && errno =3D=3D E2BIG, - "KVM_GET_CPUID2 should either succeed or give E2BIG: %d %d", - rc, errno); + /* Allow overriding the default CPUID. */ + if (vcpu->cpuid && vcpu->cpuid->nent < cpuid->nent) { + free(vcpu->cpuid); + vcpu->cpuid =3D NULL; } =20 - TEST_ASSERT(!rc, KVM_IOCTL_ERROR(KVM_GET_CPUID2, rc)); - return cpuid; + if (!vcpu->cpuid) + vcpu->cpuid =3D allocate_kvm_cpuid2(cpuid->nent); + + memcpy(vcpu->cpuid, cpuid, kvm_cpuid2_size(cpuid->nent)); + vcpu_set_cpuid(vcpu); } =20 - - /* * Locate a cpuid entry. * @@ -1286,7 +1284,7 @@ void vcpu_set_hv_cpuid(struct kvm_vcpu *vcpu) cpuid_full->nent =3D nent + cpuid_hv->nent; } =20 - vcpu_set_cpuid(vcpu, cpuid_full); + vcpu_init_cpuid(vcpu, cpuid_full); } =20 struct kvm_cpuid2 *vcpu_get_supported_hv_cpuid(struct kvm_vcpu *vcpu) diff --git a/tools/testing/selftests/kvm/x86_64/cpuid_test.c b/tools/testin= g/selftests/kvm/x86_64/cpuid_test.c index dac5b1ebb512..ca36557646b0 100644 --- a/tools/testing/selftests/kvm/x86_64/cpuid_test.c +++ b/tools/testing/selftests/kvm/x86_64/cpuid_test.c @@ -145,21 +145,22 @@ struct kvm_cpuid2 *vcpu_alloc_cpuid(struct kvm_vm *vm= , vm_vaddr_t *p_gva, struct return guest_cpuids; } =20 -static void set_cpuid_after_run(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *= cpuid) +static void set_cpuid_after_run(struct kvm_vcpu *vcpu) { + struct kvm_cpuid2 *cpuid =3D vcpu->cpuid; struct kvm_cpuid_entry2 *ent; int rc; u32 eax, ebx, x; =20 /* Setting unmodified CPUID is allowed */ - rc =3D __vcpu_set_cpuid(vcpu, cpuid); + rc =3D __vcpu_set_cpuid(vcpu); TEST_ASSERT(!rc, "Setting unmodified CPUID after KVM_RUN failed: %d", rc); =20 /* Changing CPU features is forbidden */ ent =3D get_cpuid(cpuid, 0x7, 0); ebx =3D ent->ebx; ent->ebx--; - rc =3D __vcpu_set_cpuid(vcpu, cpuid); + rc =3D __vcpu_set_cpuid(vcpu); TEST_ASSERT(rc, "Changing CPU features should fail"); ent->ebx =3D ebx; =20 @@ -168,14 +169,14 @@ static void set_cpuid_after_run(struct kvm_vcpu *vcpu= , struct kvm_cpuid2 *cpuid) eax =3D ent->eax; x =3D eax & 0xff; ent->eax =3D (eax & ~0xffu) | (x - 1); - rc =3D __vcpu_set_cpuid(vcpu, cpuid); + rc =3D __vcpu_set_cpuid(vcpu); TEST_ASSERT(rc, "Changing MAXPHYADDR should fail"); ent->eax =3D eax; } =20 int main(void) { - struct kvm_cpuid2 *supp_cpuid, *cpuid2; + struct kvm_cpuid2 *supp_cpuid; struct kvm_vcpu *vcpu; vm_vaddr_t cpuid_gva; struct kvm_vm *vm; @@ -184,18 +185,17 @@ int main(void) vm =3D vm_create_with_one_vcpu(&vcpu, guest_main); =20 supp_cpuid =3D kvm_get_supported_cpuid(); - cpuid2 =3D vcpu_get_cpuid(vcpu); =20 - compare_cpuids(supp_cpuid, cpuid2); + compare_cpuids(supp_cpuid, vcpu->cpuid); =20 - vcpu_alloc_cpuid(vm, &cpuid_gva, cpuid2); + vcpu_alloc_cpuid(vm, &cpuid_gva, vcpu->cpuid); =20 vcpu_args_set(vcpu, 1, cpuid_gva); =20 for (stage =3D 0; stage < 3; stage++) run_vcpu(vcpu, stage); =20 - set_cpuid_after_run(vcpu, cpuid2); + set_cpuid_after_run(vcpu); =20 kvm_vm_free(vm); } diff --git a/tools/testing/selftests/kvm/x86_64/emulator_error_test.c b/too= ls/testing/selftests/kvm/x86_64/emulator_error_test.c index bfff2d271c48..bb410c359599 100644 --- a/tools/testing/selftests/kvm/x86_64/emulator_error_test.c +++ b/tools/testing/selftests/kvm/x86_64/emulator_error_test.c @@ -172,7 +172,7 @@ int main(int argc, char *argv[]) entry->eax =3D (entry->eax & 0xffffff00) | MAXPHYADDR; set_cpuid(cpuid, entry); =20 - vcpu_set_cpuid(vcpu, cpuid); + vcpu_init_cpuid(vcpu, cpuid); =20 rc =3D kvm_check_cap(KVM_CAP_EXIT_ON_EMULATION_FAILURE); TEST_ASSERT(rc, "KVM_CAP_EXIT_ON_EMULATION_FAILURE is unavailable"); diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_features.c b/tools/t= esting/selftests/kvm/x86_64/hyperv_features.c index d5f37495ade8..f08f51bad68b 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_features.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_features.c @@ -161,7 +161,7 @@ static void hv_set_cpuid(struct kvm_vcpu *vcpu, struct = kvm_cpuid2 *cpuid, "failed to set HYPERV_CPUID_ENLIGHTMENT_INFO leaf"); TEST_ASSERT(set_cpuid(cpuid, dbg), "failed to set HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES leaf"); - vcpu_set_cpuid(vcpu, cpuid); + vcpu_init_cpuid(vcpu, cpuid); } =20 static void guest_test_msrs_access(void) diff --git a/tools/testing/selftests/kvm/x86_64/kvm_pv_test.c b/tools/testi= ng/selftests/kvm/x86_64/kvm_pv_test.c index 5901ccec7079..e3bb9b803944 100644 --- a/tools/testing/selftests/kvm/x86_64/kvm_pv_test.c +++ b/tools/testing/selftests/kvm/x86_64/kvm_pv_test.c @@ -200,7 +200,6 @@ static void enter_guest(struct kvm_vcpu *vcpu) =20 int main(void) { - struct kvm_cpuid2 *best; struct kvm_vcpu *vcpu; struct kvm_vm *vm; =20 @@ -210,9 +209,8 @@ int main(void) =20 vcpu_enable_cap(vcpu, KVM_CAP_ENFORCE_PV_FEATURE_CPUID, 1); =20 - best =3D kvm_get_supported_cpuid(); - clear_kvm_cpuid_features(best); - vcpu_set_cpuid(vcpu, best); + clear_kvm_cpuid_features(vcpu->cpuid); + vcpu_set_cpuid(vcpu); =20 vm_init_descriptor_tables(vm); vcpu_init_descriptor_tables(vcpu); diff --git a/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c= b/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c index 66cb2d0054e6..1cf78ec007f2 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c @@ -121,7 +121,7 @@ void test_vmx_nested_state(struct kvm_vcpu *vcpu) test_nested_state(vcpu, state); =20 /* Enable VMX in the guest CPUID. */ - vcpu_set_cpuid(vcpu, kvm_get_supported_cpuid()); + vcpu_set_cpuid(vcpu); =20 /* * Setting vmxon_pa =3D=3D -1ull and vmcs_pa =3D=3D -1ull exits early wit= hout @@ -245,7 +245,7 @@ void test_vmx_nested_state(struct kvm_vcpu *vcpu) =20 void disable_vmx(struct kvm_vcpu *vcpu) { - struct kvm_cpuid2 *cpuid =3D kvm_get_supported_cpuid(); + struct kvm_cpuid2 *cpuid =3D vcpu->cpuid; int i; =20 for (i =3D 0; i < cpuid->nent; ++i) @@ -255,7 +255,7 @@ void disable_vmx(struct kvm_vcpu *vcpu) TEST_ASSERT(i !=3D cpuid->nent, "CPUID function 1 not found"); =20 cpuid->entries[i].ecx &=3D ~CPUID_VMX; - vcpu_set_cpuid(vcpu, cpuid); + vcpu_set_cpuid(vcpu); cpuid->entries[i].ecx |=3D CPUID_VMX; } =20 diff --git a/tools/testing/selftests/kvm/x86_64/xapic_state_test.c b/tools/= testing/selftests/kvm/x86_64/xapic_state_test.c index 5c5dc7bbb4e2..7728730c2dda 100644 --- a/tools/testing/selftests/kvm/x86_64/xapic_state_test.c +++ b/tools/testing/selftests/kvm/x86_64/xapic_state_test.c @@ -138,13 +138,13 @@ int main(int argc, char *argv[]) vm =3D vm_create_with_one_vcpu(&x.vcpu, xapic_guest_code); x.is_x2apic =3D false; =20 - cpuid =3D vcpu_get_cpuid(x.vcpu); + cpuid =3D x.vcpu->cpuid; for (i =3D 0; i < cpuid->nent; i++) { if (cpuid->entries[i].function =3D=3D 1) break; } cpuid->entries[i].ecx &=3D ~BIT(21); - vcpu_set_cpuid(x.vcpu, cpuid); + vcpu_set_cpuid(x.vcpu); =20 virt_pg_map(vm, APIC_DEFAULT_GPA, APIC_DEFAULT_GPA); test_icr(&x); --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10C97CCA47D for ; Sat, 4 Jun 2022 01:23:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350173AbiFDBW5 (ORCPT ); Fri, 3 Jun 2022 21:22:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349994AbiFDBWT (ORCPT ); Fri, 3 Jun 2022 21:22:19 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8134930553 for ; Fri, 3 Jun 2022 18:21:47 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id om5-20020a17090b3a8500b001df42f1cbaaso8053683pjb.5 for ; Fri, 03 Jun 2022 18:21:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=IuS7bySLaWk96Nr3FGWjEQAo2Xsg0Uk+ZK8PKSv3jks=; b=tPq24DSwyTk5KSO20RDyya7f7yw8xQUbzDozzJsWDZxJdkHTLXmnATymku+8QAns/W fBwDfz9KAcO+cqN2Wssbg4VFRtfuMCunAJp5TfF3YqdBOjrzSP9et7q+PXF+TMU7LfLn X8tNemgrW3H4Q1z7f4pDazmxOgdWAcO0ctu1dcTWIlOIqS1G+WE3wB4YEH2mUzmf/7kR yBehsBBnSl5U5dxKH5v31h2gJQIFFZbtWlHJYPaVah7z+9fWXamR3GxfhwOFHzgMat1A ZimjzClQOBmacr7zPKTACaVruoD5OEPiZjgi3GNlJsZbhokfspa5ezz0wi2xECEYueDb Pyxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=IuS7bySLaWk96Nr3FGWjEQAo2Xsg0Uk+ZK8PKSv3jks=; b=UDTTh7LlJzDeXjAZvXzH3awWjXeSouVIzrQxr9RcdJFFrd11csJQq2Wd/W07Dfljeo pjk9bXDxcKk3BEJvpo+1kl6g0GLsX7W2/3JncunvKambNFkPhQJVUURvJ0DBGmnejmmc eivlkZiAs29YjQSfHVKab1DlQzBO7ZPfLJIMwigaHx7jo3lLHXEQ6ONcZn5bh6/eOSKC mwdA+2xKa/3HAt9A3ADyeArnVy0nQPKN0BZi0O2UPS2jrZGIDkEIhVTvVOCVVQ61pqMS FV58oXAMosg9kRnHFKROhe9HieAyeJaSiS4dbQL6h8UvXAjkWTpwA68JX/2XJ4shJymV i6OQ== X-Gm-Message-State: AOAM5334nUw8mnJaK974Fg8XP8zbMG7BURPC/LHYj6vqSVLdl5zI6fG3 wGon4cHo/AeZ3wEE6hUepioWH2ntsJs= X-Google-Smtp-Source: ABdhPJwuClwILqT2Dv4zyXmcPWZI77NL7R+wjQnwq488gAhRaMBLpiUAi+6R3tHak0WA/bKbmW7OOLU/6CM= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90a:178f:b0:1e3:3ba:c185 with SMTP id q15-20020a17090a178f00b001e303bac185mr4623pja.1.1654305693476; Fri, 03 Jun 2022 18:21:33 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:35 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-20-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 19/42] KVM: selftests: Don't use a static local in vcpu_get_supported_hv_cpuid() From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Don't use a static variable for the Hyper-V supported CPUID array, the helper unconditionally reallocates the array on every invocation (and all callers free the array immediately after use). The array is intentionally recreated and refilled because the set of supported CPUID features is dependent on vCPU state, e.g. whether or not eVMCS has been enabled. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/lib/x86_64/processor.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index c252c7463970..ae40ff426ad8 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1289,9 +1289,7 @@ void vcpu_set_hv_cpuid(struct kvm_vcpu *vcpu) =20 struct kvm_cpuid2 *vcpu_get_supported_hv_cpuid(struct kvm_vcpu *vcpu) { - static struct kvm_cpuid2 *cpuid; - - cpuid =3D allocate_kvm_cpuid2(MAX_NR_CPUID_ENTRIES); + struct kvm_cpuid2 *cpuid =3D allocate_kvm_cpuid2(MAX_NR_CPUID_ENTRIES); =20 vcpu_ioctl(vcpu, KVM_GET_SUPPORTED_HV_CPUID, cpuid); =20 --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E1ABC43334 for ; Sat, 4 Jun 2022 01:23:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350113AbiFDBXZ (ORCPT ); Fri, 3 Jun 2022 21:23:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350142AbiFDBWU (ORCPT ); Fri, 3 Jun 2022 21:22:20 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2585C2F016 for ; Fri, 3 Jun 2022 18:21:48 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2fb7bf98f1aso80707517b3.5 for ; Fri, 03 Jun 2022 18:21:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=DVDxR3/rPjapwoi40YmntTXgVr1EnJ/TXdlqXCtH5/M=; b=BL0gCNo37HVBu0UtgooziHLtHMQuT+ewg2OxZ2qfBDPI0Hfbxx8rW4MMtzA6RP2+8o U7swNEqPtyIYm99MOZKVYUPR4NeyFzPue8Pct4Zt719jQnzNoPtS1Hyuajvp9/jSKTJh lweoB476a0cKkod23VSI5mG+gQrJrCb2/IS7t8FiI6VlWAiY1CGv0e27XX5nou4xhOtT jIXjthpku/M6rKq56i1wDGYGEKLAMYg+ZfpQBJFjhYuu5uC/L5bnG/5NnAW+Nznsap+g 7YRHl68qM10ZQILCoEhVkiivMMioxe1dMJQMAQYqHbJZ+gyBmTJWc4XTkqMHkXkLEoRL ET3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=DVDxR3/rPjapwoi40YmntTXgVr1EnJ/TXdlqXCtH5/M=; b=4fjBWAYnbfAm5eC0qbmyiiEgoz7buFpot/28vcEe6CLeBy8WDEzwQk4Sepo3ohtyGQ ynQKPw4gF6ZHKz9xgOgqjFbeOdDM4bTH8DXUXfxlcLKiBUJF+zkr6PYsi3bLBeKczlo0 uHanagKca9tyrd9f6bld3Jk7IejYjm+V0IV+0JxwLUpOnqlVXv8SViEqvOyQWyVmyCvK FRaTbtRESs0EI9AbqeK3d+rQ3sFCJeonYXg8EeHgNsxe6pwbvQ7CFIDbMtGIZw6RkjRT oi+r/hm8clRoBsR+AXBO33XdPZRQdsm69+NjtcOb0RTBRMh8askKD7NgI6CjzUBxhiu2 e9tw== X-Gm-Message-State: AOAM530JgyRygELzVzcP0ZzD5Tr7Y4m95ScwnCeJD9fPYH9qvbMxLq/N W/JMh+kUqWUrSKoj5MFJomNIKmys34I= X-Google-Smtp-Source: ABdhPJy8aASDE5qPtj1QbthWSAtJneWEpm7sYMdxhfMXqhchEofuIi9Ww7pudDor9Z1AQ1oRMFg0pmjBd4U= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a81:260a:0:b0:300:1729:7654 with SMTP id m10-20020a81260a000000b0030017297654mr14142103ywm.125.1654305695249; Fri, 03 Jun 2022 18:21:35 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:36 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-21-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 20/42] KVM: selftests: Rename and tweak get_cpuid() to get_cpuid_entry() From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rename get_cpuid() to get_cpuid_entry() to better reflect its behavior. Leave set_cpuid() as is to avoid unnecessary churn, that helper will soon be removed entirely. Oppurtunistically tweak the implementation to avoid using a temporary variable in anticipation of taggin the input @cpuid with "const". No functional change intended. Signed-off-by: Sean Christopherson --- .../testing/selftests/kvm/include/x86_64/processor.h | 4 ++-- tools/testing/selftests/kvm/lib/x86_64/processor.c | 11 +++++------ tools/testing/selftests/kvm/x86_64/cpuid_test.c | 4 ++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index f170fd5f8726..fcfeac1590a2 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -692,8 +692,8 @@ void vm_set_page_table_entry(struct kvm_vm *vm, struct = kvm_vcpu *vcpu, /* * get_cpuid() - find matching CPUID entry and return pointer to it. */ -struct kvm_cpuid_entry2 *get_cpuid(struct kvm_cpuid2 *cpuid, uint32_t func= tion, - uint32_t index); +struct kvm_cpuid_entry2 *get_cpuid_entry(struct kvm_cpuid2 *cpuid, + uint32_t function, uint32_t index); /* * set_cpuid() - overwrites a matching cpuid entry with the provided value. * matches based on ent->function && ent->index. returns true diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index ae40ff426ad8..b481ad131ec6 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1191,16 +1191,15 @@ void assert_on_unhandled_exception(struct kvm_vcpu = *vcpu) } } =20 -struct kvm_cpuid_entry2 *get_cpuid(struct kvm_cpuid2 *cpuid, uint32_t func= tion, - uint32_t index) +struct kvm_cpuid_entry2 *get_cpuid_entry(struct kvm_cpuid2 *cpuid, + uint32_t function, uint32_t index) { int i; =20 for (i =3D 0; i < cpuid->nent; i++) { - struct kvm_cpuid_entry2 *cur =3D &cpuid->entries[i]; - - if (cur->function =3D=3D function && cur->index =3D=3D index) - return cur; + if (cpuid->entries[i].function =3D=3D function && + cpuid->entries[i].index =3D=3D index) + return &cpuid->entries[i]; } =20 TEST_FAIL("CPUID function 0x%x index 0x%x not found ", function, index); diff --git a/tools/testing/selftests/kvm/x86_64/cpuid_test.c b/tools/testin= g/selftests/kvm/x86_64/cpuid_test.c index ca36557646b0..8723d73dcdbd 100644 --- a/tools/testing/selftests/kvm/x86_64/cpuid_test.c +++ b/tools/testing/selftests/kvm/x86_64/cpuid_test.c @@ -157,7 +157,7 @@ static void set_cpuid_after_run(struct kvm_vcpu *vcpu) TEST_ASSERT(!rc, "Setting unmodified CPUID after KVM_RUN failed: %d", rc); =20 /* Changing CPU features is forbidden */ - ent =3D get_cpuid(cpuid, 0x7, 0); + ent =3D get_cpuid_entry(cpuid, 0x7, 0); ebx =3D ent->ebx; ent->ebx--; rc =3D __vcpu_set_cpuid(vcpu); @@ -165,7 +165,7 @@ static void set_cpuid_after_run(struct kvm_vcpu *vcpu) ent->ebx =3D ebx; =20 /* Changing MAXPHYADDR is forbidden */ - ent =3D get_cpuid(cpuid, 0x80000008, 0); + ent =3D get_cpuid_entry(cpuid, 0x80000008, 0); eax =3D ent->eax; x =3D eax & 0xff; ent->eax =3D (eax & ~0xffu) | (x - 1); --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B18E7C43334 for ; Sat, 4 Jun 2022 01:23:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232974AbiFDBXd (ORCPT ); Fri, 3 Jun 2022 21:23:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349972AbiFDBWe (ORCPT ); Fri, 3 Jun 2022 21:22:34 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 880ACF34 for ; Fri, 3 Jun 2022 18:21:49 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id y11-20020aa7804b000000b0051ba2c16046so4697726pfm.20 for ; Fri, 03 Jun 2022 18:21:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=MAb0VYGO01rN81APErjc83aRSpAeSVLJ6uKCqsMFyZY=; b=qpsSsrn3cRRFyGX9dQ2g3eQ7U+TOhp8sVQa+70aRvKIYEROHKd+hXl+qcCooaei1Hd Lde3KjSwHSkX8XXcrbC1ETlGPZ85wBictpfieWNWvVdzeAhy9/bTwrzWBUZq3JIGLB88 FWUF08J+ujHY6TjX0Rymq5vS0ftpEihSBKMV7b9t/+d9xwu9WRf0THSdEzg4Yccxvund HYYrBJ6JUT9IZ5fHlOspAYD5na7T/ZQ0LrSHJ/XPpaoHwlqI9KEuaNdlLouMxDDZyLje noZRLt/v2MMym4kJQOdriSsjYnpBsnkyRnASyRhqOfzFmKofr7xsbrlhUJ04CgwMQe8h Y1BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=MAb0VYGO01rN81APErjc83aRSpAeSVLJ6uKCqsMFyZY=; b=KU8VEUSDYKK8FAbSyTNu31rh5b3X2oYt++ReJ24rMlpTJZOykYkFuFJgN270IIvseo ViTJ3WhDGEcBU3ykseqPmGPrOe3/pE+gUxsYLt3AJEm6aN3o+LzNw0kKPqKMYCEZHOsu ubrlZzRipCekfbKd9VHk0QULIFEic0N+8E51OWzkW59479ym+MqETygqdvbkV9UVE5Ui 9NTARuTnPQ5S38PWq/iV6BC+70iTx3ktAoiYNXu8Xf4qkVVowqYq9He0LeMs8kKDrE2q tMA7aOF2A7JRAebIeQmFNl6rGS2nW4yGbnzgWUyZYoqwp3iQF5RdinSfOnF/eYhVZ0g6 HRmg== X-Gm-Message-State: AOAM531kkRee3tSICZI0Coe4Cbx0zujHFK9CSyNoDfBm0alElPoOr9Ya n4rAanqoQX0cZAQCcepAPfG0ChXHVIw= X-Google-Smtp-Source: ABdhPJwKqHsT6cTlMWKkXMg8RInDXfL66prXk3gNx7J5qEL3rOLKVQ9GiTgjGXA1ctgIMLxxMrfrKTX6cNs= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90b:3b88:b0:1e6:7aa2:4301 with SMTP id pc8-20020a17090b3b8800b001e67aa24301mr13726686pjb.118.1654305696863; Fri, 03 Jun 2022 18:21:36 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:37 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-22-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 21/42] KVM: selftests: Use get_cpuid_entry() in kvm_get_supported_cpuid_index() From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use get_cpuid_entry() in kvm_get_supported_cpuid_index() to replace functionally identical code. Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/x86_64/processor.h | 14 ++++---- .../selftests/kvm/lib/x86_64/processor.c | 32 ------------------- 2 files changed, 7 insertions(+), 39 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index fcfeac1590a2..e43a1d2fd112 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -616,6 +616,8 @@ static inline struct kvm_cpuid2 *allocate_kvm_cpuid2(in= t nr_entries) return cpuid; } =20 +struct kvm_cpuid_entry2 *get_cpuid_entry(struct kvm_cpuid2 *cpuid, + uint32_t function, uint32_t index); void vcpu_init_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid); =20 static inline int __vcpu_set_cpuid(struct kvm_vcpu *vcpu) @@ -641,8 +643,11 @@ static inline void vcpu_set_cpuid(struct kvm_vcpu *vcp= u) vcpu_ioctl(vcpu, KVM_GET_CPUID2, vcpu->cpuid); } =20 -struct kvm_cpuid_entry2 * -kvm_get_supported_cpuid_index(uint32_t function, uint32_t index); +static inline struct kvm_cpuid_entry2 *kvm_get_supported_cpuid_index(uint3= 2_t function, + uint32_t index) +{ + return get_cpuid_entry(kvm_get_supported_cpuid(), function, index); +} =20 static inline struct kvm_cpuid_entry2 * kvm_get_supported_cpuid_entry(uint32_t function) @@ -689,11 +694,6 @@ uint64_t vm_get_page_table_entry(struct kvm_vm *vm, st= ruct kvm_vcpu *vcpu, void vm_set_page_table_entry(struct kvm_vm *vm, struct kvm_vcpu *vcpu, uint64_t vaddr, uint64_t pte); =20 -/* - * get_cpuid() - find matching CPUID entry and return pointer to it. - */ -struct kvm_cpuid_entry2 *get_cpuid_entry(struct kvm_cpuid2 *cpuid, - uint32_t function, uint32_t index); /* * set_cpuid() - overwrites a matching cpuid entry with the provided value. * matches based on ent->function && ent->index. returns true diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index b481ad131ec6..a835a63a6924 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -767,38 +767,6 @@ void vcpu_init_cpuid(struct kvm_vcpu *vcpu, struct kvm= _cpuid2 *cpuid) vcpu_set_cpuid(vcpu); } =20 -/* - * Locate a cpuid entry. - * - * Input Args: - * function: The function of the cpuid entry to find. - * index: The index of the cpuid entry. - * - * Output Args: None - * - * Return: A pointer to the cpuid entry. Never returns NULL. - */ -struct kvm_cpuid_entry2 * -kvm_get_supported_cpuid_index(uint32_t function, uint32_t index) -{ - struct kvm_cpuid2 *cpuid; - struct kvm_cpuid_entry2 *entry =3D NULL; - int i; - - cpuid =3D kvm_get_supported_cpuid(); - for (i =3D 0; i < cpuid->nent; i++) { - if (cpuid->entries[i].function =3D=3D function && - cpuid->entries[i].index =3D=3D index) { - entry =3D &cpuid->entries[i]; - break; - } - } - - TEST_ASSERT(entry, "Guest CPUID entry not found: (EAX=3D%x, ECX=3D%x).", - function, index); - return entry; -} - uint64_t vcpu_get_msr(struct kvm_vcpu *vcpu, uint64_t msr_index) { struct { --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A123EC43334 for ; Sat, 4 Jun 2022 01:23:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350273AbiFDBXI (ORCPT ); Fri, 3 Jun 2022 21:23:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350143AbiFDBWU (ORCPT ); Fri, 3 Jun 2022 21:22:20 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8310FE94 for ; Fri, 3 Jun 2022 18:21:51 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id e19-20020aa79813000000b0051bba91468eso4107507pfl.14 for ; Fri, 03 Jun 2022 18:21:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=J6Ssq79acMaaHSiEP1fKlZ6/Du4B3+2P34aFf+DVOyk=; b=eup/4YoWpFBQgsbyvL1RBm8gYMRPBqN+mF0/+t4VR2laZgangtnClvcdqtTRowypVr 5c3cbSP2WyGJywo2s+yVZuxL3L91zt5jXe+LXYYy2Yowe0ecDXX8BywnX7AVtRbscRyG n4hqpT3RHXllPMeQA00uprQ6g6Hrc95RgIqnLsAGEVMBBG06DRH0xApUNuhiK5sLB/Mi PylsbDEA9MvzZXrb1yud6cW9BoRILBQLWD28SDXb1aOEo5ibwTexiY/zpkkt9xE/vKj/ F5JSg859sheEtk1OwrJiFn1FwXqgd20bkMCB9kKLqQ+12lJid+ts0lx94jRTV6i/BC4D a4Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=J6Ssq79acMaaHSiEP1fKlZ6/Du4B3+2P34aFf+DVOyk=; b=SWIdYPEkm0LJ6AZBfxbGxBJ63AT364a6lWGLRWriOMNnpDgetE001qnT78pToBywkk fJpaZnZ6YFaffDQkxKQzDDxJ9oDf7bE4uYNgKoC+OspfCN0/qy9mo0JElVjuImgCloDd zVGre2VVG1GyiczdytVVQWVMxJ72Nsm22upvS+++0BnNBAnX639naEw/MOI37FJ9r68M xVL5sLdc1hOMlTbG6gR2EP8iW4PwJRw5cA4TQXkHHXcSlfvRWMb2CvSmPTKvptlfW/rO ky+rJ1jLO/zgmKQ10X94qUdwVPttM9xVkmm+iAGb44WskSq3wemyfJq1h8edGTYeU/+A qA0Q== X-Gm-Message-State: AOAM531EAkflQz4931UJR1QXZs35CRnfAHbYKCXIKt0DRX4Qrn58mR1t GbQ1Y8Pnj1nS6oi5s5AF+lwfDJcBIoM= X-Google-Smtp-Source: ABdhPJzzsQjp/JmEChEQM0LBdDCcCp5vkf2dT8tnLgc2Dk3PG4pSi3SprpNSLj/fr4U88iACAb5HqK4LwQQ= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6a00:319b:b0:51b:c5ec:62ba with SMTP id bj27-20020a056a00319b00b0051bc5ec62bamr11398270pfb.1.1654305698761; Fri, 03 Jun 2022 18:21:38 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:38 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-23-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 22/42] KVM: selftests: Add helpers to get and modify a vCPU's CPUID entries From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add helpers to get a specific CPUID entry for a given vCPU, and to toggle a specific CPUID-based feature for a vCPU. The helpers will reduce the amount of boilerplate code needed to tweak a vCPU's CPUID model, improve code clarity, and most importantly move tests away from modifying the static "cpuid" returned by kvm_get_supported_cpuid(). Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/x86_64/processor.h | 30 +++++++++++++++++++ .../selftests/kvm/lib/x86_64/processor.c | 18 +++++++++++ 2 files changed, 48 insertions(+) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index e43a1d2fd112..61b8047243e0 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -620,6 +620,19 @@ struct kvm_cpuid_entry2 *get_cpuid_entry(struct kvm_cp= uid2 *cpuid, uint32_t function, uint32_t index); void vcpu_init_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid); =20 +static inline struct kvm_cpuid_entry2 *__vcpu_get_cpuid_entry(struct kvm_v= cpu *vcpu, + uint32_t function, + uint32_t index) +{ + return get_cpuid_entry(vcpu->cpuid, function, index); +} + +static inline struct kvm_cpuid_entry2 *vcpu_get_cpuid_entry(struct kvm_vcp= u *vcpu, + uint32_t function) +{ + return __vcpu_get_cpuid_entry(vcpu, function, 0); +} + static inline int __vcpu_set_cpuid(struct kvm_vcpu *vcpu) { int r; @@ -643,6 +656,23 @@ static inline void vcpu_set_cpuid(struct kvm_vcpu *vcp= u) vcpu_ioctl(vcpu, KVM_GET_CPUID2, vcpu->cpuid); } =20 +void vcpu_set_or_clear_cpuid_feature(struct kvm_vcpu *vcpu, + struct kvm_x86_cpu_feature feature, + bool set); + +static inline void vcpu_set_cpuid_feature(struct kvm_vcpu *vcpu, + struct kvm_x86_cpu_feature feature) +{ + vcpu_set_or_clear_cpuid_feature(vcpu, feature, true); + +} + +static inline void vcpu_clear_cpuid_feature(struct kvm_vcpu *vcpu, + struct kvm_x86_cpu_feature feature) +{ + vcpu_set_or_clear_cpuid_feature(vcpu, feature, false); +} + static inline struct kvm_cpuid_entry2 *kvm_get_supported_cpuid_index(uint3= 2_t function, uint32_t index) { diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index a835a63a6924..6c21893f5038 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -767,6 +767,24 @@ void vcpu_init_cpuid(struct kvm_vcpu *vcpu, struct kvm= _cpuid2 *cpuid) vcpu_set_cpuid(vcpu); } =20 +void vcpu_set_or_clear_cpuid_feature(struct kvm_vcpu *vcpu, + struct kvm_x86_cpu_feature feature, + bool set) +{ + struct kvm_cpuid_entry2 *entry; + u32 *reg; + + entry =3D __vcpu_get_cpuid_entry(vcpu, feature.function, feature.index); + reg =3D (&entry->eax) + feature.reg; + + if (set) + *reg |=3D BIT(feature.bit); + else + *reg &=3D ~BIT(feature.bit); + + vcpu_set_cpuid(vcpu); +} + uint64_t vcpu_get_msr(struct kvm_vcpu *vcpu, uint64_t msr_index) { struct { --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05239C433EF for ; Sat, 4 Jun 2022 01:23:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350246AbiFDBX2 (ORCPT ); Fri, 3 Jun 2022 21:23:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346233AbiFDBWd (ORCPT ); Fri, 3 Jun 2022 21:22:33 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DC46B1C for ; Fri, 3 Jun 2022 18:21:53 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id q13-20020a65624d000000b003fa74c57243so4559900pgv.19 for ; Fri, 03 Jun 2022 18:21:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=fEtaJeNPMLGJ/eGkpGlOpofTkW2QGNDDuGU/ZlXwm9s=; b=PWUuQyFQ0cb3xfkqq4zlJ7Oad3BKjmzjKlg31Ey4NS/AnNeLSb3E8qehZAMYcH7XCY 74xj8JWZPd0FH4w+79Mxohjo9stx9NZNG9QDok8L7RpnBOS0wBks6cEkHCNIflkEB6+4 82DfnKCLW490G/Gk9UAE0spgsnxs0vfNZ2QxUF5UfGMUUTxMxigCTC6rx2xbrgchNkN6 rM1GkVmZKVUQ5/nQCXKLQ+OhgSCHschbjC+BZ2O8YQDn4dhv6guu/DxjZsFIY+MDgF0L liIOYoHqZC+fDXAUcC3xGQaQTemTWN7IgS9Vj1i4+05psSeGqAymYJG2329//7OTh0EO QOgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=fEtaJeNPMLGJ/eGkpGlOpofTkW2QGNDDuGU/ZlXwm9s=; b=r/ExJcjxu8zm+0AP1TgqL0D7srFFVapX1fBozGm4ekcWpXJsl2aXtrA15SDSWxyKN+ OwNwyGM7+RAB1WDuZKSyDAn1VW1y3VQe6/V0T+f7TZZtHq+o6LIal8h/yAKKVhaBtuPD gIH5avs7mJZ/nQy0u4WFHOw3Y9mUjlZiSBcTvknEBK437qhpinyUg2m5C+pSVwog6te1 u8csvSk2kVvmkgkGsk7LzbnlpgJtiH43t3GfXWvxk73+XBmK0lRTLaBpOyGLM/N5RXgk cDsgauy81gN75Il/XTft81+HrubtPnMqCsSo+Q81HX/CguBuoQVrW4GuXgM6qEBRf8AK IlGw== X-Gm-Message-State: AOAM531A04lfL71P4GDbYFc4o83HJ4A5XBRP9Gvpg7jZ2FXnV9XUP3q+ eDlHMhZfuIju6RbOH3tXf3iZTZIm9vU= X-Google-Smtp-Source: ABdhPJw7a5VWey3nupaM34wl9wZIoJpZ3nkG6SpJ2KXXyR7kAHtXZyRbej3UxyVdSXlQ3l687VNltPilckU= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:b58c:b0:163:920c:6164 with SMTP id a12-20020a170902b58c00b00163920c6164mr12927685pls.58.1654305700533; Fri, 03 Jun 2022 18:21:40 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:39 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-24-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 23/42] KVM: selftests: Use vm->pa_bits to generate reserved PA bits From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use vm->pa_bits to generate the mask of physical address bits that are reserved in page table entries. vm->pa_bits is set when the VM is created, i.e. it's guaranteed to be valid when populating page tables. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/lib/x86_64/processor.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index 6c21893f5038..5383ccdeb8e2 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -222,16 +222,12 @@ static uint64_t *_vm_get_page_table_entry(struct kvm_= vm *vm, uint16_t index[4]; uint64_t *pml4e, *pdpe, *pde; uint64_t *pte; - struct kvm_cpuid_entry2 *entry; struct kvm_sregs sregs; - int max_phy_addr; uint64_t rsvd_mask =3D 0; =20 - entry =3D kvm_get_supported_cpuid_index(0x80000008, 0); - max_phy_addr =3D entry->eax & 0x000000ff; /* Set the high bits in the reserved mask. */ - if (max_phy_addr < 52) - rsvd_mask =3D GENMASK_ULL(51, max_phy_addr); + if (vm->pa_bits < 52) + rsvd_mask =3D GENMASK_ULL(51, vm->pa_bits); =20 /* * SDM vol 3, fig 4-11 "Formats of CR3 and Paging-Structure Entries --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DD92C43334 for ; Sat, 4 Jun 2022 01:23:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350018AbiFDBXD (ORCPT ); Fri, 3 Jun 2022 21:23:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350175AbiFDBWd (ORCPT ); Fri, 3 Jun 2022 21:22:33 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5777231D for ; Fri, 3 Jun 2022 18:21:54 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id x1-20020a170902ec8100b0016634ff72a4so4106416plg.15 for ; Fri, 03 Jun 2022 18:21:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=BQRfL0mcKRLOvZlHcCsiY1NJyzCw53bZY+TKm1ziE0s=; b=tjVtRaKDo0BEgyFGm+IZYnF4c+4jP1xVcbJ66WWUeZGoc5NuSTaNvgexhmX5pWbEWW Zf3PJ/De7Xj/BnPZz/U6Q3Q1SGT/IgQsKRa8YQEpIzhJ1oZGhXyBj6y9Mzl6Za6/fRC+ R5X/zzAUTS+T52MKM3U2hkVGNrcUwkKv/2sTmc4Lw0pmNqro/lJ8uQ6c5T+G07geNRky NN6Yssh/O52Gob70HgpjB+Ox67/pvFI9+wY7WkZjXpV4dfZlHx1DIqqH41nVtOHrWJF9 xiIsXfEwtYhuRpnttanw7QCqcrkFldug2Y4v+aImITbur4H7BNnNIvnpdxtr6fWXI7oD rfWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=BQRfL0mcKRLOvZlHcCsiY1NJyzCw53bZY+TKm1ziE0s=; b=uChZlFyadbeW7VdKtXf1iL/ZjNoaKjXQ0c/yDAVRU4yjTJ2SFnCrkAsCKwUPTUskkP ZssooNkt66fg2iemLtVWWIEbMz6yJcWnGB3jMXDUMHdGdG5IPJvvqPNtBiCJnwFYeD2m SXs4PsNO/uH3EFvrbu8YDC1zE+pjgFN+8UR5ys7a4GZPhNSy5LVQfGSmAXwIRy5oSigh 3c7vUH/XnhykWODAFUZHp008Rrlb316OAP6F2ge1mQdJGH4P+W6PUY5zMLVdMA1ANG5N CNmNDVRUiL1cqa+46b/8UyTUZqTMEcSIgvmoExVsJ7Ez8KVZLTUPQ2ffJs3EpeFxCXfb rvRQ== X-Gm-Message-State: AOAM530E04o3MaqrO92S++mJJqxHHM4ICXEGiT5/aWQsw9rg5aD6oqx/ bcRWiI2nFRsQM2VyyjBQXkLsxnmOhxk= X-Google-Smtp-Source: ABdhPJz36R8MRDTsFSI4sOua56XcUrbw7Bk751Wtkbo+spsn+gfYei04OSuvnUr1yLvEPaN6mdbD3T3wciM= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:e788:b0:163:73fc:5140 with SMTP id cp8-20020a170902e78800b0016373fc5140mr12462386plb.88.1654305702378; Fri, 03 Jun 2022 18:21:42 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:40 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-25-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 24/42] KVM: selftests: Add and use helper to set vCPU's CPUID maxphyaddr From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a helper to set a vCPU's guest.MAXPHYADDR, and use it in the test that verifies the emulator returns an error on an unknown instruction when KVM emulates in response to an EPT violation with a GPA that is legal in hardware but illegal with respect to the guest's MAXPHYADDR. Add a helper even though there's only a single user at this time. Before its removal, mmu_role_test also stuffed guest.MAXPHYADDR, and the helper provides a small amount of clarity. More importantly, this eliminates a set_cpuid() user and an instance of modifying kvm_get_supported_cpuid()'s static "cpuid". Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/x86_64/processor.h | 2 ++ tools/testing/selftests/kvm/lib/x86_64/processor.c | 8 ++++++++ .../testing/selftests/kvm/x86_64/emulator_error_test.c | 10 +--------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index 61b8047243e0..d6ffd625513b 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -656,6 +656,8 @@ static inline void vcpu_set_cpuid(struct kvm_vcpu *vcpu) vcpu_ioctl(vcpu, KVM_GET_CPUID2, vcpu->cpuid); } =20 +void vcpu_set_cpuid_maxphyaddr(struct kvm_vcpu *vcpu, uint8_t maxphyaddr); + void vcpu_set_or_clear_cpuid_feature(struct kvm_vcpu *vcpu, struct kvm_x86_cpu_feature feature, bool set); diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index 5383ccdeb8e2..06ae7542f2c9 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -763,6 +763,14 @@ void vcpu_init_cpuid(struct kvm_vcpu *vcpu, struct kvm= _cpuid2 *cpuid) vcpu_set_cpuid(vcpu); } =20 +void vcpu_set_cpuid_maxphyaddr(struct kvm_vcpu *vcpu, uint8_t maxphyaddr) +{ + struct kvm_cpuid_entry2 *entry =3D vcpu_get_cpuid_entry(vcpu, 0x80000008); + + entry->eax =3D (entry->eax & ~0xff) | maxphyaddr; + vcpu_set_cpuid(vcpu); +} + void vcpu_set_or_clear_cpuid_feature(struct kvm_vcpu *vcpu, struct kvm_x86_cpu_feature feature, bool set) diff --git a/tools/testing/selftests/kvm/x86_64/emulator_error_test.c b/too= ls/testing/selftests/kvm/x86_64/emulator_error_test.c index bb410c359599..9d08ccdf6604 100644 --- a/tools/testing/selftests/kvm/x86_64/emulator_error_test.c +++ b/tools/testing/selftests/kvm/x86_64/emulator_error_test.c @@ -151,8 +151,6 @@ static uint64_t process_ucall(struct kvm_vcpu *vcpu) =20 int main(int argc, char *argv[]) { - struct kvm_cpuid_entry2 *entry; - struct kvm_cpuid2 *cpuid; struct kvm_vcpu *vcpu; struct kvm_vm *vm; uint64_t gpa, pte; @@ -166,13 +164,7 @@ int main(int argc, char *argv[]) =20 vm =3D vm_create_with_one_vcpu(&vcpu, guest_code); =20 - cpuid =3D kvm_get_supported_cpuid(); - - entry =3D kvm_get_supported_cpuid_index(0x80000008, 0); - entry->eax =3D (entry->eax & 0xffffff00) | MAXPHYADDR; - set_cpuid(cpuid, entry); - - vcpu_init_cpuid(vcpu, cpuid); + vcpu_set_cpuid_maxphyaddr(vcpu, MAXPHYADDR); =20 rc =3D kvm_check_cap(KVM_CAP_EXIT_ON_EMULATION_FAILURE); TEST_ASSERT(rc, "KVM_CAP_EXIT_ON_EMULATION_FAILURE is unavailable"); --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6C0DC43334 for ; Sat, 4 Jun 2022 01:23:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239658AbiFDBXk (ORCPT ); Fri, 3 Jun 2022 21:23:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350198AbiFDBWf (ORCPT ); Fri, 3 Jun 2022 21:22:35 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34580B7FC for ; Fri, 3 Jun 2022 18:21:58 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-310061f47faso37421967b3.9 for ; Fri, 03 Jun 2022 18:21:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=TSkVw4BUWTj8GnGnzmYwA+VpLXiJcJCvkpVGmnLW8To=; b=i3GCfCF9cF6KmfY5ipXnOirz5jXw5qSn7RwKoi8EFHkW+so9Yx2YUsUHg9RYTUvDa/ CTNUIQx8pHxGVah5Pbj2uP9yUUs1eP2khoRC1IlI6Svl5ZxMT96NT50o9RzOjA6e+QuI SAXnYBUhqF+f+2cmZLPNwCYwMbN7eZ2KScHLJfq+l/vj0lAH1aJdo7vbxAWxYHLog5MK mHjaGvDwaU7Sh0onpM9tKjlC0Bwlmyz0fBXm6alkyrsNGM/j81ivZ+Vq93IJNZr7WIsx KfKbvCJomVIsBS2z5q3pWcV6WHsaeIZNSG3CPGJuhC9gDEYWtJt/EPwjBNEYqXwvt/y6 xDQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=TSkVw4BUWTj8GnGnzmYwA+VpLXiJcJCvkpVGmnLW8To=; b=W8u0kClM9dd3ZQr9wE3dShBdKwywTUjtxsg4irUaeO3Q/Y3jxlHmYQ01HN1Tfz7N/C 9cHS7fAAMhi981ihuhvAsAJrNc1IGFgt3WtWPYGdTIsM3XyMOYDJq0CFX7rc6Ench1KY BYWbocJXDyazt+7DQBFVfYYM+jzrtd2vXLp2H69yeQuIdprER1kM+3SumyZ7mbcQ5Ipy TORINT9DAP48QbGsTZzprnirIcNjmbzm4FhVBeTUbpuO+Hj7U5nVNUvr1bfnQZaj1CF+ K5R9tK06KxtzCLJb1abbgqKvqSV0P9sK2Yn5LFnTWOcAdIDYHZwUuAYHPoEy5OYJjYKn lHbg== X-Gm-Message-State: AOAM5336K9WuPJHbTvTThT5umN/D13aQopKRg0sZlNoo8MbYZaXyP/G2 b5HQ2i69j1vNN4DWa3rgWOeR2ALHfgk= X-Google-Smtp-Source: ABdhPJykVyZvNZtFVywiMyWJdipP4t0W0zyr/Vs1qk6OM7OzoVxIog9RBbk5wrx54Jyb83t/EiFqC1ZGwyk= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a25:4c6:0:b0:65c:9e2f:f51 with SMTP id 189-20020a2504c6000000b0065c9e2f0f51mr13696865ybe.11.1654305704251; Fri, 03 Jun 2022 18:21:44 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:41 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-26-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 25/42] KVM: selftests: Use vcpu_get_cpuid_entry() in PV features test (sort of) From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a new helper, vcpu_clear_cpuid_entry(), to do a RMW operation on the vCPU's CPUID model to clear a given CPUID entry, and use it to clear KVM's paravirt feature instead of operating on kvm_get_supported_cpuid()'s static "cpuid" variable. This also eliminates a user of the soon-be-defunct set_cpuid() helper. Signed-off-by: Sean Christopherson --- .../testing/selftests/kvm/include/x86_64/processor.h | 1 + tools/testing/selftests/kvm/lib/x86_64/processor.c | 11 +++++++++++ tools/testing/selftests/kvm/x86_64/kvm_pv_test.c | 12 +----------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index d6ffd625513b..22e2eaf42360 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -658,6 +658,7 @@ static inline void vcpu_set_cpuid(struct kvm_vcpu *vcpu) =20 void vcpu_set_cpuid_maxphyaddr(struct kvm_vcpu *vcpu, uint8_t maxphyaddr); =20 +void vcpu_clear_cpuid_entry(struct kvm_vcpu *vcpu, uint32_t function); void vcpu_set_or_clear_cpuid_feature(struct kvm_vcpu *vcpu, struct kvm_x86_cpu_feature feature, bool set); diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index 06ae7542f2c9..69239b3613f7 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -771,6 +771,17 @@ void vcpu_set_cpuid_maxphyaddr(struct kvm_vcpu *vcpu, = uint8_t maxphyaddr) vcpu_set_cpuid(vcpu); } =20 +void vcpu_clear_cpuid_entry(struct kvm_vcpu *vcpu, uint32_t function) +{ + struct kvm_cpuid_entry2 *entry =3D vcpu_get_cpuid_entry(vcpu, function); + + entry->eax =3D 0; + entry->ebx =3D 0; + entry->ecx =3D 0; + entry->edx =3D 0; + vcpu_set_cpuid(vcpu); +} + void vcpu_set_or_clear_cpuid_feature(struct kvm_vcpu *vcpu, struct kvm_x86_cpu_feature feature, bool set) diff --git a/tools/testing/selftests/kvm/x86_64/kvm_pv_test.c b/tools/testi= ng/selftests/kvm/x86_64/kvm_pv_test.c index e3bb9b803944..7ab61f3f2a20 100644 --- a/tools/testing/selftests/kvm/x86_64/kvm_pv_test.c +++ b/tools/testing/selftests/kvm/x86_64/kvm_pv_test.c @@ -142,15 +142,6 @@ static void guest_main(void) GUEST_DONE(); } =20 -static void clear_kvm_cpuid_features(struct kvm_cpuid2 *cpuid) -{ - struct kvm_cpuid_entry2 ent =3D {0}; - - ent.function =3D KVM_CPUID_FEATURES; - TEST_ASSERT(set_cpuid(cpuid, &ent), - "failed to clear KVM_CPUID_FEATURES leaf"); -} - static void pr_msr(struct ucall *uc) { struct msr_data *msr =3D (struct msr_data *)uc->args[0]; @@ -209,8 +200,7 @@ int main(void) =20 vcpu_enable_cap(vcpu, KVM_CAP_ENFORCE_PV_FEATURE_CPUID, 1); =20 - clear_kvm_cpuid_features(vcpu->cpuid); - vcpu_set_cpuid(vcpu); + vcpu_clear_cpuid_entry(vcpu, KVM_CPUID_FEATURES); =20 vm_init_descriptor_tables(vm); vcpu_init_descriptor_tables(vcpu); --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4FACFC43334 for ; Sat, 4 Jun 2022 01:24:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350275AbiFDBX6 (ORCPT ); Fri, 3 Jun 2022 21:23:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350226AbiFDBWw (ORCPT ); Fri, 3 Jun 2022 21:22:52 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98C1E13F1E for ; Fri, 3 Jun 2022 18:22:01 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id q12-20020a056a0002ac00b0051bb2e66c91so4583031pfs.4 for ; Fri, 03 Jun 2022 18:22:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=C53+Egq7YgeyPc3n0sW99y912mVxgbiYdI3cg6bBp3Y=; b=YQ35grmHKogo6yHynJeqazwUVXYivB7A7lM1euznZIPJ1nYUpn6qMs29JHsaZUK+WV T6vYhuIYqNPDzlVfYWE3s/74hkO4+BzxGcmQfmAzje2XAIyB4ogYUQqlwkpvvmpiBSex X2PNMeFVFxNvDWMiEMyAlh72iP6vhHi2IJnh6vMnyucF2UXwFJV0LjQ/jmmPOvyiAo7S Q3+bmolDurEEG10vlRHMUQbbaJxVa9umVVewmZtXsNLPNOI2MTtFRKUsG1Up16e0SntQ 4NN2s0MBc2zDucN94t8hPVPXkcdMPRYU1zX4BMpztnJ1KcKbv2wOGwu8FJvfzqXtxAgw Iqxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=C53+Egq7YgeyPc3n0sW99y912mVxgbiYdI3cg6bBp3Y=; b=jr709kELSPuAU/C33a/K/acVcqJa88uoBzVuCVO57ZKhjPZt/rT8HcZBBcBJwT1sua SWXz9kTJ1dAhm9Nbgqo4PIxK+8508l/HXZ2yi/+fliaAydvJIQgtqdqNr0A7NVxrzIMB 0zhktFzJLNN9zpnSzY2UosKrHeGfAiBxFWzgJawbDKZqVmC/s68SNOeP039ai2RZmvQv oGRlC9h1HSgZxNYGoVb2DjHohr+V0y+Jzg/VnADcxD9HqLfV4dT8WD5hPqh0UDlXzSJS Fom2JDKkPSL9bKJ3C3ANd7WLv/wHGGk+blHPXE5Q17zPfInd18Wnrsk+P/zaKNwdP9HR ZwSg== X-Gm-Message-State: AOAM53344ojNpI2CuCbFnpMg7BHry0kUMIBAqxlLhn/fnrJipo6B76Lr /AnyA/f9/svKQADnq/35QRr5kW4XowE= X-Google-Smtp-Source: ABdhPJwoVZ/DfpEUafi7wNXwlwv+xcp9j6CMW2CRh+7EtyfsPfWQBXF5IfKjniLizsErHWXtVP3JFE0v0Sk= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a63:1c5c:0:b0:3fc:109e:8386 with SMTP id c28-20020a631c5c000000b003fc109e8386mr11290697pgm.133.1654305706289; Fri, 03 Jun 2022 18:21:46 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:42 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-27-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 26/42] KVM: selftests: Use vCPU's CPUID directly in Hyper-V test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the vCPU's persistent CPUID array directly when manipulating the set of exposed Hyper-V CPUID features. Drop set_cpuid() to route all future modification through the vCPU helpers; the Hyper-V features test was the last user. Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/x86_64/processor.h | 9 -- .../selftests/kvm/lib/x86_64/processor.c | 18 --- .../selftests/kvm/x86_64/hyperv_features.c | 126 +++++++++--------- 3 files changed, 64 insertions(+), 89 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index 22e2eaf42360..b9b3a19895aa 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -727,15 +727,6 @@ uint64_t vm_get_page_table_entry(struct kvm_vm *vm, st= ruct kvm_vcpu *vcpu, void vm_set_page_table_entry(struct kvm_vm *vm, struct kvm_vcpu *vcpu, uint64_t vaddr, uint64_t pte); =20 -/* - * set_cpuid() - overwrites a matching cpuid entry with the provided value. - * matches based on ent->function && ent->index. returns true - * if a match was found and successfully overwritten. - * @cpuid: the kvm cpuid list to modify. - * @ent: cpuid entry to insert - */ -bool set_cpuid(struct kvm_cpuid2 *cpuid, struct kvm_cpuid_entry2 *ent); - uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2, uint64_t a3); =20 diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index 69239b3613f7..1812b14de3dd 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1208,24 +1208,6 @@ struct kvm_cpuid_entry2 *get_cpuid_entry(struct kvm_= cpuid2 *cpuid, return NULL; } =20 -bool set_cpuid(struct kvm_cpuid2 *cpuid, - struct kvm_cpuid_entry2 *ent) -{ - int i; - - for (i =3D 0; i < cpuid->nent; i++) { - struct kvm_cpuid_entry2 *cur =3D &cpuid->entries[i]; - - if (cur->function !=3D ent->function || cur->index !=3D ent->index) - continue; - - memcpy(cur, ent, sizeof(struct kvm_cpuid_entry2)); - return true; - } - - return false; -} - uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2, uint64_t a3) { diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_features.c b/tools/t= esting/selftests/kvm/x86_64/hyperv_features.c index f08f51bad68b..3d0df079496b 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_features.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_features.c @@ -150,37 +150,28 @@ static void guest_hcall(vm_vaddr_t pgs_gpa, struct hc= all_data *hcall) GUEST_DONE(); } =20 -static void hv_set_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid, - struct kvm_cpuid_entry2 *feat, - struct kvm_cpuid_entry2 *recomm, - struct kvm_cpuid_entry2 *dbg) +static void vcpu_reset_hv_cpuid(struct kvm_vcpu *vcpu) { - TEST_ASSERT(set_cpuid(cpuid, feat), - "failed to set KVM_CPUID_FEATURES leaf"); - TEST_ASSERT(set_cpuid(cpuid, recomm), - "failed to set HYPERV_CPUID_ENLIGHTMENT_INFO leaf"); - TEST_ASSERT(set_cpuid(cpuid, dbg), - "failed to set HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES leaf"); - vcpu_init_cpuid(vcpu, cpuid); + /* + * Enable all supported Hyper-V features, then clear the leafs holding + * the features that will be tested one by one. + */ + vcpu_set_hv_cpuid(vcpu); + + vcpu_clear_cpuid_entry(vcpu, HYPERV_CPUID_FEATURES); + vcpu_clear_cpuid_entry(vcpu, HYPERV_CPUID_ENLIGHTMENT_INFO); + vcpu_clear_cpuid_entry(vcpu, HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES); } =20 static void guest_test_msrs_access(void) { + struct kvm_cpuid2 *prev_cpuid =3D NULL; + struct kvm_cpuid_entry2 *feat, *dbg; struct kvm_vcpu *vcpu; struct kvm_run *run; struct kvm_vm *vm; struct ucall uc; int stage =3D 0; - struct kvm_cpuid_entry2 feat =3D { - .function =3D HYPERV_CPUID_FEATURES - }; - struct kvm_cpuid_entry2 recomm =3D { - .function =3D HYPERV_CPUID_ENLIGHTMENT_INFO - }; - struct kvm_cpuid_entry2 dbg =3D { - .function =3D HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES - }; - struct kvm_cpuid2 *best; vm_vaddr_t msr_gva; struct msr_data *msr; =20 @@ -194,9 +185,16 @@ static void guest_test_msrs_access(void) vcpu_args_set(vcpu, 1, msr_gva); vcpu_enable_cap(vcpu, KVM_CAP_HYPERV_ENFORCE_CPUID, 1); =20 - vcpu_set_hv_cpuid(vcpu); + if (!prev_cpuid) { + vcpu_reset_hv_cpuid(vcpu); =20 - best =3D kvm_get_supported_hv_cpuid(); + prev_cpuid =3D allocate_kvm_cpuid2(vcpu->cpuid->nent); + } else { + vcpu_init_cpuid(vcpu, prev_cpuid); + } + + feat =3D vcpu_get_cpuid_entry(vcpu, HYPERV_CPUID_FEATURES); + dbg =3D vcpu_get_cpuid_entry(vcpu, HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILI= TIES); =20 vm_init_descriptor_tables(vm); vcpu_init_descriptor_tables(vcpu); @@ -219,7 +217,7 @@ static void guest_test_msrs_access(void) msr->available =3D 0; break; case 2: - feat.eax |=3D HV_MSR_HYPERCALL_AVAILABLE; + feat->eax |=3D HV_MSR_HYPERCALL_AVAILABLE; /* * HV_X64_MSR_GUEST_OS_ID has to be written first to make * HV_X64_MSR_HYPERCALL available. @@ -246,7 +244,7 @@ static void guest_test_msrs_access(void) msr->available =3D 0; break; case 6: - feat.eax |=3D HV_MSR_VP_RUNTIME_AVAILABLE; + feat->eax |=3D HV_MSR_VP_RUNTIME_AVAILABLE; msr->write =3D 0; msr->available =3D 1; break; @@ -263,7 +261,7 @@ static void guest_test_msrs_access(void) msr->available =3D 0; break; case 9: - feat.eax |=3D HV_MSR_TIME_REF_COUNT_AVAILABLE; + feat->eax |=3D HV_MSR_TIME_REF_COUNT_AVAILABLE; msr->write =3D 0; msr->available =3D 1; break; @@ -280,7 +278,7 @@ static void guest_test_msrs_access(void) msr->available =3D 0; break; case 12: - feat.eax |=3D HV_MSR_VP_INDEX_AVAILABLE; + feat->eax |=3D HV_MSR_VP_INDEX_AVAILABLE; msr->write =3D 0; msr->available =3D 1; break; @@ -297,7 +295,7 @@ static void guest_test_msrs_access(void) msr->available =3D 0; break; case 15: - feat.eax |=3D HV_MSR_RESET_AVAILABLE; + feat->eax |=3D HV_MSR_RESET_AVAILABLE; msr->write =3D 0; msr->available =3D 1; break; @@ -313,7 +311,7 @@ static void guest_test_msrs_access(void) msr->available =3D 0; break; case 18: - feat.eax |=3D HV_MSR_REFERENCE_TSC_AVAILABLE; + feat->eax |=3D HV_MSR_REFERENCE_TSC_AVAILABLE; msr->write =3D 0; msr->available =3D 1; break; @@ -336,7 +334,7 @@ static void guest_test_msrs_access(void) vcpu_enable_cap(vcpu, KVM_CAP_HYPERV_SYNIC2, 0); break; case 22: - feat.eax |=3D HV_MSR_SYNIC_AVAILABLE; + feat->eax |=3D HV_MSR_SYNIC_AVAILABLE; msr->write =3D 0; msr->available =3D 1; break; @@ -352,7 +350,7 @@ static void guest_test_msrs_access(void) msr->available =3D 0; break; case 25: - feat.eax |=3D HV_MSR_SYNTIMER_AVAILABLE; + feat->eax |=3D HV_MSR_SYNTIMER_AVAILABLE; msr->write =3D 0; msr->available =3D 1; break; @@ -368,7 +366,7 @@ static void guest_test_msrs_access(void) msr->available =3D 0; break; case 28: - feat.edx |=3D HV_STIMER_DIRECT_MODE_AVAILABLE; + feat->edx |=3D HV_STIMER_DIRECT_MODE_AVAILABLE; msr->available =3D 1; break; =20 @@ -378,7 +376,7 @@ static void guest_test_msrs_access(void) msr->available =3D 0; break; case 30: - feat.eax |=3D HV_MSR_APIC_ACCESS_AVAILABLE; + feat->eax |=3D HV_MSR_APIC_ACCESS_AVAILABLE; msr->write =3D 1; msr->write_val =3D 1; msr->available =3D 1; @@ -390,7 +388,7 @@ static void guest_test_msrs_access(void) msr->available =3D 0; break; case 32: - feat.eax |=3D HV_ACCESS_FREQUENCY_MSRS; + feat->eax |=3D HV_ACCESS_FREQUENCY_MSRS; msr->write =3D 0; msr->available =3D 1; break; @@ -407,7 +405,7 @@ static void guest_test_msrs_access(void) msr->available =3D 0; break; case 35: - feat.eax |=3D HV_ACCESS_REENLIGHTENMENT; + feat->eax |=3D HV_ACCESS_REENLIGHTENMENT; msr->write =3D 0; msr->available =3D 1; break; @@ -430,7 +428,7 @@ static void guest_test_msrs_access(void) msr->available =3D 0; break; case 39: - feat.edx |=3D HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE; + feat->edx |=3D HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE; msr->write =3D 0; msr->available =3D 1; break; @@ -446,8 +444,8 @@ static void guest_test_msrs_access(void) msr->available =3D 0; break; case 42: - feat.edx |=3D HV_FEATURE_DEBUG_MSRS_AVAILABLE; - dbg.eax |=3D HV_X64_SYNDBG_CAP_ALLOW_KERNEL_DEBUGGING; + feat->edx |=3D HV_FEATURE_DEBUG_MSRS_AVAILABLE; + dbg->eax |=3D HV_X64_SYNDBG_CAP_ALLOW_KERNEL_DEBUGGING; msr->write =3D 0; msr->available =3D 1; break; @@ -463,7 +461,9 @@ static void guest_test_msrs_access(void) break; } =20 - hv_set_cpuid(vcpu, best, &feat, &recomm, &dbg); + vcpu_set_cpuid(vcpu); + + memcpy(prev_cpuid, vcpu->cpuid, kvm_cpuid2_size(vcpu->cpuid->nent)); =20 if (msr->idx) pr_debug("Stage %d: testing msr: 0x%x for %s\n", stage, @@ -497,24 +497,15 @@ static void guest_test_msrs_access(void) =20 static void guest_test_hcalls_access(void) { + struct kvm_cpuid_entry2 *feat, *recomm, *dbg; + struct kvm_cpuid2 *prev_cpuid =3D NULL; struct kvm_vcpu *vcpu; struct kvm_run *run; struct kvm_vm *vm; struct ucall uc; int stage =3D 0; - struct kvm_cpuid_entry2 feat =3D { - .function =3D HYPERV_CPUID_FEATURES, - .eax =3D HV_MSR_HYPERCALL_AVAILABLE - }; - struct kvm_cpuid_entry2 recomm =3D { - .function =3D HYPERV_CPUID_ENLIGHTMENT_INFO - }; - struct kvm_cpuid_entry2 dbg =3D { - .function =3D HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES - }; vm_vaddr_t hcall_page, hcall_params; struct hcall_data *hcall; - struct kvm_cpuid2 *best; =20 while (true) { vm =3D vm_create_with_one_vcpu(&vcpu, guest_hcall); @@ -534,14 +525,23 @@ static void guest_test_hcalls_access(void) vcpu_args_set(vcpu, 2, addr_gva2gpa(vm, hcall_page), hcall_params); vcpu_enable_cap(vcpu, KVM_CAP_HYPERV_ENFORCE_CPUID, 1); =20 - vcpu_set_hv_cpuid(vcpu); + if (!prev_cpuid) { + vcpu_reset_hv_cpuid(vcpu); =20 - best =3D kvm_get_supported_hv_cpuid(); + prev_cpuid =3D allocate_kvm_cpuid2(vcpu->cpuid->nent); + } else { + vcpu_init_cpuid(vcpu, prev_cpuid); + } + + feat =3D vcpu_get_cpuid_entry(vcpu, HYPERV_CPUID_FEATURES); + recomm =3D vcpu_get_cpuid_entry(vcpu, HYPERV_CPUID_ENLIGHTMENT_INFO); + dbg =3D vcpu_get_cpuid_entry(vcpu, HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILI= TIES); =20 run =3D vcpu->run; =20 switch (stage) { case 0: + feat->eax |=3D HV_MSR_HYPERCALL_AVAILABLE; hcall->control =3D 0xdeadbeef; hcall->expect =3D HV_STATUS_INVALID_HYPERCALL_CODE; break; @@ -551,7 +551,7 @@ static void guest_test_hcalls_access(void) hcall->expect =3D HV_STATUS_ACCESS_DENIED; break; case 2: - feat.ebx |=3D HV_POST_MESSAGES; + feat->ebx |=3D HV_POST_MESSAGES; hcall->expect =3D HV_STATUS_INVALID_HYPERCALL_INPUT; break; =20 @@ -560,7 +560,7 @@ static void guest_test_hcalls_access(void) hcall->expect =3D HV_STATUS_ACCESS_DENIED; break; case 4: - feat.ebx |=3D HV_SIGNAL_EVENTS; + feat->ebx |=3D HV_SIGNAL_EVENTS; hcall->expect =3D HV_STATUS_INVALID_HYPERCALL_INPUT; break; =20 @@ -569,11 +569,11 @@ static void guest_test_hcalls_access(void) hcall->expect =3D HV_STATUS_INVALID_HYPERCALL_CODE; break; case 6: - dbg.eax |=3D HV_X64_SYNDBG_CAP_ALLOW_KERNEL_DEBUGGING; + dbg->eax |=3D HV_X64_SYNDBG_CAP_ALLOW_KERNEL_DEBUGGING; hcall->expect =3D HV_STATUS_ACCESS_DENIED; break; case 7: - feat.ebx |=3D HV_DEBUGGING; + feat->ebx |=3D HV_DEBUGGING; hcall->expect =3D HV_STATUS_OPERATION_DENIED; break; =20 @@ -582,7 +582,7 @@ static void guest_test_hcalls_access(void) hcall->expect =3D HV_STATUS_ACCESS_DENIED; break; case 9: - recomm.eax |=3D HV_X64_REMOTE_TLB_FLUSH_RECOMMENDED; + recomm->eax |=3D HV_X64_REMOTE_TLB_FLUSH_RECOMMENDED; hcall->expect =3D HV_STATUS_SUCCESS; break; case 10: @@ -590,7 +590,7 @@ static void guest_test_hcalls_access(void) hcall->expect =3D HV_STATUS_ACCESS_DENIED; break; case 11: - recomm.eax |=3D HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED; + recomm->eax |=3D HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED; hcall->expect =3D HV_STATUS_SUCCESS; break; =20 @@ -599,7 +599,7 @@ static void guest_test_hcalls_access(void) hcall->expect =3D HV_STATUS_ACCESS_DENIED; break; case 13: - recomm.eax |=3D HV_X64_CLUSTER_IPI_RECOMMENDED; + recomm->eax |=3D HV_X64_CLUSTER_IPI_RECOMMENDED; hcall->expect =3D HV_STATUS_INVALID_HYPERCALL_INPUT; break; case 14: @@ -613,7 +613,7 @@ static void guest_test_hcalls_access(void) hcall->expect =3D HV_STATUS_ACCESS_DENIED; break; case 16: - recomm.ebx =3D 0xfff; + recomm->ebx =3D 0xfff; hcall->expect =3D HV_STATUS_SUCCESS; break; case 17: @@ -622,7 +622,7 @@ static void guest_test_hcalls_access(void) hcall->ud_expected =3D true; break; case 18: - feat.edx |=3D HV_X64_HYPERCALL_XMM_INPUT_AVAILABLE; + feat->edx |=3D HV_X64_HYPERCALL_XMM_INPUT_AVAILABLE; hcall->ud_expected =3D false; hcall->expect =3D HV_STATUS_SUCCESS; break; @@ -633,7 +633,9 @@ static void guest_test_hcalls_access(void) break; } =20 - hv_set_cpuid(vcpu, best, &feat, &recomm, &dbg); + vcpu_set_cpuid(vcpu); + + memcpy(prev_cpuid, vcpu->cpuid, kvm_cpuid2_size(vcpu->cpuid->nent)); =20 if (hcall->control) pr_debug("Stage %d: testing hcall: 0x%lx\n", stage, --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E383C43334 for ; Sat, 4 Jun 2022 01:23:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350320AbiFDBXp (ORCPT ); Fri, 3 Jun 2022 21:23:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347796AbiFDBWw (ORCPT ); Fri, 3 Jun 2022 21:22:52 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98DBF13F48 for ; Fri, 3 Jun 2022 18:22:02 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 70-20020a250249000000b0065cbf886b23so8231120ybc.8 for ; Fri, 03 Jun 2022 18:22:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=Mfje/LGEsIL1Phc7prlzE2OIDnqfhuSW/tqukwpVxsI=; b=D3glnvYPbXr/z3GEfKzM+4eXG6LBrh6/RJH0PVe111Y26a4ttKlQ6AAMFb9Z+3izZ8 kJhWLrzfivtnwfB7zEw6GjRRynu+w+p+DrmRQmNtrGF0SSZF3ycQMaa94bmBoswb6u6k 22zr5Oa4iIfSm2D8i0T5tMGpdvUX6bG9QgM/HgJI4iaDt7JL9MkLZm/0hnpBRtf07TQB 6cH7zN5WdaNp+t6zEOCMmzZ+OUOeq8RsVkUo7TWYvp9dFVeV3R+jRpUKRbQdbp87Vvoh n7OTM894lZ7i46UUNPOt952rkfPLjPr5mcFY0NBTt7VqDlsZ7Q+zHnLAnlzExbUUzCEe XEbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=Mfje/LGEsIL1Phc7prlzE2OIDnqfhuSW/tqukwpVxsI=; b=X+1XM4ReXetND/Pi/zRsLK+GBkLZFJwvj0z0CN4aW6izUeAXKdFWVi7CDnl8p1daTm ZSjFtpvSVnEaXgGXPyHeACBsbfjC1/9eXoCyp6pepthZncUQOQ6EUZJbxLmcZrdVzURR 0BoRBR5ikMSCtX+2kseMqvy5r2l1u3hwbR4Hx2a0A0grhxAwXqzjJhaVyz4hGQK/XXmc pK0d01f/466bSFc69kXU7XFWw+XWJLlZ0rlkkX+BSifGV7qiqr24ZdpqTvVxBUBgj0y2 4nkMuvXScPntjH5PYTuMEo/PiQPZRHHF2joDMD16hSU2tFHsOjHfqK1Zspd0DowuFddW O+rA== X-Gm-Message-State: AOAM5313G+h3Ym1Udo9jTbS0r/22ACCO8mwAXx0eNdClWHtUKRIGJdK1 TwVpWu9xzj8BhtiBRzHvtK9vyl1gfKo= X-Google-Smtp-Source: ABdhPJyuu7qyy+NAD0XIM4dph2EYsRlc1nM27AAK2h4houaEceAl5McsPosj+Sh7NPGTrV6WgqJypRNTMaY= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6902:1146:b0:660:9278:80fa with SMTP id p6-20020a056902114600b00660927880famr6695754ybu.172.1654305708092; Fri, 03 Jun 2022 18:21:48 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:43 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-28-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 27/42] KVM: selftests: Use vcpu_get_cpuid_entry() in CPUID test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use vcpu_get_cpuid_entry() instead of an open coded equivalent in the CPUID test. No functional change intended. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/x86_64/cpuid_test.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/cpuid_test.c b/tools/testin= g/selftests/kvm/x86_64/cpuid_test.c index 8723d73dcdbd..694583803468 100644 --- a/tools/testing/selftests/kvm/x86_64/cpuid_test.c +++ b/tools/testing/selftests/kvm/x86_64/cpuid_test.c @@ -147,7 +147,6 @@ struct kvm_cpuid2 *vcpu_alloc_cpuid(struct kvm_vm *vm, = vm_vaddr_t *p_gva, struct =20 static void set_cpuid_after_run(struct kvm_vcpu *vcpu) { - struct kvm_cpuid2 *cpuid =3D vcpu->cpuid; struct kvm_cpuid_entry2 *ent; int rc; u32 eax, ebx, x; @@ -157,7 +156,7 @@ static void set_cpuid_after_run(struct kvm_vcpu *vcpu) TEST_ASSERT(!rc, "Setting unmodified CPUID after KVM_RUN failed: %d", rc); =20 /* Changing CPU features is forbidden */ - ent =3D get_cpuid_entry(cpuid, 0x7, 0); + ent =3D vcpu_get_cpuid_entry(vcpu, 0x7); ebx =3D ent->ebx; ent->ebx--; rc =3D __vcpu_set_cpuid(vcpu); @@ -165,7 +164,7 @@ static void set_cpuid_after_run(struct kvm_vcpu *vcpu) ent->ebx =3D ebx; =20 /* Changing MAXPHYADDR is forbidden */ - ent =3D get_cpuid_entry(cpuid, 0x80000008, 0); + ent =3D vcpu_get_cpuid_entry(vcpu, 0x80000008); eax =3D ent->eax; x =3D eax & 0xff; ent->eax =3D (eax & ~0xffu) | (x - 1); --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3ED2AC43334 for ; Sat, 4 Jun 2022 01:23:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350358AbiFDBXu (ORCPT ); Fri, 3 Jun 2022 21:23:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349745AbiFDBWy (ORCPT ); Fri, 3 Jun 2022 21:22:54 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3973220C6 for ; Fri, 3 Jun 2022 18:22:03 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id mh12-20020a17090b4acc00b001e32eb45751so8040140pjb.9 for ; Fri, 03 Jun 2022 18:22:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=ZEoywqRe2jN83WxMzYeUPBo0DWYGkrwKbHoYsiazcV8=; b=JskoIuph7Jqycq6MAN52MeAe6aR/QuA9Xl8V1F4UOWPpX7IsnjaYtMYkj4GRBZ6yBZ j9b68ad+sTaT0tI7pY6ZvLWAlkX/ljRKlPQFaTGh8o1UGf977Lo8pfijykmMct0o7ZsI pPofcVyuN9bvwuSdz8g1kzP6oyBJETOMnAGPmiMrDRSIrDS9DW7xIBTDUbYMtpJOJ/wK Dv/b1AvkhsFeBj5dskON6W+CMqhlTrL7k55VwRLvRl7/9uVLiGHqTVHcUpD44uJIETlQ 7rRRwg7vBbTm3/SpZ5m4t3exMn34aQTU+AwffDSsvEc6X4NPW5R+ngjS/5vSwCbKpN3a jftQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=ZEoywqRe2jN83WxMzYeUPBo0DWYGkrwKbHoYsiazcV8=; b=7UMwBJ98NZaag9/cedOHhWjqNa1ERy8BkRvJv4Z/DiujdDvsEG5/3KSSsC1Vl+gxbY fUnMYnxZQM1ql/siCLkaSgryNJee3i9Gobsw47CazaWDOavu2MI1JE22jI+BBlfYjXk+ 42wmcKiY9bb5QGJbCmez/UZ78VwsK1XPaJXiYdaAfkUgWUDqadiPzDJUGMzGuS5SHwOI 9sgwdJ96sOJnRtv51+D4JBvkXEpIMBn3z6FzgdDe4MzppiQgQV8x8/GsY/xzlVHnzZ+M YjoMUtBGCM1J695yfx/uGriqDpFdA7T/DzsIbcU/6fZmlQtEOjZDHPaChj1h0ZGHWC0k o3iw== X-Gm-Message-State: AOAM531EPVwPzZqTiaP2x0R4P8vI9Zd7GWrHLBHfR/tnZVL7bjiQAYPh ZRWLE2D9wnRs0+iKC04tSSzrW619xnM= X-Google-Smtp-Source: ABdhPJxBIAnhE84vnj3pmf7obhkXbiQgzGN6yzsHkN4FaCI2JiDwne0lN5S53YNIBOnUgnsYiUb33xBlzVs= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:d491:b0:164:d43:1a23 with SMTP id c17-20020a170902d49100b001640d431a23mr12888255plg.155.1654305709778; Fri, 03 Jun 2022 18:21:49 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:44 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-29-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 28/42] KVM: selftests: Use vcpu_{set,clear}_cpuid_feature() in nVMX state test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use vcpu_{set,clear}_cpuid_feature() to toggle nested VMX support in the vCPU CPUID module in the nVMX state test. Drop CPUID_VMX as there are no longer any users. Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/x86_64/processor.h | 1 - .../kvm/x86_64/vmx_set_nested_state_test.c | 20 ++----------------- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index b9b3a19895aa..a1cac0b7d8b2 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -158,7 +158,6 @@ struct kvm_x86_cpu_feature { #define X86_FEATURE_KVM_MIGRATION_CONTROL KVM_X86_CPU_FEATURE(0x40000001, = 0, EAX, 17) =20 /* CPUID.1.ECX */ -#define CPUID_VMX (1ul << 5) #define CPUID_XSAVE (1ul << 26) #define CPUID_OSXSAVE (1ul << 27) =20 diff --git a/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c= b/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c index 1cf78ec007f2..41ea7028a1f8 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c @@ -121,7 +121,7 @@ void test_vmx_nested_state(struct kvm_vcpu *vcpu) test_nested_state(vcpu, state); =20 /* Enable VMX in the guest CPUID. */ - vcpu_set_cpuid(vcpu); + vcpu_set_cpuid_feature(vcpu, X86_FEATURE_VMX); =20 /* * Setting vmxon_pa =3D=3D -1ull and vmcs_pa =3D=3D -1ull exits early wit= hout @@ -243,22 +243,6 @@ void test_vmx_nested_state(struct kvm_vcpu *vcpu) free(state); } =20 -void disable_vmx(struct kvm_vcpu *vcpu) -{ - struct kvm_cpuid2 *cpuid =3D vcpu->cpuid; - int i; - - for (i =3D 0; i < cpuid->nent; ++i) - if (cpuid->entries[i].function =3D=3D 1 && - cpuid->entries[i].index =3D=3D 0) - break; - TEST_ASSERT(i !=3D cpuid->nent, "CPUID function 1 not found"); - - cpuid->entries[i].ecx &=3D ~CPUID_VMX; - vcpu_set_cpuid(vcpu); - cpuid->entries[i].ecx |=3D CPUID_VMX; -} - int main(int argc, char *argv[]) { struct kvm_vm *vm; @@ -280,7 +264,7 @@ int main(int argc, char *argv[]) /* * First run tests with VMX disabled to check error handling. */ - disable_vmx(vcpu); + vcpu_clear_cpuid_feature(vcpu, X86_FEATURE_VMX); =20 /* Passing a NULL kvm_nested_state causes a EFAULT. */ test_nested_state_expect_efault(vcpu, NULL); --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6853C433EF for ; Sat, 4 Jun 2022 01:24:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350264AbiFDBYX (ORCPT ); Fri, 3 Jun 2022 21:24:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350146AbiFDBXE (ORCPT ); Fri, 3 Jun 2022 21:23:04 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4198D25EAC for ; Fri, 3 Jun 2022 18:22:07 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id e18-20020a656492000000b003fa4033f9a7so4564118pgv.17 for ; Fri, 03 Jun 2022 18:22:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=fAl1+AuHRM9inCO8bRlxx9BHvcQGIGb60nHLb6rOfdI=; b=G1C+j7bRUj2zJxrGM0uz9nSZIJwVQUZJ2ZreDG6HFN1c50gYaREsj+ZgmmvuJjZKvO /2AFssTQ8QdzVP10q3z8X/jNeZAqEt/c+zCI61LcB3Hb4FYuur0QD3ZEYXntFBuTH+Wz B6scCPE7L/Q9zl9U8eRrhJubx/wiWaYKs4Sj9IblKZIvhjQxUThCELe1suaCxqAdqWt8 5miF88IXno9bvSZwjvz2RfmAP5FraDQ7OFu/lkjXJ5d2QvQvs+KWd7o2XZYFZUM+ocnn xeb8VBDnQCX2vGtoW4GFLAceWSRpBDV4AZ9q7QzSITPBqYpiQhLpMetbAD3eyA6u8rcA Pq0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=fAl1+AuHRM9inCO8bRlxx9BHvcQGIGb60nHLb6rOfdI=; b=dZ7JNLTRIJuwKpMyOdoQKs+j3R6xdux3SsRSjTH91CrVSctL6DIXo2sZF3w2iR133f f5arxYZGab813cjmXNHJiZj6GTcSoT8tjcZZvj7JtdAYrgISFbYImnM32P+jv2ZKQJ9p Ng76ulBtbKBvAxxPkjlKSwf9hc1IELXHPyugjqTSd1o/nAU8VpY9pum4EeE3mW5jRELx +TgbBArHlJGXiEvws/Ss9keqbjaIq/9cLNSFC++2pwalwaNI86as1wHyZmCiOLC75EFM yt6Aowuin/pNVocfuVOuhrHwEcRU4XPVLW891eelW5b4ow04oOdl8y8k25xpzgXVaVAD TcxA== X-Gm-Message-State: AOAM532zPAJCod3p6L8c086ds9r/AstU8WtCgr2ZwfA3NLYAKDOnrsjg ADmNb/mbVOJSAkyMKJYsFHH+zaS1sVM= X-Google-Smtp-Source: ABdhPJy0AA4cGpnkOR3s7vtIiLqzfou/9QDn663AHoOR2ivfp3NvHHxbzwhcTkdih4e+DXXcNRXmZJrZACE= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6a00:114b:b0:4f7:915:3ec3 with SMTP id b11-20020a056a00114b00b004f709153ec3mr12963470pfm.8.1654305711604; Fri, 03 Jun 2022 18:21:51 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:45 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-30-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 29/42] KVM: selftests: Use vcpu_clear_cpuid_feature() to clear x2APIC From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add X86_FEATURE_X2APIC and use vcpu_clear_cpuid_feature() to clear x2APIC support in the xAPIC state test. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/x86_64/processor.h | 1 + tools/testing/selftests/kvm/x86_64/xapic_state_test.c | 10 +--------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index a1cac0b7d8b2..c2e3ea55b697 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -81,6 +81,7 @@ struct kvm_x86_cpu_feature { #define X86_FEATURE_SMX KVM_X86_CPU_FEATURE(0x1, 0, ECX, 6) #define X86_FEATURE_PDCM KVM_X86_CPU_FEATURE(0x1, 0, ECX, 15) #define X86_FEATURE_PCID KVM_X86_CPU_FEATURE(0x1, 0, ECX, 17) +#define X86_FEATURE_X2APIC KVM_X86_CPU_FEATURE(0x1, 0, ECX, 21) #define X86_FEATURE_MOVBE KVM_X86_CPU_FEATURE(0x1, 0, ECX, 22) #define X86_FEATURE_TSC_DEADLINE_TIMER KVM_X86_CPU_FEATURE(0x1, 0, ECX, 24) #define X86_FEATURE_XSAVE KVM_X86_CPU_FEATURE(0x1, 0, ECX, 26) diff --git a/tools/testing/selftests/kvm/x86_64/xapic_state_test.c b/tools/= testing/selftests/kvm/x86_64/xapic_state_test.c index 7728730c2dda..1bc091f3b58b 100644 --- a/tools/testing/selftests/kvm/x86_64/xapic_state_test.c +++ b/tools/testing/selftests/kvm/x86_64/xapic_state_test.c @@ -122,9 +122,7 @@ int main(int argc, char *argv[]) .vcpu =3D NULL, .is_x2apic =3D true, }; - struct kvm_cpuid2 *cpuid; struct kvm_vm *vm; - int i; =20 vm =3D vm_create_with_one_vcpu(&x.vcpu, x2apic_guest_code); test_icr(&x); @@ -138,13 +136,7 @@ int main(int argc, char *argv[]) vm =3D vm_create_with_one_vcpu(&x.vcpu, xapic_guest_code); x.is_x2apic =3D false; =20 - cpuid =3D x.vcpu->cpuid; - for (i =3D 0; i < cpuid->nent; i++) { - if (cpuid->entries[i].function =3D=3D 1) - break; - } - cpuid->entries[i].ecx &=3D ~BIT(21); - vcpu_set_cpuid(x.vcpu); + vcpu_clear_cpuid_feature(x.vcpu, X86_FEATURE_X2APIC); =20 virt_pg_map(vm, APIC_DEFAULT_GPA, APIC_DEFAULT_GPA); test_icr(&x); --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97E84C43334 for ; Sat, 4 Jun 2022 01:24:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350395AbiFDBYM (ORCPT ); Fri, 3 Jun 2022 21:24:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350175AbiFDBXG (ORCPT ); Fri, 3 Jun 2022 21:23:06 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 836E727160 for ; Fri, 3 Jun 2022 18:22:08 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id y11-20020aa7804b000000b0051ba2c16046so4697923pfm.20 for ; Fri, 03 Jun 2022 18:22:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=sEiREkgq+HoUXEIbg4MsSKs5dKeKfTA3kQeTfzSdCO0=; b=m7ebo82OlPBn4pnob3hBfXD52cOfVY5eNoFRuzVEV80npImZfKSnpBOaK/H1KkYX+P s/JutEKEq4GhFSzSIbVWbDDRcMDqfri9KqMofEBYq5qGKFz6fA+v/LvGvFLVXMq5mXfi 2jCJ3HEEbPbzBKCbO1JCG+xWjh/pjGCHS+NU0sC9fLbB0Ll3MmwCaDr5B9V8KSLa6IEF 593vTWhF4e/rB40euYPwh5fWRzffs5jInW2+u18t154IkXQXVTZ5IudzB6ssibGz6iXH oXeCvDHa8unOPvYStdqHsg3BQElN4QOeQDix92O47x5NKiD3/LBAo9miZiarsIBw4wbs yg4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=sEiREkgq+HoUXEIbg4MsSKs5dKeKfTA3kQeTfzSdCO0=; b=NVsgI/6mBRndb5/08ftMAvKCDiv0Ik93t8J5aFmQI/ZtRlpfjqfBZPtDcF/wgTL48J Mo/L8MZ/c0nTFc05+N/1w7l0jSEzURu3bVxh0dIkZbyWEEL4blxtngEK0Kbt+p5NWqew GGuDTicJaN60MAwr7lujS/K6mrBAg0iZwmI6omfapGS3K94UIyOwrdeBm6K2hCloOauW hSHYkjnnvu3zowCzoaF5fSYdYeic7eAEpk9B0GyhS4EmO5XC8WynXTMV/gm8JkpB5wHr vREbduKS05b35PIjuiPv4KEvb1hdx5CqZg+dpryYFH06PTNrxq+CbLW0/eKEHrdOgqvL vFxg== X-Gm-Message-State: AOAM532xbvGj3lwDz45i/mj5CPqMbh8/re1ZlIWEqjhRzFdXPQdxh+um cvW8GetspgQns/6HsCsM6naiXX2MO7Q= X-Google-Smtp-Source: ABdhPJySn68uGi02I64F+VtPpvY1c2MX/Oirt//NxcUlYH2bbcCwJXT0jTmLNdJMojOwb89S/HjmVteyFFM= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:903:2c1:b0:158:f9d0:839c with SMTP id s1-20020a17090302c100b00158f9d0839cmr12381037plk.118.1654305713332; Fri, 03 Jun 2022 18:21:53 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:46 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-31-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 30/42] KVM: selftests: Make get_supported_cpuid() returns "const" From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Tag the returned CPUID pointers from kvm_get_supported_cpuid(), kvm_get_supported_hv_cpuid(), and vcpu_get_supported_hv_cpuid() "const" to prevent reintroducing the broken pattern of modifying the static "cpuid" variable used by kvm_get_supported_cpuid() to cache the results of KVM_GET_SUPPORTED_CPUID. Update downstream consumers as needed. Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/x86_64/processor.h | 24 ++++++++--------- .../selftests/kvm/lib/x86_64/processor.c | 27 ++++++------------- .../testing/selftests/kvm/x86_64/cpuid_test.c | 12 ++++----- .../selftests/kvm/x86_64/hyperv_cpuid.c | 10 +++---- .../kvm/x86_64/pmu_event_filter_test.c | 10 +++---- .../selftests/kvm/x86_64/vmx_pmu_caps_test.c | 2 +- 6 files changed, 36 insertions(+), 49 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index c2e3ea55b697..6c14b34014c2 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -583,7 +583,9 @@ static inline void vcpu_xcrs_set(struct kvm_vcpu *vcpu,= struct kvm_xcrs *xcrs) vcpu_ioctl(vcpu, KVM_SET_XCRS, xcrs); } =20 -struct kvm_cpuid2 *kvm_get_supported_cpuid(void); +const struct kvm_cpuid2 *kvm_get_supported_cpuid(void); +const struct kvm_cpuid2 *kvm_get_supported_hv_cpuid(void); +const struct kvm_cpuid2 *vcpu_get_supported_hv_cpuid(struct kvm_vcpu *vcpu= ); =20 bool kvm_cpuid_has(const struct kvm_cpuid2 *cpuid, struct kvm_x86_cpu_feature feature); @@ -616,15 +618,17 @@ static inline struct kvm_cpuid2 *allocate_kvm_cpuid2(= int nr_entries) return cpuid; } =20 -struct kvm_cpuid_entry2 *get_cpuid_entry(struct kvm_cpuid2 *cpuid, - uint32_t function, uint32_t index); -void vcpu_init_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid); +const struct kvm_cpuid_entry2 *get_cpuid_entry(const struct kvm_cpuid2 *cp= uid, + uint32_t function, uint32_t index); +void vcpu_init_cpuid(struct kvm_vcpu *vcpu, const struct kvm_cpuid2 *cpuid= ); +void vcpu_set_hv_cpuid(struct kvm_vcpu *vcpu); =20 static inline struct kvm_cpuid_entry2 *__vcpu_get_cpuid_entry(struct kvm_v= cpu *vcpu, uint32_t function, uint32_t index) { - return get_cpuid_entry(vcpu->cpuid, function, index); + return (struct kvm_cpuid_entry2 *)get_cpuid_entry(vcpu->cpuid, + function, index); } =20 static inline struct kvm_cpuid_entry2 *vcpu_get_cpuid_entry(struct kvm_vcp= u *vcpu, @@ -676,14 +680,13 @@ static inline void vcpu_clear_cpuid_feature(struct kv= m_vcpu *vcpu, vcpu_set_or_clear_cpuid_feature(vcpu, feature, false); } =20 -static inline struct kvm_cpuid_entry2 *kvm_get_supported_cpuid_index(uint3= 2_t function, - uint32_t index) +static inline const struct kvm_cpuid_entry2 *kvm_get_supported_cpuid_index= (uint32_t function, + uint32_t index) { return get_cpuid_entry(kvm_get_supported_cpuid(), function, index); } =20 -static inline struct kvm_cpuid_entry2 * -kvm_get_supported_cpuid_entry(uint32_t function) +static inline const struct kvm_cpuid_entry2 *kvm_get_supported_cpuid_entry= (uint32_t function) { return kvm_get_supported_cpuid_index(function, 0); } @@ -730,9 +733,6 @@ void vm_set_page_table_entry(struct kvm_vm *vm, struct = kvm_vcpu *vcpu, uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2, uint64_t a3); =20 -struct kvm_cpuid2 *kvm_get_supported_hv_cpuid(void); -void vcpu_set_hv_cpuid(struct kvm_vcpu *vcpu); -struct kvm_cpuid2 *vcpu_get_supported_hv_cpuid(struct kvm_vcpu *vcpu); void vm_xsave_req_perm(int bit); =20 enum x86_page_size { diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index 1812b14de3dd..41cc320d3e34 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -677,18 +677,7 @@ void vcpu_arch_free(struct kvm_vcpu *vcpu) free(vcpu->cpuid); } =20 -/* - * KVM Supported CPUID Get - * - * Input Args: None - * - * Output Args: - * - * Return: The supported KVM CPUID - * - * Get the guest CPUID supported by KVM. - */ -struct kvm_cpuid2 *kvm_get_supported_cpuid(void) +const struct kvm_cpuid2 *kvm_get_supported_cpuid(void) { static struct kvm_cpuid2 *cpuid; int kvm_fd; @@ -746,7 +735,7 @@ uint64_t kvm_get_feature_msr(uint64_t msr_index) return buffer.entry.data; } =20 -void vcpu_init_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid) +void vcpu_init_cpuid(struct kvm_vcpu *vcpu, const struct kvm_cpuid2 *cpuid) { TEST_ASSERT(cpuid !=3D vcpu->cpuid, "@cpuid can't be the vCPU's CPUID"); =20 @@ -1080,7 +1069,7 @@ uint32_t kvm_get_cpuid_max_extended(void) =20 void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bit= s) { - struct kvm_cpuid_entry2 *entry; + const struct kvm_cpuid_entry2 *entry; bool pae; =20 /* SDM 4.1.4 */ @@ -1192,8 +1181,8 @@ void assert_on_unhandled_exception(struct kvm_vcpu *v= cpu) } } =20 -struct kvm_cpuid_entry2 *get_cpuid_entry(struct kvm_cpuid2 *cpuid, - uint32_t function, uint32_t index) +const struct kvm_cpuid_entry2 *get_cpuid_entry(const struct kvm_cpuid2 *cp= uid, + uint32_t function, uint32_t index) { int i; =20 @@ -1219,7 +1208,7 @@ uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint= 64_t a1, uint64_t a2, return r; } =20 -struct kvm_cpuid2 *kvm_get_supported_hv_cpuid(void) +const struct kvm_cpuid2 *kvm_get_supported_hv_cpuid(void) { static struct kvm_cpuid2 *cpuid; int kvm_fd; @@ -1239,7 +1228,7 @@ struct kvm_cpuid2 *kvm_get_supported_hv_cpuid(void) void vcpu_set_hv_cpuid(struct kvm_vcpu *vcpu) { static struct kvm_cpuid2 *cpuid_full; - struct kvm_cpuid2 *cpuid_sys, *cpuid_hv; + const struct kvm_cpuid2 *cpuid_sys, *cpuid_hv; int i, nent =3D 0; =20 if (!cpuid_full) { @@ -1269,7 +1258,7 @@ void vcpu_set_hv_cpuid(struct kvm_vcpu *vcpu) vcpu_init_cpuid(vcpu, cpuid_full); } =20 -struct kvm_cpuid2 *vcpu_get_supported_hv_cpuid(struct kvm_vcpu *vcpu) +const struct kvm_cpuid2 *vcpu_get_supported_hv_cpuid(struct kvm_vcpu *vcpu) { struct kvm_cpuid2 *cpuid =3D allocate_kvm_cpuid2(MAX_NR_CPUID_ENTRIES); =20 diff --git a/tools/testing/selftests/kvm/x86_64/cpuid_test.c b/tools/testin= g/selftests/kvm/x86_64/cpuid_test.c index 694583803468..2b8ac307da64 100644 --- a/tools/testing/selftests/kvm/x86_64/cpuid_test.c +++ b/tools/testing/selftests/kvm/x86_64/cpuid_test.c @@ -66,7 +66,7 @@ static void guest_main(struct kvm_cpuid2 *guest_cpuid) GUEST_DONE(); } =20 -static bool is_cpuid_mangled(struct kvm_cpuid_entry2 *entrie) +static bool is_cpuid_mangled(const struct kvm_cpuid_entry2 *entrie) { int i; =20 @@ -79,9 +79,10 @@ static bool is_cpuid_mangled(struct kvm_cpuid_entry2 *en= trie) return false; } =20 -static void compare_cpuids(struct kvm_cpuid2 *cpuid1, struct kvm_cpuid2 *c= puid2) +static void compare_cpuids(const struct kvm_cpuid2 *cpuid1, + const struct kvm_cpuid2 *cpuid2) { - struct kvm_cpuid_entry2 *e1, *e2; + const struct kvm_cpuid_entry2 *e1, *e2; int i; =20 TEST_ASSERT(cpuid1->nent =3D=3D cpuid2->nent, @@ -175,7 +176,6 @@ static void set_cpuid_after_run(struct kvm_vcpu *vcpu) =20 int main(void) { - struct kvm_cpuid2 *supp_cpuid; struct kvm_vcpu *vcpu; vm_vaddr_t cpuid_gva; struct kvm_vm *vm; @@ -183,9 +183,7 @@ int main(void) =20 vm =3D vm_create_with_one_vcpu(&vcpu, guest_main); =20 - supp_cpuid =3D kvm_get_supported_cpuid(); - - compare_cpuids(supp_cpuid, vcpu->cpuid); + compare_cpuids(kvm_get_supported_cpuid(), vcpu->cpuid); =20 vcpu_alloc_cpuid(vm, &cpuid_gva, vcpu->cpuid); =20 diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c b/tools/test= ing/selftests/kvm/x86_64/hyperv_cpuid.c index c406b95cba9b..e804eb08dff9 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c @@ -43,7 +43,7 @@ static bool smt_possible(void) return res; } =20 -static void test_hv_cpuid(struct kvm_cpuid2 *hv_cpuid_entries, +static void test_hv_cpuid(const struct kvm_cpuid2 *hv_cpuid_entries, bool evmcs_expected) { int i; @@ -56,7 +56,7 @@ static void test_hv_cpuid(struct kvm_cpuid2 *hv_cpuid_ent= ries, nent_expected, hv_cpuid_entries->nent); =20 for (i =3D 0; i < hv_cpuid_entries->nent; i++) { - struct kvm_cpuid_entry2 *entry =3D &hv_cpuid_entries->entries[i]; + const struct kvm_cpuid_entry2 *entry =3D &hv_cpuid_entries->entries[i]; =20 TEST_ASSERT((entry->function >=3D 0x40000000) && (entry->function <=3D 0x40000082), @@ -131,7 +131,7 @@ void test_hv_cpuid_e2big(struct kvm_vm *vm, struct kvm_= vcpu *vcpu) int main(int argc, char *argv[]) { struct kvm_vm *vm; - struct kvm_cpuid2 *hv_cpuid_entries; + const struct kvm_cpuid2 *hv_cpuid_entries; struct kvm_vcpu *vcpu; =20 /* Tell stdout not to buffer its content */ @@ -146,7 +146,7 @@ int main(int argc, char *argv[]) =20 hv_cpuid_entries =3D vcpu_get_supported_hv_cpuid(vcpu); test_hv_cpuid(hv_cpuid_entries, false); - free(hv_cpuid_entries); + free((void *)hv_cpuid_entries); =20 if (!kvm_cpu_has(X86_FEATURE_VMX) || !kvm_has_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)) { @@ -156,7 +156,7 @@ int main(int argc, char *argv[]) vcpu_enable_evmcs(vcpu); hv_cpuid_entries =3D vcpu_get_supported_hv_cpuid(vcpu); test_hv_cpuid(hv_cpuid_entries, true); - free(hv_cpuid_entries); + free((void *)hv_cpuid_entries); =20 do_sys: /* Test system ioctl version */ diff --git a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c b/t= ools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c index 66930384ef97..5321bfe8b4e9 100644 --- a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c +++ b/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c @@ -358,7 +358,7 @@ static void test_pmu_config_disable(void (*guest_code)(= void)) * counter per logical processor, an EBX bit vector of length greater * than 5, and EBX[5] clear. */ -static bool check_intel_pmu_leaf(struct kvm_cpuid_entry2 *entry) +static bool check_intel_pmu_leaf(const struct kvm_cpuid_entry2 *entry) { union cpuid10_eax eax =3D { .full =3D entry->eax }; union cpuid10_ebx ebx =3D { .full =3D entry->ebx }; @@ -374,10 +374,10 @@ static bool check_intel_pmu_leaf(struct kvm_cpuid_ent= ry2 *entry) */ static bool use_intel_pmu(void) { - struct kvm_cpuid_entry2 *entry; + const struct kvm_cpuid_entry2 *entry; =20 entry =3D kvm_get_supported_cpuid_index(0xa, 0); - return is_intel_cpu() && entry && check_intel_pmu_leaf(entry); + return is_intel_cpu() && check_intel_pmu_leaf(entry); } =20 static bool is_zen1(uint32_t eax) @@ -406,10 +406,10 @@ static bool is_zen3(uint32_t eax) */ static bool use_amd_pmu(void) { - struct kvm_cpuid_entry2 *entry; + const struct kvm_cpuid_entry2 *entry; =20 entry =3D kvm_get_supported_cpuid_index(1, 0); - return is_amd_cpu() && entry && + return is_amd_cpu() && (is_zen1(entry->eax) || is_zen2(entry->eax) || is_zen3(entry->eax)); diff --git a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c b/tools= /testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c index dc3869d5aff0..689517f2aae6 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c @@ -53,7 +53,7 @@ static void guest_code(void) =20 int main(int argc, char *argv[]) { - struct kvm_cpuid_entry2 *entry_a_0; + const struct kvm_cpuid_entry2 *entry_a_0; struct kvm_vm *vm; struct kvm_vcpu *vcpu; int ret; --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BC9FC43334 for ; Sat, 4 Jun 2022 01:23:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350258AbiFDBXg (ORCPT ); Fri, 3 Jun 2022 21:23:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350183AbiFDBWe (ORCPT ); Fri, 3 Jun 2022 21:22:34 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 162385FDE for ; Fri, 3 Jun 2022 18:21:56 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id j23-20020aa78017000000b005180c6e4ef2so4710010pfi.12 for ; Fri, 03 Jun 2022 18:21:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=cK8PvxeAQtBNlCjWzChNwkY/gHGJXYhTwM/r3UTKrIg=; b=rrNnHpNRfBTyIizsoYBcvfK0rN/c+8gjsJTVPdRJrWlTLJva2ynOjR91LoW3xp4Dhu MAyuMIG/9rY6lXHdBe0y2QZbztMbkwZPLqgziWsCjSCUu30D7537YoJZiSDrpc0PuEnd jx0ogORprrpM8+JVuTOx72oikRKxJFgwRtdO5qjFcIkDIER6ZfAhlkM9oNtQxKFp0XCG LjO0TDOvJEo+oYI98XKUZpRb4WhpU8bLBvzxXoK5IXvL0pqjR7EHZ3HLUYjaJVGohufC cUyl8UgW6lFl7a5XTBOBRYKhVz1LR977DCAuonSULBmQmFPWiIHPS9+zI7remx5dCm2n ECrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=cK8PvxeAQtBNlCjWzChNwkY/gHGJXYhTwM/r3UTKrIg=; b=1J/FEOQuUHBC4NPlnkfJsZio3c6FVu1FgtLAdrVSgydbY25tKm9zR1X7p4KepkERAg YHrj8caXL4E78cWtL2PLxj6dDFW+RsbN3Dozs6mghz0bp+sdd7/vauankHSw6WC4hGOR 1KWLya4tGaSNVuPea+wt1WYaYkp7w7z2KZEyIr+hgA9q9y/X8t2IXg2RFIaJgPNO5q7O SR5UFFhX7QoChjnfWEykKRf1BhYGIxaswfaqs2y1aKBwZVJUA03Atzc+olCqFl8m+pxT lTXLh4k4YZjiXeFlPhwygV/zE5rovadcte42zCuUmJ1L725PHVxOe6xWFU0ED1bDhvxq qXSg== X-Gm-Message-State: AOAM533LJ7JH9L9Vvrtcj6xBRN02DnkupGM6HKXN9apmc7ve9WQvJ0tJ XdM3/cRbAaOuE15fjYbTf0NY5uIsawg= X-Google-Smtp-Source: ABdhPJxxrC8VUtRL8FfqCb2fIzn8BQ4nfF5atsWQCs5HnznvGnEQTRG+BcHWT9w7RqcOdLb55/ljkjFh/mU= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90a:249:b0:1e0:a8a3:3c6c with SMTP id t9-20020a17090a024900b001e0a8a33c6cmr4683pje.0.1654305715304; Fri, 03 Jun 2022 18:21:55 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:47 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-32-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 31/42] KVM: selftests: Set input function/index in raw CPUID helper(s) From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Set the function/index for CPUID in the helper instead of relying on the caller to do so. In addition to reducing the risk of consuming an uninitialized ECX, having the function/index embedded in the call makes it easier to understand what is being checked. Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/x86_64/processor.h | 16 +++++++++++++--- .../selftests/kvm/lib/x86_64/processor.c | 13 ++++--------- tools/testing/selftests/kvm/x86_64/amx_test.c | 19 ++++--------------- .../testing/selftests/kvm/x86_64/cpuid_test.c | 11 +++++------ 4 files changed, 26 insertions(+), 33 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index 6c14b34014c2..eb4730bf4e77 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -402,10 +402,13 @@ static inline void outl(uint16_t port, uint32_t value) __asm__ __volatile__("outl %%eax, %%dx" : : "d"(port), "a"(value)); } =20 -static inline void cpuid(uint32_t *eax, uint32_t *ebx, - uint32_t *ecx, uint32_t *edx) +static inline void __cpuid(uint32_t function, uint32_t index, + uint32_t *eax, uint32_t *ebx, + uint32_t *ecx, uint32_t *edx) { - /* ecx is often an input as well as an output. */ + *eax =3D function; + *ecx =3D index; + asm volatile("cpuid" : "=3Da" (*eax), "=3Db" (*ebx), @@ -415,6 +418,13 @@ static inline void cpuid(uint32_t *eax, uint32_t *ebx, : "memory"); } =20 +static inline void cpuid(uint32_t function, + uint32_t *eax, uint32_t *ebx, + uint32_t *ecx, uint32_t *edx) +{ + return __cpuid(function, 0, eax, ebx, ecx, edx); +} + #define SET_XMM(__var, __xmm) \ asm volatile("movq %0, %%"#__xmm : : "r"(__var) : #__xmm) =20 diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index 41cc320d3e34..1d92a1d9a03f 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1285,9 +1285,7 @@ unsigned long vm_compute_max_gfn(struct kvm_vm *vm) =20 /* Before family 17h, the HyperTransport area is just below 1T. */ ht_gfn =3D (1 << 28) - num_ht_pages; - eax =3D 1; - ecx =3D 0; - cpuid(&eax, &ebx, &ecx, &edx); + cpuid(1, &eax, &ebx, &ecx, &edx); if (x86_family(eax) < 0x17) goto done; =20 @@ -1296,18 +1294,15 @@ unsigned long vm_compute_max_gfn(struct kvm_vm *vm) * reduced due to SME by bits 11:6 of CPUID[0x8000001f].EBX. Use * the old conservative value if MAXPHYADDR is not enumerated. */ - eax =3D 0x80000000; - cpuid(&eax, &ebx, &ecx, &edx); + cpuid(0x80000000, &eax, &ebx, &ecx, &edx); max_ext_leaf =3D eax; if (max_ext_leaf < 0x80000008) goto done; =20 - eax =3D 0x80000008; - cpuid(&eax, &ebx, &ecx, &edx); + cpuid(0x80000008, &eax, &ebx, &ecx, &edx); max_pfn =3D (1ULL << ((eax & 0xff) - vm->page_shift)) - 1; if (max_ext_leaf >=3D 0x8000001f) { - eax =3D 0x8000001f; - cpuid(&eax, &ebx, &ecx, &edx); + cpuid(0x8000001f, &eax, &ebx, &ecx, &edx); max_pfn >>=3D (ebx >> 6) & 0x3f; } =20 diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/= selftests/kvm/x86_64/amx_test.c index bcf535646321..866a42d07d75 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -122,9 +122,7 @@ static inline void check_cpuid_xsave(void) { uint32_t eax, ebx, ecx, edx; =20 - eax =3D 1; - ecx =3D 0; - cpuid(&eax, &ebx, &ecx, &edx); + cpuid(1, &eax, &ebx, &ecx, &edx); if (!(ecx & CPUID_XSAVE)) GUEST_ASSERT(!"cpuid: no CPU xsave support!"); if (!(ecx & CPUID_OSXSAVE)) @@ -140,10 +138,7 @@ static bool enum_xtile_config(void) { u32 eax, ebx, ecx, edx; =20 - eax =3D TILE_CPUID; - ecx =3D TILE_PALETTE_CPUID_SUBLEAVE; - - cpuid(&eax, &ebx, &ecx, &edx); + __cpuid(TILE_CPUID, TILE_PALETTE_CPUID_SUBLEAVE, &eax, &ebx, &ecx, &edx); if (!eax || !ebx || !ecx) return false; =20 @@ -165,10 +160,7 @@ static bool enum_xsave_tile(void) { u32 eax, ebx, ecx, edx; =20 - eax =3D XSTATE_CPUID; - ecx =3D XFEATURE_XTILEDATA; - - cpuid(&eax, &ebx, &ecx, &edx); + __cpuid(XSTATE_CPUID, XFEATURE_XTILEDATA, &eax, &ebx, &ecx, &edx); if (!eax || !ebx) return false; =20 @@ -183,10 +175,7 @@ static bool check_xsave_size(void) u32 eax, ebx, ecx, edx; bool valid =3D false; =20 - eax =3D XSTATE_CPUID; - ecx =3D XSTATE_USER_STATE_SUBLEAVE; - - cpuid(&eax, &ebx, &ecx, &edx); + __cpuid(XSTATE_CPUID, XSTATE_USER_STATE_SUBLEAVE, &eax, &ebx, &ecx, &edx); if (ebx && ebx <=3D XSAVE_SIZE) valid =3D true; =20 diff --git a/tools/testing/selftests/kvm/x86_64/cpuid_test.c b/tools/testin= g/selftests/kvm/x86_64/cpuid_test.c index 2b8ac307da64..a4c4a5c5762a 100644 --- a/tools/testing/selftests/kvm/x86_64/cpuid_test.c +++ b/tools/testing/selftests/kvm/x86_64/cpuid_test.c @@ -31,10 +31,9 @@ static void test_guest_cpuids(struct kvm_cpuid2 *guest_c= puid) u32 eax, ebx, ecx, edx; =20 for (i =3D 0; i < guest_cpuid->nent; i++) { - eax =3D guest_cpuid->entries[i].function; - ecx =3D guest_cpuid->entries[i].index; - - cpuid(&eax, &ebx, &ecx, &edx); + __cpuid(guest_cpuid->entries[i].function, + guest_cpuid->entries[i].index, + &eax, &ebx, &ecx, &edx); =20 GUEST_ASSERT(eax =3D=3D guest_cpuid->entries[i].eax && ebx =3D=3D guest_cpuid->entries[i].ebx && @@ -46,9 +45,9 @@ static void test_guest_cpuids(struct kvm_cpuid2 *guest_cp= uid) =20 static void test_cpuid_40000000(struct kvm_cpuid2 *guest_cpuid) { - u32 eax =3D 0x40000000, ebx, ecx =3D 0, edx; + u32 eax, ebx, ecx, edx; =20 - cpuid(&eax, &ebx, &ecx, &edx); + cpuid(0x40000000, &eax, &ebx, &ecx, &edx); =20 GUEST_ASSERT(eax =3D=3D 0x40000001); } --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AD5DC433EF for ; Sat, 4 Jun 2022 01:24:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350361AbiFDBYH (ORCPT ); Fri, 3 Jun 2022 21:24:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350117AbiFDBWe (ORCPT ); Fri, 3 Jun 2022 21:22:34 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B1F49FE3 for ; Fri, 3 Jun 2022 18:21:57 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-30047b94aa8so80842897b3.1 for ; Fri, 03 Jun 2022 18:21:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=btNvlb67FRxWt/N67wV+X94puj6fGYAVKhOck9gaL8c=; b=UoZ9ymY2moYpaQqxy6WubTCRdWEX2xixmR8oQSY4AqGmDeWP4/+I+T6JpT6ipzLDsO wdCZaDORvp8L3ZjxLvRqgMLuN8TbMiooku04mdVeJJHZnHrr1btqJkM8k5PCw1+o48z0 pgLqk4mKiP6Isk4r1wcgStzGCsf5lWXePtf7Ry4+w8CdOWtkrwA9IPnEyFgus9xsW3ET 3cuzVwdtz0/NWd9Cwtppm+bwzsLMrcwGmOK8C0Ku5D6oextdHvADZevlEczm9dT6RjZJ 1mnalkxuKQpHXrbtJ5ISVKM94DgipYYVw1BRbRF63ONqp14thgQhtMQsqV9oTOfIHvY9 lI7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=btNvlb67FRxWt/N67wV+X94puj6fGYAVKhOck9gaL8c=; b=OquaaP133ZwJt6ou3sq5LwwSLj+AToCelQgfgehrN8cayarxGEQ7j7rlCl3EmVgxX7 JXMNuFY8wSYhm2tSsHI3AoHMObv75pA1CbxhBsK4e1eHNJ3QmpCOwLU5T35fS4OeOEMr GjuThzy2KcIAFUj8HnzZkT8Dxt6LAJZzNciKW3CvjiK6YBDoeKjgHrPxys5PYT4xNGya tnID+0VjHbLI7IONJoP9xXWAw0gDeixMNd84+UCYr8l0fMAy1LH+nzD+YIeiVzcEN4Mx Lh0rBVYoMieS2bUEFZ/QWisb9jTjgdIl4eNZM6XbogjhCtSZmipNTBvGBCaIwGZVVg1D hZgw== X-Gm-Message-State: AOAM5317YGjGtHhl3eztjcifFnalbWsMJlyabOFfgmkTkAlsRrJvAk5r IER8ne7MuC+Q/DbcseDGkUb4Ggtzdek= X-Google-Smtp-Source: ABdhPJyKYMvagsyZ+ivnLnJrKpiQpTQSkMagnJr59o8ovG/QztKDoBUD4k9HVwRH1Sue7MCmWfLPdrZNvv8= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a81:3a93:0:b0:2ff:a0f1:53fe with SMTP id h141-20020a813a93000000b002ffa0f153femr14287013ywa.352.1654305717259; Fri, 03 Jun 2022 18:21:57 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:48 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-33-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 32/42] KVM: selftests: Add this_cpu_has() to query X86_FEATURE_* via cpuid() From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add this_cpu_has() to query an X86_FEATURE_* via cpuid(), i.e. to query a feature from L1 (or L2) guest code. Arbitrarily select the AMX test to be the first user. Signed-off-by: Sean Christopherson --- .../testing/selftests/kvm/include/x86_64/processor.h | 12 +++++++++++- tools/testing/selftests/kvm/x86_64/amx_test.c | 9 ++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index eb4730bf4e77..d79060f55307 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -159,7 +159,6 @@ struct kvm_x86_cpu_feature { #define X86_FEATURE_KVM_MIGRATION_CONTROL KVM_X86_CPU_FEATURE(0x40000001, = 0, EAX, 17) =20 /* CPUID.1.ECX */ -#define CPUID_XSAVE (1ul << 26) #define CPUID_OSXSAVE (1ul << 27) =20 /* Page table bitfield declarations */ @@ -425,6 +424,17 @@ static inline void cpuid(uint32_t function, return __cpuid(function, 0, eax, ebx, ecx, edx); } =20 +static inline bool this_cpu_has(struct kvm_x86_cpu_feature feature) +{ + uint32_t gprs[4]; + + __cpuid(feature.function, feature.index, + &gprs[KVM_CPUID_EAX], &gprs[KVM_CPUID_EBX], + &gprs[KVM_CPUID_ECX], &gprs[KVM_CPUID_EDX]); + + return gprs[feature.reg] & BIT(feature.bit); +} + #define SET_XMM(__var, __xmm) \ asm volatile("movq %0, %%"#__xmm : : "r"(__var) : #__xmm) =20 diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/= selftests/kvm/x86_64/amx_test.c index 866a42d07d75..a886c9e81b87 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -120,13 +120,8 @@ static inline void __xsavec(struct xsave_data *data, u= int64_t rfbm) =20 static inline void check_cpuid_xsave(void) { - uint32_t eax, ebx, ecx, edx; - - cpuid(1, &eax, &ebx, &ecx, &edx); - if (!(ecx & CPUID_XSAVE)) - GUEST_ASSERT(!"cpuid: no CPU xsave support!"); - if (!(ecx & CPUID_OSXSAVE)) - GUEST_ASSERT(!"cpuid: no OS xsave support!"); + GUEST_ASSERT(this_cpu_has(X86_FEATURE_XSAVE)); + GUEST_ASSERT(this_cpu_has(X86_FEATURE_OSXSAVE)); } =20 static bool check_xsave_supports_xtile(void) --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6672AC433EF for ; Sat, 4 Jun 2022 01:24:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348909AbiFDBYm (ORCPT ); Fri, 3 Jun 2022 21:24:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350206AbiFDBXH (ORCPT ); Fri, 3 Jun 2022 21:23:07 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EAA72C646 for ; Fri, 3 Jun 2022 18:22:11 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id e19-20020aa79813000000b0051bba91468eso4107756pfl.14 for ; Fri, 03 Jun 2022 18:22:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=swbJ6v8rwkX5ox5kjlWFOdrm0/u3IDwNIqI+0XE8E5g=; b=B9PrjQZmvSAIKXNjNRf8xJhmmpWYuAkjiNJPP3tniNIahD7Fx5tuhaXmQrjxz5Hfjy zbA+y8KJQeMywOyulpapLuKGR1XYX6RgQRoPZpd4CPVI3Hgbwe/5U0uNL7vM9mhoLd+A xJO+veeL/wsAJEqlLVLAL486xa3ESlHzzCHVJBH2m1RvUm4jP8H8Grz1GmzU8BXPsi4t bhZkZ5yjaikJaes+TiN4Tic5BBxUredQrxxZg065HBYm9LLn1bVhf15LgtImwU82myGK 7iUGt9pIY2I6ISrmsR3CzaUkUl1oQExOrMhvRQoFBw3MkY/BiOQRGtI7n3C9egrDPziX gd6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=swbJ6v8rwkX5ox5kjlWFOdrm0/u3IDwNIqI+0XE8E5g=; b=h9paS2PnMMdy6mOabphXw3KVrF7j70Ei4c/jx8Jrz6epOrTxLi9XmkJvn9Vkg0W/OW 3D+gXYB+l0S0gUqSTA8brThGiEgj8yoVHiFJJXi+xEsE9ulocYnZTnBtAD1G/YgRBpRk 64EYIEQd+PRLkFrg+Cpkr+GCQ5ZiedCnsmYGeNuVyTO/s0F81rI8RLZqv2QdBiMmgj7A L7e13yHgGxeBVXFoPcDGzNfFiBbpnqOhDzuKJylRHtBtQf+qEOfONd5fvtkW8rNRAUC4 BSJtPTCubpGu1r4GH82GwP5NLjaZfkjhHADiooDJal+R9sO8IgNm00S7tWD1/l/whii2 MtIg== X-Gm-Message-State: AOAM530DdIKNv4MeGXMY74EmEuxPglLYXSzCsjPKX2Bul6jgjg8oRsu6 ctJBUpeZCQRnBvM7uqgTqMYB/xmyKkk= X-Google-Smtp-Source: ABdhPJwrOcqIcOGwRZoGsX8a7YmmriJaRtGl/5Sedt42uYX8l7pqbbhcjlOXBG0LkIxCuDzXHxckiouR+PA= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90b:4a8c:b0:1e2:f378:631d with SMTP id lp12-20020a17090b4a8c00b001e2f378631dmr13480171pjb.58.1654305718994; Fri, 03 Jun 2022 18:21:58 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:49 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-34-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 33/42] KVM: selftests: Use this_cpu_has() in CR4/CPUID sync test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use this_cpu_has() to query OSXSAVE from the L1 guest in the CR4=3D>CPUID sync test. Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/x86_64/processor.h | 3 --- .../selftests/kvm/x86_64/cr4_cpuid_sync_test.c | 14 ++------------ 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index d79060f55307..db724670c895 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -158,9 +158,6 @@ struct kvm_x86_cpu_feature { #define X86_FEATURE_KVM_HC_MAP_GPA_RANGE KVM_X86_CPU_FEATURE(0x40000001, 0= , EAX, 16) #define X86_FEATURE_KVM_MIGRATION_CONTROL KVM_X86_CPU_FEATURE(0x40000001, = 0, EAX, 17) =20 -/* CPUID.1.ECX */ -#define CPUID_OSXSAVE (1ul << 27) - /* Page table bitfield declarations */ #define PTE_PRESENT_MASK BIT_ULL(0) #define PTE_WRITABLE_MASK BIT_ULL(1) diff --git a/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c b/too= ls/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c index 092fedbe6f52..a310674b6974 100644 --- a/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c +++ b/tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c @@ -21,19 +21,9 @@ =20 static inline bool cr4_cpuid_is_sync(void) { - int func, subfunc; - uint32_t eax, ebx, ecx, edx; - uint64_t cr4; + uint64_t cr4 =3D get_cr4(); =20 - func =3D 0x1; - subfunc =3D 0x0; - __asm__ __volatile__("cpuid" - : "=3Da"(eax), "=3Db"(ebx), "=3Dc"(ecx), "=3Dd"(edx) - : "a"(func), "c"(subfunc)); - - cr4 =3D get_cr4(); - - return (!!(ecx & CPUID_OSXSAVE)) =3D=3D (!!(cr4 & X86_CR4_OSXSAVE)); + return (this_cpu_has(X86_FEATURE_OSXSAVE) =3D=3D !!(cr4 & X86_CR4_OSXSAVE= )); } =20 static void guest_code(void) --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F934C43334 for ; Sat, 4 Jun 2022 01:24:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350310AbiFDBYd (ORCPT ); Fri, 3 Jun 2022 21:24:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350205AbiFDBXI (ORCPT ); Fri, 3 Jun 2022 21:23:08 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76BED2CDE0 for ; Fri, 3 Jun 2022 18:22:12 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 70-20020a250249000000b0065cbf886b23so8231341ybc.8 for ; Fri, 03 Jun 2022 18:22:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=yfkUMsmDGGeH3M/FWDGodyCRiaziEFV/NXR4VZp8ZC8=; b=iAq/uHVPCDq8tx1UFOGN/hYZl8mPJVdCgCs3IbdeW1sBr9HKchdKNWw57cPlTCMLJ4 YN/J67fIOY8F6vc+Uq+NSmcEbAZ3BZTuTXs9fIy/fQrZweo0p0aA+ncSvPs1+BNeJkIC dMwVuIL5f/MWZv4nPjztpuyZc5VwIo9Jgs5buQjW98j82RZKO8X+v/lDBd80suitxdPj ofyx2UKi5fXFKecS+smX+rAd+JSYxd1kL/qAy3oqo9SYnJcdH8/4UkHfyY+D2sUgN1wf Ds3srqZ725SvZOAlDc6wShwngMYV6UCjlNWLl7OpFVUqgBILpHTe+3KvGoqjh5y5eh+a Cd1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=yfkUMsmDGGeH3M/FWDGodyCRiaziEFV/NXR4VZp8ZC8=; b=kb1KRw1m/rgU+aX55Js3ekayCKPjWq/lQF6Rh8bCFos8zqVqsvwyg2UgN1W3SlIPB/ 39iRRrzO9iDArUj4pnyQr7QiHs/Hc9EUFXigUAzvWvGFTWLtJzh+jLLlFNkpSsIIANpt Dwk+Mz+nGBMUunv29IJFCJPmn3jvLaspIGYV5T33nta85VLJLKP0rqwfJR/osBZLC/kP 8by7274PppTthdd9euPqz53xUb3MrDL3LgZlWLIh+3hXgIFHqrXyUSu+cjWHzYFKtIhZ 2H5P/MAh08WUNehYNLBevMIyHlWG3B0uMTjHCTqtTLr3obFjxtkYCwNmnRv+VX/8nBME O5XQ== X-Gm-Message-State: AOAM532yJeNcyVJ/ERqk08oGH5cn4A7HmClcEEvcXOgSMmfHE6kYo+35 t5+n3aHtUpDAJ1/tkYvHOvBuYa8BgkI= X-Google-Smtp-Source: ABdhPJzCKpTfCklgdTqBWfC/JE0O73kzE6vZintXmtJ8GikPR/z3QX41BuCSC4WMaRtPeur8DO/uCRcZGq4= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a5b:c0e:0:b0:65c:bfb5:2acf with SMTP id f14-20020a5b0c0e000000b0065cbfb52acfmr14300899ybq.216.1654305720843; Fri, 03 Jun 2022 18:22:00 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:50 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-35-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 34/42] KVM: selftests: Use this_cpu_has() to detect SVM support in L1 From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace an evil open coded instance of querying CPUID from L1 with this_cpu_has(X86_FEATURE_SVM). No functional change intended. Signed-off-by: Sean Christopherson --- .../testing/selftests/kvm/include/x86_64/svm_util.h | 13 ------------- tools/testing/selftests/kvm/x86_64/smm_test.c | 4 ++-- tools/testing/selftests/kvm/x86_64/state_test.c | 2 +- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/svm_util.h b/tools/= testing/selftests/kvm/include/x86_64/svm_util.h index f48806d26989..a339b537a575 100644 --- a/tools/testing/selftests/kvm/include/x86_64/svm_util.h +++ b/tools/testing/selftests/kvm/include/x86_64/svm_util.h @@ -13,9 +13,6 @@ #include "svm.h" #include "processor.h" =20 -#define CPUID_SVM_BIT 2 -#define CPUID_SVM BIT_ULL(CPUID_SVM_BIT) - #define SVM_EXIT_EXCP_BASE 0x040 #define SVM_EXIT_HLT 0x078 #define SVM_EXIT_MSR 0x07c @@ -52,16 +49,6 @@ struct svm_test_data *vcpu_alloc_svm(struct kvm_vm *vm, = vm_vaddr_t *p_svm_gva); void generic_svm_setup(struct svm_test_data *svm, void *guest_rip, void *g= uest_rsp); void run_guest(struct vmcb *vmcb, uint64_t vmcb_gpa); =20 -static inline bool cpu_has_svm(void) -{ - u32 eax =3D 0x80000001, ecx; - - asm("cpuid" : - "=3Da" (eax), "=3Dc" (ecx) : "0" (eax) : "ebx", "edx"); - - return ecx & CPUID_SVM; -} - int open_sev_dev_path_or_exit(void); =20 #endif /* SELFTEST_KVM_SVM_UTILS_H */ diff --git a/tools/testing/selftests/kvm/x86_64/smm_test.c b/tools/testing/= selftests/kvm/x86_64/smm_test.c index 40581704f129..7937db5b1037 100644 --- a/tools/testing/selftests/kvm/x86_64/smm_test.c +++ b/tools/testing/selftests/kvm/x86_64/smm_test.c @@ -83,7 +83,7 @@ static void guest_code(void *arg) sync_with_host(4); =20 if (arg) { - if (cpu_has_svm()) { + if (this_cpu_has(X86_FEATURE_SVM)) { generic_svm_setup(svm, l2_guest_code, &l2_guest_stack[L2_GUEST_STACK_SIZE]); } else { @@ -99,7 +99,7 @@ static void guest_code(void *arg) =20 sync_with_host(7); =20 - if (cpu_has_svm()) { + if (this_cpu_has(X86_FEATURE_SVM)) { run_guest(svm->vmcb, svm->vmcb_gpa); run_guest(svm->vmcb, svm->vmcb_gpa); } else { diff --git a/tools/testing/selftests/kvm/x86_64/state_test.c b/tools/testin= g/selftests/kvm/x86_64/state_test.c index 35e96d7a6ba1..d37e25229fe5 100644 --- a/tools/testing/selftests/kvm/x86_64/state_test.c +++ b/tools/testing/selftests/kvm/x86_64/state_test.c @@ -142,7 +142,7 @@ static void __attribute__((__flatten__)) guest_code(voi= d *arg) GUEST_SYNC(2); =20 if (arg) { - if (cpu_has_svm()) + if (this_cpu_has(X86_FEATURE_SVM)) svm_l1_guest_code(arg); else vmx_l1_guest_code(arg); --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AF0CC43334 for ; Sat, 4 Jun 2022 01:24:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350305AbiFDBY2 (ORCPT ); Fri, 3 Jun 2022 21:24:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350197AbiFDBXH (ORCPT ); Fri, 3 Jun 2022 21:23:07 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A1982CC8D for ; Fri, 3 Jun 2022 18:22:12 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id ob5-20020a17090b390500b001e2f03294a7so8044376pjb.8 for ; Fri, 03 Jun 2022 18:22:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=zRnQwmzMhJYRFOk2BpYJxE9o1Wk/uaPq5tbGkr4yB8o=; b=CB6KKHeU8XXyGZXIbX7xPsH4SKxTfArunR9G5W48eK0S5G9Kg40lHnU7yb7pxqJYlA OuHJlnVVDlDIbxx7rqiFpoohqofryjXt/oX0/vEdzy5F8BFuVcVjmSSRKw054yfDX8MB WJ3lob8fGw8MrHsrVOb+LUoMh/ywcbWblskaBDIArLnvZ5Ka/LSv9jYKMOeM3+YQcwfP CHIyr7Qoj7OWO3N8w3GIRgtLWmSGTTCrOZHRSI0efsRYUFQQRmFoQOLL01FJJ9SbBQnU 3JXNhCgOfm1TV0JYqipaVZG4EMz22Vw7gNsEbyW1+FwZi7k4KAV6atHrzFpvEaLkBXWm HjjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=zRnQwmzMhJYRFOk2BpYJxE9o1Wk/uaPq5tbGkr4yB8o=; b=zRBBc7g+wUCQAu1m1xPNIDYte2ejGV7yBzGFHpeP96RNCdv7DzGVSZA5PyLUKc+vNd vBLjtDz0rA1xW0pi0+e3RDHgOL28nxeBIA45Uav3ggDUp7wXZ3fyEzElQEHnb41jjXaN LqdSdrlPY1+6UvYxDftVFLpBnfgdnj83ovpFM+QUB/TmpU/tW5aXY4VboOpwil7gPLQE wvAXupk8kFPHpuL4JpUZozebI9dm3BmttCC+e10Ho6/tkb/MebjE25Pb6k5cOD9Tfp6f sNVzVGU11EXYRCrpmAuMwwU+aUpuKWYWSidsJfKnjrFKzi4eJ7KE67TCmw285A7DuJss 0NVQ== X-Gm-Message-State: AOAM533mi3PTUtTe6ymsdZCp1+d6pRO5hAUy3iJE77ZzeYCbIl+o5P+s QExccNxXIuzFUcIKlzRIsfQ4EKJesbI= X-Google-Smtp-Source: ABdhPJyc75pztoF7EwnBRfDnBKRcklxM/YhAubdHefgT1Peoo3ESR9hq5FR8mpqA13agZKWGI2zELjJYCxY= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90a:ba11:b0:1df:2d09:1308 with SMTP id s17-20020a17090aba1100b001df2d091308mr13482968pjr.184.1654305722431; Fri, 03 Jun 2022 18:22:02 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:51 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-36-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 35/42] KVM: selftests: Drop unnecessary use of kvm_get_supported_cpuid_index() From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use kvm_get_supported_cpuid_entry() instead of kvm_get_supported_cpuid_index() when passing in '0' for the index, which just so happens to be the case in all remaining users of kvm_get_supported_cpuid_index() except kvm_get_supported_cpuid_entry(). Keep the helper as there may be users in the future, and it's not doing any harm. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/x86_64/amx_test.c | 2 +- tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c | 4 ++-- tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/= selftests/kvm/x86_64/amx_test.c index a886c9e81b87..411a33cd4296 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -318,7 +318,7 @@ int main(int argc, char *argv[]) TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_XTILEDATA)); =20 /* Get xsave/restore max size */ - xsave_restore_size =3D kvm_get_supported_cpuid_index(0xd, 0)->ecx; + xsave_restore_size =3D kvm_get_supported_cpuid_entry(0xd)->ecx; =20 run =3D vcpu->run; vcpu_regs_get(vcpu, ®s1); diff --git a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c b/t= ools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c index 5321bfe8b4e9..af018af2d54d 100644 --- a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c +++ b/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c @@ -376,7 +376,7 @@ static bool use_intel_pmu(void) { const struct kvm_cpuid_entry2 *entry; =20 - entry =3D kvm_get_supported_cpuid_index(0xa, 0); + entry =3D kvm_get_supported_cpuid_entry(0xa); return is_intel_cpu() && check_intel_pmu_leaf(entry); } =20 @@ -408,7 +408,7 @@ static bool use_amd_pmu(void) { const struct kvm_cpuid_entry2 *entry; =20 - entry =3D kvm_get_supported_cpuid_index(1, 0); + entry =3D kvm_get_supported_cpuid_entry(1); return is_amd_cpu() && (is_zen1(entry->eax) || is_zen2(entry->eax) || diff --git a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c b/tools= /testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c index 689517f2aae6..6ec901dab61e 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c @@ -69,7 +69,7 @@ int main(int argc, char *argv[]) TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_PDCM)); =20 TEST_REQUIRE(kvm_get_cpuid_max_basic() >=3D 0xa); - entry_a_0 =3D kvm_get_supported_cpuid_index(0xa, 0); + entry_a_0 =3D kvm_get_supported_cpuid_entry(0xa); =20 eax.full =3D entry_a_0->eax; __TEST_REQUIRE(eax.split.version_id, "PMU is not supported by the vCPU"); --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09DCAC433EF for ; Sat, 4 Jun 2022 01:25:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350472AbiFDBZA (ORCPT ); Fri, 3 Jun 2022 21:25:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350295AbiFDBXJ (ORCPT ); Fri, 3 Jun 2022 21:23:09 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E30D2E090 for ; Fri, 3 Jun 2022 18:22:14 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id lk16-20020a17090b33d000b001e68a9ac3a1so3460543pjb.2 for ; Fri, 03 Jun 2022 18:22:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=Or9oZigrlqmog/yA1fZLlOqMIX7r2SC754YtuTj7pwE=; b=TePavb7uMhS7u9l5A/7K5usYxLzh0hNGrwjp1dzSiUJ/o6s2t7aHGWeI1BUaq8blbd ETh+obtLZ8N87UBWog4wGYhdyKzT6XEGYJTQBJShdU2aGvGOeUyL8os5tEBk1sAoJZZD F2iV7qFJSbwFM6VR/B+TUrGLu5AWvlt8LocMh70ZbH9wK8UwXxaucev6kS//x4g0s3vG zL1N6ChYD8hQEGtU+cNfoKzWJy+GBHNgSEmBcxy49asC/DXkRzIgtk3AZXacXnS1ILpW l9fIfXdH5udx/YQFU8XQdBd/yi9P64yYdPI+I7hRBaDg7oA8UG9Aoy/77vBZaUSPEwnc PCkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=Or9oZigrlqmog/yA1fZLlOqMIX7r2SC754YtuTj7pwE=; b=y6oIwGHHUx5zZUgS9D23RENSvXsSSd57lAJbrO+3yltDeMBxhWxZ5tR6JDJKXV2Gpn SXDoi82akxPOdHPjWJc0pThavffsROJgMsaKuM+Oipvm7jchTXwJP7MX6xvgWHtK3fDL wuQ6o/LqhWP4bv7MdHUS7peE+2IL4i5FT5zf9ZqPKDbXXY73+FKP5j5pv4VtDUjkpL6c ti0Zs3eHEQe1DexkNRJewZO22cWznn4NpBW5DEoTltgLeoEreTCmGsW+8be1HNGjTYJr B1DtG5A+cWWZ3FNfoldMtxgDfrE8882B9lnXt9snbeCFdJpo1mqALSS80BJfRD7LpAPA WBFA== X-Gm-Message-State: AOAM531hF1X4y/dEDGAR4y22lH27CXKk5HDSbE4Y+z1EZyNcwuC2JpN5 A9M5uH8NYrQYKoYoBAZlc/EwAWJFzBE= X-Google-Smtp-Source: ABdhPJxy1slOBG+i324d2rxO7aa0HIIwMDM/x5I1K9FxYS05V3hXvz9Jq9UVyb+l8/30ynoIuwoVqAGIQcI= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90b:1e01:b0:1e3:1f4c:dd71 with SMTP id pg1-20020a17090b1e0100b001e31f4cdd71mr13860248pjb.168.1654305724515; Fri, 03 Jun 2022 18:22:04 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:52 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-37-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 36/42] KVM: selftests: Rename kvm_get_supported_cpuid_index() to __..._entry() From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rename kvm_get_supported_cpuid_index() to __kvm_get_supported_cpuid_entry() to better show its relationship to kvm_get_supported_cpuid_entry(), and because the helper returns a CPUID entry, not the index of an entry. No functional change intended. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/x86_64/processor.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index db724670c895..b47291347a5d 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -697,15 +697,15 @@ static inline void vcpu_clear_cpuid_feature(struct kv= m_vcpu *vcpu, vcpu_set_or_clear_cpuid_feature(vcpu, feature, false); } =20 -static inline const struct kvm_cpuid_entry2 *kvm_get_supported_cpuid_index= (uint32_t function, - uint32_t index) +static inline const struct kvm_cpuid_entry2 *__kvm_get_supported_cpuid_ent= ry(uint32_t function, + uint32_t index) { return get_cpuid_entry(kvm_get_supported_cpuid(), function, index); } =20 static inline const struct kvm_cpuid_entry2 *kvm_get_supported_cpuid_entry= (uint32_t function) { - return kvm_get_supported_cpuid_index(function, 0); + return __kvm_get_supported_cpuid_entry(function, 0); } =20 uint64_t vcpu_get_msr(struct kvm_vcpu *vcpu, uint64_t msr_index); --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFE87C433EF for ; Sat, 4 Jun 2022 01:24:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348452AbiFDBYz (ORCPT ); Fri, 3 Jun 2022 21:24:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350143AbiFDBXK (ORCPT ); Fri, 3 Jun 2022 21:23:10 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDA682E9CC for ; Fri, 3 Jun 2022 18:22:14 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id g129-20020a636b87000000b003fd1deac6ebso1652919pgc.23 for ; Fri, 03 Jun 2022 18:22:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=D4pd0B8lUuq0zciMBRqcW64B09BKAynerT7v02hMJtY=; b=YRimQa6jGuJsBY2uXFkR87Hx13Z2P1/N41Jjl148F5J9r0rulXps8xOfSPm9wu/ahz a/Ae8qAu+867Thxcrt3iATtARm4do4MQ7puevwwNbOPRTRYPnAsRCjee/1Q12Wb/MRbS de2eEIkdvv1Jzv60T1mS+SU/93qaGAjwi3EvbbHOjIbLoZOaIQxFwCnMp69h+Qyjl5h4 Fk42oqb73L52B9c8XRggTZZwd0AmLXbO28xThwO2UgX+v2u0BeJ9NItbtSS2+9fUSfAH NjalDGSlPZSlUN30ZZbhz3LHUWoc8qQ//rXZa2RcZipOxkqKjgBksyPSYXrCvPFPmSk5 iUeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=D4pd0B8lUuq0zciMBRqcW64B09BKAynerT7v02hMJtY=; b=rXN5lbdAaPo2Pjz+SjJH/8USAqqWBxz8622FcwNPwQmejGTmpCcSXYhkq/w3XGDeox wh1cxIw3yqU7g6yKlNj3bMyRyJqnFs1zxAPyyVcAspglOV83unSk8+V0P7CEe5otmBMn ovWUDbw0NNmLLeMna9WGIlSXM0LqIrWIRkBb1aVt67FQxLDQnFMiIOl9SiVwjORtWR2Y RD2YSUF1TUa+Hjqd5d69gygfAmI02rvW8KGgAXGto+nL7RsKiEKE5eU8QjU4TrBBFXoH 3hkpKzfDFajie8HFzQmYA7QJLY93+FGT9ZEoO3LoLcXPO0y4Xl/Au4lED/RrC2QwetFz lJTA== X-Gm-Message-State: AOAM531H2XIKP5qUu2sB4Q+XofSQ3Rmpp1dQze6gDaGqGPy+20My0Vx2 UmdS7DriN4a1qTZgBD/S3aQSwA5tbWo= X-Google-Smtp-Source: ABdhPJz0UhqZv7zIUir0euaZw0GP9YWAeknDoZdsiE2M9GcM304y4Czt1+UOVp1Lv8jLr8ouX2q8ORK8QtY= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6a00:1744:b0:51b:d4d5:f34 with SMTP id j4-20020a056a00174400b0051bd4d50f34mr8619159pfc.0.1654305725916; Fri, 03 Jun 2022 18:22:05 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:53 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-38-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 37/42] KVM: selftests: Inline "get max CPUID leaf" helpers From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make the "get max CPUID leaf" helpers static inline, there's no reason to bury the one liners in processor.c. Signed-off-by: Sean Christopherson --- .../testing/selftests/kvm/include/x86_64/processor.h | 11 +++++++++-- tools/testing/selftests/kvm/lib/x86_64/processor.c | 10 ---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index b47291347a5d..473501e5776e 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -719,9 +719,16 @@ static inline void vcpu_set_msr(struct kvm_vcpu *vcpu,= uint64_t msr_index, TEST_ASSERT(r =3D=3D 1, KVM_IOCTL_ERROR(KVM_SET_MSRS, r)); } =20 +static inline uint32_t kvm_get_cpuid_max_basic(void) +{ + return kvm_get_supported_cpuid_entry(0)->eax; +} + +static inline uint32_t kvm_get_cpuid_max_extended(void) +{ + return kvm_get_supported_cpuid_entry(0x80000000)->eax; +} =20 -uint32_t kvm_get_cpuid_max_basic(void); -uint32_t kvm_get_cpuid_max_extended(void); void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bit= s); bool vm_is_unrestricted_guest(struct kvm_vm *vm); =20 diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index 1d92a1d9a03f..0f36f8ac7e9d 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1057,16 +1057,6 @@ bool is_amd_cpu(void) return cpu_vendor_string_is("AuthenticAMD"); } =20 -uint32_t kvm_get_cpuid_max_basic(void) -{ - return kvm_get_supported_cpuid_entry(0)->eax; -} - -uint32_t kvm_get_cpuid_max_extended(void) -{ - return kvm_get_supported_cpuid_entry(0x80000000)->eax; -} - void kvm_get_cpu_address_width(unsigned int *pa_bits, unsigned int *va_bit= s) { const struct kvm_cpuid_entry2 *entry; --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25796C43334 for ; Sat, 4 Jun 2022 01:24:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350423AbiFDBYq (ORCPT ); Fri, 3 Jun 2022 21:24:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350222AbiFDBXZ (ORCPT ); Fri, 3 Jun 2022 21:23:25 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EC8D2EA34 for ; Fri, 3 Jun 2022 18:22:16 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id j25-20020aa78d19000000b0051bb0c362a5so4705404pfe.19 for ; Fri, 03 Jun 2022 18:22:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=EAmGvaProE4PEjXpsn+IRdGnIMemtg0iePn8LC3Ji8I=; b=QK6UdgjffKn9rdPMund/0BPWiiPZ/3DtkvFH12wlU5ohRrxdqTx9WqhPbVlSFfAo+y O5LDEdYHi2rmGlJTWaelmfNTL37GekLMLfFGW+DjiRSC8DynEX2C+ATYugd8FiTdxodU zoap6iCEBZ2bIB8TluaCBI4QRrM+F3c7O35VAvMa/OcitnFcE0KojOB6TZsFr1wkCmjs ubxFCARGeNujPV/7wmqQazJXFqcxn5bEydhJ0pQ1X2Li3ZuAVBL7+T8unc5NjYuSTX6N nzw7tuwxFzobdMxcb6dIfypTjultnX60Roy68GghyW9off9ElriXu+K/ZqhHpa2sw0tU ycrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=EAmGvaProE4PEjXpsn+IRdGnIMemtg0iePn8LC3Ji8I=; b=bgvFLx6rh843bBk3JQCD3Uza8qFW0qbZB7TM3PSeL3qquV810UHSpEVW23T7NmobXa jh6mNNTu9/C+uNzeQNbBmZpM91mVAAbB5PvE145q1B95yzQBcYwB/b6Vt5/xnXnItJDh a+0SK6rMpihJud0KmgbSDHCOkHkOanP4PoIAHxCpp+Q1Wxyzdy1Z6KBV++Bxyyo+pb0a lI5PlvOC9uFdmp5/UGCa3FsP+QYNtvZNsPJ5hJL92E6mBnUjWopbVmcJ/EwckETROHHk siQLd573lEZLV3hEJhagtKYcQqfn3jiE0kLpaxOZtNXUgkpwbXX5zo6/Ui5VmLqzkqSu xCfQ== X-Gm-Message-State: AOAM533nAqyHX+omtIlG0xsOPVwCCK2ZUWh5+huUYzBz/fUQaWezlRoO w/fEOfRXOKlcATuoq7G9k1p44tA5Rc4= X-Google-Smtp-Source: ABdhPJwAssVlPRuoRdBIUw3WgLM8FNQmwoB8X3XgmYMb4uyqAlmhzCw8s3VryspK6lEVoqihYJQwR7Xg9Wc= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6a00:21cd:b0:4e1:5008:adcc with SMTP id t13-20020a056a0021cd00b004e15008adccmr12578140pfj.35.1654305727650; Fri, 03 Jun 2022 18:22:07 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:54 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-39-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 38/42] KVM: selftests: Check KVM's supported CPUID, not host CPUID, for XFD From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use kvm_cpu_has() to check for XFD supported in vm_xsave_req_perm(), simply checking host CPUID doesn't guarantee KVM supports AMX/XFD. Opportunistically hoist the check above the bit check; if XFD isn't supported, it's far better to get a "not supported at all" message, as opposed to a "feature X isn't supported" message". Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/x86_64/processor.h | 1 + .../selftests/kvm/lib/x86_64/processor.c | 19 ++----------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index 473501e5776e..e97b7c4ce367 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -115,6 +115,7 @@ struct kvm_x86_cpu_feature { #define X86_FEATURE_XTILECFG KVM_X86_CPU_FEATURE(0xD, 0, EAX, 17) #define X86_FEATURE_XTILEDATA KVM_X86_CPU_FEATURE(0xD, 0, EAX, 18) #define X86_FEATURE_XSAVES KVM_X86_CPU_FEATURE(0xD, 1, EAX, 3) +#define X86_FEATURE_XFD KVM_X86_CPU_FEATURE(0xD, 1, EAX, 4) =20 /* * Extended Leafs, a.k.a. AMD defined diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index 0f36f8ac7e9d..f1290540210d 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -579,21 +579,6 @@ static void vcpu_setup(struct kvm_vm *vm, struct kvm_v= cpu *vcpu) vcpu_sregs_set(vcpu, &sregs); } =20 -#define CPUID_XFD_BIT (1 << 4) -static bool is_xfd_supported(void) -{ - int eax, ebx, ecx, edx; - const int leaf =3D 0xd, subleaf =3D 0x1; - - __asm__ __volatile__( - "cpuid" - : /* output */ "=3Da"(eax), "=3Db"(ebx), - "=3Dc"(ecx), "=3Dd"(edx) - : /* input */ "0"(leaf), "2"(subleaf)); - - return !!(eax & CPUID_XFD_BIT); -} - void vm_xsave_req_perm(int bit) { int kvm_fd; @@ -605,6 +590,8 @@ void vm_xsave_req_perm(int bit) .addr =3D (unsigned long) &bitmask }; =20 + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_XFD)); + kvm_fd =3D open_kvm_dev_path_or_exit(); rc =3D __kvm_ioctl(kvm_fd, KVM_GET_DEVICE_ATTR, &attr); close(kvm_fd); @@ -615,8 +602,6 @@ void vm_xsave_req_perm(int bit) =20 TEST_REQUIRE(bitmask & (1ULL << bit)); =20 - TEST_REQUIRE(is_xfd_supported()); - rc =3D syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_GUEST_PERM, bit); =20 /* --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D591FC43334 for ; Sat, 4 Jun 2022 01:24:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350288AbiFDBYS (ORCPT ); Fri, 3 Jun 2022 21:24:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350182AbiFDBXG (ORCPT ); Fri, 3 Jun 2022 21:23:06 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAD5627FF3 for ; Fri, 3 Jun 2022 18:22:09 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id i19-20020aa79093000000b0050d44b83506so4703309pfa.22 for ; Fri, 03 Jun 2022 18:22:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=lWV4XxAQvtLDWa2n9sU/+Ng/xr6r4/W2FZ+RD8jHsW8=; b=pr+wWRe4GMnyYbms8mLJXpQ81expnFnSAA0vIhEn39IdHEZVE+uKJmZnzhwEO6d5bg 9jx4XGUBFdaxX87ij2BFaHP2PxM6sOE+ujU9rZ2ltljvlqb60kZWEUA1tQYi9RllK/PC 9Kd0YcUMZxdxJ54eX/Z30Wb+OXsHo5GDudAq9DObmcybrPce5hKtnUncJ0ohEQ3YOpP/ 0LscbI9J8m0/FofNyXnaGMabv02ch9FpiVNOSJ3QZ4TYRKD4o2/NyMSgvs7LSfozUmbL PwPXb/NAkdCW9zLemXfaxBk5gHZbsafOSAxt39DZghh3+jOW2pbwJQalRhBnhafaZX8i XcEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=lWV4XxAQvtLDWa2n9sU/+Ng/xr6r4/W2FZ+RD8jHsW8=; b=M8J1t4McjG/JMBn5X2eNTjAcDk+K3BxENbMARvygGEEeRRefU72M7vc0Gw4/IJDS/y oy6NwO64y7ZtjaD9v+7v4hpMl2f2zKyPSfjFTkKPZWvbYPbneQ+I62QYk3XZJpxYicDw 8nmo4q4TNofTYWntDkkqgAo5A1PZgDdNmxHsSO43G57V/yuT0fuskdpyt3L4tejAa2FP VbfgMcIHozM6d5BDNY4NTDuKNbRE9uWs3/2bKMUks0YGvXDC4Qi/wg+pW5/iQTvsTg6Z TiDu8hOdRrLnhXLqhLvQ8eSxmAyRbOnNQWg1MyGe7Z45ODIzlHy0MdFmWe7NoPbbB+wy mQfQ== X-Gm-Message-State: AOAM533xZGBEAKUxxdWyMYo8/kn8iakPBPPO+PXUBKjZnUL5rIUheCoC 2nPSSkP1zJAKVSU59BU8eSJYU6APBPY= X-Google-Smtp-Source: ABdhPJz33S1yjm2idJ8lnaWSE4xhl4nxGv29a7i4KIV4TrX+Yq5aJj/G2Lur+mmWw7sonU2o73vNWaq8d20= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6a00:a8b:b0:4e1:52db:9e5c with SMTP id b11-20020a056a000a8b00b004e152db9e5cmr79230988pfl.38.1654305729378; Fri, 03 Jun 2022 18:22:09 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:55 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-40-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 39/42] KVM: selftests: Skip AMX test if ARCH_REQ_XCOMP_GUEST_PERM isn't supported From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Skip the AMX test instead of silently returning if the host kernel doesn't support ARCH_REQ_XCOMP_GUEST_PERM. KVM didn't support XFD until v5.17, so it's extremely unlikely allowing the test to run on a pre-v5.15 kernel is the right thing to do. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/lib/x86_64/processor.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index f1290540210d..86e610967e79 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -602,14 +602,7 @@ void vm_xsave_req_perm(int bit) =20 TEST_REQUIRE(bitmask & (1ULL << bit)); =20 - rc =3D syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_GUEST_PERM, bit); - - /* - * The older kernel version(<5.15) can't support - * ARCH_REQ_XCOMP_GUEST_PERM and directly return. - */ - if (rc) - return; + TEST_REQUIRE(!syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_GUEST_PERM, bit)); =20 rc =3D syscall(SYS_arch_prctl, ARCH_GET_XCOMP_GUEST_PERM, &bitmask); TEST_ASSERT(rc =3D=3D 0, "prctl(ARCH_GET_XCOMP_GUEST_PERM) error: %ld", r= c); --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC6C8C43334 for ; Sat, 4 Jun 2022 01:25:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348297AbiFDBZJ (ORCPT ); Fri, 3 Jun 2022 21:25:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350321AbiFDBXq (ORCPT ); Fri, 3 Jun 2022 21:23:46 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF3D12FFD0 for ; Fri, 3 Jun 2022 18:22:20 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id u67-20020a627946000000b0051b9c1256b0so4720051pfc.9 for ; Fri, 03 Jun 2022 18:22:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=A+L4jwrNVFSobkDaNlEHqZZXKqAiVfG+Yz1ECFVoH7Q=; b=HClLGhYby2O6RWKIEcvB51oC+LESLcXBFm+QPDW4faSXz8u/ADPEgTOFSi1b/DDmYF ZHu4sFU1Hf5EuYnyukOn5QYVosm5hyXnuiohksPACKw5KpIcUdx6yh/9/bSE5oN+5rlK lKwkweL4a9GsPCllj8CzJjdXi+7lAIKD1jDrywxjlhXKp/t20JG5kBWawSpncwPve41f CJj9oPnATjpYJj3GkCWYuL08925Jqeah0+/SD4TYylpKF5XEejPasZ/UTZe3K2OkI5up BOT7cf1NmXwh/dX/OLCLZ/i+HIw05jmvq5J03GVmEVupmvqO0mx3wDLscfTeYCZhkmIY Pa8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=A+L4jwrNVFSobkDaNlEHqZZXKqAiVfG+Yz1ECFVoH7Q=; b=ILt9ygH0yvITYiL/4BuSg/X2h8BxtQ0EUHtJZEhkPOcaPBeSsMWhA7HcmvoqItwUqk h07czGCpR8UbOiY2gs9Cz5rsXjB0Y7zxNx6Z8lNTa0N0cymkBO8h7f1RneJvdrlzRk09 ZSECr/vBHge5SSREGYRKfaUEFWzPoI9Cwqn/4vk0QsGQQcezYwH4e71pSbvwdqEd9EU9 ATlXGPOf/L2J/mNOTWEjYS4Z+sFumL1wVlgCFkIEnNgRG2NN+zKP5/2DPfZ4xz/unja8 GY+k8UtvPI8ERTDrrA8RLWo4OCtHhAdo0ycW/rskF/EGjv2Zp+eL34REj9sUqa3NEAIr csAA== X-Gm-Message-State: AOAM533uP05+kFkvGmU+EOj8G0doqXTIOwJlckc0v6MihfEaNsIh9OyJ 0KKu2YCMjN0R62lqyGKp/CoA2hsznLI= X-Google-Smtp-Source: ABdhPJzEtoqkkyDnh1nYx3K/1boz5Ym37vwjBt8KpMw9Fqj5RUpFpkiIeVTrXaMlyUkmaUk9JYjOCaYYpKA= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6a00:23ce:b0:50d:823f:981 with SMTP id g14-20020a056a0023ce00b0050d823f0981mr12822497pfc.10.1654305731282; Fri, 03 Jun 2022 18:22:11 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:56 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-41-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 40/42] KVM: selftests: Clean up requirements for XFD-aware XSAVE features From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Provide informative error messages for the various checks related to requesting access to XSAVE features that are buried behind XSAVE Feature Disabling (XFD). Opportunistically rename the helper to have "require" in the name so that it's somewhat obvious that the helper may skip the test. Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/x86_64/processor.h | 5 ++++- tools/testing/selftests/kvm/lib/x86_64/processor.c | 8 +++++--- tools/testing/selftests/kvm/x86_64/amx_test.c | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools= /testing/selftests/kvm/include/x86_64/processor.h index e97b7c4ce367..3fd3d58148c2 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -758,7 +758,10 @@ void vm_set_page_table_entry(struct kvm_vm *vm, struct= kvm_vcpu *vcpu, uint64_t kvm_hypercall(uint64_t nr, uint64_t a0, uint64_t a1, uint64_t a2, uint64_t a3); =20 -void vm_xsave_req_perm(int bit); +void __vm_xsave_require_permission(int bit, const char *name); + +#define vm_xsave_require_permission(perm) \ + __vm_xsave_require_permission(perm, #perm) =20 enum x86_page_size { X86_PAGE_SIZE_4K =3D 0, diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index 86e610967e79..6e8c8781996c 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -579,7 +579,7 @@ static void vcpu_setup(struct kvm_vm *vm, struct kvm_vc= pu *vcpu) vcpu_sregs_set(vcpu, &sregs); } =20 -void vm_xsave_req_perm(int bit) +void __vm_xsave_require_permission(int bit, const char *name) { int kvm_fd; u64 bitmask; @@ -597,10 +597,12 @@ void vm_xsave_req_perm(int bit) close(kvm_fd); =20 if (rc =3D=3D -1 && (errno =3D=3D ENXIO || errno =3D=3D EINVAL)) - exit(KSFT_SKIP); + __TEST_REQUIRE(0, "KVM_X86_XCOMP_GUEST_SUPP not supported"); + TEST_ASSERT(rc =3D=3D 0, "KVM_GET_DEVICE_ATTR(0, KVM_X86_XCOMP_GUEST_SUPP= ) error: %ld", rc); =20 - TEST_REQUIRE(bitmask & (1ULL << bit)); + __TEST_REQUIRE(bitmask & (1ULL << bit), + "Required XSAVE feature '%s' not supported", name); =20 TEST_REQUIRE(!syscall(SYS_arch_prctl, ARCH_REQ_XCOMP_GUEST_PERM, bit)); =20 diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/= selftests/kvm/x86_64/amx_test.c index 411a33cd4296..5d749eae8c45 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -307,7 +307,7 @@ int main(int argc, char *argv[]) u32 amx_offset; int stage, ret; =20 - vm_xsave_req_perm(XSTATE_XTILE_DATA_BIT); + vm_xsave_require_permission(XSTATE_XTILE_DATA_BIT); =20 /* Create VM */ vm =3D vm_create_with_one_vcpu(&vcpu, guest_code); --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D980DC43334 for ; Sat, 4 Jun 2022 01:25:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348974AbiFDBZO (ORCPT ); Fri, 3 Jun 2022 21:25:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350378AbiFDBYK (ORCPT ); Fri, 3 Jun 2022 21:24:10 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E0333137E for ; Fri, 3 Jun 2022 18:22:26 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id nn14-20020a17090b38ce00b001e00df82de8so8063384pjb.1 for ; Fri, 03 Jun 2022 18:22:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=zvdMWaNQyj+1nBM7oAXW7KQ3veP+NMow+sZ2whewgkw=; b=nyLv+kLSFreAJTA00NX6HWxg0pjEOoRCO2HC5ufkIJPUJhf3fFpgtJtyBtv4Qt03+5 u1FriqtXRqmJiVpZ41bJw4Avvmd0fUzCVxlslfZBGWUDWSuuTLuseV6QShb105jYCkFg Ur+cvuroKi1t9F8v51EBSlsoGexyGO/34Q2/Tfv3Jf0ZiaMEkG4yw5xLM4yU+Kqm53sw yCnaPRX7dCYboyHUMrppOqRmRXgaUF12mJOBHuMHkVkeGYaoaD1GzoxsWo46QMwzWMux CeGzQ4+rmDirxDR+ZPGr03T657iX9vHlM4dp32IFIL5RtSlSocDVarnlkFKgQPRERXAH F/9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=zvdMWaNQyj+1nBM7oAXW7KQ3veP+NMow+sZ2whewgkw=; b=ZKb3UXxDrRM4jKpA6zi4Jc3oR0g+wRfMYUOAkN/beuWwtP3BK1AZYs4pr9cl1b/qiL nOJmhKJGROeqBkqbQRSr9hpGkkiT+b2h9NfZTezQVrhCNKS722/qbnArxTWz2xSviUW2 V/0LdMBAR4hVVk26MlkhFMQItoilTZBiyFHkKtzSXu0WIFgC1Fle5z++J7KA4oQ0MDpj mSXLqvK0FZSM1AMEwocgCs1PAXUYTZKmWlGzaFgyrP0B534EZCnsYfmc5I2qvS/rqvcH fQ5Ls6akEqG+n7MTR1M8hLIm5whLVwMzrdDzaSwOIBsDJpOZJwq2wOcR+MsaMYFGmGZZ KyLw== X-Gm-Message-State: AOAM531ABRh5ii1/hlHzzCOhigg0iBc9awlylERiCrFkyAHEJy9PUrEi 6xj24qMV/mEY6yO2JltKm8xXXqUCdmk= X-Google-Smtp-Source: ABdhPJyC/2HAsAcHNEpSJJ4V8icJsGEtvYteBV/YCrRlDSO8VRpS4vFTEaPdyM6FyjkfbAZj51MrIgOLvRc= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:903:41d1:b0:166:3c6:f055 with SMTP id u17-20020a17090341d100b0016603c6f055mr12689754ple.112.1654305733221; Fri, 03 Jun 2022 18:22:13 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:57 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-42-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 41/42] KVM: selftests: Use the common cpuid() helper in cpu_vendor_string_is() From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use cpuid() to get CPUID.0x0 in cpu_vendor_string_is(), thus eliminating the last open coded usage of CPUID (ignoring debug_regs.c, which emits CPUID from the guest to trigger a VM-Exit and doesn't actually care about the results of CPUID). Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/lib/x86_64/processor.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index 6e8c8781996c..5cb73b2f9978 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1012,15 +1012,9 @@ void kvm_x86_state_cleanup(struct kvm_x86_state *sta= te) static bool cpu_vendor_string_is(const char *vendor) { const uint32_t *chunk =3D (const uint32_t *)vendor; - int eax, ebx, ecx, edx; - const int leaf =3D 0; - - __asm__ __volatile__( - "cpuid" - : /* output */ "=3Da"(eax), "=3Db"(ebx), - "=3Dc"(ecx), "=3Dd"(edx) - : /* input */ "0"(leaf), "2"(0)); + uint32_t eax, ebx, ecx, edx; =20 + cpuid(0, &eax, &ebx, &ecx, &edx); return (ebx =3D=3D chunk[0] && edx =3D=3D chunk[1] && ecx =3D=3D chunk[2]= ); } =20 --=20 2.36.1.255.ge46751e96f-goog From nobody Tue Apr 28 06:32:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53199C43334 for ; Sat, 4 Jun 2022 01:25:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350343AbiFDBZV (ORCPT ); Fri, 3 Jun 2022 21:25:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350219AbiFDBYK (ORCPT ); Fri, 3 Jun 2022 21:24:10 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06DB4313BB for ; Fri, 3 Jun 2022 18:22:27 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id ob5-20020a17090b390500b001e2f03294a7so8044634pjb.8 for ; Fri, 03 Jun 2022 18:22:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=JhO3Pfqpfwvl6Pg5WoaBIuDDbRoUFFPm/3/rKP0GHj0=; b=Ewgk0zIl2X4eFMXV19jbpEsGXZP6HUvKFsmTBBQURf4xxkDLnN3y+nfGhL8TD5/HUm Z9kQt98CuGzfgi0a52OIbLPgGgaZRKA4UdBv2Z/wpLG0/IapWCZwvP+O7qYR0QtHiVsr z7WYayl9SH5XEg9H08w+ffaOlTTG4acKKbVF+vQFcS9ITPDPWJ/k9o8CPS1N3oTe/NtN ns80BNtrZ4ZZ4jgyB43xntta8rLLHJnN3DftjSIvxTvnrJJxyZEalysDaneEUG/xN1fe MBEvRkLJTrW/bHL5G7Gqb4dapyfW9j+ivFUsPKPVzm8HBVWMdw5+8ORfLlHwEMXQBL+D IrZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=JhO3Pfqpfwvl6Pg5WoaBIuDDbRoUFFPm/3/rKP0GHj0=; b=KDuUyjTy7xH1bB8HlPEf+CUWRFwviI45bDokysWia/8Eg8Ri7MSAamwN2dLQm3o+rY SMMFALGbDBgfcxHll8VmABOLSbitxHYTWxcaNEsERXjEzmjbwwQ/lpWNKfas75s5mUf/ P+xW6ZZOk5GF5GX9AwE5du1ClfEjU9H8Q1kc3ZZvWQRt1ov2cQr+VlmgGu6VSbpHBQ3Q 24cslMdm9IxVEYGIoAHW+pHx31e+ZZPwxa8cWCk6Z81BnZ59chWorQ3/2xYoPDDYQT+7 fhrxLTJ7ObBRtXIIX3mqmYeqHz+0tb4/zcu3TNhADwokdF+SVTSLsUA2xjGtGkypCNZN 3K4A== X-Gm-Message-State: AOAM531k1CBrTVGVqlHiTMJQon4IZaNpL/OIJdCPI7znpr75v0uGfPqY cxqU5628BYTRZBBVrMbW3b/fNsu1E1Q= X-Google-Smtp-Source: ABdhPJxS2lZ7pIC8pnehjqv4quML9zflFji8IUQ+8TSateGizJ9gQSh2GlujdB+K0SgqNrmR1qE6j/TO4Gw= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:a517:b0:161:e5f2:9a26 with SMTP id s23-20020a170902a51700b00161e5f29a26mr12797900plq.132.1654305734883; Fri, 03 Jun 2022 18:22:14 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 4 Jun 2022 01:20:58 +0000 In-Reply-To: <20220604012058.1972195-1-seanjc@google.com> Message-Id: <20220604012058.1972195-43-seanjc@google.com> Mime-Version: 1.0 References: <20220604012058.1972195-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH 42/42] KVM: selftests: Drop unused SVM_CPUID_FUNC macro From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, Vitaly Kuznetsov , David Matlack , Jim Mattson , linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Drop SVM_CPUID_FUNC to reduce the probability of tests open coding CPUID checks instead of using kvm_cpu_has() or this_cpu_has(). Signed-off-by: Sean Christopherson --- tools/testing/selftests/kvm/include/x86_64/svm.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/svm.h b/tools/testi= ng/selftests/kvm/include/x86_64/svm.h index 2225e5077350..c8343ff84f7f 100644 --- a/tools/testing/selftests/kvm/include/x86_64/svm.h +++ b/tools/testing/selftests/kvm/include/x86_64/svm.h @@ -218,8 +218,6 @@ struct __attribute__ ((__packed__)) vmcb { struct vmcb_save_area save; }; =20 -#define SVM_CPUID_FUNC 0x8000000a - #define SVM_VM_CR_SVM_DISABLE 4 =20 #define SVM_SELECTOR_S_SHIFT 4 --=20 2.36.1.255.ge46751e96f-goog