Advertisement
teknoraver

napi_kfree_skb

Apr 5th, 2021
1,439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.05 KB | None | 0 0
  1. diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
  2. index fffa6b399995..aa1685f72397 100644
  3. --- a/include/linux/skbuff.h
  4. +++ b/include/linux/skbuff.h
  5. @@ -2932,6 +2932,7 @@ static inline struct sk_buff *napi_alloc_skb(struct napi_struct *napi,
  6.     return __napi_alloc_skb(napi, length, GFP_ATOMIC);
  7.  }
  8.  void napi_consume_skb(struct sk_buff *skb, int budget);
  9. +void napi_kfree_skb(struct sk_buff *skb, int budget);
  10.  
  11.  void napi_skb_free_stolen_head(struct sk_buff *skb);
  12.  void __kfree_skb_defer(struct sk_buff *skb);
  13. diff --git a/net/core/skbuff.c b/net/core/skbuff.c
  14. index 7f5c02085438..294bf2068ab6 100644
  15. --- a/net/core/skbuff.c
  16. +++ b/net/core/skbuff.c
  17. @@ -951,11 +951,14 @@ void napi_skb_free_stolen_head(struct sk_buff *skb)
  18.     napi_skb_cache_put(skb);
  19.  }
  20.  
  21. -void napi_consume_skb(struct sk_buff *skb, int budget)
  22. +static void napi_release_skb(struct sk_buff *skb, int budget, bool consume)
  23.  {
  24.     /* Zero budget indicate non-NAPI context called us, like netpoll */
  25.     if (unlikely(!budget)) {
  26. -       dev_consume_skb_any(skb);
  27. +       if (consume)
  28. +           dev_consume_skb_any(skb);
  29. +       else
  30. +           dev_kfree_skb_any(skb);
  31.         return;
  32.     }
  33.  
  34. @@ -965,7 +968,10 @@ void napi_consume_skb(struct sk_buff *skb, int budget)
  35.         return;
  36.  
  37.     /* if reaching here SKB is ready to free */
  38. -   trace_consume_skb(skb);
  39. +   if (consume)
  40. +       trace_consume_skb(skb);
  41. +   else
  42. +       trace_kfree_skb(skb);
  43.  
  44.     /* if SKB is a clone, don't handle this case */
  45.     if (skb->fclone != SKB_FCLONE_UNAVAILABLE) {
  46. @@ -976,8 +982,20 @@ void napi_consume_skb(struct sk_buff *skb, int budget)
  47.     skb_release_all(skb);
  48.     napi_skb_cache_put(skb);
  49.  }
  50. +
  51. +
  52. +void napi_consume_skb(struct sk_buff *skb, int budget)
  53. +{
  54. +   napi_release_skb(skb, budget, true);
  55. +}
  56.  EXPORT_SYMBOL(napi_consume_skb);
  57.  
  58. +void napi_kfree_skb(struct sk_buff *skb, int budget)
  59. +{
  60. +   napi_release_skb(skb, budget, false);
  61. +}
  62. +EXPORT_SYMBOL(napi_kfree_skb);
  63. +
  64.  /* Make sure a field is enclosed inside headers_start/headers_end section */
  65.  #define CHECK_SKB_FIELD(field) \
  66.     BUILD_BUG_ON(offsetof(struct sk_buff, field) <      \
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement