From: Benjamin Segall Date: Fri, 14 Feb 2025 22:12:20 +0000 (-0800) Subject: posix-timers: Invoke cond_resched() during exit_itimers() X-Git-Tag: v6.15-rc1~204^2~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f99c5bb396b8d1424ed229d1ffa6f596e3b9c36b;p=thirdparty%2Fkernel%2Flinux.git posix-timers: Invoke cond_resched() during exit_itimers() exit_itimers() loops through every timer in the process to delete it. This requires taking the system-wide hash_lock for each of these timers, and contends with other processes trying to create or delete timers. When a process creates hundreds of thousands of timers, and then exits while other processes contend with it, this can trigger softlockups on CONFIG_PREEMPT=n. Add a cond_resched() invocation into the loop to allow the system to make progress. Signed-off-by: Ben Segall Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/all/xm2634gg2n23.fsf@google.com --- diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c index 1b675aee99a98..44ba7db07e900 100644 --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -1099,8 +1099,10 @@ void exit_itimers(struct task_struct *tsk) spin_unlock_irq(&tsk->sighand->siglock); /* The timers are not longer accessible via tsk::signal */ - while (!hlist_empty(&timers)) + while (!hlist_empty(&timers)) { itimer_delete(hlist_entry(timers.first, struct k_itimer, list)); + cond_resched(); + } /* * There should be no timers on the ignored list. itimer_delete() has