From: Tejun Heo <tj@kernel.org>
To: Wanwu Li <liwanwu@kylinos.cn>
Cc: David Vernet <void@manifault.com>,
Andrea Righi <arighi@nvidia.com>,
Changwoo Min <changwoo@igalia.com>,
Emil Tsalapatis <emil@etsalapatis.com>,
sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] sched_ext: Reject NMI calls to lock-taking kfuncs
Date: Tue, 01 Sep 2026 11:16:00 -1000 [thread overview]
Message-ID: <3a9bfba228c46c69408fe1ef392e60f0@kernel.org> (raw)
In-Reply-To: <20260901095652.1009104-1-liwanwu@kylinos.cn>
Hello,
On Tue, Sep 01, 2026 at 05:56:52PM +0800, Wanwu Li wrote:
> + if (!scx_kfunc_nmi_safe(__func__, sch))
> + return -EBUSY;
The return value doesn't matter much as the scheduler is being terminated.
Whatever it is, use the same one everywhere. -EBUSY suggests retrying would
help. Let's use -EDEADLK which is what's being avoided.
> +/*
> + * sched_ext kfuncs that take scheduler locks are not NMI-safe: a
> + * BPF_PROG_TYPE_TRACING program can be attached to a function that runs in
> + * NMI, and scx_kfunc_context_filter() lets such a program call every kfunc in
> + * the any/cid/idle sets. Acquiring the rq, dsq or pshard raw spinlocks - or
> + * touching the irq-masking-only kick list - from NMI while the interrupted
> + * context on the same CPU already holds them deadlocks (or corrupts) it.
> + * scx_bpf_kick_cpu() was the first guard; route all of them through here.
> + *
> + * Returns true when the caller may proceed, false when running from NMI and
> + * the kfunc must bail without touching locks. scx_error() is NMI-safe (see the
> + * lock-free ->aborting claim).
> + */
Too long. Something like:
/*
* Tracing progs can call kfuncs from NMI. Kfuncs that take scheduler locks or
* touch the kick lists, which are only protected by irq masking, can't run
* there, so abort the scheduler instead. scx_error() is NMI-safe.
*/
> +static inline bool scx_kfunc_nmi_safe(const char *who, struct scx_sched *sch)
scx_kfunc_nmi_safe() reads as if it's testing a property of the kfunc. Let's
call it scx_kf_allowed_ctx() to match scx_kf_allowed(). Also, instead of
passing @who from each call site, make it a macro wrapper which passes
__func__ to the inline function.
Thanks.
--
tejun
next prev parent reply other threads:[~2026-09-01 21:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-01 9:56 Wanwu Li
2026-09-01 19:51 ` Andrea Righi
2026-09-01 20:13 ` Tejun Heo
2026-09-01 20:28 ` Andrea Righi
2026-09-01 21:16 ` Tejun Heo [this message]
2026-09-02 2:31 ` [PATCH v2] " Wanwu Li
2026-09-02 6:44 ` Tejun Heo
2026-09-02 9:36 ` [PATCH v3] " Wanwu Li
2026-09-02 23:05 ` Tejun Heo
2026-09-03 1:46 ` liwanwu
2026-09-02 13:48 ` [PATCH v2] " liwanwu
2026-09-02 21:51 ` Tejun Heo
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=3a9bfba228c46c69408fe1ef392e60f0@kernel.org \
--to=tj@kernel.org \
--cc=arighi@nvidia.com \
--cc=changwoo@igalia.com \
--cc=emil@etsalapatis.com \
--cc=linux-kernel@vger.kernel.org \
--cc=liwanwu@kylinos.cn \
--cc=sched-ext@lists.linux.dev \
--cc=void@manifault.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®