Skip to contentSkip to conversation

xen: restore GNTTABOP_dump_table

PATCH In review Roger Pau Monne 3 participants 6 messages Oct 19, 2012 – Nov 19, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: restore GNTTABOP_dump_table

This operation was dropped long time ago, but I found it quite helpful for debugging purposes. This re-implementation uses the code already present in gnttab_usage_print and adds the maptrack-table dump.

---
 xen/common/grant_table.c      |   83 ++++++++++++++++++++++++++++++++++++++---
 xen/include/xen/grant_table.h |    3 +
 2 files changed, 80 insertions(+), 6 deletions(-)
xen/common/grant_table.c +77 -6
index c8e342b..a5de9c6 100644
@@ -1393,6 +1393,40 @@ gnttab_setup_table(
     return 0;
 }
 
+static long
+gnttab_dump_table(
+    XEN_GUEST_HANDLE(gnttab_dump_table_t) uop, unsigned int count)
+{
+    struct gnttab_dump_table   op;
+    struct domain        *d;
+
+    if ( !IS_PRIV(current->domain) )
+        return -EPERM;
+
+    if ( unlikely(copy_from_guest(&op, uop, sizeof(op)) != 0) )
+    {
+        gdprintk(XENLOG_INFO, "Fault while reading gnttab_dump_table_t.\n");
+        return -EFAULT;
+    }
+
+    d = gt_lock_target_domain_by_id(op.dom);
+    if ( IS_ERR(d) )
+    {
+        op.status = PTR_ERR(d);
+        goto out;
+    }
+
+    gnttab_usage_print(d, 1);
+
+    rcu_unlock_domain(d);
+
+out:
+    if ( unlikely(copy_to_guest(uop, &op, 1)) )
+        return -EFAULT;
+
+    return 0;
+}
+
 static long 
 gnttab_query_size(
     XEN_GUEST_HANDLE(gnttab_query_size_t) uop, unsigned int count)
@@ -2495,6 +2529,12 @@ do_grant_table_op(
         ASSERT(rc <= 0);
         break;
     }
+    case GNTTABOP_dump_table:
+    {
+        rc = gnttab_dump_table(guest_handle_cast(uop, gnttab_dump_table_t),
+                               count);
+        break;
+    }
     case GNTTABOP_transfer:
     {
         XEN_GUEST_HANDLE(gnttab_transfer_t) transfer =
@@ -2796,7 +2836,7 @@ grant_table_destroy(
     d->grant_table = NULL;
 }
 
-void gnttab_usage_print(struct domain *rd)
+void gnttab_usage_print(struct domain *rd, int print_maptrack)
 {
     int first = 1;
     grant_ref_t ref;
@@ -2808,7 +2848,7 @@ void gnttab_usage_print(struct domain *rd)
     spin_lock(&gt->lock);
 
     if ( gt->gt_version == 0 )
-        goto out;
+        goto out_grant;
 
     for ( ref = 0; ref != nr_grant_entries(gt); ref++ )
     {
@@ -2853,12 +2893,43 @@ void gnttab_usage_print(struct domain *rd)
                sha->domid, frame, status);
     }
 
- out:
-    spin_unlock(&gt->lock);
-
+out_grant:
     if ( first )
         printk("grant-table for remote domain:%5d ... "
                "no active grant table entries\n", rd->domain_id);
+
+    if ( !print_maptrack )
+        goto out;
+
+    first = 1;
+
+    printk("      -------- maptrack --------\n");
+    printk("[ref] domid         gnt    flags\n");
+
+    for ( ref = 0; ref != gt->maptrack_limit; ref++ )
+    {
+        struct grant_mapping *maptrack = &maptrack_entry(gt, ref);
+
+        if ( maptrack->flags ) {
+
+            if ( first )
+            {
+                printk("maptrack-table for remote domain:%5d\n",
+                       rd->domain_id);
+                first = 0;
+            }
+            /*      [ddd] ddddd 0xXXXXXXXX  0xXX */
+            printk("[%3d] %5d  0x%08x     0x%02x\n",
+                    ref, maptrack->domid, maptrack->ref, maptrack->flags);
+        }
+    }
+
+    if ( first )
+        printk("maptrack-table for remote domain:%5d ... "
+               "no active maptrack table entries\n", rd->domain_id);
+
+ out:
+    spin_unlock(&gt->lock);
 }
 
 static void gnttab_usage_print_all(unsigned char key)
@@ -2866,7 +2937,7 @@ static void gnttab_usage_print_all(unsigned char key)
     struct domain *d;
     printk("%s [ key '%c' pressed\n", __FUNCTION__, key);
     for_each_domain ( d )
-        gnttab_usage_print(d);
+        gnttab_usage_print(d, 0);
     printk("%s ] done\n", __FUNCTION__);
 }
 
xen/include/xen/grant_table.h +3 -0
index 0820da1..34a8304 100644
@@ -111,6 +111,9 @@ gnttab_release_mappings(
 int
 gnttab_grow_table(struct domain *d, unsigned int req_nr_frames);
 
+/* Print grant table for given domain. */
+void gnttab_usage_print(struct domain *rd, int print_maptrack);
+
 /* Number of grant table frames. Caller must hold d's grant table lock. */
 static inline unsigned int nr_grant_frames(struct grant_table *gt)
 {
Signature · 1 line
1.7.7.5 (Apple Git-26)
#1 lore raw
Quoted 3 lines · Roger Pau Monne

This operation was dropped long time ago, but I found it quite helpful for debugging purposes. This re-implementation uses the code already present in gnttab_usage_print and adds the maptrack-table dump.

Is there any interest on this patch?

#2 lore raw
In reply to Roger Pau Monne
Quoted 3 lines · Roger Pau Monne

This operation was dropped long time ago, but I found it quite helpful for debugging purposes. This re-implementation uses the code already present in gnttab_usage_print and adds the maptrack-table dump.

Why is the operation useful? Isn't the debug key sufficient?

# xl debug-key g
(XEN) gnttab_usage_print_all [ key 'g' pressed
(XEN)       -------- active --------       -------- shared --------
(XEN) [ref] localdom mfn      pin          localdom gmfn     flags
(XEN) grant-table for remote domain:    0 ... no active grant table entries
(XEN) gnttab_usage_print_all ] done

David

#3 lore raw
Quoted 6 lines · David Vrabel
Quoted 3 lines · Roger Pau Monne

This operation was dropped long time ago, but I found it quite helpful for debugging purposes. This re-implementation uses the code already present in gnttab_usage_print and adds the maptrack-table dump.

Why is the operation useful? Isn't the debug key sufficient?

The debug key doesn't print the maptrack, and also I found it quite useful to be able to call this from the guest kernel itself at certain specific points (like before and after cleaning the list of persistent grants), which is not possible when using the debug key.

Quoted 9 lines
# xl debug-key g
(XEN) gnttab_usage_print_all [ key 'g' pressed
(XEN)       -------- active --------       -------- shared --------
(XEN) [ref] localdom mfn      pin          localdom gmfn     flags
(XEN) grant-table for remote domain:    0 ... no active grant table entries
(XEN) gnttab_usage_print_all ] done

David

#4 lore raw
Quoted 6 lines · Roger Pau Monné
Quoted 5 lines · David Vrabel
Quoted 3 lines · Roger Pau Monne

This operation was dropped long time ago, but I found it quite helpful for debugging purposes. This re-implementation uses the code already present in gnttab_usage_print and adds the maptrack-table dump.

Quoted 6 lines
Quoted 1 line

Why is the operation useful? Isn't the debug key sufficient?

The debug key doesn't print the maptrack, and also I found it quite useful to be able to call this from the guest kernel itself at certain specific points (like before and after cleaning the list of persistent grants), which is not possible when using the debug key.

I presume this involved temporarily patching Xen to allow this since you wouldn't want this function to be callable by guests in general.

Ian.

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

#5 lore raw
Quoted 9 lines · Ian Campbell
Quoted 8 lines · Roger Pau Monné
Quoted 6 lines · David Vrabel
Quoted 3 lines · Roger Pau Monne

This operation was dropped long time ago, but I found it quite helpful for debugging purposes. This re-implementation uses the code already present in gnttab_usage_print and adds the maptrack-table dump.

Why is the operation useful? Isn't the debug key sufficient?

Quoted 7 lines
Quoted 4 lines

The debug key doesn't print the maptrack, and also I found it quite useful to be able to call this from the guest kernel itself at certain specific points (like before and after cleaning the list of persistent grants), which is not possible when using the debug key.

I presume this involved temporarily patching Xen to allow this since you wouldn't want this function to be callable by guests in general.

By guest kernel I meant Dom0 kernel, sorry for the confusion. I've always used the check below to prevent non privileged kernels from getting this information:

+ if ( !IS_PRIV(current->domain) )
+ return -EPERM;

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