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-changelog

[Xen-changelog] [linux-2.6.18-xen] xen: fix grant table bug

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [linux-2.6.18-xen] xen: fix grant table bug
From: "Xen patchbot-linux-2.6.18-xen" <patchbot-linux-2.6.18-xen@xxxxxxxxxxxxxxxxxxx>
Date: Mon, 31 Mar 2008 19:40:08 -0700
Delivery-date: Mon, 31 Mar 2008 19:40:03 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1206957787 -3600
# Node ID 4018c0da336008e5dfb1163bddbdfbc328c8f5c4
# Parent  5486a234923da1fbab13eef6165f25c54ab63bd9
xen: fix grant table bug

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>
---
 drivers/xen/core/gnttab.c |   39 +++++++++++++++++++++------------------
 1 files changed, 21 insertions(+), 18 deletions(-)

diff -r 5486a234923d -r 4018c0da3360 drivers/xen/core/gnttab.c
--- a/drivers/xen/core/gnttab.c Mon Mar 31 10:32:25 2008 +0100
+++ b/drivers/xen/core/gnttab.c Mon Mar 31 11:03:07 2008 +0100
@@ -52,7 +52,7 @@
 /* External tools reserve first few grant table entries. */
 #define NR_RESERVED_ENTRIES 8
 #define GNTTAB_LIST_END 0xffffffff
-#define GREFS_PER_GRANT_FRAME (PAGE_SIZE / sizeof(grant_entry_t))
+#define ENTRIES_PER_GRANT_FRAME (PAGE_SIZE / sizeof(grant_entry_t))
 
 static grant_ref_t **gnttab_list;
 static unsigned int nr_grant_frames;
@@ -69,6 +69,9 @@ static int gnttab_expand(unsigned int re
 
 #define RPP (PAGE_SIZE / sizeof(grant_ref_t))
 #define gnttab_entry(entry) (gnttab_list[(entry) / RPP][(entry) % RPP])
+
+#define nr_freelist_frames(grant_frames)                               \
+       (((grant_frames) * ENTRIES_PER_GRANT_FRAME + RPP - 1) / RPP)
 
 static int get_free_entries(int count)
 {
@@ -372,24 +375,25 @@ 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++)
-       {
+       extra_entries       = more_frames * ENTRIES_PER_GRANT_FRAME;
+
+       nr_glist_frames = nr_freelist_frames(nr_grant_frames);
+       new_nr_glist_frames = nr_freelist_frames(new_nr_grant_frames);
+       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])
                        goto grow_nomem;
        }
 
-
-       for (i = GREFS_PER_GRANT_FRAME * nr_grant_frames;
-            i < GREFS_PER_GRANT_FRAME * new_nr_grant_frames - 1; i++)
+       for (i = ENTRIES_PER_GRANT_FRAME * nr_grant_frames;
+            i < ENTRIES_PER_GRANT_FRAME * new_nr_grant_frames - 1; i++)
                gnttab_entry(i) = i + 1;
 
        gnttab_entry(i) = gnttab_free_head;
-       gnttab_free_head = GREFS_PER_GRANT_FRAME * nr_grant_frames;
+       gnttab_free_head = ENTRIES_PER_GRANT_FRAME * nr_grant_frames;
        gnttab_free_count += extra_entries;
 
        nr_grant_frames = new_nr_grant_frames;
@@ -399,7 +403,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;
 }
@@ -699,8 +703,8 @@ static int gnttab_expand(unsigned int re
        unsigned int cur, extra;
 
        cur = nr_grant_frames;
-       extra = ((req_entries + (GREFS_PER_GRANT_FRAME-1)) /
-                GREFS_PER_GRANT_FRAME);
+       extra = ((req_entries + (ENTRIES_PER_GRANT_FRAME-1)) /
+                ENTRIES_PER_GRANT_FRAME);
        if (cur + extra > max_nr_grant_frames())
                return -ENOSPC;
 
@@ -713,7 +717,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())
@@ -725,16 +729,15 @@ int __devinit gnttab_init(void)
        /* Determine the maximum number of frames required for the
         * 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)));
+       max_nr_glist_frames = nr_freelist_frames(boot_max_nr_grant_frames);
 
        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_freelist_frames(nr_grant_frames);
+       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;
@@ -743,7 +746,7 @@ int __devinit gnttab_init(void)
        if (gnttab_resume() < 0)
                return -ENODEV;
 
-       nr_init_grefs = nr_grant_frames * GREFS_PER_GRANT_FRAME;
+       nr_init_grefs = nr_grant_frames * ENTRIES_PER_GRANT_FRAME;
 
        for (i = NR_RESERVED_ENTRIES; i < nr_init_grefs - 1; i++)
                gnttab_entry(i) = i + 1;

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [linux-2.6.18-xen] xen: fix grant table bug, Xen patchbot-linux-2.6.18-xen <=