All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Karl Mehltretter" <kmehltretter@gmail.com>
Cc: linux-rt-devel@lists.linux.dev, linux-kernel@vger.kernel.org,
	bpf@vger.kernel.org
Subject: Re: [RFC PATCH] mm: restrict can_spin_trylock() to preemptible context on PREEMPT_RT
Date: Sat, 19 Sep 2026 17:24:35 +0000	[thread overview]
Message-ID: <20260919172435.B78C61F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260919171443.90512-1-kmehltretter@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] mm: can_spin_trylock() uses !preemptible() causing persistent bailout
--

commit da2bda4aca43320be916d709a95e77705d7bd75f
Author: Karl Mehltretter <kmehltretter@gmail.com>

mm: restrict can_spin_trylock() to preemptible context on PREEMPT_RT

This patch resolves a deadlock on PREEMPT_RT during kmalloc_nolock() by
restricting can_spin_trylock() to preemptible contexts only. It prevents
nested lock acquisition of the pi_lock when called from sched_waking
tracepoints inside try_to_wake_up().

> diff --git a/mm/internal.h b/mm/internal.h
> --- a/mm/internal.h
> +++ b/mm/internal.h
[ ... ]
> @@ -1641,10 +1641,14 @@ static inline bool can_spin_trylock(void)
>  	 * confuse PI logic, so return immediately if called from hard IRQ or
>  	 * NMI.
>  	 *
> -	 * Note, irqs_disabled() case is ok. spin_trylock() can be called
> -	 * from raw_spin_lock_irqsave region.
> +	 * Task context with a raw spinlock held is not safe either. The
> +	 * caller may hold a pi_lock, like a BPF program on a tracepoint in
> +	 * try_to_wake_up(). rt_spin_trylock() takes the rtmutex wait_lock
> +	 * and can take a pi_lock under it. rt_spin_unlock() wakes a waiter
> +	 * if there is one, which takes a pi_lock again. The locks held by
> +	 * the caller are not known here, so allow preemptible context only.
>  	 */
> -	if (IS_ENABLED(CONFIG_PREEMPT_RT) && (in_nmi() || in_hardirq()))
> +	if (IS_ENABLED(CONFIG_PREEMPT_RT) && !preemptible())

[Severity: Medium]
Does this !preemptible() check create a persistent bailout for ALLOC_TRYLOCK
paths on PREEMPT_RT?

BPF programs attached to non-faultable tracepoints run with preemption
disabled via guard(preempt_notrace). When they attempt to create task local
storage using kmalloc_nolock(), it calls can_spin_trylock().

Because preemption is always disabled inside the tracepoint, this check
acts as a persistent bailout rather than a transient one, unconditionally
failing the allocation on PREEMPT_RT. Will this permanently break BPF task
storage creation in tracepoints on PREEMPT_RT?

>  		return false;
>  
>  	/* On UP, spin_trylock() always succeeds even when it is locked */

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260919171443.90512-1-kmehltretter@gmail.com?part=1

  reply	other threads:[~2026-09-19 17:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-19 17:14 [RFC PATCH] mm: restrict can_spin_trylock() to preemptible context on PREEMPT_RT Karl Mehltretter
2026-09-19 17:24 ` sashiko-bot [this message]
2026-09-19 18:17 ` Alexei Starovoitov
2026-09-22  6:04   ` Karl Mehltretter
2026-09-25  4:12     ` Alexei Starovoitov
2026-09-25  7:29       ` Vlastimil Babka (SUSE)
2026-09-25 11:05         ` Harry Yoo
2026-09-25 14:31           ` Sebastian Andrzej Siewior

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=20260919172435.B78C61F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=kmehltretter@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.