WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] linux: fix grant table bug

To: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH] linux: fix grant table bug
From: Michael Abd-El-Malek <mabdelmalek@xxxxxxx>
Date: Sun, 30 Mar 2008 23:42:41 -0400
Delivery-date: Sun, 30 Mar 2008 20:45:03 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Thunderbird 2.0.0.12 (Windows/20080213)
A PV OS has two grant table data structures: the grant table itself and a free list. The free list is composed of an array of pages, which grow dynamically as the guest OS requires more grants. While the grant table contains 8-byte entries, the free list contains 4-byte entries. So we have half as many pages in the free list than in the grant table.

There was a bug in the free list allocation code. The free list was indexed as if it was the same size as the grant table. But it's only half as large. So memory got corrupted, and I was seeing crashes in the slab allocator later on.

Signed-off-by: Michael Abd-El-Malek <mabdelmalek@xxxxxxx>
diff -r 1721546b9277 drivers/xen/core/gnttab.c
--- a/drivers/xen/core/gnttab.c Fri Mar 28 01:39:23 2008 -0400
+++ b/drivers/xen/core/gnttab.c Sun Mar 30 23:24:42 2008 -0400
@@ -379,11 +379,15 @@ static int grow_gnttab_list(unsigned int
 static int grow_gnttab_list(unsigned int more_frames)
 {
        unsigned int new_nr_grant_frames, extra_entries, i;
+       unsigned int nr_glist_frames, new_nr_glist_frames;
 
        new_nr_grant_frames = nr_grant_frames + more_frames;
        extra_entries       = more_frames * GREFS_PER_GRANT_FRAME;
 
-       for (i = nr_grant_frames; i < new_nr_grant_frames; i++)
+       nr_glist_frames = (nr_grant_frames * GREFS_PER_GRANT_FRAME + RPP - 1) / 
RPP;
+       new_nr_glist_frames =
+               (new_nr_grant_frames * GREFS_PER_GRANT_FRAME + RPP - 1) / RPP;
+       for (i = nr_glist_frames; i < new_nr_glist_frames; i++)
        {
                gnttab_list[i] = (grant_ref_t *)__get_free_page(GFP_ATOMIC);
                if (!gnttab_list[i])
@@ -406,7 +410,7 @@ static int grow_gnttab_list(unsigned int
        return 0;
        
 grow_nomem:
-       for ( ; i >= nr_grant_frames; i--)
+       for ( ; i >= nr_glist_frames; i--)
                free_page((unsigned long) gnttab_list[i]);
        return -ENOMEM;
 }
@@ -720,7 +724,7 @@ int __devinit gnttab_init(void)
 int __devinit gnttab_init(void)
 {
        int i;
-       unsigned int max_nr_glist_frames;
+       unsigned int max_nr_glist_frames, nr_glist_frames;
        unsigned int nr_init_grefs;
 
        if (!is_running_on_xen())
@@ -733,15 +737,15 @@ int __devinit gnttab_init(void)
         * grant reference free list on the current hypervisor.
         */
        max_nr_glist_frames = (boot_max_nr_grant_frames *
-                              GREFS_PER_GRANT_FRAME /
-                              (PAGE_SIZE / sizeof(grant_ref_t)));
+                              GREFS_PER_GRANT_FRAME / RPP);
 
        gnttab_list = kmalloc(max_nr_glist_frames * sizeof(grant_ref_t *),
                              GFP_KERNEL);
        if (gnttab_list == NULL)
                return -ENOMEM;
 
-       for (i = 0; i < nr_grant_frames; i++) {
+       nr_glist_frames = (nr_grant_frames * GREFS_PER_GRANT_FRAME + RPP - 1) / 
RPP;
+       for (i = 0; i < nr_glist_frames; i++) {
                gnttab_list[i] = (grant_ref_t *)__get_free_page(GFP_KERNEL);
                if (gnttab_list[i] == NULL)
                        goto ini_nomem;
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>