[net-next,1/9] net: skb: introduce try_kfree_skb()

Message ID 20221029130957.1292060-2-imagedong@tencent.com
State New
Headers
Series net: tcp: add skb drop reasons to tcp state process |

Commit Message

Menglong Dong Oct. 29, 2022, 1:09 p.m. UTC
  From: Menglong Dong <imagedong@tencent.com>

In order to simply the code, introduce try_kfree_skb(), which allow
SKB_NOT_DROPPED_YET to be passed. When the reason is SKB_NOT_DROPPED_YET,
consume_skb() will be called to free the skb normally. Otherwise,
kfree_skb_reason() will be called.

Signed-off-by: Menglong Dong <imagedong@tencent.com>
---
 include/linux/skbuff.h | 9 +++++++++
 1 file changed, 9 insertions(+)
  

Comments

Eric Dumazet Oct. 29, 2022, 3:30 p.m. UTC | #1
On Sat, Oct 29, 2022 at 6:11 AM <menglong8.dong@gmail.com> wrote:
>
> From: Menglong Dong <imagedong@tencent.com>
>
> In order to simply the code, introduce try_kfree_skb(), which allow
> SKB_NOT_DROPPED_YET to be passed. When the reason is SKB_NOT_DROPPED_YET,
> consume_skb() will be called to free the skb normally. Otherwise,
> kfree_skb_reason() will be called.
>
> Signed-off-by: Menglong Dong <imagedong@tencent.com>
> ---
>  include/linux/skbuff.h | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index 59c9fd55699d..f722accc054e 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -1236,6 +1236,15 @@ static inline void consume_skb(struct sk_buff *skb)
>  }
>  #endif
>
> +static inline void try_kfree_skb(struct sk_buff *skb,
> +                                enum skb_drop_reason reason)
> +{
> +       if (reason != SKB_NOT_DROPPED_YET)
> +               kfree_skb_reason(skb, reason);
> +       else
> +               consume_skb(skb);
> +}
> +

My proposal looks better IMO

https://patchwork.kernel.org/project/netdevbpf/patch/20221028133043.2312984-2-edumazet@google.com/
  
Menglong Dong Oct. 31, 2022, 2:35 a.m. UTC | #2
On Sat, Oct 29, 2022 at 11:30 PM Eric Dumazet <edumazet@google.com> wrote:
>
> On Sat, Oct 29, 2022 at 6:11 AM <menglong8.dong@gmail.com> wrote:
> >
> > From: Menglong Dong <imagedong@tencent.com>
> >
> > In order to simply the code, introduce try_kfree_skb(), which allow
> > SKB_NOT_DROPPED_YET to be passed. When the reason is SKB_NOT_DROPPED_YET,
> > consume_skb() will be called to free the skb normally. Otherwise,
> > kfree_skb_reason() will be called.
> >
> > Signed-off-by: Menglong Dong <imagedong@tencent.com>
> > ---
> >  include/linux/skbuff.h | 9 +++++++++
> >  1 file changed, 9 insertions(+)
> >
> > diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> > index 59c9fd55699d..f722accc054e 100644
> > --- a/include/linux/skbuff.h
> > +++ b/include/linux/skbuff.h
> > @@ -1236,6 +1236,15 @@ static inline void consume_skb(struct sk_buff *skb)
> >  }
> >  #endif
> >
> > +static inline void try_kfree_skb(struct sk_buff *skb,
> > +                                enum skb_drop_reason reason)
> > +{
> > +       if (reason != SKB_NOT_DROPPED_YET)
> > +               kfree_skb_reason(skb, reason);
> > +       else
> > +               consume_skb(skb);
> > +}
> > +
>
> My proposal looks better IMO
>
> https://patchwork.kernel.org/project/netdevbpf/patch/20221028133043.2312984-2-edumazet@google.com/

Hnn...yeah, your idea seems fine, which wont
affect the existing code.
  

Patch

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 59c9fd55699d..f722accc054e 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -1236,6 +1236,15 @@  static inline void consume_skb(struct sk_buff *skb)
 }
 #endif
 
+static inline void try_kfree_skb(struct sk_buff *skb,
+				 enum skb_drop_reason reason)
+{
+	if (reason != SKB_NOT_DROPPED_YET)
+		kfree_skb_reason(skb, reason);
+	else
+		consume_skb(skb);
+}
+
 void __consume_stateless_skb(struct sk_buff *skb);
 void  __kfree_skb(struct sk_buff *skb);
 extern struct kmem_cache *skbuff_head_cache;