x86/spec-ctrl: Support Intel's new PB-OPT
PATCH 1/1 x86/spec-ctrl: Support Intel's new PB-OPT
In IPU 2025.2 (May 2025), Intel have released an alternative mitigation for a prior security issue (SA-00982) on Sappire and Emerald Rapids CPUs.
Intel suggest that certain workloads will benefit from using the alternative mode. This can be selected by booting with spec-ctrl=ibpb-alt.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
Intel have named this PBOPT (no space), but that's too close to PBRSB for my liking. PB_OPT (with a space) is also consistent with MCU_OPT, it's closest neighbour.
I've chosen not to extend print_details() with this. It's specific to two Intel CPUs and not being continued into future ones.
I'm not sure what else to say in the cmdline docs. Intel is very sparse on details. An educated guess is that in the default mode, part of the predictor is inhibited, while in the alternative mode it's active, but at the cost of extra scrubbing in IBPB.
--- docs/misc/xen-command-line.pandoc | 6 ++++- xen/arch/x86/acpi/power.c | 1 + xen/arch/x86/cpu/intel.c | 28 +++++++++++++++++++++ xen/arch/x86/include/asm/cpufeature.h | 1 + xen/arch/x86/include/asm/msr-index.h | 3 +++ xen/arch/x86/include/asm/processor.h | 3 +++ xen/arch/x86/smpboot.c | 1 + xen/arch/x86/spec_ctrl.c | 7 ++++++ xen/include/public/arch-x86/cpufeatureset.h | 1 + 9 files changed, 50 insertions(+), 1 deletion(-)
docs/misc/xen-command-line.pandoc +5 -1
@@ -2470,7 +2470,7 @@ By default SSBD will be mitigated at runtime (i.e `ssbd=runtime`). > {ibrs,ibpb,ssbd,psfd, > eager-fpu,l1d-flush,branch-harden,srb-lock, > unpriv-mmio,gds-mit,div-scrub,lock-harden, -> bhi-dis-s,bp-spec-reduce}=<bool> ]` +> bhi-dis-s,bp-spec-reduce,ibpb-alt}=<bool> ]` Controls for speculative execution sidechannel mitigations. By default, Xen will pick the most appropriate mitigations based on compiled in support,
@@ -2626,6 +2626,10 @@ bp-spec-reduce when available, as it is preferable to using `ibpb-entry=hvm` to mitigate SRSO for HVM guests, and because it is a prerequisite to advertise SRSO_U/S_NO to PV guests. +On Sappire and Emerald Rapids CPUs with May 2025 microcode or later, the +`ibpb-alt=` option can be used to switch to the alternative mitigation for +Intel SA-00982. Intel suggest that some workloads will benefit from this. + ### sync_console > `= <boolean>`
xen/arch/x86/acpi/power.c +1 -0
@@ -306,6 +306,7 @@ static int enter_state(u32 state) }update_mcu_opt_ctrl (); +update_pb_opt_ctrl ();/* * This should be before restoring CR4, but that is earlier in asm and
xen/arch/x86/cpu/intel.c +28 -0
@@ -49,6 +49,34 @@ void __init set_in_mcu_opt_ctrl(uint32_t mask, uint32_t val)update_mcu_opt_ctrl (); } +static uint32_t __ro_after_init pb_opt_ctrl_mask; +static uint32_t __ro_after_init pb_opt_ctrl_val; + +void update_pb_opt_ctrl (void ) +{ +uint32_t mask = pb_opt_ctrl_mask, lo, hi; + +if ( !mask ) +return ; + +rdmsr (MSR_PB_OPT_CTRL , lo, hi); + + lo &= ~mask; + lo |= pb_opt_ctrl_val; + +wrmsr (MSR_PB_OPT_CTRL , lo, hi); +} + +void __init set_in_pb_opt_ctrl (uint32_t mask,uint32_t val) +{ + pb_opt_ctrl_mask |= mask; + + pb_opt_ctrl_val &= ~mask; + pb_opt_ctrl_val |= (val & mask); + +update_pb_opt_ctrl (); +} +/* * Processors which have self-snooping capability can handle conflicting * memory type across CPUs by snooping its own cache. However, there exists
xen/arch/x86/include/asm/cpufeature.h +1 -0
@@ -219,6 +219,7 @@ static inline bool boot_cpu_has(unsigned int feat)#define cpu_has_gds_no boot_cpu_has(X86_FEATURE_GDS_NO)#define cpu_has_rfds_no boot_cpu_has(X86_FEATURE_RFDS_NO)#define cpu_has_rfds_clear boot_cpu_has(X86_FEATURE_RFDS_CLEAR) +#define cpu_has_pb_opt_ctrl boot_cpu_has(X86_FEATURE_PB_OPT_CTRL)#define cpu_has_its_no boot_cpu_has(X86_FEATURE_ITS_NO)/* Synthesized. */
xen/arch/x86/include/asm/msr-index.h +3 -0
@@ -56,6 +56,9 @@#define MSR_MISC_PACKAGE_CTRL 0x000000bc#define PGK_CTRL_ENERGY_FILTER_EN (_AC(1, ULL) << 0) +#define MSR_PB_OPT_CTRL 0x000000bf +#define PB_OPT_IBPB_ALT (_AC(1, ULL) << 0) +#define MSR_CORE_CAPABILITIES 0x000000cf#define CORE_CAPS_SPLITLOCK_DETECT (_AC(1, ULL) << 5)
xen/arch/x86/include/asm/processor.h +3 -0
@@ -470,6 +470,9 @@ static inline void tsx_init(void) {}void update_mcu_opt_ctrl (void );void set_in_mcu_opt_ctrl (uint32_t mask,uint32_t val); +void update_pb_opt_ctrl (void ); +void set_in_pb_opt_ctrl (uint32_t mask,uint32_t val); +enum ap_boot_method {AP_BOOT_NORMAL ,AP_BOOT_SKINIT ,
xen/arch/x86/smpboot.c +1 -0
@@ -383,6 +383,7 @@ void asmlinkage start_secondary(void *unused) info->last_spec_ctrl = default_xen_spec_ctrl; }update_mcu_opt_ctrl (); +update_pb_opt_ctrl ();tsx_init ();/* Needs microcode. May change HLE/RTM feature bits. */
xen/arch/x86/spec_ctrl.c +7 -0
@@ -85,6 +85,8 @@ static int8_t __initdata opt_gds_mit = -1;static int8_t __initdata opt_div_scrub =-1 ;bool __ro_after_init opt_bp_spec_reduce = true; +static __initdata bool opt_ibpb_alt; + static int __init cf_check parse_spec_ctrl(const char *s) {const char *ss;
@@ -369,6 +371,8 @@ static int __init cf_check parse_spec_ctrl(const char *s) opt_div_scrub = val; else if ( (val = parse_boolean("bp-spec-reduce", s, ss)) >= 0 ) opt_bp_spec_reduce = val; + else if ( (val = parse_boolean("ibpb-alt", s, ss)) >= 0 ) + opt_ibpb_alt = val; else rc = -EINVAL ;
@@ -2494,6 +2498,9 @@ void __init init_speculation_mitigations(void)wrmsrl (MSR_SPEC_CTRL , val); info->last_spec_ctrl = val; } + +if ( cpu_has_pb_opt_ctrl ) +set_in_pb_opt_ctrl (PB_OPT_IBPB_ALT , opt_ibpb_alt); }static void __init __maybe_unused build_assertions (void )
xen/include/public/arch-x86/cpufeatureset.h +1 -0
@@ -392,6 +392,7 @@ XEN_CPUFEATURE(IGN_UMONITOR, 16*32+29) /* MCU_OPT_CTRL.IGN_UMONITOR */XEN_CPUFEATURE (MON_UMON_MITG ,16 *32 +30 )/* MCU_OPT_CTRL.MON_UMON_MITG */ /* Intel-defined CPU features, MSR_ARCH_CAPS 0x10a.edx, word 17 (express in terms of word 16) */ +XEN_CPUFEATURE(PB_OPT_CTRL, 16*32+32) /* MSR_PB_OPT_CTRL.IBPB_ALT */ XEN_CPUFEATURE(ITS_NO, 16*32+62) /*!A No Indirect Target Selection */#endif /* XEN_CPUFEATURE */
base-commit: f6042f38e621525feff86bb101dc751d2d87cff8
Signature · 1 line
2.39.5
Quoted 8 lines · Andrew Cooper
In IPU 2025.2 (May 2025), Intel have released an alternative mitigation for a prior security issue (SA-00982) on Sappire and Emerald Rapids CPUs.
Intel suggest that certain workloads will benefit from using the alternative mode. This can be selected by booting with
spec-ctrl=ibpb-alt.Signed-off-by Andrew Cooper <[email protected]>
with two nits: For one, s/Sappire/Sapphire/ throughout. And then ...
xen/arch/x86/spec_ctrl.c static int8_t __initdata opt_gds_mit = -1; · line 88
Quoted 7 lines
xen/arch/x86/spec_ctrl.c +1
-0@@ -85,6 +85,8 @@ static int8_t __initdata opt_gds_mit = -1;static int8_t __initdata opt_div_scrub =-1 ;bool __ro_after_init opt_bp_spec_reduce = true; +static __initdata bool opt_ibpb_alt;
... type and attribute would preferably be swapped here, just like it's in context above as well as for the statics you add to cpu/intel.c.
Jan
Quoted 10 lines · Jan Beulich
Quoted 8 lines · Andrew Cooper
In IPU 2025.2 (May 2025), Intel have released an alternative mitigation for a prior security issue (SA-00982) on Sappire and Emerald Rapids CPUs.
Intel suggest that certain workloads will benefit from using the alternative mode. This can be selected by booting with
spec-ctrl=ibpb-alt.Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Jan Beulich <[email protected]>
Thanks.
Quoted 11 lines
with two nits: For one, s/Sappire/Sapphire/ throughout. And then ...
xen/arch/x86/spec_ctrl.c static int8_t __initdata opt_gds_mit = -1; · line 88
Quoted 7 lines
xen/arch/x86/spec_ctrl.c +1
-0@@ -85,6 +85,8 @@ static int8_t __initdata opt_gds_mit = -1;static int8_t __initdata opt_div_scrub =-1 ;bool __ro_after_init opt_bp_spec_reduce = true; +static __initdata bool opt_ibpb_alt;... type and attribute would preferably be swapped here, just like it's in context above as well as for the statics you add to
cpu/intel.c.
Oops, both fixed. (The public probably aren't aware, but this patch got lost in a bit of a mad rush of the late breaking changes to XSA-469 yesterday.)
~Andrew