]> exis.tech > repos - linux.git/commit
tipc: avoid busy looping in tipc_exit_net()
authorEric Dumazet <edumazet@google.com>
Tue, 23 Jun 2026 17:30:30 +0000 (17:30 +0000)
committerJakub Kicinski <kuba@kernel.org>
Thu, 25 Jun 2026 15:53:00 +0000 (08:53 -0700)
commitc1481c94e74c955e0448ddf46b8615a44d840c1e
tree1c9330007771e51609e6080f025dc8379e3c1c23
parent7116764ca53ff529335d7ab7c364a69f094b23a5
tipc: avoid busy looping in tipc_exit_net()

Blamed commit introduced a busy-wait loop in tipc_exit_net()
to wait for pending UDP bearer cleanup works to complete:

       while (atomic_read(&tn->wq_count))
               cond_resched();

This loop can busy-wait for a long time if cond_resched() is a NOP. This
typically happens if the netns exit is executed by a high priority task,
or under kernels configured without preemption (CONFIG_PREEMPT_NONE). In
such cases, it wastes CPU cycles and can lead to soft lockups.

Fix this by replacing the busy loop with wait_var_event(), allowing the
thread to sleep properly until the work queue count reaches zero.

Accordingly, update cleanup_bearer() to use atomic_dec_and_test() and
wake_up_var() to wake up the waiter when the count drops to zero.

This uses the global wait queue hash table, avoiding the need to bloat
struct tipc_net with a wait_queue_head_t. The atomic_dec_and_test()
provides the necessary memory barrier to ensure the wakeup is not missed.

Fixes: 04c26faa51d1 ("tipc: wait and exit until all work queues are done")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Jon Maloy <jmaloy@redhat.com>
Cc: tipc-discussion@lists.sourceforge.net
Reviewed-by: Xin Long <lucien.xin@gmail.com>
Link: https://patch.msgid.link/20260623173030.2925059-3-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/tipc/core.c
net/tipc/udp_media.c