]> xenbits.xensource.com Git - xenclient/kernel.git/commitdiff
imported patch netback-defensive.patch netback-linearise-skbs
authort_jeang <devnull@localhost>
Tue, 6 Jan 2009 12:06:02 +0000 (12:06 +0000)
committert_jeang <devnull@localhost>
Tue, 6 Jan 2009 12:06:02 +0000 (12:06 +0000)
drivers/xen/netback/netback.c

index c853fd40991ec93380dd4acb2f1d4ba1103f8a94..c91849d9dc0fd72e81f3b6261fb244ea4f838b85 100644 (file)
@@ -89,15 +89,17 @@ static inline unsigned long idx_to_kaddr(unsigned int idx)
        return (unsigned long)pfn_to_kaddr(idx_to_pfn(idx));
 }
 
-/* extra field used in struct page */
+/* we use an extra field in struct page to map pages to pending reqs */
+#define NETIF_INDEX_MASK 0xABCD0000UL    /* magic sanity check value */
 static inline void netif_set_page_index(struct page *pg, unsigned int index)
 {
-       *(unsigned long *)&pg->mapping = index;
+       *(unsigned long *)&pg->mapping = index | NETIF_INDEX_MASK;
 }
 
 static inline int netif_page_index(struct page *pg)
 {
-       unsigned long idx = (unsigned long)pg->mapping;
+       unsigned long val = (unsigned long)pg->mapping;
+       unsigned long idx = val & ~NETIF_INDEX_MASK;
 
        if (!PageForeign(pg))
                return -1;
@@ -105,6 +107,19 @@ static inline int netif_page_index(struct page *pg)
        if ((idx >= MAX_PENDING_REQS) || (mmap_pages[idx] != pg))
                return -1;
 
+       if (unlikely((val & NETIF_INDEX_MASK) != NETIF_INDEX_MASK)) {
+               printk(KERN_ERR "apparent netback page %p doesn't have NETIF_INDEX_MASK magic: %lx, dtor %#lx\n",
+                      pg, val, pg->index);
+               printk(KERN_ERR "-- page flags are %lx - %s; %s; %s\n",
+                      pg->flags,
+                      PageForeign(pg) ? "FOREIGN" : "not-foreign",
+                      PageNetback(pg) ? "NETBACK" : "not-netback",
+                      PageBlkback(pg) ? "BLKBACK" : "not-blkback");
+               printk(KERN_ERR "-- page flags are %lx\n", pg->flags);
+               printk(KERN_ERR "-- page count is %d\n", page_count(pg));
+               BUG();
+       }
+
        return idx;
 }