Skip to contentSkip to conversation

pvh: change epte_get_entry_emt() for pvh mem types

PATCH In review Mukesh Rathor 3 participants 5 messages Nov 22, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pvh: change epte_get_entry_emt() for pvh mem types

For pvh guests, epte_get_entry_emt() is incorrectly returning WB for all mem types because of the following check:

    if ( !v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT] )

Skip the check for pvh guests.

Also note, MTRR ranges are not maintained for pvh, and a solution is being contrived using PAT.

---
 xen/arch/x86/hvm/mtrr.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
xen/arch/x86/hvm/mtrr.c +6 -1
index 4ff1e55..5427e1c 100644
@@ -693,7 +693,8 @@ uint8_t epte_get_entry_emt(struct domain *d, unsigned long gfn, mfn_t mfn,
          ((d->vcpu == NULL) || ((v = d->vcpu[0]) == NULL)) )
         return MTRR_TYPE_WRBACK;
 
-    if ( !v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT] )
+    if ( !is_pvh_vcpu(v) &&
+         !v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT] )
         return MTRR_TYPE_WRBACK;
 
     if ( !mfn_valid(mfn_x(mfn)) )
@@ -717,6 +718,10 @@ uint8_t epte_get_entry_emt(struct domain *d, unsigned long gfn, mfn_t mfn,
         return MTRR_TYPE_WRBACK;
     }
 
+    /* MTRR ranges are not maintained for pvh. */
+    if ( is_pvh_vcpu(v) )
+        return MTRR_TYPE_WRBACK;
+
     gmtrr_mtype = get_mtrr_type(&v->arch.hvm_vcpu.mtrr, (gfn << PAGE_SHIFT));
     hmtrr_mtype = get_mtrr_type(&mtrr_state, (mfn_x(mfn) << PAGE_SHIFT));
     return ((gmtrr_mtype <= hmtrr_mtype) ? gmtrr_mtype : hmtrr_mtype);
Signature · 1 line
1.7.2.3
#1 lore raw
Quoted 28 lines · Mukesh Rathor

For pvh guests, epte_get_entry_emt() is incorrectly returning WB for all mem types because of the following check:

     if ( !v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT] )

Skip the check for pvh guests.

Also note, MTRR ranges are not maintained for pvh, and a solution is being contrived using PAT.

---
  xen/arch/x86/hvm/mtrr.c |    7 ++++++-
  1 files changed, 6 insertions(+), 1 deletions(-)
xen/arch/x86/hvm/mtrr.c +2 -1
index 4ff1e55..5427e1c 100644
@@ -693,7 +693,8 @@ uint8_t epte_get_entry_emt(struct domain *d, unsigned long gfn, mfn_t mfn,
           ((d->vcpu == NULL) || ((v = d->vcpu[0]) == NULL)) )
          return MTRR_TYPE_WRBACK;
 
-    if ( !v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT] )
+    if ( !is_pvh_vcpu(v) &&
+         !v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT] )
          return MTRR_TYPE_WRBACK;
 
      if ( !mfn_valid(mfn_x(mfn)) )

xen/arch/x86/hvm/mtrr.c uint8_t epte_get_entry_emt(struct domain *d, unsigned long gfn, mfn_t mfn, · line 727

Quoted 10 lines
xen/arch/x86/hvm/mtrr.c +4 -0
@@ -717,6 +718,10 @@ uint8_t epte_get_entry_emt(struct domain *d, unsigned long gfn, mfn_t mfn,
          return MTRR_TYPE_WRBACK;
      }
 
+    /* MTRR ranges are not maintained for pvh. */
+    if ( is_pvh_vcpu(v) )
+        return MTRR_TYPE_WRBACK;
+
      gmtrr_mtype = get_mtrr_type(&v->arch.hvm_vcpu.mtrr, (gfn << PAGE_SHIFT));
      hmtrr_mtype = get_mtrr_type(&mtrr_state, (mfn_x(mfn) << PAGE_SHIFT));
      return ((gmtrr_mtype <= hmtrr_mtype) ? gmtrr_mtype : hmtrr_mtype);

So this will bypass the host mtrr settings, and always return WRBACK, even if in mtrr_state it was set to something lower. Presumably that "min(host,guest)" was there for a reason. Are you sure it's safe to just ignore it?

This is why I suggested the following instead:

gmtrr_mtype = is_hvm_domain(v) ?

        get_mtrr_type(&v->arch.hvm_vcpu.mtrr, (gfn << PAGE_SHIFT)) :
        MTRR_TYPE_WRBACK;

-George

#2 lore raw
Quoted 43 lines · George Dunlap
Quoted 37 lines · Mukesh Rathor

For pvh guests, epte_get_entry_emt() is incorrectly returning WB for all mem types because of the following check:

     if ( !v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT] )

Skip the check for pvh guests.

Also note, MTRR ranges are not maintained for pvh, and a solution is being contrived using PAT.

---
  xen/arch/x86/hvm/mtrr.c |    7 ++++++-
  1 files changed, 6 insertions(+), 1 deletions(-)
xen/arch/x86/hvm/mtrr.c +5 -0
index 4ff1e55..5427e1c 100644
@@ -693,7 +693,8 @@ uint8_t epte_get_entry_emt(struct domain *d, 
 unsigned long gfn, mfn_t mfn,
           ((d->vcpu == NULL) || ((v = d->vcpu[0]) == NULL)) )
          return MTRR_TYPE_WRBACK;
  -    if ( !v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT] )
+    if ( !is_pvh_vcpu(v) &&
+ !v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT] )
          return MTRR_TYPE_WRBACK;
        if ( !mfn_valid(mfn_x(mfn)) )
@@ -717,6 +718,10 @@ uint8_t epte_get_entry_emt(struct domain *d, 
 unsigned long gfn, mfn_t mfn,
          return MTRR_TYPE_WRBACK;
      }
  +    /* MTRR ranges are not maintained for pvh. */
+    if ( is_pvh_vcpu(v) )
+        return MTRR_TYPE_WRBACK;
+
      gmtrr_mtype = get_mtrr_type(&v->arch.hvm_vcpu.mtrr, (gfn << 
 PAGE_SHIFT));
      hmtrr_mtype = get_mtrr_type(&mtrr_state, (mfn_x(mfn) << 
Quoted 2 lines
PAGE_SHIFT));
      return ((gmtrr_mtype <= hmtrr_mtype) ? gmtrr_mtype : hmtrr_mtype);

So this will bypass the host mtrr settings, and always return WRBACK, even if in mtrr_state it was set to something lower. Presumably that "min(host,guest)" was there for a reason. Are you sure it's safe to just ignore it?

Quoted 5 lines

This is why I suggested the following instead:

gmtrr_mtype = is_hvm_domain(v) ?

        get_mtrr_type(&v->arch.hvm_vcpu.mtrr, (gfn << PAGE_SHIFT)) :
        MTRR_TYPE_WRBACK;

Also, while I suppose this is fine for now (since we're starting the code freeze), for the future: is it actually better to "bake in" that MTRRs are completely disabled and always effectively return WRBACK (except for direct_mmio memory), or would it be better to initialize the virtual MTRRs to WRBACK (the way a BIOS would), and allow the guest to change them if it wants?

-George

#3 lore raw
In reply to George Dunlap
Quoted 48 lines
Quoted 1 line
Quoted 1 line · George Dunlap

xen/arch/x86/hvm/mtrr.c uint8_t epte_get_entry_emt(struct domain *d, unsigned

Quoted 18 lines · Mukesh Rathor

For pvh guests, epte_get_entry_emt() is incorrectly returning WB for all mem types because of the following check:

     if ( !v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT] )

Skip the check for pvh guests.

Also note, MTRR ranges are not maintained for pvh, and a solution is being contrived using PAT.

---
  xen/arch/x86/hvm/mtrr.c |    7 ++++++-
  1 files changed, 6 insertions(+), 1 deletions(-)
xen/arch/x86/hvm/mtrr.c +0 -0
index 4ff1e55..5427e1c 100644
@@ -693,7 +693,8 @@ uint8_t epte_get_entry_emt(struct domain *d, unsigned 

long gfn, mfn_t mfn,

xen/arch/x86/hvm/mtrr.c uint8_t epte_get_entry_emt(struct domain *d, unsigned

Quoted 10 lines
xen/arch/x86/hvm/mtrr.c +2 -1
           ((d->vcpu == NULL) || ((v = d->vcpu[0]) == NULL)) )
          return MTRR_TYPE_WRBACK;
 
-    if ( !v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT] )
+    if ( !is_pvh_vcpu(v) &&
+         !v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT] )
          return MTRR_TYPE_WRBACK;
 
      if ( !mfn_valid(mfn_x(mfn)) )
@@ -717,6 +718,10 @@ uint8_t epte_get_entry_emt(struct domain *d, unsigned 

long gfn, mfn_t mfn,

xen/arch/x86/hvm/mtrr.c uint8_t epte_get_entry_emt(struct domain *d, unsigned long gfn, mfn_t mfn, · line 727

Quoted 10 lines
xen/arch/x86/hvm/mtrr.c +4 -0
          return MTRR_TYPE_WRBACK;
      }
 
+    /* MTRR ranges are not maintained for pvh. */
+    if ( is_pvh_vcpu(v) )
+        return MTRR_TYPE_WRBACK;
+
      gmtrr_mtype = get_mtrr_type(&v->arch.hvm_vcpu.mtrr, (gfn << PAGE_SHIFT));
      hmtrr_mtype = get_mtrr_type(&mtrr_state, (mfn_x(mfn) << PAGE_SHIFT));
      return ((gmtrr_mtype <= hmtrr_mtype) ? gmtrr_mtype : hmtrr_mtype);

So this will bypass the host mtrr settings, and always return WRBACK, even if in mtrr_state it was set to something lower. Presumably that "min(host,guest)" was there for a reason. Are you sure it's safe to just ignore it?

Quoted 5 lines

This is why I suggested the following instead:

gmtrr_mtype = is_hvm_domain(v) ?

         get_mtrr_type(&v->arch.hvm_vcpu.mtrr, (gfn << PAGE_SHIFT)) :
         MTRR_TYPE_WRBACK;

Indeed, that's what we should use.

Jan

#4 lore raw
Quoted 52 lines · On Fri, 22 Nov 2013 12:05:03 +0000 "Jan Beulich" <[email protected]> wrote:
Quoted 52 lines
Quoted 2 lines
Quoted 2 lines

On 22.11.13 at 11:52, George Dunlap <[email protected]> wrote:

Quoted 18 lines · Mukesh Rathor

For pvh guests, epte_get_entry_emt() is incorrectly returning WB for all mem types because of the following check:

     if ( !v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT] )

Skip the check for pvh guests.

Also note, MTRR ranges are not maintained for pvh, and a solution is being contrived using PAT.

---
  xen/arch/x86/hvm/mtrr.c |    7 ++++++-
  1 files changed, 6 insertions(+), 1 deletions(-)
xen/arch/x86/hvm/mtrr.c +0 -0
index 4ff1e55..5427e1c 100644
@@ -693,7 +693,8 @@ uint8_t epte_get_entry_emt(struct domain *d,
Quoted 1 line

unsigned

long gfn, mfn_t mfn,

Quoted 11 lines
           ((d->vcpu == NULL) || ((v = d->vcpu[0]) == NULL)) )
          return MTRR_TYPE_WRBACK;
xen/arch/x86/hvm/mtrr.c +2 -1
-    if ( !v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT] )
+    if ( !is_pvh_vcpu(v) &&
+         !v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT] )
          return MTRR_TYPE_WRBACK;
 
      if ( !mfn_valid(mfn_x(mfn)) )
@@ -717,6 +718,10 @@ uint8_t epte_get_entry_emt(struct domain *d,

unsigned

long gfn, mfn_t mfn,

Quoted 11 lines
          return MTRR_TYPE_WRBACK;
      }
xen/arch/x86/hvm/mtrr.c +4 -0
+    /* MTRR ranges are not maintained for pvh. */
+    if ( is_pvh_vcpu(v) )
+        return MTRR_TYPE_WRBACK;
+
      gmtrr_mtype = get_mtrr_type(&v->arch.hvm_vcpu.mtrr, (gfn <<

PAGE_SHIFT)); hmtrr_mtype = get_mtrr_type(&mtrr_state, (mfn_x(mfn) << PAGE_SHIFT)); return ((gmtrr_mtype <= hmtrr_mtype) ? gmtrr_mtype : hmtrr_mtype);

So this will bypass the host mtrr settings, and always return WRBACK, even if in mtrr_state it was set to something lower. Presumably that "min(host,guest)" was there for a reason. Are you sure it's safe to just ignore it?

Quoted 7 lines
Quoted 5 lines

This is why I suggested the following instead:

gmtrr_mtype = is_hvm_domain(v) ?

         get_mtrr_type(&v->arch.hvm_vcpu.mtrr, (gfn <<

PAGE_SHIFT)) : MTRR_TYPE_WRBACK;

Indeed, that's what we should use.

Sorry, totally my bad. For some reason I had concluded that hmtrr_mtype was being set to UC. V2 patch on the way...

thanks
Mukesh