diff options
-rw-r--r-- | include/linux/skbuff.h | 1 | ||||
-rw-r--r-- | net/core/skbuff.c | 31 | ||||
-rw-r--r-- | net/netlink/af_netlink.c | 6 |
3 files changed, 25 insertions, 13 deletions
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 06793b598f44..66e374d62f64 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h | |||
@@ -773,6 +773,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from, | |||
773 | 773 | ||
774 | struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags, | 774 | struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags, |
775 | int node); | 775 | int node); |
776 | struct sk_buff *__build_skb(void *data, unsigned int frag_size); | ||
776 | struct sk_buff *build_skb(void *data, unsigned int frag_size); | 777 | struct sk_buff *build_skb(void *data, unsigned int frag_size); |
777 | static inline struct sk_buff *alloc_skb(unsigned int size, | 778 | static inline struct sk_buff *alloc_skb(unsigned int size, |
778 | gfp_t priority) | 779 | gfp_t priority) |
diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 456ead534e10..3cfff2a3d651 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c | |||
@@ -280,13 +280,14 @@ nodata: | |||
280 | EXPORT_SYMBOL(__alloc_skb); | 280 | EXPORT_SYMBOL(__alloc_skb); |
281 | 281 | ||
282 | /** | 282 | /** |
283 | * build_skb - build a network buffer | 283 | * __build_skb - build a network buffer |
284 | * @data: data buffer provided by caller | 284 | * @data: data buffer provided by caller |
285 | * @frag_size: size of fragment, or 0 if head was kmalloced | 285 | * @frag_size: size of data, or 0 if head was kmalloced |
286 | * | 286 | * |
287 | * Allocate a new &sk_buff. Caller provides space holding head and | 287 | * Allocate a new &sk_buff. Caller provides space holding head and |
288 | * skb_shared_info. @data must have been allocated by kmalloc() only if | 288 | * skb_shared_info. @data must have been allocated by kmalloc() only if |
289 | * @frag_size is 0, otherwise data should come from the page allocator. | 289 | * @frag_size is 0, otherwise data should come from the page allocator |
290 | * or vmalloc() | ||
290 | * The return is the new skb buffer. | 291 | * The return is the new skb buffer. |
291 | * On a failure the return is %NULL, and @data is not freed. | 292 | * On a failure the return is %NULL, and @data is not freed. |
292 | * Notes : | 293 | * Notes : |
@@ -297,7 +298,7 @@ EXPORT_SYMBOL(__alloc_skb); | |||
297 | * before giving packet to stack. | 298 | * before giving packet to stack. |
298 | * RX rings only contains data buffers, not full skbs. | 299 | * RX rings only contains data buffers, not full skbs. |
299 | */ | 300 | */ |
300 | struct sk_buff *build_skb(void *data, unsigned int frag_size) | 301 | struct sk_buff *__build_skb(void *data, unsigned int frag_size) |
301 | { | 302 | { |
302 | struct skb_shared_info *shinfo; | 303 | struct skb_shared_info *shinfo; |
303 | struct sk_buff *skb; | 304 | struct sk_buff *skb; |
@@ -311,11 +312,6 @@ struct sk_buff *build_skb(void *data, unsigned int frag_size) | |||
311 | 312 | ||
312 | memset(skb, 0, offsetof(struct sk_buff, tail)); | 313 | memset(skb, 0, offsetof(struct sk_buff, tail)); |
313 | skb->truesize = SKB_TRUESIZE(size); | 314 | skb->truesize = SKB_TRUESIZE(size); |
314 | if (frag_size) { | ||
315 | skb->head_frag = 1; | ||
316 | if (virt_to_head_page(data)->pfmemalloc) | ||
317 | skb->pfmemalloc = 1; | ||
318 | } | ||
319 | atomic_set(&skb->users, 1); | 315 | atomic_set(&skb->users, 1); |
320 | skb->head = data; | 316 | skb->head = data; |
321 | skb->data = data; | 317 | skb->data = data; |
@@ -332,6 +328,23 @@ struct sk_buff *build_skb(void *data, unsigned int frag_size) | |||
332 | 328 | ||
333 | return skb; | 329 | return skb; |
334 | } | 330 | } |
331 | |||
332 | /* build_skb() is wrapper over __build_skb(), that specifically | ||
333 | * takes care of skb->head and skb->pfmemalloc | ||
334 | * This means that if @frag_size is not zero, then @data must be backed | ||
335 | * by a page fragment, not kmalloc() or vmalloc() | ||
336 | */ | ||
337 | struct sk_buff *build_skb(void *data, unsigned int frag_size) | ||
338 | { | ||
339 | struct sk_buff *skb = __build_skb(data, frag_size); | ||
340 | |||
341 | if (skb && frag_size) { | ||
342 | skb->head_frag = 1; | ||
343 | if (virt_to_head_page(data)->pfmemalloc) | ||
344 | skb->pfmemalloc = 1; | ||
345 | } | ||
346 | return skb; | ||
347 | } | ||
335 | EXPORT_SYMBOL(build_skb); | 348 | EXPORT_SYMBOL(build_skb); |
336 | 349 | ||
337 | struct netdev_alloc_cache { | 350 | struct netdev_alloc_cache { |
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index 19909d0786a2..ec4adbdcb9b4 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c | |||
@@ -1629,13 +1629,11 @@ static struct sk_buff *netlink_alloc_large_skb(unsigned int size, | |||
1629 | if (data == NULL) | 1629 | if (data == NULL) |
1630 | return NULL; | 1630 | return NULL; |
1631 | 1631 | ||
1632 | skb = build_skb(data, size); | 1632 | skb = __build_skb(data, size); |
1633 | if (skb == NULL) | 1633 | if (skb == NULL) |
1634 | vfree(data); | 1634 | vfree(data); |
1635 | else { | 1635 | else |
1636 | skb->head_frag = 0; | ||
1637 | skb->destructor = netlink_skb_destructor; | 1636 | skb->destructor = netlink_skb_destructor; |
1638 | } | ||
1639 | 1637 | ||
1640 | return skb; | 1638 | return skb; |
1641 | } | 1639 | } |