mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ravindran, Binoy" <binoy@vt.edu>
To: "paulmck@kernel.org" <paulmck@kernel.org>
Cc: 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>,
	"rcu@vger.kernel.org" <rcu@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"live-patching@vger.kernel.org" <live-patching@vger.kernel.org>,
	Yafang Shao <laoar.shao@gmail.com>,
	"Shastri, Jaidev" <jaidevshastri@vt.edu>
Subject: Re: [PATCH v4 1/3] rcu-tasks: Add helpers to visit tasks on the exit lists
Date: Wed, 2 Dec 2026 06:16:32 +0000	[thread overview]
Message-ID: <DM6PR05MB41375F7AE7D930B15E2959C0D14C2@DM6PR05MB4137.namprd05.prod.outlook.com> (raw)
In-Reply-To: <3c5f8fce-56e8-43e4-bbfe-4bd5eed706a1@paulmck-laptop>


On Mon, Nov 30, 2026, Paul E. McKenney wrote:
> Apologies for my confusion, but so many RCU versions!  ;-)

No apology needed, and thank you.

> Would it work to add those __srcu_read_lock() and __srcu_read_unlock()
> calls to exit_tasks_rcu_start() and exit_tasks_rcu_finish(),
> respectively, then have your code do synchronize_srcu() instead of
> synchronize_rcu_tasks(), presumably by invoking a helper function in
> kernel/rcu/tasks.h?

Yes, it works in our tests.

I built it on v7.4-rc2 with our series. exit_tasks_rcu_start() enters an
SRCU read-side critical section on a static SRCU domain, and keeps the
index in a new task_struct field. exit_tasks_rcu_finish() leaves it. A
helper in kernel/rcu/tasks.h calls synchronize_srcu().
klp_try_complete_transition() calls it after every task on the task
list has switched, before the cleanup.

> Some thought and/or experiment maybe required to come up with the optimal
> variant of __srcu_read_lock() and __srcu_read_unlock(), but those are
> good places to start.

I used plain __srcu_read_lock() and __srcu_read_unlock(). I have not
tried other variants yet.

> This assumes that your code would not be holding mutexes across my
> proposed synchronize_srcu() that are also acquired by do_exit() between
> its calls to exit_tasks_rcu_start() and exit_tasks_rcu_finish().  See
> here for more details:
>
> 1612160b9127 ("rcu-tasks: Eliminate deadlocks involving do_exit() and RCU tasks")
>
> If your code does need to hold such mutexes, back to the drawing board.

Our code does hold klp_mutex across synchronize_srcu(). I checked
against 1612160b9127, and as far as I can see, nothing between
exit_tasks_rcu_start() and exit_tasks_rcu_finish() takes klp_mutex. No
test deadlocked.

The test is the same as before. A test-only hook makes exiting tasks
sleep after exit_notify(), and two livepatches that both replace
do_exit() replace each other in a loop.

Safety: 120 runs and 1,440 cycles, with no sleep and with sleeps from
20 ms to 2 s, had no crash. 42 of those runs used your SRCU change
without our exit-list walks, and they also had no warnings. I did not
test forced transitions with SRCU.

Lockdep: I ran three kernels under PROVE_LOCKING, PROVE_RCU and
DEBUG_ATOMIC_SLEEP: your SRCU change without our walks, your SRCU
change with the rest of our series, and our current series. Each
kernel ran 16 runs, with a 2 s sleep, a 200 ms sleep and no sleep.
There were no lockdep or sleep-in-atomic reports, no hung tasks and no
crashes. The only warning was the reschedule IPI warning at
arch/x86/kernel/apic/ipi.c:71, which we also see without either change.

Latency: here the two designs differ. The SRCU wait covers every task
in the exit window, even one that never runs patched code. Our walk
waits only for exiting tasks that still run patched code. To show this,
I used two livepatches that change getpid(), so no exiting task runs
patched code. Transition times, from "starting patching transition" to
"patching complete", as p90 / p99, from 36 runs per exit sleep (18 for
no sleep):

  no sleep:  our walk 1.68 / 1.79 s,  SRCU 1.68 / 1.78 s
  500 ms:    our walk 1.73 / 1.84 s,  SRCU 1.89 / 2.26 s
  1 s:       our walk 1.75 / 1.91 s,  SRCU 2.48 / 2.80 s
  2 s:       our walk 1.84 / 2.03 s,  SRCU 3.60 / 3.86 s

Both designs retry the transition once a second, which accounts for
most of the time with no sleep.

With no injected sleep, I also ran 24 runs per design while the guests
tore down PID namespaces, about 430,000 for each design. The p99 was
1.78 s with our walk and 1.76 s with SRCU. The longest transition was
1.94 s with our walk and 3.97 s with SRCU.

Slow exits do happen without an injected sleep. We traced exits while
PID namespaces were torn down in a loop. The longest voluntary sleep in
the exit window was 146 ms on an arm64 host and 2 ms on an x86-64 host.
Every voluntary sleep of 1 ms or more was a namespace's init waiting
for its children.

So in these runs, SRCU cost little when no exit was slow, and it added
the length of a slow exit when there was one. It is also simpler and
needs no new walker interface on the RCU side. Which would you and the
livepatch maintainers prefer? I am happy to rework the series around
SRCU if that is the better fit.

Thanks,
Binoy



  reply	other threads:[~2026-12-02  6:16 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 16:41 [PATCH v4 0/3] livepatch: Do not lose exiting tasks during a transition Binoy Ravindran via B4 Relay
2026-11-26 16:41 ` [PATCH v4 1/3] rcu-tasks: Add helpers to visit tasks on the exit lists Binoy Ravindran via B4 Relay
2026-11-26 18:52   ` Petr Mladek
2026-11-27 18:56     ` Ravindran, Binoy
2026-11-30 17:42   ` Paul E. McKenney
2026-11-30 18:17     ` Ravindran, Binoy
2026-11-30 19:55       ` Paul E. McKenney
2026-12-01  0:29         ` Ravindran, Binoy
2026-12-01  1:24           ` Paul E. McKenney
2026-12-02  6:16             ` Ravindran, Binoy [this message]
2026-11-26 16:41 ` [PATCH v4 2/3] livepatch: Include exiting tasks in the transition Binoy Ravindran via B4 Relay
2026-11-27 16:10   ` Petr Mladek
2026-11-27 19:30     ` Ravindran, Binoy
2026-11-26 16:41 ` [PATCH v4 3/3] livepatch: Select TASKS_RCU Binoy Ravindran via B4 Relay

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=DM6PR05MB41375F7AE7D930B15E2959C0D14C2@DM6PR05MB4137.namprd05.prod.outlook.com \
    --to=binoy@vt.edu \
    --cc=boqun@kernel.org \
    --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=laoar.shao@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mbenes@suse.cz \
    --cc=mingo@kernel.org \
    --cc=neeraj.upadhyay@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=pmladek@suse.com \
    --cc=qiang.zhang@linux.dev \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=song@kernel.org \
    --cc=urezki@gmail.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

all inboxes | Powered by JetHome®