Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42B64606A31A for ; Wed, 2 Dec 2026 16:48:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=citrix.com header.i=@citrix.com header.a=rsa-sha256 header.s=google header.b=RUQtIaL1 Received: from list by lists.xenproject.org with outflank-mailman.1510790.1703405 (Exim 4.92) (envelope-from ) id 1xYnUz-0001jF-2l; Wed, 02 Dec 2026 16:48:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1510790.1703405; Wed, 02 Dec 2026 16:48:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xYnUy-0001j8-Vu; Wed, 02 Dec 2026 16:48:04 +0000 Received: by outflank-mailman (input) for mailman id 1510790; Wed, 02 Dec 2026 16:48:03 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xYnUx-0001fM-Ge for xen-devel@lists.xenproject.org; Wed, 02 Dec 2026 16:48:03 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xYnUw-009LoL-T7 for xen-devel@lists.xenproject.org; Wed, 02 Dec 2026 17:48:02 +0100 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6b104ba5-e002-0a2a0a5209dd-0a2a4504a886-32 for ; Wed, 02 Dec 2026 17:48:02 +0100 Received: from [209.85.221.42] (helo=mail-wr1-f42.google.com) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6b104bc2-b57f-0a2a45040019-d155dd2ae8e3-3 for ; Wed, 02 Dec 2026 17:48:02 +0100 Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-48e09aa5264so7719734f8f.2 for ; Wed, 02 Dec 2026 08:48:02 -0800 (PST) Received: from localhost.localdomain (host-78-146-248-75.as13285.net. [78.146.248.75]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6baa3c4dsm66162330f8f.46.2026.12.02.08.48.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 08:48:01 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Post: List-Help: List-Subscribe: , Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=citrix.com header.i="@citrix.com" header.h="Content-Transfer-Encoding:Content-Type:MIME-Version:Message-Id:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1796230082; x=1796834882; darn=lists.xenproject.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=aYzmdJYKKbxDIyxyfh16iNHevBxzVAFm3Go9mWocJq8=; b=RUQtIaL1+/0Ui8aj0OiewxYPNWbSk7vE1nXJx9JO6TndTfEfKOQAgnsco91aUINhTM +Eu69EUsK0qxxXzFGD/M36SEIKkC+N/V6juiqRGno1qmYYMzVjo/yWdrGgBci2oVaIv5 x903CoK4AnMvEtlkZ5sBjBC7Kc6fBHNdXi9as= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796230082; x=1796834882; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=aYzmdJYKKbxDIyxyfh16iNHevBxzVAFm3Go9mWocJq8=; b=dxu9OS+wEbBoIQ1cSFgqZIkJGCcU2647siLNQ3t2usYYpdS54XlJYaTlZkACJgeYyU yNMTn5/RHPYc0Wwh935e/OVjY0nSE3ThWr6KWJeQ2wZ/AWloTpmBd364g5c6Md8pZu4+ UkjoHMgoZCX7POVz3u3oNI18wM99A9Og2WQFtQ2UD8DXr6AFIOUgys3V/lkhXiBvMeNc W2yqbRVVSKaGs4eiXcHQUGaL+F3uEV5OzsWh7cO9ETRrrWeWke5q41YhQWQf7Ritgdcq YBK7Ct4TsGcqKcg8U960PYE/oM2JCJcLSCedpwmG9cShv7P2386Fj4WO9V/dqAaWcPbu 12yg== X-Gm-Message-State: APuU4Z9LZzoPTHG2rWSFGEBkkNyUYjXxUQfBdZWxRssHyqMAiulb+/Hk Uu/fVvrajqpgStNdAF5nyzT1doLn24GEF0GxHgh6FHyUVCHtiySVEPa2uqtWIf/nzaXxlMaYCNi HPhdH X-Gm-Gg: AZFdTZcjD3iauO1HabXFZZdrnAV62g97oOGi5FxTM4rEQzcj7ET3+c5rGFzEaq+1M1G q1sb0Ad1sN6X3VhdG6tyZs3mXRR/WvaUcw2/ctm9UthrpAPSDyJ6mtJl/1ZMd1QtIFQ7vLGOdl3 A6/QtHMauImMIM1eEY9POYEpb9QOS4zxHYWeuVjNFOkWGSq/+jsNlq9ld14SIKTQpM8PzfHMCo6 tOwThTZb37F2LcyPf7N86Jvuqfps5jwSvF/8GV+0XwOCcJJBsN6xAmvaIO2dAs1lVyVP0d5Oddq +hbQ7xfGu8U9hCjnChbIMk+tgA8tXFrOAk4HfRfvWSxVVc7X7Tg4zMxMvuls04W+vyRqWkcVzjM OZV/KTQgG0121dL0vnffaqY1Qu1i/o4w/pcRbER5OjNhph4t10JxLvnvFj9crPeQTsT+r4sIWW7 ryXM0tMygvjkBPRIH65aQ4Xi+FhDeuK6PEOku3IxTnQ3FO0RNSXvxRoncQX4wKTJhl/LUHXT81P QyO/gY/dPRvGSGYdFeNelJ29VoaUM4eaT5oPG7fIgTgn56Lq/Kxcn+RpkOz4XyHpJBmvN7yumRf zbVnhbZWKcAqd87dADaLSCaD0jui1NejRHglh6OsVEOk8rWIJEJl9iKGz41rreDr6tBT8XUSn02 pL3Q= X-Received: by 2002:a05:6000:613:b0:498:88f:14c8 with SMTP id ffacd0b85a97d-4abb0f3bc7emr88201344f8f.9.1796230081684; Wed, 02 Dec 2026 08:48:01 -0800 (PST) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , George Dunlap Subject: [PATCH] x86: Fully remove MPX support Date: Wed, 2 Dec 2026 16:47:59 +0000 Message-Id: <20261202164759.1007512-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.5 X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-purgate-ID: tlsNG-ebf023/1796230082-C26CAB50-83483A9E/0/0 X-purgate-type: clean X-purgate-size: 22868 X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Roger Pau Monné CC: Teddy Astie CC: George Dunlap --- 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(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f967437eda0f..fcbc973ef17b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c index 0db6d77cd801..7c1e2ca9aae8 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -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); diff --git a/xen/arch/x86/cpu-policy.c b/xen/arch/x86/cpu-policy.c index e797585528d0..0798291a2873 100644 --- a/xen/arch/x86/cpu-policy.c +++ b/xen/arch/x86/cpu-policy.c @@ -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); } diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 2407c575d9fb..97629f734089 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -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); diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 95247e772d09..8efaa18a1394 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -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: diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 8ec7ae7403ca..2508d57fc128 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -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 & diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index a5c68b5b53f7..6d2bddc3f8b7 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -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); diff --git a/xen/arch/x86/include/asm/hvm/vmx/vmcs.h b/xen/arch/x86/include/asm/hvm/vmx/vmcs.h index d0716e97d25c..0bf97733cdb6 100644 --- a/xen/arch/x86/include/asm/hvm/vmx/vmcs.h +++ b/xen/arch/x86/include/asm/hvm/vmx/vmcs.h @@ -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)) diff --git a/xen/arch/x86/include/asm/xstate.h b/xen/arch/x86/include/asm/xstate.h index 0519379edb57..dc0cd46f92dd 100644 --- a/xen/arch/x86/include/asm/xstate.h +++ b/xen/arch/x86/include/asm/xstate.h @@ -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, diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c index e9fa02a03f71..3d906384b319 100644 --- a/xen/arch/x86/msr.c +++ b/xen/arch/x86/msr.c @@ -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; diff --git a/xen/arch/x86/x86_emulate/private.h b/xen/arch/x86/x86_emulate/private.h index ff0f3eba0e72..4dd3f74ae343 100644 --- a/xen/arch/x86/x86_emulate/private.h +++ b/xen/arch/x86/x86_emulate/private.h @@ -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) diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c b/xen/arch/x86/x86_emulate/x86_emulate.c index 20d90904b5f7..284bc4a579b4 100644 --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -35,9 +35,6 @@ }) # define cpu_has_amd_erratum(nr) 0 -# define cpu_has_mpx false -# define read_bndcfgu() 0 -# define xstate_set_init(what) /* For generic assembly code: use macros to define operation/operand sizes. */ # ifdef __i386__ @@ -1234,46 +1231,6 @@ static bool is_branch_step(struct x86_emulate_ctxt *ctxt, return debugctl & IA32_DEBUGCTLMSR_BTF; } -static void adjust_bnd(struct x86_emulate_ctxt *ctxt, - const struct x86_emulate_ops *ops, enum vex_pfx pfx) -{ - uint64_t xcr0, bndcfg; - int rc; - - if ( pfx == vex_f2 || !cpu_has_mpx || !vcpu_has_mpx() ) - return; - - if ( !ops->read_xcr || ops->read_xcr(0, &xcr0, ctxt) != X86EMUL_OKAY || - !(xcr0 & X86_XCR0_BNDREGS) || !(xcr0 & X86_XCR0_BNDCSR) ) - { - ASSERT(!ctxt->event_pending); - return; - } - - if ( !mode_ring0() ) - bndcfg = read_bndcfgu(); - else if ( !ops->read_msr || - (rc = ops->read_msr(MSR_IA32_BNDCFGS, &bndcfg, - ctxt)) != X86EMUL_OKAY ) - { - if ( rc == X86EMUL_EXCEPTION ) - x86_emul_reset_event(ctxt); - return; - } - if ( (bndcfg & IA32_BNDCFGS_ENABLE) && !(bndcfg & IA32_BNDCFGS_PRESERVE) ) - { - /* - * Using BNDMK or any other MPX instruction here is pointless, as - * we run with MPX disabled ourselves, and hence they're all no-ops. - * Therefore we have two ways to clear BNDn: Enable MPX temporarily - * (in which case executing any suitable non-prefixed branch - * instruction would do), or use XRSTOR. - */ - xstate_set_init(X86_XCR0_BNDREGS); - } - done:; -} - int cf_check x86emul_unhandleable_rw( enum x86_segment seg, unsigned long offset, @@ -1952,7 +1909,6 @@ x86_emulate( case 0x70 ... 0x7f: /* jcc (short) */ if ( test_cc(b, _regs.eflags) ) jmp_rel((int32_t)src.val); - adjust_bnd(ctxt, ops, vex.pfx); break; case 0x80: case 0x81: case 0x82: case 0x83: /* Grp1 */ @@ -2363,7 +2319,6 @@ x86_emulate( (rc = ops->insn_fetch(dst.val, NULL, 0, ctxt)) ) goto done; _regs.r(ip) = dst.val; - adjust_bnd(ctxt, ops, vex.pfx); break; case 0xc4: /* les */ @@ -2596,15 +2551,12 @@ x86_emulate( op_bytes = ((op_bytes == 4) && mode_64bit()) ? 8 : op_bytes; src.val = _regs.r(ip); jmp_rel(rel); - adjust_bnd(ctxt, ops, vex.pfx); goto push; } case 0xe9: /* jmp (near) */ case 0xeb: /* jmp (short) */ jmp_rel((int32_t)src.val); - if ( !(b & 2) ) - adjust_bnd(ctxt, ops, vex.pfx); break; case 0xea: /* jmp (far, absolute) */ @@ -2887,14 +2839,12 @@ x86_emulate( goto done; _regs.r(ip) = src.val; src.val = dst.val; - adjust_bnd(ctxt, ops, vex.pfx); goto push; case 4: /* jmp (near) */ if ( (rc = ops->insn_fetch(src.val, NULL, 0, ctxt)) ) goto done; _regs.r(ip) = src.val; dst.type = OP_NONE; - adjust_bnd(ctxt, ops, vex.pfx); break; case 3: /* call (far, absolute indirect) */ case 5: /* jmp (far, absolute indirect) */ @@ -4983,7 +4933,6 @@ x86_emulate( case X86EMUL_OPC(0x0f, 0x80) ... X86EMUL_OPC(0x0f, 0x8f): /* jcc (near) */ if ( test_cc(b, _regs.eflags) ) jmp_rel((int32_t)src.val); - adjust_bnd(ctxt, ops, vex.pfx); break; case X86EMUL_OPC(0x0f, 0x90) ... X86EMUL_OPC(0x0f, 0x9f): /* setcc */ diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c index 9b7a9eec7df0..2a34fbd2e880 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -524,24 +524,11 @@ int xstate_alloc_save_area(struct vcpu *v) */ size = XSTATE_AREA_MIN_SIZE; } - else if ( !is_idle_vcpu(v) || !cpu_has_xsavec ) + else { size = xsave_cntxt_size; BUG_ON(size < XSTATE_AREA_MIN_SIZE); } - else - { - /* - * For idle vcpus on XSAVEC-capable CPUs allocate an area large - * enough to save any individual extended state. - */ - unsigned int i; - - for ( size = 0, i = 2; i < xstate_features; ++i ) - if ( size < xstate_sizes[i] ) - size = xstate_sizes[i]; - size += XSTATE_AREA_MIN_SIZE; - } /* XSAVE/XRSTOR requires the save area be 64-byte-boundary aligned. */ BUILD_BUG_ON(__alignof(*save_area) < 64); @@ -1021,69 +1008,6 @@ int handle_xsetbv(u32 index, u64 new_bv) return 0; } -uint64_t read_bndcfgu(void) -{ - unsigned long cr0 = read_cr0(); - struct xsave_struct *xstate - = idle_vcpu[smp_processor_id()]->arch.xsave_area; - const struct xstate_bndcsr *bndcsr; - - ASSERT(cpu_has_mpx); - clts(); - - if ( cpu_has_xsavec ) - { - asm ( ".byte 0x0f,0xc7,0x27\n" /* xsavec */ - : "=m" (*xstate) - : "a" (X86_XCR0_BNDCSR), "d" (0), "D" (xstate) ); - - bndcsr = (void *)(xstate + 1); - } - else - { - asm ( ".byte 0x0f,0xae,0x27\n" /* xsave */ - : "=m" (*xstate) - : "a" (X86_XCR0_BNDCSR), "d" (0), "D" (xstate) ); - - bndcsr = (void *)xstate + xstate_offsets[ilog2(X86_XCR0_BNDCSR)]; - } - - if ( cr0 & X86_CR0_TS ) - write_cr0(cr0); - - return xstate->xsave_hdr.xstate_bv & X86_XCR0_BNDCSR ? bndcsr->bndcfgu : 0; -} - -void xstate_set_init(uint64_t mask) -{ - unsigned long cr0 = read_cr0(); - unsigned long xcr0 = this_cpu(xcr0); - struct vcpu *v = idle_vcpu[smp_processor_id()]; - struct xsave_struct *xstate; - - if ( ~xfeature_mask & mask ) - { - ASSERT_UNREACHABLE(); - return; - } - - if ( (~xcr0 & mask) && !set_xcr0(xcr0 | mask) ) - return; - - clts(); - - xstate = VCPU_MAP_XSAVE_AREA(v); - memset(&xstate->xsave_hdr, 0, sizeof(xstate->xsave_hdr)); - xrstor(v, mask); - VCPU_UNMAP_XSAVE_AREA(v, xstate); - - if ( cr0 & X86_CR0_TS ) - write_cr0(cr0); - - if ( (~xcr0 & mask) && !set_xcr0(xcr0) ) - BUG(); -} - /* * Local variables: * mode: C diff --git a/xen/include/public/arch-x86/cpufeatureset.h b/xen/include/public/arch-x86/cpufeatureset.h index fb65548381ab..465aa9e65a1e 100644 --- a/xen/include/public/arch-x86/cpufeatureset.h +++ b/xen/include/public/arch-x86/cpufeatureset.h @@ -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 -- 2.39.5