From: sashiko-bot@kernel.org
To: "Egor Shalashnov" <shalasheg@gmail.com>, linux-mm@kvack.org
Cc: akpm@linux-foundation.org, dennis@kernel.org, tj@kernel.org,
cl@gentwo.org
Subject: Re: [RFC] percpu_ref: deadlock when release calls exit on an atomic ref
Date: Tue, 01 Dec 2026 16:48:11 +0000 [thread overview]
Message-ID: <sashiko-outbox-243736@kernel.org> (raw)
In-Reply-To: <c94764bc-a8c9-4771-a649-ccebded0844e@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] percpu_ref: missing Signed-off-by trailer in commit message
- [Low] percpu_ref: missing Fixes trailer on bug-fix commit
--
commit a5a8e856aaed90127d6381609b067a69b8547fd2
Author: Egor Shalashnov <shalasheg@gmail.com>
> percpu_ref: deadlock when release calls exit on an atomic ref
>
> Hi,
>
> After implementing hashed switch locks, I continued experimenting
> with percpu_ref and came across a deadlock when killing a ref that
> is already in atomic mode and whose release callback calls
> percpu_ref_exit(). This also reproduces with the original global
> switch lock.
>
> A minimal example is:
>
> static void release(struct percpu_ref *ref)
> {
> percpu_ref_exit(ref);
> }
>
> static int reproduce(void)
> {
> struct percpu_ref ref;
> int ret;
>
> ret = percpu_ref_init(&ref, release, PERCPU_REF_INIT_ATOMIC,
> GFP_KERNEL);
> if (ret)
> return ret;
>
> percpu_ref_kill(&ref);
> return 0;
> }
>
> percpu_ref_kill_and_confirm() holds percpu_ref_switch_lock while
> dropping the initial reference. With no additional references,
> percpu_ref_put() decrements the count from 1 to 0 and invokes
> release() synchronously. percpu_ref_exit() then tries to acquire
> the same lock:
>
> percpu_ref_kill()
> percpu_ref_kill_and_confirm()
> spin_lock_irqsave()
> percpu_ref_put()
> release()
> percpu_ref_exit()
> spin_lock_irqsave() /* recursive acquisition */
>
> The same situation can arise after explicitly switching a ref
> to atomic mode. I have not identified an in-tree caller that
> triggers this exact sequence, but the documentation
> for percpu_ref_exit() explicitly says:
>
> "The usual places to invoke this function from are the
> @ref->release() callback or in init failure path [...]"
>
> When kill starts from percpu mode, the transition to atomic mode
> takes an extra reference, which is dropped from the RCU callback.
> This prevents the put in percpu_ref_kill_and_confirm() from
> invoking release() while holding the switch lock. No such extra
> reference is taken when the ref is already in atomic mode.
>
> My codex agent suggested the following fix:
[Severity: High]
The commit message is missing a Signed-off-by: trailer, and it still
contains email greeting and lead-in text ("Hi,", "My codex agent
suggested the following fix:") instead of a formatted changelog.
[Severity: Low]
Since this fixes the recursive percpu_ref_switch_lock acquisition between
percpu_ref_kill_and_confirm() and percpu_ref_exit(), should it include:
Fixes: 33e465ce7cb3 ("percpu_ref: allow operation mode switching operations to be called concurrently")
Fixes: 2b0d3d3e4fcf ("percpu_ref: reduce memory footprint of percpu_ref in fast path")
--
Sashiko AI review · https://sashiko.dev/#/patchset/c94764bc-a8c9-4771-a649-ccebded0844e@gmail.com?part=1
prev parent reply other threads:[~2026-12-01 16:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 16:47 [RFC] percpu_ref: deadlock when release calls exit on an atomic ref Egor Shalashnov
2026-12-01 16:48 ` sashiko-bot [this message]
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-243736@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=cl@gentwo.org \
--cc=dennis@kernel.org \
--cc=linux-mm@kvack.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shalasheg@gmail.com \
--cc=tj@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 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.