Skip to contentSkip to conversation

clean up MSR save/restore code

PATCH Superseded Paul Durrant 2 participants 9 messages Mar 11, 2019 – Mar 14, 2019

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover clean up MSR save/restore code

Paul Durrant (4):
x86: stop handling MSR_IA32_BNDCFGS save/restore in implementation
code
x86: move the saved value of MSR_IA32_XSS into struct vcpu_msrs
x86: stop handling MSR_IA32_XSS save/restore in implementation code
x86: remove defunct init/load/save_msr() hvm_funcs

 xen/arch/x86/domain.c          |  2 +-
 xen/arch/x86/hvm/hvm.c         | 58 +++++++----------------------
 xen/arch/x86/hvm/vmx/vmx.c     | 68 ----------------------------------
 xen/arch/x86/msr.c             | 34 ++++++++++++++++-
 xen/arch/x86/pv/emul-priv-op.c |  2 +-
 xen/include/asm-x86/hvm/hvm.h  |  4 --
 xen/include/asm-x86/hvm/vcpu.h |  1 -
 xen/include/asm-x86/msr.h      |  7 +++-
 8 files changed, 54 insertions(+), 122 deletions(-)

---
v2:
- Drop patches #2 and #6 of the v1 series

Cc Andrew Cooper <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Jun Nakajima <[email protected]>
Cc Kevin Tian <[email protected]>
Cc "Roger Pau Monné" <[email protected]>
Cc Wei Liu <[email protected]>
Signature · 7 lines
2.20.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH v2 1/4 x86: stop handling MSR_IA32_BNDCFGS save/restore in implementation code

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.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: Jun Nakajima <[email protected]>

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     | 19 -------------------
 xen/arch/x86/msr.c             | 16 +++++++++++++++-
 xen/arch/x86/pv/emul-priv-op.c |  2 +-
 xen/include/asm-x86/msr.h      |  2 +-
 5 files changed, 19 insertions(+), 34 deletions(-)
xen/arch/x86/hvm/hvm.c +2 -12
index 8adbb61b57..e566d83f8b 100644
@@ -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;
xen/arch/x86/hvm/vmx/vmx.c +0 -19
index 725dd88c13..42232dbb37 100644
@@ -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;
xen/arch/x86/msr.c +15 -1
index 9bb38b6d66..3c24ee7ba3 100644
@@ -115,7 +115,7 @@ int init_vcpu_msr_policy(struct vcpu *v)
     return 0;
 }
 
-int guest_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val)
+int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)
 {
     const struct vcpu *curr = current;
     const struct domain *d = v->domain;
@@ -158,6 +158,13 @@ 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 ( !is_hvm_domain(d) || !cp->feat.mpx ||
+             !hvm_get_guest_bndcfgs(v, val) )
+            goto gp_fault;
+
+        break;
+
     case 0x40000000 ... 0x400001ff:
         if ( is_viridian_domain(d) )
         {
@@ -319,6 +326,13 @@ 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 ( !is_hvm_domain(d) || !cp->feat.mpx ||
+             !hvm_set_guest_bndcfgs(v, val) )
+            goto gp_fault;
+
+        break;
+
     case 0x40000000 ... 0x400001ff:
         if ( is_viridian_domain(d) )
         {
xen/arch/x86/pv/emul-priv-op.c +1 -1
index 3746e2ad54..0dcb7f726e 100644
@@ -819,7 +819,7 @@ static inline bool is_cpufreq_controller(const struct domain *d)
 static int read_msr(unsigned int reg, uint64_t *val,
                     struct x86_emulate_ctxt *ctxt)
 {
-    const struct vcpu *curr = current;
+    struct vcpu *curr = current;
     const struct domain *currd = curr->domain;
     bool vpmu_msr = false;
     int ret;
xen/include/asm-x86/msr.h +1 -1
index a7244793bf..c3107f8542 100644
@@ -328,7 +328,7 @@ int init_vcpu_msr_policy(struct vcpu *v);
  * These functions are also used by the migration logic, so need to cope with
  * being used outside of v's context.
  */
-int guest_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val);
+int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val);
 int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val);
 
 #endif /* !__ASSEMBLY__ */
Signature · 7 lines
2.20.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

Re: [PATCH v2 1/4] x86: stop handling MSR_IA32_BNDCFGS save/restore in implementation code

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 11.03.19 at 19:09, <[email protected]> wrote:

v2:
- Addressed comments from Jan by largely removing hunks

I think you've removed more than I was expecting, but I'm fine this way.

Quoted 15 lines
xen/arch/x86/msr.c +7 -0
@@ -158,6 +158,13 @@ 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 ( !is_hvm_domain(d) || !cp->feat.mpx ||
+             !hvm_get_guest_bndcfgs(v, val) )
+            goto gp_fault;
+
+        break;
+
     case 0x40000000 ... 0x400001ff:
         if ( is_viridian_domain(d) )
         {

xen/arch/x86/msr.c int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val) · line 332

Quoted 7 lines
xen/arch/x86/msr.c +4 -0
@@ -319,6 +326,13 @@ 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 ( !is_hvm_domain(d) || !cp->feat.mpx ||
+             !hvm_set_guest_bndcfgs(v, val) )
+            goto gp_fault;

In both cases the is_hvm_*() check looks to be redundant, as for PV guests cp->feat.mpx can't be set. Personally I'd prefer this to be an ASSERT() instead, but I'd listen to Andrew (as the main author of this code) saying otherwise.

xen/include/asm-x86/msr.h int init_vcpu_msr_policy(struct vcpu *v); · line 331

Quoted 8 lines
xen/include/asm-x86/msr.h +1 -1
@@ -328,7 +328,7 @@ int init_vcpu_msr_policy(struct vcpu *v);
  * These functions are also used by the migration logic, so need to cope with
  * being used outside of v's context.
  */
-int guest_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val);
+int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val);

I find this pretty undesirable, and I'd like to at least put out for discussion a means how to avoid it: Any entity being passed a const struct vcpu *cv can get hold of a non-const one by doing

    struct vcpu *v = cv->domain->vcpu[cv->vcpu_id];

Of course this shouldn't be used arbitrarily, but to hide an implementation detail like that of vmx_vmcs_enter() I think this could be justified. Thoughts?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw

Re: [PATCH v2 1/4] x86: stop handling MSR_IA32_BNDCFGS save/restore in implementation code

Quoted 34 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Jan Beulich
Sent: 13 March 2019 15:55
To: Andrew Cooper <[email protected]>; Paul Durrant <[email protected]>
Cc: xen-devel <[email protected]>; Kevin Tian <[email protected]>; Wei Liu <[email protected]>; Jun Nakajima <[email protected]>; Roger Pau Monne <[email protected]>
Subject: Re: [Xen-devel] [PATCH v2 1/4] x86: stop handling MSR_IA32_BNDCFGS save/restore in implementation code

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 11.03.19 at 19:09, <[email protected]> wrote:

v2:
- Addressed comments from Jan by largely removing hunks

I think you've removed more than I was expecting, but I'm fine this way.

Quoted 18 lines
xen/arch/x86/msr.c +7 -0
@@ -158,6 +158,13 @@ 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 ( !is_hvm_domain(d) || !cp->feat.mpx ||
+             !hvm_get_guest_bndcfgs(v, val) )
+            goto gp_fault;
+
+        break;
+
     case 0x40000000 ... 0x400001ff:
         if ( is_viridian_domain(d) )
         {
@@ -319,6 +326,13 @@ int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val)
         ret = guest_wrmsr_x2apic(v, msr, val);
         break;
 
Quoted 9 lines

xen/arch/x86/msr.c int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val) · line 332

Quoted 4 lines
xen/arch/x86/msr.c +4 -0
+    case MSR_IA32_BNDCFGS:
+        if ( !is_hvm_domain(d) || !cp->feat.mpx ||
+             !hvm_set_guest_bndcfgs(v, val) )
+            goto gp_fault;

In both cases the is_hvm_*() check looks to be redundant, as for PV guests cp->feat.mpx can't be set. Personally I'd prefer this to be an ASSERT() instead, but I'd listen to Andrew (as the main author of this code) saying otherwise.

I'm ok with an ASSERT but I'll check with Andrew as you suggest.

Quoted 15 lines

xen/include/asm-x86/msr.h int init_vcpu_msr_policy(struct vcpu *v); · line 331

Quoted 9 lines
xen/include/asm-x86/msr.h +1 -1
@@ -328,7 +328,7 @@ int init_vcpu_msr_policy(struct vcpu *v);
  * These functions are also used by the migration logic, so need to cope with
  * being used outside of v's context.
  */
-int guest_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val);
+int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val);

I find this pretty undesirable, and I'd like to at least put out for discussion a means how to avoid it: Any entity being passed a const struct vcpu *cv can get hold of a non-const one by doing

Quoted 2 lines
    struct vcpu *v = cv->domain->vcpu[cv->vcpu_id];

Looks kind of odd, but of course it will certainly work.

Quoted 4 lines

Of course this shouldn't be used arbitrarily, but to hide an implementation detail like that of vmx_vmcs_enter() I think this could be justified. Thoughts?

I guess the question is at what level to do this? Probably in the hvm code rather than in the vmx code.

Paul

Quoted 8 lines

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw

Re: [PATCH v2 1/4] x86: stop handling MSR_IA32_BNDCFGS save/restore in implementation code

Quoted 24 lines
Quoted 19 lines
Quoted 1 line · On 13.03.19 at 17:05, <[email protected]> wrote:

From: Xen-devel [mailto:[email protected]] On Behalf Of Jan Beulich
Sent: 13 March 2019 15:55

xen/include/asm-x86/msr.h int init_vcpu_msr_policy(struct vcpu *v); · line 331

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 11.03.19 at 19:09, <[email protected]> wrote:
xen/include/asm-x86/msr.h +1 -1
@@ -328,7 +328,7 @@ int init_vcpu_msr_policy(struct vcpu *v);
  * These functions are also used by the migration logic, so need to cope with
  * being used outside of v's context.
  */
-int guest_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val);
+int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val);

I find this pretty undesirable, and I'd like to at least put out for discussion a means how to avoid it: Any entity being passed a const struct vcpu *cv can get hold of a non-const one by doing

Quoted 2 lines
    struct vcpu *v = cv->domain->vcpu[cv->vcpu_id];

Looks kind of odd, but of course it will certainly work.

Quoted 7 lines
Quoted 4 lines

Of course this shouldn't be used arbitrarily, but to hide an implementation detail like that of vmx_vmcs_enter() I think this could be justified. Thoughts?

I guess the question is at what level to do this? Probably in the hvm code rather than in the vmx code.

I think it should be in VMX code, as that's where the vmx_vmcs_enter() oddity lives.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw

PATCH v2 2/4 x86: move the saved value of MSR_IA32_XSS into struct vcpu_msrs

In reply to Paul Durrant

Currently the value is saved directly in struct hvm_vcpu. This patch simply co-locates it with other saved MSR values. No functional change.

---
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: Jun Nakajima <[email protected]>

---
 xen/arch/x86/domain.c          | 2 +-
 xen/arch/x86/hvm/hvm.c         | 4 ++--
 xen/arch/x86/hvm/vmx/vmx.c     | 4 ++--
 xen/include/asm-x86/hvm/vcpu.h | 1 -
 xen/include/asm-x86/msr.h      | 5 +++++
 5 files changed, 10 insertions(+), 6 deletions(-)
xen/arch/x86/domain.c +1 -1
index 8d579e2cf9..aa38555736 100644
@@ -1653,7 +1653,7 @@ static void __context_switch(void)
                 BUG();
 
             if ( cpu_has_xsaves && is_hvm_vcpu(n) )
-                set_msr_xss(n->arch.hvm.msr_xss);
+                set_msr_xss(n->arch.msrs->xss.raw);
         }
         vcpu_restore_fpu_nonlazy(n, false);
         nd->arch.ctxt_switch->to(n);
xen/arch/x86/hvm/hvm.c +2 -2
index e566d83f8b..dff590e658 100644
@@ -3466,7 +3466,7 @@ int hvm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
     case MSR_IA32_XSS:
         if ( !d->arch.cpuid->xstate.xsaves )
             goto gp_fault;
-        *msr_content = v->arch.hvm.msr_xss;
+        *msr_content = v->arch.msrs->xss.raw;
         break;
 
     case MSR_K8_ENABLE_C1E:
@@ -3612,7 +3612,7 @@ int hvm_msr_write_intercept(unsigned int msr, uint64_t msr_content,
         /* No XSS features currently supported for guests. */
         if ( !d->arch.cpuid->xstate.xsaves || msr_content != 0 )
             goto gp_fault;
-        v->arch.hvm.msr_xss = msr_content;
+        v->arch.msrs->xss.raw = msr_content;
         break;
 
     case MSR_AMD64_NB_CFG:
xen/arch/x86/hvm/vmx/vmx.c +2 -2
index 42232dbb37..90a66650a9 100644
@@ -807,7 +807,7 @@ 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.hvm.msr_xss;
+        ctxt->msr[ctxt->count].val = v->arch.msrs->xss.raw;
         if ( ctxt->msr[ctxt->count].val )
             ctxt->msr[ctxt->count++].index = MSR_IA32_XSS;
     }
@@ -826,7 +826,7 @@ static int vmx_load_msr(struct vcpu *v, struct hvm_msr *ctxt)
         {
         case MSR_IA32_XSS:
             if ( cpu_has_xsaves && cpu_has_vmx_xsaves )
-                v->arch.hvm.msr_xss = ctxt->msr[i].val;
+                v->arch.msrs->xss.raw = ctxt->msr[i].val;
             else
                 err = -ENXIO;
             break;
xen/include/asm-x86/hvm/vcpu.h +0 -1
index 6c84d5a5a6..5563d28a4e 100644
@@ -176,7 +176,6 @@ struct hvm_vcpu {
     struct hvm_vcpu_asid n1asid;
 
     u64                 msr_tsc_adjust;
-    u64                 msr_xss;
 
     union {
         struct vmx_vcpu vmx;
xen/include/asm-x86/msr.h +5 -0
index c3107f8542..2c9ef9fdda 100644
@@ -313,6 +313,11 @@ struct vcpu_msrs
      * values here may be stale in current context.
      */
     uint32_t dr_mask[4];
+
+    /* 0x00000da0 - MSR_IA32_XSS */
+    struct {
+        uint64_t raw;
+    } xss;
 };
 
 void init_guest_msr_policy(void);
Signature · 7 lines
2.20.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#6 lore raw

PATCH v2 3/4 x86: stop handling MSR_IA32_XSS save/restore in implementation code

In reply to Paul Durrant

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.

---
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: Jun Nakajima <[email protected]>

---
 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(-)
xen/arch/x86/hvm/hvm.c +2 -13
index dff590e658..deb7fb2adb 100644
@@ -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;
xen/arch/x86/hvm/vmx/vmx.c +0 -49

61 lines not on this page · raw message

xen/arch/x86/msr.c +18 -0
index 3c24ee7ba3..59cca5557c 100644
@@ -165,6 +165,13 @@ int guest_rdmsr(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) )
         {
@@ -333,6 +340,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) )
         {
Signature · 7 lines
2.20.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#7 lore raw

PATCH v2 4/4 x86: remove defunct init/load/save_msr() hvm_funcs

In reply to Paul Durrant

These hvm_funcs are no longer required since no MSR values are saved or restored by implementation-specific code.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

v2:
- Re-instate err check on loop in hvm_load_cpu_msrs()

---
 xen/arch/x86/hvm/hvm.c        | 29 +++++++++--------------------
 xen/include/asm-x86/hvm/hvm.h |  4 ----
 2 files changed, 9 insertions(+), 24 deletions(-)
xen/arch/x86/hvm/hvm.c +9 -20
index deb7fb2adb..f84bf11f0f 100644
@@ -1310,7 +1310,6 @@ static const uint32_t msrs_to_send[] = {
     MSR_AMD64_DR2_ADDRESS_MASK,
     MSR_AMD64_DR3_ADDRESS_MASK,
 };
-static unsigned int __read_mostly msr_count_max = ARRAY_SIZE(msrs_to_send);
 
 static int hvm_save_cpu_msrs(struct vcpu *v, hvm_domain_context_t *h)
 {
@@ -1320,7 +1319,7 @@ static int hvm_save_cpu_msrs(struct vcpu *v, hvm_domain_context_t *h)
     int err;
 
     err = _hvm_init_entry(h, CPU_MSR_CODE, v->vcpu_id,
-                             HVM_CPU_MSR_SIZE(msr_count_max));
+                             HVM_CPU_MSR_SIZE(ARRAY_SIZE(msrs_to_send)));
     if ( err )
         return err;
     ctxt = (struct hvm_msr *)&h->data[h->cur];
@@ -1353,10 +1352,7 @@ static int hvm_save_cpu_msrs(struct vcpu *v, hvm_domain_context_t *h)
         ctxt->msr[ctxt->count++].val = val;
     }
 
-    if ( hvm_funcs.save_msr )
-        hvm_funcs.save_msr(v, ctxt);
-
-    ASSERT(ctxt->count <= msr_count_max);
+    ASSERT(ctxt->count <= ARRAY_SIZE(msrs_to_send));
 
     for ( i = 0; i < ctxt->count; ++i )
         ctxt->msr[i]._rsvd = 0;
@@ -1431,9 +1427,6 @@ static int hvm_load_cpu_msrs(struct domain *d, hvm_domain_context_t *h)
             return -EOPNOTSUPP;
     /* Checking finished */
 
-    if ( hvm_funcs.load_msr )
-        err = hvm_funcs.load_msr(v, ctxt);
-
     for ( i = 0; !err && i < ctxt->count; ++i )
     {
         switch ( ctxt->msr[i].index )
@@ -1475,17 +1468,13 @@ static int __init hvm_register_CPU_save_and_restore(void)
                             sizeof(struct hvm_save_descriptor),
                         HVMSR_PER_VCPU);
 
-    if ( hvm_funcs.init_msr )
-        msr_count_max += hvm_funcs.init_msr();
-
-    if ( msr_count_max )
-        hvm_register_savevm(CPU_MSR_CODE,
-                            "CPU_MSR",
-                            hvm_save_cpu_msrs,
-                            hvm_load_cpu_msrs,
-                            HVM_CPU_MSR_SIZE(msr_count_max) +
-                                sizeof(struct hvm_save_descriptor),
-                            HVMSR_PER_VCPU);
+    hvm_register_savevm(CPU_MSR_CODE,
+                        "CPU_MSR",
+                        hvm_save_cpu_msrs,
+                        hvm_load_cpu_msrs,
+                        HVM_CPU_MSR_SIZE(ARRAY_SIZE(msrs_to_send)) +
+                            sizeof(struct hvm_save_descriptor),
+                        HVMSR_PER_VCPU);
 
     return 0;
 }
xen/include/asm-x86/hvm/hvm.h +0 -4
index 53ffebb2c5..ce2afb4ebb 100644
@@ -115,10 +115,6 @@ struct hvm_function_table {
     void (*save_cpu_ctxt)(struct vcpu *v, struct hvm_hw_cpu *ctxt);
     int (*load_cpu_ctxt)(struct vcpu *v, struct hvm_hw_cpu *ctxt);
 
-    unsigned int (*init_msr)(void);
-    void (*save_msr)(struct vcpu *, struct hvm_msr *);
-    int (*load_msr)(struct vcpu *, struct hvm_msr *);
-
     /* Examine specifics of the guest state. */
     unsigned int (*get_interrupt_shadow)(struct vcpu *v);
     void (*set_interrupt_shadow)(struct vcpu *v, unsigned int intr_shadow);
Signature · 7 lines
2.20.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 4/4
#8 lore raw

Re: [PATCH v2 4/4] x86: remove defunct init/load/save_msr() hvm_funcs

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 11.03.19 at 19:09, <[email protected]> wrote:

These hvm_funcs are no longer required since no MSR values are saved or restored by implementation-specific code.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel