live-patching.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Patching kthread functions
@ 2020-09-30 15:44 Evgenii Shatokhin
  2020-10-01 11:13 ` Miroslav Benes
  0 siblings, 1 reply; 10+ messages in thread
From: Evgenii Shatokhin @ 2020-09-30 15:44 UTC (permalink / raw)
  To: live-patching

Hi,

I wonder, can livepatch from the current mainline kernel patch the main 
functions of kthreads, which are running or sleeping constantly? Are 
there any best practices here?

I mean, suppose we have a function which runs in a kthread (passed to 
kthread_create()) and is organized like this:

while (!kthread_should_stop()) {
   ...
   DEFINE_WAIT(_wait);
   for (;;) {
     prepare_to_wait(waitq, &_wait, TASK_INTERRUPTIBLE);
     if (we_have_requests_to_process || kthread_should_stop())
       break;
     schedule();
   }
   finish_wait(waitq, &_wait);
   ...
   if (we_have_requests_to_process)
     process_one_request();
   ...
}

(The question appeared when I was looking at the following code: 
https://src.openvz.org/projects/OVZ/repos/vzkernel/browse/drivers/block/ploop/io_kaio.c?at=refs%2Ftags%2Frh7-3.10.0-1127.8.2.vz7.151.14#478)

The kthread is always running and never exits the kernel.

I could rewrite the function to add klp_update_patch_state() somewhere, 
but would it help?

No locks are held right before and after "schedule()", and the thread is 
not processing any requests at that point. But even if I place 
klp_update_patch_state(), say, just before schedule(), it would just 
switch task->patch_state for that kthread. The old function will 
continue running, right?

Looks like we can only switch to the patched code of the function at the 
beginning, via Ftrace hook. So, if the function is constantly running or 
sleeping, it seems, it cannot be live-patched. Is that so? Are there any 
workarounds?

Thanks in advance.

Regards,
Evgenii

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-10-02 13:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-30 15:44 Patching kthread functions Evgenii Shatokhin
2020-10-01 11:13 ` Miroslav Benes
2020-10-01 12:43   ` Nicolai Stange
2020-10-01 13:18     ` Evgenii Shatokhin
2020-10-01 13:12   ` Evgenii Shatokhin
2020-10-02 11:53     ` Miroslav Benes
2020-10-02 12:52       ` Evgenii Shatokhin
2020-10-02 13:06         ` Miroslav Benes
2020-10-01 14:46   ` Petr Mladek
2020-10-01 16:34     ` Evgenii Shatokhin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).