Re: [PATCH net] tap: do not take consumer_lock in tap_sock_destruct()

From: Shuai Liu

Date: Thu Nov 26 2026 - 05:16:45 EST


Hi Jiayi,

Thanks for your detailed analysis — your fix is definitely the right
approach, and you caught a flaw in my reasoning that I missed entirely.

My patch only changed tap_sock_destruct() to acquire consumer_lock with
spin_lock_irqsave(), assuming that making the destructor take the lock
with uniform BH semantics would be enough. But I completely failed to
consider the other holders of consumer_lock: tap_do_read(), tap_poll(),
tap_peek_len() and vhost_net_buf_produce() all take it with plain
spin_lock(), and tap_queue_resize() with spin_lock_bh(). So lockdep
would still flag the inconsistency between {IN-SOFTIRQ-W} and
{SOFTIRQ-ON-W} for the same lock class — exactly as you demonstrated.

Your argument that the destructor does not need the lock at all is
solid: tap_put_queue() runs synchronize_rcu() and RCU_INIT_POINTER(q->tap,
NULL) before the final sock_put(), so tap_handle_frame() can no longer
reach the queue via RCU dereference. The dellink paths unregister the rx
handler before tap_del_queues(). No other path can race with the
destructor.

Applied your patch locally, builds cleanly and passes checkpatch strict
with 0 errors / 0 warnings.

Please ignore my earlier patch — it's wrong and should not be applied.

Reviewed-by: Shuai Liu <847807867@xxxxxx>
Tested-by: Shuai Liu <847807867@xxxxxx>

Shuai