livepatch: klp_send_signal should treat PF_IO_WORKER like PF_KTHREAD
Subsystems (5)
PATCH 1/1 livepatch: klp_send_signal should treat PF_IO_WORKER like PF_KTHREAD
commit 15b2219facad ("kernel: freezer should treat PF_IO_WORKER like PF_KTHREAD for freezing") is to fix the freezeing issue of IO threads by making the freezer not send them fake signals.
Here live patching consistency model call klp_send_signals to wake up all tasks by send fake signal to all non-kthread which only check the PF_KTHREAD flag, so it still send signal to io threads which may lead to freezeing issue of io threads.
Here we take the same fix action by treating PF_IO_WORKERS as PF_KTHREAD within klp_send_signal function.
---
note:
the io threads freeze issue links:
[1] https://lore.kernel.org/io-uring/YEgnIp43%[email protected]/
[2] https://lore.kernel.org/io-uring/[email protected]/
kernel/livepatch/transition.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/livepatch/transition.c +1 -1
@@ -358,7 +358,7 @@ static void klp_send_signals(void)* Meanwhile the task could migrate itself and the action * would be meaningless. It is not serious though. */ -if (task->flags &PF_KTHREAD ) { +if (task->flags & (PF_KTHREAD |PF_IO_WORKER )) {/* * Wake up a kthread which sleeps interruptedly and * still has not been migrated.
Signature · 1 line
2.17.1
Quoted 2 lines · Dong Kai
commit
15b2219facad("kernel: freezer should treatPF_IO_WORKERlikePF_KTHREADfor freezing") is to fix the freezeing issue of IO threads
nit: s/freezeing/freezing
Quoted 26 lines
by making the freezer not send them fake signals.
Here live patching consistency model call
klp_send_signalsto wake up all tasks by send fake signal to all non-kthread which only check thePF_KTHREADflag, so it still send signal to io threads which may lead to freezeing issue of io threads.Here we take the same fix action by treating
PF_IO_WORKERSasPF_KTHREADwithinklp_send_signalfunction.Signed-off-by Dong Kai <[email protected]>---
note:
the io threads freeze issue links:
[1] https://lore.kernel.org/io-uring/YEgnIp43%[email protected]/
[2] https://lore.kernel.org/io-uring/[email protected]/kernel/livepatch/transition.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/livepatch/transition.c +0
-0
kernel/livepatch/transition.c static void klp_send_signals(void) · line 364
Quoted 8 lines
kernel/livepatch/transition.c +1
-1@@ -358,7 +358,7 @@ static void klp_send_signals(void)* Meanwhile the task could migrate itself and the action * would be meaningless. It is not serious though. */ -if (task->flags &PF_KTHREAD ) { +if (task->flags & (PF_KTHREAD |PF_IO_WORKER )) {/* * Wake up a kthread which sleeps interruptedly and * still has not been migrated.
(PF_KTHREAD | PF_IO_WORKER) is open coded in soo many places maybe this is a silly question, but...
If the livepatch code could use fake_signal_wake_up(), we could consolidate the pattern in klp_send_signals() with the one in freeze_task(). Then there would only one place for wake up / fake signal logic.
I don't fully understand the differences in the freeze_task() version, so I only pose this as a question and not v2 request.
As it is, this change seems logical to me, so:
Thanks,
-- Joe
Miroslav Benes
maintainerQuoted 9 lines
(
PF_KTHREAD|PF_IO_WORKER) is open coded in soo many places maybe this is a silly question, but...If the livepatch code could use
fake_signal_wake_up(), we could consolidate the pattern inklp_send_signals()with the one infreeze_task(). Then there would only one place for wake up / fake signal logic.I don't fully understand the differences in the
freeze_task()version, so I only pose this as a question and not v2 request.
The plan was to remove our live patching fake signal completely and use the new infrastructure Jens proposed in the past.
Something like
kernel/livepatch/transition.c +2 -3
@@ -9,6 +9,7 @@#include <linux/cpu.h> #include <linux/stacktrace.h> +#include <linux/tracehook.h> #include "core.h" #include "patch.h" #include "transition.h"
@@ -369,9 +370,7 @@ static void klp_send_signals(void)* Send fake signal to all non-kthread tasks which are * still not migrated. */ -spin_lock_irq (&task->sighand->siglock); -signal_wake_up (task,0 ); -spin_unlock_irq (&task->sighand->siglock); +set_notify_signal (task); } }read_unlock (&tasklist_lock);
kernel/signal.c +1 -2
@@ -181,8 +181,7 @@ void recalc_sigpending_and_wake(struct task_struct *t)void recalc_sigpending (void ) { -if (!recalc_sigpending_tsk (current) && !freezing (current) && - !klp_patch_pending (current)) +if (!recalc_sigpending_tsk (current) && !freezing (current))clear_thread_flag (TIF_SIGPENDING ); }
Let me verify it still works and there are all the needed pieces merged for all the architectures we support (x86_64, ppc64le and s390x). I'll send a proper patch then.
Miroslav
Quoted 7 lines · Miroslav Benes
Quoted 7 lines
(
PF_KTHREAD|PF_IO_WORKER) is open coded in soo many places maybe this is a silly question, but...If the livepatch code could use
fake_signal_wake_up(), we could consolidate the pattern inklp_send_signals()with the one infreeze_task(). Then there would only one place for wake up / fake signal logic.
Quoted 5 lines
Quoted 2 lines
I don't fully understand the differences in the
freeze_task()version, so I only pose this as a question and not v2 request.The plan was to remove our live patching fake signal completely and use the new infrastructure Jens proposed in the past.
That would be great, I've actually been waiting for that to show up! I would greatly prefer this approach if you deem it suitable for 5.12, if not we'll still need the temporary work-around for live patching.
Signature · 1 line
Jens Axboe
Miroslav Benes
maintainerQuoted 8 lines · Jens Axboe
Quoted 7 lines · Miroslav Benes
Quoted 7 lines
(
PF_KTHREAD|PF_IO_WORKER) is open coded in soo many places maybe this is a silly question, but...If the livepatch code could use
fake_signal_wake_up(), we could consolidate the pattern inklp_send_signals()with the one infreeze_task(). Then there would only one place for wake up / fake signal logic.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
I don't fully understand the differences in the
freeze_task()version, so I only pose this as a question and not v2 request.The plan was to remove our live patching fake signal completely and use the new infrastructure Jens proposed in the past.
That would be great, I've actually been waiting for that to show up!
Sorry about that. I failed to notice that the infrastructure was merged already. I'll send it soonish.
Quoted 2 lines
I would greatly prefer this approach if you deem it suitable for 5.12, if not we'll still need the temporary work-around for live patching.
I noticed there is [email protected] now, so I suppose we should wait for that to land in mainline and simply do nothing about PF_IO_WORKER for live patching.
Miroslav
Miroslav Benes
maintainerQuoted 8 lines · Dong Kai
commit
15b2219facad("kernel: freezer should treatPF_IO_WORKERlikePF_KTHREADfor freezing") is to fix the freezeing issue of IO threads by making the freezer not send them fake signals.Here live patching consistency model call
klp_send_signalsto wake up all tasks by send fake signal to all non-kthread which only check thePF_KTHREADflag, so it still send signal to io threads which may lead to freezeing issue of io threads.
I suppose this could happen, but it will also affect the live patching transition if the io threads do not react to signals.
Are you able to reproduce it easily? I mean, is there a testcase I could use to take a closer look?
Quoted 2 lines
Here we take the same fix action by treating
PF_IO_WORKERSasPF_KTHREADwithinklp_send_signalfunction.
Yes, this sounds reasonable.
Miroslav
Quoted 23 lines
Signed-off-by Dong Kai <[email protected]>---
note:
the io threads freeze issue links:
[1] https://lore.kernel.org/io-uring/YEgnIp43%[email protected]/
[2] https://lore.kernel.org/io-uring/[email protected]/kernel/livepatch/transition.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/livepatch/transition.c +1
-1@@ -358,7 +358,7 @@ static void klp_send_signals(void)* Meanwhile the task could migrate itself and the action * would be meaningless. It is not serious though. */ -if (task->flags &PF_KTHREAD ) { +if (task->flags & (PF_KTHREAD |PF_IO_WORKER )) {/* * Wake up a kthread which sleeps interruptedly and * still has not been migrated.
Joe Lawrence
maintainerQuoted 11 lines · Miroslav Benes
Quoted 8 lines · Dong Kai
commit
15b2219facad("kernel: freezer should treatPF_IO_WORKERlikePF_KTHREADfor freezing") is to fix the freezeing issue of IO threads by making the freezer not send them fake signals.Here live patching consistency model call
klp_send_signalsto wake up all tasks by send fake signal to all non-kthread which only check thePF_KTHREADflag, so it still send signal to io threads which may lead to freezeing issue of io threads.
Quoted 6 lines
I suppose this could happen, but it will also affect the live patching transition if the io threads do not react to signals.
Are you able to reproduce it easily? I mean, is there a testcase I could use to take a closer look?
If repro is only hypothetical at this point, perhaps we can artificially create it in selftests? And useful to verify the future change you mentioned in your other reply?
-- Joe
Quoted 11 lines · Miroslav Benes
Quoted 8 lines · Dong Kai
commit
15b2219facad("kernel: freezer should treatPF_IO_WORKERlikePF_KTHREADfor freezing") is to fix the freezeing issue of IO threads by making the freezer not send them fake signals.Here live patching consistency model call
klp_send_signalsto wake up all tasks by send fake signal to all non-kthread which only check thePF_KTHREADflag, so it still send signal to io threads which may lead to freezeing issue of io threads.
Quoted 6 lines
I suppose this could happen, but it will also affect the live patching transition if the io threads do not react to signals.
Are you able to reproduce it easily? I mean, is there a testcase I could use to take a closer look?
Um... I tried but failed to reproduce this on real environment as i'm not familiar with the io uring usage.
So i use a tricky way to verify this possibility by the following patch which create a fake io thread in module and patch the func which is always within thread running stack. Then the stack check will failed when transition and trigger the klp_send_signal flow.
This example may not suitable, but you can get my point
Kai
Note: this patch export some symbols just for test via module because if i create io thread via sysinit, it will receive SIGKILL signal[set by zap_other_threads] when run init process and exit the loop, weird...
fs/exec.c +1 -0
@@ -1229,6 +1229,7 @@ void __set_task_comm(struct task_struct *tsk, const char *buf, bool exec)task_unlock (tsk);perf_event_comm (tsk, exec); } +EXPORT_SYMBOL_GPL (__set_task_comm);/* * Calling this is the point of no return. None of the failures will be
kernel/fork.c +1 -0
@@ -2447,6 +2447,7 @@ struct task_struct *create_io_thread(int (*fn)(void *), void *arg, int node) }return tsk; } +EXPORT_SYMBOL (create_io_thread);/* * Ok, this is the main fork-routine.
index 98191218d891..8151d17149a0 100644
kernel/sched/core.c +1 -0
@@ -3856,6 +3856,7 @@ void wake_up_new_task(struct task_struct *p)#endif task_rq_unlock (rq, p, &rf); } +EXPORT_SYMBOL_GPL (wake_up_new_task);#ifdef CONFIG_PREEMPT_NOTIFIERS
samples/test/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-m += io_thread.o livepatch-sample.o
samples/test/io_thread.c new file +49 -0
49 lines not on this page · raw message
samples/test/livepatch-sample.c new file +43 -0
43 lines not on this page · raw message
Quoted 31 lines
Quoted 2 lines
Here we take the same fix action by treating
PF_IO_WORKERSasPF_KTHREADwithinklp_send_signalfunction.Yes, this sounds reasonable.
Miroslav
Quoted 23 lines
Signed-off-by Dong Kai <[email protected]>---
note:
the io threads freeze issue links:
[1] https://lore.kernel.org/io-uring/YEgnIp43%[email protected]/
[2] https://lore.kernel.org/io-uring/[email protected]/kernel/livepatch/transition.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/livepatch/transition.c +1
-1@@ -358,7 +358,7 @@ static void klp_send_signals(void)* Meanwhile the task could migrate itself and the action * would be meaningless. It is not serious though. */ -if (task->flags &PF_KTHREAD ) { +if (task->flags & (PF_KTHREAD |PF_IO_WORKER )) {/* * Wake up a kthread which sleeps interruptedly and * still has not been migrated.
Quoted 11 lines · Dong Kai
commit
15b2219facad("kernel: freezer should treatPF_IO_WORKERlikePF_KTHREADfor freezing") is to fix the freezeing issue of IO threads by making the freezer not send them fake signals.Here live patching consistency model call
klp_send_signalsto wake up all tasks by send fake signal to all non-kthread which only check thePF_KTHREADflag, so it still send signal to io threads which may lead to freezeing issue of io threads.Here we take the same fix action by treating
PF_IO_WORKERSasPF_KTHREADwithinklp_send_signalfunction.
Signature · 1 line
Jens Axboe