live-patching.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
To: Petr Mladek <pmladek@suse.com>
Cc: Miroslav Benes <mbenes@suse.cz>,
	live-patching@vger.kernel.org, nstange@suse.de
Subject: Re: Patching kthread functions
Date: Thu, 1 Oct 2020 19:34:16 +0300	[thread overview]
Message-ID: <b7f76c10-28a4-8779-c07c-b958955d9077@virtuozzo.com> (raw)
In-Reply-To: <20201001144625.GE17717@alley>

On 01.10.2020 17:46, Petr Mladek wrote:
> On Thu 2020-10-01 13:13:07, Miroslav Benes wrote:
>> On Wed, 30 Sep 2020, Evgenii Shatokhin wrote:
>>
>>> 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?
>>
>> No. It is a "known" limitation, "" because we discussed it a couple of
>> times (at least with Petr), but it is not documented :(
>>
>> I wonder if it is really an issue practically. I haven't met a case
>> yet when we wanted to patch such thing. But yes, you're correct, it is not
>> possible.
>>   
>>> 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();
>>>    ...
>>> }
> 
> Crazy hack would be to patch only process_one_request() the following way:
> 
> 1. Put the fixed main loop into the new process_one_request() function.
> 
> 2. Put the original process_one_request() code into another function,
>     e.g. do_process_one_request_for_real() and call it from the
>     fixed loop.
> 
> Does it make any sense or should I provide some code?

I think, I get the idea, thanks!

So, the thread would loop in the new process_one_request() and, with 
necessary care taken, would exit both loops correctly when needed.

In our case (kaio_fsync_thread() at the mentioned URL) 
process_one_request() is actually not a separate function but rather 
part of the same thread function. So, in this particular case it would 
not help. If we refactor the function in some future versions, this 
could be an option.

But, yes, such patch would need to remain applied forever, no updates 
and no unloads, which is a downside.

> 
> Be aware that such patch could not get reverted because it would never
> leave the new main loop.
> 
> Best Regards,
> Petr
> .
> 

Regards,
Evgenii

      reply	other threads:[~2020-10-01 16:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b7f76c10-28a4-8779-c07c-b958955d9077@virtuozzo.com \
    --to=eshatokhin@virtuozzo.com \
    --cc=live-patching@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=nstange@suse.de \
    --cc=pmladek@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).