tools/mfn-dump: Fixes to 'dump-p2m'
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 24 Apr 2014 21:06:27 +0000 (22:06 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Fri, 2 May 2014 12:34:35 +0000 (13:34 +0100)
* Don't walk off the end of p2m_table under the mistaken impression that it
  contains toolstack unsigned longs.  Despite its array type it contains guest
  unsigned longs so unconditionally needs casting to the guest width to use
  correctly.  Furthermore, a 64bit toolstack must be extra careful when it
  finds a 32bit guest's INVALID_MFN.

* Drop 'mapped' and 'pinned' descriptions.  This are both bogus, including all
  uses of the is_mapped() macro.

* Rearrange the type name printing to be more concise.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Dario Faggioli <dario.faggioli@citrix.com>
Reviewed-by: Dario Faggioli <dario.faggioli@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/misc/xen-mfndump.c

index e1ea536754ec145c7b0a64bbb382dcebf53e8067..1af3bd8060ad2b61c9c166c8d2a5d13b5de9faa9 100644 (file)
@@ -101,43 +101,47 @@ int dump_p2m_func(int argc, char *argv[])
     {
         unsigned long pagetype = minfo.pfn_type[i] &
                                      XEN_DOMCTL_PFINFO_LTAB_MASK;
+        xen_pfn_t mfn;
 
-        printf("  pfn=0x%lx ==> mfn=0x%lx (type 0x%lx)", i, minfo.p2m_table[i],
-               pagetype >> XEN_DOMCTL_PFINFO_LTAB_SHIFT);
-
-        if ( is_mapped(minfo.p2m_table[i]) )
-            printf(" [mapped]");
-
-        if ( pagetype & XEN_DOMCTL_PFINFO_LPINTAB )
-            printf (" [pinned]");
-
-        if ( pagetype == XEN_DOMCTL_PFINFO_XTAB )
-            printf(" [xtab]");
-        if ( pagetype == XEN_DOMCTL_PFINFO_BROKEN )
-            printf(" [broken]");
-        if ( pagetype == XEN_DOMCTL_PFINFO_XALLOC )
-            printf( " [xalloc]");
-
-        switch ( pagetype & XEN_DOMCTL_PFINFO_LTABTYPE_MASK )
+        if ( minfo.guest_width == sizeof(uint64_t) )
+            mfn = ((uint64_t*)minfo.p2m_table)[i];
+        else
         {
-            case XEN_DOMCTL_PFINFO_L1TAB:
-                printf(" L1 table");
-                break;
-
-            case XEN_DOMCTL_PFINFO_L2TAB:
-                printf(" L2 table");
-                break;
+            mfn = ((uint32_t*)minfo.p2m_table)[i];
+#ifdef __x86_64__
+            if ( mfn == ~0U ) /* Expand a 32bit guest's idea of INVALID_MFN */
+                mfn = ~0UL;
+#endif
+        }
 
-            case XEN_DOMCTL_PFINFO_L3TAB:
-                printf(" L3 table");
-                break;
+        printf("  pfn=0x%lx ==> mfn=0x%lx (type 0x%lx)", i, mfn,
+               pagetype >> XEN_DOMCTL_PFINFO_LTAB_SHIFT);
 
-            case XEN_DOMCTL_PFINFO_L4TAB:
-                printf(" L4 table");
-                break;
+        switch ( pagetype >> XEN_DOMCTL_PFINFO_LTAB_SHIFT )
+        {
+        case 0x0: /* NOTAB */
+            printf("\n");
+            break;
+        case 0x1 ... 0x4: /* L1 -> L4 */
+            printf(" L%lu\n", pagetype >> XEN_DOMCTL_PFINFO_LTAB_SHIFT);
+            break;
+        case 0x9 ... 0xc: /* Pinned L1 -> L4 */
+            printf(" pinned L%lu\n",
+                   (pagetype >> XEN_DOMCTL_PFINFO_LTAB_SHIFT) & 7);
+            break;
+        case 0xd: /* BROKEN */
+            printf(" broken\n");
+            break;
+        case 0xe: /* XALLOC */
+            printf(" xalloc\n");
+            break;
+        case 0xf: /* XTAB */
+            printf(" invalid\n");
+            break;
+        default:
+            printf(" <invalid type>\n");
+            break;
         }
-
-        printf("\n");
     }
     printf(" --- End of P2M for domain %d ---\n", domid);