303-core-0001-net-readd-skb_recycle.patch 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. From 446a17652a69f749dd7a50b28e984c4904dc3aaf Mon Sep 17 00:00:00 2001
  2. From: Madalin Bucur <[email protected]>
  3. Date: Tue, 5 Jan 2016 12:12:07 +0200
  4. Subject: [PATCH] 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 <[email protected]>
  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. @@ -1025,6 +1025,7 @@ void skb_dump(const char *level, const s
  15. void skb_tx_error(struct sk_buff *skb);
  16. void consume_skb(struct sk_buff *skb);
  17. void __consume_stateless_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. @@ -945,6 +945,32 @@ void napi_consume_skb(struct sk_buff *sk
  24. }
  25. EXPORT_SYMBOL(napi_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) < \