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 3/4] x86: stop handling MSR_IA32_XSS save/restore in implementation code
Date: Thu, 14 Mar 2019 13:51:24 +0000 [thread overview]
Message-ID: <20190314135125.1958-4-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.
This patch also adds proper checks of CPUID policy in the new get/set code.
NOTE: MSR_IA32_XSS is the last MSR to be saved and restored by
implementation-specific code. This patch therefore removes the
(VMX) definitions and of the init_msr(), save_msr() and
load_msr() hvm_funcs, as they are no longer necessary. The
declarations of and calls to those hvm_funcs will be cleaned up
by a subsequent patch.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.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>
---
xen/arch/x86/hvm/hvm.c | 15 ++----------
xen/arch/x86/hvm/vmx/vmx.c | 49 --------------------------------------
xen/arch/x86/msr.c | 18 ++++++++++++++
3 files changed, 20 insertions(+), 62 deletions(-)
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index dff590e658..deb7fb2adb 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -1304,6 +1304,7 @@ static const uint32_t msrs_to_send[] = {
MSR_SPEC_CTRL,
MSR_INTEL_MISC_FEATURES_ENABLES,
MSR_IA32_BNDCFGS,
+ MSR_IA32_XSS,
MSR_AMD64_DR0_ADDRESS_MASK,
MSR_AMD64_DR1_ADDRESS_MASK,
MSR_AMD64_DR2_ADDRESS_MASK,
@@ -1442,6 +1443,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_IA32_XSS:
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);
@@ -3463,12 +3465,6 @@ int hvm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
MTRRcap_VCNT))];
break;
- case MSR_IA32_XSS:
- if ( !d->arch.cpuid->xstate.xsaves )
- goto gp_fault;
- *msr_content = v->arch.msrs->xss.raw;
- break;
-
case MSR_K8_ENABLE_C1E:
case MSR_AMD64_NB_CFG:
/*
@@ -3608,13 +3604,6 @@ int hvm_msr_write_intercept(unsigned int msr, uint64_t msr_content,
goto gp_fault;
break;
- case MSR_IA32_XSS:
- /* No XSS features currently supported for guests. */
- if ( !d->arch.cpuid->xstate.xsaves || msr_content != 0 )
- goto gp_fault;
- v->arch.msrs->xss.raw = msr_content;
- 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 985e5735d2..c46e05b91e 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -797,52 +797,6 @@ static int vmx_load_vmcs_ctxt(struct vcpu *v, struct hvm_hw_cpu *ctxt)
return 0;
}
-static unsigned int __init vmx_init_msr(void)
-{
- return (cpu_has_mpx && cpu_has_vmx_mpx) +
- (cpu_has_xsaves && cpu_has_vmx_xsaves);
-}
-
-static void vmx_save_msr(struct vcpu *v, struct hvm_msr *ctxt)
-{
- if ( cpu_has_xsaves && cpu_has_vmx_xsaves )
- {
- ctxt->msr[ctxt->count].val = v->arch.msrs->xss.raw;
- if ( ctxt->msr[ctxt->count].val )
- ctxt->msr[ctxt->count++].index = MSR_IA32_XSS;
- }
-}
-
-static int vmx_load_msr(struct vcpu *v, struct hvm_msr *ctxt)
-{
- unsigned int i;
- int err = 0;
-
- vmx_vmcs_enter(v);
-
- for ( i = 0; i < ctxt->count; ++i )
- {
- switch ( ctxt->msr[i].index )
- {
- case MSR_IA32_XSS:
- if ( cpu_has_xsaves && cpu_has_vmx_xsaves )
- v->arch.msrs->xss.raw = ctxt->msr[i].val;
- else
- err = -ENXIO;
- break;
- default:
- continue;
- }
- if ( err )
- break;
- ctxt->msr[i]._rsvd = 1;
- }
-
- vmx_vmcs_exit(v);
-
- return err;
-}
-
static void vmx_fpu_enter(struct vcpu *v)
{
vcpu_restore_fpu_lazy(v);
@@ -2282,9 +2236,6 @@ static struct hvm_function_table __initdata vmx_function_table = {
.vcpu_destroy = vmx_vcpu_destroy,
.save_cpu_ctxt = vmx_save_vmcs_ctxt,
.load_cpu_ctxt = vmx_load_vmcs_ctxt,
- .init_msr = vmx_init_msr,
- .save_msr = vmx_save_msr,
- .load_msr = vmx_load_msr,
.get_interrupt_shadow = vmx_get_interrupt_shadow,
.set_interrupt_shadow = vmx_set_interrupt_shadow,
.guest_x86_mode = vmx_guest_x86_mode,
diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 0e901d2397..4b5e000224 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -170,6 +170,13 @@ int guest_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val)
break;
+ case MSR_IA32_XSS:
+ if ( !cp->xstate.xsaves )
+ goto gp_fault;
+
+ *val = msrs->xss.raw;
+ break;
+
case 0x40000000 ... 0x400001ff:
if ( is_viridian_domain(d) )
{
@@ -343,6 +350,17 @@ int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val)
break;
+ case MSR_IA32_XSS:
+ if ( !cp->xstate.xsaves )
+ goto gp_fault;
+
+ /* No XSS features currently supported for guests */
+ if ( val != 0 )
+ goto gp_fault;
+
+ msrs->xss.raw = val;
+ break;
+
case 0x40000000 ... 0x400001ff:
if ( is_viridian_domain(d) )
{
--
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 ` [PATCH v4 1/4] x86: stop handling MSR_IA32_BNDCFGS save/restore in implementation code Paul Durrant
2019-03-14 14:23 ` 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 ` Paul Durrant [this message]
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-4-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).