From: Paul Durrant <paul.durrant@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: "Kevin Tian" <kevin.tian@intel.com>,
"Wei Liu" <wei.liu2@citrix.com>,
"Jun Nakajima" <jun.nakajima@intel.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Paul Durrant" <paul.durrant@citrix.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH v4 1/4] x86: stop handling MSR_IA32_BNDCFGS save/restore in implementation code
Date: Thu, 14 Mar 2019 13:51:22 +0000 [thread overview]
Message-ID: <20190314135125.1958-2-paul.durrant@citrix.com> (raw)
In-Reply-To: <20190314135125.1958-1-paul.durrant@citrix.com>
Saving and restoring the value of this MSR is currently handled by
implementation-specific code despite it being architectural. This patch
moves handling of accesses to this MSR from hvm.c into the msr.c, thus
allowing the common MSR save/restore code to handle it.
NOTE: Because vmx_get/set_guest_bndcfgs() call vmx_vmcs_enter(), the
struct vcpu pointer passed in, and hence the vcpu pointer passed to
guest_rdmsr() cannot be const.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
---
Cc: Kevin Tian <kevin.tian@intel.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Cc: "Roger Pau Monné" <roger.pau@citrix.com>
Cc: Jun Nakajima <jun.nakajima@intel.com>
v4:
- Cosmetic re-arrangements and an additional ASSERT requested by Jan
v3:
- Address further comments from Jan
- Dropped Kevin's R-b because of change to vmx.c
v2:
- Addressed comments from Jan by largely removing hunks
- Keeping Kevin's R-b since remaining hunks in vmx.c are as before
---
xen/arch/x86/hvm/hvm.c | 14 ++------------
xen/arch/x86/hvm/vmx/vmx.c | 24 ++++--------------------
xen/arch/x86/msr.c | 20 ++++++++++++++++++++
xen/include/asm-x86/hvm/hvm.h | 4 ++--
4 files changed, 28 insertions(+), 34 deletions(-)
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 8adbb61b57..e566d83f8b 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -1303,6 +1303,7 @@ static int hvm_load_cpu_xsave_states(struct domain *d, hvm_domain_context_t *h)
static const uint32_t msrs_to_send[] = {
MSR_SPEC_CTRL,
MSR_INTEL_MISC_FEATURES_ENABLES,
+ MSR_IA32_BNDCFGS,
MSR_AMD64_DR0_ADDRESS_MASK,
MSR_AMD64_DR1_ADDRESS_MASK,
MSR_AMD64_DR2_ADDRESS_MASK,
@@ -1440,6 +1441,7 @@ static int hvm_load_cpu_msrs(struct domain *d, hvm_domain_context_t *h)
case MSR_SPEC_CTRL:
case MSR_INTEL_MISC_FEATURES_ENABLES:
+ case MSR_IA32_BNDCFGS:
case MSR_AMD64_DR0_ADDRESS_MASK:
case MSR_AMD64_DR1_ADDRESS_MASK ... MSR_AMD64_DR3_ADDRESS_MASK:
rc = guest_wrmsr(v, ctxt->msr[i].index, ctxt->msr[i].val);
@@ -3467,12 +3469,6 @@ int hvm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
*msr_content = v->arch.hvm.msr_xss;
break;
- case MSR_IA32_BNDCFGS:
- if ( !d->arch.cpuid->feat.mpx ||
- !hvm_get_guest_bndcfgs(v, msr_content) )
- goto gp_fault;
- break;
-
case MSR_K8_ENABLE_C1E:
case MSR_AMD64_NB_CFG:
/*
@@ -3619,12 +3615,6 @@ int hvm_msr_write_intercept(unsigned int msr, uint64_t msr_content,
v->arch.hvm.msr_xss = msr_content;
break;
- case MSR_IA32_BNDCFGS:
- if ( !d->arch.cpuid->feat.mpx ||
- !hvm_set_guest_bndcfgs(v, msr_content) )
- goto gp_fault;
- break;
-
case MSR_AMD64_NB_CFG:
/* ignore the write */
break;
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index 725dd88c13..f8481d032a 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -805,17 +805,6 @@ static unsigned int __init vmx_init_msr(void)
static void vmx_save_msr(struct vcpu *v, struct hvm_msr *ctxt)
{
- vmx_vmcs_enter(v);
-
- if ( cpu_has_mpx && cpu_has_vmx_mpx )
- {
- __vmread(GUEST_BNDCFGS, &ctxt->msr[ctxt->count].val);
- if ( ctxt->msr[ctxt->count].val )
- ctxt->msr[ctxt->count++].index = MSR_IA32_BNDCFGS;
- }
-
- vmx_vmcs_exit(v);
-
if ( cpu_has_xsaves && cpu_has_vmx_xsaves )
{
ctxt->msr[ctxt->count].val = v->arch.hvm.msr_xss;
@@ -835,14 +824,6 @@ static int vmx_load_msr(struct vcpu *v, struct hvm_msr *ctxt)
{
switch ( ctxt->msr[i].index )
{
- case MSR_IA32_BNDCFGS:
- if ( cpu_has_mpx && cpu_has_vmx_mpx &&
- is_canonical_address(ctxt->msr[i].val) &&
- !(ctxt->msr[i].val & IA32_BNDCFGS_RESERVED) )
- __vmwrite(GUEST_BNDCFGS, ctxt->msr[i].val);
- else if ( ctxt->msr[i].val )
- err = -ENXIO;
- break;
case MSR_IA32_XSS:
if ( cpu_has_xsaves && cpu_has_vmx_xsaves )
v->arch.hvm.msr_xss = ctxt->msr[i].val;
@@ -1215,8 +1196,11 @@ static bool vmx_set_guest_bndcfgs(struct vcpu *v, u64 val)
return true;
}
-static bool vmx_get_guest_bndcfgs(struct vcpu *v, u64 *val)
+static bool vmx_get_guest_bndcfgs(const struct vcpu *cv, u64 *val)
{
+ /* Get a non-const pointer for vmx_vmcs_enter() */
+ struct vcpu *v = cv->domain->vcpu[cv->vcpu_id];
+
ASSERT(cpu_has_mpx && cpu_has_vmx_mpx);
vmx_vmcs_enter(v);
diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 4df4a59f4d..0e901d2397 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -160,6 +160,16 @@ int guest_rdmsr(const 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 )
+ goto gp_fault;
+
+ ASSERT(is_hvm_domain(d));
+ if (!hvm_get_guest_bndcfgs(v, val) )
+ goto gp_fault;
+
+ break;
+
case 0x40000000 ... 0x400001ff:
if ( is_viridian_domain(d) )
{
@@ -323,6 +333,16 @@ int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val)
ret = guest_wrmsr_x2apic(v, msr, val);
break;
+ case MSR_IA32_BNDCFGS:
+ if ( !cp->feat.mpx )
+ goto gp_fault;
+
+ ASSERT(is_hvm_domain(d));
+ if ( !hvm_set_guest_bndcfgs(v, val) )
+ goto gp_fault;
+
+ break;
+
case 0x40000000 ... 0x400001ff:
if ( is_viridian_domain(d) )
{
diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h
index 53ffebb2c5..d41ed63232 100644
--- a/xen/include/asm-x86/hvm/hvm.h
+++ b/xen/include/asm-x86/hvm/hvm.h
@@ -149,7 +149,7 @@ struct hvm_function_table {
int (*get_guest_pat)(struct vcpu *v, u64 *);
int (*set_guest_pat)(struct vcpu *v, u64);
- bool (*get_guest_bndcfgs)(struct vcpu *v, u64 *);
+ bool (*get_guest_bndcfgs)(const struct vcpu *v, u64 *);
bool (*set_guest_bndcfgs)(struct vcpu *v, u64);
void (*set_tsc_offset)(struct vcpu *v, u64 offset, u64 at_tsc);
@@ -448,7 +448,7 @@ static inline unsigned long hvm_get_shadow_gs_base(struct vcpu *v)
return hvm_funcs.get_shadow_gs_base(v);
}
-static inline bool hvm_get_guest_bndcfgs(struct vcpu *v, u64 *val)
+static inline bool hvm_get_guest_bndcfgs(const struct vcpu *v, u64 *val)
{
return hvm_funcs.get_guest_bndcfgs &&
hvm_funcs.get_guest_bndcfgs(v, val);
--
2.20.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2019-03-14 13:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-14 13:51 [PATCH v4 0/4] clean up MSR save/restore code Paul Durrant
2019-03-14 13:51 ` Paul Durrant [this message]
2019-03-14 14:23 ` [PATCH v4 1/4] x86: stop handling MSR_IA32_BNDCFGS save/restore in implementation code Jan Beulich
2019-04-05 11:29 ` Jan Beulich
2019-04-05 11:29 ` [Xen-devel] " Jan Beulich
2019-04-09 3:10 ` Tian, Kevin
2019-04-09 3:10 ` [Xen-devel] " Tian, Kevin
2019-04-09 14:38 ` Andrew Cooper
2019-04-09 14:38 ` [Xen-devel] " Andrew Cooper
2019-04-09 15:03 ` Jan Beulich
2019-04-09 15:03 ` [Xen-devel] " Jan Beulich
2019-03-14 13:51 ` [PATCH v4 2/4] x86: move the saved value of MSR_IA32_XSS into struct vcpu_msrs Paul Durrant
2019-03-14 13:51 ` [PATCH v4 3/4] x86: stop handling MSR_IA32_XSS save/restore in implementation code Paul Durrant
2019-03-14 13:51 ` [PATCH v4 4/4] x86: remove defunct init/load/save_msr() hvm_funcs Paul Durrant
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190314135125.1958-2-paul.durrant@citrix.com \
--to=paul.durrant@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=jun.nakajima@intel.com \
--cc=kevin.tian@intel.com \
--cc=roger.pau@citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).