From: netdev-bot+sashiko@kernel.org
To: 847807867@qq.com
Cc: willemdebruijn.kernel@gmail.com, jasowangio@gmail.com,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com,
syzbot+a2220efe757ca2a7358d@syzkaller.appspotmail.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: tap: fix inconsistent lock state in tap_sock_destruct
Date: Fri, 27 Nov 2026 01:00:17 +0000 [thread overview]
Message-ID: <179574121714.3135.6932520604039855103@kernel.org> (raw)
In-Reply-To: <tencent_934E899D4D24BB3B4827B2A0C9D73461E00A@qq.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The patch does not remove the lockdep report it says it fixes.
- [Medium] The commit message's technical explanation has factual errors.
- [Low] The patch fixes a syzbot-reported lockdep problem in
tap_sock_destruct() but has no Fixes: tag.
--
net: tap: fix inconsistent lock state in tap_sock_destruct
This patch replaces the ptr_ring_cleanup() call in tap_sock_destruct()
with an open-coded loop. The loop takes the ring's consumer_lock with
spin_lock_irqsave() and then calls kvfree() on the ring queue. The aim is
to silence a syzbot lockdep report of inconsistent {IN-SOFTIRQ-W} ->
{SOFTIRQ-ON-W} usage of consumer_lock.
Link: https://syzkaller.appspot.com/bug?extid=a2220efe757ca2a7358d
> 1. softirq context: from softirq rx drop paths via
> skb_release_head_state() -> sock_wfree() -> __sk_free() ->
> sk_destruct() -> tap_sock_destruct(). In softirq the BH
> state is already disabled, so consumer_lock is taken with
> SOFTIRQ-ON-W semantics.
[ ... ]
> Fix by hand-rolling the cleanup loop with spin_lock_irqsave() /
> spin_unlock_irqrestore() so consumer_lock is always taken from a
> uniform softirq state. irqsave is a no-op on the softirq path
> (interrupts are already off), so there is no extra cost there.
[Severity: Medium]
Are the lockdep states the wrong way round here? When the lock is taken
from softirq context, lockdep records IN-SOFTIRQ-W. SOFTIRQ-ON-W is the
process context case, where softirqs are enabled.
Are interrupts actually off on the softirq path? Softirq handlers and
RCU callbacks run with hardirqs enabled. So spin_lock_irqsave() really
does disable interrupts there, and it is not a no-op.
No hardirq context takes consumer_lock, so why mask hardirqs at all? The
_bh helpers such as ptr_ring_consume_bh() seem to fit a softirq versus
process context conflict.
tap_sock_destruct() only runs after the last socket reference is gone.
At that point no other context can hold the same ring's consumer_lock.
That makes this a lock class report, not a real deadlock on a single
ring. Could the commit message say that?
Also, the new loop in tap_sock_destruct() is the same as the existing
helper in include/linux/ptr_ring.h:
static inline void *ptr_ring_consume_any(struct ptr_ring *r)
{
...
spin_lock_irqsave(&r->consumer_lock, flags);
ptr = __ptr_ring_consume(r);
spin_unlock_irqrestore(&r->consumer_lock, flags);
...
}
The loop plus the kvfree(q->ring.queue) copies the internals of
ptr_ring_cleanup() into the driver. Would tap then miss future changes
to that helper?
> Reported-by: syzbot <syzbot+a2220efe757ca2a7358d@syzkaller.appspotmail.com>
> Link: https://syzkaller.appspot.com/bug?extid=a2220efe757ca2a7358d
> Signed-off-by: Shuai Liu <847807867@qq.com>
[Severity: Low]
This isn't a bug, but should there be a Fixes: tag? The replaced
ptr_ring_cleanup() call in tap_sock_destruct() came from commit
5990a30510ed ("tun/tap: use ptr_ring instead of skb_array"). That commit
kept the ring cleanup in the destructor that commit 362899b8725b
("macvtap: switch to use skb array") added.
> diff --git a/drivers/net/tap.c b/drivers/net/tap.c
> index 2f19fb07bb2d4..d749c7e73858a 100644
> --- a/drivers/net/tap.c
> +++ b/drivers/net/tap.c
> @@ -440,8 +440,18 @@ static void tap_sock_write_space(struct sock *sk)
> static void tap_sock_destruct(struct sock *sk)
> {
> struct tap_queue *q = container_of(sk, struct tap_queue, sk);
> -
> - ptr_ring_cleanup(&q->ring, __skb_array_destroy_skb);
> + unsigned long flags;
> + void *ptr;
> +
> + while (true) {
> + spin_lock_irqsave(&q->ring.consumer_lock, flags);
> + ptr = __ptr_ring_consume(&q->ring);
> + spin_unlock_irqrestore(&q->ring.consumer_lock, flags);
[Severity: High]
Does this change actually stop the lockdep report? Lockdep tracks lock
classes, not individual locks. Every tap queue's consumer_lock shares
one class, set by the spin_lock_init() in ptr_ring_init(), which
tap_open() calls.
tap_sock_destruct() can still run in softirq. One example is an skb
allocated by sock_alloc_send_pskb() in tap_get_user(), sent with
dev_queue_xmit() and then freed in softirq:
kfree_skb()
sock_wfree()
__sk_free()
sk_destruct()
tap_sock_destruct()
Lockdep marks the class IN-SOFTIRQ-W whenever it is taken in softirq
context, even when spin_lock_irqsave() is used.
Several other users of the same class still take it with a plain
spin_lock() in process context, with softirqs enabled:
drivers/net/tap.c:tap_do_read()
skb = ptr_ring_consume(&q->ring);
drivers/net/tap.c:tap_poll()
if (!ptr_ring_empty(&q->ring))
drivers/net/tap.c:tap_peek_len()
return PTR_RING_PEEK_CALL(&q->ring, __skb_array_len_with_tag);
drivers/vhost/net.c:vhost_net_buf_produce()
spin_lock(&nvq->rx_ring->consumer_lock);
The vhost case works on the ring returned by tap_get_ptr_ring().
Won't any normal tap reader, poller or vhost-net backend still record
SOFTIRQ-ON-W? Then the same {IN-SOFTIRQ-W} -> {SOFTIRQ-ON-W} splat can
fire again. The patch seems to stop only the destructor's own process
context call from counting as SOFTIRQ-ON.
Because this is a class-level report, should the fix cover the whole
class rather than one call site? Some options:
- Make every consumer_lock user in tap and vhost BH-safe, as resize
already does with ptr_ring_resize_multiple_bh().
- Drain the ring in the destructor without taking the lock, since
nothing else can use the ring at that point.
- Give the destructor's acquisition a separate lockdep annotation.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/tencent_934E899D4D24BB3B4827B2A0C9D73461E00A%40qq.com
prev parent reply other threads:[~2026-11-27 1:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 0:34 [PATCH] net: tap: fix inconsistent lock state in tap_sock_destruct Shuai Liu
2026-11-26 17:34 ` willemb
2026-11-27 1:00 ` netdev-bot+sashiko [this message]
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=179574121714.3135.6932520604039855103@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=847807867@qq.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=jasowangio@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=syzbot+a2220efe757ca2a7358d@syzkaller.appspotmail.com \
--cc=willemdebruijn.kernel@gmail.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