Live Patching
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Josh Poimboeuf <jpoimboe@kernel.org>, live-patching@vger.kernel.org
Subject: Re: question re klp_transition_work kickoff timeout
Date: Thu, 23 Mar 2023 17:22:09 +0100	[thread overview]
Message-ID: <ZBx8sRTmpljI/i6Z@alley> (raw)
In-Reply-To: <ZBx5pvZXLv/ikl/f@alley>

On Thu 2023-03-23 17:09:13, Petr Mladek wrote:
> On Wed 2023-03-22 18:41:40, Alexey Dobriyan wrote:
> > Hi, Josh.
> > 
> > I've been profiling how much time livepatching takes and I have a question
> > regarding these lines:
> > 
> > 	void klp_try_complete_transition(void)
> > 	{
> > 		...
> > 		if (!complete) {
> > 			schedule_delayed_work(&klp_transition_work, round_jiffies_relative(HZ));
> > 			return;
> > 		}
> > 
> > 	}
> > 
> > The problem here is that if the system is idle, then the previous loop
> > checking idle tasks will reliably sets "complete = false" and then
> > patching wastes time waiting for next second so that klp_transition_work
> > will repeat the same code without reentering itself.
> > 
> > I've created trivial patch which changes 2 functions and it takes
> > ~1.3 seconds to complete transition:
> > 
> > 	[   33.829506] livepatch: 'main': starting patching transition
> > 	[   35.190721] livepatch: 'main': patching complete
> > 
> > I don't know what's the correct timeout to retry transition work
> > but it can be made near-instant:
> > 
> > 	[  100.930758] livepatch: 'main': starting patching transition
> > 	[  100.956190] livepatch: 'main': patching complete
> > 
> > 
> > 	Alexey (CloudLinux)
> > 
> > 
> > --- a/kernel/livepatch/transition.c
> > +++ b/kernel/livepatch/transition.c
> > @@ -435,8 +435,7 @@ void klp_try_complete_transition(void)
> >  		 * later and/or wait for other methods like kernel exit
> >  		 * switching.
> >  		 */
> > -		schedule_delayed_work(&klp_transition_work,
> > -				      round_jiffies_relative(HZ));
> > +		schedule_delayed_work(&klp_transition_work, msecs_to_jiffies(1));
> 
> Note that this affects all iterations, not only the first one. In
> practice, it might schedule another klp_transition_work() almost
> immediately. Servers typically use HZ = 250 and 1ms is less than 1 jiffy.
> 
> Now, klp_try_complete_transition() takes tasklist_lock and blocks
> forking and exiting. It sounds scary to do this so frequently.
> Is am actually surprised that nobody reported any problems
> even with the 1sec period.
> 
> Please, stop these micro-optimizations!
> 
> Livepatching is about security and reliability. It is not about speed!
> 
> The fact that the transition is so lazy is a great feature.
> Livepatching should make the system more safe without breaking it.
> It is great that it could run in background and do not limit
> the normal workload too much.

By other words. It might be interesting to find a way how to migrate
the idle tasks during the first klp_try_complete_transition() call.
As a result the 2nd call would not be needed and it would make
livepatching even more lightweight.

But just increasing the frequency of klp_try_complete_transition()
is not the way to go.

Best Regards,
Petr

  reply	other threads:[~2023-03-23 16:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-22 15:41 question re klp_transition_work kickoff timeout Alexey Dobriyan
2023-03-22 16:07 ` Miroslav Benes
2023-03-23  9:52   ` Alexey Dobriyan
2023-03-23 15:15     ` Miroslav Benes
2023-03-23 16:09 ` Petr Mladek
2023-03-23 16:22   ` Petr Mladek [this message]
2023-03-23 16:31     ` Alexey Dobriyan

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=ZBx8sRTmpljI/i6Z@alley \
    --to=pmladek@suse.com \
    --cc=adobriyan@gmail.com \
    --cc=jpoimboe@kernel.org \
    --cc=live-patching@vger.kernel.org \
    /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