Skip to contentSkip to conversation

xen/arm: Add more debug in get_page_from_gva

PATCH In review Julien Grall 3 participants 9 messages Nov 15, 2017 – Nov 16, 2017

lore
Share & tools
lore
#0 lore raw

cover xen/arm: Add more debug in get_page_from_gva

Hi all,

It looks like get_page_from_gva intermittenly fails on the Arndale (see [1]) leading to Dom0 crashing.

At the moment it is a bit hard to know why given the hypervisor does not provide much information.

This series add more debug in get_page_from_gva to hopefully narrow down the issue.

I think the 2 patches are good candidate for Xen 4.10 as this may help fixing a dom0 crash on the Arndale.

Cheers,

[1] https://lists.xen.org/archives/html/xen-devel/2017-11/msg00942.html

Julien Grall (2):
xen/arm: mm: Change the return value of gvirt_to_maddr xen/arm: p2m: Add more debug in get_page_from_gva

 xen/arch/arm/domain_build.c |  8 ++++----
 xen/arch/arm/kernel.c       |  8 ++++----
 xen/arch/arm/p2m.c          | 19 ++++++++++++++++---
 xen/include/asm-arm/mm.h    |  9 +++++++--
 4 files changed, 31 insertions(+), 13 deletions(-)
Signature · 7 lines
2.11.0


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

PATCH 1/2 xen/arm: mm: Change the return value of gvirt_to_maddr

Currently, gvirt_to_maddr return -EFAULT when the translation failed. It might be useful to return the PAR_EL1 (Physical Address Register) in such a case to get a better idea of the reason.

So modify the return value to use 0 on sucess or return the PAR on failure.

The callers are modified to reflect the change of the return value.

Note that with the change in gvirt_to_maddr, ma needs to be initialized to avoid GCC been confused (i.e value may be unitialized) with the new construction.

---
 xen/arch/arm/domain_build.c | 8 ++++----
 xen/arch/arm/kernel.c       | 8 ++++----
 xen/arch/arm/p2m.c          | 6 +++---
 xen/include/asm-arm/mm.h    | 9 +++++++--
 4 files changed, 18 insertions(+), 13 deletions(-)
xen/arch/arm/domain_build.c +4 -4
index bf29299707..c74f4dd69d 100644
@@ -2002,15 +2002,15 @@ static void initrd_load(struct kernel_info *kinfo)
 
     for ( offs = 0; offs < len; )
     {
-        int rc;
-        paddr_t s, l, ma;
+        uint64_t par;
+        paddr_t s, l, ma = 0;
         void *dst;
 
         s = offs & ~PAGE_MASK;
         l = min(PAGE_SIZE - s, len);
 
-        rc = gvirt_to_maddr(load_addr + offs, &ma, GV2M_WRITE);
-        if ( rc )
+        par = gvirt_to_maddr(load_addr + offs, &ma, GV2M_WRITE);
+        if ( par )
         {
             panic("Unable to translate guest address");
             return;
xen/arch/arm/kernel.c +4 -4
index c2755a9ab9..a6c6413712 100644
@@ -167,15 +167,15 @@ static void kernel_zimage_load(struct kernel_info *info)
            paddr, load_addr, load_addr + len);
     for ( offs = 0; offs < len; )
     {
-        int rc;
-        paddr_t s, l, ma;
+        uint64_t par;
+        paddr_t s, l, ma = 0;
         void *dst;
 
         s = offs & ~PAGE_MASK;
         l = min(PAGE_SIZE - s, len);
 
-        rc = gvirt_to_maddr(load_addr + offs, &ma, GV2M_WRITE);
-        if ( rc )
+        par = gvirt_to_maddr(load_addr + offs, &ma, GV2M_WRITE);
+        if ( par )
         {
             panic("Unable to map translate guest address");
             return;
xen/arch/arm/p2m.c +3 -3
index 68b488997d..f6b3d8e421 100644
@@ -1414,7 +1414,7 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
     struct page_info *page = NULL;
     paddr_t maddr = 0;
-    int rc;
+    uint64_t par;
 
     /*
      * XXX: To support a different vCPU, we would need to load the
@@ -1425,9 +1425,9 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
 
     p2m_read_lock(p2m);
 
-    rc = gvirt_to_maddr(va, &maddr, flags);
+    par = gvirt_to_maddr(va, &maddr, flags);
 
-    if ( rc )
+    if ( par )
         goto err;
 
     if ( !mfn_valid(maddr_to_mfn(maddr)) )
xen/include/asm-arm/mm.h +7 -2
index cd6dfb54b9..ad2f2a43dc 100644
@@ -266,11 +266,16 @@ static inline void *maddr_to_virt(paddr_t ma)
 }
 #endif
 
-static inline int gvirt_to_maddr(vaddr_t va, paddr_t *pa, unsigned int flags)
+/*
+ * Translate a guest virtual address to a machine address.
+ * Return the fault information if the translation has failed else 0.
+ */
+static inline uint64_t gvirt_to_maddr(vaddr_t va, paddr_t *pa,
+                                      unsigned int flags)
 {
     uint64_t par = gva_to_ma_par(va, flags);
     if ( par & PAR_F )
-        return -EFAULT;
+        return par;
     *pa = (par & PADDR_MASK & PAGE_MASK) | ((unsigned long) va & ~PAGE_MASK);
     return 0;
 }
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH for-4.10 1/2] xen/arm: mm: Change the return value of gvirt_to_maddr

Quoted 5 lines · Julien Grall

Currently, gvirt_to_maddr return -EFAULT when the translation failed. It might be useful to return the PAR_EL1 (Physical Address Register) in such a case to get a better idea of the reason.

So modify the return value to use 0 on sucess or return the PAR on

^ success

Quoted 6 lines

failure.

The callers are modified to reflect the change of the return value.

Note that with the change in gvirt_to_maddr, ma needs to be initialized to avoid GCC been confused (i.e value may be unitialized) with the new

^ uninitialized

Quoted 3 lines

construction.

I fixed on commit

Quoted 106 lines
---
 xen/arch/arm/domain_build.c | 8 ++++----
 xen/arch/arm/kernel.c       | 8 ++++----
 xen/arch/arm/p2m.c          | 6 +++---
 xen/include/asm-arm/mm.h    | 9 +++++++--
 4 files changed, 18 insertions(+), 13 deletions(-)
xen/arch/arm/domain_build.c +4 -4
index bf29299707..c74f4dd69d 100644
@@ -2002,15 +2002,15 @@ static void initrd_load(struct kernel_info *kinfo)
 
     for ( offs = 0; offs < len; )
     {
-        int rc;
-        paddr_t s, l, ma;
+        uint64_t par;
+        paddr_t s, l, ma = 0;
         void *dst;
 
         s = offs & ~PAGE_MASK;
         l = min(PAGE_SIZE - s, len);
 
-        rc = gvirt_to_maddr(load_addr + offs, &ma, GV2M_WRITE);
-        if ( rc )
+        par = gvirt_to_maddr(load_addr + offs, &ma, GV2M_WRITE);
+        if ( par )
         {
             panic("Unable to translate guest address");
             return;
xen/arch/arm/kernel.c +4 -4
index c2755a9ab9..a6c6413712 100644
@@ -167,15 +167,15 @@ static void kernel_zimage_load(struct kernel_info *info)
            paddr, load_addr, load_addr + len);
     for ( offs = 0; offs < len; )
     {
-        int rc;
-        paddr_t s, l, ma;
+        uint64_t par;
+        paddr_t s, l, ma = 0;
         void *dst;
 
         s = offs & ~PAGE_MASK;
         l = min(PAGE_SIZE - s, len);
 
-        rc = gvirt_to_maddr(load_addr + offs, &ma, GV2M_WRITE);
-        if ( rc )
+        par = gvirt_to_maddr(load_addr + offs, &ma, GV2M_WRITE);
+        if ( par )
         {
             panic("Unable to map translate guest address");
             return;
xen/arch/arm/p2m.c +3 -3
index 68b488997d..f6b3d8e421 100644
@@ -1414,7 +1414,7 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
     struct page_info *page = NULL;
     paddr_t maddr = 0;
-    int rc;
+    uint64_t par;
 
     /*
      * XXX: To support a different vCPU, we would need to load the
@@ -1425,9 +1425,9 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
 
     p2m_read_lock(p2m);
 
-    rc = gvirt_to_maddr(va, &maddr, flags);
+    par = gvirt_to_maddr(va, &maddr, flags);
 
-    if ( rc )
+    if ( par )
         goto err;
 
     if ( !mfn_valid(maddr_to_mfn(maddr)) )
xen/include/asm-arm/mm.h +7 -2
index cd6dfb54b9..ad2f2a43dc 100644
@@ -266,11 +266,16 @@ static inline void *maddr_to_virt(paddr_t ma)
 }
 #endif
 
-static inline int gvirt_to_maddr(vaddr_t va, paddr_t *pa, unsigned int flags)
+/*
+ * Translate a guest virtual address to a machine address.
+ * Return the fault information if the translation has failed else 0.
+ */
+static inline uint64_t gvirt_to_maddr(vaddr_t va, paddr_t *pa,
+                                      unsigned int flags)
 {
     uint64_t par = gva_to_ma_par(va, flags);
     if ( par & PAR_F )
-        return -EFAULT;
+        return par;
     *pa = (par & PADDR_MASK & PAGE_MASK) | ((unsigned long) va & ~PAGE_MASK);
     return 0;
 }
Signature · 1 line
2.11.0

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

#3 lore raw

PATCH 2/2 xen/arm: p2m: Add more debug in get_page_from_gva

In reply to Julien Grall

The function get_page_from_gva is used by copy_*_guest helpers to translate a guest virtual address to a machine physical address and take reference on the page.

There are a couple of errors path that will return the same value making difficult to know the exact error. Add more debug in each error patch only for debug-build.

This should help narrowing down the intermittent failure with the hypercall GNTTABOP_copy (see [1]).

[1] https://lists.xen.org/archives/html/xen-devel/2017-11/msg00942.html

---
 xen/arch/arm/p2m.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
xen/arch/arm/p2m.c +13 -0
index f6b3d8e421..417609ede2 100644
@@ -1428,16 +1428,29 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
     par = gvirt_to_maddr(va, &maddr, flags);
 
     if ( par )
+    {
+        dprintk(XENLOG_G_DEBUG,
+                "%pv: gvirt_to_maddr failed va=%#"PRIvaddr" flags=0x%lx par=%#"PRIx64"\n",
+                v, va, flags, par);
         goto err;
+    }
 
     if ( !mfn_valid(maddr_to_mfn(maddr)) )
+    {
+        dprintk(XENLOG_G_DEBUG, "%pv: Invalid MFN %#"PRI_mfn"\n",
+                v, mfn_x(maddr_to_mfn(maddr)));
         goto err;
+    }
 
     page = mfn_to_page(maddr_to_mfn(maddr));
     ASSERT(page);
 
     if ( unlikely(!get_page(page, d)) )
+    {
+        dprintk(XENLOG_G_DEBUG, "%pv: Failing to acquire the MFN %#"PRI_mfn"\n",
+                v, mfn_x(maddr_to_mfn(maddr)));
         page = NULL;
+    }
 
 err:
     if ( !page && p2m->mem_access_enabled )
Signature · 7 lines
2.11.0


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

Re: [PATCH for-4.10 2/2] xen/arm: p2m: Add more debug in get_page_from_gva

Quoted 23 lines · Julien Grall

The function get_page_from_gva is used by copy_*_guest helpers to translate a guest virtual address to a machine physical address and take reference on the page.

There are a couple of errors path that will return the same value making difficult to know the exact error. Add more debug in each error patch only for debug-build.

This should help narrowing down the intermittent failure with the hypercall GNTTABOP_copy (see [1]).

[1] https://lists.xen.org/archives/html/xen-devel/2017-11/msg00942.html

---
 xen/arch/arm/p2m.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
xen/arch/arm/p2m.c +0 -0
index f6b3d8e421..417609ede2 100644

xen/arch/arm/p2m.c struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va, · line 1434

Quoted 7 lines
xen/arch/arm/p2m.c +4 -0
@@ -1428,16 +1428,29 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
     par = gvirt_to_maddr(va, &maddr, flags);
 
     if ( par )
+    {
+        dprintk(XENLOG_G_DEBUG,
+                "%pv: gvirt_to_maddr failed va=%#"PRIvaddr" flags=0x%lx par=%#"PRIx64"\n",
+                v, va, flags, par);

Given the long round-trip time on debugging output, how about trying to dump the guest and/or second stage table walk?

~Andrew

Quoted 12 lines
xen/arch/arm/p2m.c +5 -0
         goto err;
+    }
 
     if ( !mfn_valid(maddr_to_mfn(maddr)) )
+    {
+        dprintk(XENLOG_G_DEBUG, "%pv: Invalid MFN %#"PRI_mfn"\n",
+                v, mfn_x(maddr_to_mfn(maddr)));
         goto err;
+    }
 
     page = mfn_to_page(maddr_to_mfn(maddr));
     ASSERT(page);

xen/arch/arm/p2m.c struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va, · line 1456

Quoted 10 lines
xen/arch/arm/p2m.c +4 -0
 
     if ( unlikely(!get_page(page, d)) )
+    {
+        dprintk(XENLOG_G_DEBUG, "%pv: Failing to acquire the MFN %#"PRI_mfn"\n",
+                v, mfn_x(maddr_to_mfn(maddr)));
         page = NULL;
+    }
 
 err:
     if ( !page && p2m->mem_access_enabled )

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

#5 lore raw

Re: [PATCH for-4.10 2/2] xen/arm: p2m: Add more debug in get_page_from_gva

Hi Andrew,

Quoted 26 lines · Andrew Cooper
Quoted 25 lines · Julien Grall

The function get_page_from_gva is used by copy_*_guest helpers to translate a guest virtual address to a machine physical address and take reference on the page.

There are a couple of errors path that will return the same value making difficult to know the exact error. Add more debug in each error patch only for debug-build.

This should help narrowing down the intermittent failure with the hypercall GNTTABOP_copy (see [1]).

[1] https://lists.xen.org/archives/html/xen-devel/2017-11/msg00942.html

---
  xen/arch/arm/p2m.c | 13 +++++++++++++
  1 file changed, 13 insertions(+)
xen/arch/arm/p2m.c +0 -0
index f6b3d8e421..417609ede2 100644
@@ -1428,16 +1428,29 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
      par = gvirt_to_maddr(va, &maddr, flags);
 
Quoted 8 lines

xen/arch/arm/p2m.c struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va, · line 1434

Quoted 5 lines
xen/arch/arm/p2m.c +4 -0
      if ( par )
+    {
+        dprintk(XENLOG_G_DEBUG,
+                "%pv: gvirt_to_maddr failed va=%#"PRIvaddr" flags=0x%lx par=%#"PRIx64"\n",
+                v, va, flags, par);

Given the long round-trip time on debugging output, how about trying to dump the guest and/or second stage table walk?

I thought about it, however at the moment dump_s1_guest_walk() is very minimal and would be add much value here. Thought, Now that we have code to do first-stage walk (see guest_walk_tables), we might be able to get a better dump here. Thought I am not sure it would be 4.10 material.

However, I think we could try to translate the guest VA to a guest PA using hardware instruction and then do the second-stage walk using dump_p2m_lookup.

Let me have a look.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v1 2/2
#6 lore raw

Re: [PATCH for-4.10 2/2] xen/arm: p2m: Add more debug in get_page_from_gva

In reply to Julien Grall
Quoted 5 lines · Julien Grall

The function get_page_from_gva is used by copy_*_guest helpers to translate a guest virtual address to a machine physical address and take reference on the page.

There are a couple of errors path that will return the same value making

^ paths

Quoted 1 line

difficult to know the exact error. Add more debug in each error patch

^ it difficult

Quoted 8 lines

only for debug-build.

This should help narrowing down the intermittent failure with the hypercall GNTTABOP_copy (see [1]).

[1] https://lists.xen.org/archives/html/xen-devel/2017-11/msg00942.html

fixed on commit

Quoted 28 lines
---
 xen/arch/arm/p2m.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
xen/arch/arm/p2m.c +9 -0
index f6b3d8e421..417609ede2 100644
@@ -1428,16 +1428,29 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
     par = gvirt_to_maddr(va, &maddr, flags);
 
     if ( par )
+    {
+        dprintk(XENLOG_G_DEBUG,
+                "%pv: gvirt_to_maddr failed va=%#"PRIvaddr" flags=0x%lx par=%#"PRIx64"\n",
+                v, va, flags, par);
         goto err;
+    }
 
     if ( !mfn_valid(maddr_to_mfn(maddr)) )
+    {
+        dprintk(XENLOG_G_DEBUG, "%pv: Invalid MFN %#"PRI_mfn"\n",
+                v, mfn_x(maddr_to_mfn(maddr)));
         goto err;
+    }
 
     page = mfn_to_page(maddr_to_mfn(maddr));
     ASSERT(page);

xen/arch/arm/p2m.c struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va, · line 1456

Quoted 10 lines
xen/arch/arm/p2m.c +4 -0
 
     if ( unlikely(!get_page(page, d)) )
+    {
+        dprintk(XENLOG_G_DEBUG, "%pv: Failing to acquire the MFN %#"PRI_mfn"\n",
+                v, mfn_x(maddr_to_mfn(maddr)));
         page = NULL;
+    }
 
 err:
     if ( !page && p2m->mem_access_enabled )

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

#7 lore raw

Re: [PATCH for-4.10 2/2] xen/arm: p2m: Add more debug in get_page_from_gva

Quoted 17 lines · Stefano Stabellini
Quoted 5 lines · Julien Grall

The function get_page_from_gva is used by copy_*_guest helpers to translate a guest virtual address to a machine physical address and take reference on the page.

There are a couple of errors path that will return the same value making

^ paths

Quoted 1 line

difficult to know the exact error. Add more debug in each error patch

^ it difficult

Quoted 5 lines

only for debug-build.

This should help narrowing down the intermittent failure with the hypercall GNTTABOP_copy (see [1]).

Quoted 7 lines
Quoted 3 lines

[1] https://lists.xen.org/archives/html/xen-devel/2017-11/msg00942.html

fixed on commit

I am not sure why this was merged given Andrew gave some comments...

Quoted 38 lines
Quoted 38 lines

---
  xen/arch/arm/p2m.c | 13 +++++++++++++
  1 file changed, 13 insertions(+)
xen/arch/arm/p2m.c +13 -0
index f6b3d8e421..417609ede2 100644
@@ -1428,16 +1428,29 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
      par = gvirt_to_maddr(va, &maddr, flags);
 
      if ( par )
+    {
+        dprintk(XENLOG_G_DEBUG,
+                "%pv: gvirt_to_maddr failed va=%#"PRIvaddr" flags=0x%lx par=%#"PRIx64"\n",
+                v, va, flags, par);
          goto err;
+    }
 
      if ( !mfn_valid(maddr_to_mfn(maddr)) )
+    {
+        dprintk(XENLOG_G_DEBUG, "%pv: Invalid MFN %#"PRI_mfn"\n",
+                v, mfn_x(maddr_to_mfn(maddr)));
          goto err;
+    }
 
      page = mfn_to_page(maddr_to_mfn(maddr));
      ASSERT(page);
 
      if ( unlikely(!get_page(page, d)) )
+    {
+        dprintk(XENLOG_G_DEBUG, "%pv: Failing to acquire the MFN %#"PRI_mfn"\n",
+                v, mfn_x(maddr_to_mfn(maddr)));
          page = NULL;
+    }
 
Quoted 2 lines

xen/arch/arm/p2m.c struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va, · line 1456

Quoted 2 lines
xen/arch/arm/p2m.c +0 -0
  err:
      if ( !page && p2m->mem_access_enabled )

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

#8 lore raw

Re: [PATCH for-4.10 2/2] xen/arm: p2m: Add more debug in get_page_from_gva

Quoted 20 lines · Julien Grall
Quoted 19 lines · Stefano Stabellini
Quoted 5 lines · Julien Grall

The function get_page_from_gva is used by copy_*_guest helpers to translate a guest virtual address to a machine physical address and take reference on the page.

There are a couple of errors path that will return the same value making

^ paths

Quoted 1 line

difficult to know the exact error. Add more debug in each error patch

^ it difficult

Quoted 7 lines

only for debug-build.

This should help narrowing down the intermittent failure with the hypercall GNTTABOP_copy (see [1]).

[1] https://lists.xen.org/archives/html/xen-devel/2017-11/msg00942.html

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

fixed on commit

I am not sure why this was merged given Andrew gave some comments...

Sorry Andrew! I missed your reply!

Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
---
  xen/arch/arm/p2m.c | 13 +++++++++++++
  1 file changed, 13 insertions(+)
xen/arch/arm/p2m.c +9 -0
index f6b3d8e421..417609ede2 100644
@@ -1428,16 +1428,29 @@ struct page_info *get_page_from_gva(struct vcpu
 *v, vaddr_t va,
      par = gvirt_to_maddr(va, &maddr, flags);
        if ( par )
+    {
+        dprintk(XENLOG_G_DEBUG,
+                "%pv: gvirt_to_maddr failed va=%#"PRIvaddr" flags=0x%lx
 par=%#"PRIx64"\n",
+                v, va, flags, par);
          goto err;
+    }
        if ( !mfn_valid(maddr_to_mfn(maddr)) )
+    {
+        dprintk(XENLOG_G_DEBUG, "%pv: Invalid MFN %#"PRI_mfn"\n",
+                v, mfn_x(maddr_to_mfn(maddr)));
          goto err;
+    }
        page = mfn_to_page(maddr_to_mfn(maddr));
      ASSERT(page);
        if ( unlikely(!get_page(page, d)) )
Quoted 9 lines
Quoted 8 lines

xen/arch/arm/p2m.c struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va, · line 1456

Quoted 8 lines
xen/arch/arm/p2m.c +4 -0
+    {
+        dprintk(XENLOG_G_DEBUG, "%pv: Failing to acquire the MFN
 %#"PRI_mfn"\n",
+                v, mfn_x(maddr_to_mfn(maddr)));
          page = NULL;
+    }
    err:
      if ( !page && p2m->mem_access_enabled )

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