Skip to contentSkip to conversation

x86/P2M: reduce time bulk type changes take

PATCH Superseded Jan Beulich 4 participants 21 messages Apr 22, 2014 – Apr 28, 2014

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover x86/P2M: reduce time bulk type changes take

1: EPT: don't walk entire page tables when globally changing types 2: EPT: don't walk entire page tables when changing types on a range 3: P2M: simplify write_p2m_entry()
4: NPT: don't walk entire page tables when changing types on a range 5: NPT: don't walk entire page tables when globally changing types 6: P2M: cleanup

Beyond this series it might also be worthwhile considering to make HVMOP_set_mem_type use p2m_change_type_range(), avoiding the need for explicit preemption there.

---
v2: Add overview comments to the more complex of the functions added.

#1 lore raw

PATCH v2 1/6 x86/EPT: don't walk entire page tables when globally changing types

Instead leverage the EPT_MISCONFIG VM exit by marking just the top level entries as needing recalculation of their type, propagating the the recalculation state down as necessary such that the actual recalculation gets done upon access.

For this to work, we have to
- restrict the types between which conversions can be done (right now only the two types involved in log dirty tracking need to be taken care of)
- remember the ranges that log dirty tracking was requested for as well as whether global log dirty tracking is in effect

xen/arch/x86/mm/hap/hap.c +12 -0
@@ -110,11 +110,18 @@ int hap_track_dirty_vram(struct domain *
         if ( begin_pfn != dirty_vram->begin_pfn ||
              begin_pfn + nr != dirty_vram->end_pfn )
         {
+            unsigned long ostart = dirty_vram->begin_pfn;
+            unsigned long oend = dirty_vram->end_pfn;
+
             dirty_vram->begin_pfn = begin_pfn;
             dirty_vram->end_pfn = begin_pfn + nr;
 
             paging_unlock(d);
 
+            if ( oend > ostart )
+                p2m_change_type_range(d, ostart, oend,
+                                      p2m_ram_logdirty, p2m_ram_rw);
+
             /* set l1e entries of range within P2M table to be read-only. */
             p2m_change_type_range(d, begin_pfn, begin_pfn + nr,
                                   p2m_ram_rw, p2m_ram_logdirty);
@@ -150,11 +157,16 @@ int hap_track_dirty_vram(struct domain *
              * If zero pages specified while tracking dirty vram
              * then stop tracking
              */
+            begin_pfn = dirty_vram->begin_pfn;
+            nr = dirty_vram->end_pfn - dirty_vram->begin_pfn;
             xfree(dirty_vram);
             d->arch.hvm_domain.dirty_vram = NULL;
         }
 
         paging_unlock(d);
+        if ( nr )
+            p2m_change_type_range(d, begin_pfn, begin_pfn + nr,
+                                  p2m_ram_logdirty, p2m_ram_rw);
     }
 out:
     if ( dirty_bitmap )
xen/arch/x86/mm/p2m.c +59 -7

108 lines not on this page · raw message

xen/arch/x86/mm/p2m-ept.c +101 -64

315 lines not on this page · raw message

xen/include/asm-x86/hvm/vmx/vmx.h +1 -1
@@ -38,7 +38,7 @@ typedef union {
         ipat        :   1,  /* bit 6 - Ignore PAT memory type */
         sp          :   1,  /* bit 7 - Is this a superpage? */
         rsvd1       :   2,  /* bits 9:8 - Reserved for future use */
-        avail1      :   1,  /* bit 10 - Software available 1 */
+        recalc      :   1,  /* bit 10 - Software available 1 */
         snp         :   1,  /* bit 11 - VT-d snoop control in shared
                                EPT/VT-d usage */
         mfn         :   40, /* bits 51:12 - Machine physical frame number */
xen/include/asm-x86/p2m.h +13 -0
@@ -139,6 +139,10 @@ typedef unsigned int p2m_query_t;
                       | p2m_to_mask(p2m_grant_map_ro)   \
                       | p2m_to_mask(p2m_ram_shared) )
 
+/* Types that can be subject to bulk transitions. */
+#define P2M_CHANGEABLE_TYPES (p2m_to_mask(p2m_ram_rw) \
+                              | p2m_to_mask(p2m_ram_logdirty) )
+
 #define P2M_POD_TYPES (p2m_to_mask(p2m_populate_on_demand))
 
 /* Pageable types */
@@ -167,6 +171,7 @@ typedef unsigned int p2m_query_t;
 #define p2m_is_hole(_t) (p2m_to_mask(_t) & P2M_HOLE_TYPES)
 #define p2m_is_mmio(_t) (p2m_to_mask(_t) & P2M_MMIO_TYPES)
 #define p2m_is_readonly(_t) (p2m_to_mask(_t) & P2M_RO_TYPES)
+#define p2m_is_changeable(_t) (p2m_to_mask(_t) & P2M_CHANGEABLE_TYPES)
 #define p2m_is_pod(_t) (p2m_to_mask(_t) & P2M_POD_TYPES)
 #define p2m_is_grant(_t) (p2m_to_mask(_t) & P2M_GRANT_TYPES)
 /* Grant types are *not* considered valid, because they can be
@@ -209,6 +214,11 @@ struct p2m_domain {
      * threaded on in LRU order. */
     struct list_head   np2m_list;
 
+    /* Host p2m: Log-dirty ranges registered for the domain. */
+    struct rangeset   *logdirty_ranges;
+
+    /* Host p2m: Global log-dirty mode enabled for the domain. */
+    bool_t             global_logdirty;
 
     /* Host p2m: when this flag is set, don't flush all the nested-p2m 
      * tables on every host-p2m change.  The setter of this flag 
@@ -510,6 +520,9 @@ p2m_type_t p2m_change_type(struct domain
 /* Report a change affecting memory types. */
 void p2m_memory_type_changed(struct domain *d);
 
+int p2m_is_logdirty_range(struct p2m_domain *, unsigned long start,
+                          unsigned long end);
+
 /* Set mmio addresses in the p2m table (for pass-through) */
 int set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn);
 int clear_mmio_p2m_entry(struct domain *d, unsigned long gfn);

x86/EPT: don't walk entire page tables when globally changing types

Instead leverage the EPT_MISCONFIG VM exit by marking just the top level entries as needing recalculation of their type, propagating the the recalculation state down as necessary such that the actual recalculation gets done upon access.

For this to work, we have to
- restrict the types between which conversions can be done (right now only the two types involved in log dirty tracking need to be taken care of)
- remember the ranges that log dirty tracking was requested for as well as whether global log dirty tracking is in effect

xen/arch/x86/mm/hap/hap.c +12 -0
@@ -110,11 +110,18 @@ int hap_track_dirty_vram(struct domain *
         if ( begin_pfn != dirty_vram->begin_pfn ||
              begin_pfn + nr != dirty_vram->end_pfn )
         {
+            unsigned long ostart = dirty_vram->begin_pfn;
+            unsigned long oend = dirty_vram->end_pfn;
+
             dirty_vram->begin_pfn = begin_pfn;
             dirty_vram->end_pfn = begin_pfn + nr;
 
             paging_unlock(d);
 
+            if ( oend > ostart )
+                p2m_change_type_range(d, ostart, oend,
+                                      p2m_ram_logdirty, p2m_ram_rw);
+
             /* set l1e entries of range within P2M table to be read-only. */
             p2m_change_type_range(d, begin_pfn, begin_pfn + nr,
                                   p2m_ram_rw, p2m_ram_logdirty);
@@ -150,11 +157,16 @@ int hap_track_dirty_vram(struct domain *
              * If zero pages specified while tracking dirty vram
              * then stop tracking
              */
+            begin_pfn = dirty_vram->begin_pfn;
+            nr = dirty_vram->end_pfn - dirty_vram->begin_pfn;
             xfree(dirty_vram);
             d->arch.hvm_domain.dirty_vram = NULL;
         }
 
         paging_unlock(d);
+        if ( nr )
+            p2m_change_type_range(d, begin_pfn, begin_pfn + nr,
+                                  p2m_ram_logdirty, p2m_ram_rw);
     }
 out:
     if ( dirty_bitmap )
xen/arch/x86/mm/p2m.c +59 -7

108 lines not on this page · raw message

xen/arch/x86/mm/p2m-ept.c +101 -64

315 lines not on this page · raw message

xen/include/asm-x86/hvm/vmx/vmx.h +1 -1
@@ -38,7 +38,7 @@ typedef union {
         ipat        :   1,  /* bit 6 - Ignore PAT memory type */
         sp          :   1,  /* bit 7 - Is this a superpage? */
         rsvd1       :   2,  /* bits 9:8 - Reserved for future use */
-        avail1      :   1,  /* bit 10 - Software available 1 */
+        recalc      :   1,  /* bit 10 - Software available 1 */
         snp         :   1,  /* bit 11 - VT-d snoop control in shared
                                EPT/VT-d usage */
         mfn         :   40, /* bits 51:12 - Machine physical frame number */
xen/include/asm-x86/p2m.h +13 -0
@@ -139,6 +139,10 @@ typedef unsigned int p2m_query_t;
                       | p2m_to_mask(p2m_grant_map_ro)   \
                       | p2m_to_mask(p2m_ram_shared) )
 
+/* Types that can be subject to bulk transitions. */
+#define P2M_CHANGEABLE_TYPES (p2m_to_mask(p2m_ram_rw) \
+                              | p2m_to_mask(p2m_ram_logdirty) )
+
 #define P2M_POD_TYPES (p2m_to_mask(p2m_populate_on_demand))
 
 /* Pageable types */
@@ -167,6 +171,7 @@ typedef unsigned int p2m_query_t;
 #define p2m_is_hole(_t) (p2m_to_mask(_t) & P2M_HOLE_TYPES)
 #define p2m_is_mmio(_t) (p2m_to_mask(_t) & P2M_MMIO_TYPES)
 #define p2m_is_readonly(_t) (p2m_to_mask(_t) & P2M_RO_TYPES)
+#define p2m_is_changeable(_t) (p2m_to_mask(_t) & P2M_CHANGEABLE_TYPES)
 #define p2m_is_pod(_t) (p2m_to_mask(_t) & P2M_POD_TYPES)
 #define p2m_is_grant(_t) (p2m_to_mask(_t) & P2M_GRANT_TYPES)
 /* Grant types are *not* considered valid, because they can be
@@ -209,6 +214,11 @@ struct p2m_domain {
      * threaded on in LRU order. */
     struct list_head   np2m_list;
 
+    /* Host p2m: Log-dirty ranges registered for the domain. */
+    struct rangeset   *logdirty_ranges;
+
+    /* Host p2m: Global log-dirty mode enabled for the domain. */
+    bool_t             global_logdirty;
 
     /* Host p2m: when this flag is set, don't flush all the nested-p2m 
      * tables on every host-p2m change.  The setter of this flag 
@@ -510,6 +520,9 @@ p2m_type_t p2m_change_type(struct domain
 /* Report a change affecting memory types. */
 void p2m_memory_type_changed(struct domain *d);
 
+int p2m_is_logdirty_range(struct p2m_domain *, unsigned long start,
+                          unsigned long end);
+
 /* Set mmio addresses in the p2m table (for pass-through) */
 int set_mmio_p2m_entry(struct domain *d, unsigned long gfn, mfn_t mfn);
 int clear_mmio_p2m_entry(struct domain *d, unsigned long gfn);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw

Re: [PATCH v2 1/6] x86/EPT: don't walk entire page tables when globally changing types

Quoted 5 lines · Jan Beulich

Instead leverage the EPT_MISCONFIG VM exit by marking just the top level entries as needing recalculation of their type, propagating the the recalculation state down as necessary such that the actual recalculation gets done upon access.

Quoted 8 lines

For this to work, we have to
- restrict the types between which conversions can be done (right now only the two types involved in log dirty tracking need to be taken care of)
- remember the ranges that log dirty tracking was requested for as well as whether global log dirty tracking is in effect

Generally looks good; I think the core idea of reusing the misconfig mechanism is the right way to go.

The naming you've chosen implies that it might be extended later to other lazily-updated types; I'm not sure how well that will scale. OTOH right now I can't think of any other users for this (and I can see why you're not happy with using change_type() to flush out foreign mappings on teardown after this changes).

A few comments on detail below:

Quoted 8 lines
xen/arch/x86/mm/hap/hap.c +2 -0
@@ -110,11 +110,18 @@ int hap_track_dirty_vram(struct domain *
         if ( begin_pfn != dirty_vram->begin_pfn ||
              begin_pfn + nr != dirty_vram->end_pfn )
         {
+            unsigned long ostart = dirty_vram->begin_pfn;
+            unsigned long oend = dirty_vram->end_pfn;

xen/arch/x86/mm/hap/hap.c int hap_track_dirty_vram(struct domain * · line 124

Quoted 10 lines
xen/arch/x86/mm/hap/hap.c +5 -0
+
             dirty_vram->begin_pfn = begin_pfn;
             dirty_vram->end_pfn = begin_pfn + nr;
 
             paging_unlock(d);
 
+            if ( oend > ostart )
+                p2m_change_type_range(d, ostart, oend,
+                                      p2m_ram_logdirty, p2m_ram_rw);
+

Does this (and the simlar change below) not risk losing updates if we're in full log-dirty mode? I think it should be fine to leave those entries as log-dirty, since at worst they'll provoke another fault-and-fixup.

xen/arch/x86/mm/p2m.c static int p2m_init_hostp2m(struct domai · line 120

Quoted 10 lines
xen/arch/x86/mm/p2m.c +2 -2
@@ -116,8 +116,14 @@ static int p2m_init_hostp2m(struct domai
 
     if ( p2m )
     {
-        d->arch.p2m = p2m;
-        return 0;
+        p2m->logdirty_ranges = rangeset_new(d, "log-dirty",
+                                            RANGESETF_prettyprint_hex);

Is there anything the guest can do to cause this rangeset to grow very large? Like moving its video RAM around?

xen/arch/x86/mm/p2m.c static int p2m_init_hostp2m(struct domai

Quoted 10 lines
xen/arch/x86/mm/p2m.c +9 -0
+/*
+ * Resolve deliberately mis-configured (EMT field set to an invalid value)
+ * entries in the page table hierarchy for the given GFN:
+ * - calculate the correct value for the EMT field
+ * - if marked so, re-calculate the P2M type
+ * - propagate EMT and re-calculation flag down to the next page table level
+ *   for entries not involved in the translation of the given GFN
+ */
+static int resolve_misconfig(struct p2m_domain *p2m, unsigned long gfn)
 {

Please document the different return values here as well.

xen/arch/x86/mm/p2m.c

Quoted 3 lines
xen/arch/x86/mm/p2m.c +1 -1
-    return !!okay;
+    return rc >= !spurious;

Please just write out this logic in a human-readable way. The compiler will DTRT. :)

Quoted 4 lines

}

/*

xen/arch/x86/mm/p2m.c ept_set_entry(struct p2m_domain *p2m, un · line 477

Quoted 10 lines
xen/arch/x86/mm/p2m.c +1 -2
@@ -416,12 +470,11 @@ ept_set_entry(struct p2m_domain *p2m, un
     unsigned long gfn_remainder = gfn;
     int i, target = order / EPT_TABLE_ORDER;
     int rc = 0;
-    int ret = 0;
     bool_t direct_mmio = (p2mt == p2m_mmio_direct);
     uint8_t ipat = 0;
     int need_modify_vtd_table = 1;
     int vtd_pte_present = 0;
-    int needs_sync = 1;
+    int ret, needs_sync = -1;

Hmmm, another tristate. I find these hard to follow, esp. without comments to say which non-zero value is which. I wonder if we could add some sort of framework for these to make them clearer. Ideally we'd have an enum-like type and rely on the compiler to DTRT about optimizing the tests.

In this case, where needs_sync isn't being passed as a return value, I think we'd be fine with two booleans in place of this int.

And more generally, I would like to see at least a comment on every new instance of this trick before I ack it in x86/mm code.

Cheers,

Tim.

#3 lore raw

Re: [PATCH v2 1/6] x86/EPT: don't walk entire page tables when globally changing types

Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 24.04.14 at 17:41, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
xen/arch/x86/mm/hap/hap.c +3 -0
@@ -110,11 +110,18 @@ int hap_track_dirty_vram(struct domain *
         if ( begin_pfn != dirty_vram->begin_pfn ||
              begin_pfn + nr != dirty_vram->end_pfn )
         {
+            unsigned long ostart = dirty_vram->begin_pfn;
+            unsigned long oend = dirty_vram->end_pfn;
+
             dirty_vram->begin_pfn = begin_pfn;
             dirty_vram->end_pfn = begin_pfn + nr;
 
             paging_unlock(d);
 
Quoted 9 lines

xen/arch/x86/mm/hap/hap.c int hap_track_dirty_vram(struct domain * · line 124

Quoted 4 lines
xen/arch/x86/mm/hap/hap.c +4 -0
+            if ( oend > ostart )
+                p2m_change_type_range(d, ostart, oend,
+                                      p2m_ram_logdirty, p2m_ram_rw);
+

Does this (and the simlar change below) not risk losing updates if we're in full log-dirty mode? I think it should be fine to leave those entries as log-dirty, since at worst they'll provoke another fault-and-fixup.

I don't think any updates can be lost: When their types get re- calculated, p2m_is_logdirty_range() (taking p2m->global_logdirty into account) will still cause them to become p2m_ram_logdirty again.

And these are needed mainly because ...

Quoted 4 lines
Quoted 4 lines
xen/arch/x86/mm/p2m.c +0 -0
@@ -116,8 +116,14 @@ static int p2m_init_hostp2m(struct domai
 
Quoted 9 lines

xen/arch/x86/mm/p2m.c static int p2m_init_hostp2m(struct domai · line 120

Quoted 6 lines
xen/arch/x86/mm/p2m.c +2 -2
     if ( p2m )
     {
-        d->arch.p2m = p2m;
-        return 0;
+        p2m->logdirty_ranges = rangeset_new(d, "log-dirty",
+                                            RANGESETF_prettyprint_hex);

Is there anything the guest can do to cause this rangeset to grow very large? Like moving its video RAM around?

... we need to avoid this. If there was ever something added that could cause multiple such regions to be created, we'd need to add an upper limit on the number of permissible ranges. But there can only be one VRAM region right now, so we're safe.

Quoted 18 lines

xen/arch/x86/mm/p2m.c ept_set_entry(struct p2m_domain *p2m, un · line 477

Quoted 11 lines
xen/arch/x86/mm/p2m.c +1 -2
@@ -416,12 +470,11 @@ ept_set_entry(struct p2m_domain *p2m, un
     unsigned long gfn_remainder = gfn;
     int i, target = order / EPT_TABLE_ORDER;
     int rc = 0;
-    int ret = 0;
     bool_t direct_mmio = (p2mt == p2m_mmio_direct);
     uint8_t ipat = 0;
     int need_modify_vtd_table = 1;
     int vtd_pte_present = 0;
-    int needs_sync = 1;
+    int ret, needs_sync = -1;

Hmmm, another tristate. I find these hard to follow, esp. without comments to say which non-zero value is which. I wonder if we could add some sort of framework for these to make them clearer. Ideally we'd have an enum-like type and rely on the compiler to DTRT about optimizing the tests.

Quoted 2 lines

In this case, where needs_sync isn't being passed as a return value, I think we'd be fine with two booleans in place of this int.

I guess I'll make these tristates distinct enums then...

Jan

#4 lore raw

Re: [PATCH v2 1/6] x86/EPT: don't walk entire page tables when globally changing types

Quoted 26 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 24.04.14 at 17:41, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
xen/arch/x86/mm/hap/hap.c +3 -0
@@ -110,11 +110,18 @@ int hap_track_dirty_vram(struct domain *
         if ( begin_pfn != dirty_vram->begin_pfn ||
              begin_pfn + nr != dirty_vram->end_pfn )
         {
+            unsigned long ostart = dirty_vram->begin_pfn;
+            unsigned long oend = dirty_vram->end_pfn;
+
             dirty_vram->begin_pfn = begin_pfn;
             dirty_vram->end_pfn = begin_pfn + nr;
 
             paging_unlock(d);
 
Quoted 9 lines

xen/arch/x86/mm/hap/hap.c int hap_track_dirty_vram(struct domain * · line 124

Quoted 4 lines
xen/arch/x86/mm/hap/hap.c +4 -0
+            if ( oend > ostart )
+                p2m_change_type_range(d, ostart, oend,
+                                      p2m_ram_logdirty, p2m_ram_rw);
+

Does this (and the simlar change below) not risk losing updates if we're in full log-dirty mode? I think it should be fine to leave those entries as log-dirty, since at worst they'll provoke another fault-and-fixup.

Quoted 4 lines

I don't think any updates can be lost: When their types get re- calculated, p2m_is_logdirty_range() (taking p2m->global_logdirty into account) will still cause them to become p2m_ram_logdirty again.

Right, I see. That's fine then.

Quoted 4 lines
Quoted 2 lines

In this case, where needs_sync isn't being passed as a return value, I think we'd be fine with two booleans in place of this int.

I guess I'll make these tristates distinct enums then...

Thanks!

Tim.

#5 lore raw

Re: [PATCH v2 1/6] x86/EPT: don't walk entire page tables when globally changing types

In reply to Jan Beulich

xen/include/asm-x86/hvm/vmx/vmx.h typedef union { · line 41

Quoted 8 lines
xen/include/asm-x86/hvm/vmx/vmx.h +1 -1
@@ -38,7 +38,7 @@ typedef union {
         ipat        :   1,  /* bit 6 - Ignore PAT memory type */
         sp          :   1,  /* bit 7 - Is this a superpage? */
         rsvd1       :   2,  /* bits 9:8 - Reserved for future use */
-        avail1      :   1,  /* bit 10 - Software available 1 */
+        recalc      :   1,  /* bit 10 - Software available 1 */

The comment probably needs an update.

#6 lore raw

Re: [PATCH v2 1/6] x86/EPT: don't walk entire page tables when globally changing types

Quoted 12 lines

xen/include/asm-x86/hvm/vmx/vmx.h typedef union { · line 41

Quoted 9 lines
Quoted 1 line · On 25.04.14 at 21:37, <[email protected]> wrote:

--- a/xen/include/asm-x86/hvm/vmx/vmx.h
+++ b/xen/include/asm-x86/hvm/vmx/vmx.h

xen/include/asm-x86/hvm/vmx/vmx.h +1 -1
@@ -38,7 +38,7 @@ typedef union {
         ipat        :   1,  /* bit 6 - Ignore PAT memory type */
         sp          :   1,  /* bit 7 - Is this a superpage? */
         rsvd1       :   2,  /* bits 9:8 - Reserved for future use */
-        avail1      :   1,  /* bit 10 - Software available 1 */
+        recalc      :   1,  /* bit 10 - Software available 1 */

The comment probably needs an update.

Not sure - I intentionally left it as it was, explaining the meaning it's being given by the specification, matching e.g. the comment on sa_p2mt.

Jan

#7 lore raw

PATCH v2 2/6 x86/EPT: don't walk entire page tables when changing types on a range

In reply to Jan Beulich

This requires a new P2M backend hook and a little bit of extra care on accounting in the generic function.

Note that even on leaf entries we must not immediately set the new type (in an attempt to avoid the EPT_MISCONFIG VM exits), since the global accounting in p2m_change_type_range() gets intentionally done only after updating page tables (or else the update there would conflict with the function's own use of p2m_is_logdirty_range()), and the correct type can only be calculated with that in place.

xen/arch/x86/mm/p2m.c +26 -4
@@ -730,17 +730,33 @@ void p2m_change_type_range(struct domain
 {
     p2m_access_t a;
     p2m_type_t pt;
-    unsigned long gfn;
+    unsigned long gfn = start;
     mfn_t mfn;
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
     int rc = 0;
 
-    BUG_ON(p2m_is_grant(ot) || p2m_is_grant(nt));
+    ASSERT(ot != nt);
+    ASSERT(p2m_is_changeable(ot) && p2m_is_changeable(nt));
 
     p2m_lock(p2m);
     p2m->defer_nested_flush = 1;
 
-    for ( gfn = start; gfn < end; )
+    if ( unlikely(end > p2m->max_mapped_pfn) )
+    {
+        if ( !gfn )
+        {
+            p2m->change_entry_type_global(p2m, ot, nt);
+            gfn = end;
+        }
+        end = p2m->max_mapped_pfn + 1;
+    }
+
+    if ( gfn < end && p2m->change_entry_type_range )
+    {
+        rc = p2m->change_entry_type_range(p2m, ot, nt, gfn, end - 1);
+        gfn = end;
+    }
+    while ( !rc && gfn < end )
     {
         unsigned int order;
 
@@ -769,12 +785,18 @@ void p2m_change_type_range(struct domain
                 order = PAGE_ORDER_4K;
         }
         if ( pt == ot )
-            p2m_set_entry(p2m, gfn, mfn, order, nt, a);
+            rc = p2m_set_entry(p2m, gfn, mfn, order, nt, a);
         gfn += 1UL << order;
         gfn &= -1UL << order;
         if ( !gfn )
             break;
     }
+    if ( rc )
+    {
+        printk(XENLOG_G_ERR "Error %d changing Dom%d GFNs [%lx,%lx] from %d to %d\n",
+               rc, d->domain_id, start, end - 1, ot, nt);
+        domain_crash(d);
+    }
 
     switch ( nt )
     {
xen/arch/x86/mm/p2m-ept.c +117 -0

135 lines not on this page · raw message

xen/include/asm-x86/p2m.h +4 -0
@@ -243,6 +243,10 @@ struct p2m_domain {
     void               (*change_entry_type_global)(struct p2m_domain *p2m,
                                                    p2m_type_t ot,
                                                    p2m_type_t nt);
+    int                (*change_entry_type_range)(struct p2m_domain *p2m,
+                                                  p2m_type_t ot, p2m_type_t nt,
+                                                  unsigned long first_gfn,
+                                                  unsigned long last_gfn);
     void               (*memory_type_changed)(struct p2m_domain *p2m);
     
     void               (*write_p2m_entry)(struct p2m_domain *p2m,

x86/EPT: don't walk entire page tables when changing types on a range

This requires a new P2M backend hook and a little bit of extra care on accounting in the generic function.

Note that even on leaf entries we must not immediately set the new type (in an attempt to avoid the EPT_MISCONFIG VM exits), since the global accounting in p2m_change_type_range() gets intentionally done only after updating page tables (or else the update there would conflict with the function's own use of p2m_is_logdirty_range()), and the correct type can only be calculated with that in place.

xen/arch/x86/mm/p2m.c +26 -4
@@ -730,17 +730,33 @@ void p2m_change_type_range(struct domain
 {
     p2m_access_t a;
     p2m_type_t pt;
-    unsigned long gfn;
+    unsigned long gfn = start;
     mfn_t mfn;
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
     int rc = 0;
 
-    BUG_ON(p2m_is_grant(ot) || p2m_is_grant(nt));
+    ASSERT(ot != nt);
+    ASSERT(p2m_is_changeable(ot) && p2m_is_changeable(nt));
 
     p2m_lock(p2m);
     p2m->defer_nested_flush = 1;
 
-    for ( gfn = start; gfn < end; )
+    if ( unlikely(end > p2m->max_mapped_pfn) )
+    {
+        if ( !gfn )
+        {
+            p2m->change_entry_type_global(p2m, ot, nt);
+            gfn = end;
+        }
+        end = p2m->max_mapped_pfn + 1;
+    }
+
+    if ( gfn < end && p2m->change_entry_type_range )
+    {
+        rc = p2m->change_entry_type_range(p2m, ot, nt, gfn, end - 1);
+        gfn = end;
+    }
+    while ( !rc && gfn < end )
     {
         unsigned int order;
 
@@ -769,12 +785,18 @@ void p2m_change_type_range(struct domain
                 order = PAGE_ORDER_4K;
         }
         if ( pt == ot )
-            p2m_set_entry(p2m, gfn, mfn, order, nt, a);
+            rc = p2m_set_entry(p2m, gfn, mfn, order, nt, a);
         gfn += 1UL << order;
         gfn &= -1UL << order;
         if ( !gfn )
             break;
     }
+    if ( rc )
+    {
+        printk(XENLOG_G_ERR "Error %d changing Dom%d GFNs [%lx,%lx] from %d to %d\n",
+               rc, d->domain_id, start, end - 1, ot, nt);
+        domain_crash(d);
+    }
 
     switch ( nt )
     {
xen/arch/x86/mm/p2m-ept.c +117 -0

135 lines not on this page · raw message

xen/include/asm-x86/p2m.h +4 -0
@@ -243,6 +243,10 @@ struct p2m_domain {
     void               (*change_entry_type_global)(struct p2m_domain *p2m,
                                                    p2m_type_t ot,
                                                    p2m_type_t nt);
+    int                (*change_entry_type_range)(struct p2m_domain *p2m,
+                                                  p2m_type_t ot, p2m_type_t nt,
+                                                  unsigned long first_gfn,
+                                                  unsigned long last_gfn);
     void               (*memory_type_changed)(struct p2m_domain *p2m);
     
     void               (*write_p2m_entry)(struct p2m_domain *p2m,

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Reviewed-by on v2 2/6
#8 lore raw

Re: [PATCH v2 2/6] x86/EPT: don't walk entire page tables when changing types on a range

Quoted 11 lines · Jan Beulich

This requires a new P2M backend hook and a little bit of extra care on accounting in the generic function.

Note that even on leaf entries we must not immediately set the new type (in an attempt to avoid the EPT_MISCONFIG VM exits), since the global accounting in p2m_change_type_range() gets intentionally done only after updating page tables (or else the update there would conflict with the function's own use of p2m_is_logdirty_range()), and the correct type can only be calculated with that in place.

Looks good, once 1/6 is ready.

#9 lore raw

PATCH v2 3/6 x86/P2M: simplify write_p2m_entry()

In reply to Jan Beulich

The "table_mfn" parameter really isn't needed anywhere, so it gets dropped.

The "struct vcpu *" one was always bogus (as was being made up by paging_write_p2m_entry()), and is not commonly used. It can be easily enough made up in the one place (sh_unshadow_for_p2m_change()) it is needed, and we can otherwise pass "struct domain *" instead, properly reflecting that P2M operations are per-domain.

xen/arch/x86/mm/hap/hap.c +2 -3
@@ -695,10 +695,9 @@ static void hap_update_paging_modes(stru
 }
 
 static void
-hap_write_p2m_entry(struct vcpu *v, unsigned long gfn, l1_pgentry_t *p,
-                    mfn_t table_mfn, l1_pgentry_t new, unsigned int level)
+hap_write_p2m_entry(struct domain *d, unsigned long gfn, l1_pgentry_t *p,
+                    l1_pgentry_t new, unsigned int level)
 {
-    struct domain *d = v->domain;
     uint32_t old_flags;
     bool_t flush_nestedp2m = 0;
 
xen/arch/x86/mm/hap/nested_hap.c +1 -1
@@ -79,7 +79,7 @@
 
 void
 nestedp2m_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn,
-    l1_pgentry_t *p, mfn_t table_mfn, l1_pgentry_t new, unsigned int level)
+    l1_pgentry_t *p, l1_pgentry_t new, unsigned int level)
 {
     struct domain *d = p2m->domain;
     uint32_t old_flags;
xen/arch/x86/mm/p2m-pt.c +21 -25

149 lines not on this page · raw message

xen/arch/x86/mm/paging.c +3 -6
@@ -724,18 +724,15 @@ void paging_update_nestedmode(struct vcp
 }
 
 void paging_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn,
-                            l1_pgentry_t *p, mfn_t table_mfn,
-                            l1_pgentry_t new, unsigned int level)
+                            l1_pgentry_t *p, l1_pgentry_t new,
+                            unsigned int level)
 {
     struct domain *d = p2m->domain;
     struct vcpu *v = current;
     if ( v->domain != d )
         v = d->vcpu ? d->vcpu[0] : NULL;
     if ( likely(v && paging_mode_enabled(d) && paging_get_hostmode(v) != NULL) )
-    {
-        return paging_get_hostmode(v)->write_p2m_entry(v, gfn, p, table_mfn,
-                                                       new, level);
-    }
+        paging_get_hostmode(v)->write_p2m_entry(d, gfn, p, new, level);
     else
         safe_write_pte(p, new);
 }
xen/arch/x86/mm/shadow/common.c +11 -10
@@ -3310,11 +3310,14 @@ static int shadow_test_disable(struct do
  * shadow processing jobs.
  */
 
-static void sh_unshadow_for_p2m_change(struct vcpu *v, unsigned long gfn, 
-                                       l1_pgentry_t *p, mfn_t table_mfn, 
-                                       l1_pgentry_t new, unsigned int level)
+static void sh_unshadow_for_p2m_change(struct domain *d, unsigned long gfn,
+                                       l1_pgentry_t *p, l1_pgentry_t new,
+                                       unsigned int level)
 {
-    struct domain *d = v->domain;
+    struct vcpu *v = current;
+
+    if ( v->domain != d )
+        v = d->vcpu ? d->vcpu[0] : NULL;
 
     /* The following assertion is to make sure we don't step on 1GB host
      * page support of HVM guest. */
@@ -3379,18 +3382,16 @@ static void sh_unshadow_for_p2m_change(s
 }
 
 void
-shadow_write_p2m_entry(struct vcpu *v, unsigned long gfn, 
-                       l1_pgentry_t *p, mfn_t table_mfn, 
-                       l1_pgentry_t new, unsigned int level)
+shadow_write_p2m_entry(struct domain *d, unsigned long gfn,
+                       l1_pgentry_t *p, l1_pgentry_t new,
+                       unsigned int level)
 {
-    struct domain *d = v->domain;
-    
     paging_lock(d);
 
     /* If there are any shadows, update them.  But if shadow_teardown()
      * has already been called then it's not safe to try. */ 
     if ( likely(d->arch.paging.shadow.total_pages != 0) )
-         sh_unshadow_for_p2m_change(v, gfn, p, table_mfn, new, level);
+         sh_unshadow_for_p2m_change(d, gfn, p, new, level);
 
     /* Update the entry with new content */
     safe_write_pte(p, new);
xen/arch/x86/mm/shadow/private.h +3 -3
@@ -359,9 +359,9 @@ extern int sh_remove_write_access(struct
                                   unsigned long fault_addr);
 
 /* Functions that atomically write PT/P2M entries and update state */
-void shadow_write_p2m_entry(struct vcpu *v, unsigned long gfn, 
-                            l1_pgentry_t *p, mfn_t table_mfn,
-                            l1_pgentry_t new, unsigned int level);
+void shadow_write_p2m_entry(struct domain *d, unsigned long gfn,
+                            l1_pgentry_t *p, l1_pgentry_t new,
+                            unsigned int level);
 int shadow_write_guest_entry(struct vcpu *v, intpte_t *p,
                              intpte_t new, mfn_t gmfn);
 int shadow_cmpxchg_guest_entry(struct vcpu *v, intpte_t *p,
xen/include/asm-x86/p2m.h +2 -3
@@ -251,8 +251,7 @@ struct p2m_domain {
     
     void               (*write_p2m_entry)(struct p2m_domain *p2m,
                                           unsigned long gfn, l1_pgentry_t *p,
-                                          mfn_t table_mfn, l1_pgentry_t new,
-                                          unsigned int level);
+                                          l1_pgentry_t new, unsigned int level);
     long               (*audit_p2m)(struct p2m_domain *p2m);
 
     /* Default P2M access type for each page in the the domain: new pages,
@@ -679,7 +678,7 @@ void p2m_flush(struct vcpu *v, struct p2
 void p2m_flush_nestedp2m(struct domain *d);
 
 void nestedp2m_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn,
-    l1_pgentry_t *p, mfn_t table_mfn, l1_pgentry_t new, unsigned int level);
+    l1_pgentry_t *p, l1_pgentry_t new, unsigned int level);
 
 #endif /* _XEN_P2M_H */
 
xen/include/asm-x86/paging.h +5 -6
@@ -111,9 +111,8 @@ struct paging_mode {
                                             unsigned int *page_order);
     void          (*update_cr3            )(struct vcpu *v, int do_locking);
     void          (*update_paging_modes   )(struct vcpu *v);
-    void          (*write_p2m_entry       )(struct vcpu *v, unsigned long gfn,
-                                            l1_pgentry_t *p, mfn_t table_mfn, 
-                                            l1_pgentry_t new, 
+    void          (*write_p2m_entry       )(struct domain *d, unsigned long gfn,
+                                            l1_pgentry_t *p, l1_pgentry_t new,
                                             unsigned int level);
     int           (*write_guest_entry     )(struct vcpu *v, intpte_t *p,
                                             intpte_t new, mfn_t gmfn);
@@ -335,9 +334,9 @@ static inline void safe_write_pte(l1_pge
  * we are writing. */
 struct p2m_domain;
 
-void paging_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn, 
-                            l1_pgentry_t *p, mfn_t table_mfn,
-                            l1_pgentry_t new, unsigned int level);
+void paging_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn,
+                            l1_pgentry_t *p, l1_pgentry_t new,
+                            unsigned int level);
 
 /* Called from the guest to indicate that the a process is being
  * torn down and its pagetables will soon be discarded */

x86/P2M: simplify write_p2m_entry()

The "table_mfn" parameter really isn't needed anywhere, so it gets dropped.

The "struct vcpu *" one was always bogus (as was being made up by paging_write_p2m_entry()), and is not commonly used. It can be easily enough made up in the one place (sh_unshadow_for_p2m_change()) it is needed, and we can otherwise pass "struct domain *" instead, properly reflecting that P2M operations are per-domain.

xen/arch/x86/mm/hap/hap.c +2 -3
@@ -695,10 +695,9 @@ static void hap_update_paging_modes(stru
 }
 
 static void
-hap_write_p2m_entry(struct vcpu *v, unsigned long gfn, l1_pgentry_t *p,
-                    mfn_t table_mfn, l1_pgentry_t new, unsigned int level)
+hap_write_p2m_entry(struct domain *d, unsigned long gfn, l1_pgentry_t *p,
+                    l1_pgentry_t new, unsigned int level)
 {
-    struct domain *d = v->domain;
     uint32_t old_flags;
     bool_t flush_nestedp2m = 0;
 
xen/arch/x86/mm/hap/nested_hap.c +1 -1
@@ -79,7 +79,7 @@
 
 void
 nestedp2m_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn,
-    l1_pgentry_t *p, mfn_t table_mfn, l1_pgentry_t new, unsigned int level)
+    l1_pgentry_t *p, l1_pgentry_t new, unsigned int level)
 {
     struct domain *d = p2m->domain;
     uint32_t old_flags;
xen/arch/x86/mm/p2m-pt.c +21 -25

149 lines not on this page · raw message

xen/arch/x86/mm/paging.c +3 -6
@@ -724,18 +724,15 @@ void paging_update_nestedmode(struct vcp
 }
 
 void paging_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn,
-                            l1_pgentry_t *p, mfn_t table_mfn,
-                            l1_pgentry_t new, unsigned int level)
+                            l1_pgentry_t *p, l1_pgentry_t new,
+                            unsigned int level)
 {
     struct domain *d = p2m->domain;
     struct vcpu *v = current;
     if ( v->domain != d )
         v = d->vcpu ? d->vcpu[0] : NULL;
     if ( likely(v && paging_mode_enabled(d) && paging_get_hostmode(v) != NULL) )
-    {
-        return paging_get_hostmode(v)->write_p2m_entry(v, gfn, p, table_mfn,
-                                                       new, level);
-    }
+        paging_get_hostmode(v)->write_p2m_entry(d, gfn, p, new, level);
     else
         safe_write_pte(p, new);
 }
xen/arch/x86/mm/shadow/common.c +11 -10
@@ -3310,11 +3310,14 @@ static int shadow_test_disable(struct do
  * shadow processing jobs.
  */
 
-static void sh_unshadow_for_p2m_change(struct vcpu *v, unsigned long gfn, 
-                                       l1_pgentry_t *p, mfn_t table_mfn, 
-                                       l1_pgentry_t new, unsigned int level)
+static void sh_unshadow_for_p2m_change(struct domain *d, unsigned long gfn,
+                                       l1_pgentry_t *p, l1_pgentry_t new,
+                                       unsigned int level)
 {
-    struct domain *d = v->domain;
+    struct vcpu *v = current;
+
+    if ( v->domain != d )
+        v = d->vcpu ? d->vcpu[0] : NULL;
 
     /* The following assertion is to make sure we don't step on 1GB host
      * page support of HVM guest. */
@@ -3379,18 +3382,16 @@ static void sh_unshadow_for_p2m_change(s
 }
 
 void
-shadow_write_p2m_entry(struct vcpu *v, unsigned long gfn, 
-                       l1_pgentry_t *p, mfn_t table_mfn, 
-                       l1_pgentry_t new, unsigned int level)
+shadow_write_p2m_entry(struct domain *d, unsigned long gfn,
+                       l1_pgentry_t *p, l1_pgentry_t new,
+                       unsigned int level)
 {
-    struct domain *d = v->domain;
-    
     paging_lock(d);
 
     /* If there are any shadows, update them.  But if shadow_teardown()
      * has already been called then it's not safe to try. */ 
     if ( likely(d->arch.paging.shadow.total_pages != 0) )
-         sh_unshadow_for_p2m_change(v, gfn, p, table_mfn, new, level);
+         sh_unshadow_for_p2m_change(d, gfn, p, new, level);
 
     /* Update the entry with new content */
     safe_write_pte(p, new);
xen/arch/x86/mm/shadow/private.h +3 -3
@@ -359,9 +359,9 @@ extern int sh_remove_write_access(struct
                                   unsigned long fault_addr);
 
 /* Functions that atomically write PT/P2M entries and update state */
-void shadow_write_p2m_entry(struct vcpu *v, unsigned long gfn, 
-                            l1_pgentry_t *p, mfn_t table_mfn,
-                            l1_pgentry_t new, unsigned int level);
+void shadow_write_p2m_entry(struct domain *d, unsigned long gfn,
+                            l1_pgentry_t *p, l1_pgentry_t new,
+                            unsigned int level);
 int shadow_write_guest_entry(struct vcpu *v, intpte_t *p,
                              intpte_t new, mfn_t gmfn);
 int shadow_cmpxchg_guest_entry(struct vcpu *v, intpte_t *p,
xen/include/asm-x86/p2m.h +2 -3
@@ -251,8 +251,7 @@ struct p2m_domain {
     
     void               (*write_p2m_entry)(struct p2m_domain *p2m,
                                           unsigned long gfn, l1_pgentry_t *p,
-                                          mfn_t table_mfn, l1_pgentry_t new,
-                                          unsigned int level);
+                                          l1_pgentry_t new, unsigned int level);
     long               (*audit_p2m)(struct p2m_domain *p2m);
 
     /* Default P2M access type for each page in the the domain: new pages,
@@ -679,7 +678,7 @@ void p2m_flush(struct vcpu *v, struct p2
 void p2m_flush_nestedp2m(struct domain *d);
 
 void nestedp2m_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn,
-    l1_pgentry_t *p, mfn_t table_mfn, l1_pgentry_t new, unsigned int level);
+    l1_pgentry_t *p, l1_pgentry_t new, unsigned int level);
 
 #endif /* _XEN_P2M_H */
 
xen/include/asm-x86/paging.h +5 -6
@@ -111,9 +111,8 @@ struct paging_mode {
                                             unsigned int *page_order);
     void          (*update_cr3            )(struct vcpu *v, int do_locking);
     void          (*update_paging_modes   )(struct vcpu *v);
-    void          (*write_p2m_entry       )(struct vcpu *v, unsigned long gfn,
-                                            l1_pgentry_t *p, mfn_t table_mfn, 
-                                            l1_pgentry_t new, 
+    void          (*write_p2m_entry       )(struct domain *d, unsigned long gfn,
+                                            l1_pgentry_t *p, l1_pgentry_t new,
                                             unsigned int level);
     int           (*write_guest_entry     )(struct vcpu *v, intpte_t *p,
                                             intpte_t new, mfn_t gmfn);
@@ -335,9 +334,9 @@ static inline void safe_write_pte(l1_pge
  * we are writing. */
 struct p2m_domain;
 
-void paging_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn, 
-                            l1_pgentry_t *p, mfn_t table_mfn,
-                            l1_pgentry_t new, unsigned int level);
+void paging_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn,
+                            l1_pgentry_t *p, l1_pgentry_t new,
+                            unsigned int level);
 
 /* Called from the guest to indicate that the a process is being
  * torn down and its pagetables will soon be discarded */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Reviewed-by on v2 3/6
#10 lore raw

Re: [PATCH v2 3/6] x86/P2M: simplify write_p2m_entry()

Quoted 10 lines · Jan Beulich

The "table_mfn" parameter really isn't needed anywhere, so it gets dropped.

The "struct vcpu *" one was always bogus (as was being made up by paging_write_p2m_entry()), and is not commonly used. It can be easily enough made up in the one place (sh_unshadow_for_p2m_change()) it is needed, and we can otherwise pass "struct domain *" instead, properly reflecting that P2M operations are per-domain.

and I think should be applicable independent of the rest of the series.

Cheers,

Tim.

#11 lore raw

Re: [PATCH v2 3/6] x86/P2M: simplify write_p2m_entry()

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 24.04.14 at 18:00, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich

The "table_mfn" parameter really isn't needed anywhere, so it gets dropped.

The "struct vcpu *" one was always bogus (as was being made up by paging_write_p2m_entry()), and is not commonly used. It can be easily enough made up in the one place (sh_unshadow_for_p2m_change()) it is needed, and we can otherwise pass "struct domain *" instead, properly reflecting that P2M operations are per-domain.

Quoted 6 lines
Quoted 1 line

and I think should be applicable independent of the rest of the series.

Yes indeed, all that is required is that it precedes the NPT patches. I guess I'll commit it some time tomorrow unless you tell me otherwise.

Jan

#12 lore raw

PATCH v2 4/6 x86/NPT: don't walk entire page tables when changing types on a range

In reply to Jan Beulich

This builds on the fact that in order for no NPF VM exit to occur, _PAGE_USER must always be set. I.e. by clearing the flag we can force a VM exit allowing us to do similar lazy type changes as on EPT.

That way, the generic entry-wise code can go away, and we could remove the range restriction in enforced on HVMOP_track_dirty_vram for XSA-27.

xen/arch/x86/hvm/svm/svm.c +10 -1
@@ -2557,7 +2557,16 @@ void svm_vmexit_handler(struct cpu_user_
         perfc_incra(svmexits, VMEXIT_NPF_PERFC);
         if ( cpu_has_svm_decode )
             v->arch.hvm_svm.cached_insn_len = vmcb->guest_ins_len & 0xf;
-        svm_do_nested_pgfault(v, regs, vmcb->exitinfo1, vmcb->exitinfo2);
+        rc = p2m_npt_fault(vmcb->exitinfo2);
+        if ( rc >= 0 )
+            svm_do_nested_pgfault(v, regs, vmcb->exitinfo1, vmcb->exitinfo2);
+        else
+        {
+            printk(XENLOG_G_ERR
+                   "%pv: Error %d handling NPF (gpa=%08lx ec=%04lx)\n",
+                   v, rc, vmcb->exitinfo2, vmcb->exitinfo1);
+            domain_crash(v->domain);
+        }
         v->arch.hvm_svm.cached_insn_len = 0;
         break;
 
xen/arch/x86/mm/p2m.c +1 -43

58 lines not on this page · raw message

xen/arch/x86/mm/p2m-pt.c +282 -13

400 lines not on this page · raw message

xen/include/asm-x86/p2m.h +2 -0
@@ -668,6 +668,8 @@ static inline p2m_type_t p2m_flags_to_ty
     return (flags >> 12) & 0x7f;
 }
 
+int p2m_npt_fault(uint64_t gpa);
+
 /*
  * Nested p2m: shadow p2m tables used for nested HVM virtualization 
  */

x86/NPT: don't walk entire page tables when changing types on a range

This builds on the fact that in order for no NPF VM exit to occur, _PAGE_USER must always be set. I.e. by clearing the flag we can force a VM exit allowing us to do similar lazy type changes as on EPT.

That way, the generic entry-wise code can go away, and we could remove the range restriction in enforced on HVMOP_track_dirty_vram for XSA-27.

xen/arch/x86/hvm/svm/svm.c +10 -1
@@ -2557,7 +2557,16 @@ void svm_vmexit_handler(struct cpu_user_
         perfc_incra(svmexits, VMEXIT_NPF_PERFC);
         if ( cpu_has_svm_decode )
             v->arch.hvm_svm.cached_insn_len = vmcb->guest_ins_len & 0xf;
-        svm_do_nested_pgfault(v, regs, vmcb->exitinfo1, vmcb->exitinfo2);
+        rc = p2m_npt_fault(vmcb->exitinfo2);
+        if ( rc >= 0 )
+            svm_do_nested_pgfault(v, regs, vmcb->exitinfo1, vmcb->exitinfo2);
+        else
+        {
+            printk(XENLOG_G_ERR
+                   "%pv: Error %d handling NPF (gpa=%08lx ec=%04lx)\n",
+                   v, rc, vmcb->exitinfo2, vmcb->exitinfo1);
+            domain_crash(v->domain);
+        }
         v->arch.hvm_svm.cached_insn_len = 0;
         break;
 
xen/arch/x86/mm/p2m.c +1 -43

58 lines not on this page · raw message

xen/arch/x86/mm/p2m-pt.c +282 -13

400 lines not on this page · raw message

xen/include/asm-x86/p2m.h +2 -0
@@ -668,6 +668,8 @@ static inline p2m_type_t p2m_flags_to_ty
     return (flags >> 12) & 0x7f;
 }
 
+int p2m_npt_fault(uint64_t gpa);
+
 /*
  * Nested p2m: shadow p2m tables used for nested HVM virtualization 
  */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#13 lore raw

Re: [PATCH v2 4/6] x86/NPT: don't walk entire page tables when changing types on a range

Quoted 12 lines · Jan Beulich

This builds on the fact that in order for no NPF VM exit to occur, _PAGE_USER must always be set. I.e. by clearing the flag we can force a VM exit allowing us to do similar lazy type changes as on EPT.

That way, the generic entry-wise code can go away, and we could remove the range restriction in enforced on HVMOP_track_dirty_vram for XSA-27.

xen/arch/x86/hvm/svm/svm.c void svm_vmexit_handler(struct cpu_user_ · line 2560

Quoted 5 lines
xen/arch/x86/hvm/svm/svm.c +1 -1
@@ -2557,7 +2557,16 @@ void svm_vmexit_handler(struct cpu_user_
         perfc_incra(svmexits, VMEXIT_NPF_PERFC);
         if ( cpu_has_svm_decode )
             v->arch.hvm_svm.cached_insn_len = vmcb->guest_ins_len & 0xf;
-        svm_do_nested_pgfault(v, regs, vmcb->exitinfo1, vmcb->exitinfo2);
+        rc = p2m_npt_fault(vmcb->exitinfo2);

Can we limit the classes of fault that we need to check for recalc on? e.g. if bit 0 of the error code is clear, then the page is not mapped at all.

I'm unsure about having two different fixup paths here anyway -- one for log-dirty and one for everything else (PoD, sharing &c). This call should probably go _inside_ svm_do_nested_pgfault() at least.

Also, maybe it wants a more descriptive name than p2m_npt_fault(). p2m_pt_hnadle_misconfig(), to match the EPT equivalent?

Quoted 30 lines
xen/arch/x86/hvm/svm/svm.c +30 -0
+static int p2m_pt_change_entry_type_range(struct p2m_domain *p2m,
+                                          p2m_type_t ot, p2m_type_t nt,
+                                          unsigned long first_gfn,
+                                          unsigned long last_gfn)
+{
+    unsigned long mask = (1 << PAGETABLE_ORDER) - 1;
+    unsigned int i;
+    int err = 0;
+
+    ASSERT(hap_enabled(p2m->domain));
+
+    for ( i = 1; i <= 4; )
+    {
+        if ( first_gfn & mask )
+        {
+            unsigned long end_gfn = min(first_gfn | mask, last_gfn);
+
+            err = p2m_pt_set_recalc_range(p2m, i, first_gfn, end_gfn);
+            if ( err || end_gfn >= last_gfn )
+                break;
+            first_gfn = end_gfn + 1;
+        }
+        else if ( (last_gfn & mask) != mask )
+        {
+            unsigned long start_gfn = max(first_gfn, last_gfn & ~mask);
+
+            err = p2m_pt_set_recalc_range(p2m, i, start_gfn, last_gfn);
+            if ( err || start_gfn <= first_gfn )
+                break;
+            last_gfn = start_gfn - 1;

xen/arch/x86/hvm/svm/svm.c void svm_vmexit_handler(struct cpu_user_

Quoted 10 lines
xen/arch/x86/hvm/svm/svm.c +10 -0
+        }
+        else
+        {
+            ++i;
+            mask |= mask << PAGETABLE_ORDER;
+        }
+    }
+
+    return err;
+}

This looks like it could be merged with the EPT equivalent. Or would that be too unwieldy?

Cheers,

Tim.

#14 lore raw

Re: [PATCH v2 4/6] x86/NPT: don't walk entire page tables when changing types on a range

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 24.04.14 at 18:25, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich

This builds on the fact that in order for no NPF VM exit to occur, _PAGE_USER must always be set. I.e. by clearing the flag we can force a VM exit allowing us to do similar lazy type changes as on EPT.

That way, the generic entry-wise code can go away, and we could remove the range restriction in enforced on HVMOP_track_dirty_vram for XSA-27.

Quoted 12 lines

xen/arch/x86/hvm/svm/svm.c void svm_vmexit_handler(struct cpu_user_ · line 2560

Quoted 8 lines
xen/arch/x86/hvm/svm/svm.c +1 -1
@@ -2557,7 +2557,16 @@ void svm_vmexit_handler(struct cpu_user_
         perfc_incra(svmexits, VMEXIT_NPF_PERFC);
         if ( cpu_has_svm_decode )
             v->arch.hvm_svm.cached_insn_len = vmcb->guest_ins_len & 0xf;
-        svm_do_nested_pgfault(v, regs, vmcb->exitinfo1, vmcb->exitinfo2);
+        rc = p2m_npt_fault(vmcb->exitinfo2);

Can we limit the classes of fault that we need to check for recalc on? e.g. if bit 0 of the error code is clear, then the page is not mapped at all.

That's a good suggestion (albeit I'm not sure if there really are frequent faults with P clear - with paging perhaps, but that's a slow path anyway). Ideally we would have an indication that the fault was because of the U bit clear, but sadly that doesn't exist.

Quoted 3 lines

I'm unsure about having two different fixup paths here anyway -- one for log-dirty and one for everything else (PoD, sharing &c). This call should probably go _inside_ svm_do_nested_pgfault() at least.

I intentionally kept it separate, so it's not getting farther away than necessary from how EPT handling is structured.

Quoted 2 lines

Also, maybe it wants a more descriptive name than p2m_npt_fault(). p2m_pt_hnadle_misconfig(), to match the EPT equivalent?

I first considered naming it that way, but it's not really a mis- configuration. But if you think that's a better name despite not describing what it really does, I'm okay changing it...

Quoted 35 lines
Quoted 35 lines
xen/arch/x86/hvm/svm/svm.c +35 -0
+static int p2m_pt_change_entry_type_range(struct p2m_domain *p2m,
+                                          p2m_type_t ot, p2m_type_t nt,
+                                          unsigned long first_gfn,
+                                          unsigned long last_gfn)
+{
+    unsigned long mask = (1 << PAGETABLE_ORDER) - 1;
+    unsigned int i;
+    int err = 0;
+
+    ASSERT(hap_enabled(p2m->domain));
+
+    for ( i = 1; i <= 4; )
+    {
+        if ( first_gfn & mask )
+        {
+            unsigned long end_gfn = min(first_gfn | mask, last_gfn);
+
+            err = p2m_pt_set_recalc_range(p2m, i, first_gfn, end_gfn);
+            if ( err || end_gfn >= last_gfn )
+                break;
+            first_gfn = end_gfn + 1;
+        }
+        else if ( (last_gfn & mask) != mask )
+        {
+            unsigned long start_gfn = max(first_gfn, last_gfn & ~mask);
+
+            err = p2m_pt_set_recalc_range(p2m, i, start_gfn, last_gfn);
+            if ( err || start_gfn <= first_gfn )
+                break;
+            last_gfn = start_gfn - 1;
+        }
+        else
+        {
+            ++i;
+            mask |= mask << PAGETABLE_ORDER;
Quoted 8 lines

xen/arch/x86/hvm/svm/svm.c

Quoted 5 lines
xen/arch/x86/hvm/svm/svm.c +5 -0
+        }
+    }
+
+    return err;
+}

This looks like it could be merged with the EPT equivalent. Or would that be too unwieldy?

I considered unifying both this and/or the helpers of it, but decided that the result would be uglier (too many parameters just to tell one from the other) than the duplication that results from this approach.

Jan

#15 lore raw

Re: [PATCH v2 4/6] x86/NPT: don't walk entire page tables when changing types on a range

Quoted 24 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 24.04.14 at 18:25, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich

This builds on the fact that in order for no NPF VM exit to occur, _PAGE_USER must always be set. I.e. by clearing the flag we can force a VM exit allowing us to do similar lazy type changes as on EPT.

That way, the generic entry-wise code can go away, and we could remove the range restriction in enforced on HVMOP_track_dirty_vram for XSA-27.

Quoted 12 lines

xen/arch/x86/hvm/svm/svm.c void svm_vmexit_handler(struct cpu_user_ · line 2560

Quoted 8 lines
xen/arch/x86/hvm/svm/svm.c +1 -1
@@ -2557,7 +2557,16 @@ void svm_vmexit_handler(struct cpu_user_
         perfc_incra(svmexits, VMEXIT_NPF_PERFC);
         if ( cpu_has_svm_decode )
             v->arch.hvm_svm.cached_insn_len = vmcb->guest_ins_len & 0xf;
-        svm_do_nested_pgfault(v, regs, vmcb->exitinfo1, vmcb->exitinfo2);
+        rc = p2m_npt_fault(vmcb->exitinfo2);

Can we limit the classes of fault that we need to check for recalc on? e.g. if bit 0 of the error code is clear, then the page is not mapped at all.

Quoted 4 lines

That's a good suggestion (albeit I'm not sure if there really are frequent faults with P clear - with paging perhaps, but that's a slow path anyway). Ideally we would have an indication that the fault was because of the U bit clear, but sadly that doesn't exist.

Yeah, that's a shame.

Quoted 6 lines
Quoted 3 lines

I'm unsure about having two different fixup paths here anyway -- one for log-dirty and one for everything else (PoD, sharing &c). This call should probably go _inside_ svm_do_nested_pgfault() at least.

I intentionally kept it separate, so it's not getting farther away than necessary from how EPT handling is structured.

Hmm. Well, in that case I guess it's OK here. The alternative would be to put it right into the HVM nested fault handler and replumb the ERPT path to go the same way, but I can see that would be inefficient...

Quoted 6 lines
Quoted 2 lines

Also, maybe it wants a more descriptive name than p2m_npt_fault(). p2m_pt_hnadle_misconfig(), to match the EPT equivalent?

I first considered naming it that way, but it's not really a mis- configuration. But if you think that's a better name despite not describing what it really does, I'm okay changing it...

I think I do prefer it, but maybe we can find a better name for both of them: {p2m_pt,ept}_handle_deferred_changes()?

Quoted 6 lines
Quoted 2 lines

This looks like it could be merged with the EPT equivalent. Or would that be too unwieldy?

I considered unifying both this and/or the helpers of it, but decided that the result would be uglier (too many parameters just to tell one from the other) than the duplication that results from this approach.

OK, fair enough.

Tim.

#16 lore raw

PATCH v2 5/6 x86/NPT: don't walk entire page tables when globally changing types

In reply to Jan Beulich

Instead leverage the NPF VM exit enforcement by marking just the top level entries as needing recalculation of their type, building on the respective range type change modifications.

xen/arch/x86/mm/p2m.c +4 -0
@@ -214,6 +214,10 @@ void p2m_change_entry_type_global(struct
                                   p2m_type_t ot, p2m_type_t nt)
 {
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
+
+    ASSERT(ot != nt);
+    ASSERT(p2m_is_changeable(ot) && p2m_is_changeable(nt));
+
     p2m_lock(p2m);
     p2m->change_entry_type_global(p2m, ot, nt);
     p2m->global_logdirty = (nt == p2m_ram_logdirty);
xen/arch/x86/mm/p2m-ept.c +1 -3
@@ -879,11 +879,9 @@ static void ept_change_entry_type_global
 {
     unsigned long mfn = ept_get_asr(&p2m->ept);
 
-    if ( !mfn || ot == nt )
+    if ( !mfn )
         return;
 
-    BUG_ON(!p2m_is_changeable(ot) || !p2m_is_changeable(nt));
-
     if ( ept_invalidate_emt(_mfn(mfn), 1) )
         ept_sync_domain(p2m);
 }
xen/arch/x86/mm/p2m-pt.c +16 -98

134 lines not on this page · raw message

x86/NPT: don't walk entire page tables when globally changing types

Instead leverage the NPF VM exit enforcement by marking just the top level entries as needing recalculation of their type, building on the respective range type change modifications.

xen/arch/x86/mm/p2m.c +4 -0
@@ -214,6 +214,10 @@ void p2m_change_entry_type_global(struct
                                   p2m_type_t ot, p2m_type_t nt)
 {
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
+
+    ASSERT(ot != nt);
+    ASSERT(p2m_is_changeable(ot) && p2m_is_changeable(nt));
+
     p2m_lock(p2m);
     p2m->change_entry_type_global(p2m, ot, nt);
     p2m->global_logdirty = (nt == p2m_ram_logdirty);
xen/arch/x86/mm/p2m-ept.c +1 -3
@@ -879,11 +879,9 @@ static void ept_change_entry_type_global
 {
     unsigned long mfn = ept_get_asr(&p2m->ept);
 
-    if ( !mfn || ot == nt )
+    if ( !mfn )
         return;
 
-    BUG_ON(!p2m_is_changeable(ot) || !p2m_is_changeable(nt));
-
     if ( ept_invalidate_emt(_mfn(mfn), 1) )
         ept_sync_domain(p2m);
 }
xen/arch/x86/mm/p2m-pt.c +16 -98

134 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Reviewed-by on v2 5/6
#17 lore raw

Re: [PATCH v2 5/6] x86/NPT: don't walk entire page tables when globally changing types

Quoted 5 lines · Jan Beulich

Instead leverage the NPF VM exit enforcement by marking just the top level entries as needing recalculation of their type, building on the respective range type change modifications.

Cheers,

Tim.

#18 lore raw

PATCH v2 6/6 x86/P2M: cleanup

In reply to Jan Beulich

- don't abuse __PAGE_HYPERVISOR
- don't use bogus constructs like mfn_x(_mfn())

xen/arch/x86/mm/p2m-pt.c +7 -7
@@ -193,7 +193,7 @@ p2m_next_level(struct p2m_domain *p2m, v
             return -ENOMEM;
 
         new_entry = l1e_from_pfn(mfn_x(page_to_mfn(pg)),
-                                 __PAGE_HYPERVISOR | _PAGE_USER);
+                                 P2M_BASE_FLAGS | _PAGE_RW);
 
         switch ( type ) {
         case PGT_l3_page_table:
@@ -229,7 +229,7 @@ p2m_next_level(struct p2m_domain *p2m, v
         flags = l1e_get_flags(*p2m_entry);
         pfn = l1e_get_pfn(*p2m_entry);
 
-        l1_entry = map_domain_page(mfn_x(page_to_mfn(pg)));
+        l1_entry = __map_domain_page(pg);
         for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ )
         {
             new_entry = l1e_from_pfn(pfn + (i * L1_PAGETABLE_ENTRIES), flags);
@@ -238,7 +238,7 @@ p2m_next_level(struct p2m_domain *p2m, v
         }
         unmap_domain_page(l1_entry);
         new_entry = l1e_from_pfn(mfn_x(page_to_mfn(pg)),
-                                 __PAGE_HYPERVISOR|_PAGE_USER); //disable PSE
+                                 P2M_BASE_FLAGS | _PAGE_RW); /* disable PSE */
         p2m_add_iommu_flags(&new_entry, 2, IOMMUF_readable|IOMMUF_writable);
         p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, 3);
     }
@@ -273,7 +273,7 @@ p2m_next_level(struct p2m_domain *p2m, v
         unmap_domain_page(l1_entry);
         
         new_entry = l1e_from_pfn(mfn_x(page_to_mfn(pg)),
-                                 __PAGE_HYPERVISOR|_PAGE_USER);
+                                 P2M_BASE_FLAGS | _PAGE_RW);
         p2m_add_iommu_flags(&new_entry, 1, IOMMUF_readable|IOMMUF_writable);
         p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, 2);
     }
@@ -929,7 +929,7 @@ long p2m_pt_audit_p2m(struct p2m_domain 
                 gfn += 1 << (L4_PAGETABLE_SHIFT - PAGE_SHIFT);
                 continue;
             }
-            l3e = map_domain_page(mfn_x(_mfn(l4e_get_pfn(l4e[i4]))));
+            l3e = map_domain_page(l4e_get_pfn(l4e[i4]));
             for ( i3 = 0;
                   i3 < L3_PAGETABLE_ENTRIES;
                   i3++ )
@@ -964,7 +964,7 @@ long p2m_pt_audit_p2m(struct p2m_domain 
                     }
                 }
 
-                l2e = map_domain_page(mfn_x(_mfn(l3e_get_pfn(l3e[i3]))));
+                l2e = map_domain_page(l3e_get_pfn(l3e[i3]));
                 for ( i2 = 0; i2 < L2_PAGETABLE_ENTRIES; i2++ )
                 {
                     if ( !(l2e_get_flags(l2e[i2]) & _PAGE_PRESENT) )
@@ -1000,7 +1000,7 @@ long p2m_pt_audit_p2m(struct p2m_domain 
                         continue;
                     }
 
-                    l1e = map_domain_page(mfn_x(_mfn(l2e_get_pfn(l2e[i2]))));
+                    l1e = map_domain_page(l2e_get_pfn(l2e[i2]));
 
                     for ( i1 = 0; i1 < L1_PAGETABLE_ENTRIES; i1++, gfn++ )
                     {

x86/P2M: cleanup

- don't abuse __PAGE_HYPERVISOR
- don't use bogus constructs like mfn_x(_mfn())

xen/arch/x86/mm/p2m-pt.c +7 -7
@@ -193,7 +193,7 @@ p2m_next_level(struct p2m_domain *p2m, v
             return -ENOMEM;
 
         new_entry = l1e_from_pfn(mfn_x(page_to_mfn(pg)),
-                                 __PAGE_HYPERVISOR | _PAGE_USER);
+                                 P2M_BASE_FLAGS | _PAGE_RW);
 
         switch ( type ) {
         case PGT_l3_page_table:
@@ -229,7 +229,7 @@ p2m_next_level(struct p2m_domain *p2m, v
         flags = l1e_get_flags(*p2m_entry);
         pfn = l1e_get_pfn(*p2m_entry);
 
-        l1_entry = map_domain_page(mfn_x(page_to_mfn(pg)));
+        l1_entry = __map_domain_page(pg);
         for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ )
         {
             new_entry = l1e_from_pfn(pfn + (i * L1_PAGETABLE_ENTRIES), flags);
@@ -238,7 +238,7 @@ p2m_next_level(struct p2m_domain *p2m, v
         }
         unmap_domain_page(l1_entry);
         new_entry = l1e_from_pfn(mfn_x(page_to_mfn(pg)),
-                                 __PAGE_HYPERVISOR|_PAGE_USER); //disable PSE
+                                 P2M_BASE_FLAGS | _PAGE_RW); /* disable PSE */
         p2m_add_iommu_flags(&new_entry, 2, IOMMUF_readable|IOMMUF_writable);
         p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, 3);
     }
@@ -273,7 +273,7 @@ p2m_next_level(struct p2m_domain *p2m, v
         unmap_domain_page(l1_entry);
         
         new_entry = l1e_from_pfn(mfn_x(page_to_mfn(pg)),
-                                 __PAGE_HYPERVISOR|_PAGE_USER);
+                                 P2M_BASE_FLAGS | _PAGE_RW);
         p2m_add_iommu_flags(&new_entry, 1, IOMMUF_readable|IOMMUF_writable);
         p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, 2);
     }
@@ -929,7 +929,7 @@ long p2m_pt_audit_p2m(struct p2m_domain 
                 gfn += 1 << (L4_PAGETABLE_SHIFT - PAGE_SHIFT);
                 continue;
             }
-            l3e = map_domain_page(mfn_x(_mfn(l4e_get_pfn(l4e[i4]))));
+            l3e = map_domain_page(l4e_get_pfn(l4e[i4]));
             for ( i3 = 0;
                   i3 < L3_PAGETABLE_ENTRIES;
                   i3++ )
@@ -964,7 +964,7 @@ long p2m_pt_audit_p2m(struct p2m_domain 
                     }
                 }
 
-                l2e = map_domain_page(mfn_x(_mfn(l3e_get_pfn(l3e[i3]))));
+                l2e = map_domain_page(l3e_get_pfn(l3e[i3]));
                 for ( i2 = 0; i2 < L2_PAGETABLE_ENTRIES; i2++ )
                 {
                     if ( !(l2e_get_flags(l2e[i2]) & _PAGE_PRESENT) )
@@ -1000,7 +1000,7 @@ long p2m_pt_audit_p2m(struct p2m_domain 
                         continue;
                     }
 
-                    l1e = map_domain_page(mfn_x(_mfn(l2e_get_pfn(l2e[i2]))));
+                    l1e = map_domain_page(l2e_get_pfn(l2e[i2]));
 
                     for ( i1 = 0; i1 < L1_PAGETABLE_ENTRIES; i1++, gfn++ )
                     {

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Reviewed-by on v2 6/6
#19 lore raw

Re: [PATCH v2 6/6] x86/P2M: cleanup

Quoted 4 lines · Jan Beulich

- don't abuse __PAGE_HYPERVISOR
- don't use bogus constructs like mfn_x(_mfn())

Quoted 71 lines
xen/arch/x86/mm/p2m-pt.c +7 -7
@@ -193,7 +193,7 @@ p2m_next_level(struct p2m_domain *p2m, v
             return -ENOMEM;
 
         new_entry = l1e_from_pfn(mfn_x(page_to_mfn(pg)),
-                                 __PAGE_HYPERVISOR | _PAGE_USER);
+                                 P2M_BASE_FLAGS | _PAGE_RW);
 
         switch ( type ) {
         case PGT_l3_page_table:
@@ -229,7 +229,7 @@ p2m_next_level(struct p2m_domain *p2m, v
         flags = l1e_get_flags(*p2m_entry);
         pfn = l1e_get_pfn(*p2m_entry);
 
-        l1_entry = map_domain_page(mfn_x(page_to_mfn(pg)));
+        l1_entry = __map_domain_page(pg);
         for ( i = 0; i < L2_PAGETABLE_ENTRIES; i++ )
         {
             new_entry = l1e_from_pfn(pfn + (i * L1_PAGETABLE_ENTRIES), flags);
@@ -238,7 +238,7 @@ p2m_next_level(struct p2m_domain *p2m, v
         }
         unmap_domain_page(l1_entry);
         new_entry = l1e_from_pfn(mfn_x(page_to_mfn(pg)),
-                                 __PAGE_HYPERVISOR|_PAGE_USER); //disable PSE
+                                 P2M_BASE_FLAGS | _PAGE_RW); /* disable PSE */
         p2m_add_iommu_flags(&new_entry, 2, IOMMUF_readable|IOMMUF_writable);
         p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, 3);
     }
@@ -273,7 +273,7 @@ p2m_next_level(struct p2m_domain *p2m, v
         unmap_domain_page(l1_entry);
 
         new_entry = l1e_from_pfn(mfn_x(page_to_mfn(pg)),
-                                 __PAGE_HYPERVISOR|_PAGE_USER);
+                                 P2M_BASE_FLAGS | _PAGE_RW);
         p2m_add_iommu_flags(&new_entry, 1, IOMMUF_readable|IOMMUF_writable);
         p2m->write_p2m_entry(p2m, gfn, p2m_entry, new_entry, 2);
     }
@@ -929,7 +929,7 @@ long p2m_pt_audit_p2m(struct p2m_domain 
                 gfn += 1 << (L4_PAGETABLE_SHIFT - PAGE_SHIFT);
                 continue;
             }
-            l3e = map_domain_page(mfn_x(_mfn(l4e_get_pfn(l4e[i4]))));
+            l3e = map_domain_page(l4e_get_pfn(l4e[i4]));
             for ( i3 = 0;
                   i3 < L3_PAGETABLE_ENTRIES;
                   i3++ )
@@ -964,7 +964,7 @@ long p2m_pt_audit_p2m(struct p2m_domain 
                     }
                 }
 
-                l2e = map_domain_page(mfn_x(_mfn(l3e_get_pfn(l3e[i3]))));
+                l2e = map_domain_page(l3e_get_pfn(l3e[i3]));
                 for ( i2 = 0; i2 < L2_PAGETABLE_ENTRIES; i2++ )
                 {
                     if ( !(l2e_get_flags(l2e[i2]) & _PAGE_PRESENT) )
@@ -1000,7 +1000,7 @@ long p2m_pt_audit_p2m(struct p2m_domain 
                         continue;
                     }
 
-                    l1e = map_domain_page(mfn_x(_mfn(l2e_get_pfn(l2e[i2]))));
+                    l1e = map_domain_page(l2e_get_pfn(l2e[i2]));
 
                     for ( i1 = 0; i1 < L1_PAGETABLE_ENTRIES; i1++, gfn++ )
                     {
Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel