From nobody Mon Apr 27 10:05:32 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 EC023CCA480 for ; Tue, 14 Jun 2022 20:07:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242345AbiFNUHS (ORCPT ); Tue, 14 Jun 2022 16:07:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347396AbiFNUHQ (ORCPT ); Tue, 14 Jun 2022 16:07:16 -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 7965A4D6AA for ; Tue, 14 Jun 2022 13:07:15 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id q2-20020a170902dac200b00168b3978426so5339247plx.17 for ; Tue, 14 Jun 2022 13:07: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=V4zIbtKJ1hQubZ2Po5itG3J6U3n8PHWRADbXM/EgI5s=; b=ipu+l6K1KLZTBB0JOCBxUwcMdeHTImhhfbvpc3v15RMSRz9Cgt3mQV6vmIiXbh7uAW PlKOvblbjVUNHpEUa+ucuCqWM6b3DrBUvS1WkH/rpBPGmsSQk8knZn24x5udaJ8M8Mc/ H5iK4fbagCGgntVT3iamNDONL8xoOkNX0yfOj7ow+nGfdqoiKXD6+Ml1mYHye9IZQAFS gsK1Y1c3Lc+Oc27TCOOBZA7krpgDk6IXrZSKgB6h+w+J8YPNwrZoOxLFl86ImWg1ddiD tDfeVH2svWqLZG4Pd19JsCRhEqKoopcdQijrPpPfwS67C4OuQWUF0yKHywPlkHHb8gtr y3mQ== 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=V4zIbtKJ1hQubZ2Po5itG3J6U3n8PHWRADbXM/EgI5s=; b=LtGNE7y6Kg8pWj87MG85zt/utDT5rsKcVFXz4NIG+C05Q725UxrkyBdi4q6qp6zRDA F7UV247Q8fZQaKhuWgMrNAK7TnmZrvCkwG+LJTVChtncuOxZ9igtk3YSqTWFA42FfFNy aY3Mch9l4XPHwSJtso0+v+45NmdAF2JVLZGvllx7eXBzUNz72+Ur9/N8HzCWuGoksDXm XVaoo5RevGEwv86IDFBrqSLkpgcPJX0Ue1sDamUz6f81/y+3wBop/M122o61ZC1R7V6k Lj4o1v+DmO7bBlcH0rYtxABFVUNBm1AFuZpQC+EkBhL1JBjMYxUmka323Rnk95/OJJ9n jBEw== X-Gm-Message-State: AJIora9Su0EsKTKU+dja9jllxh4yBPJYQw/QhsCnia9/pb7O9Kz83cc7 b/GHEFgHZ9BqbKwgRZSxvPXnWrYizgw= X-Google-Smtp-Source: AGRyM1vvDnbvaeDW3hTiZGuNUlGtl4c59JAQ9AXo/b96fG7zMYPGTEJ671xWzoiuXkNgsej2288gqhlk7qc= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90b:3a8f:b0:1e8:7669:8a2f with SMTP id om15-20020a17090b3a8f00b001e876698a2fmr6214455pjb.55.1655237234951; Tue, 14 Jun 2022 13:07:14 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:26 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-2-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 cdaea2383543..1b9e8719c624 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 39f2f5f1338f..38c6083c9ce1 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -392,11 +392,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 /* @@ -1813,7 +1819,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 4a7de11d6f37..c46a22f8a9af 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -663,6 +663,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 D08E2C433EF for ; Tue, 14 Jun 2022 20:07:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351825AbiFNUHb (ORCPT ); Tue, 14 Jun 2022 16:07:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350565AbiFNUHT (ORCPT ); Tue, 14 Jun 2022 16:07:19 -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 7CFFA4D6B0 for ; Tue, 14 Jun 2022 13:07:17 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id p143-20020a25d895000000b006648c7235a6so7717287ybg.1 for ; Tue, 14 Jun 2022 13:07: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=gFBrtRlDF3lH8d+M3xs/KaCiXtONEeFHhxQZdekcdbU=; b=RwZiSISLRP5Jmddd28lockJNVdfvQZA4w4rWdZGYLt+asA4X5x0/OSzjaVS9RnPgvf dca+zd0t6wam9yqO0UYy4r6C+8s7Kcf8xwI8cQ1GozrxgKQXOxetyEHs672fkneibNEP f0Iv/g1S6G3lM7op5OIPNu4VJjbG2uhJIq1D2qlvr1aycbaoyDYucSibs8GwI8aw0t7B 9xCxpUkiRrZbjk9NHi2uHIl4JYr+F2YsLMo/lpqFuDOIz7dm/3++yARmGD5FGSFgsj87 Om2fiUMw+PmCFjQwlXCIBBpaFlPHz1fXQDH08G+kz008LC9rR+TPDrJEuYNEgkMe6GiX MzcA== 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=gFBrtRlDF3lH8d+M3xs/KaCiXtONEeFHhxQZdekcdbU=; b=nDkKHUNhiQz3Fy4UPW2RrJmfaj5fimi4Akku5VIUhKjNCNJM7iOTe1Cc9kpSIy1Afj QVuQXTAuP51M2buZuTP3eEAu4STgvYHCjElLtE5nPQ13dluGx0d6H/310HwDeFwFBbni JDRi+rlsTtYuZkLLSE0foCpjsNSeAxEQuqac4ibZslp87Szzdh5bSrIkqo2/VhpNV/8C 61Kg5xAWkmmODHW0x5To9jUIZBzrNhS3N1lflCNkMRBNclNFAhXzvNV2KX0omr/LpHaU A1CExO//7QlCyI+wp0k9zBTwxDZjYZUmyw1I4OVZfkkFbYdf4BfMzaMyfXM22NKyc7X0 XC6g== X-Gm-Message-State: AJIora9dI6bGyboypLB7Mn6aC7d0PAwgbmdA/Q0jjNvaoH5abTv48Uc7 YWsoKaoW18TkAsOkjx3l3D2OBA5giJg= X-Google-Smtp-Source: AGRyM1vdSturGtI2PTOIo343GwMnfY2JF4QJfIJXDZQQzFSc21V8131+XS87dx52wrjxAWs9EX7RTdjXPig= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a81:11d3:0:b0:314:67c9:1654 with SMTP id 202-20020a8111d3000000b0031467c91654mr4202824ywr.481.1655237236710; Tue, 14 Jun 2022 13:07:16 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:27 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-3-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 32964d7b2218..2b13ea74362a 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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 A2FC7C43334 for ; Tue, 14 Jun 2022 20:07:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356678AbiFNUHm (ORCPT ); Tue, 14 Jun 2022 16:07:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347396AbiFNUHU (ORCPT ); Tue, 14 Jun 2022 16:07:20 -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 D46FF4D6B2 for ; Tue, 14 Jun 2022 13:07:18 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id u8-20020a170902e5c800b00168d1fb52a9so4453704plf.10 for ; Tue, 14 Jun 2022 13:07: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=KTI4cDcDxRU2AdleYfc0AxKMoqQ5q7lkRFosyv3tl7Y=; b=WEDEWQkuXhSllM1JC9oQhj/pCnwiE7iF98H3mjG/aYZZ7lbVH/6Z5dbZa7YrmruZMW Jp27bzveE+Ya+fSj6NgZXVZyxb1uxWP1S0lA8Qr4kP4CvvxSWlXLWt7EsYPnkFkQWaj0 sCcQiUm8syctpWhMtyaziC8rn++i43vhBDU5t4AwLaGKLKSezD6tDLqAhYrRF6ii9tLe /Duk3QjYcaze8akzq0b3LPqWsgErUuJ67+4UhN7gzeigWS3+Rbl53Maeqarb4LqOhqtv sZ5+JeDO95H6ZjeSK2Q95rnKsdIFq4a3s1MolsGYUFUSuaks2AONXQwKGOw91oARXftT FG1w== 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=KTI4cDcDxRU2AdleYfc0AxKMoqQ5q7lkRFosyv3tl7Y=; b=Op9zw19bxsU0tT9I90ZoqowfKQHYjWQVfdQc1IwwzVJBCjQ65l4HP+dBKNqiB8rGpI JlPgCqqOPMYdbcm7R9JQVe4EP2bPrRQlzgDu9anHmPXbx1UwJldHW7VtkR7RaVV6CD6O h8ZTK8zI4h4qEaGobzuoZPTKY7xis8CAukgPFA0mpqdaYz2jI96z9qL1YEXji4WKIrjF BR7cvGDvzedCDODh5QORVFcHZKjQJ3UMwjk+ZjbdFQT6eC/AOeeYaWp2C+2zrNhM15bo kb8XBWI09YXUgusDQWJzaW2jomEv9oX/3PFEFmrxwhJUzDDtAeP+8yGN5+BDYxzvgWqo ZiPw== X-Gm-Message-State: AJIora8FTf7rt4dw1o7zW52lpyQAMLq9vpTq3pMTrlnbR5fV7D6rdq32 9UG6ZmgvFiU0xucvNiVS0nUdJ6L8YJA= X-Google-Smtp-Source: AGRyM1v4EQlG3wiKA/PqQz/ZBuEzfBcFq0tXOl0lwAd6C12EawhwojNf4d35w9mQ0v5jBs3DgR1AdWQRttM= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:6946:b0:167:8ff3:1608 with SMTP id k6-20020a170902694600b001678ff31608mr5765641plt.116.1655237238390; Tue, 14 Jun 2022 13:07:18 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:28 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-4-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 03/42] KVM: selftests: Add framework to query KVM CPUID bits From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 2b13ea74362a..ee3f7239cea7 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 c46a22f8a9af..7666f24a145a 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -734,6 +734,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 D6E62C43334 for ; Tue, 14 Jun 2022 20:07:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351902AbiFNUHi (ORCPT ); Tue, 14 Jun 2022 16:07:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351053AbiFNUHW (ORCPT ); Tue, 14 Jun 2022 16:07:22 -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 AC7F44D9CA for ; Tue, 14 Jun 2022 13:07:20 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id c11-20020a17090a4d0b00b001e4e081d525so8643475pjg.7 for ; Tue, 14 Jun 2022 13:07: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=yVOVbpSs8meRSwOuAAzFlzcoWe8mEuzABJ9vClZbdV8=; b=b0vt+aJdZXu3gcnC37y/5e+nUMyiMnti+YljfyQH7TKjOBYB1863wGkYlxkdqIHY0p SRxHhk8DMTFh8GIqpZ+eIz1bRFutZOG1j82+Klk06fpYOOjg2oO5ZSfk5KSxBxHcRii2 0aXtbkoHXjEFRv8GX8S0m82cwgVu9harL1y/CvD0WfoojpZKfXuL4KWJskjLxsIodbo3 MAtZpOKYSpGv9aD4eguoGr4VMqbckuV3n8jGm2StS/gZuRZ5Csv4oaSSD3yOJirNbiuL M3HlbA72vsbMsYtL2E2yK6NLYAgkOuBRoVMfQw6ZRu9h7LN9zAW0xBl2bFAyMKYeCA5P gV7Q== 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=yVOVbpSs8meRSwOuAAzFlzcoWe8mEuzABJ9vClZbdV8=; b=vW3cyN91hVvCRxl+1tCHmau/yF4tnrxe/RpYS4Up4F0JA9Vf1UiOXCQ5whIUduJ4es tqZiLNJheSy1Djsd+YbVHcKEvw7pQylUv5HrZPZFGsMteNFs0Jgxkwj8GRghMpB9gFYl 8JlBYlydN7P4WBDkfRHVq43ls4Xu+5JSjBLeKL5bUEbMV86uIdM4ufKAVIAPR02mBJGR 9HHZsbR0kEEVjc7xoJaD8nN077YqbiiC/fsZzeKlSfcCToHSfTjUvVsvzV6GN2z5EsXI 9XSuFO+Vyy0lTBrLZPl56BVO18UflDWbc/al7oJlf5L7mz6V3Jn8aGqVhlwnwUg0UUIy 5zXw== X-Gm-Message-State: AJIora9kpBwcO6GLUJtEhKBhJBmxcbIDXe9TRLRxPwQmS2NOwHnWRg+8 69/oB1Wkooe7/b3uLFp+c81yIH9j9is= X-Google-Smtp-Source: AGRyM1tteAYoZg835mQqJ4PAc0QqFzsuk2Zip7QKmP5O7OvvtmePboUPr90NwUfweM2Iv43VIwG1mUjxaPc= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:b407:b0:168:e554:33be with SMTP id x7-20020a170902b40700b00168e55433bemr5948707plr.130.1655237240171; Tue, 14 Jun 2022 13:07:20 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:29 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-5-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 04/42] KVM: selftests: Use kvm_cpu_has() in the SEV migration test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 ee3f7239cea7..e1f9aa34f90a 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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 411F5C43334 for ; Tue, 14 Jun 2022 20:07:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352502AbiFNUHq (ORCPT ); Tue, 14 Jun 2022 16:07:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351642AbiFNUH0 (ORCPT ); Tue, 14 Jun 2022 16:07:26 -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 6D3E8F7E for ; Tue, 14 Jun 2022 13:07:22 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id u71-20020a63854a000000b004019c5cac3aso5443121pgd.19 for ; Tue, 14 Jun 2022 13:07: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=J93edaE74FyBzoZW2rh0wjT0Yg14RVMCKpGZ/ATfHIY=; b=epJQbRv6fZOQ46aFKGz/2X1l/u1LHD23Fnu20xpVzGTyWGFNlJNcjtyPdhLPeGbIbz UbwfDb/eohWGpYEiayDBNojIksfhX6hSGEXO4xjFsOrNOj3o49C+O5pRGxV6iROiC5AK UC2H2j+zbeWKyIh6cr0p6fu8qipwWRzmYiHCMuqA32F+QQKcS9bgzwSEsGzBWgQrM27I gMHkoHMYpmKmwqpox104N4kE7DyouJJ+MmF7crj/d6CVvH7EHZKE7smKweTywZUirezP oQCQ/VWxTFGb8TsHM4hYSBP0s0gVzEzPFZJc19hqODlQEzcAdv19/JsE8gZCBSVf6Cfg DA4Q== 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=J93edaE74FyBzoZW2rh0wjT0Yg14RVMCKpGZ/ATfHIY=; b=AM/VEKLUS5lIx0WWx/0QO+paC4nk/CgPBV6/1ArJhWNUqhZ527xdA6ApwRqI/cdm2t qEFXw3GoJ0zCy4eZV/vWp8rbUiwF0MCNqJV4sUhJmYFRTqDEjBhyBxwiVjaleuWUrW62 KYmc4MgxKz4SKqzrd2GchR3F961+3DDGrQd8OyMhAPwL0yRlfUu35EjylL1N7nMFZHyK Cm1/u8w96IV74PLp/fiqr6/k04wV5nrBbFre4LgU09qe2G6LXXf3GOmWIKzXBFSO/zmM OWRo4ZAraiLwee5OVRj7RMGhjJMwmXTd/mkb99nMoEMxPT2GfTKxgGcnvbtWayq20zEh dEgw== X-Gm-Message-State: AJIora8WcZzR/LRcsW436eXZSm8u2st/5OcZKWQGYxMqEirD2yITIuy1 g2mvSchKQVTGOqIphMYiXjPO+TI74E0= X-Google-Smtp-Source: AGRyM1tzu39iODqRptuUGTNst3eC6hfAzODozizMM2ZFnewKJZkyLTZhmuNVHR98uQ3Z6vnPmREfEEDLIDM= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:903:1104:b0:168:d336:cd1e with SMTP id n4-20020a170903110400b00168d336cd1emr5972887plh.72.1655237241883; Tue, 14 Jun 2022 13:07:21 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:30 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-6-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 05/42] KVM: selftests: Use kvm_cpu_has() for nested SVM checks From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 8D58ACCA47A for ; Tue, 14 Jun 2022 20:07:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357069AbiFNUH5 (ORCPT ); Tue, 14 Jun 2022 16:07:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344139AbiFNUHe (ORCPT ); Tue, 14 Jun 2022 16:07:34 -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 842D12DD1 for ; Tue, 14 Jun 2022 13:07:24 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id y63-20020a638a42000000b003fd47b6f280so5448723pgd.12 for ; Tue, 14 Jun 2022 13:07:24 -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=0JTtDUieBFaLFlQRtGbTAPlsLVfcOSXXVCv+GbCgdXE=; b=OU1Xu45m/J7KzT3I6oZZ3vKZFB0Myqk8L6vWUifD7R+bsK00aEjbusuJL+5ljPiAfY MybIX04aRAFIvpJ3eR7nV4f79Q0SfCVkk/RoBRN+YlXaDhndvq2NZMpbH+zHy5vVZuIf 4TszjqROx+6uJqDFoiRF2J6DuO7t1b2T5uW0B2uKdnjzejP/uRmHKe03lqMmuzgAkZ3H xsdss/OPifd+KojsEwGJkyuzvS2uwvEVF87t9UH0C5fRcA/PYh+H/5dNddmK/aGeapEZ fPlFST6FLkfXXjS5owU436vELiOB5/IsAGPHeqjD+CCtvij8N+OUTNxiRUvac9usj9FP uNLw== 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=0JTtDUieBFaLFlQRtGbTAPlsLVfcOSXXVCv+GbCgdXE=; b=2+GFYR5aLL6MRi4UfFeKaDHLmbh5Xe8cRMDzhNqiEMZirhi1yWWkq7Jz2L//FO5tqk 8ma8aQWLOXMbFHfv6oLtV9v7RiwOYokZlN0pjJAwWhcNkBov9wCWRc1LDyi9M7s4jpM3 JG5YarZeAP9CbWliJtq8p4o1H4rSfgW6wmUIJQA+TVn8o5rPZiOa1qxNQVEnd4+22Z27 /pi4Z+qhhMMQkEkafH5U8ha8gG0Ooia06nowVXO1SWtspvenM5qS7Gp6HDIM2eHTTn9g Aii54oLbmxnQEyX5g8qOxuT/ePah+tgkOxPWoEs1X5IqAbiupuhS20Ji1BWsHvxHs4Rs Ewuw== X-Gm-Message-State: AJIora9ReYc5dn8iG95tJAyzyOZT4tTgRVX5dIETYpxvTrEuD75WuZ/s tnF1ftwTOUTMXdia2sijCO5bId1TJBE= X-Google-Smtp-Source: AGRyM1sUELAlikNyS+EdWM9NJWDffUhBbDLd0ybpx8b7KtWK1+SqD/n8ej07TLnIbAhCQVdvHyFIXPyd+FY= 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-20020a17090a024900b001e0a8a33c6cmr192524pje.0.1655237243754; Tue, 14 Jun 2022 13:07:23 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:31 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-7-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 06/42] KVM: selftests: Use kvm_cpu_has() for nested VMX checks From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 | 2 -- .../selftests/kvm/lib/x86_64/perf_test_util.c | 2 +- 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 +- 16 files changed, 15 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 cc3604f8f1d3..99fa1410964c 100644 --- a/tools/testing/selftests/kvm/include/x86_64/vmx.h +++ b/tools/testing/selftests/kvm/include/x86_64/vmx.h @@ -607,8 +607,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); bool ept_1g_pages_supported(void); =20 void nested_pg_map(struct vmx_pages *vmx, struct kvm_vm *vm, diff --git a/tools/testing/selftests/kvm/lib/x86_64/perf_test_util.c b/tool= s/testing/selftests/kvm/lib/x86_64/perf_test_util.c index bfe85c8c2f6e..0f344a7c89c4 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/perf_test_util.c +++ b/tools/testing/selftests/kvm/lib/x86_64/perf_test_util.c @@ -84,7 +84,7 @@ void perf_test_setup_nested(struct kvm_vm *vm, int nr_vcp= us, struct kvm_vcpu *vc vm_vaddr_t vmx_gva; int vcpu_id; =20 - nested_vmx_check_supported(); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX)); =20 for (vcpu_id =3D 0; vcpu_id < nr_vcpus; vcpu_id++) { vmx =3D vcpu_alloc_vmx(vm, &vmx_gva); diff --git a/tools/testing/selftests/kvm/lib/x86_64/vmx.c b/tools/testing/s= elftests/kvm/lib/x86_64/vmx.c index 381432741df4..80a568c439b8 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/vmx.c +++ b/tools/testing/selftests/kvm/lib/x86_64/vmx.c @@ -382,18 +382,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()); -} - static void nested_create_pte(struct kvm_vm *vm, struct eptPageTableEntry *pte, uint64_t nested_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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 B5FC6C433EF for ; Tue, 14 Jun 2022 20:07:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357012AbiFNUHw (ORCPT ); Tue, 14 Jun 2022 16:07:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351733AbiFNUHe (ORCPT ); Tue, 14 Jun 2022 16:07:34 -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 846325F4F for ; Tue, 14 Jun 2022 13:07:26 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id c11-20020a17090a4d0b00b001e4e081d525so8643475pjg.7 for ; Tue, 14 Jun 2022 13:07: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=/Py9Wl5goNG9EkafS3McJwH0IeUf3VIZaz2X9X8WLpo=; b=UDJlKpJOmkqypxjrLa7Npl/zLUFzASy7rj0pC/Jb0WCdVMh8xrKERa5N7sAKFQ5l01 a95GCVmTMRuVq070UaKKxwcSu3NEkA8xGX/2K4qW2IiqD0I1JZD3nfWdKzMsyF2KOBdc IYk0lizeekO8DOxdbYVBT1z8BJrJl06o1A0Si8kOAP7pJxqMk84ub2SMQuvkUKSfzVx7 wXPPRzmZLnp4Qv5HF7Au65eHTmhXUsIV5wJ3JoUSgjHNmKgVJB95diRRu77bzYYoyJPM zxLjBBXuEx9J6V0ayjToVGDaVo8+CGoEWv8jNjCQp7I1ghKa1b98qpVR3PTLrwdHIYcK /ExQ== 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=/Py9Wl5goNG9EkafS3McJwH0IeUf3VIZaz2X9X8WLpo=; b=FtztAs49EF82b8GuZvjgzUkCmfE/zAilrb/b2lTkRJhJ7W/nWP7S+NnGZHgZJjvvGg GMMzeH1wqysnQbZSaQFGpEIsTe4+f5IO/I6Q2OQs/G2UQkw2VTmArlnlJJiI2XkccGX+ /daEDOC+RTTsK7zpkQMy/W/kriAVPpVSrHfl3vxjOBOwTiVfAqPrjVyN+c0wM8BhqJQu B0DFpGaFBugS2a1HQuji1Ve+pVoRlhm35BPmXkMZeLCnhk9PtiHEDWc9js7XFPggfXhR mxJkYe+Yi5ofUkhUIZG36xpHxtL44ai3KRaZOEATKlUhgrtcSm+4vLTDByUyrXsGi+zl 4lTQ== X-Gm-Message-State: AJIora9Rugk6r/QhOVgxvFbpDBKYB+Is1hETKIKY3Y+80za3pRuCGVVx 1r2nLBCmo4di2sY2T5ell12EKWqKy4M= X-Google-Smtp-Source: AGRyM1sotNG6tjyoxS7kiO4PovYl0UZv23UCjHzxQyjTWMOc6aF2Af5Ca5lzgT1YeCt1ZTBSvaftpXBbWTk= 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-20020a17090a178f00b001e303bac185mr192336pja.1.1655237245815; Tue, 14 Jun 2022 13:07:25 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:32 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-8-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 e1f9aa34f90a..9fe2a9534686 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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 30784C43334 for ; Tue, 14 Jun 2022 20:08:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356810AbiFNUIB (ORCPT ); Tue, 14 Jun 2022 16:08:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352187AbiFNUHf (ORCPT ); Tue, 14 Jun 2022 16:07:35 -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 A9A31EB7 for ; Tue, 14 Jun 2022 13:07:28 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2fed274f3fbso33959717b3.17 for ; Tue, 14 Jun 2022 13:07: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=kVwV6JYFJ6utxVeswV5UZJLPrp6uZhhdEbw3jp8RhEE=; b=WI/GojvuQE25iMByhGawtFgC8pDFtglByVBkcrSCmBzHfBVX+b9wbBRUbJMiZ24cpn ict/0+XoxFi4p6RzUhvABJQHpIDoeOGvungKIIDC3E8TUJQihcTHQ4b982kAS5ID4WTo OlMVSzBbgZl9UfkHgGavgVsEwPs02h9fU5J6Lac2SL5N2YCiX10U1j1ktDFwT/T5dnIY UdQ3UJF1EWMg68JGoF5JtLPbVWOOq0eAPsYrirzA+ViZAReYmzMeRx9Pc1LMn3kxmxv/ 44wsd5zQp3i01Ncrz+g1qChrthvY2A1TgkFisK9VNa1L3yD3t/U9clbsWH61dGkFMtGb drAQ== 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=kVwV6JYFJ6utxVeswV5UZJLPrp6uZhhdEbw3jp8RhEE=; b=v7nLwlN+vzouW537JJTu2NnyctzAEW9ezI69/dHOHfnpSX8EToQoiK30zTAQIpfOis neqLQ369HTp7Bd720dNAjy1LKtrVvFeSLvu9il9ttWfTYvSB5Xo9DlSXrIXcM7fqT30r f47VcTQtn79y8ypUv68i0XmlMYXPAV5tgaonIZ7QGhsaVv13KYjYsulDUsicKhVVs332 +WJaeqbbTgKw+wd1aOegItsOZygNYrXJRX2csayBSf9hgc2TpPL3j23HcwIvb/nqau9F nQf2H512ezJ78HIRk5NwRsplvS9P2TVZN6cNG50t0HpaJE+aKHR5f4+kbJW4qCVKdAOt 897w== X-Gm-Message-State: AJIora8jVdKIuWf6wQ/OQvWW166ECD4U3NxEGQ6f2QfLwyhAZLGwK8wU ihABI8NG7NQKsnuCZpXKUefR4DPRTZc= X-Google-Smtp-Source: AGRyM1tChiJEQJlnuBJBQoShmjkNfYkRf+ieBtVl8lBlIfxB/XmyQmKWhT+UtRF6beTnzZgrsKWhdYNrXrg= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a0d:eb08:0:b0:30c:2f46:f7aa with SMTP id u8-20020a0deb08000000b0030c2f46f7aamr7552327ywe.299.1655237247728; Tue, 14 Jun 2022 13:07:27 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:33 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-9-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 08/42] KVM: selftests: Drop redundant vcpu_set_cpuid() from PMU selftest From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 16A04C43334 for ; Tue, 14 Jun 2022 20:08:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356567AbiFNUIF (ORCPT ); Tue, 14 Jun 2022 16:08:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352366AbiFNUHg (ORCPT ); Tue, 14 Jun 2022 16:07:36 -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 1A22DBC8C for ; Tue, 14 Jun 2022 13:07:29 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id b9-20020a656689000000b003f672946300so5427916pgw.16 for ; Tue, 14 Jun 2022 13:07:29 -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=Ix8LxbFMyT0f0KurACg7xFUB0b+m8p+ZiAchdE34/lk=; b=SOLoRrkUYs63+1Nm8A8481yZmKUKX/unwtnE3WCdTt//i6TjDOEdiHAFp1tydZQyHE BqCYWKW9pzqhMc+A9V1cLaGM6smcnmrs55VoVJpSsnPJGLnEMX8sKdhqGSfTNMZXw2F4 PVx/upckfItAzOLe/70klXtzXWmhMDz1HLwvZsM553CH7aVnDrNrSvDm1Tuggv3bPabc ZDy70wx/nGvVz4bUZQPdL7K/A1uhDlmje6umIU3FhlLpildyMFzri/BvP+YvQXiJH5tP nhE9xJ0xPJxj4b9Qss5F+Y70QaOsgviTFOl5vQAIAWOlinTY9AMe2fmlVPc5DKVSfNAb lpoQ== 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=Ix8LxbFMyT0f0KurACg7xFUB0b+m8p+ZiAchdE34/lk=; b=IfCZLqolwtX2VUQLdRLJ4kVf7ZYgGl/3xWMrJveNCoQNJdtElx+HVN4qE6/zvcCp5M lzRXF0Phs9CIqy+3itWkyCRaF1HsCw8RvSQE6GngiYfrDQPaUcCOiCqr0AO2udnRf8bF 5eBpB/L71wk9GZD35TQvpLGCJLFqf93/dzIoAVb6MeocUb5ORGoMfRECyyVclFsSXjkf ecNuncoiLAhLN8o5W7dpJ6VgwfJ9CqPDmEPNeKekWf5aTW8RLAB/l8Qnnr+CtvgeSiU9 NpMg6lDZkLKpwVVNAdHBqwm03iCOEW7oDb3T2IF7QZAp1Nj/yVkd3R6n6y4/Eb4P2c8a jbqw== X-Gm-Message-State: AJIora9T6teKmyxc+HUT8MejQ8hLH0VMmg6akYOa1oMWRG9HnDYyzM7n 6a6maHA+0wqlrGK1OoVm0VMerznG5CI= X-Google-Smtp-Source: AGRyM1uo0B5/l7IOGbrwE1pyFaa/TwYOxA8i4cDON+VwOIKn2m2Z1KgTc4TWuHq0YSIwD9XFnz1Yho+Dmgs= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6a00:4503:b0:51b:de97:7f2c with SMTP id cw3-20020a056a00450300b0051bde977f2cmr5990382pfb.12.1655237249548; Tue, 14 Jun 2022 13:07:29 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:34 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-10-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 9fe2a9534686..2100eb08916a 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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 B7453C43334 for ; Tue, 14 Jun 2022 20:08:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353252AbiFNUIJ (ORCPT ); Tue, 14 Jun 2022 16:08:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355079AbiFNUHk (ORCPT ); Tue, 14 Jun 2022 16:07:40 -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 1E865E028 for ; Tue, 14 Jun 2022 13:07:31 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id j10-20020aa783ca000000b00518265c7cacso4241251pfn.3 for ; Tue, 14 Jun 2022 13:07:31 -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=MksWVyw3GKJunqV2uq+ZgTGX3Mhc72udxz4fsPG/7ic=; b=ceLFX3rSwoTFNDpb3FVJtM503EwtikfUe8vquzqeFYvH7dUWn3SMnUwtzoAySZAVRd uW5iVLgtlWlREv4+00HxU/k+HFQZvCaJzoehxjcqWIKsKfgjrgJBYpN7SmfCxPjz+jr2 fx5bggpJDLP9LaDp1qC2khQEu/G6LW9s+2fiuTcMoH/YUucVH6RTjAfEgxxBKRJGaa7z /qfy3Birz4V8YgtYnGSqFpel7oa4sINTQf3W4s3dDLkZiwh3mWd3ZKYKpjRBalecTF6a DZ8rSMXr8gE4hVIeRN4Yel8fFLAC5s0lqCOtqX1+6Ee/O83rcCfh46uQOhrb7xPXjmng OyJA== 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=MksWVyw3GKJunqV2uq+ZgTGX3Mhc72udxz4fsPG/7ic=; b=v5s5n9XiKWQiqcrSCX/NZ+6lL7t+qsmvKvYxSiAdCDSKArYtfgVvIOvV56BPlhZ1hE 7reWtrbM25k6uATiayk1rz0A7AHZUGMewcx1TQYjB+BI0fyjvx0x5kvN2FH1IEUEi7FQ pr/qo/w9mYuFPjPk+yhaV3ECHS41Bi2QRwCEqwfC6yjJIyhir5/ocoCaVarxkpw+tep0 ZQDpjmqPiNGbxpuhbRjnX8dHExIi03Y9sM4wpFHDQ8z4Q3RPyrLiyz0STrRZo99xxsVT 6mqp1Wki3q3XQuPXPH11JDPeFDmpKbfftNpjQzYX+qgYu8Y3L34flP8KUxArzG6ZvpqN vMjg== X-Gm-Message-State: AJIora9qu0ikfEvk5LoRtYHeBXobSdABAbml1y1XrliLg7qUEQVsn/zq ni0GnV8/x8ld9e84HAx9TVId1zyc0Lk= X-Google-Smtp-Source: AGRyM1vJ5pqrJFJ3WlsZ7s7Lfko+SH25Pjb4oKs8fqrZCzpCgEirCRElDq4vbaWazbcAhcKkU0N6zUtxlF8= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a62:544:0:b0:51b:a90d:64d3 with SMTP id 65-20020a620544000000b0051ba90d64d3mr5966933pff.40.1655237251012; Tue, 14 Jun 2022 13:07:31 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:35 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-11-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 6C022C433EF for ; Tue, 14 Jun 2022 20:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357030AbiFNUIN (ORCPT ); Tue, 14 Jun 2022 16:08:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355647AbiFNUHl (ORCPT ); Tue, 14 Jun 2022 16:07:41 -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 1F92010FC8 for ; Tue, 14 Jun 2022 13:07:33 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id t1-20020a62ea01000000b0051be221a3ebso4225990pfh.17 for ; Tue, 14 Jun 2022 13:07:33 -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=h/OjiDb6ZU4P5Rs5vu7aiUIGzMiM/JPLT2d72W0LmOU=; b=V/PVBaSR2bLGOHRJbPWigQqdEEPXG7MEjVfNM/QRCqTtB7/z8VLHqdL1HAY4cIKh60 nQw1kz9GcPK9lyYvtOgx4NSRZ0WQ/nY1eML4nb3GpY6LyyNbs25KuVJNwF8EEZmJUvX/ UwoNvUIT5gaC22a4bjCA3q6ite18+bSIiZn+SX3kGMPzxlgT0wKGNO1Ltri6OL689KQG IuloNc3NWtPYLD4sRv8VTVQtCb3JCLOndw9IRZMZdpGjqs2QhR+sbassZmk6ZohOrAod 9SMfepYTN7O6dwEpqfO3w37+vydn+++QS7q3zbUqVtoUiN5fJPXn46d+5KErcQImCBcW oxFg== 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=h/OjiDb6ZU4P5Rs5vu7aiUIGzMiM/JPLT2d72W0LmOU=; b=Y54/ZOwHcDmEGJM2my77hNCh9+l1Ltk5JEMttCKiv/dh/c1xKmVXwaLOOoppEXXXPP cg+5jD9mEByq0l+yrWaRnI7RY2Sx7Ci5YLkRdZBozvkOHYcOtjLAXkXQjfdGteKvFkoI dh+7MxCcklBzbx2+tLkXHftqlibaYhwR9rz4ubDP4nZUOEpEuu+//g4qBQWtAmIFSjEc 3QlWTIsR3u8hdFFS8wUjO0Cm3jDRAeNY5+kkh5UcNOc8VU3nAl020F1dk/fvky2BT8ne 9RiYQ/ChJ2GjkNcGuxIPL1V8bID9ogl/iDw2YQPy97VJCAG40uT7x6llqiN+4pclTpdx ptDw== X-Gm-Message-State: AJIora8zwl77W0dAa1o2a/jGTDaJz+p4SNu3fjYejDJKTEcDA/YzsYD0 a4tAL4AW5narBVhCuS2cteoS59a9Gds= X-Google-Smtp-Source: AGRyM1sbl6DAPvZxgxT8mIXgVOSQ2LO6MFqbJax4sOk95lVr2Hlq+qrnHEPEhZB92ZdPwkAmkT8eCtHGi/s= 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-20020a17090a024900b001e0a8a33c6cmr192553pje.0.1655237252726; Tue, 14 Jun 2022 13:07:32 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:36 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-12-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 11/42] KVM: selftests: Use kvm_cpu_has() in AMX test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 2100eb08916a..b5d2e6c69c1a 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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 E486DC433EF for ; Tue, 14 Jun 2022 20:08:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357245AbiFNUIu (ORCPT ); Tue, 14 Jun 2022 16:08:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356689AbiFNUHm (ORCPT ); Tue, 14 Jun 2022 16:07:42 -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 AF1642DE8 for ; Tue, 14 Jun 2022 13:07:35 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id mh12-20020a17090b4acc00b001e32eb45751so8639929pjb.9 for ; Tue, 14 Jun 2022 13:07:35 -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=+K2U9ZQLTr9r2599616R5ArFkm9I26JZTi1y24xJeZM=; b=WCW721NtOLXF8OgreyIUQne2OjoMN1a3eLd251FVPN/55Ud0cP8y/Sjc+VYwrSgwnB zam6Y0aljOPtgfYno6oLzsHbjGoBbt1ynomyy8Q0OH+ea0bk81TZwoY9uUUin22XifI9 NGDNq8M5BtvqYlT2zVdhMTM0Feyar4QiZQTvb4qgSH07ySOk88fhw8fjGbp6ykYiWYOP 8xCPe8GzJKD3U6Q/THOKV27Dg7CQ3V4cCqju09EIGzs7wvhvwVvst48GaFaUI2nwPAOG IMWG4Asu+x1J6EsTdwiu+JGe/w9pc+hfPbLTUJ1BFTYoIpzTCGzeo/Mb4ph6OgFPbzO3 Fjcw== 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=+K2U9ZQLTr9r2599616R5ArFkm9I26JZTi1y24xJeZM=; b=NRYoxDKExHQRFTlLyF9brz0bxNCcq1LClkYvRrlarl/gvpiXr2Rc8ld0ZmSGQd1w6C 6zDr395CsVp5fF/LmCG3QPfQNN1zyXlBPhPj+2BNGkT1QIp2XLm+CPy32hfQLbgslZpL 2wUQMZaHA0CohU2kNijMG2dW6SbWK9ISoLXlTxQb2V1StyLXC30dfk56BOtHggGLvhQG YRQERIQg7jjbxHWEkZ6SXlDa9UQVXP4ukkDhau6wlfhkNoYME7k0YBzrYC5Wp79cuQgq wWdgZkCLUtU1RLP9GX98LUE2DsWRkaGWaypEmU/itNg+S+Kxa11knRFScWgqm7Y002bo wMzg== X-Gm-Message-State: AJIora/aUngfuK94RHgokw/6HGFac2Y9vLXTLc1qJqCmlkPukvHM6auJ VSt2tHAZgT0IhavGyruQR7fewd0GHbI= X-Google-Smtp-Source: AGRyM1umlki2IGqUel3cRE/RbccGMPSY0ssB0AV3HHohG2BDAlbagsZzWAxDSe3r8RwVDj60wIYIjKRYl0Q= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:cf0f:b0:15a:24e0:d9b0 with SMTP id i15-20020a170902cf0f00b0015a24e0d9b0mr5869347plg.42.1655237254915; Tue, 14 Jun 2022 13:07:34 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:37 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-13-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 41ACEC433EF for ; Tue, 14 Jun 2022 20:08:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349457AbiFNUIR (ORCPT ); Tue, 14 Jun 2022 16:08:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357038AbiFNUHz (ORCPT ); Tue, 14 Jun 2022 16:07:55 -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 5759213D2C for ; Tue, 14 Jun 2022 13:07:37 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id v191-20020a25c5c8000000b00663d6d41f5aso8239115ybe.12 for ; Tue, 14 Jun 2022 13:07:37 -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=vq20hxrPmqVc31s1r8TPtx4ezGH69rkNq0SRoBaom4o=; b=V/t4JSSMPQa9jPegCIx0X+tIQTdUIpqToRCCfDar4Zuy7FpaRPzQ1oHMzlhfMDSLph U8A0jYqjDHL6wXC0bgEoszqb7jTb8eVqw4ldN4hJtwsZERtszcq7tdbs1yOjpqeMjkj0 9gaEcOoX3qzb9qjQzckCe2je27zm9469mWkC+zdtY+3ijy6w5Je1M0r4Oh10dc9YOjJv DJM/E8jyVvRcG7hWDIoK+xG/r4tBR6mvjjDtOlN8GyHQTuw7xt7xfIAeorqa99k4Y1vH /KLTH03//6Jlj9e5vH1mfPrJLGOuxSA2+2Zx43FCpOZHqC4V49fOWfX5GoWmtVCYbwDo A+0w== 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=vq20hxrPmqVc31s1r8TPtx4ezGH69rkNq0SRoBaom4o=; b=Sp0u8bLz4a/LDVwhZPZx9vhpXUTHowiPJO0Y514RVnIlnqGThJxF0TeC9kTGCXC30Z fwW7X3lcf2aOhfHaOrQa20VSrI1SzxN9f/jx4Tb6Y+3JjhhynzVFrHemWB4fq6XiEwm7 HgwOzsCjsyCpkx6iSPdx1FsA5Cg6L8n9L+ro7Q5Oetv3WcajI6HiVHGI+LxA94CvrKdF gz6pe0g2mRwYy/s5MofrNhNgFk0JAVVyv6iAXQsqBAyZ8XqfDhpYEaOImbVJArmTWb+1 FyHBAxfn52K25BS3y8tU32hoKfYH13Ait9Hw6RtgIvVY2OSxAB4UqnWI0hibko81VwvQ 854g== X-Gm-Message-State: AJIora9P6hcIVNzEXSJQ0DsJ96NAHsSp1JdmHNfCuKE02xxJKXkoN2Uo n32mGCVDN5VdGL0/J2nPvm1Xo6NMk8c= X-Google-Smtp-Source: AGRyM1uWY1dPZmUvLxKfwFxNKMG50R1/LmedNWgmYjkmMmPw6gtMeKVZPYiya7iuf2HdxjRNxXT11tghX9k= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a25:bbc8:0:b0:664:f99f:877 with SMTP id c8-20020a25bbc8000000b00664f99f0877mr6722282ybk.348.1655237256584; Tue, 14 Jun 2022 13:07:36 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:38 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-14-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 13/42] KVM: selftests: Remove the obsolete/dead MMU role test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 b52c130f7b2f..2ca5400220b9 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -83,7 +83,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 b5d2e6c69c1a..95d1b402da9b 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 383fff2c9587..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, PG_LEVEL_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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 14DFBC43334 for ; Tue, 14 Jun 2022 20:08:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243974AbiFNUIY (ORCPT ); Tue, 14 Jun 2022 16:08:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355067AbiFNUH5 (ORCPT ); Tue, 14 Jun 2022 16:07:57 -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 6EBC919003 for ; Tue, 14 Jun 2022 13:07:38 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id mh12-20020a17090b4acc00b001e32eb45751so8639929pjb.9 for ; Tue, 14 Jun 2022 13:07:38 -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=+7ZQJwDPN94XCZWfMY0f3bKfe/+MUS1iizJz1cRRud0=; b=sIqMgtwGiyDHB3/kQbsW/oD4UnbmjesMIETpHCFlNxZxusO1G/q1uZC8YeeenM8ChI wncWmYl+BRdoJ3ADmpzPLWZjcQbT0uv2CaZ2/ysVEnstkkMEcSVSLA2yCISAUeGDKgHJ 8F5n3MynOh8inkdgO4AkZ4MmT2QsYl7U0BgXBnQ3jmdH2Wj/x12qd247+fwKKk8E6tx4 xYBhZxemKJ0UTSNaY1OEeLjV7pakGUlm8HDmU5NWfCGhPueh/MXo0ljJFqn1wb+S0t1l RHdKvrWADr/xFpNanNJOoB+GI0PHHm+G1UrzCy7WF44LteDCNKnWqmRz0xOzo93vX7mH QrYg== 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=+7ZQJwDPN94XCZWfMY0f3bKfe/+MUS1iizJz1cRRud0=; b=ArcFJEPXF4827lZPUKZCD0VdKhPojeBrunUUEZvSzDiRsBPDfvma0051Ja8gq9xwy5 a05qSstvgD3JegvnoqDtjqquf+zK6KHe8lfUJouNO+1ynj1KuZ7TJbhU2HFrTNvGMQE0 3bkQBkcvSvOjwfNl+GqyGxGYNuIJkmRrILq3zH3mym+tsg0cl84NW4lkSLDH1ErdgK/g n1q3W43ow3DK9BIyi6zX1Ophd51C1WQ1iZ8SfThIxEA7JMXv0EhmeYIk3BlBfXIQCcda Z9ge97YUhmQuycSb62mNGJ5lOVtQC9nfIckL0kjKC2WUnqZI2xrYisdVcs61WKVpMZwL 7uig== X-Gm-Message-State: AOAM533bgsdbintl3Um9dltFuHFvDbRm0NGCk2vILg0FKx/e5ckSOn3g 3xaEj5Xpg9PxSHRYpulieNrnpPfgaEQ= X-Google-Smtp-Source: ABdhPJxgqeZMM0y2qDglaFdnE6xkyIlTT/6rdReCFv/JLoNxOC50esqKyJy67OTUPqUBCIH1rq7hmLiIqdc= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6a00:15c9:b0:51c:178:ac7e with SMTP id o9-20020a056a0015c900b0051c0178ac7emr5974949pfu.64.1655237258068; Tue, 14 Jun 2022 13:07:38 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:39 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-15-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 95d1b402da9b..db8d5a2775dd 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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 82E5CC433EF for ; Tue, 14 Jun 2022 20:08:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357544AbiFNUIc (ORCPT ); Tue, 14 Jun 2022 16:08:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357153AbiFNUH6 (ORCPT ); Tue, 14 Jun 2022 16:07:58 -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 0CA731EAD2 for ; Tue, 14 Jun 2022 13:07:40 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 70-20020a250249000000b0065cbf886b23so8510136ybc.8 for ; Tue, 14 Jun 2022 13:07: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=A5Yqv/oATZC7iG9rkjQz5o5BXjSdlLOP6pd+ZfOPJAo=; b=AgVOhQGu0SLIY5ajIXV9p1vIDBjR2/ZUJNw+6fyWRAty92D2bTHaQK6z1KolqWCRkU WQL/3tX6ShDRgEasqeVc8tGjuRwq8kbQEyTwzx7JfyF7RsZ/TBaixjA4nebXHtaLKPrL sdVcYiE7xpsZIOB8DopL+O5Dgw0cDl0rJeWdBmoOdk/k/9FUmmhOZVkYRSfBEKU4DvVX cdMMcNvbyi9WYqci05dFIUQJ9cXEpt8yrIRhLtp45mDAkNgniwU422YQCb8UQwK74FKk IVdn2Bb6ELAWP61Lk3J5LaeHA0PEPTI+XZAztcGU/gZeQsf2mkhC75YWXnSWHMVJSQFe jhxA== 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=A5Yqv/oATZC7iG9rkjQz5o5BXjSdlLOP6pd+ZfOPJAo=; b=olmNKj1n+hCnOqqxCQH5pyWTAhM0bM7zmw8/WkIMuemsIhWHGMn1exUQ2Jci0JvVvo VNxqf8cDyfS9fAXl3ga5evNsqj9uxw3pkdJyNt5PgWJWzS2kGdvKQy1fGXydLx9BrPet 3IByth+Nnblyab3VMHOnvh/LYzegGQsziJc9iF0PFY3A6DdiZ926qhBL4jtYBtRxjNXP iXIr+MEfKDRkOcSkK1IDCIyCD8veWNhQqfTM/IExdZQ6lSuDFeXC3huV80CR0afDb93u YtZn1g4hb897jSWENMsig8kJShkejk68CzTLPDbMMv2e5cbCRgGs01SE75QN4Oofx3US +/ow== X-Gm-Message-State: AJIora88m/2pxaFFZiS6h1ntgDHHoospZFhLAnL+aM9KSNNRB+1SFfER gL2Oh3qPf3GBuNQwh3eEjvLqGOzWLa8= X-Google-Smtp-Source: AGRyM1sOeU3iBT+j7fHxZMpCvarktKuhg8iqjlJ/iEqvX51llTGOjwpDec4lLKGXwU7IelXZigbq5n/S3Hc= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a25:ca17:0:b0:664:60ce:9369 with SMTP id a23-20020a25ca17000000b0066460ce9369mr6537797ybg.455.1655237259955; Tue, 14 Jun 2022 13:07:39 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:40 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-16-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 db8d5a2775dd..f5fa7d2e44a6 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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 91651C433EF for ; Tue, 14 Jun 2022 20:08:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357167AbiFNUIp (ORCPT ); Tue, 14 Jun 2022 16:08:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357165AbiFNUH6 (ORCPT ); Tue, 14 Jun 2022 16:07:58 -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 BE0F1205FC for ; Tue, 14 Jun 2022 13:07:41 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id u71-20020a63854a000000b004019c5cac3aso5443121pgd.19 for ; Tue, 14 Jun 2022 13:07:41 -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=3g6panSSHQgYqlim8rZBaxutX2L51x10az76OlO4Z68=; b=Hwtfi3PL4gwEMKgjA3xrlYKysxaKAG5YEmKWUQuhgrLXuy8eZfkhVuyxpj5O6s2O3V yE1wSQM8MCjSsZmXXJJu1dfGRs/7Bht6jO41ng1h5Gh1s5vtJLGIFNUAbmVXta0CyVXo oy9E3vlemkQGDw0aBDEdzrgx7IQt2uplgvGWXY6QzIxn0dkYi4BrphcgrG4gr24T74kB SAIqynypcgmCNce3qQ+IQzJrYbAB0tpW/oXgBPCzjz735FdYGkkLVu+Y/GBbuwz5HqPm hCvFyFgjTxHO+H4i/caB8sJdCV3C0zXSsnYj57rgdxWs4mw5rafmnv34FQvcXWxhfcLU JAwA== 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=3g6panSSHQgYqlim8rZBaxutX2L51x10az76OlO4Z68=; b=X693DrG6HZBEGhafZezfdgny8FwvEl4a/MsqS/cISkQhMiyqyot0y6slWJRSlloJl9 Ze7RXkaRRUFQ30c8w3oFfsod/FtsDxqWmxcxEUBkQcBWzSGWqd9PT/0zrthpdAVS+gJg MCFWBTgkFveotAC6vQ/bwnPzLZViXgRaXF0BL4uZXMN+/ffkwld/463gyTxG57G7vbuG X0EQ5VZWiqOPPbIJhFc3yiwpH9UvqXgZSHh4aVeYDmQFRH+h7O4YZmHgPIXODZDeYWXP Y+fzNRQl3lFfMEajtYiVpT+sMqHPGP85ovguZuqcboDJKHwvGkU8U1qnSQRZ87v7WMoI JLlw== X-Gm-Message-State: AJIora/iU3RMRzI+2A+8JngMtK5YdGP0kW0px7a0+XbGiMgoJTDFdgYW VOn/onjJ/7GigtvJGsB82RIFwHpF0fM= X-Google-Smtp-Source: AGRyM1txikG7zi07OUVNaKZjWrjQVwZNbe4HY/7GZqCt/1ScgSF01+LuViWdVHACRUXRXLZkHG4lbrMgQ5k= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:8bc2:b0:167:7645:e76a with SMTP id r2-20020a1709028bc200b001677645e76amr6147597plo.115.1655237261430; Tue, 14 Jun 2022 13:07:41 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:41 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-17-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 7866CC433EF for ; Tue, 14 Jun 2022 20:09:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357369AbiFNUI5 (ORCPT ); Tue, 14 Jun 2022 16:08:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357218AbiFNUIA (ORCPT ); Tue, 14 Jun 2022 16:08:00 -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 ADFE626AF1 for ; Tue, 14 Jun 2022 13:07:43 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id 206-20020a6218d7000000b0051893ee2888so4213761pfy.16 for ; Tue, 14 Jun 2022 13:07: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=CEG3CJA3T32C0gPYBuKCbmkH92xhHKXCyYJXkyouerY=; b=dtJ4GvALEhmxEVYBs2chY8pzwRAXgqgmmWWEtgDilKGOIKa/eR/WHOdU5Fm50VTQSm ASCGPRAL070TK4zUPlidhtOjJQSv4BtgvVoaEb5ULT+J3WxGa2B8OHsEM8zeueAEQmxu rmUY2WzvFvt0LTpabzktombu0Z1WIOR36Hbh2JxkYaE5CgIPLBSypF01gzHC1JF9MNem U0tJKcgtkJ/I2zTh/k+H+LL76zTnPYXN7Suzff4oQD6x9jKqUi41m1l0DmQa1Isdh9E+ XDEXU1/IUIhhpfEwAnj1cxTLJOWirdlQIgB3wFirEFBfK93WIupNerNjWFKtce46TTHq opCQ== 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=CEG3CJA3T32C0gPYBuKCbmkH92xhHKXCyYJXkyouerY=; b=cEOvZBAk9MroyKRkGBM4TmYuI/Sy8rH8HuJBJJUNm0sZcl/mUyjVZ/f/nftjPbSGTS wnu6ty2d3LJAZXWBq0uyV4245RI1I+IBf+H3PVakaXl/QmHGJYqsSPw7GFhljMgxc6WL RxPgS/u5ljB9HxRrmbvcWP9CHrDlCwJ7S8eUqKrtyOYVceGeED1jeBRWlV0mFK1h85QK dW3ilFUF2/L/fR+ajfmY4FbhIKKpuiOEES4J9+9ByZVdWDMimFuu5EYbLYb+YhRajnST PYgBOoVImSdH48ez81Aik64bin1Dqfw/o3LUSvy/8aEsxvQm6qLVrZbuF0iEmGMlDiny dFqA== X-Gm-Message-State: AJIora/0bo/+yoUJB9qzneQPh8OsQPhUzzuyh6YRNe02I+t+cwqgjRCI fmCBE/gBPupKjGjuQ+7oIo1vZnFuOcg= X-Google-Smtp-Source: ABdhPJwbg13NsMMqPnrgV7ewwb6XxOstI31ZoJyGbnr/FuQBFZgaXPeNHE+OUzHrMrlGzXZH/uxSkDNVEHY= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:aa7:9728:0:b0:51b:e78e:b333 with SMTP id k8-20020aa79728000000b0051be78eb333mr6045991pfg.36.1655237263254; Tue, 14 Jun 2022 13:07:43 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:42 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-18-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 17/42] KVM: selftests: Split out kvm_cpuid2_size() from allocate_kvm_cpuid2() From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 f5fa7d2e44a6..002ed02cc2ef 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 7666f24a145a..e9a2c606c6c3 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) @@ -672,40 +674,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 * @@ -725,7 +693,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); @@ -781,7 +749,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++) { @@ -1278,7 +1246,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); @@ -1297,9 +1265,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(); @@ -1326,7 +1292,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 64E5EC43334 for ; Tue, 14 Jun 2022 20:09:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357530AbiFNUJI (ORCPT ); Tue, 14 Jun 2022 16:09:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356821AbiFNUIB (ORCPT ); Tue, 14 Jun 2022 16:08:01 -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 B6ACE275E5 for ; Tue, 14 Jun 2022 13:07:45 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id l5-20020a170902f68500b00167654aeba1so5354636plg.2 for ; Tue, 14 Jun 2022 13:07: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=hHYs1CgMxsK1k9Vi8KGsv4zPtK7ZFwYVZyJnd/Yk1Cg=; b=bU+bgH83cUlJY1z4QcN203bnumc5dy54FGYc/+DggICznvnhV6ETc2yhry4U9Pnt4x 1xUi3R1JKWYjiwYY/9UaR1GQCHXFsNYK00kFoom/OI3xO2u1EJ/kQAiOZSS2N9S4rQRh /xUzCP1F5iU1PGV7LksybFeL+3UCKaga4tTqrLUvzHaD4/GK8yISDR1FhHfEQ78+OBeY 8ur+WTTf8cB03jc3vNEDjnbN0bGyt+y0JHtTKpp64KpxoJPRa/NWf+hj7r1vnfx16fMg 5RcqwH2Zgi1Y8jqRFUNinwUtIjk6a6J247pmyX2nxL4Fe0iY4ovbegdZgN7RtPtvDUj/ doew== 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=hHYs1CgMxsK1k9Vi8KGsv4zPtK7ZFwYVZyJnd/Yk1Cg=; b=YqAzWRriVwt1cTEPKJEqUd2dxtzEoEHWDUFEidE2ORCLzbVejhd+7Lq4nXd1kjTmSV dkx8k63/6cXhsbowC6Nat1ybTLusHmbhH9ma6PxumJGXYGesSGFZHED35kIgQhWO5aqh /SN9X9En1uEnkUmauYBOeqPdoi/y/BVqUDuCHmzD90cvdB6AicKhU2zPIk0PHH95QXPc 7w6RzpxVrrfE7XbyRU7Jdd55GsANWRn4NslAjeVHWMCUmAQgldrSRzrHx4xJ9+kUPuJP vqqBqgduZ5tGabDFmVN9LpHcH0zGgq9/YZeZatu1a1O9xvN2Zb1kxA8Nk/Nica0nIvuR eZZQ== X-Gm-Message-State: AJIora+E1QPxnXlQmYeaSfDa9DEfIF4AO+6ltVyHK5oLYpthoBAf5OZd n9UYDIgEW1/Zo1LGoMGD2wv549+1i3c= X-Google-Smtp-Source: AGRyM1uexK/G9eM66+Bh90bg2qJEgX6hlOeW++qr81Wyz/Vh85kDzcrQsKIsv3T5iZDK+iqR0hIIcp+LQeI= 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-20020a17090a178f00b001e303bac185mr192376pja.1.1655237264941; Tue, 14 Jun 2022 13:07:44 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:43 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-19-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 18/42] KVM: selftests: Cache CPUID in struct kvm_vcpu From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 1b9e8719c624..a344ec2afe03 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 002ed02cc2ef..7c14e5ffd515 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 38c6083c9ce1..4da0f7b7985d 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -476,6 +476,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 * @@ -505,6 +510,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 e9a2c606c6c3..55838c603102 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -648,7 +648,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 */ @@ -669,11 +669,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 * @@ -743,31 +749,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. * @@ -1285,7 +1283,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 EA742CCA47A for ; Tue, 14 Jun 2022 20:09:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357426AbiFNUJC (ORCPT ); Tue, 14 Jun 2022 16:09:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356831AbiFNUIA (ORCPT ); Tue, 14 Jun 2022 16:08:00 -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 A677727CEE for ; Tue, 14 Jun 2022 13:07:47 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id e1-20020a17090301c100b00168d7df157cso4030565plh.3 for ; Tue, 14 Jun 2022 13:07: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=6m++h1TLmwB8cNEM0gWLCTf/lVisfRn3tV3Xo5ZBF2o=; b=nWH/hVsCDdNk2ASx5jRA6o8Tna0+54SOB08YEt9isPQyB5OimOPuFRizPtguQSLNIh wM+hRGc267ThJtLhSExxvQy9S3xULfRuAhaw6p2s9Iu+bLTEpC+Y1Va6DX0+Su9jThbJ /EdkVlTgE1aZGRKWt1soyOy+IkhJrUVhwZ4BXa/qT2MwyjuD9IFuxEUPiCM1467a9Xn8 SSacTIOVEDUlgMDNZHrL3uVGJ11hu3kXiNefWHKg/HWcKPcA1I06gRBhdkww2RE5X8M2 P1SvIQQJ5Hana9l/zq+prl8PAmPyUboVk1EvCXar/b6xDzLpq1ncksE1z3wxgNPUFGOx eRmg== 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=6m++h1TLmwB8cNEM0gWLCTf/lVisfRn3tV3Xo5ZBF2o=; b=ORUX6XFn72wAmBAaDzjWDO7tw2KDdY782h21p+mSp/u9tMwIgdsjpOTiSt7Y59c1/L OTYgwZ8FdyFil4JklAUfVmRxdRTsW01zIPVeTBoZJB/pEYzcQREYx5zmS0Ic0UaAJ625 Fpx1j7gdRugNZMZG+O79ix/hWXiRjnH5d62Jge+Ju0UPenfjUjkbkIz0b8J0WZjpzwtn bNq3ahtabvMo69lf5nMVkxWce/kWjiSH1Ops9Ao6nRGe1Z7DM+w9d3OeXfiuRgzCrEQ0 7sUqVAy/qNfRmiVfRbIktmAGYou/5dOT1hMcS3YRDm+4LTIeGOMTAUTmPWPhHxbwHyhV VAbA== X-Gm-Message-State: AJIora983JwrINicpksA0GL5w/c+UmPMCLJI8BxRPaU4aAFUDHBHlyWj H9U8w38VE0N72VFDlrS/x/UTXLw5NmA= X-Google-Smtp-Source: AGRyM1vt7V/df3fvVEWr9ejSWyNdVhY7D3OL27S/3XkGdZ4iP7evofRU8vS/rOiDkTiD5UeyK3+yiJ+yGSo= 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-20020a17090a024900b001e0a8a33c6cmr192571pje.0.1655237266602; Tue, 14 Jun 2022 13:07:46 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:44 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-20-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 55838c603102..7c0363759864 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1288,9 +1288,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 E4C66C433EF for ; Tue, 14 Jun 2022 20:09:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357630AbiFNUJO (ORCPT ); Tue, 14 Jun 2022 16:09:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234934AbiFNUIB (ORCPT ); Tue, 14 Jun 2022 16:08:01 -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 A1CDA286FB for ; Tue, 14 Jun 2022 13:07:48 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id t1-20020a62ea01000000b0051be221a3ebso4225990pfh.17 for ; Tue, 14 Jun 2022 13:07: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=Ykj31SxfOFF88awQ7WBVcXppu/G/Rsb7kgEzRmofc6c=; b=iXs8SlZ/Gv1hD19mtuf0EyxToq1qFW6rDVGnC4cUhGkyCbx3MwuX2GytRoV4b16zO0 vmc2zJSkPpYFCENu5hvk85RZRyOJKIq5s/2l/6MyqVVZlOJ2x+++uCpEZQjm2mX6UiBk hyeAJrXaM8klB3Ig7dE1Feu6Gv8XCAf/LwR0N4tZFJ4ROA3U2RVSX8UDAYdA5wkJi+W1 7jtb7gjuLLZESMVYheuDH2lZdTTPLjfKvLkHQTBJAk7N2CKk14ERskPC491jcAGdgKzD ARhhJSGULNPJ5ztxt8PNUVNCSAAfT0l5EHN+eqU02gKOheSBKAXcwC92QtyMcLXgJlCV zyHg== 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=Ykj31SxfOFF88awQ7WBVcXppu/G/Rsb7kgEzRmofc6c=; b=zYr9jpDD2wCrL3Pxk3lt2xqH5bMbhho/irN8I+3V/FFwxvEeY+Yn9D3dqnI58o1O14 QaScYNrVkjHuT1PUZgpBPJLZn7EBawGcDxcs0+v6nvT35pD5JQ8X2Dl//InySK4knD3d Po4gp/c4Ub28F/dJhkQTmCwGLCukViXt7MZ7kNmMtdbh4wmB1iy8r/31yHTv62p0ioWg lf/f/Y08J6zr3K3mhZ8e8YFBERkfshk8f/DP10CDY0f1pe4Y/F0DRxxY0CYnBjYq55Qd G86SZiV6+N1+P/fowOh9A9ANigsfCR+Fa0MKTFtsKPUQKCE4r8W8QE5Q8FqD0aP+jQZ6 WW+Q== X-Gm-Message-State: AJIora/BEi3yht+Za6TMZBHH1If34nmm1l5tMtzJ3JqGhZqVLYx8J0My ILZA5euaHV2FDWoe6PFnK8RiLcfzeys= X-Google-Smtp-Source: AGRyM1tGeQ4gZu3n6/g13Y00M7lq3cR5HCq7NIfhUmFJxA2dKTega8bfcNYdMrUrZ781r4DhI/qY32rKyfc= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:db06:b0:166:42b5:c827 with SMTP id m6-20020a170902db0600b0016642b5c827mr6063116plx.145.1655237268267; Tue, 14 Jun 2022 13:07:48 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:45 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-21-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 20/42] KVM: selftests: Rename and tweak get_cpuid() to get_cpuid_entry() From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 7c14e5ffd515..36c75acd4509 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 7c0363759864..d4ea5628746c 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1190,16 +1190,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 D626BC433EF for ; Tue, 14 Jun 2022 20:09:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357789AbiFNUJW (ORCPT ); Tue, 14 Jun 2022 16:09:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357256AbiFNUIB (ORCPT ); Tue, 14 Jun 2022 16:08:01 -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 F16012873F for ; Tue, 14 Jun 2022 13:07:50 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-313bc9c54acso34373597b3.4 for ; Tue, 14 Jun 2022 13:07:50 -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=fiFiuxHIXgxAegJSj8gHfTJ9tT66KFy3T9yk9UrH1WA=; b=BqYhsM3ta9qAOvxT/8fB3pAXO46xUVrQnLHPqO3swLXf7Yx69UT8IeGNP9VcLfis1h PR+5/whVYPOCSJcKwGg2py7+MP0vudhhgwoc2Vf0vwUnnMnG2+uPdBfl907koadWZP50 aA/yJv1nqFAejidU/mt9ZTJmK5/I3Hk3aT/bLrvVKLT6qoqNh8wDQqKc3aW8Z1ObYCRh cM0jjnHApfzUCbBzHEYNW8mcwrQyJoMP+uWFV9YenmMmU3AfX8Jv/dI+dyEBLhLn50ny Yqwyk/MiF6IxdBiCMPY+v/OX8KQ2Z163j+q8VDkTgutJVHnP/+akxXA/c3oN4JKMz+iR DlUw== 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=fiFiuxHIXgxAegJSj8gHfTJ9tT66KFy3T9yk9UrH1WA=; b=OGmT6TlT4MfmDs9QnGnmAY26KKz3qJnk7423qneloli5LGi4snC4clrlWjyr/VHU7M Fn5WtnWKaqZJ4R4IEeBAV8t/9cRwTyM5zFPbFmxWAX82YBWJ/YMDBrcaXSF7gWnbF2BO QDf+ZNbDxmbBS8jgNSi99HfXlDnQjS/hVUGDB2fe4QJV9WCWGJCQUifSPA1LhQ9r9dyr KXxQMEiQ6WgwLuXu8jTnPObd/snMnDImsRhQSPal+B8RPyQUU59P0qTVlPQf8c8GVm8G AhcfarwLKHszVJ/ztBFz9CZguiv8Ruw8h7YtGQ3m6VKwBZ5trhhM1EZO7kUW6QAy/sFx 4h9A== X-Gm-Message-State: AJIora+OWtXBUw0Ydq8EPm+RWj/QSW4imOaLTHPAyVJBg8Jawwl7sWiM HFjLyDCezCL26MRAIBwEjHax38SsZr0= X-Google-Smtp-Source: AGRyM1vp/gYIujKzWJ4tGvzmphkG9wplsr6yXQfpOs2tkEkB9kNjmhE0zNhf+X1rdBQS6MBSp0B8vQuY+rA= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a25:5e87:0:b0:660:240c:784 with SMTP id s129-20020a255e87000000b00660240c0784mr6538456ybb.445.1655237270172; Tue, 14 Jun 2022 13:07:50 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:46 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-22-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 36c75acd4509..b62d93a15903 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 d4ea5628746c..8226aa5274f3 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -766,38 +766,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 B49EAC43334 for ; Tue, 14 Jun 2022 20:09:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357723AbiFNUJS (ORCPT ); Tue, 14 Jun 2022 16:09:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357265AbiFNUIB (ORCPT ); Tue, 14 Jun 2022 16:08:01 -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 7432D2FE4B for ; Tue, 14 Jun 2022 13:07:52 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id u8-20020a170902e5c800b00168d1fb52a9so4454299plf.10 for ; Tue, 14 Jun 2022 13:07:52 -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=k6fOpzXTad6Gmd8LBBX4EXfh/QWW1eOl/5tiLfmnInI=; b=hYIn2Aps9BLc9Odukg1hEhbOJKDYn42y6mC71I32gF84OmC5sKaHZ9EvxNJ4wYI/vq l3E6kMq07QR7GNNB2N2XjdHDS2kyHcytQ3trME2Y1a9A6aJ9ecUj9ZEVp62H58Hy8Bh1 rotM8RCRokburuGWnNThUCBRPJpShH9OCGXF0CzyUj1ODC7Zc5XmPuiDaPnLtD6clYdm EVPEfMLSua9QXnQ8odGH0ubEop13WOFZIloSDB7WE7ASrkoznsbY6DaRsjqFejIQcU/Q TZTpG4CJ0yrUB/kAiWYRsDOE/P0/L/4wF6W9bAXT0AKCsmt6p3lEyhI+WYGShNMOQjlg exmQ== 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=k6fOpzXTad6Gmd8LBBX4EXfh/QWW1eOl/5tiLfmnInI=; b=QD2jUkX6YlEk6/IQJzkzGmB8lXwLvkQDgBf72Y3D5F1RJagFH0GKYc9YmfUhME7eWA 9dtNP8Gx0p0HN19/Qafhu4SnARSPfT/c09Nfk+80PG2T0BD9duna0CnVBQb2AZyR0yNm ZYc4wXqSPQZheVhOpcM754yQbxRDMC7NS7uuhp+VVNF++/vO07i1gVFdlBA5jaPVP2In BFsY2RQVGdpF9jkEJzynzmigky/xSG1+OkF+HtOP26ytiplq5acqiUiVgS6hyv22Gde6 vBTXmOcLWzYycAklwB546WMJH5nj1cbOFKSrhoqEjaX2JCbOYhgK5fuiOVe0l422AZK3 IFXg== X-Gm-Message-State: AJIora+2prDVv6XB6nXkqwMPqUdiiG9TGHiDgQfJqaSDcUiw78vSJvSR XTc9D9q0AkhdxUy5f4rGLGO0b7sk2v4= X-Google-Smtp-Source: AGRyM1sSxupj+zuoboxhbkSugiSNWO7sYWthUk7HXQ73ELSUtqT/NiZZPmh/kvNTGEKCCUwGY1HAZtb7R68= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:b597:b0:168:d8ce:4a63 with SMTP id a23-20020a170902b59700b00168d8ce4a63mr5925487pls.57.1655237271987; Tue, 14 Jun 2022 13:07:51 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:47 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-23-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 b62d93a15903..555e73f96982 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 8226aa5274f3..887272a33837 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -766,6 +766,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 B810CC43334 for ; Tue, 14 Jun 2022 20:09:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357313AbiFNUJ0 (ORCPT ); Tue, 14 Jun 2022 16:09:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357289AbiFNUIB (ORCPT ); Tue, 14 Jun 2022 16:08:01 -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 211C2403F8 for ; Tue, 14 Jun 2022 13:07:54 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id p123-20020a625b81000000b0051c31cc75dfso4237606pfb.5 for ; Tue, 14 Jun 2022 13:07: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=6sq6rj6hOcf7RofhLuTE1YZqxCrSxa9nH7bmYla6Ve4=; b=gtFwbBvlNOl94V69Y69CeUBN/v/9ZsmCJYxvsdf5jkijI3TKi8zWco4zFrPlLI/Dbr w30+1Ydf0dlNImj7N+ySceO8//UGPhQ6n4YwAHZlqV1n/Ad679e+Io29psdRUTx5JHlg gOhiVphWmk7dGAi5F9BOKfNXULxDAThXEOgoVdU7lbSiZqN1GR0dN9SnoT1dkIi4rBoq zvu7poj57gUnNJdxcl3MJ4+7ITtlOhtgX+rNitJJwq9OHq8AFQ1JWh2kf4Z895mBUqKz SQUey1k/WGWPnJMkVKfugkgwf9lV0D3oNPZcadjnl3rsLAJ+hUxqdr6I66YNpOH5EJFn OhrQ== 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=6sq6rj6hOcf7RofhLuTE1YZqxCrSxa9nH7bmYla6Ve4=; b=BueV7yDgWk9VuV0OO33zmAnZ7UwFNeWIRkKR384hTrmYaEq78rxIc8XrkvZGKyOK0w j/EL9SRfpKhAL0uzhgqLkvTADLweWmCy0XBvfilL33TIKgG2wq8flhDnSoYxgnvEaT6M QH+vn0xQzdScdsIzaCTpJcKb6l1Ri39IPTeiTd0Y2IaKak2Shte/HBI7IYn0eFWcrIUj gSj/avq5oCg5dRY2jQefp6Z7Q8A5V5548dyZncZlZLh+G+IrcgwU4jE7a8tq6Trfx2e1 k/yaWW+EZTtipBh1I3WvnsixGE4CWPIAd/LTunNvE7O8J31/KZOPpbO+rNAV/bNobikI guww== X-Gm-Message-State: AOAM530cEQ621w9/K0l/jHtQW2KRP3cFbQtlj6xKGYIwE3nkr22uy5Fx PKTi6lPhARQvEI90jOYcfB4+6XkuXQw= X-Google-Smtp-Source: ABdhPJwc8Qgd57+EiS3z0qYQYX/WbkXJMJSV/lS4my02g7V+8R8qwOxGczY3Ka2H3SpOwbUW1vGd2h2xDDM= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:aa7:8141:0:b0:518:425b:760e with SMTP id d1-20020aa78141000000b00518425b760emr6360171pfn.27.1655237273630; Tue, 14 Jun 2022 13:07:53 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:48 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-24-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 23/42] KVM: selftests: Use vm->pa_bits to generate reserved PA bits From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 887272a33837..5fd6563f23d1 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -221,16 +221,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 5997AC43334 for ; Tue, 14 Jun 2022 20:09:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357921AbiFNUJx (ORCPT ); Tue, 14 Jun 2022 16:09:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357294AbiFNUIC (ORCPT ); Tue, 14 Jun 2022 16:08:02 -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 DAE7611A30 for ; Tue, 14 Jun 2022 13:07:55 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id mh12-20020a17090b4acc00b001e32eb45751so8639929pjb.9 for ; Tue, 14 Jun 2022 13:07:55 -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=oGoInidDHUgzKInjiMzYTC4+hLGUBWpt78EcTlPSheA=; b=IWSBcmGtUu2yFATqX0U7jHGVdD1p/n2dDsQ+yvmCv87YVaEbIN1OuFmeSSu0oFY7LS L+cQ6/1STlUQl10EFzKOd5O7CoN3OVe9JBnr0Pzz2DAE73V4Z80kSpHagbaQL7ZTQMEy MIvw8zJXcCBeSIan6JK14ITPVFuTkcUkDKjhF8yXGAjYNEq6tCTDBt4lRH4C/Q48WchQ sVGGoBb2SltoUrDSLm+aSrC0q4K30KCX4X1sbLkTCsHuD7p1Gje+XjcF91sRm86FG25B yzbMF1w/HV69cl5+PBBWnheKL5t2aKRpUmFqMu2/CE2QJlMXNr8W/5Ep2tiYQjcHVwlu kHZQ== 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=oGoInidDHUgzKInjiMzYTC4+hLGUBWpt78EcTlPSheA=; b=UJGOL2NP4Qt03K66utOGuKy8oJu1IOzgw6dc5XA7yX+eIcXmlL4gVzxBjrFURFh0em Xe18MQldgudbytNpVobU4OZpLxnRgeM0jPDgFF3gHNq6dj/cv/o6JEkHIVbBUjm2LCQ+ 5+eCgjeJpnQsv9mX8rkzLJSB7wM0gf3JRmwrAjCJEt6bKw5vFwtX37EKZVrAT2KFmezv 4rRf4qxEd4WraA6u5Cor1E8iR2svntYEhd+VoIhXuUGDUuwg0QdHnjW9AEVatCnqUbTE YND96LiJFNBV/LgnDAYReIC+xORvKWL1vPKM7GsONj31QJSMGCv+FzIccrdwlHcFQSib 8hEg== X-Gm-Message-State: AOAM532OlMFCssWYKeZma29xE5C4+ZU+kqSOQC+e9kdB2wXJs3A/em8+ F07Ge5rWmVWJPf45dCpbjq2ihg6cpHs= X-Google-Smtp-Source: AGRyM1v1PPmjWq4SV8HLSELMJXXYJac3kl+1yrRZDnFUB/3o7xEpKnF+O4UkofHRAhv1VUtRac09srOrZT0= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:efc6:b0:167:8177:60a7 with SMTP id ja6-20020a170902efc600b00167817760a7mr5914061plb.110.1655237275404; Tue, 14 Jun 2022 13:07:55 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:49 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-25-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 555e73f96982..2097822b4b98 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 5fd6563f23d1..cdc35dd765e7 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -762,6 +762,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 8D299C433EF for ; Tue, 14 Jun 2022 20:09:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357254AbiFNUJa (ORCPT ); Tue, 14 Jun 2022 16:09:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357403AbiFNUIE (ORCPT ); Tue, 14 Jun 2022 16:08:04 -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 9F6604E397 for ; Tue, 14 Jun 2022 13:07:58 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id z5-20020aa79f85000000b0051baa4e9fb8so4240852pfr.7 for ; Tue, 14 Jun 2022 13:07: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=23Eq/JZXCr5ZESFLdA8mGk7iqKBFVcqZyF81SwbEVZM=; b=RZjhh4TeZyIoaM2EyrlYwJRdn0z7RGpPjZ1d48u6k5pF+BR8SW75Ymt/vhe5vcJS0d FwITp1anv20mqLl9pwoNzTm6zLuq+1UjDOAV9MYSl9VPtXZjdIE8mnQv/F0bSLN6Xl+P xUJcin4+BxjllggdfSEbMpBGvfLchuLG+3BrumI23xrenipl88VhEdnGM1RfUmYeO/Yh Qu7MEl45nl6XTY/Ge+3hlyzpPKL9PbET8UOIXVJz/f9a20OljWw+/6zu9OCn/xEd9hmh ORq9OEUdpCZOEqAm7w9U9EGCTkHFLuFyTnVtiUxPxczY9DDeZWcVdhOCI2/ieTcXEf85 pH7g== 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=23Eq/JZXCr5ZESFLdA8mGk7iqKBFVcqZyF81SwbEVZM=; b=AR/Iac34YkAtE1ISxJxPJBx7/U+Q4h/dM1+if0iKqv+Tc3e+kvZppVXKEi0Jk6bPzM Meg3FL7Hbp1u4fkhH6JuBmofV2lX1jYm6L2MH0tBy+tydpOi0ysOlStPNL5pzg4cuPjy lJrdkfGfkk+ZOsITmt7xQCx3+NzsEcTa9Mdx3SmE2fC2f1TZmLwjDJ9+klqVibhkFWg7 31Ssk36VLKtpiZ741x0XETMiJRV1wKSMl4OyWjeblaygREefuwjL6/KXKqVaFcxomXFN 6f1YDvu0XX1MHlwD0ZL0gtygPRzW7Zvy5BYcG0to+kOkeccPuI2JtMet5o7IqVPugDcr 37fA== X-Gm-Message-State: AJIora/17XOvps+P6WVHRgDevT+oXAYlln2+IRbZpvt1E0Pq7loC/HMz l7RQTTWlOVSoTvUVoGbKBgIPDxvmeP0= X-Google-Smtp-Source: AGRyM1tYZu8naFBrPOdwNY8kQHUsmExve1u10RgmcgbOUsZASefh0dCXTNMyGlGcwSOHtj8di5Fm+kDBgc0= 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-20020a17090a178f00b001e303bac185mr192391pja.1.1655237277256; Tue, 14 Jun 2022 13:07:57 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:50 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-26-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 2097822b4b98..65f3a828c903 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 cdc35dd765e7..99f72f3b4382 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -770,6 +770,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 92D64C43334 for ; Tue, 14 Jun 2022 20:09:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357513AbiFNUJn (ORCPT ); Tue, 14 Jun 2022 16:09:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357745AbiFNUIi (ORCPT ); Tue, 14 Jun 2022 16:08:38 -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 3699E4EF51 for ; Tue, 14 Jun 2022 13:08:07 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id x29-20020a056a000bdd00b0051c0902c1f3so4218908pfu.20 for ; Tue, 14 Jun 2022 13:08: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=oIKeCC07UA6rpS52rdp9U2pzOJ1GxJ81uiIJSJ491gE=; b=PmSrZeRRtWls9Tfis8/Wf3pjs0hyxa8C4PTmRxL+AqSvORmO/6E2fK4dt8WEHYXqLT ZwK5TEXLZvUpBgLmlJ7MozDXQv5KkmH5jOWEUqglrvxrjU1u8vYH9wM6rgJF1mPwdH+z E9osaEGZBCUKRltZs0mDWFQiVHFS5b7dhkg+4VaIN4fQ4zM5vwtI301AwzdrJxwOHpji ZhYU8+JHlmcTUdZ6VGk+tzCR8g1CzAbPer31Z4GZ7YrTO7z51xUaWWtPIFqhUz3gFbVZ VnUb0gEDe8F/ux5PfV1OfB6Rt/Tk0u6cWnBzEAQSlANr2I8qIOoauoLix7Nb6qP0gvo6 EWHw== 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=oIKeCC07UA6rpS52rdp9U2pzOJ1GxJ81uiIJSJ491gE=; b=NXevQBeaEBOArhIsIaBZiMxk/ZfYPrF+4fTEwsxman7eMCEp53kzoEyh0J/UMXnUxU 8BWv4XRbpMKqaPiBmkY54kIjyfJYXZv5y/7SBPQjckISH4h7JeY6tuWIpN7vGcbYADGI qiNuuQc+cWyfQTgYuFmuxcAbdP/dfN3uQ/yYpZEmeMvaTbTFa1copaCAvEc0rIaPTst/ o95U74IokthUN2W2UaHAFmaTr8aYGugLYh7Bi2lsp8HmtKIGNXnt8SI4w3E2HbAucJiz 3CGKbFcrRFcxJcWyrnEwbYYZruNu51gAJhxUAW+5L6rFA/i1NQrAI0o+Wa9ybLgCILMn 5+pA== X-Gm-Message-State: AJIora/BLoyF9xYFUaZKmreeQoxz74gZhKpDsy3qqL/UzqH5mItulxRc FiFMOeszabrh3QEDjoAxLuK91bD+AB8= X-Google-Smtp-Source: AGRyM1tV0u+UGlLTE9sAiNHAgB8Kde0ZNsd8TKtAwZjtproeO9Wa4Q0YDsTrl65QhNkID1969lBR/VluhWk= 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-20020a17090a178f00b001e303bac185mr192395pja.1.1655237279082; Tue, 14 Jun 2022 13:07:59 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:51 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-27-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 26/42] KVM: selftests: Use vCPU's CPUID directly in Hyper-V test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 65f3a828c903..fb8f98faa58b 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 99f72f3b4382..2a878703dc3f 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1207,24 +1207,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 C6579CCA47B for ; Tue, 14 Jun 2022 20:09:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357520AbiFNUJr (ORCPT ); Tue, 14 Jun 2022 16:09:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357794AbiFNUIj (ORCPT ); Tue, 14 Jun 2022 16:08:39 -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 67B234EF6E for ; Tue, 14 Jun 2022 13:08:09 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id x1-20020a170902ec8100b0016634ff72a4so5340468plg.15 for ; Tue, 14 Jun 2022 13:08: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=xo1qDgQfLuXoeUJsd2fB/DhbQ6NUNvOIxbn7J+1FRkI=; b=YAFZFhP4ujJ+4Z4z2Wzs5pJblK6AlYCVkpLyv4/Ji/q6/TLZKupD0qmSlBWboQLswM xQMp4YENRSgn7lLS90Q0x7/2FmGOgk96VUCA+KEEp6GMAk6ag6chPKsaDncgt4j3bva+ KTyvAQmMI3fbEpZNolhUH2iTNhxvz4UGBLcOkNCpIdVihOPeWF6XkoA27rSKadSa8aJ2 XYvKNAxIi2uanQyfP3jTNIWIzTfW+fJlm7mPAOITbk9DelYy0K8sZUeMKvEX5ghVByF5 OnStN04CJjgjqX7mGbvQ+k5HX5dO5f5eMF9qrbd2ppu5n5UqEqYdxjGrk9bF3MFaiIFc TI1Q== 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=xo1qDgQfLuXoeUJsd2fB/DhbQ6NUNvOIxbn7J+1FRkI=; b=TLaV7HLS7SJT1syo6BI+AwfqPaWohSi2Ik7UNaS98W4VdB7GgvSRLv1YbeV/VH04aI soNFocaQVmzjBZwI5qFRD6HE5elOukrsH5JQMULhcV2ldOs1u2PTYk/HIxDUJSzwHQ0k nU1hhh3F37/K3HAWFEM7ctkebz3Kn0NrPRp8x+44g9VARZLWM5dy4VeVz/uXODduOwhJ CHuSEG5eVGRfcKT91Egh3IreOShAdoZ61D7WgOeCXQ42nxpA90KvTtIaI0L8wprGoUL2 C72wiR46EibJH6ikDtY8/8bbxFlvkoZULe/BMTc2pa8Ou06AIJ5d+O0MvHXnG88C7g8w DY0g== X-Gm-Message-State: AJIora+NzfrpuhuOEaeDmHFYlbpc8VYJQNpFsDkHqjXKlL1N6ZuIBrA5 hPkG5Bxh16rhFhXU2L0jG+43OX2frh8= X-Google-Smtp-Source: AGRyM1tO2CBJtsKmDlSqCBIPkUlrozcg78gkzMsXmJdD2PKSXmOVgsKKc0huRWug6941nM+zyJ+YTU3SdIk= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:903:32c4:b0:163:e765:5071 with SMTP id i4-20020a17090332c400b00163e7655071mr5876009plr.153.1655237280764; Tue, 14 Jun 2022 13:08:00 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:52 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-28-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 27/42] KVM: selftests: Use vcpu_get_cpuid_entry() in CPUID test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 4A17AC433EF for ; Tue, 14 Jun 2022 20:09:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357617AbiFNUJ4 (ORCPT ); Tue, 14 Jun 2022 16:09:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357153AbiFNUIm (ORCPT ); Tue, 14 Jun 2022 16:08:42 -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 37F4F4EF7F for ; Tue, 14 Jun 2022 13:08:11 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id n65-20020a25da44000000b0066508f279e4so3876083ybf.4 for ; Tue, 14 Jun 2022 13:08: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=XhdgywsCTVr4zamq9DydAKZeu7w865wFF1QrREP6uEA=; b=XnMj9gGl/lKHOJ5mLjDMnRzDzsH54eEMvL+WKVfFoCu9AKiSMjvd/qLzQGeIWQjOmZ hi77l4USVL2B8BGMgKvtVSyjl/lsH0KzTmXG/WzXiV67+yYb970Mat9oqNgIsgczcmrS hQFfHGbc3tTEUmp/UjqmbIjfEqxXtN7noB5Q80nv1JpwGosVBph5iP0HYGO1T2oK4XL+ C2J/kz7mXhHG7uaTiuv1vJl/q9wG32J1uY7S8LmbjVRnL//RMPovtpSK+WU9w9om+F8G RvrDVrDdbo0qn7lKvCQSmV2p/qCZM/YnrwcZ5mJdN8NTAou/GOoUGbtKetJ3lkr2ltV1 NA2Q== 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=XhdgywsCTVr4zamq9DydAKZeu7w865wFF1QrREP6uEA=; b=IuLRcMJR3cxskJ3LOO+anEKfVI2JYx3GXIOE2FJe31mK1RzdTYZuURTUmS673GFArv e2qudA7YtOPuxF++ZfiA0I99HNzh4vPWGu2XmVR6Z7QvBQ4OHcvtkOmKddo+YaG2xMBs Lw6gc6N1begIQvEFAzKX17+mvX23Tif/XnDIeRI/WXbVWuSj9i8ce4cHbioubTcPXf9P kFdx3n9mrnk4oXhTpFLG/zQlAFt9WWZmFmdo9M4uwdAxHCgK8wDeQWWaw3QTyTYjNHGM OYnB1OHdtLMSH0PzzZi2sjghxofu3eTOqj7zx1hOxEKyoHDalZPl3/HAOl593/cMjzSB Aeeg== X-Gm-Message-State: AJIora+uAikYPPAC/xOCshJLmK4Hsk9igiyFwMRxmsy0HWxPqYMR1QjY ApXnyoELnH8joObQtmTxtER32m/s1b8= X-Google-Smtp-Source: AGRyM1vx5xJkm24U7PQboLNiezldUvmh9cSFVVSP1ea5iZIYyuZUVr/+NsX8hk36be26wtzmexXJ6A3SR7Y= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a25:7209:0:b0:663:f48e:83d6 with SMTP id n9-20020a257209000000b00663f48e83d6mr6716225ybc.76.1655237282704; Tue, 14 Jun 2022 13:08:02 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:53 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-29-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 fb8f98faa58b..0633196e7b79 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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 9CC14C433EF for ; Tue, 14 Jun 2022 20:09:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357403AbiFNUJk (ORCPT ); Tue, 14 Jun 2022 16:09:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357647AbiFNUIe (ORCPT ); Tue, 14 Jun 2022 16:08:34 -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 DBB5D11A1F for ; Tue, 14 Jun 2022 13:08:04 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id s10-20020a170902a50a00b00162359521c9so5325956plq.23 for ; Tue, 14 Jun 2022 13:08: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=7dK1gA3gQqs3fKdWhyCzD6xfEZc5UbOlaOb38QzqS2U=; b=EfidSeuIFghasfraZ/h9MY6yqwTwna2AYjeiLNaoG1XPpeGj8hqD/XONv0aLw+T4rk XipfpeJLj7y8ros9hl/NR4Wzo2ZSolo+APyf30zS+di7ZDk8pMKT31y9yay7d/aXd/aZ UGYyql+gZtqm5yttsA8J3L22Ab9c28Llr/DUAzQGK6YzaB9GaepTwZIODnUUnuqjBrog K9RcMSBzA75u++KgAZajQ0G1AG34vuohCykGQDijr8+xxdQ4vQdUgAfvVYsry/Bf5y5r LZsW75VLszGu7ubjZjo/F+zsC/AZKMaZThpT2BPIls3EOuBsYulJFkBhy2MuD3i02yOI 59PA== 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=7dK1gA3gQqs3fKdWhyCzD6xfEZc5UbOlaOb38QzqS2U=; b=iAL+8RSs3upGbpwOLQyZEmgY5Z3yV2DX2Eg1OVv3eTZKcOVHZ+g97IrHuGBblbqd7u EKKTOnVKdJD5zk+xndk88rdv4Na9JCDRQlzQzrrP7Sc2wX95I0///gVQiENXvh/QMWRf cLhrG6RQZLz3IjkwNohNuVwzs1naB4fiDxvWOcDuYussWribdsVqm9XYHXG3z+JKiArf RSNVdzxMRPmClu7T01fKt3dByQVynu1sgEr+WPwaSu73yO3bh2p1vWhkIHx3w56DEAOU 3wQCXmLh0LOQoSqWEAEptcioGD6kmtvOZzAZdi+kbsdzQkxS6FpUrmJwspBvyCxJHUnZ Uaag== X-Gm-Message-State: AOAM532ux6Pynma8+OB78ZjzNivs3KO309/vM73kpUugqYu9J+bYCOzD E+UokQYn0wHjRm2nj9tIhN92bwvyVEo= X-Google-Smtp-Source: ABdhPJwxNNqOpI9VOAwwy5MYZeAACQttRNAKCs5bimbP/mDlaSZ/xbLFtZQWnairbklsaQB1SVD2pgo4eBU= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a65:6c08:0:b0:3f2:6a6a:98d with SMTP id y8-20020a656c08000000b003f26a6a098dmr5888282pgu.30.1655237284555; Tue, 14 Jun 2022 13:08:04 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:54 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-30-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 29/42] KVM: selftests: Use vcpu_clear_cpuid_feature() to clear x2APIC From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 0633196e7b79..98d05e153fa3 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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 5819FC43334 for ; Tue, 14 Jun 2022 20:10:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357964AbiFNUKB (ORCPT ); Tue, 14 Jun 2022 16:10:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357416AbiFNUJC (ORCPT ); Tue, 14 Jun 2022 16:09:02 -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 D01394F1E7 for ; Tue, 14 Jun 2022 13:08:12 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id q9-20020a17090a1b0900b001e87ad1beadso17301pjq.1 for ; Tue, 14 Jun 2022 13:08: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=98aCqm9xw9nDmwuzmU0jJimOnA/h6/nIweHPxTZxc5M=; b=Htt41QOGs2JjQff/mGVeHLvR5We5QXTnpyiTvfFcegzpA2lPTINGRU/6pViGqTgt6Y 8pdris5VJYT/Ls2rcQrGIpihdKltRXLkXMstaD2NHRTif2RvfMq4VJxgbBL+9VufXNfY czFN/xb2gbxjY9EM3oMObGNVvZ1X3/w7amafpUyAytOM6f72ena38PB9JEtqY79VzhX2 u/jIRO+lZaLvj+ohGScTBKVmkzxG7WZEOenXCtUEx+hTHbHB5/fadLUN+s5hzYVpHEnt 4fS6wZ26PtdmhTeqkG1T6eZJQpUq692TiM2CX4WKlVEO3XsXfoLPz4UVeCZHz1ywlNuY iN3Q== 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=98aCqm9xw9nDmwuzmU0jJimOnA/h6/nIweHPxTZxc5M=; b=tgpfJq8SeUAnUEJSNGiufXULOTpnQapPa35bbxccd+WPQhRoUJJigDI50PlT4k3HYw q66lGCmN3GGOs4lMW/XkLQEHUgCjzkk8S+NeQzMzqFvtMnwEFSpnzy9Sj6upQIn8cYHw RrtjNv2ulTE3X39QOFUrPIzO1u1/R1s9WUOTe++DGh9kfFfkJ77m/InEGuUzRMix7Y3O +JGrG5nSSv69W/59zfV8wKupQ0LYi91XXiBuFrgoDE6KjX0jBh132FbZA89KHknaprPh XHoSB3CsEyAXiRkAQuKfHIgSN/jyhq81wNst51b+gHgbK2cXl2w9L4d7EvQ4aCHAizkb kfJw== X-Gm-Message-State: AOAM531/ui0AaoVeeRfZmRcuoa4vTzevG0RTLOYzJv2du+0iqp87+yFp AI0vCx8IYpITw6wJglX4pWG/xA4UIUs= X-Google-Smtp-Source: ABdhPJwQQ7atUFm1lXFyaMmlSSBxIAGy8UPBgUtugEt3COcHtGRUcML0zRBsKKPA6eztUx9QAXg52AAygf0= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6a00:218c:b0:51c:c64:3f6a with SMTP id h12-20020a056a00218c00b0051c0c643f6amr6054245pfi.50.1655237286151; Tue, 14 Jun 2022 13:08:06 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:55 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-31-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 30/42] KVM: selftests: Make get_supported_cpuid() returns "const" From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 98d05e153fa3..617b437ce0f9 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 pg_level { diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index 2a878703dc3f..eb73c690edd9 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -676,18 +676,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; @@ -745,7 +734,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 @@ -1079,7 +1068,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 */ @@ -1191,8 +1180,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 @@ -1218,7 +1207,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; @@ -1238,7 +1227,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) { @@ -1268,7 +1257,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 786b3a794f84..090d9c5e1c14 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 @@ -384,7 +384,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 }; @@ -400,10 +400,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) @@ -432,10 +432,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 46F36C433EF for ; Tue, 14 Jun 2022 20:10:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358011AbiFNUKW (ORCPT ); Tue, 14 Jun 2022 16:10:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357526AbiFNUJI (ORCPT ); Tue, 14 Jun 2022 16:09:08 -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 8633B26131 for ; Tue, 14 Jun 2022 13:08:15 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id cd16-20020a056a00421000b00520785db095so4226465pfb.15 for ; Tue, 14 Jun 2022 13:08: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=fsYs/Bc5rpxse3GLtefGgeT1BXM2hAUZSMcPuFOqZt8=; b=UxPNtGzjOcVb4Ln31qKWgNs8Puid2D2l/L8wZdNe8OuZX3epfyZRFQ+nP0x/VYJvSn /z2L00Lw2JpwQgHOxM98Ki8H52lWGYrKVJFMO/HPXQz1QmrpMCRlFfqT3gZYu7BTcNMk rm+y3KtfVoIdG4NkOgpb4BaZMQJKtiKMERIOryj/lsNUxwvGqBAkb1SNyh18KVpcEqzO AXtmOwDRr4nazbksGrnnTYlirI/AATF0b0U/Jl/cSWPLNbd4w3SnJMDN28lV3+AiTwP+ 6NU/Zs3lwCma9KuyKhGR0/uniP3lDIkCilShywwvMUwhZQLptXIoSsn7x/FYyeveTVwk GkQg== 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=fsYs/Bc5rpxse3GLtefGgeT1BXM2hAUZSMcPuFOqZt8=; b=t4eqexeK10lO6uQbb1p7kjjFles7HzjPklbSa8ujyarLbxWeFU+IOBlviG7tnP3TEf dYeaUUCHh/it8+46kPLMoNX+S8FyFhSOGI+n5tz9X+/3BDroBmYFIBhkpIoEJGG9KWfY tEJ8qrWrx81z+6Tc8obGgFfRDjyJk0q2R1OgYIXyZZbeWfjuhrT/s45of3zKozW3x55S VwiERGIFKtyaEh8KQ5+eOHEIawBNPu82UR4v9pIjXD5t5DvY+xT0cedPfHiAMEQjfozO hVF3/mHce2RF+9GsRGg39LFfuaV9nrlJElZ3PbTdE8Ls+yO9IDbEiDJbVkcPPq+8ATwL DndA== X-Gm-Message-State: AJIora907BP9UWO48JtQy2pBYWxKnSelKWK98EEJh/cN/ZCDx/PpFrF+ 0vSuLhUZLr5RNh90M5SHUwkptCaGKks= X-Google-Smtp-Source: AGRyM1t5wcpUgvUC0oVchaUGPZJJDC1R53MEqhqZYm/H7uxKLJ6kCZV9nvkk3k8jPOagL2eHu/iHr5ZS0hQ= 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-20020a17090a024900b001e0a8a33c6cmr192604pje.0.1655237288184; Tue, 14 Jun 2022 13:08:08 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:56 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-32-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 31/42] KVM: selftests: Set input function/index in raw CPUID helper(s) From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 617b437ce0f9..ed148607a813 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 eb73c690edd9..7bce93760cad 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1284,9 +1284,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 @@ -1295,18 +1293,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 C0F55C433EF for ; Tue, 14 Jun 2022 20:10:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357978AbiFNUKI (ORCPT ); Tue, 14 Jun 2022 16:10:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357577AbiFNUJJ (ORCPT ); Tue, 14 Jun 2022 16:09:09 -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 ECD7B4F452 for ; Tue, 14 Jun 2022 13:08:16 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id c4-20020a170902d48400b001640bfb2b4fso5328237plg.20 for ; Tue, 14 Jun 2022 13:08: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=4mAB76+I05WmZi+6YBbeLTbS4pzwCUEDOF/e/K6fR38=; b=BKqFVQj/ojsssYjh5WI51oMSrT0pRP/P38wzQsQVhxLze0+KuZcL91yBZ/NsVnJIk+ 67C/OCnj2rZW1JEM2ONXM4Eutq+Tptm/mrF9is+LKeJqpDGZwakgiCSFd+PFDLcx6MqZ 2v7qhbTX2XYNm0O4LCJP+UyfMyknn7Tat87VQMi7oVDznpIpTF3TUTMCK9+GiCJStyfO o9BVlcpe3lrcUph8ciwVsmacSiS61h9ZZUaQ0cf4LOIOVqi4f4FRYGjwyrrtrydOwASu L4HTAK+Gusd4Yg59tf5DytWEyX7X4dnTrFtRyMrGCZpXRAbyDQV/kw6KYiYvFGczPaz9 orJQ== 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=4mAB76+I05WmZi+6YBbeLTbS4pzwCUEDOF/e/K6fR38=; b=pNywPH76L7zTHGKCDoiWoE1SToGwFXxIUCcQZ1U4AvesY771hn4jEBC/1O67FALp92 JQuw95plm8ojXiA9yDDFQZEXKl00GQhHKQwUasBPJnVapSiHJ2pt61kVnCobdrUKpM2J t8hj3ZIyzoZmH5vLUA8F+xgWtTyYw4dkf6zp/9i5UP+B1z3nSh2vvpksPsfMVuc0iq0c if2QT5+3tbF+uxmcMJDQKsKDmTOzprENKrNPkZQO5mMlbAMm7B209NSFYYfq29o/XZ+q BHe4sdy2uV5Nu5xFR3CZAwV1Xo/nOj4Sdwc8BnVXSyCW2aH3b0SxxEqpOF/CwkkMvueG 7Y5w== X-Gm-Message-State: AOAM530h9XIf2fuvT4PsJkjsnaLlwraQ4Xu93lwUhpIsOMxI9YpxWx/G 7doUlK4xavlVuVCwFsToXKM4f/ahQ+8= X-Google-Smtp-Source: ABdhPJwLiFRNhyIb9FkHjj5TKdIOPnnGCc1Ubp8Aaww8I0LviFsV6ZedkJd8Hpv0I0Ijc32w2ZpfL8NQzl8= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a63:483:0:b0:3fc:9128:60a5 with SMTP id 125-20020a630483000000b003fc912860a5mr6021762pge.606.1655237290104; Tue, 14 Jun 2022 13:08:10 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:57 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-33-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 ed148607a813..be2ce21926db 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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 C91B4C433EF for ; Tue, 14 Jun 2022 20:10:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357993AbiFNUKS (ORCPT ); Tue, 14 Jun 2022 16:10:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357609AbiFNUJM (ORCPT ); Tue, 14 Jun 2022 16:09:12 -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 721664F457 for ; Tue, 14 Jun 2022 13:08:17 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id o8-20020a17090a9f8800b001dc9f554c7fso4075494pjp.4 for ; Tue, 14 Jun 2022 13:08: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=K0KRVkUMqr9HilXYEGpWol1qMgJzvxP/fvNXOBy5syI=; b=LfG8d16faXS6+zLzbmXubosAUEIUFvF8bXDbPYtOUm9Y+HqjxB9YZTMUGJwf+cV2bG t5aVb5T+ahQqimNhTlj+jhunK50HNOq3m7mJ2V9zrl184ByEGKI0HwUbzOnKOSFl5ZbE 7Y9+fi06/lft1N/mCJBZ89xvjeu2eiWxrwqOVNgmWjqqWz68NIrk16C0dhMCghrmRfLf 0+sFO/5L+62MMWiUE57UF/w2cpXgwK28fM/JkcPTDDcT99kklLghX4uNFM+XHn6CSXFv ywnAFXtccbqKrAvJXL0pVPYZI/tkIQuFxPiBqp9//WpSXfdMwlalA3H4HSHtEBDzQ8N3 iggA== 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=K0KRVkUMqr9HilXYEGpWol1qMgJzvxP/fvNXOBy5syI=; b=Le8Q6AO5iqx/vml5cvxdg7Osct+jek9Gp0mpW6byy84zSHXqMsCi7dyhOs2eLegGr4 Qc5GKd/uGJm+TiR+g0J4u930wOG23uLs2ll+Mip2J8kyVk8kYgU6NtAvoq5n0RtCP1U4 t4bgVdV3f98nIEjbQw0Wa0mXZb5aWdDYyVA/JSB9qkl3tnSoatb6XHsDSucVgG8Wd19d aSu+DpjrTsGZ4O2YrDtdRf8YxcHdLR/JrG4DXFLqZ7haJZDJPoGaUXIw/h8E5fHpUL5i hoZOzxiVyKAXtiVah9TgXQNvdFA+3yH2E1xHLqoGxUnpN6twEW7GajAx/ar4GRW7mLGV VXAw== X-Gm-Message-State: AOAM530GSeUC36273Q76jbp8dSrmOgTrMXDnQH11Tljac9z4wj2ynsrx M1uUF/Eb+BYsk6IP1v8KY5Da+D0gdXM= X-Google-Smtp-Source: AGRyM1vleOyhOHbogXs9WGT/bajRXjGNAhfi3rke+40RFJIhC7SDTzq8Q1z6IuDNBNmSfiMWg8T5DlA/HpY= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:e0cc:b0:167:82d5:4753 with SMTP id e12-20020a170902e0cc00b0016782d54753mr5899159pla.138.1655237291812; Tue, 14 Jun 2022 13:08:11 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:58 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-34-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 33/42] KVM: selftests: Use this_cpu_has() in CR4/CPUID sync test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 be2ce21926db..f56a3a7a4246 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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 268C2C43334 for ; Tue, 14 Jun 2022 20:10:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358074AbiFNUKi (ORCPT ); Tue, 14 Jun 2022 16:10:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357334AbiFNUJ0 (ORCPT ); Tue, 14 Jun 2022 16:09:26 -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 CB6CF4F9D8 for ; Tue, 14 Jun 2022 13:08:21 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id 15-20020a63020f000000b003fca9ebc5cbso5442475pgc.22 for ; Tue, 14 Jun 2022 13:08:21 -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=VAWi7Bdww9IG9P9iwSIPXN8TXA1x0JQZXp9kmqWl1Y4=; b=L6HRWDOfXbPW+DDR3STq/bmXiXYmh0xgwyIlyEUU9EPaQg6uVNUUlXOfqp2XRgOUKi g4ZxjUFuxYkw36mZXH/nwbe+BiCZecowWl83RhmTvocYTPSFH+xFXGeW7daq8LBbI6hK j/GYyhXNAboO1pn3/7/DoRSrqs95VhLSmVL6JaWbuvZeq7Hjp3kHb3EZ1JMnH1zskAw0 Z2RTjO2UsXinXae3KqXFrtsSBMlFH6F1LIAZy0/IN6FsKMJ0O0pGnPBOY39iFnrF4eo0 6YoTqOC4SdlkdY85+fBbuEeXD/rfz8SwOOJ/OobIwxQRwqoqN+4RTgxdpmUTZ/E4EiP3 +5Rg== 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=VAWi7Bdww9IG9P9iwSIPXN8TXA1x0JQZXp9kmqWl1Y4=; b=FwYom43iQ+5cBuJG4XnFMEXvRJBAMvM5HC9P9Uc1PoG9lNGWMSGMGurECJyoqjNGP0 V/FoFg/seku8fUG+tnKo9fkee3AsvLau1DNP18rNGTK91EdLGqEQ9+zh5VsNHsX+7Fpb SpLTjbNjrapk6mR2L89Qu8FCs4e+EGjsIhOsfrPMS4eTyjMNjVqcuR66P0wyl17fTmOX 5GPxSBfHdI825Y389I18ES1ul/iOLrVE7MYI/48NZrPFu4SbwNIvW8GlAIJv+KkPBSPh e/fAVQxTzTHusS9QmhZC9hFzf8DPgNn0frkMsysk4LilxRW9pcv42CKkWxar1MfhZBjH 349A== X-Gm-Message-State: AJIora9zM/rAQoSlYk46Jp05MyFj76ME4+fPOAqn3U8sJa9MwfwAFxL9 UusUSgscxSiHuxAaM8JbhvPL7ebAcN0= X-Google-Smtp-Source: AGRyM1s4nEeW+5kwThDu7KkeacO/t1l1CoHigrin+2yNEeHYbfc2GanaMhB00e8aRt8zt11kSjJ5CIi7Efo= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90b:3b86:b0:1e8:6b89:2bb2 with SMTP id pc6-20020a17090b3b8600b001e86b892bb2mr6335631pjb.15.1655237293659; Tue, 14 Jun 2022 13:08:13 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:06:59 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-35-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 2012DC43334 for ; Tue, 14 Jun 2022 20:10:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357875AbiFNUKn (ORCPT ); Tue, 14 Jun 2022 16:10:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357873AbiFNUJl (ORCPT ); Tue, 14 Jun 2022 16:09: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 2AF5E4F9FE for ; Tue, 14 Jun 2022 13:08:25 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id j4-20020a170902da8400b00168b0b2341dso5354325plx.5 for ; Tue, 14 Jun 2022 13:08:25 -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=h3RwRgkH3viEGiVwk/Kgcg86FthLy8sfCzc8sgc8x6g=; b=nW9P7nc/G0v2UnLMGl9qvPdqSulKgM4tJFUFYxG70973c4HXppFyOG+ju5TMrzEXpl Wi2zWgxr6qe6Ab690h7RYd8dVpmToVW7edcZv30K/gVCH0inG+XFCbsMNNf3/PQJ49vX iHz6c2OggoWiI52qOShJvqG8DkAIUd2D95GxE9Voh30CdJAZi3oy4WGi3pufjTlG071A bY3xQN5OPOhmilPp+GXPWGeq1xKj9SQYnrVJK92KiBJYm+2sePiKppv1Amwq/mfqsKXY mRJsLXv88LKTsg/gxXjHb7tKfKDncX9xAWZwd1jUf9xlViUKJM1hSFgGip0q4Ns1tna6 803g== 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=h3RwRgkH3viEGiVwk/Kgcg86FthLy8sfCzc8sgc8x6g=; b=kTQT29+PA1of38V2uH1pfpzhZdJbP4r4YZ8mmzmo6JngIV6k9shCfUn9l9BT1LrI2M cH9/VCbVjex3f6GIvmbumoeQfh6n+mC+QUUd8VYf3ZZtlomltd5AOPdh4KkmrvOToPV7 ei7OvoKVgeFF0r9LPk+LAqAnkFp03NMXEleiPHmyvQjwuVhpsOhHIzZWFF77zYFX2h4U IVSl3qCkdbErkgbeDVCg3rMQEZwjf8NLXtDwRv6mXBlvgRQXuKTqbxRjr/Wy+oVTy1qy MqsKjXNXsmwfFec50u9rJcYuUFZbuUg3hd3OfTeLbAalnYwHn8ic1UbklI6vWN9t+sn6 VTIg== X-Gm-Message-State: AOAM530ns2UOT0CwUOFwxL89n5pmMuje6zrOLVhxE+bNu8VG9/Qerx6s jMdaLyl60JmNnB6mbcmu/yF9mFP3m0Q= X-Google-Smtp-Source: ABdhPJyFrnV1rrk/NTa+jhcmzHIM6bDAAj7JaQLfoXiXnGj8jlCJSVCAbWSCLy3A5amhaXjqwUPVHbqklrY= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6a00:248a:b0:51b:f461:8318 with SMTP id c10-20020a056a00248a00b0051bf4618318mr6300396pfv.47.1655237295488; Tue, 14 Jun 2022 13:08:15 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:07:00 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-36-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 35/42] KVM: selftests: Drop unnecessary use of kvm_get_supported_cpuid_index() From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 090d9c5e1c14..9179e1377bc1 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 @@ -402,7 +402,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 @@ -434,7 +434,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 A8247C433EF for ; Tue, 14 Jun 2022 20:10:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357834AbiFNUKy (ORCPT ); Tue, 14 Jun 2022 16:10:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357558AbiFNUJq (ORCPT ); Tue, 14 Jun 2022 16:09:46 -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 D17D44FC64 for ; Tue, 14 Jun 2022 13:08:29 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id c10-20020a170903234a00b00168b5f7661bso5338691plh.6 for ; Tue, 14 Jun 2022 13:08:29 -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=8CAKrp2Z8ftc2PspLOtgMbM3jnTmjfGGexJauokjvSQ=; b=LP06UuiX73tTu8Qg7T/691M0mzRF0kjN7OVbuQAf60HJbvRNImjYmbTOvJYQZrPnIR YWchqRCu1wHbGDsqBAj4Nl++xVMEaSQ8CUiV0f+OiEtR/fcUsS0FO4DXM28zelnF0wwF PfmR4ND+Up9ZHuTmUDagxP0ie0CkptdavgZlT2Wd4zNeb8JCAMA9RZzBenxoiQsPPyEW XktGDJd74lyIul3dbDy77GyVJ1ndKWcqKg4VPfmz9Q22YUhJARZ2Bg5zHVnIIxvl4JLi /l34r20C0uZv7sYs6QHEn9eCI5q/RMw3lEQpAaR7RGsmOfd4hq4CDFgPQxuW4hyZtpLx ozOw== 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=8CAKrp2Z8ftc2PspLOtgMbM3jnTmjfGGexJauokjvSQ=; b=zYCz2oXa+He3vb+zjKgYbuZR348nRzWzIVxMrsWTBgwL2O9m+ous241cnWvztzu4y3 5nIrCiN2/S4kvzZpoFwbp4RC0N14L35bt/bgQi/wb/842bO/eC3+OmyirPkXxRIB5LIl e0XwkOL+PMncPhCtpeQQLdZ8u18prYMxqlwD9R4I9HCYXq55zimsbKkJg6ai6kSbVoj8 4N18SNcdlubYGrE/RWB6eSO6kdtuNjp/HUqi+SwdTrnpaIzxzpmQJqNRj1uHWo/DJDw+ yfyg58fLbSj2K+zamPDaMR0kjuRHdRjhUThg4sSpcBbyuU790CI0h27D+Zz99EewiR/j 9xKA== X-Gm-Message-State: AOAM533o7brYThZh6lMYOiBWQbQErflz2DqBWDY68SBM8cHHCRWq36my UTI1hbBSxCNLpG7MrkseygzgCKWrQVw= X-Google-Smtp-Source: ABdhPJyddL2Xxx5Ba016b/xeNk7X22tFDKDeOdgQTAwBpplAF+EoXjNwbLs8Vcen8+EViIVd2cuCdJf/qKI= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:aa7:990e:0:b0:51f:2b9f:6402 with SMTP id z14-20020aa7990e000000b0051f2b9f6402mr6299117pff.9.1655237297066; Tue, 14 Jun 2022 13:08:17 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:07:01 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-37-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 36/42] KVM: selftests: Rename kvm_get_supported_cpuid_index() to __..._entry() From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 f56a3a7a4246..311ddc899322 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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 B34C8C43334 for ; Tue, 14 Jun 2022 20:10:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358027AbiFNUK0 (ORCPT ); Tue, 14 Jun 2022 16:10:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357694AbiFNUJP (ORCPT ); Tue, 14 Jun 2022 16:09: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 087274F471 for ; Tue, 14 Jun 2022 13:08:18 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id p123-20020a625b81000000b0051c31cc75dfso4237606pfb.5 for ; Tue, 14 Jun 2022 13:08: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=o3z+boBvvuABIlKxvViYzVtbgDDM2QmQlL0qvBp6XMI=; b=IzAQAcpsNM1EVPwh75OuwuNE/EuroO7nOIrXJjywOj+SCFXcrreHAx5p2O+bIpTR80 cLB5h07YA92d8XsSI63WQMa3fMaUjrPwcz6h8AGS589ZG/ZVusDCDkpHUgFmv3DOsVXU ArEeQDWBXSNufx8+04mkDV0Uf2Z1szeuhWUGnmJsm8TY02BY0A/aUXfMmiksIFnB13uZ y/VvHvNTR4tby1DhQRQQ25HTuezE0zLe8IogrR3V93XM6nLh4IuCU59Rec5pzMjhkuza QRou5yQzqxFuL0lecIDavFmQ6mFujZLcyR9hIKuDtjsgPOvYDY5xnd2Rl5krMCXbQsSy dgJA== 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=o3z+boBvvuABIlKxvViYzVtbgDDM2QmQlL0qvBp6XMI=; b=BI3eCnm/9cELUnOIflFf/eA+8S2/pGFqtli2lvaLrXoMBosK46A1IjaNZnPi2RACU7 CDVqxjyDyxEvDUCYIhKsfQltZeuZLugiATM7x9TLsoFYpN0Ji7ztarO7fr4avsI9KP4y s++JxEx7EigqH9brWdYYR2LE+/uMrgkRhrgt4fsJUBsRNNzNQNoJiUThSJFlrJV4EmMT swmQvbbrPSRthJ0G1XKnKJTNhnNeRRta2MHFtePZbEdH/4fvQPhsVYZPl+ae2yIj9dIq zpLe4FcYFSdiwVcxofPzBxtG06qwgDZcceRuVxx9PlVqfJKxRnKPSZGGzZ/dLYyIg7Nn z9aw== X-Gm-Message-State: AOAM530cG0IM395+dFaRXB4dE4l9Z91NTA8w3zYyMVUkQF0HL6zLJhOZ Z2yEE6DdlOlSWqE1O1GIpboj+ArWIy8= X-Google-Smtp-Source: ABdhPJyOHezLBoiZzom/lI2EvhUINKbJYNeT+S59G7Bjs/W8A1gXffmixvdqvPkhIBTuTJWpZxVe6PI2LVQ= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a63:6b02:0:b0:3fb:da5e:42a1 with SMTP id g2-20020a636b02000000b003fbda5e42a1mr5911425pgc.273.1655237298696; Tue, 14 Jun 2022 13:08:18 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:07:02 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-38-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 37/42] KVM: selftests: Inline "get max CPUID leaf" helpers From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 311ddc899322..fd0da7eb2058 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 7bce93760cad..522972e0d42c 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1056,16 +1056,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 7F9A8C43334 for ; Tue, 14 Jun 2022 20:11:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234934AbiFNULD (ORCPT ); Tue, 14 Jun 2022 16:11:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357747AbiFNUKf (ORCPT ); Tue, 14 Jun 2022 16:10:35 -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 3689F4FC77 for ; Tue, 14 Jun 2022 13:08:31 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id e18-20020a656492000000b003fa4033f9a7so5448205pgv.17 for ; Tue, 14 Jun 2022 13:08:31 -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=lCIfRU6G43lIwYqasc5Sb9W/ChPMCByn+h4LqEdr0K8=; b=TTCI+yuU+cTfab7HcwwHxQ6dTczkYUNTBGxGGJhQItC1oLQZv90OwxYvRvRJZo7Ji1 mg+mJ8BywDCJIDzQ0Vc6MOd3u/0sh4ZNtSfADTTauouR1xu35i7+dOzuHNXTayzfXY4p yi/BPq5XwRkUf5nxVRWi/elQ4c9qog/QFYtkrUfZzXhAs0ESnknpz5Bry1fa80yF2aDZ K+vw8Z0OaR4KHwi0ns8il9DS7gFoG4Aj+FQhWgztivZDvv7H5p2699T544PhdBqgSPv7 Chl8FurWlgH2uFtDKeT3Ebs+0LHICufzqzlz4p5aBY6egyRQ1RzFryEWCCemEhu8c56B esUw== 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=lCIfRU6G43lIwYqasc5Sb9W/ChPMCByn+h4LqEdr0K8=; b=Gv6CeLjjTV2gUpEl/pj+4eBYl86yUTaO52DBBvE4A0rko+hwker8tC/HPe5J/3ifj2 fxCSGObWxrHapYW1G3FwYk78rnOt5Ui7RGM+lviesDaJnrPXIVlzFoKJbDiU9exwjNIg qoMDWg9XZaC01SIb6i6V8ZxSAnqK41mp0vQZeSrWZsSEuNZpinXoPpCemSMQg6UHuca4 mgEpq4SKcH2oFCRjwWKIipc9hNHE4w1S5Tlo73lJnkNtjhJWQM3Ut75qHhttyeEA/U27 SHX3OGqI8ZLOZ0FSk/hMCnu1Fv9N/cq6bxALvtAb/wQMJBg9G8yYVBqlXWqCuPqYra6D 55TA== X-Gm-Message-State: AJIora/BZ2+7mh4M+N3cFYbfN50ig1K2+5dSF6N/ji1JmkEmY68/C8ZI mBLDJT2slH7UCunyF35I7MAgPJ3q2Bw= X-Google-Smtp-Source: ABdhPJzoEzevP/PwRbSKVIQ4Tz2wPS6giYd9onsycWbuCqTMli3rR7FudOBzwK21m8boKoYEtWJmsGrRtp0= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:903:244b:b0:167:74f3:74aa with SMTP id l11-20020a170903244b00b0016774f374aamr5814638pls.67.1655237300483; Tue, 14 Jun 2022 13:08:20 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:07:03 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-39-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 fd0da7eb2058..b51227ccfb96 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 522972e0d42c..c7fe584c71ed 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -578,21 +578,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; @@ -604,6 +589,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); @@ -614,8 +601,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 AA88DC433EF for ; Tue, 14 Jun 2022 20:11:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357886AbiFNULL (ORCPT ); Tue, 14 Jun 2022 16:11:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358051AbiFNUKh (ORCPT ); Tue, 14 Jun 2022 16:10:37 -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 0C2EBBE19 for ; Tue, 14 Jun 2022 13:08:34 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id 78-20020a630051000000b003fe25580679so5455757pga.9 for ; Tue, 14 Jun 2022 13:08:34 -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=GcnQGtIgWgA8fnCOJZ2NC0z3fNMByJKLtilK+3LRet8=; b=UUtRfLBdt6WVEsGg8pTCK6naNVhi6UmL2mpQWCl4tgb+SWxp688YfD43lVCKfntZtp ulzBd3n3DXfhY32sqPSq40Uo8lgJ2qnSVRsBRN/OswminfCDsUmo8WOzC3xnw6s2nQ/q 0dDOIAinhyxAs6/Lq9gY5rAhptG1Mz8jcWsyPLBMz2EQb66gZlz3QFYnaLHAcEYoXwS7 Dnwv7Qe7yRYZ2lVH9FTCVwXKXYpHIWub63SuXvefqgHcw785Ez7TKcdYSM5xIy7cr4L5 8NMLQ2m+hy+43ld5vGxlvk5tWwo9B9gGRE8po6sm6g6mvdSSQHfExeqUkQE06XrYY96M 5Msg== 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=GcnQGtIgWgA8fnCOJZ2NC0z3fNMByJKLtilK+3LRet8=; b=MAeVUSnMJNCd6qJU1FAO7kNcetbTZpQOSp7oR7Upem7UGFGthCtSRkXpDI5EM2sbL8 o2RuMCHApAYXoQimnYvJxVYV/sfTan6eVqxURhtj5dqNRvDIr47i/EqQTlqqJpVi5pvG 5FQz8zUd5qOIMTd9sL7lMC0oIHRwRY8OfjVPuG1VnwGhvyCaIKfElLCOtiuBEmfqRNhz UTynqyhwXtuBCv1vWFZ0DN5/CAupBIPcUU1mbJFHXhkSpAgaeh1QGQ6BgA8676f+jVYQ 9Ob6AnbUeIp8/zBk5qLMF4EM/qxJW/EAXcwrkSw1omfWzge88thi7EMGrJr1Q/Hj44EP j+aw== X-Gm-Message-State: AJIora/4Ihn+3X1zzE8eFojyilfMjnYda+DsBbGDudO1Se1a/S93KFAh zpCJ42yu02o+LUexf6FpyXOuxI5oy9g= X-Google-Smtp-Source: AGRyM1tbmRuWodF0xUlWN6zVml/CAWJNtDGr7rzGXaVv3e5/LmimEj98XorvzTGzIlQDPkTO0GS2+EyRaz4= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90b:1d02:b0:1e6:961d:d56f with SMTP id on2-20020a17090b1d0200b001e6961dd56fmr6287808pjb.225.1655237302377; Tue, 14 Jun 2022 13:08:22 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:07:04 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-40-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 c7fe584c71ed..ee346a280482 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -601,14 +601,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 13248C433EF for ; Tue, 14 Jun 2022 20:11:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358094AbiFNULH (ORCPT ); Tue, 14 Jun 2022 16:11:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357289AbiFNUKh (ORCPT ); Tue, 14 Jun 2022 16:10:37 -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 5ADB44B1C6 for ; Tue, 14 Jun 2022 13:08:35 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id t24-20020a170902b21800b00168e27c3c2aso3363126plr.18 for ; Tue, 14 Jun 2022 13:08:35 -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=+JUUrANpcy0WjjSaiXZvhzOGdtbSexwErj2l4cNYJS4=; b=Vb6Fxn9aW/ul2PuLhdqDpBabNbGgeHaHowJIejicivMlRiTuveW2wSWYlyj8pjeGcD Mc86DtuoPa63NN5X2eCCV9xegjdN+JE3VK9F2XensCypsWWMEFpKCFMFULfsG2kR++3D kW3z8ZlsCnWm4SXmgEm2sMh5O/qYrG9GysgrHHgSP2uu7aofa2NvtGkcChgZujvq4aXK kcZlFttFF88PaiFHDmyL0ihlkgq3+yyC3UweBLXypfk07710ZQIE+vf+X7QfHaxLcF+4 p4iRdkRkFD/wWdDDi91ZmSZsWyVT8IIR3RaGoP8gqpic9ZmExjPt4R1tMPkT6kse8qN/ EoDQ== 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=+JUUrANpcy0WjjSaiXZvhzOGdtbSexwErj2l4cNYJS4=; b=CRvdwzEP3ZrfikzbMt6MZwWOTfOjK7EAhA3WYL200mbubdPGfdhcs4qh+wClhp1x+o Bi0U7tgfnuvz3UfNJluP0PXxiwH3KtKVppwjrtD0wVv+K1N3ESf2TFjusWvjVT3mSewF 9aqwF+qhddx0gGvr/mXWU9nCg3MNXNiEm6GysZHVzJl9ZgDx9hv6oDkpuLmCj4cDNZCu jQnaBhIRKyf/xitpPTCFRLB9DUJYq9VHCEYocmo17daAv0ODINQL1ZntGm1AV9yDpukO gOp8tg1W+rX1p/kpDBBacCoRcdPT8UUe6gmjrJwMNIu2+zeNdI6RT0WWhU6oaJ9wQWZT b1RQ== X-Gm-Message-State: AOAM533SOuTefsYSeMf9IvFXQFP7K3qLl8x5GlgnAp9k7Pc8gmpzBXAt M+VKBZlzwnOwzCxEuBYksHZIoqGweRw= X-Google-Smtp-Source: ABdhPJwnUdjdJO83HH4EqAXo+UyDJs0dAsj30iouzGW8CMW3p9szyM5Gb6CDc09QkFopB/4B4KXP2M0us9I= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:aa7:9f84:0:b0:51b:b64d:fc69 with SMTP id z4-20020aa79f84000000b0051bb64dfc69mr6412254pfr.7.1655237303978; Tue, 14 Jun 2022 13:08:23 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:07:05 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-41-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 40/42] KVM: selftests: Clean up requirements for XFD-aware XSAVE features From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 b51227ccfb96..19c023f767fc 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 pg_level { PG_LEVEL_NONE, diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/tes= ting/selftests/kvm/lib/x86_64/processor.c index ee346a280482..d606ee2d970a 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -578,7 +578,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; @@ -596,10 +596,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 867B9C43334 for ; Tue, 14 Jun 2022 20:11:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357900AbiFNULQ (ORCPT ); Tue, 14 Jun 2022 16:11:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358080AbiFNUKi (ORCPT ); Tue, 14 Jun 2022 16:10: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 797954D9E0 for ; Tue, 14 Jun 2022 13:08:36 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id t24-20020a170902b21800b00168e27c3c2aso3363153plr.18 for ; Tue, 14 Jun 2022 13:08: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=/uGXcjYgRdwThYzoVEngvsjuBTkNgyg4uSxffZc50Bk=; b=pzfVMA20p2pnNldqq01nGCMA5u/qRXcRcGB7M5KM+fz/WvBFzJMig40OUcz7HZ7WRe M5dmPWiMIisozQJp2yWvSJqz0rej3BW1dhb1o8s6sv0ceYHY0/0xHDFtEcjHpM912iJf ED7ooCsSdoKKLIro/Xax0qMRIZ3fBCu3Su0BsRbb5l1jrXg/j0cn1lDScQ9UwZaLZy4T 7Gh7BmDpDDXUobaRtKDaNyxEX2dVwWoCtnlFOwlUGtHnhR04IIg5pwD9Ve9kouqjzJKA jmkYJ8+UB7yTEEIwkAbML6UzIZfNQWcuK5MeaqxnSPf8yk0VaJ6DwrhF9iX8lnOZzq9E hN4Q== 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=/uGXcjYgRdwThYzoVEngvsjuBTkNgyg4uSxffZc50Bk=; b=itVby3O+UUETnXctSLpMPwLLHVeI3vNib4xaTHbJx3aWEnbwvfnlcw6h9v2U0qmEXE h6lu+oVjdvWQZ0JCbHjkaTTKxSeysH4fGE9vUou/kD9MomvOLz99JYkSTYmM0zQsr7VH qOsVeHl1mC1XzXjgn7pT24N+pQiiS/bAgOM6ZUQwzyfmCP4jnq5wZOJ6STVr2ZfPFudh zP1JmQcVIp8m+/h1LF9PbcNSDRMJs4r+3gqaq50eUuXkiMTVMeZeu2myMVmR3s1gT7YF 6OaKhKdXbvmQsUoZ9drs2xGVfzTQdxiiitVo4OzXNLjNCVpjt4Qj/CYyiaTNVR7/uNPz ZeWw== X-Gm-Message-State: AOAM530+U4gOmrAVeumnp57vKXj9X8E8EoBMVB6Vjpk5Dte2fp5OIH+J sa+Q6o4fDJ6vl/zhqRQezrOxCfLbWhg= X-Google-Smtp-Source: ABdhPJyx++YntFm0WsQdNfldGACaB/WlL3fz/aantDLV1wzIbzfVFkyeMg44LApwWEef3B57OG4/I6G9LgI= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a05:6a00:4406:b0:51c:244f:85d8 with SMTP id br6-20020a056a00440600b0051c244f85d8mr6275367pfb.36.1655237305726; Tue, 14 Jun 2022 13:08:25 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:07:06 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-42-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 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, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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 d606ee2d970a..936ad738ad4a 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c @@ -1011,15 +1011,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.476.g0c4daa206d-goog From nobody Mon Apr 27 10:05:32 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 B0372C43334 for ; Tue, 14 Jun 2022 20:11:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357619AbiFNULT (ORCPT ); Tue, 14 Jun 2022 16:11:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357334AbiFNUKj (ORCPT ); Tue, 14 Jun 2022 16:10:39 -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 242194D9E4 for ; Tue, 14 Jun 2022 13:08:37 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id o16-20020a170902d4d000b00166d7813226so5345261plg.13 for ; Tue, 14 Jun 2022 13:08:37 -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=PJnlmNpDUw7STxIFmSjFwcfSAZgkd9fbeUjZMsv1LHA=; b=TkCuCdr3DpRCtXXD9LiJCJrqfX+6Ep+D8GsO66RIYfJwCWm5tsN2UpsnNeUbqoDgzc IOC34y1OqtMQEGzm7jZUBS49jRI2mCT/eS4ICJHTlXx6UHxeecv8ypgle+JVcW8+7H/t NYL1JDtBBSVyMWUVbXUAbkWSzYM1xSsCYxlmXykCMMPnFnc5IpE5jlkRIZNmh/kODxNv VIWAL0KiWsooPZ9RuMDQodhhq81fekiwE5qBgGNm5bK2tflgpkaKkrt/b66Z45SMkJ63 LGEzJitMPuLtHyIC73JET0BVf94Ip3e6rBKAcBMVfVJ/iDGgxqeD8DqSA2p/WFsdr29v /4cw== 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=PJnlmNpDUw7STxIFmSjFwcfSAZgkd9fbeUjZMsv1LHA=; b=YZnzvZl4qhcOECZr2U3qrj0hbSK9XpkYCB93kL2EppXOplEK0mXszCEdZa18t3meV8 7Wa6Ki9EAOvL2DODPUs9Bkm3m2eS4oCmfS4GcNzi8KiSfTO9ATpacLRAUzQJRlPAGGeo +oc89DAZ2Xz0M4OwdhWIdjlB3p0P9ecsSUpAU+uzhsScyaIwfFhiefHaAAPDK3P0jBRV Q2D6mlpdG7Z8H/90z2VMtUSxDdIGKN1+lngOS41jhxz09coxurHaO9YNCCQTMkYyodHZ bD8hj4kkV+ISXmwHz/eQRbFmXjQ8AgCGdmdbWPgcBtpwat2EDEHRyXK3Jja0WRYs5jwg 5c2A== X-Gm-Message-State: AOAM532Qsji5BXDWs4ech4klYeEL303qx1fxmONDFE67aR+Y73D/veFU hzlrN5fmIUqHmhpACrcjpyzru9Wh7bM= X-Google-Smtp-Source: ABdhPJzcaivXKiKvWFdb2C7A5+oPu4QwxuurTm707cyW1Zg6UjB+HkY6ZL43Uxh2Enfsj4DSX85UowNeAMk= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a62:d10e:0:b0:51b:d711:b189 with SMTP id z14-20020a62d10e000000b0051bd711b189mr6449271pfg.40.1655237307579; Tue, 14 Jun 2022 13:08:27 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 14 Jun 2022 20:07:07 +0000 In-Reply-To: <20220614200707.3315957-1-seanjc@google.com> Message-Id: <20220614200707.3315957-43-seanjc@google.com> Mime-Version: 1.0 References: <20220614200707.3315957-1-seanjc@google.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [PATCH v2 42/42] KVM: selftests: Drop unused SVM_CPUID_FUNC macro From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Jim Mattson 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.476.g0c4daa206d-goog