From: Qi Tang <tpluszz77@gmail.com>
To: steffen.klassert@secunet.com
Cc: davem@davemloft.net, edumazet@google.com,
herbert@gondor.apana.org.au, horms@kernel.org, kuba@kernel.org,
netdev@vger.kernel.org, pabeni@redhat.com
Subject: Re: [PATCH net] xfrm: hold skb->dev across async IPv6 transport reinject
Date: Thu, 26 Mar 2026 20:41:31 +0800 [thread overview]
Message-ID: <20260326124131.193796-1-tpluszz77@gmail.com> (raw)
In-Reply-To: <abz65sB_1I9ImMx6@secunet.com>
I reworked the fix direction to avoid taking another netdev reference.
The current idea is to reuse the existing dev_hold() in xfrm_input(),
carry that reference across the async transport reinject path, and drop
it only once the skb is either consumed earlier or the async reinject
callback has completed.
Very roughly, the change would look like this:
- in xfrm_input(), do not drop the existing dev reference immediately
on async resume
- add a dedicated queueing path for skbs that already carry that
input-side reference
- in transport_finish(), switch from NF_HOOK() to nf_hook() so the
ret != 1 path can drop the carried reference when the skb is consumed
before okfn runs
- in xfrm_trans_reinject(), drop the transferred reference after the
callback completes
Something along these lines:
diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c
@@
if (encap_type == -1) {
async = 1;
- dev_put(skb->dev);
seq = XFRM_SKB_CB(skb)->seq.input.low;
...
}
@@
+int xfrm_trans_queue_in(struct net *net, struct sk_buff *skb, ...)
+{
+ ...
+ XFRM_TRANS_SKB_CB(skb)->dev_ref_held = true;
+ ...
+}
diff --git a/net/ipv6/xfrm6_input.c b/net/ipv6/xfrm6_input.c
@@
- NF_HOOK(..., xfrm6_transport_finish2);
+ ret = nf_hook(..., async ? xfrm6_transport_finish2_async :
+ xfrm6_transport_finish2);
+ if (ret != 1) {
+ if (async)
+ dev_put(dev);
+ return 0;
+ }
+ (async ? xfrm6_transport_finish2_async :
+ xfrm6_transport_finish2)(net, NULL, skb);
diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c
@@
while ((skb = __skb_dequeue(&queue))) {
+ bool dev_ref_held = cb->dev_ref_held;
+ struct net_device *dev = dev_ref_held ? skb->dev : NULL;
cb->finish(cb->net, NULL, skb);
+ if (dev_ref_held)
+ dev_put(dev);
}
Does this sound like a reasonable direction for a v2?
next prev parent reply other threads:[~2026-03-26 12:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-20 7:30 [PATCH net] xfrm: hold skb->dev across async IPv6 transport reinject Qi Tang
2026-03-20 7:44 ` Steffen Klassert
2026-03-26 12:41 ` Qi Tang [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-03-20 8:32 steffen-ai
2026-03-20 8:37 ` Steffen Klassert
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=20260326124131.193796-1-tpluszz77@gmail.com \
--to=tpluszz77@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=steffen.klassert@secunet.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