[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAP01T75_tsZoGX0SghGtO5V6LJOkDEMDcocWHZwoOpXmS7cK9w@mail.gmail.com>
Date: Tue, 23 Sep 2025 12:38:26 +0200
From: Kumar Kartikeya Dwivedi <memxor@...il.com>
To: Andrea Righi <arighi@...dia.com>
Cc: Tejun Heo <tj@...nel.org>, David Vernet <void@...ifault.com>,
Changwoo Min <changwoo@...lia.com>, Christian Loehle <christian.loehle@....com>,
sched-ext@...ts.linux.dev, bpf@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] sched_ext: Verify RCU protection in scx_bpf_cpu_curr()
On Tue, 23 Sept 2025 at 11:16, Andrea Righi <arighi@...dia.com> wrote:
>
> scx_bpf_cpu_curr() has been introduced to retrieve the current task of a
> given runqueue, allowing schedulers to interact with that task.
>
> The kfunc assumes that it is always called in an RCU context, but this
> is not always guaranteed and some BPF schedulers can trigger the
> following warning:
>
> WARNING: suspicious RCU usage
> sched_ext: BPF scheduler "cosmos_1.0.2_gd0e71ca_x86_64_unknown_linux_gnu_debug" enabled
> 6.17.0-rc1 #1-NixOS Not tainted
> -----------------------------
> kernel/sched/ext.c:6415 suspicious rcu_dereference_check() usage!
> ...
> Call Trace:
> <IRQ>
> dump_stack_lvl+0x6f/0xb0
> lockdep_rcu_suspicious.cold+0x4e/0x96
> scx_bpf_cpu_curr+0x7e/0x80
> bpf_prog_c68b2b6b6b1b0ff8_sched_timerfn+0xce/0x1dc
> bpf_timer_cb+0x7b/0x130
> __hrtimer_run_queues+0x1ea/0x380
> hrtimer_run_softirq+0x8c/0xd0
> handle_softirqs+0xc9/0x3b0
> __irq_exit_rcu+0x96/0xc0
> irq_exit_rcu+0xe/0x20
> sysvec_apic_timer_interrupt+0x73/0x80
> </IRQ>
> <TASK>
>
> To address this, mark the kfunc with KF_RCU_PROTECTED, so the verifier
> can enforce its usage only inside RCU-protected sections.
>
> Note: this also requires commit 1512231b6cc86 ("bpf: Enforce RCU protection
> for KF_RCU_PROTECTED"), currently in bpf-next, to enforce the proper
> KF_RCU_PROTECTED.
>
> Fixes: 20b158094a1ad ("sched_ext: Introduce scx_bpf_cpu_curr()")
> Cc: Christian Loehle <christian.loehle@....com>
> Cc: Kumar Kartikeya Dwivedi <memxor@...il.com>
> Signed-off-by: Andrea Righi <arighi@...dia.com>
> ---
Acked-by: Kumar Kartikeya Dwivedi <memxor@...il.com>
Powered by blists - more mailing lists