x86: Fully remove MPX support
PATCH 1/1 x86: Fully remove MPX support
Intel dropped MPX from hardware starting in 2019. GCC 9.1 (the same year) dropped support, as did Linux 5.6 (2020). Xen ceased offering MPX to VMs by default in 4.14 (also 2020).
Aside from the substantial performance hit when turned on, and the hardware spilling mechanism being incompatible with C (i.e. the primary target for additional bounds checking), one problem with MPX is that the BNDCFGU register cannot be accessed by anything except XSAVE instructions.
The emulator needing to adjust BNDCFGU places a burden on Xen's XSAVE code, and on the forthcoming ASI series. The time has come to get rid of it fully, which also allows us to stop allocating an XSTATE buffer for the idle vCPUs, for which the emulator's MPX handling was the only user.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
CC: George Dunlap <[email protected]>
--- CHANGELOG.md | 4 ++ tools/libs/guest/xg_cpuid_x86.c | 12 ++-- xen/arch/x86/cpu-policy.c | 6 -- xen/arch/x86/domain.c | 2 - xen/arch/x86/hvm/hvm.c | 2 - xen/arch/x86/hvm/vmx/vmcs.c | 15 ++-- xen/arch/x86/hvm/vmx/vmx.c | 8 --- xen/arch/x86/include/asm/hvm/vmx/vmcs.h | 4 -- xen/arch/x86/include/asm/xstate.h | 10 +-- xen/arch/x86/msr.c | 35 +-------- xen/arch/x86/x86_emulate/private.h | 1 - xen/arch/x86/x86_emulate/x86_emulate.c | 51 -------------- xen/arch/x86/xstate.c | 78 +-------------------- xen/include/public/arch-x86/cpufeatureset.h | 2 +- 14 files changed, 20 insertions(+), 210 deletions(-)
CHANGELOG.md +4 -0
@@ -30,6 +30,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - The example stubdom "c-stubdom" has been removed. - The grub-pv stubdom has been removed. A grub-pv stubdom from an older Xen version (e.g. 4.22) will still work with Xen 4.23. + - MPX (Memory Protection Extensions) support has been fully removed. Intel + removed support in hardware in 2019, and Xen 4.14 (2020) stopped offering + it to VMs by default. VMs with MPX cannot be migrated or restored onto + this version of Xen, and need reconfiguring without MPX first. ## [4.22.0](https://xenbits.xenproject.org/gitweb/?p=xen.git;a=shortlog;h=staging) - 2026-07-30
tools/libs/guest/xg_cpuid_x86.c +7 -5
@@ -632,17 +632,19 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore,* Specifically: * - Clamp max leaves. * - Re-enable features which have become (possibly) off by default. +* +* Exceptions: +* - MPX support has been removed in Xen, so is not considered for +* re-inclusion. A VM which was genuinely using MPX will get +* rejected due to its XSTATE and/or MSR_BNDCFGS record. Other VMs +* might see the feature disappear but they're unlikely to notice, +* let alone care. */ p->policy.basic.rdrand =test_bit (X86_FEATURE_RDRAND , host_featureset); p->policy.feat.hle =test_bit (X86_FEATURE_HLE , host_featureset); p->policy.feat.rtm =test_bit (X86_FEATURE_RTM , host_featureset); -if ( hvm ) - { - p->policy.feat.mpx =test_bit (X86_FEATURE_MPX , host_featureset); - } - p->policy.basic.max_leaf =min (p->policy.basic.max_leaf,0xdu ); p->policy.feat.max_subleaf =min (p->policy.feat.max_subleaf,0x2u ); p->policy.extd.max_leaf =min (p->policy.extd.max_leaf,0x80000021 );
xen/arch/x86/cpu-policy.c +0 -6
@@ -208,9 +208,6 @@ static void recalculate_xstate(struct cpu_policy *p)if ( p->basic.avx ) xstates |=X86_XCR0_YMM ; -if ( p->feat.mpx ) - xstates |=X86_XCR0_BNDREGS |X86_XCR0_BNDCSR ; -if ( p->feat.avx512f ) xstates |=X86_XCR0_OPMASK |X86_XCR0_ZMM |X86_XCR0_HI_ZMM ;
@@ -848,9 +845,6 @@ static void __init calculate_hvm_max_policy(void)if ( !cpu_has_vmx_invpcid )__clear_bit (X86_FEATURE_INVPCID , fs); -if ( !cpu_has_vmx_mpx ) -__clear_bit (X86_FEATURE_MPX , fs); -if ( !cpu_has_vmx_xsaves )__clear_bit (X86_FEATURE_XSAVES , fs); }
xen/arch/x86/domain.c +0 -2
@@ -541,8 +541,6 @@ int arch_vcpu_create(struct vcpu *v)if ( (rc =init_vcpu_msr_policy (v)) ) goto fail; } -else if ( (rc =xstate_alloc_save_area (v)) !=0 ) -return rc;spin_lock_init (&v->arch.vpmu.vpmu_lock);
xen/arch/x86/hvm/hvm.c +0 -2
@@ -1390,7 +1390,6 @@ static const uint32_t msrs_to_send[] = {MSR_SPEC_CTRL ,MSR_INTEL_MISC_FEATURES_ENABLES ,MSR_PKRS , -MSR_IA32_BNDCFGS ,MSR_IA32_XSS ,MSR_VIRT_SPEC_CTRL , MSR_AMD64_DR0_ADDRESS_MASK,
@@ -1544,7 +1543,6 @@ static int cf_check hvm_load_cpu_msrs(struct domain *d, hvm_domain_context_t *h)case MSR_SPEC_CTRL :case MSR_INTEL_MISC_FEATURES_ENABLES :case MSR_PKRS : -case MSR_IA32_BNDCFGS :case MSR_IA32_XSS :case MSR_VIRT_SPEC_CTRL :case MSR_AMD64_DR0_ADDRESS_MASK :
xen/arch/x86/hvm/vmx/vmcs.c +4 -11
@@ -455,7 +455,7 @@ static int vmx_init_vmcs_config(bool bsp) min =VM_EXIT_ACK_INTR_ON_EXIT ; opt = (VM_EXIT_SAVE_GUEST_PAT |VM_EXIT_LOAD_HOST_PAT | -VM_EXIT_LOAD_HOST_EFER |VM_EXIT_CLEAR_BNDCFGS ); +VM_EXIT_LOAD_HOST_EFER ); min |=VM_EXIT_IA32E_MODE ; caps.vmexit_control =adjust_vmx_controls ("VMExit Control" , min, opt,MSR_IA32_VMX_EXIT_CTLS , &mismatch);
@@ -495,8 +495,7 @@ static int vmx_init_vmcs_config(bool bsp) caps.secondary_exec_control &= ~SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS ; min =0 ; - opt = (VM_ENTRY_LOAD_GUEST_PAT |VM_ENTRY_LOAD_GUEST_EFER | -VM_ENTRY_LOAD_BNDCFGS ); + opt = (VM_ENTRY_LOAD_GUEST_PAT |VM_ENTRY_LOAD_GUEST_EFER ); caps.vmentry_control =adjust_vmx_controls ("VMEntry Control" , min, opt,MSR_IA32_VMX_ENTRY_CTLS , &mismatch);
@@ -1205,9 +1204,6 @@ static int construct_vmcs(struct vcpu *v)vmx_clear_msr_intercept (v,MSR_IA32_SYSENTER_EIP ,VMX_MSR_RW );if ( !paging_mode_shadow (d) && (!is_iommu_enabled (d) || iommu_snoop) )vmx_clear_msr_intercept (v,MSR_IA32_CR_PAT ,VMX_MSR_RW ); -if ( (vmexit_ctl &VM_EXIT_CLEAR_BNDCFGS ) && - (vmentry_ctl &VM_ENTRY_LOAD_BNDCFGS ) ) -vmx_clear_msr_intercept (v,MSR_IA32_BNDCFGS ,VMX_MSR_RW ); }/* I/O access bitmap. */
@@ -1358,8 +1354,6 @@ static int construct_vmcs(struct vcpu *v)__vmwrite (HOST_PAT ,XEN_MSR_PAT );__vmwrite (GUEST_PAT ,MSR_IA32_CR_PAT_RESET ); } -if ( cpu_has_vmx_mpx ) -__vmwrite (GUEST_BNDCFGS ,0 );if ( cpu_has_vmx_xsaves )__vmwrite (XSS_EXIT_BITMAP ,0 );
@@ -2032,9 +2026,8 @@ void vmcs_dump_vcpu(struct vcpu *v) vmr32(GUEST_PREEMPTION_TIMER), vmr32(GUEST_SMBASE));printk ("DebugCtl = 0x%016lx DebugExceptions = 0x%016lx\n" ,vmr (GUEST_IA32_DEBUGCTL ),vmr (GUEST_PENDING_DBG_EXCEPTIONS )); -if ( vmentry_ctl & (VM_ENTRY_LOAD_PERF_GLOBAL_CTRL |VM_ENTRY_LOAD_BNDCFGS ) ) -printk ("PerfGlobCtl = 0x%016lx BndCfgS = 0x%016lx\n" , -vmr (GUEST_PERF_GLOBAL_CTRL ),vmr (GUEST_BNDCFGS )); +if ( vmentry_ctl &VM_ENTRY_LOAD_PERF_GLOBAL_CTRL ) +printk ("PerfGlobCtl = 0x%016lx\n" ,vmr (GUEST_PERF_GLOBAL_CTRL ));printk ("Interruptibility = %08x ActivityState = %08x\n" ,vmr32 (GUEST_INTERRUPTIBILITY_INFO ),vmr32 (GUEST_ACTIVITY_STATE )); if ( v->arch.hvm.vmx.secondary_exec_control &
xen/arch/x86/hvm/vmx/vmx.c +0 -8
@@ -2774,10 +2774,6 @@ static uint64_t cf_check vmx_get_reg(struct vcpu *v, unsigned int reg)__vmread (SPEC_CTRL_SHADOW , &val);break ; -case MSR_IA32_BNDCFGS : -__vmread (GUEST_BNDCFGS , &val); -break ; -default :printk (XENLOG_G_ERR "%s(%pv, 0x%08x) Bad register\n" , __func__, v, reg);
@@ -2829,10 +2825,6 @@ static void cf_check vmx_set_reg(struct vcpu *v, unsigned int reg, uint64_t val)__vmwrite (SPEC_CTRL_SHADOW , val);break ; -case MSR_IA32_BNDCFGS : -__vmwrite (GUEST_BNDCFGS , val); -break ; -default :printk (XENLOG_G_ERR "%s(%pv, 0x%08x, 0x%016" PRIx64") Bad register\n" , __func__, v, reg, val);
xen/arch/x86/include/asm/hvm/vmx/vmcs.h +0 -4
@@ -401,10 +401,6 @@ extern struct vmx_caps vmx_caps;#define cpu_has_vmx_pml \ (IS_ENABLED(CONFIG_INTEL_VMX) && \ (vmx_caps.secondary_exec_control & SECONDARY_EXEC_ENABLE_PML)) -#define cpu_has_vmx_mpx \ - (IS_ENABLED(CONFIG_INTEL_VMX) && \ - (vmx_caps.vmexit_control & VM_EXIT_CLEAR_BNDCFGS) && \ - (vmx_caps.vmentry_control & VM_ENTRY_LOAD_BNDCFGS))#define cpu_has_vmx_xsaves \ (IS_ENABLED(CONFIG_INTEL_VMX) && \ (vmx_caps.secondary_exec_control & SECONDARY_EXEC_XSAVES))
xen/arch/x86/include/asm/xstate.h +1 -9
@@ -33,8 +33,7 @@ extern uint32_t mxcsr_mask;#define XSTATE_FP_SSE (X86_XCR0_X87 | X86_XCR0_SSE)#define XCNTXT_MASK (X86_XCR0_X87 | X86_XCR0_SSE | X86_XCR0_YMM | \ X86_XCR0_OPMASK | X86_XCR0_ZMM | X86_XCR0_HI_ZMM | \ - X86_XCR0_BNDREGS | X86_XCR0_BNDCSR | X86_XCR0_PKRU | \ - X86_XCR0_TILE_CFG | X86_XCR0_TILE_DATA) + X86_XCR0_PKRU | X86_XCR0_TILE_CFG | X86_XCR0_TILE_DATA)#define XSTATE_ALL (~(1ULL << 63))#define XSTATE_XSAVES_ONLY 0
@@ -84,20 +83,13 @@ struct __attribute__((aligned (64))) xsave_struct typedef typeof(((struct xsave_struct){}).fpu_sse) fpusse_t; -struct xstate_bndcsr { -uint64_t bndcfgu; -uint64_t bndstatus; -}; -/* extended state operations */ bool __must_check set_xcr0 (u64 xfeatures);uint64_t get_xcr0 (void );void set_msr_xss (u64 xss);uint64_t get_msr_xss (void ); -uint64_t read_bndcfgu (void );void xsave (struct vcpu *v,uint64_t mask);void xrstor (struct vcpu *v,uint64_t mask); -void xstate_set_init (uint64_t mask);bool xsave_enabled (const struct vcpu *v); int __must_check validate_xstate(const struct domain *d, uint64_t xcr0, uint64_t xcr0_accum,
xen/arch/x86/msr.c +2 -33
@@ -141,6 +141,7 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)case MSR_U_CET :case MSR_S_CET : case MSR_PL0_SSP ... MSR_ISST: +case MSR_IA32_BNDCFGS :case MSR_AMD64_LWP_CFG :case MSR_AMD64_LWP_CBADDR :case MSR_PPIN_CTL :
@@ -261,11 +262,6 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val) ret =guest_rdmsr_x2apic (v, msr, val);break ; -case MSR_IA32_BNDCFGS : -if ( !cp->feat.mpx )/* Implies Intel HVM only */ - goto gp_fault; - goto get_reg; -case MSR_IA32_XSS :if ( !cp->xstate.xsaves ) goto gp_fault;
@@ -443,6 +439,7 @@ int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val)case MSR_U_CET :case MSR_S_CET : case MSR_PL0_SSP ... MSR_ISST: +case MSR_IA32_BNDCFGS :case MSR_AMD64_LWP_CFG :case MSR_AMD64_LWP_CBADDR :case MSR_PPIN_CTL :
@@ -571,34 +568,6 @@ int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val) ret =guest_wrmsr_x2apic (v, msr, val);break ; -#ifdef CONFIG_HVM -case MSR_IA32_BNDCFGS : -if ( !cp->feat.mpx ||/* Implies Intel HVM only */ - !is_canonical_address (val) || (val &IA32_BNDCFGS_RESERVED ) ) - goto gp_fault; - -/* -* While MPX instructions are supposed to be gated on XCR0.BND*, let's -* nevertheless force the relevant XCR0 bits on when the feature is -* being enabled in BNDCFGS. -*/ -if ( (val &IA32_BNDCFGS_ENABLE ) && - !(v->arch.xcr0_accum & (X86_XCR0_BNDREGS |X86_XCR0_BNDCSR )) ) - { -uint64_t xcr0 =get_xcr0 (); - -if ( v != curr || -handle_xsetbv (XCR_XFEATURE_ENABLED_MASK , - xcr0 |X86_XCR0_BNDREGS |X86_XCR0_BNDCSR ) ) - goto gp_fault; - -if (handle_xsetbv (XCR_XFEATURE_ENABLED_MASK , xcr0) ) -/* nothing, best effort only */ ; - } - - goto set_reg; -#endif /* CONFIG_HVM */ -case MSR_IA32_XSS :if ( !cp->xstate.xsaves ) goto gp_fault;
xen/arch/x86/x86_emulate/private.h +0 -1
@@ -574,7 +574,6 @@ amd_like(const struct x86_emulate_ctxt *ctxt)#define vcpu_has_bmi2 () (ctxt->cpuid->feat.bmi2)#define vcpu_has_invpcid () (ctxt->cpuid->feat.invpcid)#define vcpu_has_rtm () (ctxt->cpuid->feat.rtm) -#define vcpu_has_mpx () (ctxt->cpuid->feat.mpx)#define vcpu_has_avx512f () (ctxt->cpuid->feat.avx512f)#define vcpu_has_avx512dq () (ctxt->cpuid->feat.avx512dq)#define vcpu_has_rdseed () (ctxt->cpuid->feat.rdseed)
xen/arch/x86/x86_emulate/x86_emulate.c +0 -51
105 lines not on this page · raw message
xen/arch/x86/xstate.c +1 -77
94 lines not on this page · raw message
xen/include/public/arch-x86/cpufeatureset.h +1 -1
@@ -199,7 +199,7 @@ XEN_CPUFEATURE(INVPCID, 5*32+10) /*H Invalidate Process Context ID */ XEN_CPUFEATURE(RTM, 5*32+11) /*!A Restricted Transactional Memory */ XEN_CPUFEATURE(PQM, 5*32+12) /* Platform QoS Monitoring */ XEN_CPUFEATURE(NO_FPU_SEL, 5*32+13) /*! FPU CS/DS stored as zero */ -XEN_CPUFEATURE(MPX, 5*32+14) /*s Memory Protection Extensions */ +XEN_CPUFEATURE(MPX, 5*32+14) /* Memory Protection Extensions */ XEN_CPUFEATURE(PQE, 5*32+15) /* Platform QoS Enforcement */ XEN_CPUFEATURE(AVX512F, 5*32+16) /*A AVX-512 Foundation Instructions */XEN_CPUFEATURE (AVX512DQ ,5 *32 +17 )/*A AVX-512 Doubleword & Quadword Instrs */
base-commit: 0f5037b465b647428b66ba2d413f44315d5b97d0
Signature · 1 line
2.39.5
Le 02/12/2026 à 17:48, Andrew Cooper a écrit :
Quoted 14 lines
Intel dropped MPX from hardware starting in 2019. GCC 9.1 (the same year) dropped support, as did Linux 5.6 (2020). Xen ceased offering MPX to VMs by default in 4.14 (also 2020).
Aside from the substantial performance hit when turned on, and the hardware spilling mechanism being incompatible with C (i.e. the primary target for additional bounds checking), one problem with MPX is that the BNDCFGU register cannot be accessed by anything except XSAVE instructions.
The emulator needing to adjust BNDCFGU places a burden on Xen's XSAVE code, and on the forthcoming ASI series. The time has come to get rid of it fully, which also allows us to stop allocating an XSTATE buffer for the idle vCPUs, for which the emulator's MPX handling was the only user.
Quoted 7 lines
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
CC: George Dunlap <[email protected]>
---
(...)
xsave.c still has some logic related to MPX
if ( cpu_has_mpx )
check_new_xstate(&s, X86_XCR0_BNDCSR | X86_XCR0_BNDREGS);
Is it intended or should we drop it as well ?
Aside this : Reviewed-by: Teddy Astie <[email protected]>
Teddy
Quoted 31 lines · Teddy Astie
Le 02/12/2026 à 17:48, Andrew Cooper a écrit :
Quoted 22 lines
Intel dropped MPX from hardware starting in 2019. GCC 9.1 (the same year)
dropped support, as did Linux 5.6 (2020). Xen ceased offering MPX to VMs by
default in 4.14 (also 2020).Aside from the substantial performance hit when turned on, and the hardware
spilling mechanism being incompatible with C (i.e. the primary target for
additional bounds checking), one problem with MPX is that the BNDCFGU register
cannot be accessed by anything except XSAVE instructions.The emulator needing to adjust BNDCFGU places a burden on Xen's XSAVE code,
and on the forthcoming ASI series. The time has come to get rid of it fully,
which also allows us to stop allocating an XSTATE buffer for the idle vCPUs,
for which the emulator's MPX handling was the only user.Quoted 7 lines
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
CC: George Dunlap <[email protected]>
---
Quoted 8 lines
(...)
xsave.cstill has some logic related to MPXif (
cpu_has_mpx)
check_new_xstate(&s, X86_XCR0_BNDCSR | X86_XCR0_BNDREGS);Is it intended or should we drop it as well ?
That was intentional. The whole function is behind CONFIG_SELF_TESTS in the first place, and it's not really about MPX, it's about cross checking hardware against xstate_{un,}compressed_size().
We could drop it, but the test gets better coverage if we don't.
Quoted 2 lines
Aside this : Reviewed-by: Teddy Astie <[email protected]>
Thanks.
~Andrew
Quoted 9 lines · Andrew Cooper
Intel dropped MPX from hardware starting in 2019. GCC 9.1 (the same year) dropped support, as did Linux 5.6 (2020). Xen ceased offering MPX to VMs by default in 4.14 (also 2020).
Aside from the substantial performance hit when turned on, and the hardware spilling mechanism being incompatible with C (i.e. the primary target for additional bounds checking), one problem with MPX is that the BNDCFGU register cannot be accessed by anything except XSAVE instructions.
Quoted 6 lines
The emulator needing to adjust BNDCFGU places a burden on Xen's XSAVE code, and on the forthcoming ASI series. The time has come to get rid of it fully, which also allows us to stop allocating an XSTATE buffer for the idle vCPUs, for which the emulator's MPX handling was the only user.
Signed-off-by Andrew Cooper <[email protected]>