aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'net/core/skbuff.c')
-rw-r--r--net/core/skbuff.c44
1 files changed, 37 insertions, 7 deletions
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index cd759409eacb..6cca6a0c5751 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -398,7 +398,11 @@ struct sk_buff *__netdev_alloc_skb(struct net_device *dev, unsigned int len,
398 398
399 len += NET_SKB_PAD; 399 len += NET_SKB_PAD;
400 400
401 if ((len > SKB_WITH_OVERHEAD(PAGE_SIZE)) || 401 /* If requested length is either too small or too big,
402 * we use kmalloc() for skb->head allocation.
403 */
404 if (len <= SKB_WITH_OVERHEAD(1024) ||
405 len > SKB_WITH_OVERHEAD(PAGE_SIZE) ||
402 (gfp_mask & (__GFP_DIRECT_RECLAIM | GFP_DMA))) { 406 (gfp_mask & (__GFP_DIRECT_RECLAIM | GFP_DMA))) {
403 skb = __alloc_skb(len, gfp_mask, SKB_ALLOC_RX, NUMA_NO_NODE); 407 skb = __alloc_skb(len, gfp_mask, SKB_ALLOC_RX, NUMA_NO_NODE);
404 if (!skb) 408 if (!skb)
@@ -459,13 +463,17 @@ EXPORT_SYMBOL(__netdev_alloc_skb);
459struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, unsigned int len, 463struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, unsigned int len,
460 gfp_t gfp_mask) 464 gfp_t gfp_mask)
461{ 465{
462 struct napi_alloc_cache *nc = this_cpu_ptr(&napi_alloc_cache); 466 struct napi_alloc_cache *nc;
463 struct sk_buff *skb; 467 struct sk_buff *skb;
464 void *data; 468 void *data;
465 469
466 len += NET_SKB_PAD + NET_IP_ALIGN; 470 len += NET_SKB_PAD + NET_IP_ALIGN;
467 471
468 if ((len > SKB_WITH_OVERHEAD(PAGE_SIZE)) || 472 /* If requested length is either too small or too big,
473 * we use kmalloc() for skb->head allocation.
474 */
475 if (len <= SKB_WITH_OVERHEAD(1024) ||
476 len > SKB_WITH_OVERHEAD(PAGE_SIZE) ||
469 (gfp_mask & (__GFP_DIRECT_RECLAIM | GFP_DMA))) { 477 (gfp_mask & (__GFP_DIRECT_RECLAIM | GFP_DMA))) {
470 skb = __alloc_skb(len, gfp_mask, SKB_ALLOC_RX, NUMA_NO_NODE); 478 skb = __alloc_skb(len, gfp_mask, SKB_ALLOC_RX, NUMA_NO_NODE);
471 if (!skb) 479 if (!skb)
@@ -473,6 +481,7 @@ struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, unsigned int len,
473 goto skb_success; 481 goto skb_success;
474 } 482 }
475 483
484 nc = this_cpu_ptr(&napi_alloc_cache);
476 len += SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); 485 len += SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
477 len = SKB_DATA_ALIGN(len); 486 len = SKB_DATA_ALIGN(len);
478 487
@@ -1853,6 +1862,12 @@ int pskb_trim_rcsum_slow(struct sk_buff *skb, unsigned int len)
1853 skb->csum = csum_block_sub(skb->csum, 1862 skb->csum = csum_block_sub(skb->csum,
1854 skb_checksum(skb, len, delta, 0), 1863 skb_checksum(skb, len, delta, 0),
1855 len); 1864 len);
1865 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
1866 int hdlen = (len > skb_headlen(skb)) ? skb_headlen(skb) : len;
1867 int offset = skb_checksum_start_offset(skb) + skb->csum_offset;
1868
1869 if (offset + sizeof(__sum16) > hdlen)
1870 return -EINVAL;
1856 } 1871 }
1857 return __pskb_trim(skb, len); 1872 return __pskb_trim(skb, len);
1858} 1873}
@@ -1962,7 +1977,7 @@ void *__pskb_pull_tail(struct sk_buff *skb, int delta)
1962 /* Free pulled out fragments. */ 1977 /* Free pulled out fragments. */
1963 while ((list = skb_shinfo(skb)->frag_list) != insp) { 1978 while ((list = skb_shinfo(skb)->frag_list) != insp) {
1964 skb_shinfo(skb)->frag_list = list->next; 1979 skb_shinfo(skb)->frag_list = list->next;
1965 kfree_skb(list); 1980 consume_skb(list);
1966 } 1981 }
1967 /* And insert new clone at head. */ 1982 /* And insert new clone at head. */
1968 if (clone) { 1983 if (clone) {
@@ -2690,8 +2705,11 @@ skb_zerocopy_headlen(const struct sk_buff *from)
2690 2705
2691 if (!from->head_frag || 2706 if (!from->head_frag ||
2692 skb_headlen(from) < L1_CACHE_BYTES || 2707 skb_headlen(from) < L1_CACHE_BYTES ||
2693 skb_shinfo(from)->nr_frags >= MAX_SKB_FRAGS) 2708 skb_shinfo(from)->nr_frags >= MAX_SKB_FRAGS) {
2694 hlen = skb_headlen(from); 2709 hlen = skb_headlen(from);
2710 if (!hlen)
2711 hlen = from->len;
2712 }
2695 2713
2696 if (skb_has_frag_list(from)) 2714 if (skb_has_frag_list(from))
2697 hlen = from->len; 2715 hlen = from->len;
@@ -3077,7 +3095,19 @@ EXPORT_SYMBOL(skb_split);
3077 */ 3095 */
3078static int skb_prepare_for_shift(struct sk_buff *skb) 3096static int skb_prepare_for_shift(struct sk_buff *skb)
3079{ 3097{
3080 return skb_cloned(skb) && pskb_expand_head(skb, 0, 0, GFP_ATOMIC); 3098 int ret = 0;
3099
3100 if (skb_cloned(skb)) {
3101 /* Save and restore truesize: pskb_expand_head() may reallocate
3102 * memory where ksize(kmalloc(S)) != ksize(kmalloc(S)), but we
3103 * cannot change truesize at this point.
3104 */
3105 unsigned int save_truesize = skb->truesize;
3106
3107 ret = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3108 skb->truesize = save_truesize;
3109 }
3110 return ret;
3081} 3111}
3082 3112
3083/** 3113/**
@@ -5452,7 +5482,7 @@ static int pskb_carve_frag_list(struct sk_buff *skb,
5452 /* Free pulled out fragments. */ 5482 /* Free pulled out fragments. */
5453 while ((list = shinfo->frag_list) != insp) { 5483 while ((list = shinfo->frag_list) != insp) {
5454 shinfo->frag_list = list->next; 5484 shinfo->frag_list = list->next;
5455 kfree_skb(list); 5485 consume_skb(list);
5456 } 5486 }
5457 /* And insert new clone at head. */ 5487 /* And insert new clone at head. */
5458 if (clone) { 5488 if (clone) {