public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Peter Zijlstra <peterz@infradead.org>
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 10:49:10 +0100	[thread overview]
Message-ID: <Z-PNll7fJQzCDH35@pathway.suse.cz> (raw)
In-Reply-To: <20250324134909.GA14718@noisy.programming.kicks-ass.net>

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().

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.

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.

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.

Best Regards,
Petr

  reply	other threads:[~2025-03-26  9:49 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 [this message]
2025-03-26 10:38   ` Peter Zijlstra
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=Z-PNll7fJQzCDH35@pathway.suse.cz \
    --to=pmladek@suse.com \
    --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=peterz@infradead.org \
    --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