From: Saeed Mahameed <saeed@kernel.org>
To: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
edumazet@google.com, pabeni@redhat.com
Subject: Re: [PATCH net-next 1/2] net: fix call location in kfree_skb_list_reason
Date: Fri, 6 Jan 2023 11:54:00 -0800 [thread overview]
Message-ID: <Y7h8WPoi6hS/2Hs2@x130> (raw)
In-Reply-To: <167293336279.249536.18331792118487373874.stgit@firesoul>
On 05 Jan 16:42, Jesper Dangaard Brouer wrote:
>The SKB drop reason uses __builtin_return_address(0) to give the call
>"location" to trace_kfree_skb() tracepoint skb:kfree_skb.
>
>To keep this stable for compilers kfree_skb_reason() is annotated with
>__fix_address (noinline __noclone) as fixed in commit c205cc7534a9
>("net: skb: prevent the split of kfree_skb_reason() by gcc").
>
>The function kfree_skb_list_reason() invoke kfree_skb_reason(), which
>cause the __builtin_return_address(0) "location" to report the
>unexpected address of kfree_skb_list_reason.
>
>Example output from 'perf script':
> kpktgend_0 1337 [000] 81.002597: skb:kfree_skb: skbaddr=0xffff888144824700 protocol=2048 location=kfree_skb_list_reason+0x1e reason: QDISC_DROP
>
>Patch creates an __always_inline __kfree_skb_reason() helper call that
>is called from both kfree_skb_list() and kfree_skb_list_reason().
>Suggestions for solutions that shares code better are welcome.
>
>As preparation for next patch move __kfree_skb() invocation out of
>this helper function.
>
>Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
>---
> net/core/skbuff.c | 34 +++++++++++++++++++++-------------
> 1 file changed, 21 insertions(+), 13 deletions(-)
>
>diff --git a/net/core/skbuff.c b/net/core/skbuff.c
>index 4a0eb5593275..007a5fbe284b 100644
>--- a/net/core/skbuff.c
>+++ b/net/core/skbuff.c
>@@ -932,6 +932,21 @@ void __kfree_skb(struct sk_buff *skb)
> }
> EXPORT_SYMBOL(__kfree_skb);
>
>+static __always_inline
>+bool __kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason)
>+{
>+ if (unlikely(!skb_unref(skb)))
>+ return false;
>+
>+ DEBUG_NET_WARN_ON_ONCE(reason <= 0 || reason >= SKB_DROP_REASON_MAX);
>+
>+ if (reason == SKB_CONSUMED)
>+ trace_consume_skb(skb);
>+ else
>+ trace_kfree_skb(skb, __builtin_return_address(0), reason);
>+ return true;
why not just call __kfree_skb(skb); here instead of the boolean return ?
if it because __kfree_skb() makes a call to
skb_release_all()->..->kfree_skb_list_reason()
then it's already too deep and the return address in that case isn't
predictable, so you're not avoiding any breakage by keeping
direct calls to __kfree_skb() from kfree_skb_reason and+kfree_skb_list_reason
>+}
>+
> /**
> * kfree_skb_reason - free an sk_buff with special reason
> * @skb: buffer to free
>@@ -944,26 +959,19 @@ EXPORT_SYMBOL(__kfree_skb);
> void __fix_address
> kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason)
> {
>- if (unlikely(!skb_unref(skb)))
>- return;
>-
>- DEBUG_NET_WARN_ON_ONCE(reason <= 0 || reason >= SKB_DROP_REASON_MAX);
>-
>- if (reason == SKB_CONSUMED)
>- trace_consume_skb(skb);
>- else
>- trace_kfree_skb(skb, __builtin_return_address(0), reason);
>- __kfree_skb(skb);
>+ if (__kfree_skb_reason(skb, reason))
>+ __kfree_skb(skb);
> }
> EXPORT_SYMBOL(kfree_skb_reason);
>
>-void kfree_skb_list_reason(struct sk_buff *segs,
>- enum skb_drop_reason reason)
>+void __fix_address
>+kfree_skb_list_reason(struct sk_buff *segs, enum skb_drop_reason reason)
> {
> while (segs) {
> struct sk_buff *next = segs->next;
>
>- kfree_skb_reason(segs, reason);
>+ if (__kfree_skb_reason(segs, reason))
>+ __kfree_skb(segs);
> segs = next;
> }
> }
>
>
next prev parent reply other threads:[~2023-01-06 19:55 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-05 15:42 [PATCH net-next 0/2] net: use kmem_cache_free_bulk in kfree_skb_list Jesper Dangaard Brouer
2023-01-05 15:42 ` [PATCH net-next 1/2] net: fix call location in kfree_skb_list_reason Jesper Dangaard Brouer
2023-01-06 19:54 ` Saeed Mahameed [this message]
2023-01-06 19:57 ` Saeed Mahameed
2023-01-05 15:42 ` [PATCH net-next 2/2] net: kfree_skb_list use kmem_cache_free_bulk Jesper Dangaard Brouer
2023-01-06 20:09 ` Saeed Mahameed
2023-01-06 22:33 ` Jakub Kicinski
2023-01-09 12:24 ` Jesper Dangaard Brouer
2023-01-09 19:34 ` Jakub Kicinski
2023-01-09 22:10 ` Alexander H Duyck
2023-01-10 14:52 ` Jesper Dangaard Brouer
2023-01-10 20:20 ` Jakub Kicinski
2023-01-13 13:42 ` Jesper Dangaard Brouer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y7h8WPoi6hS/2Hs2@x130 \
--to=saeed@kernel.org \
--cc=brouer@redhat.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox