The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git after rh8-4.18.0-240.1.1.vz8.5.27 ------> commit 2d6adea14caacb91cc588fa1ab44fe391d5cd98c Author: Kirill Tkhai <ktk...@virtuozzo.com> Date: Tue May 11 19:19:06 2021 +0300
tty: Use RCU read lock to iterate tasks and threads in __do_SAK() There were made several efforts to make __do_SAK() working in process context long ago, but it does not solves the problem completely. Since __do_SAK() may take tasklist_lock for a long time, the concurent processes, waiting for write lock with interrupts disabled (e.g., forking), get into the same situation like __do_SAK() would have been executed in interrupt context. I've observed several hard lockups on 3.10 kernel running 200 containers, caused by long duration of copy_process()->write_lock_irq() after SAK was sent to a tty. Current mainline kernel has the same problem. The solution is to use RCU to iterate processes and threads. Task list integrity is the only reason we taken tasklist_lock before, as tty subsys primitives mostly take it for reading also (e.g., __proc_set_tty). RCU read lock is enough for that. This patch solves the problem and makes __do_SAK() to be not greedy of tasklist_lock. That should prevent hard lockups I've pointed above. https://jira.sw.ru/browse/PSBM-80340 Signed-off-by: Kirill Tkhai <ktk...@virtuozzo.com> Reviewed-by: Pavel Tikhomirov <ptikhomi...@virtuozzo.com> (cherry picked from vz7 commit 6aecb63c35a5 ("tty: Use RCU read lock to iterate tasks and threads in __do_SAK()")) Signed-off-by: Andrey Zhadchenko <andrey.zhadche...@virtuozzo.com> --- drivers/tty/tty_io.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index c20eb63d700b..1bd5a9d4e416 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -2790,8 +2790,10 @@ void __do_SAK(struct tty_struct *tty) task_pid_nr(p), p->comm); group_send_sig_info(SIGKILL, SEND_SIG_PRIV, p, PIDTYPE_SID); } while_each_pid_task(session, PIDTYPE_SID, p); + read_unlock(&tasklist_lock); /* Now kill any processes that happen to have the tty open */ + rcu_read_lock(); for_each_process(p) { if (p->signal->tty == tty) { tty_notice(tty, "SAK: killed process %d (%s): by controlling tty\n", @@ -2820,7 +2822,7 @@ void __do_SAK(struct tty_struct *tty) kill: group_send_sig_info(SIGKILL, SEND_SIG_PRIV, p, PIDTYPE_SID); } - read_unlock(&tasklist_lock); + rcu_read_unlock(); #endif } _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel