Skip to contentSkip to conversation

xen: arm: Use super pages in p2m

PATCH New Ian Campbell 3 participants 26 messages Jun 10, 2014 – Jun 11, 2014

lore
Share & tools
lore
#0 lore raw

cover xen: arm: Use super pages in p2m

The following series adds support for superpage mappings (1G and 2M) in the p2m for dom0 and domU.

At the moment it is not possible to allocate 1G regions to guests, because this is gated on multipage_allocation_permitted() which currently (incorrectly) returns false for dom0 on ARM. This is fixed by Arianna's "arch/arm: domain build: let dom0 access I/O memory of mapped devices" (which initialises iomem_caps for dom0).

On a 32-bit platform this causes the overhead of kernbench vs. native to drop from 8-9% to 1.5-3% (it's basically the same for both dom0 and domU).

I couldn't get my 64-bit platform to boot natively for some reason but in absolute terms kernbench improved by ~5% (domU) to ~15% (dom0).

Ian.

#1 lore raw

PATCH 1/6 xen: arm: dump vcpu gic info in arch_dump_vcpu_info

Instead of looping over vcpus in arch_dump_domain_info

---
 xen/arch/arm/domain.c |    7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
xen/arch/arm/domain.c +1 -6
index 04d0cd0..e494112 100644
@@ -742,12 +742,6 @@ int domain_relinquish_resources(struct domain *d)
 
 void arch_dump_domain_info(struct domain *d)
 {
-    struct vcpu *v;
-
-    for_each_vcpu ( d, v )
-    {
-        gic_dump_info(v);
-    }
 }
 
 
@@ -770,6 +764,7 @@ long arch_do_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
 
 void arch_dump_vcpu_info(struct vcpu *v)
 {
+    gic_dump_info(v);
 }
 
 void vcpu_mark_events_pending(struct vcpu *v)
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 2/6 tools: arm: allocate superpages to guests.

In reply to Ian Campbell

Tries to allocate as many large (1G or 2M) pages as it can to the guest and tries to align to the next larger size on each attempt so that we can attempt to allocate even larger pages on the next iteration (this is currently only exercised via a compile time debug option, which is left in place under a #if 0).

Since ARM page tables are consistent at each level there is a common helper function which tries to allocate a levels worth of pages. The exception to this consistency is level 0 which does not support table mappings (0.5TB superpages!).

---
 tools/libxc/xc_dom_arm.c |  103 +++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 92 insertions(+), 11 deletions(-)
tools/libxc/xc_dom_arm.c +92 -11
index 75f8363..da68ec3 100644
@@ -30,6 +30,13 @@
 #define CONSOLE_PFN_OFFSET 0
 #define XENSTORE_PFN_OFFSET 1
 
+#define LPAE_SHIFT 9
+
+#define PFN_4K_SHIFT  (0)
+#define PFN_2M_SHIFT  (PFN_4K_SHIFT+LPAE_SHIFT)
+#define PFN_1G_SHIFT  (PFN_2M_SHIFT+LPAE_SHIFT)
+#define PFN_512G_SHIFT (PFN_1G_SHIFT+LPAE_SHIFT)
+
 /* get guest IO ABI protocol */
 const char *xc_domain_get_native_protocol(xc_interface *xch,
                                           uint32_t domid)
@@ -249,11 +256,57 @@ static int set_mode(xc_interface *xch, domid_t domid, char *guest_type)
     return rc;
 }
 
+#define min_t(type,x,y) \
+        ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
+
+/*  >0: success, *nr_pfns set to number actually populated
+ *   0: didn't try with this pfn shift (e.g. misaligned base etc)
+ *  <0: ERROR
+ */
+static int populate_one_size(struct xc_dom_image *dom, int pfn_shift,
+                             xen_pfn_t base_pfn, xen_pfn_t *nr_pfns)
+{
+    uint64_t mask = ((uint64_t)1<<(pfn_shift))-1;
+    uint64_t next_mask = ((uint64_t)1<<(LPAE_SHIFT))-1;
+    int nr, i, count = min_t(int, 1024*1024, *nr_pfns >> pfn_shift);
+    xen_pfn_t extents[count];
+
+    /* No level zero super pages with current hardware */
+    if ( pfn_shift == PFN_512G_SHIFT )
+        return 0;
+
+    /* Nothing to allocate */
+    if ( !count )
+        return 0;
+
+    /* base is misaligned for this level */
+    if ( mask & base_pfn )
+        return 0;
+
+    /* align to the end of a super page at this level */
+    if ( count & next_mask )
+        count &= next_mask;
+
+    for ( i = 0 ; i < count ; i ++ )
+        extents[i] = base_pfn + (i<<pfn_shift);
+
+    nr = xc_domain_populate_physmap(dom->xch, dom->guest_domid, count,
+                                    pfn_shift, 0, extents);
+    if ( nr <= 0 ) return nr;
+    DOMPRINTF("%s: populated %#x/%#x entries with shift %d",
+              __FUNCTION__, nr, count, pfn_shift);
+
+    *nr_pfns = nr << pfn_shift;
+
+    return 1;
+}
+
 static int populate_guest_memory(struct xc_dom_image *dom,
                                  xen_pfn_t base_pfn, xen_pfn_t nr_pfns)
 {
-    int rc;
+    int rc = 0;
     xen_pfn_t allocsz, pfn;
+    int debug_iters = 0;
 
     DOMPRINTF("%s: populating RAM @ %016"PRIx64"-%016"PRIx64" (%"PRId64"MB)",
               __FUNCTION__,
@@ -261,21 +314,49 @@ static int populate_guest_memory(struct xc_dom_image *dom,
               (uint64_t)(base_pfn + nr_pfns) << XC_PAGE_SHIFT,
               (uint64_t)nr_pfns >> (20-XC_PAGE_SHIFT));
 
-    for ( pfn = 0; pfn < nr_pfns; pfn++ )
-        dom->p2m_host[pfn] = base_pfn + pfn;
-
-    for ( pfn = rc = allocsz = 0; (pfn < nr_pfns) && !rc; pfn += allocsz )
+    for ( pfn = 0; pfn < nr_pfns; pfn += allocsz )
     {
         allocsz = nr_pfns - pfn;
-        if ( allocsz > 1024*1024 )
-            allocsz = 1024*1024;
 
-        rc = xc_domain_populate_physmap_exact(
-            dom->xch, dom->guest_domid, allocsz,
-            0, 0, &dom->p2m_host[pfn]);
+        if ( debug_iters++ > 4 )
+            abort();
+#if 0 /* Enable this to exercise/debug the code which tries to realign
+       * to a superpage boundary, by misaligning at the start. */
+        if ( pfn == 0 )
+        {
+            allocsz = 1;
+            rc = populate_one_size(dom, PFN_4K_SHIFT, base_pfn + pfn, &allocsz);
+            if (rc < 0) break;
+            if (rc > 0) continue;
+            /* Failed to allocate a single page? */
+            break;
+        }
+#endif
+
+        rc = populate_one_size(dom, PFN_512G_SHIFT, base_pfn + pfn, &allocsz);
+        if (rc < 0) break;
+        if (rc > 0) continue;
+
+        rc = populate_one_size(dom, PFN_1G_SHIFT, base_pfn + pfn, &allocsz);
+        if (rc < 0) break;
+        if (rc > 0) continue;
+
+        rc = populate_one_size(dom, PFN_2M_SHIFT, base_pfn + pfn, &allocsz);
+        if (rc < 0) break;
+        if (rc > 0) continue;
+
+        rc = populate_one_size(dom, PFN_4K_SHIFT, base_pfn + pfn, &allocsz);
+        if (rc < 0) break;
+
+        assert(rc > 0); /* Must have tried to allocate some 4k pages! */
     }
 
-    return rc;
+    DOMPRINTF("%s: rc=%d", __FUNCTION__, rc);
+
+    for ( pfn = 0; pfn < nr_pfns; pfn++ )
+        dom->p2m_host[pfn] = base_pfn + pfn;
+
+    return rc < 0 ? rc : 0;
 }
 
 int arch_setup_meminit(struct xc_dom_image *dom)
Signature · 1 line
1.7.10.4
#4 lore raw

Re: [PATCH 2/6] tools: arm: allocate superpages to guests.

Hi Ian,

Quoted 35 lines · Ian Campbell

Tries to allocate as many large (1G or 2M) pages as it can to the guest and tries to align to the next larger size on each attempt so that we can attempt to allocate even larger pages on the next iteration (this is currently only exercised via a compile time debug option, which is left in place under a #if 0).

Since ARM page tables are consistent at each level there is a common helper function which tries to allocate a levels worth of pages. The exception to this consistency is level 0 which does not support table mappings (0.5TB superpages!).

---
 tools/libxc/xc_dom_arm.c |  103 +++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 92 insertions(+), 11 deletions(-)
tools/libxc/xc_dom_arm.c +7 -0
index 75f8363..da68ec3 100644
@@ -30,6 +30,13 @@
 #define CONSOLE_PFN_OFFSET 0
 #define XENSTORE_PFN_OFFSET 1
 
+#define LPAE_SHIFT 9
+
+#define PFN_4K_SHIFT  (0)
+#define PFN_2M_SHIFT  (PFN_4K_SHIFT+LPAE_SHIFT)
+#define PFN_1G_SHIFT  (PFN_2M_SHIFT+LPAE_SHIFT)
+#define PFN_512G_SHIFT (PFN_1G_SHIFT+LPAE_SHIFT)
+
 /* get guest IO ABI protocol */
 const char *xc_domain_get_native_protocol(xc_interface *xch,
                                           uint32_t domid)

tools/libxc/xc_dom_arm.c static int set_mode(xc_interface *xch, domid_t domid, char *guest_type) · line 260

Quoted 5 lines
tools/libxc/xc_dom_arm.c +2 -0
@@ -249,11 +256,57 @@ static int set_mode(xc_interface *xch, domid_t domid, char *guest_type)
     return rc;
 }
 
+#define min_t(type,x,y) \
+        ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })

min_t is also defined in xc_dom_decompress_unsafe_xz.c. It might be interesting to define it in a common header (such as xc_private.h).

tools/libxc/xc_dom_arm.c static int set_mode(xc_interface *xch, domid_t domid, char *guest_type) · line 271

Quoted 10 lines
tools/libxc/xc_dom_arm.c +10 -0
+/*  >0: success, *nr_pfns set to number actually populated
+ *   0: didn't try with this pfn shift (e.g. misaligned base etc)
+ *  <0: ERROR
+ */
+static int populate_one_size(struct xc_dom_image *dom, int pfn_shift,
+                             xen_pfn_t base_pfn, xen_pfn_t *nr_pfns)
+{
+    uint64_t mask = ((uint64_t)1<<(pfn_shift))-1;
+    uint64_t next_mask = ((uint64_t)1<<(LPAE_SHIFT))-1;
+    int nr, i, count = min_t(int, 1024*1024, *nr_pfns >> pfn_shift);

Stupid question, where does come from the 1024*1024?

tools/libxc/xc_dom_arm.c static int set_mode(xc_interface *xch, domid_t domid, char *guest_type) · line 272

Quoted 1 line
tools/libxc/xc_dom_arm.c +1 -0
+    xen_pfn_t extents[count];

If I follow the count definition, it's possible to allocate 1024*1024 xen_pfn_t (about 8MB) on the stack.

[..]

Quoted 19 lines
tools/libxc/xc_dom_arm.c +3 -5
 static int populate_guest_memory(struct xc_dom_image *dom,
                                  xen_pfn_t base_pfn, xen_pfn_t nr_pfns)
 {
-    int rc;
+    int rc = 0;
     xen_pfn_t allocsz, pfn;
+    int debug_iters = 0;
 
     DOMPRINTF("%s: populating RAM @ %016"PRIx64"-%016"PRIx64" (%"PRId64"MB)",
               __FUNCTION__,
@@ -261,21 +314,49 @@ static int populate_guest_memory(struct xc_dom_image *dom,
               (uint64_t)(base_pfn + nr_pfns) << XC_PAGE_SHIFT,
               (uint64_t)nr_pfns >> (20-XC_PAGE_SHIFT));
 
-    for ( pfn = 0; pfn < nr_pfns; pfn++ )
-        dom->p2m_host[pfn] = base_pfn + pfn;
-
-    for ( pfn = rc = allocsz = 0; (pfn < nr_pfns) && !rc; pfn += allocsz )
+    for ( pfn = 0; pfn < nr_pfns; pfn += allocsz )

tools/libxc/xc_dom_arm.c static int populate_guest_memory(struct xc_dom_image *dom, · line 322

Quoted 10 lines
tools/libxc/xc_dom_arm.c +2 -5
     {
         allocsz = nr_pfns - pfn;
-        if ( allocsz > 1024*1024 )
-            allocsz = 1024*1024;
 
-        rc = xc_domain_populate_physmap_exact(
-            dom->xch, dom->guest_domid, allocsz,
-            0, 0, &dom->p2m_host[pfn]);
+        if ( debug_iters++ > 4 )
+            abort();

IIRC, abort doesn't give any stack trace. I'm not sure if you intended to keep it in your patch. If so, I would add an error message.

Regards,

Signature · 1 line
Julien Grall
#5 lore raw

Re: [PATCH 2/6] tools: arm: allocate superpages to guests.

Quoted 41 lines · Julien Grall

Hi Ian,

Quoted 38 lines · Ian Campbell

Tries to allocate as many large (1G or 2M) pages as it can to the guest and tries to align to the next larger size on each attempt so that we can attempt to allocate even larger pages on the next iteration (this is currently only exercised via a compile time debug option, which is left in place under a #if 0).

Since ARM page tables are consistent at each level there is a common helper function which tries to allocate a levels worth of pages. The exception to this consistency is level 0 which does not support table mappings (0.5TB superpages!).

---
 tools/libxc/xc_dom_arm.c |  103 +++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 92 insertions(+), 11 deletions(-)
tools/libxc/xc_dom_arm.c +7 -0
index 75f8363..da68ec3 100644
@@ -30,6 +30,13 @@
 #define CONSOLE_PFN_OFFSET 0
 #define XENSTORE_PFN_OFFSET 1
 
+#define LPAE_SHIFT 9
+
+#define PFN_4K_SHIFT  (0)
+#define PFN_2M_SHIFT  (PFN_4K_SHIFT+LPAE_SHIFT)
+#define PFN_1G_SHIFT  (PFN_2M_SHIFT+LPAE_SHIFT)
+#define PFN_512G_SHIFT (PFN_1G_SHIFT+LPAE_SHIFT)
+
 /* get guest IO ABI protocol */
 const char *xc_domain_get_native_protocol(xc_interface *xch,
                                           uint32_t domid)
@@ -249,11 +256,57 @@ static int set_mode(xc_interface *xch, domid_t domid, char *guest_type)
     return rc;
 }
 
Quoted 5 lines

tools/libxc/xc_dom_arm.c static int set_mode(xc_interface *xch, domid_t domid, char *guest_type) · line 260

Quoted 2 lines
tools/libxc/xc_dom_arm.c +2 -0
+#define min_t(type,x,y) \
+        ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })

min_t is also defined in xc_dom_decompress_unsafe_xz.c. It might be interesting to define it in a common header (such as xc_private.h).

Yes, good idea. I'll add a precursor patch.

Quoted 13 lines

tools/libxc/xc_dom_arm.c static int set_mode(xc_interface *xch, domid_t domid, char *guest_type) · line 271

Quoted 11 lines
tools/libxc/xc_dom_arm.c +10 -0
+/*  >0: success, *nr_pfns set to number actually populated
+ *   0: didn't try with this pfn shift (e.g. misaligned base etc)
+ *  <0: ERROR
+ */
+static int populate_one_size(struct xc_dom_image *dom, int pfn_shift,
+                             xen_pfn_t base_pfn, xen_pfn_t *nr_pfns)
+{
+    uint64_t mask = ((uint64_t)1<<(pfn_shift))-1;
+    uint64_t next_mask = ((uint64_t)1<<(LPAE_SHIFT))-1;
+    int nr, i, count = min_t(int, 1024*1024, *nr_pfns >> pfn_shift);

Stupid question, where does come from the 1024*1024?

It was in the original as a backstop on allocsz. It would correspond to 4GB worth of 4K page I suppose

Quoted 4 lines

tools/libxc/xc_dom_arm.c static int set_mode(xc_interface *xch, domid_t domid, char *guest_type) · line 272

Quoted 1 line
tools/libxc/xc_dom_arm.c +1 -0
+    xen_pfn_t extents[count];

If I follow the count definition, it's possible to allocate 1024*1024 xen_pfn_t (about 8MB) on the stack.

userspace stack isn't all that precious but 8MB does seem a little excessive. Previously this was using the already allocated host p2m so it wasn't an issue, but that doesn't work for allocations of page >4K.

The tradeoff is that smaller batches mean it will take longer.

I don't think it would be unreasonable to reduce this to be e.g. 1GB worth of entries (256*1024) or 2MB of stack.

Quoted 27 lines

[..]

Quoted 24 lines

static int populate_guest_memory(struct xc_dom_image *dom,
xen_pfn_t base_pfn, xen_pfn_t nr_pfns)
{

tools/libxc/xc_dom_arm.c +3 -7
-    int rc;
+    int rc = 0;
     xen_pfn_t allocsz, pfn;
+    int debug_iters = 0;
 
     DOMPRINTF("%s: populating RAM @ %016"PRIx64"-%016"PRIx64" (%"PRId64"MB)",
               __FUNCTION__,
@@ -261,21 +314,49 @@ static int populate_guest_memory(struct xc_dom_image *dom,
               (uint64_t)(base_pfn + nr_pfns) << XC_PAGE_SHIFT,
               (uint64_t)nr_pfns >> (20-XC_PAGE_SHIFT));
 
-    for ( pfn = 0; pfn < nr_pfns; pfn++ )
-        dom->p2m_host[pfn] = base_pfn + pfn;
-
-    for ( pfn = rc = allocsz = 0; (pfn < nr_pfns) && !rc; pfn += allocsz )
+    for ( pfn = 0; pfn < nr_pfns; pfn += allocsz )
     {
         allocsz = nr_pfns - pfn;
-        if ( allocsz > 1024*1024 )
-            allocsz = 1024*1024;
 
Quoted 8 lines

tools/libxc/xc_dom_arm.c static int populate_guest_memory(struct xc_dom_image *dom, · line 322

Quoted 5 lines
tools/libxc/xc_dom_arm.c +2 -3
-        rc = xc_domain_populate_physmap_exact(
-            dom->xch, dom->guest_domid, allocsz,
-            0, 0, &dom->p2m_host[pfn]);
+        if ( debug_iters++ > 4 )
+            abort();

IIRC, abort doesn't give any stack trace. I'm not sure if you intended to keep it in your patch. If so, I would add an error message.

I can't remember what I was doing here, but it is just debug so I'll nuke it.

Ian.

#6 lore raw

Re: [PATCH 2/6] tools: arm: allocate superpages to guests.

Quoted 13 lines · Ian Campbell
Quoted 4 lines
Quoted 4 lines

+/* >0: success, *nr_pfns set to number actually populated
+ * 0: didn't try with this pfn shift (e.g. misaligned base etc)
+ * <0: ERROR
+ */

Quoted 8 lines

tools/libxc/xc_dom_arm.c static int set_mode(xc_interface *xch, domid_t domid, char *guest_type) · line 271

Quoted 6 lines
tools/libxc/xc_dom_arm.c +6 -0
+static int populate_one_size(struct xc_dom_image *dom, int pfn_shift,
+                             xen_pfn_t base_pfn, xen_pfn_t *nr_pfns)
+{
+    uint64_t mask = ((uint64_t)1<<(pfn_shift))-1;
+    uint64_t next_mask = ((uint64_t)1<<(LPAE_SHIFT))-1;
+    int nr, i, count = min_t(int, 1024*1024, *nr_pfns >> pfn_shift);

Stupid question, where does come from the 1024*1024?

Quoted 2 lines

It was in the original as a backstop on allocsz. It would correspond to 4GB worth of 4K page I suppose

Ah ok. I didn't pay attention about it.

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

+ xen_pfn_t extents[count];

If I follow the count definition, it's possible to allocate 1024*1024 xen_pfn_t (about 8MB) on the stack.

Quoted 8 lines

userspace stack isn't all that precious but 8MB does seem a little excessive. Previously this was using the already allocated host p2m so it wasn't an issue, but that doesn't work for allocations of page >4K.

The tradeoff is that smaller batches mean it will take longer.

I don't think it would be unreasonable to reduce this to be e.g. 1GB worth of entries (256*1024) or 2MB of stack.

It seems the default stack size is 8MB, I'm wondering if we can have some use case where this limit is smaller.

Is there any issue to allocate this variable with malloc?

Regards,

Signature · 1 line
Julien Grall
#7 lore raw

Re: [PATCH 2/6] tools: arm: allocate superpages to guests.

Quoted 29 lines · Julien Grall
Quoted 13 lines · Ian Campbell
Quoted 4 lines
Quoted 4 lines

+/* >0: success, *nr_pfns set to number actually populated
+ * 0: didn't try with this pfn shift (e.g. misaligned base etc)
+ * <0: ERROR
+ */

Quoted 8 lines

tools/libxc/xc_dom_arm.c static int set_mode(xc_interface *xch, domid_t domid, char *guest_type) · line 271

Quoted 6 lines
tools/libxc/xc_dom_arm.c +6 -0
+static int populate_one_size(struct xc_dom_image *dom, int pfn_shift,
+                             xen_pfn_t base_pfn, xen_pfn_t *nr_pfns)
+{
+    uint64_t mask = ((uint64_t)1<<(pfn_shift))-1;
+    uint64_t next_mask = ((uint64_t)1<<(LPAE_SHIFT))-1;
+    int nr, i, count = min_t(int, 1024*1024, *nr_pfns >> pfn_shift);

Stupid question, where does come from the 1024*1024?

Quoted 2 lines

It was in the original as a backstop on allocsz. It would correspond to 4GB worth of 4K page I suppose

Ah ok. I didn't pay attention about it.

Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

+ xen_pfn_t extents[count];

If I follow the count definition, it's possible to allocate 1024*1024 xen_pfn_t (about 8MB) on the stack.

userspace stack isn't all that precious but 8MB does seem a little excessive. Previously this was using the already allocated host p2m so it wasn't an issue, but that doesn't work for allocations of page >4K.

Quoted 7 lines
Quoted 4 lines

The tradeoff is that smaller batches mean it will take longer.

I don't think it would be unreasonable to reduce this to be e.g. 1GB worth of entries (256*1024) or 2MB of stack.

It seems the default stack size is 8MB, I'm wondering if we can have some use case where this limit is smaller.

I think we effectively assume it is larger than any amount we would practically use.

Quoted 1 line

Is there any issue to allocate this variable with malloc?

Just more book keeping code really.

Ian.

#8 lore raw

Re: [PATCH 2/6] tools: arm: allocate superpages to guests.

Quoted 38 lines · Ian Campbell
Quoted 29 lines · Julien Grall
Quoted 13 lines · Ian Campbell
Quoted 4 lines
Quoted 4 lines

+/* >0: success, *nr_pfns set to number actually populated
+ * 0: didn't try with this pfn shift (e.g. misaligned base etc)
+ * <0: ERROR
+ */

Quoted 8 lines

tools/libxc/xc_dom_arm.c static int set_mode(xc_interface *xch, domid_t domid, char *guest_type) · line 271

Quoted 6 lines
tools/libxc/xc_dom_arm.c +6 -0
+static int populate_one_size(struct xc_dom_image *dom, int pfn_shift,
+                             xen_pfn_t base_pfn, xen_pfn_t *nr_pfns)
+{
+    uint64_t mask = ((uint64_t)1<<(pfn_shift))-1;
+    uint64_t next_mask = ((uint64_t)1<<(LPAE_SHIFT))-1;
+    int nr, i, count = min_t(int, 1024*1024, *nr_pfns >> pfn_shift);

Stupid question, where does come from the 1024*1024?

Quoted 2 lines

It was in the original as a backstop on allocsz. It would correspond to 4GB worth of 4K page I suppose

Ah ok. I didn't pay attention about it.

Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

+ xen_pfn_t extents[count];

If I follow the count definition, it's possible to allocate 1024*1024 xen_pfn_t (about 8MB) on the stack.

userspace stack isn't all that precious but 8MB does seem a little excessive. Previously this was using the already allocated host p2m so it wasn't an issue, but that doesn't work for allocations of page >4K.

Quoted 7 lines
Quoted 4 lines

The tradeoff is that smaller batches mean it will take longer.

I don't think it would be unreasonable to reduce this to be e.g. 1GB worth of entries (256*1024) or 2MB of stack.

It seems the default stack size is 8MB, I'm wondering if we can have some use case where this limit is smaller.

Quoted 6 lines

I think we effectively assume it is larger than any amount we would practically use.

Quoted 1 line

Is there any issue to allocate this variable with malloc?

Just more book keeping code really.

Looking to the code, it doesn't seem too difficult to add malloc and handle error.

I would prefer to use the malloc rather the stack and therefore assuming that's stack a quite big, even though this variable should never be too big. It wouldn't be mad to have an OS using a 1M stack (or even less).

Anyway it seems that x86 libxc is using the same trick for superpage...

Regards,

Signature · 1 line
Julien Grall
#9 lore raw

PATCH 3/6 xen: arm: only put_page for p2m operations which require it.

In reply to Ian Campbell

In particular do not do it for CACHEFLUSH.

INSERT, RELINQUISH and REMOVE should all put the page (if the current pte is valid). ALLOCATE doesn't need to since it asserts the current PTE must be invalid.

---
 xen/arch/arm/p2m.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
xen/arch/arm/p2m.c +21 -0
index 9960e17..830a9f9 100644
@@ -299,6 +299,23 @@ enum p2m_operation {
     CACHEFLUSH,
 };
 
+static void p2m_put_page(const lpae_t pte)
+{
+    /* TODO: Handle other p2m types
+     *
+     * It's safe to do the put_page here because page_alloc will
+     * flush the TLBs if the page is reallocated before the end of
+     * this loop.
+     */
+    if ( p2m_is_foreign(pte.p2m.type) )
+    {
+        unsigned long mfn = pte.p2m.base;
+
+        ASSERT(mfn_valid(mfn));
+        put_page(mfn_to_page(mfn));
+    }
+}
+
 static int apply_p2m_changes(struct domain *d,
                      enum p2m_operation op,
                      paddr_t start_gpaddr,
@@ -436,6 +453,8 @@ static int apply_p2m_changes(struct domain *d,
                 break;
             case INSERT:
                 {
+                    if ( pte.p2m.valid )
+                        p2m_put_page(pte);
                     pte = mfn_to_p2m_entry(maddr >> PAGE_SHIFT, mattr, t);
                     p2m_write_pte(&third[third_table_offset(addr)],
                                   pte, flush_pt);
@@ -451,6 +470,8 @@ static int apply_p2m_changes(struct domain *d,
                         break;
                     }
 
+                    p2m_put_page(pte);
+
                     count += 0x10;
 
                     memset(&pte, 0x00, sizeof(pte));
Signature · 1 line
1.7.10.4
#10 lore raw

Re: [PATCH 3/6] xen: arm: only put_page for p2m operations which require it.

Hi Ian,

Quoted 26 lines · Ian Campbell

In particular do not do it for CACHEFLUSH.

INSERT, RELINQUISH and REMOVE should all put the page (if the current pte is valid). ALLOCATE doesn't need to since it asserts the current PTE must be invalid.

---
 xen/arch/arm/p2m.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
xen/arch/arm/p2m.c +7 -0
index 9960e17..830a9f9 100644
@@ -299,6 +299,23 @@ enum p2m_operation {
     CACHEFLUSH,
 };
 
+static void p2m_put_page(const lpae_t pte)
+{
+    /* TODO: Handle other p2m types
+     *
+     * It's safe to do the put_page here because page_alloc will
+     * flush the TLBs if the page is reallocated before the end of
+     * this loop.

xen/arch/arm/p2m.c enum p2m_operation { · line 318

Quoted 10 lines
xen/arch/arm/p2m.c +10 -0
+     */
+    if ( p2m_is_foreign(pte.p2m.type) )
+    {
+        unsigned long mfn = pte.p2m.base;
+
+        ASSERT(mfn_valid(mfn));
+        put_page(mfn_to_page(mfn));
+    }
+}
+

You forgot to drop the put_page in apply_p2m_changes. So, now we have 2 put_page rather than one.

Regards,

Signature · 1 line
Julien Grall
#11 lore raw

Re: [PATCH 3/6] xen: arm: only put_page for p2m operations which require it.

Quoted 2 lines · Julien Grall

You forgot to drop the put_page in apply_p2m_changes. So, now we have 2 put_page rather than one.

Rebasing snafu meant it got removed in the final patch instead of here. I'll fix.

Ian.

#12 lore raw

PATCH 4/6 xen: arm: handle superpage mappings in p2m_lookup

In reply to Ian Campbell

Currently none are actually created, but they will be shortly.

---
 xen/arch/arm/p2m.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
xen/arch/arm/p2m.c +8 -1
index 830a9f9..5d654ce 100644
@@ -123,6 +123,7 @@ paddr_t p2m_lookup(struct domain *d, paddr_t paddr, p2m_type_t *t)
     struct p2m_domain *p2m = &d->arch.p2m;
     lpae_t pte, *first = NULL, *second = NULL, *third = NULL;
     paddr_t maddr = INVALID_PADDR;
+    paddr_t mask;
     p2m_type_t _t;
 
     /* Allow t to be NULL */
@@ -136,15 +137,21 @@ paddr_t p2m_lookup(struct domain *d, paddr_t paddr, p2m_type_t *t)
     if ( !first )
         goto err;
 
+    mask = FIRST_MASK;
     pte = first[first_table_offset(paddr)];
     if ( !pte.p2m.valid || !pte.p2m.table )
         goto done;
 
+    mask = SECOND_MASK;
     second = map_domain_page(pte.p2m.base);
     pte = second[second_table_offset(paddr)];
     if ( !pte.p2m.valid || !pte.p2m.table )
         goto done;
 
+    mask = THIRD_MASK;
+
+    BUILD_BUG_ON(THIRD_MASK != PAGE_MASK);
+
     third = map_domain_page(pte.p2m.base);
     pte = third[third_table_offset(paddr)];
 
@@ -156,7 +163,7 @@ done:
     if ( pte.p2m.valid )
     {
         ASSERT(pte.p2m.type != p2m_invalid);
-        maddr = (pte.bits & PADDR_MASK & PAGE_MASK) | (paddr & ~PAGE_MASK);
+        maddr = (pte.bits & PADDR_MASK & mask) | (paddr & ~mask);
         *t = pte.p2m.type;
     }
 
Signature · 1 line
1.7.10.4
#14 lore raw

PATCH 5/6 xen: arm: add some helpers for assessing p2m pte

In reply to Ian Campbell

Not terribly helpful right now, since they aren't widely used, but makes future patches easier to read.

---
 xen/arch/arm/p2m.c |   19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
xen/arch/arm/p2m.c +12 -7
index 5d654ce..233df72 100644
@@ -14,6 +14,11 @@
 #define P2M_FIRST_ORDER 1
 #define P2M_FIRST_ENTRIES (LPAE_ENTRIES<<P2M_FIRST_ORDER)
 
+#define p2m_valid(pte) ((pte).p2m.valid)
+/* Remember: L3 entries set the table bit! */
+#define p2m_table(pte) (p2m_valid(pte) && (pte).p2m.table)
+#define p2m_entry(pte) (p2m_valid(pte) && !(pte).p2m.table)
+
 void dump_p2m_lookup(struct domain *d, paddr_t addr)
 {
     struct p2m_domain *p2m = &d->arch.p2m;
@@ -139,13 +144,13 @@ paddr_t p2m_lookup(struct domain *d, paddr_t paddr, p2m_type_t *t)
 
     mask = FIRST_MASK;
     pte = first[first_table_offset(paddr)];
-    if ( !pte.p2m.valid || !pte.p2m.table )
+    if ( !p2m_table(pte) )
         goto done;
 
     mask = SECOND_MASK;
     second = map_domain_page(pte.p2m.base);
     pte = second[second_table_offset(paddr)];
-    if ( !pte.p2m.valid || !pte.p2m.table )
+    if ( !p2m_table(pte) )
         goto done;
 
     mask = THIRD_MASK;
@@ -156,11 +161,11 @@ paddr_t p2m_lookup(struct domain *d, paddr_t paddr, p2m_type_t *t)
     pte = third[third_table_offset(paddr)];
 
     /* This bit must be one in the level 3 entry */
-    if ( !pte.p2m.table )
+    if ( !p2m_table(pte) )
         pte.bits = 0;
 
 done:
-    if ( pte.p2m.valid )
+    if ( p2m_valid(pte) )
     {
         ASSERT(pte.p2m.type != p2m_invalid);
         maddr = (pte.bits & PADDR_MASK & mask) | (paddr & ~mask);
@@ -367,7 +372,7 @@ static int apply_p2m_changes(struct domain *d,
             cur_first_page = p2m_first_level_index(addr);
         }
 
-        if ( !first[first_table_offset(addr)].p2m.valid )
+        if ( !p2m_valid(first[first_table_offset(addr)]) )
         {
             if ( !populate )
             {
@@ -384,7 +389,7 @@ static int apply_p2m_changes(struct domain *d,
             }
         }
 
-        BUG_ON(!first[first_table_offset(addr)].p2m.valid);
+        BUG_ON(!p2m_valid(first[first_table_offset(addr)]));
 
         if ( cur_first_offset != first_table_offset(addr) )
         {
@@ -394,7 +399,7 @@ static int apply_p2m_changes(struct domain *d,
         }
         /* else: second already valid */
 
-        if ( !second[second_table_offset(addr)].p2m.valid )
+        if ( !p2m_valid(second[second_table_offset(addr)]) )
         {
             if ( !populate )
             {
Signature · 1 line
1.7.10.4
#15 lore raw

Re: [PATCH 5/6] xen: arm: add some helpers for assessing p2m pte

Quoted 9 lines · Ian Campbell
     mask = SECOND_MASK;
     second = map_domain_page(pte.p2m.base);
     pte = second[second_table_offset(paddr)];
xen/arch/arm/p2m.c +1 -1
-    if ( !pte.p2m.valid || !pte.p2m.table )
+    if ( !p2m_table(pte) )
         goto done;
 
     mask = THIRD_MASK;

xen/arch/arm/p2m.c paddr_t p2m_lookup(struct domain *d, paddr_t paddr, p2m_type_t *t) · line 168

Quoted 10 lines
xen/arch/arm/p2m.c +2 -2
@@ -156,11 +161,11 @@ paddr_t p2m_lookup(struct domain *d, paddr_t paddr, p2m_type_t *t)
     pte = third[third_table_offset(paddr)];
 
     /* This bit must be one in the level 3 entry */
-    if ( !pte.p2m.table )
+    if ( !p2m_table(pte) )
         pte.bits = 0;
 
 done:
-    if ( pte.p2m.valid )
+    if ( p2m_valid(pte) )

Regardless the current check, I think this should be p2m_entry(pte) to help code comprehension.

Indeed, the can only get the address if the pte is pointed to a memory block.

Regards,

Signature · 1 line
Julien Grall
#16 lore raw

Re: [PATCH 5/6] xen: arm: add some helpers for assessing p2m pte

Quoted 24 lines · Julien Grall
Quoted 9 lines · Ian Campbell
     mask = SECOND_MASK;
     second = map_domain_page(pte.p2m.base);
     pte = second[second_table_offset(paddr)];
xen/arch/arm/p2m.c +1 -1
-    if ( !pte.p2m.valid || !pte.p2m.table )
+    if ( !p2m_table(pte) )
         goto done;
 
     mask = THIRD_MASK;

xen/arch/arm/p2m.c paddr_t p2m_lookup(struct domain *d, paddr_t paddr, p2m_type_t *t) · line 168

Quoted 10 lines
xen/arch/arm/p2m.c +2 -2
@@ -156,11 +161,11 @@ paddr_t p2m_lookup(struct domain *d, paddr_t paddr, p2m_type_t *t)
     pte = third[third_table_offset(paddr)];
 
     /* This bit must be one in the level 3 entry */
-    if ( !pte.p2m.table )
+    if ( !p2m_table(pte) )
         pte.bits = 0;
 
 done:
-    if ( pte.p2m.valid )
+    if ( p2m_valid(pte) )

Regardless the current check, I think this should be p2m_entry(pte) to help code comprehension.

Quoted 2 lines

Indeed, the can only get the address if the pte is pointed to a memory block.

Yes, but an L3 PTE has the table bit set, which would make p2m_entry(pte) false...

Acked-by
#17 lore raw

Re: [PATCH 5/6] xen: arm: add some helpers for assessing p2m pte

Quoted 25 lines · Ian Campbell
Quoted 24 lines · Julien Grall
Quoted 9 lines · Ian Campbell
     mask = SECOND_MASK;
     second = map_domain_page(pte.p2m.base);
     pte = second[second_table_offset(paddr)];
xen/arch/arm/p2m.c +1 -1
-    if ( !pte.p2m.valid || !pte.p2m.table )
+    if ( !p2m_table(pte) )
         goto done;
 
     mask = THIRD_MASK;

xen/arch/arm/p2m.c paddr_t p2m_lookup(struct domain *d, paddr_t paddr, p2m_type_t *t) · line 168

Quoted 10 lines
xen/arch/arm/p2m.c +2 -2
@@ -156,11 +161,11 @@ paddr_t p2m_lookup(struct domain *d, paddr_t paddr, p2m_type_t *t)
     pte = third[third_table_offset(paddr)];
 
     /* This bit must be one in the level 3 entry */
-    if ( !pte.p2m.table )
+    if ( !p2m_table(pte) )
         pte.bits = 0;
 
 done:
-    if ( pte.p2m.valid )
+    if ( p2m_valid(pte) )

Regardless the current check, I think this should be p2m_entry(pte) to help code comprehension.

Quoted 5 lines
Quoted 2 lines

Indeed, the can only get the address if the pte is pointed to a memory block.

Yes, but an L3 PTE has the table bit set, which would make p2m_entry(pte) false...

Hmmm... right. But this bit (ie table bit) doesn't have the same meaning on L3. Your comment on p2m_table is confusing.

Anyway:

Signature · 1 line
Julien Grall
#18 lore raw

Re: [PATCH 5/6] xen: arm: add some helpers for assessing p2m pte

Quoted 26 lines · Julien Grall
Quoted 25 lines · Ian Campbell
Quoted 24 lines · Julien Grall
Quoted 9 lines · Ian Campbell
     mask = SECOND_MASK;
     second = map_domain_page(pte.p2m.base);
     pte = second[second_table_offset(paddr)];
xen/arch/arm/p2m.c +1 -1
-    if ( !pte.p2m.valid || !pte.p2m.table )
+    if ( !p2m_table(pte) )
         goto done;
 
     mask = THIRD_MASK;

xen/arch/arm/p2m.c paddr_t p2m_lookup(struct domain *d, paddr_t paddr, p2m_type_t *t) · line 168

Quoted 10 lines
xen/arch/arm/p2m.c +2 -2
@@ -156,11 +161,11 @@ paddr_t p2m_lookup(struct domain *d, paddr_t paddr, p2m_type_t *t)
     pte = third[third_table_offset(paddr)];
 
     /* This bit must be one in the level 3 entry */
-    if ( !pte.p2m.table )
+    if ( !p2m_table(pte) )
         pte.bits = 0;
 
 done:
-    if ( pte.p2m.valid )
+    if ( p2m_valid(pte) )

Regardless the current check, I think this should be p2m_entry(pte) to help code comprehension.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Indeed, the can only get the address if the pte is pointed to a memory block.

Yes, but an L3 PTE has the table bit set, which would make p2m_entry(pte) false...

Hmmm... right. But this bit (ie table bit) doesn't have the same meaning on L3. Your comment on p2m_table is confusing.

You mean: /* Remember: L3 entries set the table bit! */ ?

That was intended to be a comment on the two helpers which follow. Do you have an idea how I could make it clearer? Perhaps appending "So these two functions will return the opposite to what you expect for L3 ptes"?

Quoted 5 lines

Anyway:

Thanks.

#19 lore raw

Re: [PATCH 5/6] xen: arm: add some helpers for assessing p2m pte

Quoted 36 lines · Ian Campbell
Quoted 26 lines · Julien Grall
Quoted 25 lines · Ian Campbell
Quoted 24 lines · Julien Grall
Quoted 9 lines · Ian Campbell
     mask = SECOND_MASK;
     second = map_domain_page(pte.p2m.base);
     pte = second[second_table_offset(paddr)];
xen/arch/arm/p2m.c +1 -1
-    if ( !pte.p2m.valid || !pte.p2m.table )
+    if ( !p2m_table(pte) )
         goto done;
 
     mask = THIRD_MASK;

xen/arch/arm/p2m.c paddr_t p2m_lookup(struct domain *d, paddr_t paddr, p2m_type_t *t) · line 168

Quoted 10 lines
xen/arch/arm/p2m.c +2 -2
@@ -156,11 +161,11 @@ paddr_t p2m_lookup(struct domain *d, paddr_t paddr, p2m_type_t *t)
     pte = third[third_table_offset(paddr)];
 
     /* This bit must be one in the level 3 entry */
-    if ( !pte.p2m.table )
+    if ( !p2m_table(pte) )
         pte.bits = 0;
 
 done:
-    if ( pte.p2m.valid )
+    if ( p2m_valid(pte) )

Regardless the current check, I think this should be p2m_entry(pte) to help code comprehension.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Indeed, the can only get the address if the pte is pointed to a memory block.

Yes, but an L3 PTE has the table bit set, which would make p2m_entry(pte) false...

Hmmm... right. But this bit (ie table bit) doesn't have the same meaning on L3. Your comment on p2m_table is confusing.

Quoted 6 lines

You mean: /* Remember: L3 entries set the table bit! */ ?

That was intended to be a comment on the two helpers which follow. Do you have an idea how I could make it clearer? Perhaps appending "So these two functions will return the opposite to what you expect for L3 ptes"?

I was thinking something like "These two functions are only valid for L1 and L2 ptes".

Signature · 1 line
Julien Grall
#20 lore raw

Re: [PATCH 5/6] xen: arm: add some helpers for assessing p2m pte

Quoted 11 lines · Julien Grall
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Indeed, the can only get the address if the pte is pointed to a memory block.

Yes, but an L3 PTE has the table bit set, which would make p2m_entry(pte) false...

Hmmm... right. But this bit (ie table bit) doesn't have the same meaning on L3. Your comment on p2m_table is confusing.

You mean: /* Remember: L3 entries set the table bit! */ ?

Quoted 7 lines
Quoted 4 lines

That was intended to be a comment on the two helpers which follow. Do you have an idea how I could make it clearer? Perhaps appending "So these two functions will return the opposite to what you expect for L3 ptes"?

I was thinking something like "These two functions are only valid for L1 and L2 ptes".

I think I'll do some combination of both.

Ian.

#21 lore raw

PATCH 6/6 xen: arm: use superpages in p2m when pages are suitably aligned

In reply to Ian Campbell

This creates superpage (1G and 2M) mappings in the p2m for both domU and dom0 when the guest and machine addresses are suitably aligned. This relies on the domain builder to allocate suitably sized regions, this is trivially true for 1:1 mapped dom0's and was arranged for guests in a previous patch. A non-1:1 dom0's memory is not currently deliberately aligned.

Since ARM pagetables are (mostly) consistent at each level this is implemented by refactoring the handling of a single level of pagetable into a common function. The two inconsistencies are that there are no superpage mappings at level zero and that level three entry mappings must set the table bit.

When inserting new mappings the code shatters superpage mappings as necessary, but currently makes no attempt to coalesce anything again. In particular when inserting a mapping which could be a superpage over an existing table mapping we do not attempt to free that lower page table and instead descend into it.

Some p2m statistics are added to keep track of the number of each level of mapping and the number of times we've had to shatter an existing mapping.

---
 xen/arch/arm/domain.c     |    1 +
 xen/arch/arm/p2m.c        |  497 +++++++++++++++++++++++++++++++++------------
 xen/include/asm-arm/p2m.h |    9 +
 3 files changed, 373 insertions(+), 134 deletions(-)
xen/arch/arm/domain.c +1 -0
index e494112..45b7cbd 100644
@@ -742,6 +742,7 @@ int domain_relinquish_resources(struct domain *d)
 
 void arch_dump_domain_info(struct domain *d)
 {
+    p2m_dump_info(d);
 }
 
 
xen/arch/arm/p2m.c +363 -134

585 lines not on this page · raw message

xen/include/asm-arm/p2m.h +9 -0
index 911d32d..0cfbb09 100644
@@ -29,6 +29,12 @@ struct p2m_domain {
      * resume the search. Apart from during teardown this can only
      * decrease. */
     unsigned long lowest_mapped_gfn;
+
+    struct {
+        uint32_t mappings[4]; /* Number of mappings at each p2m tree level */
+        uint32_t shattered[4]; /* Number of times we have shattered a mapping
+                                * at each p2m tree level. */
+    } stats;
 };
 
 /* List of possible type for each page in the p2m entry.
@@ -79,6 +85,9 @@ int p2m_alloc_table(struct domain *d);
 void p2m_save_state(struct vcpu *p);
 void p2m_restore_state(struct vcpu *n);
 
+/* */
+void p2m_dump_info(struct domain *d);
+
 /* Look up the MFN corresponding to a domain's PFN. */
 paddr_t p2m_lookup(struct domain *d, paddr_t gpfn, p2m_type_t *t);
 
Signature · 1 line
1.7.10.4
#22 lore raw

Re: [PATCH 6/6] xen: arm: use superpages in p2m when pages are suitably aligned

Hi Ian,

This patch looks good in general. I've only few comments, see them below.

xen/arch/arm/p2m.c line 35

Quoted 13 lines · Ian Campbell
xen/arch/arm/p2m.c +13 -0
+void p2m_dump_info(struct domain *d)
+{
+    struct p2m_domain *p2m = &d->arch.p2m;
+
+    spin_lock(&p2m->lock);
+    printk("p2m mappings for domain %d (vmid %d):\n",
+           d->domain_id, p2m->vmid);
+    BUG_ON(p2m->stats.mappings[0] || p2m->stats.shattered[0]);
+    printk("  1G mappings: %d (shattered %d)\n",
+           p2m->stats.mappings[1], p2m->stats.shattered[1]);
+    printk("  2M mappings: %d (shattered %d)\n",
+           p2m->stats.mappings[2], p2m->stats.shattered[2]);
+    printk("  4K mappings: %d\n", p2m->stats.mappings[3]);

I wondering if we can have more than 2^32-1 4K mapping sometimes...

[..]

xen/arch/arm/p2m.c static int p2m_create_table(struct domain *d, lpae_t *entry, bool_t flush_cache) · line 351

Quoted 5 lines
xen/arch/arm/p2m.c +5 -0
+    else
+    {
+        clear_page(p);
+    }
+

Spurious {}.

[..]

Quoted 2 lines

+/*
+ * 0 == (P2M_ONE_DESCEND) continue to decend the tree

s/decend/descend/

[..]

xen/arch/arm/p2m.c void guest_physmap_remove_page(struct domain *d, · line 816

Quoted 13 lines
xen/arch/arm/p2m.c +2 -2
@@ -574,7 +803,7 @@ int guest_physmap_add_entry(struct domain *d,
 {
     return apply_p2m_changes(d, INSERT,
                              pfn_to_paddr(gpfn),
-                             pfn_to_paddr(gpfn + (1 << page_order)),
+                             pfn_to_paddr(gpfn + (1 << page_order)) - 1,
 
@@ -584,7 +813,7 @@ void guest_physmap_remove_page(struct domain *d,
 {
     apply_p2m_changes(d, REMOVE,
                       pfn_to_paddr(gpfn),
-                      pfn_to_paddr(gpfn + (1<<page_order)),
+                      pfn_to_paddr(gpfn + (1<<page_order)) - 1,

Why did you add -1 on both function? This is inconsistent with p2m_populate_ram which use the range [start, end[.

I think we should document how we pass the argument to apply_p2m_changes somewhere. Even better, use gmfn and nr_gfn, as x86 does, for apply_p2m_changes and handle internally the pfn_to_paddr stuff. This would avoid this kind of problem.

Regards,

Signature · 1 line
Julien Grall
#23 lore raw

Re: [PATCH 6/6] xen: arm: use superpages in p2m when pages are suitably aligned

Quoted 5 lines · Julien Grall

Hi Ian,

This patch looks good in general. I've only few comments, see them below.

On 06/10/2014 10:57 AM, Ian Campbell wrote:

Quoted 15 lines

xen/arch/arm/p2m.c line 35

Quoted 13 lines
xen/arch/arm/p2m.c +13 -0
+void p2m_dump_info(struct domain *d)
+{
+    struct p2m_domain *p2m = &d->arch.p2m;
+
+    spin_lock(&p2m->lock);
+    printk("p2m mappings for domain %d (vmid %d):\n",
+           d->domain_id, p2m->vmid);
+    BUG_ON(p2m->stats.mappings[0] || p2m->stats.shattered[0]);
+    printk("  1G mappings: %d (shattered %d)\n",
+           p2m->stats.mappings[1], p2m->stats.shattered[1]);
+    printk("  2M mappings: %d (shattered %d)\n",
+           p2m->stats.mappings[2], p2m->stats.shattered[2]);
+    printk("  4K mappings: %d\n", p2m->stats.mappings[3]);

I wondering if we can have more than 2^32-1 4K mapping sometimes...

That would be 16TB of memory, which isn't out of the question but we don't currently support it. Still, not much harm in increase to a 64-bit field.

Quoted 9 lines

[..]

xen/arch/arm/p2m.c static int p2m_create_table(struct domain *d, lpae_t *entry, bool_t flush_cache) · line 351

Quoted 5 lines
xen/arch/arm/p2m.c +5 -0
+    else
+    {
+        clear_page(p);
+    }
+

Spurious {}.

I prefer them when on both halves of an else when one of them needs them, but I guess I'm in a minority so I'll remove.

Quoted 7 lines
Quoted 6 lines
xen/arch/arm/p2m.c +1 -1
@@ -574,7 +803,7 @@ int guest_physmap_add_entry(struct domain *d,
 {
     return apply_p2m_changes(d, INSERT,
                              pfn_to_paddr(gpfn),
-                             pfn_to_paddr(gpfn + (1 << page_order)),
+                             pfn_to_paddr(gpfn + (1 << page_order)) - 1,
Quoted 9 lines

xen/arch/arm/p2m.c void guest_physmap_remove_page(struct domain *d, · line 816

Quoted 6 lines
xen/arch/arm/p2m.c +1 -1
@@ -584,7 +813,7 @@ void guest_physmap_remove_page(struct domain *d,
 {
     apply_p2m_changes(d, REMOVE,
                       pfn_to_paddr(gpfn),
-                      pfn_to_paddr(gpfn + (1<<page_order)),
+                      pfn_to_paddr(gpfn + (1<<page_order)) - 1,

Why did you add -1 on both function? This is inconsistent with p2m_populate_ram which use the range [start, end[.

I thihk I thought the that the callers of apply_p2m_changes were inconsistent about this, but then I changed my mind and somehow failed to remove this change.

Quoted 4 lines

I think we should document how we pass the argument to apply_p2m_changes somewhere. Even better, use gmfn and nr_gfn, as x86 does, for apply_p2m_changes and handle internally the pfn_to_paddr stuff. This would avoid this kind of problem.

Arianna is sorting that all out in her mmio mapping series.

Ian.

#24 lore raw

Re: [PATCH 6/6] xen: arm: use superpages in p2m when pages are suitably aligned

Quoted 22 lines · Ian Campbell
Quoted 5 lines · Julien Grall

Hi Ian,

This patch looks good in general. I've only few comments, see them below.

On 06/10/2014 10:57 AM, Ian Campbell wrote:

Quoted 15 lines

xen/arch/arm/p2m.c line 35

Quoted 13 lines
xen/arch/arm/p2m.c +13 -0
+void p2m_dump_info(struct domain *d)
+{
+    struct p2m_domain *p2m = &d->arch.p2m;
+
+    spin_lock(&p2m->lock);
+    printk("p2m mappings for domain %d (vmid %d):\n",
+           d->domain_id, p2m->vmid);
+    BUG_ON(p2m->stats.mappings[0] || p2m->stats.shattered[0]);
+    printk("  1G mappings: %d (shattered %d)\n",
+           p2m->stats.mappings[1], p2m->stats.shattered[1]);
+    printk("  2M mappings: %d (shattered %d)\n",
+           p2m->stats.mappings[2], p2m->stats.shattered[2]);
+    printk("  4K mappings: %d\n", p2m->stats.mappings[3]);

I wondering if we can have more than 2^32-1 4K mapping sometimes...

Quoted 3 lines

That would be 16TB of memory, which isn't out of the question but we don't currently support it. Still, not much harm in increase to a 64-bit field.

Sounds good.

Quoted 6 lines
Quoted 4 lines

I think we should document how we pass the argument to apply_p2m_changes somewhere. Even better, use gmfn and nr_gfn, as x86 does, for apply_p2m_changes and handle internally the pfn_to_paddr stuff. This would avoid this kind of problem.

Arianna is sorting that all out in her mmio mapping series.

Oh right. Some of you will have to rebase his/her series on top of the other one :).

Regards,

Signature · 1 line
Julien Grall
#25 lore raw

Re: [PATCH 6/6] xen: arm: use superpages in p2m when pages are suitably aligned

Quoted 24 lines · Julien Grall
Quoted 22 lines · Ian Campbell
Quoted 20 lines · Julien Grall

Hi Ian,

This patch looks good in general. I've only few comments, see them below.

xen/arch/arm/p2m.c line 35

Quoted 13 lines · Ian Campbell
xen/arch/arm/p2m.c +13 -0
+void p2m_dump_info(struct domain *d)
+{
+    struct p2m_domain *p2m = &d->arch.p2m;
+
+    spin_lock(&p2m->lock);
+    printk("p2m mappings for domain %d (vmid %d):\n",
+           d->domain_id, p2m->vmid);
+    BUG_ON(p2m->stats.mappings[0] || p2m->stats.shattered[0]);
+    printk("  1G mappings: %d (shattered %d)\n",
+           p2m->stats.mappings[1], p2m->stats.shattered[1]);
+    printk("  2M mappings: %d (shattered %d)\n",
+           p2m->stats.mappings[2], p2m->stats.shattered[2]);
+    printk("  4K mappings: %d\n", p2m->stats.mappings[3]);

I wondering if we can have more than 2^32-1 4K mapping sometimes...

Quoted 5 lines
Quoted 3 lines

That would be 16TB of memory, which isn't out of the question but we don't currently support it. Still, not much harm in increase to a 64-bit field.

Sounds good.

In the end I went with unsigned long which is the size of a pfn for arm32 and arm64 and therefore not wasteful on arm32.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

I think we should document how we pass the argument to apply_p2m_changes somewhere. Even better, use gmfn and nr_gfn, as x86 does, for apply_p2m_changes and handle internally the pfn_to_paddr stuff. This would avoid this kind of problem.

Arianna is sorting that all out in her mmio mapping series.

Oh right. Some of you will have to rebase his/her series on top of the other one :).

Yes.

Ian.