All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Binoy Ravindran" <binoy@vt.edu>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	"Frederic Weisbecker" <frederic@kernel.org>,
	"Neeraj Upadhyay" <neeraj.upadhyay@kernel.org>,
	"Joel Fernandes" <joelagnelf@nvidia.com>,
	"Josh Triplett" <josh@joshtriplett.org>,
	"Boqun Feng" <boqun@kernel.org>,
	"Uladzislau Rezki" <urezki@gmail.com>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
	"Lai Jiangshan" <jiangshanlai@gmail.com>,
	Zqiang <qiang.zhang@linux.dev>,
	"Josh Poimboeuf" <jpoimboe@kernel.org>,
	"Miroslav Benes" <mbenes@suse.cz>,
	"Petr Mladek" <pmladek@suse.com>,
	"Joe Lawrence" <joe.lawrence@redhat.com>,
	"Song Liu" <song@kernel.org>, "Ingo Molnar" <mingo@kernel.org>,
	"Jiri Kosina" <jikos@kernel.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Juri Lelli" <juri.lelli@redhat.com>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
	"Ben Segall" <bsegall@google.com>, "Mel Gorman" <mgorman@suse.de>,
	"Valentin Schneider" <vschneid@redhat.com>,
	"K Prateek Nayak" <kprateek.nayak@amd.com>
Cc: live-patching@vger.kernel.org,
	"Yafang Shao" <laoar.shao@gmail.com>,
	"Jaidev Shastri" <jaidevshastri@vt.edu>
Subject: Re: [PATCH v5 1/4] rcu-tasks: Make the exit window an SRCU read-side critical section
Date: Sat, 05 Dec 2026 18:28:46 +0000	[thread overview]
Message-ID: <sashiko-outbox-251791@kernel.org> (raw)
In-Reply-To: <20261205-klp-series-v3-v5-1-3d60c8ea9316@vt.edu>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Low] rcu-tasks: exit SRCU wait APIs undefined if TASKS_RCU_GENERIC &&
  !TASKS_RCU
- [Low] rcu-tasks: duplicate rcu_tasks_exit_srcu_idx field bloats
  task_struct
- [Low] rcu-tasks: new exit wait APIs lack locking and exit-tail
  documentation
--

commit 609ca5b3cbc8a384c9da27d490a20f664c23f2de
Author: Binoy Ravindran <binoy@vt.edu>

rcu-tasks: Make the exit window an SRCU read-side critical section

This commit wraps the do_exit() window between exit_tasks_rcu_start() and
exit_tasks_rcu_finish() in a new tasks_rcu_exit_srcu read-side critical
section and adds blocking and polled wait helpers for callers that need to
wait for exiting tasks to leave that window.

> diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
> index 3f74ae6d6e1f2..4442fbe9e9ac8 100644
> --- a/include/linux/rcupdate.h
> +++ b/include/linux/rcupdate.h
> @@ -204,6 +204,9 @@ void rcu_tasks_rude_torture_stats_print(char *tt, char *tf);
>  #define rcu_note_voluntary_context_switch(t) rcu_tasks_qs(t, false)
>  void exit_tasks_rcu_start(void);
>  void exit_tasks_rcu_finish(void);
> +void synchronize_rcu_tasks_exit(void);
> +unsigned long start_poll_synchronize_rcu_tasks_exit(void);
> +bool poll_state_synchronize_rcu_tasks_exit(unsigned long cookie);
>  #else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
>  #define rcu_tasks_classic_qs(t, preempt) do { } while (0)
>  #define rcu_tasks_qs(t, preempt) do { } while (0)
> @@ -212,6 +215,9 @@ void exit_tasks_rcu_finish(void);
>  #define synchronize_rcu_tasks synchronize_rcu
>  static inline void exit_tasks_rcu_start(void) { }
>  static inline void exit_tasks_rcu_finish(void) { }
> +static inline void synchronize_rcu_tasks_exit(void) { }
> +static inline unsigned long start_poll_synchronize_rcu_tasks_exit(void) { return 0; }
> +static inline bool poll_state_synchronize_rcu_tasks_exit(unsigned long cookie) { return true; }
>  #endif /* #else #ifdef CONFIG_TASKS_RCU_GENERIC */

[Severity: Low]
Can calling these three helpers fail to link when CONFIG_TASKS_RCU_GENERIC
is enabled without CONFIG_TASKS_RCU?

CONFIG_TASKS_RCU_GENERIC is enabled whenever CONFIG_TASKS_RUDE_RCU is set,
so these declarations are exposed as external symbols even when
CONFIG_TASKS_RCU is disabled.  In kernel/rcu/tasks.h, however, they are only
defined under #ifdef CONFIG_TASKS_RCU, with no stubs in the #else branch.

Commit "livepatch: Select TASKS_RCU" later in this series avoids the link
error for livepatch, but the guard mismatch remains.  Guarding the
declarations and stubs with #ifdef CONFIG_TASKS_RCU (or adding matching
definitions in kernel/rcu/tasks.h) would keep all configs linkable.

> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index e4f6323d78555..0fe18976d1b40 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -963,6 +963,7 @@ struct task_struct {
>  	struct list_head		rcu_tasks_holdout_list;
>  	int				rcu_tasks_exit_cpu;
>  	struct list_head		rcu_tasks_exit_list;
> +	int				rcu_tasks_exit_srcu_idx;
>  #endif /* #ifdef CONFIG_TASKS_RCU */

[Severity: Low]
Could this reuse the existing u8 rcu_tasks_idx field in the same
#ifdef CONFIG_TASKS_RCU block instead of adding rcu_tasks_exit_srcu_idx?

rcu_tasks_idx has had no remaining users since commit 6b70399f9ef3
("rcu-tasks: Maintain lists to eliminate RCU-tasks/do_exit() deadlocks"),
and __srcu_read_lock() only returns 0 or 1.  Appending an int after
rcu_tasks_exit_list needlessly grows struct task_struct by 8 bytes (with
padding) on 64-bit builds without CONFIG_TASKS_TRACE_RCU and
CONFIG_TRIVIAL_PREEMPT_RCU.

> diff --git a/kernel/rcu/tasks.h b/kernel/rcu/tasks.h
> index fcac7361ec51e..57a16d7c33122 100644
> --- a/kernel/rcu/tasks.h
> +++ b/kernel/rcu/tasks.h
> @@ -1288,6 +1288,32 @@ void rcu_tasks_get_gp_data(int *flags, unsigned long *gp_seq)
>  }
>  EXPORT_SYMBOL_GPL(rcu_tasks_get_gp_data);
>  
> +/*
> + * Tasks between exit_tasks_rcu_start() and exit_tasks_rcu_finish() are
> + * no longer on the task list, but they still run kernel code.  This SRCU
> + * domain lets other subsystems wait for every task in that window to
> + * leave it.
> + */
> +DEFINE_STATIC_SRCU(tasks_rcu_exit_srcu);
> +
> +/* Wait for all tasks currently in the exit window to leave it. */
> +void synchronize_rcu_tasks_exit(void)
> +{
> +	synchronize_srcu(&tasks_rcu_exit_srcu);
> +}
> +
> +/* Start waiting for the tasks in the exit window, without blocking. */
> +unsigned long start_poll_synchronize_rcu_tasks_exit(void)
> +{
> +	return start_poll_synchronize_srcu(&tasks_rcu_exit_srcu);
> +}
> +
> +/* Have all tasks that were in the exit window at @cookie left it? */
> +bool poll_state_synchronize_rcu_tasks_exit(unsigned long cookie)
> +{
> +	return poll_state_synchronize_srcu(&tasks_rcu_exit_srcu, cookie);
> +}

[Severity: Low]
Should these new public helpers carry kernel-doc covering their calling
contexts, locking constraints, and exit-tail semantics, like
synchronize_rcu_tasks()?

exit_tasks_rcu_start() calls __srcu_read_lock() directly to bypass lockdep
(do_exit() checks debug_check_no_locks_held() inside the window).  Holding
any lock acquired in late do_exit() across synchronize_rcu_tasks_exit() will
deadlock silently, as in commit 1612160b9127 ("rcu-tasks: Eliminate
deadlocks involving do_exit() and RCU tasks").

In addition, exit_tasks_rcu_finish() runs inside the final preempt_disable()
section before lockdep_free_task() and do_task_dead(), so completing this
SRCU grace period alone does not guarantee exiting tasks are off the CPU;
callers needing that still require a follow-up CPU synchronization step.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-klp-series-v3-v5-0-3d60c8ea9316@vt.edu?part=1

  reply	other threads:[~2026-12-05 18:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 18:08 [PATCH v5 0/4] livepatch: Do not lose exiting tasks during a transition Binoy Ravindran
2026-12-05 18:08 ` Binoy Ravindran via B4 Relay
2026-12-05 18:08 ` [PATCH v5 1/4] rcu-tasks: Make the exit window an SRCU read-side critical section Binoy Ravindran
2026-12-05 18:08   ` Binoy Ravindran via B4 Relay
2026-12-05 18:28   ` sashiko-bot [this message]
2026-12-05 18:08 ` [PATCH v5 2/4] livepatch: Retry klp_synchronize_transition() if it fails Binoy Ravindran
2026-12-05 18:08   ` Binoy Ravindran via B4 Relay
2026-12-05 18:22   ` sashiko-bot
2026-12-05 18:08 ` [PATCH v5 3/4] livepatch: Select TASKS_RCU Binoy Ravindran
2026-12-05 18:08   ` Binoy Ravindran via B4 Relay
2026-12-05 18:08 ` [PATCH v5 4/4] livepatch: Wait for exiting tasks around a transition Binoy Ravindran
2026-12-05 18:08   ` Binoy Ravindran via B4 Relay
2026-12-05 18:27   ` sashiko-bot

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=sashiko-outbox-251791@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=binoy@vt.edu \
    --cc=boqun@kernel.org \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=frederic@kernel.org \
    --cc=jaidevshastri@vt.edu \
    --cc=jiangshanlai@gmail.com \
    --cc=jikos@kernel.org \
    --cc=joe.lawrence@redhat.com \
    --cc=joelagnelf@nvidia.com \
    --cc=josh@joshtriplett.org \
    --cc=jpoimboe@kernel.org \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=laoar.shao@gmail.com \
    --cc=live-patching@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mbenes@suse.cz \
    --cc=mgorman@suse.de \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=neeraj.upadhyay@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=qiang.zhang@linux.dev \
    --cc=rostedt@goodmis.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=song@kernel.org \
    --cc=urezki@gmail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.