diff mbox series

[3/5] x86/spec-ctrl: Remove open-coded check of SVM_FEATURE_SPEC_CTRL

Message ID 20240429151625.977884-4-andrew.cooper3@citrix.com (mailing list archive)
State New
Headers show
Series x86: AMD CPUID handling improvements | expand

Commit Message

Andrew Cooper April 29, 2024, 3:16 p.m. UTC
Now that the SVM feature leaf has been included in normal feature handling, it
is available early enough for init_speculation_mitigations() to use.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Xenia Ragiadakou <xenia.ragiadakou@amd.com>
CC: Sergiy Kibrik <Sergiy_Kibrik@epam.com>
CC: George Dunlap <george.dunlap@citrix.com>
CC: Andrei Semenov <andrei.semenov@vates.fr>
CC: Vaishali Thakkar <vaishali.thakkar@vates.tech>
---
 xen/arch/x86/include/asm/cpufeature.h | 3 +++
 xen/arch/x86/spec_ctrl.c              | 7 +------
 2 files changed, 4 insertions(+), 6 deletions(-)

Comments

Jan Beulich April 30, 2024, 1:13 p.m. UTC | #1
On 29.04.2024 17:16, Andrew Cooper wrote:
> Now that the SVM feature leaf has been included in normal feature handling, it
> is available early enough for init_speculation_mitigations() to use.
> 
> No functional change.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>
even if ...

> --- a/xen/arch/x86/include/asm/cpufeature.h
> +++ b/xen/arch/x86/include/asm/cpufeature.h
> @@ -217,6 +217,9 @@ static inline bool boot_cpu_has(unsigned int feat)
>  #define cpu_has_rfds_no         boot_cpu_has(X86_FEATURE_RFDS_NO)
>  #define cpu_has_rfds_clear      boot_cpu_has(X86_FEATURE_RFDS_CLEAR)
>  
> +/* CPUID level 0x8000000a.edx */
> +#define cpu_has_v_spec_ctrl     boot_cpu_has(X86_FEATURE_V_SPEC_CTRL)

... the names here were to change (see comment on the earlier patch). In
fact ...

> @@ -1896,12 +1895,8 @@ void __init init_speculation_mitigations(void)
>           *
>           * No need for SCF_ist_sc_msr because Xen's value is restored
>           * atomically WRT NMIs in the VMExit path.
> -         *
> -         * TODO: Adjust cpu_has_svm_spec_ctrl to be usable earlier on boot.
>           */
> -        if ( opt_msr_sc_hvm &&
> -             (boot_cpu_data.extended_cpuid_level >= 0x8000000aU) &&
> -             (cpuid_edx(0x8000000aU) & (1u << SVM_FEATURE_SPEC_CTRL)) )
> +        if ( opt_msr_sc_hvm && cpu_has_v_spec_ctrl )
>              setup_force_cpu_cap(X86_FEATURE_SC_MSR_HVM);
>      }

... the use here demonstrates my earlier point quite well: It being AMD's
feature is completely invisible here when not considering the code being
replaced. But yes, when looking at the entire comment / block, it still
is visible.

Jan
diff mbox series

Patch

diff --git a/xen/arch/x86/include/asm/cpufeature.h b/xen/arch/x86/include/asm/cpufeature.h
index 9bc553681f4a..77cfd900cb56 100644
--- a/xen/arch/x86/include/asm/cpufeature.h
+++ b/xen/arch/x86/include/asm/cpufeature.h
@@ -217,6 +217,9 @@  static inline bool boot_cpu_has(unsigned int feat)
 #define cpu_has_rfds_no         boot_cpu_has(X86_FEATURE_RFDS_NO)
 #define cpu_has_rfds_clear      boot_cpu_has(X86_FEATURE_RFDS_CLEAR)
 
+/* CPUID level 0x8000000a.edx */
+#define cpu_has_v_spec_ctrl     boot_cpu_has(X86_FEATURE_V_SPEC_CTRL)
+
 /* Synthesized. */
 #define cpu_has_arch_perfmon    boot_cpu_has(X86_FEATURE_ARCH_PERFMON)
 #define cpu_has_cpuid_faulting  boot_cpu_has(X86_FEATURE_CPUID_FAULTING)
diff --git a/xen/arch/x86/spec_ctrl.c b/xen/arch/x86/spec_ctrl.c
index 40f6ae017010..0bda9d01def5 100644
--- a/xen/arch/x86/spec_ctrl.c
+++ b/xen/arch/x86/spec_ctrl.c
@@ -11,7 +11,6 @@ 
 #include <xen/warning.h>
 
 #include <asm/amd.h>
-#include <asm/hvm/svm/svm.h>
 #include <asm/intel-family.h>
 #include <asm/microcode.h>
 #include <asm/msr.h>
@@ -1896,12 +1895,8 @@  void __init init_speculation_mitigations(void)
          *
          * No need for SCF_ist_sc_msr because Xen's value is restored
          * atomically WRT NMIs in the VMExit path.
-         *
-         * TODO: Adjust cpu_has_svm_spec_ctrl to be usable earlier on boot.
          */
-        if ( opt_msr_sc_hvm &&
-             (boot_cpu_data.extended_cpuid_level >= 0x8000000aU) &&
-             (cpuid_edx(0x8000000aU) & (1u << SVM_FEATURE_SPEC_CTRL)) )
+        if ( opt_msr_sc_hvm && cpu_has_v_spec_ctrl )
             setup_force_cpu_cap(X86_FEATURE_SC_MSR_HVM);
     }