From: Peter Zijlstra <peterz@infradead.org>
To: Petr Mladek <pmladek@suse.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>,
mingo@kernel.com, juri.lelli@redhat.com,
vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
vschneid@redhat.com, jpoimboe@kernel.org, jikos@kernel.org,
mbenes@suse.cz, joe.lawrence@redhat.com,
linux-kernel@vger.kernel.org, live-patching@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Subject: Re: [RFC][PATCH] sched,livepatch: Untangle cond_resched() and live-patching
Date: Wed, 26 Mar 2025 11:38:43 +0100 [thread overview]
Message-ID: <20250326103843.GB5880@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <Z-PNll7fJQzCDH35@pathway.suse.cz>
On Wed, Mar 26, 2025 at 10:49:10AM +0100, Petr Mladek wrote:
> On Mon 2025-03-24 14:49:09, Peter Zijlstra wrote:
> >
> > With the goal of deprecating / removing VOLUNTARY preempt, live-patch
> > needs to stop relying on cond_resched() to make forward progress.
> >
> > Instead, rely on schedule() with TASK_FREEZABLE set. Just like
> > live-patching, the freezer needs to be able to stop tasks in a safe /
> > known state.
>
> > Compile tested only.
> >
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> > ---
> > include/linux/livepatch_sched.h | 15 +++++--------
> > include/linux/sched.h | 6 -----
> > kernel/livepatch/transition.c | 30 ++++++-------------------
> > kernel/sched/core.c | 50 +++++++----------------------------------
> > 4 files changed, 21 insertions(+), 80 deletions(-)
> >
> > diff --git a/include/linux/livepatch_sched.h b/include/linux/livepatch_sched.h
> > index 013794fb5da0..7e8171226dd7 100644
> > --- a/include/linux/livepatch_sched.h
> > +++ b/include/linux/livepatch_sched.h
> > @@ -3,27 +3,24 @@
> > #define _LINUX_LIVEPATCH_SCHED_H_
> >
> > #include <linux/jump_label.h>
> > -#include <linux/static_call_types.h>
> > +#include <linux/sched.h>
> > +
> >
> > #ifdef CONFIG_LIVEPATCH
> >
> > void __klp_sched_try_switch(void);
> >
> > -#if !defined(CONFIG_PREEMPT_DYNAMIC) || !defined(CONFIG_HAVE_PREEMPT_DYNAMIC_CALL)
> > -
> > DECLARE_STATIC_KEY_FALSE(klp_sched_try_switch_key);
> >
> > -static __always_inline void klp_sched_try_switch(void)
> > +static __always_inline void klp_sched_try_switch(struct task_struct *curr)
> > {
> > - if (static_branch_unlikely(&klp_sched_try_switch_key))
> > + if (static_branch_unlikely(&klp_sched_try_switch_key) &&
> > + READ_ONCE(curr->__state) & TASK_FREEZABLE)
> > __klp_sched_try_switch();
> > }
>
> Do we really need to check the TASK_FREEZABLE state, please?
>
> My understanding is that TASK_FREEZABLE is set when kernel kthreads go into
> a "freezable" sleep, e.g. wait_event_freezable().
Right.
> But __klp_sched_try_switch() should be safe when the task is not
> running and the stack is reliable. IMHO, it should be safe anytime
> it is being scheduled out.
So for the reasons you touched upon in the next paragraph, FREEZABLE
seemed like a more suitable location.
> Note that wait_event_freezable() is a good location. It is usually called in
> the main loop of the kthread where the stack is small. So that the chance
> that it is not running a livepatched function is higher than on
> another random schedulable location.
Right, it is the natural quiescent state of the kthread, it holds no
resources.
> But we actually wanted to have it in cond_resched() because
> it might take a long time to reach the main loop, and sleep there.
Well, cond_resched() is going to get deleted, so we need to find
something else. And I was thinking that the suspend people want
reasonable timeliness too -- you don't want your laptop to continue
running for many seconds after you close the lid and stuff it in your
bag, now do you.
So per that reasoning I figured FREEZABLE should be good enough.
Sharing the pain with suspend can only lead to improving both -- faster
patching progress leads to faster suspend and vice-versa.
next prev parent reply other threads:[~2025-03-26 10:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-24 13:49 [RFC][PATCH] sched,livepatch: Untangle cond_resched() and live-patching Peter Zijlstra
2025-03-26 9:49 ` Petr Mladek
2025-03-26 10:38 ` Peter Zijlstra [this message]
2025-03-26 14:37 ` Miroslav Benes
2025-03-26 14:42 ` Peter Zijlstra
2025-03-26 14:52 ` Miroslav Benes
2025-03-26 14:54 ` Miroslav Benes
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=20250326103843.GB5880@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bigeasy@linutronix.de \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=jpoimboe@redhat.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=mgorman@suse.de \
--cc=mingo@kernel.com \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.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