[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Fix alloc_skb() to ensure data is always physically contiguous.



# HG changeset patch
# User kaf24@xxxxxxxxxxxxxxxxxxxx
# Node ID 98bcd8fbd5e36662c10becdcd0222a22161bb2b6
# Parent  0915074c356e37017562298ded188c5c354ed463
Fix alloc_skb() to ensure data is always physically contiguous.
Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>

diff -r 0915074c356e -r 98bcd8fbd5e3 linux-2.6-xen-sparse/arch/xen/Kconfig
--- a/linux-2.6-xen-sparse/arch/xen/Kconfig     Tue Nov  8 14:58:31 2005
+++ b/linux-2.6-xen-sparse/arch/xen/Kconfig     Tue Nov  8 15:48:42 2005
@@ -173,6 +173,10 @@
 
 endmenu
 
+config HAVE_ARCH_ALLOC_SKB
+       bool
+       default y
+
 config HAVE_ARCH_DEV_ALLOC_SKB
        bool
        default y
diff -r 0915074c356e -r 98bcd8fbd5e3 
linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_32
--- a/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_32       Tue Nov 
 8 14:58:31 2005
+++ b/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_32       Tue Nov 
 8 15:48:42 2005
@@ -25,6 +25,7 @@
 CONFIG_XEN_SCRUB_PAGES=y
 CONFIG_XEN_X86=y
 # CONFIG_XEN_X86_64 is not set
+CONFIG_HAVE_ARCH_ALLOC_SKB=y
 CONFIG_HAVE_ARCH_DEV_ALLOC_SKB=y
 
 #
diff -r 0915074c356e -r 98bcd8fbd5e3 
linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_64
--- a/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_64       Tue Nov 
 8 14:58:31 2005
+++ b/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_64       Tue Nov 
 8 15:48:42 2005
@@ -25,6 +25,7 @@
 CONFIG_XEN_SCRUB_PAGES=y
 # CONFIG_XEN_X86 is not set
 CONFIG_XEN_X86_64=y
+CONFIG_HAVE_ARCH_ALLOC_SKB=y
 CONFIG_HAVE_ARCH_DEV_ALLOC_SKB=y
 
 #
diff -r 0915074c356e -r 98bcd8fbd5e3 
linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_32
--- a/linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_32       Tue Nov 
 8 14:58:31 2005
+++ b/linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_32       Tue Nov 
 8 15:48:42 2005
@@ -22,6 +22,7 @@
 CONFIG_XEN_SCRUB_PAGES=y
 CONFIG_XEN_X86=y
 # CONFIG_XEN_X86_64 is not set
+CONFIG_HAVE_ARCH_ALLOC_SKB=y
 CONFIG_HAVE_ARCH_DEV_ALLOC_SKB=y
 
 #
diff -r 0915074c356e -r 98bcd8fbd5e3 
linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_64
--- a/linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_64       Tue Nov 
 8 14:58:31 2005
+++ b/linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_64       Tue Nov 
 8 15:48:42 2005
@@ -22,6 +22,7 @@
 CONFIG_XEN_SCRUB_PAGES=y
 # CONFIG_XEN_X86 is not set
 CONFIG_XEN_X86_64=y
+CONFIG_HAVE_ARCH_ALLOC_SKB=y
 CONFIG_HAVE_ARCH_DEV_ALLOC_SKB=y
 
 #
diff -r 0915074c356e -r 98bcd8fbd5e3 
linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_32
--- a/linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_32        Tue Nov 
 8 14:58:31 2005
+++ b/linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_32        Tue Nov 
 8 15:48:42 2005
@@ -25,6 +25,7 @@
 CONFIG_XEN_SCRUB_PAGES=y
 CONFIG_XEN_X86=y
 # CONFIG_XEN_X86_64 is not set
+CONFIG_HAVE_ARCH_ALLOC_SKB=y
 CONFIG_HAVE_ARCH_DEV_ALLOC_SKB=y
 
 #
diff -r 0915074c356e -r 98bcd8fbd5e3 
linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_64
--- a/linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_64        Tue Nov 
 8 14:58:31 2005
+++ b/linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_64        Tue Nov 
 8 15:48:42 2005
@@ -25,6 +25,7 @@
 CONFIG_XEN_SCRUB_PAGES=y
 # CONFIG_XEN_X86 is not set
 CONFIG_XEN_X86_64=y
+CONFIG_HAVE_ARCH_ALLOC_SKB=y
 CONFIG_HAVE_ARCH_DEV_ALLOC_SKB=y
 
 #
diff -r 0915074c356e -r 98bcd8fbd5e3 
linux-2.6-xen-sparse/arch/xen/kernel/skbuff.c
--- a/linux-2.6-xen-sparse/arch/xen/kernel/skbuff.c     Tue Nov  8 14:58:31 2005
+++ b/linux-2.6-xen-sparse/arch/xen/kernel/skbuff.c     Tue Nov  8 15:48:42 2005
@@ -19,6 +19,37 @@
 
 #define MAX_SKBUFF_ORDER 2
 static kmem_cache_t *skbuff_order_cachep[MAX_SKBUFF_ORDER + 1];
+
+static struct {
+       int size;
+       kmem_cache_t *cachep;
+} skbuff_small[] = { { 512, NULL }, { 2048, NULL } };
+
+struct sk_buff *alloc_skb(unsigned int length, int gfp_mask)
+{
+       int order, i;
+       kmem_cache_t *cachep;
+
+       length = SKB_DATA_ALIGN(length) + sizeof(struct skb_shared_info);
+
+       if (length <= skbuff_small[ARRAY_SIZE(skbuff_small)-1].size) {
+               for (i = 0; skbuff_small[i].size < length; i++)
+                       continue;
+               cachep = skbuff_small[i].cachep;
+       } else {
+               order = get_order(length);
+               if (order > MAX_SKBUFF_ORDER) {
+                       printk(KERN_ALERT "Attempt to allocate order %d "
+                              "skbuff. Increase MAX_SKBUFF_ORDER.\n", order);
+                       return NULL;
+               }
+               cachep = skbuff_order_cachep[order];
+       }
+
+       length -= sizeof(struct skb_shared_info);
+
+       return alloc_skb_from_cache(cachep, length, gfp_mask);
+}
 
 struct sk_buff *__dev_alloc_skb(unsigned int length, int gfp_mask)
 {
@@ -68,8 +99,20 @@
 static int __init skbuff_init(void)
 {
        static char name[MAX_SKBUFF_ORDER + 1][20];
+       static char small_name[ARRAY_SIZE(skbuff_small)][20];
        unsigned long size;
-       int order;
+       int i, order;
+
+       for (i = 0; i < ARRAY_SIZE(skbuff_small); i++) {
+               size = skbuff_small[i].size;
+               sprintf(small_name[i], "xen-skb-%lu", size);
+               /*
+                * No ctor/dtor: objects do not span page boundaries, and they
+                * are only used on transmit path so no need for scrubbing.
+                */
+               skbuff_small[i].cachep = kmem_cache_create(
+                       small_name[i], size, size, 0, NULL, NULL);
+       }
 
        for (order = 0; order <= MAX_SKBUFF_ORDER; order++) {
                size = PAGE_SIZE << order;
@@ -82,7 +125,7 @@
 
        return 0;
 }
-__initcall(skbuff_init);
+core_initcall(skbuff_init);
 
 EXPORT_SYMBOL(__dev_alloc_skb);
 
diff -r 0915074c356e -r 98bcd8fbd5e3 linux-2.6-xen-sparse/net/core/skbuff.c
--- a/linux-2.6-xen-sparse/net/core/skbuff.c    Tue Nov  8 14:58:31 2005
+++ b/linux-2.6-xen-sparse/net/core/skbuff.c    Tue Nov  8 15:48:42 2005
@@ -129,6 +129,7 @@
  *     Buffers may only be allocated from interrupts using a @gfp_mask of
  *     %GFP_ATOMIC.
  */
+#ifndef CONFIG_HAVE_ARCH_ALLOC_SKB
 struct sk_buff *alloc_skb(unsigned int size, int gfp_mask)
 {
        struct sk_buff *skb;
@@ -166,6 +167,7 @@
        skb = NULL;
        goto out;
 }
+#endif /* !CONFIG_HAVE_ARCH_ALLOC_SKB */
 
 /**
  *     alloc_skb_from_cache    -       allocate a network buffer

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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.