7019-net-readd-skb_recycle.patch 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. From abc24ef7a69f54c3317beea98078831ba9bfa2cd Mon Sep 17 00:00:00 2001
  2. From: Madalin Bucur <madalin.bucur@freescale.com>
  3. Date: Tue, 5 Jan 2016 12:12:07 +0200
  4. Subject: [PATCH 19/70] net: readd skb_recycle()
  5. Adding back skb_recycle() as it's used by the DPAA Ethernet driver.
  6. This was removed from the upstream kernel because it was lacking users.
  7. Signed-off-by: Madalin Bucur <madalin.bucur@freescale.com>
  8. ---
  9. include/linux/skbuff.h | 1 +
  10. net/core/skbuff.c | 26 ++++++++++++++++++++++++++
  11. 2 files changed, 27 insertions(+)
  12. --- a/include/linux/skbuff.h
  13. +++ b/include/linux/skbuff.h
  14. @@ -804,6 +804,7 @@ void kfree_skb(struct sk_buff *skb);
  15. void kfree_skb_list(struct sk_buff *segs);
  16. void skb_tx_error(struct sk_buff *skb);
  17. void consume_skb(struct sk_buff *skb);
  18. +void skb_recycle(struct sk_buff *skb);
  19. void __kfree_skb(struct sk_buff *skb);
  20. extern struct kmem_cache *skbuff_head_cache;
  21. --- a/net/core/skbuff.c
  22. +++ b/net/core/skbuff.c
  23. @@ -770,6 +770,32 @@ void consume_skb(struct sk_buff *skb)
  24. }
  25. EXPORT_SYMBOL(consume_skb);
  26. +/**
  27. + * skb_recycle - clean up an skb for reuse
  28. + * @skb: buffer
  29. + *
  30. + * Recycles the skb to be reused as a receive buffer. This
  31. + * function does any necessary reference count dropping, and
  32. + * cleans up the skbuff as if it just came from __alloc_skb().
  33. + */
  34. +void skb_recycle(struct sk_buff *skb)
  35. +{
  36. + struct skb_shared_info *shinfo;
  37. + u8 head_frag = skb->head_frag;
  38. +
  39. + skb_release_head_state(skb);
  40. +
  41. + shinfo = skb_shinfo(skb);
  42. + memset(shinfo, 0, offsetof(struct skb_shared_info, dataref));
  43. + atomic_set(&shinfo->dataref, 1);
  44. +
  45. + memset(skb, 0, offsetof(struct sk_buff, tail));
  46. + skb->data = skb->head + NET_SKB_PAD;
  47. + skb->head_frag = head_frag;
  48. + skb_reset_tail_pointer(skb);
  49. +}
  50. +EXPORT_SYMBOL(skb_recycle);
  51. +
  52. /* Make sure a field is enclosed inside headers_start/headers_end section */
  53. #define CHECK_SKB_FIELD(field) \
  54. BUILD_BUG_ON(offsetof(struct sk_buff, field) < \