x86: Improvements and fixes to Spectre handling
cover x86: Improvements and fixes to Spectre handling
In hindsight, the end result of the Spectre mitigations aren't as great as I'd hoped, and have several inefficiencies. Also, the bti= command line option isn't as flexible as intended.
This series does four things:
1) Some internal cleanup, for clarity and to help the other features
2) Introduce spec-ctrl=no-pv mode. XenServer's performance measurements see a 10% net/disk performance improvement in some production scenarios.
3) Introduce the ability to use IBPB-only mode for guests. This was discussed by Amazon during the Spectre work, but I don't have any performance numbers to hand.
4) Avoid imposing IBRS mode while dom0 is booting. This was reported by Oracle on the list, and speeds up boot time on some servers by 50s.
I know this series is rather late for 4.11, but seeing as I've managed to complete it before 4.12 opens, it should be considered at this point, as all of the Spectre code is new in 4.11.
Andrew Cooper (10):
x86/spec_ctrl: Read MSR_ARCH_CAPABILITIES only once
x86/spec_ctrl: Express Xen's choice of MSR_SPEC_CTRL value as a variable x86/spec_ctrl: Merge bti_ist_info and use_shadow_spec_ctrl into spec_ctrl_flags x86/spec_ctrl: Fold the XEN_IBRS_{SET,CLEAR} ALTERNATIVES together x86/spec_ctrl: Rename bits of infrastructure to avoid NATIVE and VMEXIT x86/spec_ctrl: Split X86_FEATURE_SC_MSR into PV and HVM variants x86/spec_ctrl: Explicitly set Xen's default MSR_SPEC_CTRL value x86/cpuid: Improvements to guest policies for speculative sidechannel features x86/spec_ctrl: Introduce a new spec-ctrl= command line argument to replace bti= x86/spec_ctrl: Elide MSR_SPEC_CTRL handling in idle context when possible
docs/misc/xen-command-line.markdown | 49 +++++++ xen/arch/x86/acpi/power.c | 4 +- xen/arch/x86/cpuid.c | 60 +++++---- xen/arch/x86/hvm/svm/entry.S | 4 +- xen/arch/x86/hvm/vmx/entry.S | 4 +- xen/arch/x86/setup.c | 7 + xen/arch/x86/smpboot.c | 8 ++ xen/arch/x86/spec_ctrl.c | 258 ++++++++++++++++++++++++++++-------- xen/arch/x86/x86_64/asm-offsets.c | 4 +- xen/arch/x86/x86_64/compat/entry.S | 2 +- xen/arch/x86/x86_64/entry.S | 2 +- xen/include/asm-x86/cpufeatures.h | 9 +- xen/include/asm-x86/current.h | 4 +- xen/include/asm-x86/spec_ctrl.h | 20 +-- xen/include/asm-x86/spec_ctrl_asm.h | 131 +++++++++--------- 15 files changed, 396 insertions(+), 170 deletions(-)
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/10 x86/spec_ctrl: Read MSR_ARCH_CAPABILITIES only once
Make it available from the beginning of init_speculation_mitigations(), and pass it into appropriate functions. Fix an RSBA typo while moving the affected comment.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Juergen Gross <[email protected]>
--- xen/arch/x86/spec_ctrl.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-)
xen/arch/x86/spec_ctrl.c +14 -20
@@ -97,18 +97,15 @@ static int __init parse_bti(const char *s) }custom_param ("bti" , parse_bti); -static void __init print_details (enum ind_thunk thunk) +static void __init print_details (enum ind_thunk thunk,uint64_t caps) {unsigned int _7d0 =0 , e8b =0 , tmp; -uint64_t caps =0 ;/* Collect diagnostics about available mitigations. */ if ( boot_cpu_data.cpuid_level >=7 )cpuid_count (7 ,0 , &tmp, &tmp, &tmp, &_7d0);if ( boot_cpu_data.extended_cpuid_level >=0x80000008 )cpuid (0x80000008 , &tmp, &e8b, &tmp, &tmp); -if ( _7d0 &cpufeat_mask (X86_FEATURE_ARCH_CAPS ) ) -rdmsrl (MSR_ARCH_CAPABILITIES , caps);printk (XENLOG_DEBUG "Speculative mitigation facilities:\n" );
@@ -142,7 +139,7 @@ static void __init print_details(enum ind_thunk thunk) }/* Calculate whether Retpoline is known-safe on this CPU. */ -static bool __init retpoline_safe (void ) +static bool __init retpoline_safe (uint64_t caps) {unsigned int ucode_rev =this_cpu (ucode_cpu_info).cpu_sig.rev;
@@ -153,19 +150,12 @@ static bool __init retpoline_safe(void) boot_cpu_data.x86 != 6 )return false; -if (boot_cpu_has (X86_FEATURE_ARCH_CAPS ) ) - { -uint64_t caps; - -rdmsrl (MSR_ARCH_CAPABILITIES , caps); - -/* -* RBSA may be set by a hypervisor to indicate that we may move to a -* processor which isn't retpoline-safe. -*/ -if ( caps &ARCH_CAPS_RSBA ) -return false; - } +/* +* RSBA may be set by a hypervisor to indicate that we may move to a +* processor which isn't retpoline-safe. +*/ +if ( caps &ARCH_CAPS_RSBA ) +return false;switch ( boot_cpu_data.x86_model ) {
@@ -299,6 +289,10 @@ void __init init_speculation_mitigations(void) {enum ind_thunk thunk =THUNK_DEFAULT ;bool ibrs = false; +uint64_t caps =0 ; + +if (boot_cpu_has (X86_FEATURE_ARCH_CAPS ) ) +rdmsrl (MSR_ARCH_CAPABILITIES , caps);/* * Has the user specified any custom BTI mitigations? If so, follow their
@@ -327,7 +321,7 @@ void __init init_speculation_mitigations(void)* On Intel hardware, we'd like to use retpoline in preference to * IBRS, but only if it is safe on this hardware. */ - else if ( retpoline_safe() ) + else if ( retpoline_safe(caps) ) thunk =THUNK_RETPOLINE ; else if ( boot_cpu_has(X86_FEATURE_IBRSB) ) ibrs = true;
@@ -418,7 +412,7 @@ void __init init_speculation_mitigations(void)else setup_clear_cpu_cap (X86_FEATURE_NO_XPTI ); -print_details (thunk); +print_details (thunk, caps); }static void __init __maybe_unused build_assertions (void )
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 01/10] x86/spec_ctrl: Read MSR_ARCH_CAPABILITIES only once
Quoted 5 lines · Andrew Cooper
Make it available from the beginning of
init_speculation_mitigations(), and pass it into appropriate functions. Fix an RSBA typo while moving the affected comment.Signed-off-by Andrew Cooper <[email protected]>
Thank you!
Quoted 105 lines
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Juergen Gross <[email protected]>--- xen/arch/x86/spec_ctrl.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-)xen/arch/x86/spec_ctrl.c +14
-20@@ -97,18 +97,15 @@ static int __init parse_bti(const char *s) }custom_param ("bti" , parse_bti); -static void __init print_details (enum ind_thunk thunk) +static void __init print_details (enum ind_thunk thunk,uint64_t caps) {unsigned int _7d0 =0 , e8b =0 , tmp; -uint64_t caps =0 ;/* Collect diagnostics about available mitigations. */ if ( boot_cpu_data.cpuid_level >=7 )cpuid_count (7 ,0 , &tmp, &tmp, &tmp, &_7d0);if ( boot_cpu_data.extended_cpuid_level >=0x80000008 )cpuid (0x80000008 , &tmp, &e8b, &tmp, &tmp); -if ( _7d0 &cpufeat_mask (X86_FEATURE_ARCH_CAPS ) ) -rdmsrl (MSR_ARCH_CAPABILITIES , caps);printk (XENLOG_DEBUG "Speculative mitigation facilities:\n" );@@ -142,7 +139,7 @@ static void __init print_details(enum ind_thunk thunk) }/* Calculate whether Retpoline is known-safe on this CPU. */ -static bool __init retpoline_safe (void ) +static bool __init retpoline_safe (uint64_t caps) {unsigned int ucode_rev =this_cpu (ucode_cpu_info).cpu_sig.rev;@@ -153,19 +150,12 @@ static bool __init retpoline_safe(void) boot_cpu_data.x86 != 6 )return false; -if (boot_cpu_has (X86_FEATURE_ARCH_CAPS ) ) - { -uint64_t caps; - -rdmsrl (MSR_ARCH_CAPABILITIES , caps); - -/* -* RBSA may be set by a hypervisor to indicate that we may move to a -* processor which isn't retpoline-safe. -*/ -if ( caps &ARCH_CAPS_RSBA ) -return false; - } +/* +* RSBA may be set by a hypervisor to indicate that we may move to a +* processor which isn't retpoline-safe. +*/ +if ( caps &ARCH_CAPS_RSBA ) +return false;switch ( boot_cpu_data.x86_model ) {@@ -299,6 +289,10 @@ void __init init_speculation_mitigations(void) {enum ind_thunk thunk =THUNK_DEFAULT ;bool ibrs = false; +uint64_t caps =0 ; + +if (boot_cpu_has (X86_FEATURE_ARCH_CAPS ) ) +rdmsrl (MSR_ARCH_CAPABILITIES , caps);/* * Has the user specified any custom BTI mitigations? If so, follow their @@ -327,7 +321,7 @@ void __init init_speculation_mitigations(void)* On Intel hardware, we'd like to use retpoline in preference to * IBRS, but only if it is safe on this hardware. */ - else if ( retpoline_safe() ) + else if ( retpoline_safe(caps) ) thunk =THUNK_RETPOLINE ; else if ( boot_cpu_has(X86_FEATURE_IBRSB) ) ibrs = true;@@ -418,7 +412,7 @@ void __init init_speculation_mitigations(void)else setup_clear_cpu_cap (X86_FEATURE_NO_XPTI ); -print_details (thunk); +print_details (thunk, caps); }static void __init __maybe_unused build_assertions (void )Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 01/10] x86/spec_ctrl: Read MSR_ARCH_CAPABILITIES only once
In reply to Andrew CooperQuoted 5 lines · Andrew Cooper
Make it available from the beginning of
init_speculation_mitigations(), and pass it into appropriate functions. Fix an RSBA typo while moving the affected comment.Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/10 x86/spec_ctrl: Express Xen's choice of MSR_SPEC_CTRL value as a variable
In reply to Andrew CooperAt the moment, we have two different encodings of Xen's MSR_SPEC_CTRL value, which is a side effect of how the Spectre series developed. One encoding is via an alias with the bottom bit of bti_ist_info, and can encode IBRS or not, but not other configuraitons such as STIBP.
Break Xen's value out into a separate variable (in the top of stack block for XPTI reasons) and use this instead of bti_ist_info in the IST path.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Juergen Gross <[email protected]>
--- xen/arch/x86/spec_ctrl.c | 8 +++++--- xen/arch/x86/x86_64/asm-offsets.c | 1 + xen/include/asm-x86/current.h | 1 + xen/include/asm-x86/spec_ctrl.h | 2 ++ xen/include/asm-x86/spec_ctrl_asm.h | 8 ++------ 5 files changed, 11 insertions(+), 9 deletions(-)
xen/arch/x86/spec_ctrl.c +5 -3
@@ -38,6 +38,7 @@ static int8_t __initdata opt_ibrs = -1;static bool __initdata opt_rsb_native = true;static bool __initdata opt_rsb_vmexit = true;bool __read_mostly opt_ibpb = true; +uint8_t __read_mostly default_xen_spec_ctrl;uint8_t __read_mostly default_bti_ist_info;static int __init parse_bti (const char *s)
@@ -366,11 +367,14 @@ void __init init_speculation_mitigations(void)* guests. */ if ( ibrs ) + { + default_xen_spec_ctrl |=SPEC_CTRL_IBRS ;setup_force_cpu_cap (X86_FEATURE_XEN_IBRS_SET ); + }else setup_force_cpu_cap (X86_FEATURE_XEN_IBRS_CLEAR ); - default_bti_ist_info |=BTI_IST_WRMSR | ibrs; + default_bti_ist_info |=BTI_IST_WRMSR ; }/*
@@ -417,8 +421,6 @@ void __init init_speculation_mitigations(void)static void __init __maybe_unused build_assertions (void ) { -/* The optimised assembly relies on this alias. */ -BUILD_BUG_ON (BTI_IST_IBRS !=SPEC_CTRL_IBRS ); }/*
xen/arch/x86/x86_64/asm-offsets.c +1 -0
@@ -134,6 +134,7 @@ void __dummy__(void) OFFSET(CPUINFO_xen_cr3, struct cpu_info, xen_cr3); OFFSET(CPUINFO_pv_cr3, struct cpu_info, pv_cr3); OFFSET(CPUINFO_shadow_spec_ctrl, struct cpu_info, shadow_spec_ctrl); + OFFSET(CPUINFO_xen_spec_ctrl, struct cpu_info, xen_spec_ctrl); OFFSET(CPUINFO_use_shadow_spec_ctrl, struct cpu_info, use_shadow_spec_ctrl); OFFSET(CPUINFO_bti_ist_info, struct cpu_info, bti_ist_info); OFFSET(CPUINFO_root_pgt_changed, struct cpu_info, root_pgt_changed);
xen/include/asm-x86/current.h +1 -0
@@ -54,6 +54,7 @@ struct cpu_info {/* See asm-x86/spec_ctrl_asm.h for usage. */ unsigned int shadow_spec_ctrl; +uint8_t xen_spec_ctrl;bool use_shadow_spec_ctrl;uint8_t bti_ist_info;
xen/include/asm-x86/spec_ctrl.h +2 -0
@@ -27,6 +27,7 @@void init_speculation_mitigations (void );extern bool opt_ibpb; +extern uint8_t default_xen_spec_ctrl;extern uint8_t default_bti_ist_info;extern uint8_t opt_xpti;
@@ -38,6 +39,7 @@ static inline void init_shadow_spec_ctrl_state(void)struct cpu_info *info =get_cpu_info (); info->shadow_spec_ctrl = info->use_shadow_spec_ctrl =0 ; + info->xen_spec_ctrl = default_xen_spec_ctrl; info->bti_ist_info = default_bti_ist_info; }
xen/include/asm-x86/spec_ctrl_asm.h +2 -6
@@ -21,7 +21,6 @@#define __X86_SPEC_CTRL_ASM_H__/* Encoding of the bottom bits in cpuinfo.bti_ist_info */ -#define BTI_IST_IBRS (1 << 0)#define BTI_IST_WRMSR (1 << 1)#define BTI_IST_RSB (1 << 2)
@@ -283,12 +282,9 @@ setz %dl and %dl, STACK_CPUINFO_FIELD(use_shadow_spec_ctrl)(%r14) -/* -* Load Xen's intended value. SPEC_CTRL_IBRS vs 0 is encoded in the -* bottom bit of bti_ist_info, via a deliberate alias with BTI_IST_IBRS. -*/ +/* Load Xen's intended value. */ mov $MSR_SPEC_CTRL, %ecx - and $BTI_IST_IBRS, %eax + movzbl STACK_CPUINFO_FIELD(xen_spec_ctrl)(%r14), %eax xor %edx, %edx wrmsr
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 02/10] x86/spec_ctrl: Express Xen's choice of MSR_SPEC_CTRL value as a variable
Quoted 9 lines · Andrew Cooper
At the moment, we have two different encodings of Xen's
MSR_SPEC_CTRLvalue, which is a side effect of how the Spectre series developed. One encoding is via an alias with the bottom bit ofbti_ist_info, and can encode IBRS or not, but not other configuraitons such as STIBP.Break Xen's value out into a separate variable (in the top of stack block for XPTI reasons) and use this instead of
bti_ist_infoin the IST path.Signed-off-by Andrew Cooper <[email protected]>
xen/arch/x86/spec_ctrl.c void __init init_speculation_mitigations(void) · line 421
Quoted 8 lines
/*xen/arch/x86/spec_ctrl.c +0
-2@@ -417,8 +421,6 @@ void __init init_speculation_mitigations(void)static void __init __maybe_unused build_assertions (void ) { -/* The optimised assembly relies on this alias. */ -BUILD_BUG_ON (BTI_IST_IBRS !=SPEC_CTRL_IBRS );
I was about to suggest removing this function entirely but it is in fact filled in later, so this is fine.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 3/10 x86/spec_ctrl: Merge bti_ist_info and use_shadow_spec_ctrl into spec_ctrl_flags
In reply to Andrew CooperAll 3 bits of information here are control flags for the entry/exit code behaviour. Treat them as such, rather than having two different variables.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Juergen Gross <[email protected]>
--- xen/arch/x86/acpi/power.c | 4 ++-- xen/arch/x86/spec_ctrl.c | 10 ++++---- xen/arch/x86/x86_64/asm-offsets.c | 3 +-- xen/include/asm-x86/current.h | 3 +-- xen/include/asm-x86/spec_ctrl.h | 10 ++++---- xen/include/asm-x86/spec_ctrl_asm.h | 46 ++++++++++++++++++++----------------- 6 files changed, 40 insertions(+), 36 deletions(-)
xen/arch/x86/acpi/power.c +2 -2
@@ -215,7 +215,7 @@ static int enter_state(u32 state) ci =get_cpu_info ();spec_ctrl_enter_idle (ci);/* Avoid NMI/#MC using MSR_SPEC_CTRL until we've reloaded microcode. */ - ci->bti_ist_info =0 ; + ci->spec_ctrl_flags &= ~SCF_ist_wrmsr;ACPI_FLUSH_CPU_CACHE ();
@@ -259,7 +259,7 @@ static int enter_state(u32 state)panic ("Missing previously available feature(s)." );/* Re-enabled default NMI/#MC use of MSR_SPEC_CTRL. */ - ci->bti_ist_info = default_bti_ist_info; + ci->spec_ctrl_flags |= (default_spec_ctrl_flags & SCF_ist_wrmsr);spec_ctrl_exit_idle (ci); done:
xen/arch/x86/spec_ctrl.c +6 -4
@@ -39,7 +39,7 @@ static bool __initdata opt_rsb_native = true;static bool __initdata opt_rsb_vmexit = true;bool __read_mostly opt_ibpb = true;uint8_t __read_mostly default_xen_spec_ctrl; -uint8_t __read_mostly default_bti_ist_info; +uint8_t __read_mostly default_spec_ctrl_flags;static int __init parse_bti (const char *s) {
@@ -374,7 +374,7 @@ void __init init_speculation_mitigations(void)else setup_force_cpu_cap (X86_FEATURE_XEN_IBRS_CLEAR ); - default_bti_ist_info |=BTI_IST_WRMSR ; + default_spec_ctrl_flags |= SCF_ist_wrmsr; }/*
@@ -393,7 +393,7 @@ void __init init_speculation_mitigations(void)if ( opt_rsb_native ) {setup_force_cpu_cap (X86_FEATURE_RSB_NATIVE ); - default_bti_ist_info |=BTI_IST_RSB ; + default_spec_ctrl_flags |= SCF_ist_rsb; }/*
@@ -407,7 +407,7 @@ void __init init_speculation_mitigations(void)if ( !boot_cpu_has (X86_FEATURE_IBRSB ) && !boot_cpu_has (X86_FEATURE_IBPB ) ) opt_ibpb = false; -/* (Re)init BSP state now that default_bti_ist_info has been calculated. */ +/* (Re)init BSP state now that default_spec_ctrl_flags has been calculated. */ init_shadow_spec_ctrl_state ();xpti_init_default (false);
@@ -421,6 +421,8 @@ void __init init_speculation_mitigations(void)static void __init __maybe_unused build_assertions (void ) { +/* The optimised assembly relies on this alias. */ +BUILD_BUG_ON (SCF_use_shadow !=1 ); }/*
xen/arch/x86/x86_64/asm-offsets.c +1 -2
@@ -135,8 +135,7 @@ void __dummy__(void) OFFSET(CPUINFO_pv_cr3, struct cpu_info, pv_cr3); OFFSET(CPUINFO_shadow_spec_ctrl, struct cpu_info, shadow_spec_ctrl); OFFSET(CPUINFO_xen_spec_ctrl, struct cpu_info, xen_spec_ctrl); - OFFSET(CPUINFO_use_shadow_spec_ctrl, struct cpu_info, use_shadow_spec_ctrl); - OFFSET(CPUINFO_bti_ist_info, struct cpu_info, bti_ist_info); + OFFSET(CPUINFO_spec_ctrl_flags, struct cpu_info, spec_ctrl_flags); OFFSET(CPUINFO_root_pgt_changed, struct cpu_info, root_pgt_changed); OFFSET(CPUINFO_use_pv_cr3, struct cpu_info, use_pv_cr3);DEFINE (CPUINFO_sizeof,sizeof (struct cpu_info ));
xen/include/asm-x86/current.h +1 -2
@@ -55,8 +55,7 @@ struct cpu_info {/* See asm-x86/spec_ctrl_asm.h for usage. */ unsigned int shadow_spec_ctrl;uint8_t xen_spec_ctrl; -bool use_shadow_spec_ctrl; -uint8_t bti_ist_info; +uint8_t spec_ctrl_flags;/* * The following field controls copying of the L4 page table of 64-bit
xen/include/asm-x86/spec_ctrl.h +5 -5
@@ -28,7 +28,7 @@ void init_speculation_mitigations(void);extern bool opt_ibpb;extern uint8_t default_xen_spec_ctrl; -extern uint8_t default_bti_ist_info; +extern uint8_t default_spec_ctrl_flags;extern uint8_t opt_xpti;#define OPT_XPTI_DOM0 0x01
@@ -38,9 +38,9 @@ static inline void init_shadow_spec_ctrl_state(void) {struct cpu_info *info =get_cpu_info (); - info->shadow_spec_ctrl = info->use_shadow_spec_ctrl =0 ; + info->shadow_spec_ctrl =0 ; info->xen_spec_ctrl = default_xen_spec_ctrl; - info->bti_ist_info = default_bti_ist_info; + info->spec_ctrl_flags = default_spec_ctrl_flags; }/* WARNING! `ret`, `call *`, `jmp *` not safe after this call. */
@@ -54,7 +54,7 @@ static always_inline void spec_ctrl_enter_idle(struct cpu_info *info)*/ info->shadow_spec_ctrl = val;barrier (); - info->use_shadow_spec_ctrl = true; + info->spec_ctrl_flags |= SCF_use_shadow;barrier (); asm volatile ( ALTERNATIVE(ASM_NOP3, "wrmsr", X86_FEATURE_XEN_IBRS_SET) :: "a" (val), "c" (MSR_SPEC_CTRL), "d" (0) : "memory" );
@@ -69,7 +69,7 @@ static always_inline void spec_ctrl_exit_idle(struct cpu_info *info)* Disable shadowing before updating the MSR. There are no SMP issues * here; only local processor ordering concerns. */ - info->use_shadow_spec_ctrl = false; + info->spec_ctrl_flags &= ~SCF_use_shadow;barrier (); asm volatile ( ALTERNATIVE(ASM_NOP3, "wrmsr", X86_FEATURE_XEN_IBRS_SET) :: "a" (val), "c" (MSR_SPEC_CTRL), "d" (0) : "memory" );
xen/include/asm-x86/spec_ctrl_asm.h +25 -21
117 lines not on this page · raw message
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 03/10] x86/spec_ctrl: Merge bti_ist_info and use_shadow_spec_ctrl into spec_ctrl_flags
Quoted 4 lines · Andrew Cooper
All 3 bits of information here are control flags for the entry/exit code behaviour. Treat them as such, rather than having two different variables.
Signed-off-by Andrew Cooper <[email protected]>
This patch does what it says on the tin.
FWIW:
Quoted 6 lines
xen/include/asm-x86/spec_ctrl_asm.h +0
-0@@ -20,9 +20,10 @@#ifndef __X86_SPEC_CTRL_ASM_H__
xen/include/asm-x86/spec_ctrl_asm.h line 27
Quoted 10 lines
xen/include/asm-x86/spec_ctrl_asm.h +4
-3#define __X86_SPEC_CTRL_ASM_H__ -/* Encoding of the bottom bits in cpuinfo.bti_ist_info */ -#define BTI_IST_WRMSR (1 << 1) -#define BTI_IST_RSB (1 << 2) +/* Encoding of cpuinfo.spec_ctrl_flags */ +#define SCF_use_shadow (1 << 0) +#define SCF_ist_wrmsr (1 << 1) +#define SCF_ist_rsb (1 << 2)
Fancy turning them into 1u << X while you're at it?
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 4/10 x86/spec_ctrl: Fold the XEN_IBRS_{SET, CLEAR} ALTERNATIVES together
In reply to Andrew CooperCurrently, the SPEC_CTRL_{ENTRY,EXIT}_* macros encode Xen's choice of MSR_SPEC_CTRL as an immediate constant, and chooses between IBRS or not by doubling up the entire alternative block.
There is now a variable holding Xen's choice of value, so use that and simplify the alternatives.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Juergen Gross <[email protected]>
--- xen/arch/x86/spec_ctrl.c | 12 +++++----- xen/include/asm-x86/cpufeatures.h | 3 +-- xen/include/asm-x86/spec_ctrl.h | 6 ++--- xen/include/asm-x86/spec_ctrl_asm.h | 45 +++++++++++++------------------------ 4 files changed, 24 insertions(+), 42 deletions(-)
xen/arch/x86/spec_ctrl.c +5 -7
@@ -128,8 +128,9 @@ static void __init print_details(enum ind_thunk thunk, uint64_t caps) thunk ==THUNK_RETPOLINE ?"RETPOLINE" : thunk ==THUNK_LFENCE ?"LFENCE" : thunk ==THUNK_JMP ?"JMP" :"?" , -boot_cpu_has (X86_FEATURE_XEN_IBRS_SET ) ?" IBRS+" : -boot_cpu_has (X86_FEATURE_XEN_IBRS_CLEAR ) ?" IBRS-" :"" , +boot_cpu_has (X86_FEATURE_SC_MSR ) ? + default_xen_spec_ctrl &SPEC_CTRL_IBRS ?" IBRS+" : +" IBRS-" :"" , opt_ibpb ?" IBPB" :"" ,boot_cpu_has (X86_FEATURE_RSB_NATIVE ) ?" RSB_NATIVE" :"" , boot_cpu_has(X86_FEATURE_RSB_VMEXIT) ? " RSB_VMEXIT" : "");
@@ -366,13 +367,10 @@ void __init init_speculation_mitigations(void)* need the IBRS entry/exit logic to virtualise IBRS support for * guests. */ +setup_force_cpu_cap (X86_FEATURE_SC_MSR ); +if ( ibrs ) - { default_xen_spec_ctrl |=SPEC_CTRL_IBRS ; -setup_force_cpu_cap (X86_FEATURE_XEN_IBRS_SET ); - } -else -setup_force_cpu_cap (X86_FEATURE_XEN_IBRS_CLEAR ); default_spec_ctrl_flags |= SCF_ist_wrmsr; }
xen/include/asm-x86/cpufeatures.h +1 -2
@@ -26,8 +26,7 @@ XEN_CPUFEATURE(LFENCE_DISPATCH, (FSCAPINTS+0)*32+12) /* lfence set as Dispatch S XEN_CPUFEATURE(IND_THUNK_LFENCE,(FSCAPINTS+0)*32+13) /* Use IND_THUNK_LFENCE */ XEN_CPUFEATURE(IND_THUNK_JMP, (FSCAPINTS+0)*32+14) /* Use IND_THUNK_JMP */ XEN_CPUFEATURE(XEN_IBPB, (FSCAPINTS+0)*32+15) /* IBRSB || IBPB */ -XEN_CPUFEATURE(XEN_IBRS_SET, (FSCAPINTS+0)*32+16) /* IBRSB && IRBS set in Xen */ -XEN_CPUFEATURE(XEN_IBRS_CLEAR, (FSCAPINTS+0)*32+17) /* IBRSB && IBRS clear in Xen */ +XEN_CPUFEATURE(SC_MSR, (FSCAPINTS+0)*32+16) /* MSR_SPEC_CTRL used by Xen */ XEN_CPUFEATURE(RSB_NATIVE, (FSCAPINTS+0)*32+18) /* RSB overwrite needed for native */ XEN_CPUFEATURE(RSB_VMEXIT, (FSCAPINTS+0)*32+19) /* RSB overwrite needed for vmexit */XEN_CPUFEATURE (NO_XPTI , (FSCAPINTS +0 )*32 +20 )/* XPTI mitigation not in use */
xen/include/asm-x86/spec_ctrl.h +3 -3
@@ -56,14 +56,14 @@ static always_inline void spec_ctrl_enter_idle(struct cpu_info *info)barrier (); info->spec_ctrl_flags |= SCF_use_shadow;barrier (); - asm volatile ( ALTERNATIVE(ASM_NOP3, "wrmsr", X86_FEATURE_XEN_IBRS_SET) + asm volatile ( ALTERNATIVE(ASM_NOP3, "wrmsr", X86_FEATURE_SC_MSR) :: "a" (val), "c" (MSR_SPEC_CTRL), "d" (0) : "memory" ); }/* WARNING! `ret`, `call *`, `jmp *` not safe before this call. */ static always_inline void spec_ctrl_exit_idle(struct cpu_info *info) { -uint32_t val =SPEC_CTRL_IBRS ; +uint32_t val = info->xen_spec_ctrl;/* * Disable shadowing before updating the MSR. There are no SMP issues
@@ -71,7 +71,7 @@ static always_inline void spec_ctrl_exit_idle(struct cpu_info *info)*/ info->spec_ctrl_flags &= ~SCF_use_shadow;barrier (); - asm volatile ( ALTERNATIVE(ASM_NOP3, "wrmsr", X86_FEATURE_XEN_IBRS_SET) + asm volatile ( ALTERNATIVE(ASM_NOP3, "wrmsr", X86_FEATURE_SC_MSR) :: "a" (val), "c" (MSR_SPEC_CTRL), "d" (0) : "memory" ); }
xen/include/asm-x86/spec_ctrl_asm.h +15 -30
90 lines not on this page · raw message
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 04/10] x86/spec_ctrl: Fold the XEN_IBRS_{SET, CLEAR} ALTERNATIVES together
Quoted 8 lines · Andrew Cooper
Currently, the SPEC_CTRL_{ENTRY,EXIT}_* macros encode Xen's choice of
MSR_SPEC_CTRLas an immediate constant, and chooses between IBRS or not by doubling up the entire alternative block.There is now a variable holding Xen's choice of value, so use that and simplify the alternatives.
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 5/10 x86/spec_ctrl: Rename bits of infrastructure to avoid NATIVE and VMEXIT
In reply to Andrew CooperIn hindsight, using NATIVE and VMEXIT as naming terminology was not clever. A future change wants to split SPEC_CTRL_EXIT_TO_GUEST into PV and HVM specific implementations, and using VMEXIT as a term is completely wrong.
Take the opportunity to fix some stale documentation in spec_ctrl_asm.h. The IST helpers were missing from the large comment block, and since SPEC_CTRL_ENTRY_FROM_INTR_IST was introduced, we've gained a new piece of functionality which currently depends on the fine grain control, which exists in lieu of livepatching. Note this in the comment.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Juergen Gross <[email protected]>
--- xen/arch/x86/hvm/svm/entry.S | 4 ++-- xen/arch/x86/hvm/vmx/entry.S | 4 ++-- xen/arch/x86/spec_ctrl.c | 28 ++++++++++++++-------------- xen/arch/x86/x86_64/compat/entry.S | 2 +- xen/arch/x86/x86_64/entry.S | 2 +- xen/include/asm-x86/cpufeatures.h | 4 ++-- xen/include/asm-x86/spec_ctrl_asm.h | 36 +++++++++++++++++++++++++----------- 7 files changed, 47 insertions(+), 33 deletions(-)
xen/arch/x86/hvm/svm/entry.S +2 -2
@@ -68,7 +68,7 @@ __UNLIKELY_END(nsvm_hap) mov VCPUMSR_spec_ctrl_raw(%rax), %eax /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ - SPEC_CTRL_EXIT_TO_GUEST /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */ + SPEC_CTRL_EXIT_TO_HVM /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */ pop %r15 pop %r14
@@ -93,7 +93,7 @@ __UNLIKELY_END(nsvm_hap) GET_CURRENT(bx) - SPEC_CTRL_ENTRY_FROM_VMEXIT /* Req: b=curr %rsp=regs/cpuinfo, Clob: acd */ + SPEC_CTRL_ENTRY_FROM_HVM /* Req: b=curr %rsp=regs/cpuinfo, Clob: acd */ /* WARNING! `ret`, `call *`, `jmp *` not safe before this point. */ STGI
xen/arch/x86/hvm/vmx/entry.S +2 -2
@@ -38,7 +38,7 @@ ENTRY(vmx_asm_vmexit_handler) movb $1,VCPU_vmx_launched(%rbx) mov %rax,VCPU_hvm_guest_cr2(%rbx) - SPEC_CTRL_ENTRY_FROM_VMEXIT /* Req: b=curr %rsp=regs/cpuinfo, Clob: acd */ + SPEC_CTRL_ENTRY_FROM_HVM /* Req: b=curr %rsp=regs/cpuinfo, Clob: acd */ /* WARNING! `ret`, `call *`, `jmp *` not safe before this point. */ mov %rsp,%rdi
@@ -76,7 +76,7 @@ UNLIKELY_END(realmode) mov VCPUMSR_spec_ctrl_raw(%rax), %eax /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ - SPEC_CTRL_EXIT_TO_GUEST /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */ + SPEC_CTRL_EXIT_TO_HVM /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */ mov VCPU_hvm_guest_cr2(%rbx),%rax
xen/arch/x86/spec_ctrl.c +14 -14
@@ -35,8 +35,8 @@ static enum ind_thunk {THUNK_JMP , } opt_thunk __initdata = THUNK_DEFAULT;static int8_t __initdata opt_ibrs =-1 ; -static bool __initdata opt_rsb_native = true; -static bool __initdata opt_rsb_vmexit = true; +static bool __initdata opt_rsb_pv = true; +static bool __initdata opt_rsb_hvm = true;bool __read_mostly opt_ibpb = true;uint8_t __read_mostly default_xen_spec_ctrl;uint8_t __read_mostly default_spec_ctrl_flags;
@@ -57,8 +57,8 @@ static int __init parse_bti(const char *s) opt_thunk =THUNK_JMP ; opt_ibrs =0 ; opt_ibpb = false; - opt_rsb_native = false; - opt_rsb_vmexit = false; + opt_rsb_pv = false; + opt_rsb_hvm = false; }else if ( val >0 ) rc = -EINVAL ;
@@ -80,13 +80,13 @@ static int __init parse_bti(const char *s)else if ( (val =parse_boolean ("ibpb" , s, ss)) >=0 ) opt_ibpb = val;else if ( (val =parse_boolean ("rsb_native" , s, ss)) >=0 ) - opt_rsb_native = val; + opt_rsb_pv = val;else if ( (val =parse_boolean ("rsb_vmexit" , s, ss)) >=0 ) - opt_rsb_vmexit = val; + opt_rsb_hvm = val;else if ( (val =parse_boolean ("rsb" , s, ss)) >=0 ) { - opt_rsb_native = val; - opt_rsb_vmexit = val; + opt_rsb_pv = val; + opt_rsb_hvm = val; }else rc = -EINVAL ;
@@ -132,8 +132,8 @@ static void __init print_details(enum ind_thunk thunk, uint64_t caps) default_xen_spec_ctrl &SPEC_CTRL_IBRS ?" IBRS+" : " IBRS-" : "", opt_ibpb ?" IBPB" :"" , -boot_cpu_has (X86_FEATURE_RSB_NATIVE ) ?" RSB_NATIVE" :"" , - boot_cpu_has(X86_FEATURE_RSB_VMEXIT) ? " RSB_VMEXIT" : ""); +boot_cpu_has (X86_FEATURE_SC_RSB_PV ) ?" RSB_NATIVE" :"" , + boot_cpu_has(X86_FEATURE_SC_RSB_HVM) ? " RSB_VMEXIT" : ""); printk("XPTI (64-bit PV only): Dom0 %s, DomU %s\n", opt_xpti & OPT_XPTI_DOM0 ? "enabled" : "disabled",
@@ -388,9 +388,9 @@ void __init init_speculation_mitigations(void)* If a processors speculates to 32bit PV guest kernel mappings, it is * speculating in 64bit supervisor mode, and can leak data. */ -if ( opt_rsb_native ) +if ( opt_rsb_pv ) { -setup_force_cpu_cap (X86_FEATURE_RSB_NATIVE ); +setup_force_cpu_cap (X86_FEATURE_SC_RSB_PV ); default_spec_ctrl_flags |= SCF_ist_rsb; }
@@ -398,8 +398,8 @@ void __init init_speculation_mitigations(void)* HVM guests can always poison the RSB to point at Xen supervisor * mappings. */ -if ( opt_rsb_vmexit ) -setup_force_cpu_cap (X86_FEATURE_RSB_VMEXIT ); +if ( opt_rsb_hvm ) +setup_force_cpu_cap (X86_FEATURE_SC_RSB_HVM );/* Check we have hardware IBPB support before using it... */ if ( !boot_cpu_has (X86_FEATURE_IBRSB ) && !boot_cpu_has (X86_FEATURE_IBPB ) )
xen/arch/x86/x86_64/compat/entry.S +1 -1
@@ -158,7 +158,7 @@ ENTRY(compat_restore_all_guest) mov VCPUMSR_spec_ctrl_raw(%rax), %eax /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ - SPEC_CTRL_EXIT_TO_GUEST /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */ + SPEC_CTRL_EXIT_TO_PV /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */ RESTORE_ALL adj=8 compat=1 .Lft0: iretq
xen/arch/x86/x86_64/entry.S +1 -1
@@ -177,7 +177,7 @@ restore_all_guest: mov %r15d, %eax /* WARNING! `ret`, `call *`, `jmp *` not safe beyond this point. */ - SPEC_CTRL_EXIT_TO_GUEST /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */ + SPEC_CTRL_EXIT_TO_PV /* Req: a=spec_ctrl %rsp=regs/cpuinfo, Clob: cd */ RESTORE_ALL testw $TRAP_syscall,4(%rsp)
xen/include/asm-x86/cpufeatures.h +2 -2
@@ -27,6 +27,6 @@ XEN_CPUFEATURE(IND_THUNK_LFENCE,(FSCAPINTS+0)*32+13) /* Use IND_THUNK_LFENCE */ XEN_CPUFEATURE(IND_THUNK_JMP, (FSCAPINTS+0)*32+14) /* Use IND_THUNK_JMP */ XEN_CPUFEATURE(XEN_IBPB, (FSCAPINTS+0)*32+15) /* IBRSB || IBPB */ XEN_CPUFEATURE(SC_MSR, (FSCAPINTS+0)*32+16) /* MSR_SPEC_CTRL used by Xen */ -XEN_CPUFEATURE(RSB_NATIVE, (FSCAPINTS+0)*32+18) /* RSB overwrite needed for native */ -XEN_CPUFEATURE(RSB_VMEXIT, (FSCAPINTS+0)*32+19) /* RSB overwrite needed for vmexit */ +XEN_CPUFEATURE(SC_RSB_PV, (FSCAPINTS+0)*32+18) /* RSB overwrite needed for PV */ +XEN_CPUFEATURE(SC_RSB_HVM, (FSCAPINTS+0)*32+19) /* RSB overwrite needed for HVM */XEN_CPUFEATURE (NO_XPTI , (FSCAPINTS +0 )*32 +20 )/* XPTI mitigation not in use */
xen/include/asm-x86/spec_ctrl_asm.h +25 -11
@@ -72,11 +72,14 @@* * The following ASM fragments implement this algorithm. See their local * comments for further details. -* - SPEC_CTRL_ENTRY_FROM_VMEXIT +* - SPEC_CTRL_ENTRY_FROM_HVM * - SPEC_CTRL_ENTRY_FROM_PV * - SPEC_CTRL_ENTRY_FROM_INTR +* - SPEC_CTRL_ENTRY_FROM_INTR_IST +* - SPEC_CTRL_EXIT_TO_XEN_IST * - SPEC_CTRL_EXIT_TO_XEN -* - SPEC_CTRL_EXIT_TO_GUEST +* - SPEC_CTRL_EXIT_TO_PV +* - SPEC_CTRL_EXIT_TO_HVM */ .macro DO_OVERWRITE_RSB tmp=rax
@@ -117,7 +120,7 @@ mov %\tmp, %rsp /* Restore old %rsp */ .endm -.macro DO_SPEC_CTRL_ENTRY_FROM_VMEXIT +.macro DO_SPEC_CTRL_ENTRY_FROM_HVM/* * Requires %rbx=current, %rsp=regs/cpuinfo * Clobbers %rax, %rcx, %rdx
@@ -217,20 +220,20 @@ .endm/* Use after a VMEXIT from an HVM guest. */ -#define SPEC_CTRL_ENTRY_FROM_VMEXIT \ - ALTERNATIVE "", DO_OVERWRITE_RSB, X86_FEATURE_RSB_VMEXIT; \ - ALTERNATIVE "", DO_SPEC_CTRL_ENTRY_FROM_VMEXIT, \ +#define SPEC_CTRL_ENTRY_FROM_HVM \ + ALTERNATIVE "", DO_OVERWRITE_RSB, X86_FEATURE_SC_RSB_HVM; \ + ALTERNATIVE "", DO_SPEC_CTRL_ENTRY_FROM_HVM, \ X86_FEATURE_SC_MSR/* Use after an entry from PV context (syscall/sysenter/int80/int82/etc). */ #define SPEC_CTRL_ENTRY_FROM_PV \ - ALTERNATIVE "", DO_OVERWRITE_RSB, X86_FEATURE_RSB_NATIVE; \ + ALTERNATIVE "", DO_OVERWRITE_RSB, X86_FEATURE_SC_RSB_PV; \ ALTERNATIVE "", __stringify(DO_SPEC_CTRL_ENTRY maybexen=0), \ X86_FEATURE_SC_MSR/* Use in interrupt/exception context. May interrupt Xen or PV context. */ #define SPEC_CTRL_ENTRY_FROM_INTR \ - ALTERNATIVE "", DO_OVERWRITE_RSB, X86_FEATURE_RSB_NATIVE; \ + ALTERNATIVE "", DO_OVERWRITE_RSB, X86_FEATURE_SC_RSB_PV; \ ALTERNATIVE "", __stringify(DO_SPEC_CTRL_ENTRY maybexen=1), \ X86_FEATURE_SC_MSR
@@ -239,12 +242,22 @@ALTERNATIVE "" , \DO_SPEC_CTRL_EXIT_TO_XEN ,X86_FEATURE_SC_MSR -/* Use when exiting to guest context. */ -#define SPEC_CTRL_EXIT_TO_GUEST \ +/* Use when exiting to PV guest context. */ +#define SPEC_CTRL_EXIT_TO_PV \ ALTERNATIVE "", \ DO_SPEC_CTRL_EXIT_TO_GUEST, X86_FEATURE_SC_MSR -/* TODO: Drop these when the alternatives infrastructure is NMI/#MC safe. */ +/* Use when exiting to HVM guest context. */ +#define SPEC_CTRL_EXIT_TO_HVM \ + ALTERNATIVE "", \ + DO_SPEC_CTRL_EXIT_TO_GUEST, X86_FEATURE_SC_MSR + +/* +* Use in IST interrupt/exception context. May interrupt Xen or PV context. +* Fine grain control of SCF_ist_wrmsr is needed for safety in the S3 resume +* path to avoid using MSR_SPEC_CTRL before the microcode introducing it has +* been reloaded. +*/ .macro SPEC_CTRL_ENTRY_FROM_INTR_IST/* * Requires %rsp=regs, %r14=stack_end
@@ -291,6 +304,7 @@ UNLIKELY_DISPATCH_LABEL(\@_serialise): UNLIKELY_END(\@_serialise) .endm +/* Use when exiting to Xen in IST context. */ .macro SPEC_CTRL_EXIT_TO_XEN_IST/* * Requires %rbx=stack_end
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 05/10] x86/spec_ctrl: Rename bits of infrastructure to avoid NATIVE and VMEXIT
Quoted 10 lines · Andrew Cooper
In hindsight, using NATIVE and VMEXIT as naming terminology was not clever. A future change wants to split
SPEC_CTRL_EXIT_TO_GUESTinto PV and HVM specific implementations, and using VMEXIT as a term is completely wrong.Take the opportunity to fix some stale documentation in
spec_ctrl_asm.h. The IST helpers were missing from the large comment block, and sinceSPEC_CTRL_ENTRY_FROM_INTR_ISTwas introduced, we've gained a new piece of functionality which currently depends on the fine grain control, which exists in lieu of livepatching. Note this in the comment.
Quoted 3 lines
No functional change.
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 6/10 x86/spec_ctrl: Split X86_FEATURE_SC_MSR into PV and HVM variants
In reply to Andrew CooperIn order to separately control whether MSR_SPEC_CTRL is virtualised for PV and HVM guests, split the feature used to control runtime alternatives into two. Xen will use MSR_SPEC_CTRL itself if either of these features are active.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Juergen Gross <[email protected]>
--- xen/arch/x86/spec_ctrl.c | 6 ++++-- xen/include/asm-x86/cpufeatures.h | 3 ++- xen/include/asm-x86/spec_ctrl.h | 8 ++++++-- xen/include/asm-x86/spec_ctrl_asm.h | 12 ++++++------ 4 files changed, 18 insertions(+), 11 deletions(-)
xen/arch/x86/spec_ctrl.c +4 -2
@@ -128,7 +128,8 @@ static void __init print_details(enum ind_thunk thunk, uint64_t caps) thunk ==THUNK_RETPOLINE ?"RETPOLINE" : thunk ==THUNK_LFENCE ?"LFENCE" : thunk ==THUNK_JMP ?"JMP" :"?" , -boot_cpu_has (X86_FEATURE_SC_MSR ) ? + (boot_cpu_has (X86_FEATURE_SC_MSR_PV ) || +boot_cpu_has (X86_FEATURE_SC_MSR_HVM )) ? default_xen_spec_ctrl &SPEC_CTRL_IBRS ?" IBRS+" :" IBRS-" :"" , opt_ibpb ? " IBPB" : "",
@@ -367,7 +368,8 @@ void __init init_speculation_mitigations(void)* need the IBRS entry/exit logic to virtualise IBRS support for * guests. */ -setup_force_cpu_cap (X86_FEATURE_SC_MSR ); +setup_force_cpu_cap (X86_FEATURE_SC_MSR_PV ); +setup_force_cpu_cap (X86_FEATURE_SC_MSR_HVM );if ( ibrs ) default_xen_spec_ctrl |=SPEC_CTRL_IBRS ;
xen/include/asm-x86/cpufeatures.h +2 -1
@@ -26,7 +26,8 @@ XEN_CPUFEATURE(LFENCE_DISPATCH, (FSCAPINTS+0)*32+12) /* lfence set as Dispatch S XEN_CPUFEATURE(IND_THUNK_LFENCE,(FSCAPINTS+0)*32+13) /* Use IND_THUNK_LFENCE */ XEN_CPUFEATURE(IND_THUNK_JMP, (FSCAPINTS+0)*32+14) /* Use IND_THUNK_JMP */ XEN_CPUFEATURE(XEN_IBPB, (FSCAPINTS+0)*32+15) /* IBRSB || IBPB */ -XEN_CPUFEATURE(SC_MSR, (FSCAPINTS+0)*32+16) /* MSR_SPEC_CTRL used by Xen */ +XEN_CPUFEATURE(SC_MSR_PV, (FSCAPINTS+0)*32+16) /* MSR_SPEC_CTRL used by Xen for PV */ +XEN_CPUFEATURE(SC_MSR_HVM, (FSCAPINTS+0)*32+17) /* MSR_SPEC_CTRL used by Xen for HVM */ XEN_CPUFEATURE(SC_RSB_PV, (FSCAPINTS+0)*32+18) /* RSB overwrite needed for PV */ XEN_CPUFEATURE(SC_RSB_HVM, (FSCAPINTS+0)*32+19) /* RSB overwrite needed for HVM */XEN_CPUFEATURE (NO_XPTI , (FSCAPINTS +0 )*32 +20 )/* XPTI mitigation not in use */
xen/include/asm-x86/spec_ctrl.h +6 -2
@@ -56,7 +56,9 @@ static always_inline void spec_ctrl_enter_idle(struct cpu_info *info)barrier (); info->spec_ctrl_flags |= SCF_use_shadow;barrier (); - asm volatile ( ALTERNATIVE(ASM_NOP3, "wrmsr", X86_FEATURE_SC_MSR) + asm volatile ( ALTERNATIVE_2(ASM_NOP3, + "wrmsr", X86_FEATURE_SC_MSR_PV, + "wrmsr", X86_FEATURE_SC_MSR_HVM) :: "a" (val), "c" (MSR_SPEC_CTRL), "d" (0) : "memory" ); }
@@ -71,7 +73,9 @@ static always_inline void spec_ctrl_exit_idle(struct cpu_info *info)*/ info->spec_ctrl_flags &= ~SCF_use_shadow;barrier (); - asm volatile ( ALTERNATIVE(ASM_NOP3, "wrmsr", X86_FEATURE_SC_MSR) + asm volatile ( ALTERNATIVE_2(ASM_NOP3, + "wrmsr", X86_FEATURE_SC_MSR_PV, + "wrmsr", X86_FEATURE_SC_MSR_HVM) :: "a" (val), "c" (MSR_SPEC_CTRL), "d" (0) : "memory" ); }
xen/include/asm-x86/spec_ctrl_asm.h +6 -6
@@ -223,34 +223,34 @@#define SPEC_CTRL_ENTRY_FROM_HVM \ ALTERNATIVE "", DO_OVERWRITE_RSB, X86_FEATURE_SC_RSB_HVM; \ ALTERNATIVE "", DO_SPEC_CTRL_ENTRY_FROM_HVM, \ - X86_FEATURE_SC_MSR + X86_FEATURE_SC_MSR_HVM/* Use after an entry from PV context (syscall/sysenter/int80/int82/etc). */ #define SPEC_CTRL_ENTRY_FROM_PV \ ALTERNATIVE "", DO_OVERWRITE_RSB, X86_FEATURE_SC_RSB_PV; \ ALTERNATIVE "", __stringify(DO_SPEC_CTRL_ENTRY maybexen=0), \ - X86_FEATURE_SC_MSR + X86_FEATURE_SC_MSR_PV/* Use in interrupt/exception context. May interrupt Xen or PV context. */ #define SPEC_CTRL_ENTRY_FROM_INTR \ ALTERNATIVE "", DO_OVERWRITE_RSB, X86_FEATURE_SC_RSB_PV; \ ALTERNATIVE "", __stringify(DO_SPEC_CTRL_ENTRY maybexen=1), \ - X86_FEATURE_SC_MSR + X86_FEATURE_SC_MSR_PV/* Use when exiting to Xen context. */ #define SPEC_CTRL_EXIT_TO_XEN \ ALTERNATIVE "", \ - DO_SPEC_CTRL_EXIT_TO_XEN, X86_FEATURE_SC_MSR + DO_SPEC_CTRL_EXIT_TO_XEN, X86_FEATURE_SC_MSR_PV/* Use when exiting to PV guest context. */ #define SPEC_CTRL_EXIT_TO_PV \ ALTERNATIVE "", \ - DO_SPEC_CTRL_EXIT_TO_GUEST, X86_FEATURE_SC_MSR + DO_SPEC_CTRL_EXIT_TO_GUEST, X86_FEATURE_SC_MSR_PV/* Use when exiting to HVM guest context. */ #define SPEC_CTRL_EXIT_TO_HVM \ ALTERNATIVE "", \ - DO_SPEC_CTRL_EXIT_TO_GUEST, X86_FEATURE_SC_MSR + DO_SPEC_CTRL_EXIT_TO_GUEST, X86_FEATURE_SC_MSR_HVM/* * Use in IST interrupt/exception context. May interrupt Xen or PV context.
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 06/10] x86/spec_ctrl: Split X86_FEATURE_SC_MSR into PV and HVM variants
Quoted 5 lines · Andrew Cooper
In order to separately control whether
MSR_SPEC_CTRLis virtualised for PV and HVM guests, split the feature used to control runtime alternatives into two. Xen will useMSR_SPEC_CTRLitself if either of these features are active.Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 06/10] x86/spec_ctrl: Split X86_FEATURE_SC_MSR into PV and HVM variants
In reply to Andrew CooperQuoted 14 lines
Quoted 1 line
Quoted 1 line · On 11.05.18 at 12:38, <[email protected]> wrote:
xen/arch/x86/spec_ctrl.c +2
-1@@ -128,7 +128,8 @@ static void __init print_details(enum ind_thunk thunk, uint64_t caps) thunk ==THUNK_RETPOLINE ?"RETPOLINE" : thunk ==THUNK_LFENCE ?"LFENCE" : thunk ==THUNK_JMP ?"JMP" :"?" , -boot_cpu_has (X86_FEATURE_SC_MSR ) ? + (boot_cpu_has (X86_FEATURE_SC_MSR_PV ) || +boot_cpu_has (X86_FEATURE_SC_MSR_HVM )) ? default_xen_spec_ctrl &SPEC_CTRL_IBRS ?" IBRS+" :" IBRS-" :"" , opt_ibpb ? " IBPB" : "",
xen/arch/x86/spec_ctrl.c void __init init_speculation_mitigations(void) · line 372
Quoted 6 lines
xen/arch/x86/spec_ctrl.c +2
-1@@ -367,7 +368,8 @@ void __init init_speculation_mitigations(void)* need the IBRS entry/exit logic to virtualise IBRS support for * guests. */ -setup_force_cpu_cap (X86_FEATURE_SC_MSR ); +setup_force_cpu_cap (X86_FEATURE_SC_MSR_PV ); +setup_force_cpu_cap (X86_FEATURE_SC_MSR_HVM );
Besides these sort of open coding alternative_io_2() (you'd really want an output-less variant here, I agree) these are slightly bending the rules of when/how to use multiple alternatives: The above ends up correct only because of both replacements being identical.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 06/10] x86/spec_ctrl: Split X86_FEATURE_SC_MSR into PV and HVM variants
Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 11.05.18 at 12:38, <[email protected]> wrote:
xen/arch/x86/spec_ctrl.c +2
-1@@ -128,7 +128,8 @@ static void __init print_details(enum ind_thunk thunk, uint64_t caps) thunk ==THUNK_RETPOLINE ?"RETPOLINE" : thunk ==THUNK_LFENCE ?"LFENCE" : thunk ==THUNK_JMP ?"JMP" :"?" , -boot_cpu_has (X86_FEATURE_SC_MSR ) ? + (boot_cpu_has (X86_FEATURE_SC_MSR_PV ) || +boot_cpu_has (X86_FEATURE_SC_MSR_HVM )) ? default_xen_spec_ctrl &SPEC_CTRL_IBRS ?" IBRS+" :" IBRS-" :"" , opt_ibpb ? " IBPB" : "",@@ -367,7 +368,8 @@ void __init init_speculation_mitigations(void)* need the IBRS entry/exit logic to virtualise IBRS support for * guests.
Quoted 8 lines
xen/arch/x86/spec_ctrl.c void __init init_speculation_mitigations(void) · line 372
Quoted 4 lines
xen/arch/x86/spec_ctrl.c +2
-1*/ -setup_force_cpu_cap (X86_FEATURE_SC_MSR ); +setup_force_cpu_cap (X86_FEATURE_SC_MSR_PV ); +setup_force_cpu_cap (X86_FEATURE_SC_MSR_HVM );Besides these sort of open coding
alternative_io_2()(you'd really want an output-less variant here, I agree) these are slightly bending the rules of when/how to use multiple alternatives: The above ends up correct only because of both replacements being identical.
Actually, by reordering patch 10 ahead of this patch, we never get to needing the ALTERNATIVE_2()'s in the first place, and lose any concerns with bending the rules along the series.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 06/10] x86/spec_ctrl: Split X86_FEATURE_SC_MSR into PV and HVM variants
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 15.05.18 at 21:52, <[email protected]> wrote:
Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 11.05.18 at 12:38, <[email protected]> wrote:
xen/arch/x86/spec_ctrl.c +2
-1@@ -128,7 +128,8 @@ static void __init print_details(enum ind_thunk thunk, uint64_t caps) thunk ==THUNK_RETPOLINE ?"RETPOLINE" : thunk ==THUNK_LFENCE ?"LFENCE" : thunk ==THUNK_JMP ?"JMP" :"?" , -boot_cpu_has (X86_FEATURE_SC_MSR ) ? + (boot_cpu_has (X86_FEATURE_SC_MSR_PV ) || +boot_cpu_has (X86_FEATURE_SC_MSR_HVM )) ? default_xen_spec_ctrl &SPEC_CTRL_IBRS ?" IBRS+" :" IBRS-" :"" , opt_ibpb ? " IBPB" : "",@@ -367,7 +368,8 @@ void __init init_speculation_mitigations(void)* need the IBRS entry/exit logic to virtualise IBRS support for * guests. Quoted 8 lines
xen/arch/x86/spec_ctrl.c void __init init_speculation_mitigations(void) · line 372
Quoted 4 lines
xen/arch/x86/spec_ctrl.c +2
-1*/ -setup_force_cpu_cap (X86_FEATURE_SC_MSR ); +setup_force_cpu_cap (X86_FEATURE_SC_MSR_PV ); +setup_force_cpu_cap (X86_FEATURE_SC_MSR_HVM );Besides these sort of open coding
alternative_io_2()(you'd really want an output-less variant here, I agree) these are slightly bending the rules of when/how to use multiple alternatives: The above ends up correct only because of both replacements being identical.
Quoted 3 lines
Actually, by reordering patch 10 ahead of this patch, we never get to needing the ALTERNATIVE_2()'s in the first place, and lose any concerns with bending the rules along the series.
Ah yes, indeed. And you would better use alternative_input() there then, instead of open coding it.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 06/10] x86/spec_ctrl: Split X86_FEATURE_SC_MSR into PV and HVM variants
Quoted 26 lines · Jan Beulich
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 15.05.18 at 21:52, <[email protected]> wrote:
Quoted 24 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 11.05.18 at 12:38, <[email protected]> wrote:
xen/arch/x86/spec_ctrl.c +2
-1@@ -128,7 +128,8 @@ static void __init print_details(enum ind_thunk thunk, uint64_t caps) thunk ==THUNK_RETPOLINE ?"RETPOLINE" : thunk ==THUNK_LFENCE ?"LFENCE" : thunk ==THUNK_JMP ?"JMP" :"?" , -boot_cpu_has (X86_FEATURE_SC_MSR ) ? + (boot_cpu_has (X86_FEATURE_SC_MSR_PV ) || +boot_cpu_has (X86_FEATURE_SC_MSR_HVM )) ? default_xen_spec_ctrl &SPEC_CTRL_IBRS ?" IBRS+" :" IBRS-" :"" , opt_ibpb ? " IBPB" : "",xen/arch/x86/spec_ctrl.c void __init init_speculation_mitigations(void) · line 372
Quoted 6 lines
xen/arch/x86/spec_ctrl.c +2
-1@@ -367,7 +368,8 @@ void __init init_speculation_mitigations(void)* need the IBRS entry/exit logic to virtualise IBRS support for * guests. */ -setup_force_cpu_cap (X86_FEATURE_SC_MSR ); +setup_force_cpu_cap (X86_FEATURE_SC_MSR_PV ); +setup_force_cpu_cap (X86_FEATURE_SC_MSR_HVM );Besides these sort of open coding
alternative_io_2()(you'd really want an output-less variant here, I agree) these are slightly bending the rules of when/how to use multiple alternatives: The above ends up correct only because of both replacements being identical.
Quoted 5 lines
Quoted 3 lines
Actually, by reordering patch 10 ahead of this patch, we never get to needing the ALTERNATIVE_2()'s in the first place, and lose any concerns with bending the rules along the series.
Ah yes, indeed. And you would better use
alternative_input()there then, instead of open coding it.
The reason this doesn't use alternative_input() at the moment is because of the memory clobber. (And the lack of a memory clobber is called out as a peculiarity in comment). The current code looks dangerously inconsistent WRT barriers.
As for bending the rules, I now disagree with your assessment. The alternative_*() wrappers do nothing but make it harder to express the parameters, as perfectly demonstrated by the ASM_OUTPUT2() bodge.
I don't see their value, and they have a cost of making an asm volatile statement not look and work quite as an asm volatile statement does in all other callsites.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 06/10] x86/spec_ctrl: Split X86_FEATURE_SC_MSR into PV and HVM variants
Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 16.05.18 at 12:28, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 15.05.18 at 21:52, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
xen/arch/x86/spec_ctrl.c static void __init print_details(enum ind_thunk thunk,
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 11.05.18 at 12:38, <[email protected]> wrote:
xen/arch/x86/spec_ctrl.c +0
-0@@ -128,7 +128,8 @@ static void __init print_details(enum ind_thunk thunk,
uint64_tcaps)Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 10 lines
xen/arch/x86/spec_ctrl.c +2
-1thunk ==THUNK_RETPOLINE ?"RETPOLINE" : thunk ==THUNK_LFENCE ?"LFENCE" : thunk ==THUNK_JMP ?"JMP" :"?" , -boot_cpu_has (X86_FEATURE_SC_MSR ) ? + (boot_cpu_has (X86_FEATURE_SC_MSR_PV ) || +boot_cpu_has (X86_FEATURE_SC_MSR_HVM )) ? default_xen_spec_ctrl &SPEC_CTRL_IBRS ?" IBRS+" :" IBRS-" :"" , opt_ibpb ? " IBPB" : "",xen/arch/x86/spec_ctrl.c void __init init_speculation_mitigations(void) · line 372
Quoted 6 lines
xen/arch/x86/spec_ctrl.c +2
-1@@ -367,7 +368,8 @@ void __init init_speculation_mitigations(void)* need the IBRS entry/exit logic to virtualise IBRS support for * guests. */ -setup_force_cpu_cap (X86_FEATURE_SC_MSR ); +setup_force_cpu_cap (X86_FEATURE_SC_MSR_PV ); +setup_force_cpu_cap (X86_FEATURE_SC_MSR_HVM );Besides these sort of open coding
alternative_io_2()(you'd really want an output-less variant here, I agree) these are slightly bending the rules of when/how to use multiple alternatives: The above ends up correct only because of both replacements being identical.Quoted 5 lines
Quoted 3 lines
Actually, by reordering patch 10 ahead of this patch, we never get to needing the ALTERNATIVE_2()'s in the first place, and lose any concerns with bending the rules along the series.
Ah yes, indeed. And you would better use
alternative_input()there then, instead of open coding it.
Quoted 8 lines
The reason this doesn't use
alternative_input()at the moment is because of the memory clobber. (And the lack of a memory clobber is called out as a peculiarity in comment). The current code looks dangerously inconsistent WRT barriers.As for bending the rules, I now disagree with your assessment. The alternative_*() wrappers do nothing but make it harder to express the parameters, as perfectly demonstrated by the
ASM_OUTPUT2()bodge.
The "bending the rules" comment was unrelated to alternative_*() vs ALTERNATIVE*() use, and instead was solely related to there being a dependency here on both pieces of replacement code being identical.
Quoted 3 lines
I don't see their value, and they have a cost of making an asm volatile statement not look and work quite as an asm volatile statement does in all other callsites.
I don't mind consistency being achieved to other way around (i.e. by dropping those wrappers). But I'd prefer if we didn't mix things unless there's a compelling reason to do so.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 06/10] x86/spec_ctrl: Split X86_FEATURE_SC_MSR into PV and HVM variants
Quoted 46 lines · Jan Beulich
Quoted 34 lines
Quoted 1 line
Quoted 1 line · On 16.05.18 at 12:28, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 15.05.18 at 21:52, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
xen/arch/x86/spec_ctrl.c static void __init print_details(enum ind_thunk thunk,
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 11.05.18 at 12:38, <[email protected]> wrote:
xen/arch/x86/spec_ctrl.c +0
-0@@ -128,7 +128,8 @@ static void __init print_details(enum ind_thunk thunk,
uint64_tcaps)Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 10 lines
xen/arch/x86/spec_ctrl.c +2
-1thunk ==THUNK_RETPOLINE ?"RETPOLINE" : thunk ==THUNK_LFENCE ?"LFENCE" : thunk ==THUNK_JMP ?"JMP" :"?" , -boot_cpu_has (X86_FEATURE_SC_MSR ) ? + (boot_cpu_has (X86_FEATURE_SC_MSR_PV ) || +boot_cpu_has (X86_FEATURE_SC_MSR_HVM )) ? default_xen_spec_ctrl &SPEC_CTRL_IBRS ?" IBRS+" :" IBRS-" :"" , opt_ibpb ? " IBPB" : "",xen/arch/x86/spec_ctrl.c void __init init_speculation_mitigations(void) · line 372
Quoted 6 lines
xen/arch/x86/spec_ctrl.c +2
-1@@ -367,7 +368,8 @@ void __init init_speculation_mitigations(void)* need the IBRS entry/exit logic to virtualise IBRS support for * guests. */ -setup_force_cpu_cap (X86_FEATURE_SC_MSR ); +setup_force_cpu_cap (X86_FEATURE_SC_MSR_PV ); +setup_force_cpu_cap (X86_FEATURE_SC_MSR_HVM );Besides these sort of open coding
alternative_io_2()(you'd really want an output-less variant here, I agree) these are slightly bending the rules of when/how to use multiple alternatives: The above ends up correct only because of both replacements being identical.Quoted 5 lines
Quoted 3 lines
Actually, by reordering patch 10 ahead of this patch, we never get to needing the ALTERNATIVE_2()'s in the first place, and lose any concerns with bending the rules along the series.
Ah yes, indeed. And you would better use
alternative_input()there then, instead of open coding it.Quoted 8 lines
The reason this doesn't use
alternative_input()at the moment is because of the memory clobber. (And the lack of a memory clobber is called out as a peculiarity in comment). The current code looks dangerously inconsistent WRT barriers.As for bending the rules, I now disagree with your assessment. The alternative_*() wrappers do nothing but make it harder to express the parameters, as perfectly demonstrated by the
ASM_OUTPUT2()bodge.The "bending the rules" comment was unrelated to alternative_*() vs ALTERNATIVE*() use, and instead was solely related to there being a dependency here on both pieces of replacement code being identical.
Quoted 6 lines
Quoted 3 lines
I don't see their value, and they have a cost of making an asm volatile statement not look and work quite as an asm volatile statement does in all other callsites.
I don't mind consistency being achieved to other way around (i.e. by dropping those wrappers). But I'd prefer if we didn't mix things unless there's a compelling reason to do so.
I'll see about doing some cleanup of the overall tree for 4.12. For now, its already mixed, and this doesn't make anything worse.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 7/10 x86/spec_ctrl: Explicitly set Xen's default MSR_SPEC_CTRL value
In reply to Andrew CooperWith the impending ability to disable MSR_SPEC_CTRL handling on a per-guest-type basis, the first exit-from-guest may not have the side effect of loading Xen's choice of value. Explicitly set Xen's default during the BSP and AP boot paths.
For the BSP however, delay setting a non-zero MSR_SPEC_CTRL default until after dom0 has been constructed when safe to do so. Oracle report that this speeds up boots of some hardware by 50s.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Zhenzhong Duan <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Boris Ostrovsky <[email protected]>
CC: Juergen Gross <[email protected]>
--- xen/arch/x86/setup.c | 7 +++++++ xen/arch/x86/smpboot.c | 8 ++++++++ xen/arch/x86/spec_ctrl.c | 28 ++++++++++++++++++++++++++++ xen/include/asm-x86/spec_ctrl.h | 2 ++ 4 files changed, 45 insertions(+)
xen/arch/x86/setup.c +7 -0
@@ -1743,6 +1743,13 @@ void __init noreturn __start_xen(unsigned long mbi_p)setup_io_bitmap (dom0); +if ( bsp_delay_spec_ctrl ) + { +get_cpu_info ()->spec_ctrl_flags &= ~SCF_use_shadow; +barrier (); +wrmsrl (MSR_SPEC_CTRL , default_xen_spec_ctrl); + } +/* Jump to the 1:1 virtual mappings of cpu0_stack. */ asm volatile ("mov %[stk], %%rsp; jmp %c[fn]" :: [stk] "g" (__va(__pa(get_stack_bottom()))),
xen/arch/x86/smpboot.c +8 -0
@@ -358,6 +358,14 @@ void start_secondary(void *unused)else microcode_resume_cpu (cpu); +/* +* If MSR_SPEC_CTRL is available, apply Xen's default setting and discard +* any firmware settings. Note: MSR_SPEC_CTRL may only become available +* after loading microcode. +*/ +if (boot_cpu_has (X86_FEATURE_IBRSB ) ) +wrmsrl (MSR_SPEC_CTRL , default_xen_spec_ctrl); +if ( xen_guest )hypervisor_ap_setup ();
xen/arch/x86/spec_ctrl.c +28 -0
@@ -38,6 +38,8 @@ static int8_t __initdata opt_ibrs = -1;static bool __initdata opt_rsb_pv = true;static bool __initdata opt_rsb_hvm = true;bool __read_mostly opt_ibpb = true; + +bool __initdata bsp_delay_spec_ctrl;uint8_t __read_mostly default_xen_spec_ctrl;uint8_t __read_mostly default_spec_ctrl_flags;
@@ -417,6 +419,32 @@ void __init init_speculation_mitigations(void)setup_clear_cpu_cap (X86_FEATURE_NO_XPTI );print_details (thunk, caps); + +/* +* If MSR_SPEC_CTRL is available, apply Xen's default setting and discard +* any firmware settings. For performance reasons on native hardware, we +* delay applying non-zero settings until after dom0 has been constructed. +*/ +if (boot_cpu_has (X86_FEATURE_IBRSB ) ) + { + bsp_delay_spec_ctrl = !cpu_has_hypervisor && default_xen_spec_ctrl; + +/* +* If delaying MSR_SPEC_CTRL setup, use the same mechanism as +* spec_ctrl_enter_idle(), by using a shadow value of zero. +*/ +if ( bsp_delay_spec_ctrl ) + { +struct cpu_info *info =get_cpu_info (); + + info->shadow_spec_ctrl =0 ; +barrier (); + info->spec_ctrl_flags |= SCF_use_shadow; +barrier (); + } + +wrmsrl (MSR_SPEC_CTRL , bsp_delay_spec_ctrl ?0 : default_xen_spec_ctrl); + } }static void __init __maybe_unused build_assertions (void )
xen/include/asm-x86/spec_ctrl.h +2 -0
@@ -27,6 +27,8 @@void init_speculation_mitigations (void );extern bool opt_ibpb; + +extern bool bsp_delay_spec_ctrl;extern uint8_t default_xen_spec_ctrl;extern uint8_t default_spec_ctrl_flags;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 07/10] x86/spec_ctrl: Explicitly set Xen's default MSR_SPEC_CTRL value
Quoted 4 lines · Andrew Cooper
xen/arch/x86/spec_ctrl.c +0
-0@@ -417,6 +419,32 @@ void __init init_speculation_mitigations(void)setup_clear_cpu_cap (X86_FEATURE_NO_XPTI );print_details (thunk, caps);
xen/arch/x86/spec_ctrl.c void __init init_speculation_mitigations(void) · line 431
Quoted 10 lines
xen/arch/x86/spec_ctrl.c +10
-0+ +/* +* If MSR_SPEC_CTRL is available, apply Xen's default setting and discard +* any firmware settings. For performance reasons on native hardware, we +* delay applying non-zero settings until after dom0 has been constructed. +*/ +if (boot_cpu_has (X86_FEATURE_IBRSB ) ) + { + bsp_delay_spec_ctrl = !cpu_has_hypervisor && default_xen_spec_ctrl; +
Why is cpu_has_hypervisor needed here? This should help nested case as well. And it wouldn't make the setup less secure, right?
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 07/10] x86/spec_ctrl: Explicitly set Xen's default MSR_SPEC_CTRL value
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 14.05.18 at 17:39, <[email protected]> wrote:
Quoted 3 lines · Andrew Cooper
xen/arch/x86/spec_ctrl.c +0
-0@@ -417,6 +419,32 @@ void __init init_speculation_mitigations(void)setup_clear_cpu_cap (X86_FEATURE_NO_XPTI );
Quoted 14 lines
xen/arch/x86/spec_ctrl.c void __init init_speculation_mitigations(void) · line 431
Quoted 11 lines
xen/arch/x86/spec_ctrl.c +10
-0print_details (thunk, caps); + +/* +* If MSR_SPEC_CTRL is available, apply Xen's default setting and discard +* any firmware settings. For performance reasons on native hardware, we +* delay applying non-zero settings until after dom0 has been constructed. +*/ +if (boot_cpu_has (X86_FEATURE_IBRSB ) ) + { + bsp_delay_spec_ctrl = !cpu_has_hypervisor && default_xen_spec_ctrl; +Why is
cpu_has_hypervisorneeded here? This should help nested case as well. And it wouldn't make the setup less secure, right?
Ah, yes, Andrew, this should indeed be explained in at least one of comment or commit message.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 07/10] x86/spec_ctrl: Explicitly set Xen's default MSR_SPEC_CTRL value
Quoted 18 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 14.05.18 at 17:39, <[email protected]> wrote:
Quoted 3 lines · Andrew Cooper
xen/arch/x86/spec_ctrl.c +0
-0@@ -417,6 +419,32 @@ void __init init_speculation_mitigations(void)setup_clear_cpu_cap (X86_FEATURE_NO_XPTI );Quoted 13 lines
xen/arch/x86/spec_ctrl.c void __init init_speculation_mitigations(void) · line 431
Quoted 11 lines
xen/arch/x86/spec_ctrl.c +10
-0print_details (thunk, caps); + +/* +* If MSR_SPEC_CTRL is available, apply Xen's default setting and discard +* any firmware settings. For performance reasons on native hardware, we +* delay applying non-zero settings until after dom0 has been constructed. +*/ +if (boot_cpu_has (X86_FEATURE_IBRSB ) ) + { + bsp_delay_spec_ctrl = !cpu_has_hypervisor && default_xen_spec_ctrl; +Why is
cpu_has_hypervisorneeded here? This should help nested case as well. And it wouldn't make the setup less secure, right?
Quoted 2 lines
Ah, yes, Andrew, this should indeed be explained in at least one of comment or commit message.
I've adjusted this comment to read:
/*
* If MSR_SPEC_CTRL is available, apply Xen's default setting and discard
* any firmware settings. For performance reasons, when safe to do so, we
* delay applying non-zero settings until after dom0 has been constructed.
*
* "when safe to do so" is based on whether we are virtualised. A native
* boot won't have any other code running in a position to mount an
* attack.
*/
and added the same second paragraph to the commit message.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 07/10] x86/spec_ctrl: Explicitly set Xen's default MSR_SPEC_CTRL value
Quoted 34 lines · Andrew Cooper
Quoted 18 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 14.05.18 at 17:39, <[email protected]> wrote:
Quoted 3 lines · Andrew Cooper
xen/arch/x86/spec_ctrl.c +0
-0@@ -417,6 +419,32 @@ void __init init_speculation_mitigations(void)setup_clear_cpu_cap (X86_FEATURE_NO_XPTI );Quoted 13 lines
xen/arch/x86/spec_ctrl.c void __init init_speculation_mitigations(void) · line 431
Quoted 11 lines
xen/arch/x86/spec_ctrl.c +10
-0print_details (thunk, caps); + +/* +* If MSR_SPEC_CTRL is available, apply Xen's default setting and discard +* any firmware settings. For performance reasons on native hardware, we +* delay applying non-zero settings until after dom0 has been constructed. +*/ +if (boot_cpu_has (X86_FEATURE_IBRSB ) ) + { + bsp_delay_spec_ctrl = !cpu_has_hypervisor && default_xen_spec_ctrl; +Why is
cpu_has_hypervisorneeded here? This should help nested case as well. And it wouldn't make the setup less secure, right?Quoted 2 lines
Ah, yes, Andrew, this should indeed be explained in at least one of comment or commit message.
I've adjusted this comment to read:
/*
* IfMSR_SPEC_CTRLis available, apply Xen's default setting and discard
* any firmware settings. For performance reasons, when safe to do so, we
* delay applying non-zero settings until after dom0 has been constructed. *
* "when safe to do so" is based on whether we are virtualised. A native
* boot won't have any other code running in a position to mount an
* attack.
*/
Quoted 1 line
and added the same second paragraph to the commit message.
LGTM. Thanks!
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 8/10 x86/cpuid: Improvements to guest policies for speculative sidechannel features
In reply to Andrew CooperIf Xen isn't virtualising MSR_SPEC_CTRL for guests, IBRSB shouldn't be advertised. It is not currently possible to express this via the existing command line options, but such an ability will be introduced.
Another useful option in some usecases is to offer IBPB without IBRS. When a guest kernel is known to be compatible (uses retpoline and knows about the AMD IBPB feature bit), an administrator with pre-Skylake hardware may wish to hide IBRS. This allows the VM to have full protection, without Xen or the VM needing to touch MSR_SPEC_CTRL, which can reduce the overhead of Spectre mitigations.
Break the logic common to both PV and HVM CPUID calculations into a common helper, to avoid duplication.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Juergen Gross <[email protected]>
--- xen/arch/x86/cpuid.c | 60 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 23 deletions(-)
xen/arch/x86/cpuid.c +37 -23
@@ -368,6 +368,28 @@ static void __init calculate_host_policy(void) } } +static void __init guest_common_feature_adjustments (uint32_t *fs) +{ +/* Unconditionally claim to be able to set the hypervisor bit. */ +__set_bit (X86_FEATURE_HYPERVISOR , fs); + +/* +* If IBRS is offered to the guest, unconditionally offer STIBP. It is a +* nop on non-HT hardware, and has this behaviour to make heterogeneous +* setups easier to manage. +*/ +if (test_bit (X86_FEATURE_IBRSB , fs) ) +__set_bit (X86_FEATURE_STIBP , fs); + +/* +* On hardware which supports IBRS/IBPB, we can offer IBPB independently +* of IBRS by using the AMD feature bit. An administrator may wish for +* performance reasons to offer IBPB without IBRS. +*/ +if ( host_cpuid_policy.feat.ibrsb ) +__set_bit (X86_FEATURE_IBPB , fs); +} +static void __init calculate_pv_max_policy (void ) {struct cpuid_policy *p = &pv_max_cpuid_policy;
@@ -380,18 +402,14 @@ static void __init calculate_pv_max_policy(void)for ( i =0 ; i <ARRAY_SIZE (pv_featureset); ++i ) pv_featureset[i] &= pv_featuremask[i]; -/* Unconditionally claim to be able to set the hypervisor bit. */ -__set_bit (X86_FEATURE_HYPERVISOR , pv_featureset); - -/* On hardware with IBRS/IBPB support, there are further adjustments. */ -if (test_bit (X86_FEATURE_IBRSB , pv_featureset) ) - { -/* Offer STIBP unconditionally. It is a nop on non-HT hardware. */ -__set_bit (X86_FEATURE_STIBP , pv_featureset); +/* +* If Xen isn't virtualising MSR_SPEC_CTRL for PV guests because of +* administrator choice, hide the feature. +*/ +if ( !boot_cpu_has (X86_FEATURE_SC_MSR_PV ) ) +__clear_bit (X86_FEATURE_IBRSB , pv_featureset); -/* AMD's IBPB is a subset of IBRS/IBPB. */ -__set_bit (X86_FEATURE_IBPB , pv_featureset); - } +guest_common_feature_adjustments (pv_featureset);sanitise_featureset (pv_featureset);cpuid_featureset_to_policy (pv_featureset, p);
@@ -419,9 +437,6 @@ static void __init calculate_hvm_max_policy(void)for ( i =0 ; i <ARRAY_SIZE (hvm_featureset); ++i ) hvm_featureset[i] &= hvm_featuremask[i]; -/* Unconditionally claim to be able to set the hypervisor bit. */ -__set_bit (X86_FEATURE_HYPERVISOR , hvm_featureset); -/* * Xen can provide an APIC emulation to HVM guests even if the host's APIC * isn't enabled.
@@ -438,6 +453,13 @@ static void __init calculate_hvm_max_policy(void)__set_bit (X86_FEATURE_SEP , hvm_featureset);/* +* If Xen isn't virtualising MSR_SPEC_CTRL for HVM guests because of +* administrator choice, hide the feature. +*/ +if ( !boot_cpu_has (X86_FEATURE_SC_MSR_HVM ) ) +__clear_bit (X86_FEATURE_IBRSB , hvm_featureset); + +/* * With VT-x, some features are only supported by Xen if dedicated * hardware support is also available. */
@@ -450,15 +472,7 @@ static void __init calculate_hvm_max_policy(void)__clear_bit (X86_FEATURE_XSAVES , hvm_featureset); } -/* On hardware with IBRS/IBPB support, there are further adjustments. */ -if (test_bit (X86_FEATURE_IBRSB , hvm_featureset) ) - { -/* Offer STIBP unconditionally. It is a nop on non-HT hardware. */ -__set_bit (X86_FEATURE_STIBP , hvm_featureset); - -/* AMD's IBPB is a subset of IBRS/IBPB. */ -__set_bit (X86_FEATURE_IBPB , hvm_featureset); - } +guest_common_feature_adjustments (hvm_featureset);sanitise_featureset (hvm_featureset);cpuid_featureset_to_policy (hvm_featureset, p);
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 9/10 x86/spec_ctrl: Introduce a new `spec-ctrl=` command line argument to replace `bti=`
In reply to Andrew CooperIn hindsight, the options for bti= aren't as flexible or useful as expected (including several options which don't appear to behave as intended). Changing the behaviour of an existing option is problematic for compatibility, so introduce a new spec-ctrl= in the hopes that we can do better.
One common way of deploying Xen is with a single PV dom0 and all domUs being HVM domains. In such a setup, an administrator who has weighed up the risks may wish to forgo protection against malicious PV domains, to reduce the overall performance hit. To cater for this usecase, spec-ctrl=no-pv will disable all speculative protection for PV domains, while leaving all speculative protection for HVM domains intact.
For coding clarity as much as anything else, the suboptions are grouped by logical area; those which affect the alternatives blocks, and those which affect Xen's in-hypervisor settings. See the xen-command-line.markdown for full details of the new options.
While changing the command line options, take the time to change how the data is reported to the user. The three DEBUG printks are upgraded to unilateral, as they are all relevant pieces of information, and the old "mitigations:" line is split in the two logical areas described above.
Sample output from booting with spec-ctrl=no-pv looks like:
(XEN) Speculative mitigation facilities:
(XEN) Hardware features: IBRS/IBPB STIBP IBPB (XEN) Compiled-in support: INDIRECT_THUNK (XEN) Xen settings: BTI-Thunk RETPOLINE, SPEC_CTRL: IBRS-, Other: IBPB (XEN) Support for VMs: PV: None, HVM: MSR_SPEC_CTRL RSB (XEN) XPTI (64-bit PV only): Dom0 enabled, DomU enabled
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Juergen Gross <[email protected]>
--- docs/misc/xen-command-line.markdown | 49 +++++++++++ xen/arch/x86/spec_ctrl.c | 164 ++++++++++++++++++++++++++++++------ 2 files changed, 188 insertions(+), 25 deletions(-)
docs/misc/xen-command-line.markdown +49 -0
@@ -248,6 +248,9 @@ the NMI watchdog is also enabled. ### bti (x86) > `= List of [ <bool>, thunk=retpoline|lfence|jmp, ibrs=<bool>, ibpb=<bool>, rsb=<bool>, rsb_{vmexit,native}=<bool> ]` +**WARNING: This command line option is deprecated, and superseded by +_spec-ctrl=_ - using both options in combination is undefined.** + Branch Target Injection controls. By default, Xen will pick the most appropriate BTI mitigations based on compiled in support, loaded microcode, and hardware details.
@@ -1752,6 +1755,52 @@ enforces the maximum theoretically necessary timeout of 670ms. Any number is being interpreted as a custom timeout in milliseconds. Zero or boolean false disable the quirk workaround, which is also the default. +### spec-ctrl (x86) +> `= List of [ <bool>, xen=<bool>, {pv,hvm,msr-sc,rsb}=<bool>, +> bti-thunk=retpoline|lfence|jmp, {ibrs,ibpb}=<bool> ]` + +Controls for speculative execution sidechannel mitigations. By default, Xen +will pick the most appropriate mitigations based on compiled in support, +loaded microcode, and hardware details, and will virtualise appropriate +mitigations for guests to use. + +**WARNING: Any use of this option may interfere with heuristics. Use with +extreme care.** + +An overall boolean value, `spec-ctrl=no`, can be specified to turn off all +mitigations, including pieces of infrastructure used to virtualise certain +mitigation features for guests. Alternatively, a slightly more restricted +`spec-ctrl=no-xen` can be used to turn off all of Xen's mitigations, while +leaving the virtualisation support in place for guests to use. Use of a +positive boolean value for either of these options is invalid. + +The booleans `pv=`, `hvm=`, `msr-sc=` and `rsb=` offer fine grained control +over the alternative blocks used by Xen. These impact Xen's ability to +protect itself, and Xen's ability to virtualise support for guests to use. + +* `pv=` and `hvm=` offer control over all suboptions for PV and HVM guests + respectively. +* `msr-sc=` offers control over Xen's support for manipulating MSR\_SPEC\_CTRL + on entry and exit. These blocks are necessary to virtualise support for + guests and if disabled, guests will be unable to use IBRS/STIBP/etc. +* `rsb=` offers control over whether to overwrite the Return Stack Buffer / + Return Address Stack on entry to Xen. + +If Xen was compiled with INDIRECT\_THUNK support, `bti-thunk=` can be used to +select which of the thunks gets patched into the `__x86_indirect_thunk_%reg` +locations. The default thunk is `retpoline` (generally preferred for Intel +hardware), with the alternatives being `jmp` (a `jmp *%reg` gadget, minimal +overhead), and `lfence` (an `lfence; jmp *%reg` gadget, preferred for AMD). + +On hardware supporting IBRS (Indirect Branch Restricted Speculation), the +`ibrs=` option can be used to force or prevent Xen using the feature itself. +If Xen is not using IBRS itself, functionality is still set up so IBRS can be +virtualised for guests. + +On hardware supporting IBPB (Indirect Branch Prediction Barrier), the `ibpb=` +option can be used to force (the default) or prevent Xen from issuing branch +prediction barriers on vcpu context switches. + ### sync\_console > `= <boolean>`
xen/arch/x86/spec_ctrl.c +139 -25
220 lines not on this page · raw message
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 10/10 x86/spec_ctrl: Elide MSR_SPEC_CTRL handling in idle context when possible
In reply to Andrew CooperIf Xen is virtualising MSR_SPEC_CTRL handling for guests, but using 0 as its own MSR_SPEC_CTRL value, spec_ctrl_{enter,exit}_idle() need not write to the MSR.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Juergen Gross <[email protected]>
--- xen/arch/x86/spec_ctrl.c | 4 ++++ xen/include/asm-x86/cpufeatures.h | 1 + xen/include/asm-x86/spec_ctrl.h | 8 ++------ 3 files changed, 7 insertions(+), 6 deletions(-)
xen/arch/x86/spec_ctrl.c +4 -0
@@ -526,6 +526,10 @@ void __init init_speculation_mitigations(void)/* (Re)init BSP state now that default_spec_ctrl_flags has been calculated. */ init_shadow_spec_ctrl_state (); +/* If Xen is using any MSR_SPEC_CTRL settings, adjust the idle path. */ +if ( default_xen_spec_ctrl ) +setup_force_cpu_cap (X86_FEATURE_SC_MSR_IDLE ); +xpti_init_default (false);if ( opt_xpti ==0 )setup_force_cpu_cap (X86_FEATURE_NO_XPTI );
xen/include/asm-x86/cpufeatures.h +1 -0
@@ -31,3 +31,4 @@ XEN_CPUFEATURE(SC_MSR_HVM, (FSCAPINTS+0)*32+17) /* MSR_SPEC_CTRL used by Xe XEN_CPUFEATURE(SC_RSB_PV, (FSCAPINTS+0)*32+18) /* RSB overwrite needed for PV */ XEN_CPUFEATURE(SC_RSB_HVM, (FSCAPINTS+0)*32+19) /* RSB overwrite needed for HVM */ XEN_CPUFEATURE(NO_XPTI, (FSCAPINTS+0)*32+20) /* XPTI mitigation not in use */ +XEN_CPUFEATURE (SC_MSR_IDLE , (FSCAPINTS +0 )*32 +21 )/* (SC_MSR_PV || SC_MSR_HVM) && default_xen_spec_ctrl */
xen/include/asm-x86/spec_ctrl.h +2 -6
@@ -58,9 +58,7 @@ static always_inline void spec_ctrl_enter_idle(struct cpu_info *info)barrier (); info->spec_ctrl_flags |= SCF_use_shadow;barrier (); - asm volatile ( ALTERNATIVE_2(ASM_NOP3, - "wrmsr", X86_FEATURE_SC_MSR_PV, - "wrmsr", X86_FEATURE_SC_MSR_HVM) + asm volatile ( ALTERNATIVE(ASM_NOP3, "wrmsr", X86_FEATURE_SC_MSR_IDLE) :: "a" (val), "c" (MSR_SPEC_CTRL), "d" (0) : "memory" ); }
@@ -75,9 +73,7 @@ static always_inline void spec_ctrl_exit_idle(struct cpu_info *info)*/ info->spec_ctrl_flags &= ~SCF_use_shadow;barrier (); - asm volatile ( ALTERNATIVE_2(ASM_NOP3, - "wrmsr", X86_FEATURE_SC_MSR_PV, - "wrmsr", X86_FEATURE_SC_MSR_HVM) + asm volatile ( ALTERNATIVE(ASM_NOP3, "wrmsr", X86_FEATURE_SC_MSR_IDLE) :: "a" (val), "c" (MSR_SPEC_CTRL), "d" (0) : "memory" ); }
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 10/10] x86/spec_ctrl: Elide MSR_SPEC_CTRL handling in idle context when possible
Quoted 37 lines · Andrew Cooper
If Xen is virtualising
MSR_SPEC_CTRLhandling for guests, but using 0 as its ownMSR_SPEC_CTRLvalue, spec_ctrl_{enter,exit}_idle() need not write to the MSR.Requested-by Jan Beulich <[email protected]>Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Juergen Gross <[email protected]>--- xen/arch/x86/spec_ctrl.c | 4 ++++ xen/include/asm-x86/cpufeatures.h | 1 + xen/include/asm-x86/spec_ctrl.h | 8 ++------ 3 files changed, 7 insertions(+), 6 deletions(-)xen/arch/x86/spec_ctrl.c +4
-0@@ -526,6 +526,10 @@ void __init init_speculation_mitigations(void)/* (Re)init BSP state now that default_spec_ctrl_flags has been calculated. */ init_shadow_spec_ctrl_state (); +/* If Xen is using any MSR_SPEC_CTRL settings, adjust the idle path. */ +if ( default_xen_spec_ctrl ) +setup_force_cpu_cap (X86_FEATURE_SC_MSR_IDLE ); +xpti_init_default (false);if ( opt_xpti ==0 )setup_force_cpu_cap (X86_FEATURE_NO_XPTI );xen/include/asm-x86/cpufeatures.h +0
-0
xen/include/asm-x86/cpufeatures.h XEN_CPUFEATURE(SC_MSR_HVM, (FSCAPINTS+0)*32+17) /* MSR_SPEC_CTRL used by Xe · line 34
Quoted 4 lines
xen/include/asm-x86/cpufeatures.h +1
-0@@ -31,3 +31,4 @@ XEN_CPUFEATURE(SC_MSR_HVM, (FSCAPINTS+0)*32+17) /* MSR_SPEC_CTRL used by Xe XEN_CPUFEATURE(SC_RSB_PV, (FSCAPINTS+0)*32+18) /* RSB overwrite needed for PV */ XEN_CPUFEATURE(SC_RSB_HVM, (FSCAPINTS+0)*32+19) /* RSB overwrite needed for HVM */ XEN_CPUFEATURE(NO_XPTI, (FSCAPINTS+0)*32+20) /* XPTI mitigation not in use */ +XEN_CPUFEATURE (SC_MSR_IDLE , (FSCAPINTS +0 )*32 +21 )/* (SC_MSR_PV || SC_MSR_HVM) && default_xen_spec_ctrl */
I don't follow: the code above only depends on default_xen_spec_ctrl but the comment says SC_MSR_PV and SC_MSR_HVM are also taken into consideration.
The rest looks fine.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 10/10] x86/spec_ctrl: Elide MSR_SPEC_CTRL handling in idle context when possible
Quoted 37 lines · Wei Liu
Quoted 36 lines · Andrew Cooper
If Xen is virtualising
MSR_SPEC_CTRLhandling for guests, but using 0 as its ownMSR_SPEC_CTRLvalue, spec_ctrl_{enter,exit}_idle() need not write to the MSR.Requested-by Jan Beulich <[email protected]>Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Juergen Gross <[email protected]>--- xen/arch/x86/spec_ctrl.c | 4 ++++ xen/include/asm-x86/cpufeatures.h | 1 + xen/include/asm-x86/spec_ctrl.h | 8 ++------ 3 files changed, 7 insertions(+), 6 deletions(-)xen/arch/x86/spec_ctrl.c +4
-0@@ -526,6 +526,10 @@ void __init init_speculation_mitigations(void)/* (Re)init BSP state now that default_spec_ctrl_flags has been calculated. */ init_shadow_spec_ctrl_state (); +/* If Xen is using any MSR_SPEC_CTRL settings, adjust the idle path. */ +if ( default_xen_spec_ctrl ) +setup_force_cpu_cap (X86_FEATURE_SC_MSR_IDLE ); +xpti_init_default (false);if ( opt_xpti ==0 )setup_force_cpu_cap (X86_FEATURE_NO_XPTI );xen/include/asm-x86/cpufeatures.h +0
-0
Quoted 8 lines
xen/include/asm-x86/cpufeatures.h XEN_CPUFEATURE(SC_MSR_HVM, (FSCAPINTS+0)*32+17) /* MSR_SPEC_CTRL used by Xe · line 34
Quoted 5 lines
xen/include/asm-x86/cpufeatures.h +1
-0@@ -31,3 +31,4 @@ XEN_CPUFEATURE(SC_MSR_HVM, (FSCAPINTS+0)*32+17) /* MSR_SPEC_CTRL used by Xe XEN_CPUFEATURE(SC_RSB_PV, (FSCAPINTS+0)*32+18) /* RSB overwrite needed for PV */ XEN_CPUFEATURE(SC_RSB_HVM, (FSCAPINTS+0)*32+19) /* RSB overwrite needed for HVM */ XEN_CPUFEATURE(NO_XPTI, (FSCAPINTS+0)*32+20) /* XPTI mitigation not in use */ +XEN_CPUFEATURE (SC_MSR_IDLE , (FSCAPINTS +0 )*32 +21 )/* (SC_MSR_PV || SC_MSR_HVM) && default_xen_spec_ctrl */ I don't follow: the code above only depends on
default_xen_spec_ctrlbut the comment saysSC_MSR_PVandSC_MSR_HVMare also taken into consideration.
default_xen_spec_ctrl is only ever nonzero when SC_MSR_PV or SC_MSR_HVM is set. In principle, I could assert that one of the two is set.
I have phrased it like this because it is going to become rather more complicated (than != 0) when adding IBRS_ATT mode.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 10/10] x86/spec_ctrl: Elide MSR_SPEC_CTRL handling in idle context when possible
Quoted 47 lines · Andrew Cooper
Quoted 37 lines · Wei Liu
Quoted 36 lines · Andrew Cooper
If Xen is virtualising
MSR_SPEC_CTRLhandling for guests, but using 0 as its ownMSR_SPEC_CTRLvalue, spec_ctrl_{enter,exit}_idle() need not write to the MSR.Requested-by Jan Beulich <[email protected]>Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Juergen Gross <[email protected]>--- xen/arch/x86/spec_ctrl.c | 4 ++++ xen/include/asm-x86/cpufeatures.h | 1 + xen/include/asm-x86/spec_ctrl.h | 8 ++------ 3 files changed, 7 insertions(+), 6 deletions(-)xen/arch/x86/spec_ctrl.c +4
-0@@ -526,6 +526,10 @@ void __init init_speculation_mitigations(void)/* (Re)init BSP state now that default_spec_ctrl_flags has been calculated. */ init_shadow_spec_ctrl_state (); +/* If Xen is using any MSR_SPEC_CTRL settings, adjust the idle path. */ +if ( default_xen_spec_ctrl ) +setup_force_cpu_cap (X86_FEATURE_SC_MSR_IDLE ); +xpti_init_default (false);if ( opt_xpti ==0 )setup_force_cpu_cap (X86_FEATURE_NO_XPTI );xen/include/asm-x86/cpufeatures.h +0
-0Quoted 8 lines
xen/include/asm-x86/cpufeatures.h XEN_CPUFEATURE(SC_MSR_HVM, (FSCAPINTS+0)*32+17) /* MSR_SPEC_CTRL used by Xe · line 34
Quoted 5 lines
xen/include/asm-x86/cpufeatures.h +1
-0@@ -31,3 +31,4 @@ XEN_CPUFEATURE(SC_MSR_HVM, (FSCAPINTS+0)*32+17) /* MSR_SPEC_CTRL used by Xe XEN_CPUFEATURE(SC_RSB_PV, (FSCAPINTS+0)*32+18) /* RSB overwrite needed for PV */ XEN_CPUFEATURE(SC_RSB_HVM, (FSCAPINTS+0)*32+19) /* RSB overwrite needed for HVM */ XEN_CPUFEATURE(NO_XPTI, (FSCAPINTS+0)*32+20) /* XPTI mitigation not in use */ +XEN_CPUFEATURE (SC_MSR_IDLE , (FSCAPINTS +0 )*32 +21 )/* (SC_MSR_PV || SC_MSR_HVM) && default_xen_spec_ctrl */ I don't follow: the code above only depends on
default_xen_spec_ctrlbut the comment saysSC_MSR_PVandSC_MSR_HVMare also taken into consideration.
Quoted 5 lines
default_xen_spec_ctrlis only ever nonzero whenSC_MSR_PVorSC_MSR_HVMis set. In principle, I could assert that one of the two is set.I have phrased it like this because it is going to become rather more complicated (than != 0) when adding
IBRS_ATTmode.
OK, thanks for explaining.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 3 lines · Andrew Cooper
In hindsight, the end result of the Spectre mitigations aren't as great as I'd hoped, and have several inefficiencies. Also, the
bti=command line option isn't as flexible as intended.
I think this is a good argument for this series to be in for 4.11.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 11.05.18 at 12:38, <[email protected]> wrote:
In hindsight, the end result of the Spectre mitigations aren't as great as I'd hoped, and have several inefficiencies. Also, the
bti=command line option isn't as flexible as intended.This series does four things:
1) Some internal cleanup, for clarity and to help the other features
2) Introducespec-ctrl=no-pvmode. XenServer's performance measurements see a 10% net/disk performance improvement in some production scenarios.
3) Introduce the ability to use IBPB-only mode for guests. This was discussed by Amazon during the Spectre work, but I don't have any performance numbers to hand.
4) Avoid imposing IBRS mode while dom0 is booting. This was reported by Oracle on the list, and speeds up boot time on some servers by 50s.I know this series is rather late for 4.11, but seeing as I've managed to complete it before 4.12 opens, it should be considered at this point, as all of the Spectre code is new in 4.11.
Quoted 11 lines
Andrew Cooper (10):
x86/spec_ctrl: ReadMSR_ARCH_CAPABILITIESonly once
x86/spec_ctrl: Express Xen's choice ofMSR_SPEC_CTRLvalue as a variable x86/spec_ctrl: Mergebti_ist_infoanduse_shadow_spec_ctrlintospec_ctrl_flagsx86/spec_ctrl: Fold the XEN_IBRS_{SET,CLEAR} ALTERNATIVES together x86/spec_ctrl: Rename bits of infrastructure to avoid NATIVE and VMEXIT x86/spec_ctrl: SplitX86_FEATURE_SC_MSRinto PV and HVM variants x86/spec_ctrl: Explicitly set Xen's defaultMSR_SPEC_CTRLvalue x86/cpuid: Improvements to guest policies for speculative sidechannel features x86/spec_ctrl: Introduce a newspec-ctrl=command line argument to replacebti=x86/spec_ctrl: ElideMSR_SPEC_CTRLhandling in idle context when possible
Irrespective of the small comment just sent for patch 6:
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 31 lines · Andrew Cooper
In hindsight, the end result of the Spectre mitigations aren't as great as I'd hoped, and have several inefficiencies. Also, the
bti=command line option isn't as flexible as intended.This series does four things:
1) Some internal cleanup, for clarity and to help the other features
2) Introducespec-ctrl=no-pvmode. XenServer's performance measurements see a 10% net/disk performance improvement in some production scenarios.
3) Introduce the ability to use IBPB-only mode for guests. This was discussed by Amazon during the Spectre work, but I don't have any performance numbers to hand.
4) Avoid imposing IBRS mode while dom0 is booting. This was reported by Oracle on the list, and speeds up boot time on some servers by 50s.I know this series is rather late for 4.11, but seeing as I've managed to complete it before 4.12 opens, it should be considered at this point, as all of the Spectre code is new in 4.11.
Andrew Cooper (10):
x86/spec_ctrl: ReadMSR_ARCH_CAPABILITIESonly once
x86/spec_ctrl: Express Xen's choice ofMSR_SPEC_CTRLvalue as a variable x86/spec_ctrl: Mergebti_ist_infoanduse_shadow_spec_ctrlintospec_ctrl_flagsx86/spec_ctrl: Fold the XEN_IBRS_{SET,CLEAR} ALTERNATIVES together x86/spec_ctrl: Rename bits of infrastructure to avoid NATIVE and VMEXIT x86/spec_ctrl: SplitX86_FEATURE_SC_MSRinto PV and HVM variants x86/spec_ctrl: Explicitly set Xen's defaultMSR_SPEC_CTRLvalue x86/cpuid: Improvements to guest policies for speculative sidechannel features x86/spec_ctrl: Introduce a newspec-ctrl=command line argument to replacebti=x86/spec_ctrl: ElideMSR_SPEC_CTRLhandling in idle context when possible
Quoted 17 lines
docs/misc/xen-command-line.markdown | 49 +++++++ xen/arch/x86/acpi/power.c | 4 +- xen/arch/x86/cpuid.c | 60 +++++---- xen/arch/x86/hvm/svm/entry.S | 4 +- xen/arch/x86/hvm/vmx/entry.S | 4 +- xen/arch/x86/setup.c | 7 + xen/arch/x86/smpboot.c | 8 ++ xen/arch/x86/spec_ctrl.c | 258 ++++++++++++++++++++++++++++-------- xen/arch/x86/x86_64/asm-offsets.c | 4 +- xen/arch/x86/x86_64/compat/entry.S | 2 +- xen/arch/x86/x86_64/entry.S | 2 +- xen/include/asm-x86/cpufeatures.h | 9 +- xen/include/asm-x86/current.h | 4 +- xen/include/asm-x86/spec_ctrl.h | 20 +-- xen/include/asm-x86/spec_ctrl_asm.h | 131 +++++++++--------- 15 files changed, 396 insertions(+), 170 deletions(-)
For the series:
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel