Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring/io-wq: don't trigger hung task for syzbot craziness

Use the same trick that blk_io_schedule() does to avoid triggering the
hung task warning (and potential reboot/panic, depending on system
settings), and only wait for half the hung task timeout at the time.
If we exceed the default IO_URING_EXIT_WAIT_MAX period where we expect
things to certainly have finished unless there's a bug, then throw a
WARN_ON_ONCE() for that case.

Reported-by: syzbot+4eb282331cab6d5b6588@syzkaller.appspotmail.com
Tested-by: syzbot+4eb282331cab6d5b6588@syzkaller.appspotmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

+21 -1
+21 -1
io_uring/io-wq.c
··· 17 17 #include <linux/task_work.h> 18 18 #include <linux/audit.h> 19 19 #include <linux/mmu_context.h> 20 + #include <linux/sched/sysctl.h> 20 21 #include <uapi/linux/io_uring.h> 21 22 22 23 #include "io-wq.h" ··· 1317 1316 1318 1317 static void io_wq_exit_workers(struct io_wq *wq) 1319 1318 { 1319 + unsigned long timeout, warn_timeout; 1320 + 1320 1321 if (!wq->task) 1321 1322 return; 1322 1323 ··· 1328 1325 io_wq_for_each_worker(wq, io_wq_worker_wake, NULL); 1329 1326 rcu_read_unlock(); 1330 1327 io_worker_ref_put(wq); 1331 - wait_for_completion(&wq->worker_done); 1328 + 1329 + /* 1330 + * Shut up hung task complaint, see for example 1331 + * 1332 + * https://lore.kernel.org/all/696fc9e7.a70a0220.111c58.0006.GAE@google.com/ 1333 + * 1334 + * where completely overloading the system with tons of long running 1335 + * io-wq items can easily trigger the hung task timeout. Only sleep 1336 + * uninterruptibly for half that time, and warn if we exceeded end 1337 + * up waiting more than IO_URING_EXIT_WAIT_MAX. 1338 + */ 1339 + timeout = sysctl_hung_task_timeout_secs * HZ / 2; 1340 + warn_timeout = jiffies + IO_URING_EXIT_WAIT_MAX; 1341 + do { 1342 + if (wait_for_completion_timeout(&wq->worker_done, timeout)) 1343 + break; 1344 + WARN_ON_ONCE(time_after(jiffies, warn_timeout)); 1345 + } while (1); 1332 1346 1333 1347 spin_lock_irq(&wq->hash->wait.lock); 1334 1348 list_del_init(&wq->wait.entry);