netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] sk_buff: drop all skb extensions on free and skb scrubbing
@ 2019-09-26 14:18 Florian Westphal
  2019-09-26 17:24 ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Westphal @ 2019-09-26 14:18 UTC (permalink / raw)
  To: netdev; +Cc: steffen.klassert, paulb, vladbu, Florian Westphal

Now that we have a 3rd extension, add a new helper that drops the
extension space and use it when we need to scrub an sk_buff.

At this time, scrubbing clears secpath and bridge netfilter data, but
retains the tc skb extension, after this patch all three get cleared.

NAPI reuse/free assumes we can only have a secpath attached to skb, but
it seems better to clear all extensions there as well.

Fixes: 95a7233c452a ("net: openvswitch: Set OvS recirc_id from tc chain index")
Signed-off-by: Florian Westphal <fw@strlen.de>
---
 include/linux/skbuff.h | 9 +++++++++
 net/core/dev.c         | 4 ++--
 net/core/skbuff.c      | 2 +-
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 907209c0794e..4debdd58a0ce 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -4144,8 +4144,17 @@ static inline void *skb_ext_find(const struct sk_buff *skb, enum skb_ext_id id)
 
 	return NULL;
 }
+
+static inline void skb_ext_reset(struct sk_buff *skb)
+{
+	if (skb->active_extensions) {
+		__skb_ext_put(skb->extensions);
+		skb->active_extensions = 0;
+	}
+}
 #else
 static inline void skb_ext_put(struct sk_buff *skb) {}
+static inline void skb_ext_reset(struct sk_buff *skb) {}
 static inline void skb_ext_del(struct sk_buff *skb, int unused) {}
 static inline void __skb_ext_copy(struct sk_buff *d, const struct sk_buff *s) {}
 static inline void skb_ext_copy(struct sk_buff *dst, const struct sk_buff *s) {}
diff --git a/net/core/dev.c b/net/core/dev.c
index 71b18e80389f..bf3ed413abaf 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5666,7 +5666,7 @@ EXPORT_SYMBOL(gro_find_complete_by_type);
 static void napi_skb_free_stolen_head(struct sk_buff *skb)
 {
 	skb_dst_drop(skb);
-	secpath_reset(skb);
+	skb_ext_put(skb);
 	kmem_cache_free(skbuff_head_cache, skb);
 }
 
@@ -5733,7 +5733,7 @@ static void napi_reuse_skb(struct napi_struct *napi, struct sk_buff *skb)
 	skb->encapsulation = 0;
 	skb_shinfo(skb)->gso_type = 0;
 	skb->truesize = SKB_TRUESIZE(skb_end_offset(skb));
-	secpath_reset(skb);
+	skb_ext_reset(skb);
 
 	napi->skb = skb;
 }
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index f12e8a050edb..01d65206f4fb 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -5119,7 +5119,7 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet)
 	skb->skb_iif = 0;
 	skb->ignore_df = 0;
 	skb_dst_drop(skb);
-	secpath_reset(skb);
+	skb_ext_reset(skb);
 	nf_reset(skb);
 	nf_reset_trace(skb);
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net] sk_buff: drop all skb extensions on free and skb scrubbing
  2019-09-26 14:18 [PATCH net] sk_buff: drop all skb extensions on free and skb scrubbing Florian Westphal
@ 2019-09-26 17:24 ` Eric Dumazet
  2019-09-26 18:06   ` Florian Westphal
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2019-09-26 17:24 UTC (permalink / raw)
  To: Florian Westphal, netdev; +Cc: steffen.klassert, paulb, vladbu



On 9/26/19 7:18 AM, Florian Westphal wrote:
> Now that we have a 3rd extension, add a new helper that drops the
> extension space and use it when we need to scrub an sk_buff.
> 
> At this time, scrubbing clears secpath and bridge netfilter data, but
> retains the tc skb extension, after this patch all three get cleared.
> 
> NAPI reuse/free assumes we can only have a secpath attached to skb, but
> it seems better to clear all extensions there as well.
> 
> Fixes: 95a7233c452a ("net: openvswitch: Set OvS recirc_id from tc chain index")
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
>  include/linux/skbuff.h | 9 +++++++++
>  net/core/dev.c         | 4 ++--
>  net/core/skbuff.c      | 2 +-
>  3 files changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index 907209c0794e..4debdd58a0ce 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -4144,8 +4144,17 @@ static inline void *skb_ext_find(const struct sk_buff *skb, enum skb_ext_id id)
>  
>  	return NULL;
>  }
> +
> +static inline void skb_ext_reset(struct sk_buff *skb)
> +{
> +	if (skb->active_extensions) {

This deserves an unlikely(skb->active_extensions) hint here ?

> +		__skb_ext_put(skb->extensions);
> +		skb->active_extensions = 0;
> +	}
> +}
>  #else
>  static inline void skb_ext_put(struct sk_buff *skb) {}
> +static inline void skb_ext_reset(struct sk_buff *skb) {}
>  static inline void skb_ext_del(struct sk_buff *skb, int unused) {}
>  static inline void __skb_ext_copy(struct sk_buff *d, const struct sk_buff *s) {}
>  static inline void skb_ext_copy(struct sk_buff *dst, const struct sk_buff *s) {}
> diff --git a/net/core/dev.c b/net/core/dev.c
> index 71b18e80389f..bf3ed413abaf 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -5666,7 +5666,7 @@ EXPORT_SYMBOL(gro_find_complete_by_type);
>  static void napi_skb_free_stolen_head(struct sk_buff *skb)
>  {
>  	skb_dst_drop(skb);
> -	secpath_reset(skb);
> +	skb_ext_put(skb);
>  	kmem_cache_free(skbuff_head_cache, skb);
>  }
>  
> @@ -5733,7 +5733,7 @@ static void napi_reuse_skb(struct napi_struct *napi, struct sk_buff *skb)
>  	skb->encapsulation = 0;
>  	skb_shinfo(skb)->gso_type = 0;
>  	skb->truesize = SKB_TRUESIZE(skb_end_offset(skb));
> -	secpath_reset(skb);
> +	skb_ext_reset(skb);
>  
>  	napi->skb = skb;
>  }
> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index f12e8a050edb..01d65206f4fb 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
> @@ -5119,7 +5119,7 @@ void skb_scrub_packet(struct sk_buff *skb, bool xnet)
>  	skb->skb_iif = 0;
>  	skb->ignore_df = 0;
>  	skb_dst_drop(skb);
> -	secpath_reset(skb);
> +	skb_ext_reset(skb);
>  	nf_reset(skb);
>  	nf_reset_trace(skb);
>  
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] sk_buff: drop all skb extensions on free and skb scrubbing
  2019-09-26 17:24 ` Eric Dumazet
@ 2019-09-26 18:06   ` Florian Westphal
  2019-09-26 18:15     ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Westphal @ 2019-09-26 18:06 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: Florian Westphal, netdev, steffen.klassert, paulb, vladbu

Eric Dumazet <eric.dumazet@gmail.com> wrote:
> > +static inline void skb_ext_reset(struct sk_buff *skb)
> > +{
> > +	if (skb->active_extensions) {
> 
> This deserves an unlikely(skb->active_extensions) hint here ?

unlikely() isn't used in the other helpers (e.g. skb_ext_{put,del,copy}
either, should I add it there too?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] sk_buff: drop all skb extensions on free and skb scrubbing
  2019-09-26 18:06   ` Florian Westphal
@ 2019-09-26 18:15     ` Eric Dumazet
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2019-09-26 18:15 UTC (permalink / raw)
  To: Florian Westphal, Eric Dumazet; +Cc: netdev, steffen.klassert, paulb, vladbu



On 9/26/19 11:06 AM, Florian Westphal wrote:
> Eric Dumazet <eric.dumazet@gmail.com> wrote:
>>> +static inline void skb_ext_reset(struct sk_buff *skb)
>>> +{
>>> +	if (skb->active_extensions) {
>>
>> This deserves an unlikely(skb->active_extensions) hint here ?
> 
> unlikely() isn't used in the other helpers (e.g. skb_ext_{put,del,copy}
> either, should I add it there too?
> 

At least in GRO paths unlikely() makes sense.

For other paths it might not be the case.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-09-26 18:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-26 14:18 [PATCH net] sk_buff: drop all skb extensions on free and skb scrubbing Florian Westphal
2019-09-26 17:24 ` Eric Dumazet
2019-09-26 18:06   ` Florian Westphal
2019-09-26 18:15     ` Eric Dumazet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).