From: Christian Loehle <christian.loehle@arm.com>
To: Andrea Righi <arighi@nvidia.com>
Cc: linux-kernel@vger.kernel.org, sched-ext@lists.linux.dev,
tj@kernel.org, void@manifault.com, mingo@redhat.com,
peterz@infradead.org
Subject: Re: [PATCH 3/3] sched_ext: Guarantee rq lock on scx_bpf_cpu_rq()
Date: Fri, 1 Aug 2025 15:54:34 +0100 [thread overview]
Message-ID: <cb977466-ad2d-48af-b388-b3c55a5169e2@arm.com> (raw)
In-Reply-To: <aIzUX4d0KRXI4E8O@gpd4>
On 8/1/25 15:51, Andrea Righi wrote:
> On Fri, Aug 01, 2025 at 03:17:41PM +0100, Christian Loehle wrote:
>> Most fields in scx_bpf_cpu_rq() assume that its rq_lock is held.
>> Furthermore they become meaningless without rq lock, too.
>> Only return scx_bpf_cpu_rq() when we hold rq lock of that rq.
>>
>> All upstream scx schedulers can be converted into the new
>> scx_bpf_remote_curr() instead.
>>
>> Signed-off-by: Christian Loehle <christian.loehle@arm.com>
>> ---
>> kernel/sched/ext.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
>> index 92e66bb0b5f2..627df3088fd0 100644
>> --- a/kernel/sched/ext.c
>> +++ b/kernel/sched/ext.c
>> @@ -7425,7 +7425,7 @@ __bpf_kfunc s32 scx_bpf_task_cpu(const struct task_struct *p)
>> }
>>
>> /**
>> - * scx_bpf_cpu_rq - Fetch the rq of a CPU
>> + * scx_bpf_cpu_rq - Fetch the rq of a CPU if its rq lock is currently held
>> * @cpu: CPU of the rq
>> */
>> __bpf_kfunc struct rq *scx_bpf_cpu_rq(s32 cpu)
>> @@ -7433,7 +7433,7 @@ __bpf_kfunc struct rq *scx_bpf_cpu_rq(s32 cpu)
>> if (!kf_cpu_valid(cpu, NULL))
>> return NULL;
>>
>> - return cpu_rq(cpu);
>> + return this_cpu_read(locked_rq) == cpu_rq(cpu) ? cpu_rq(cpu) : NULL;
>
> Maybe we should consider an access to an unlocked rq as invalid and trigger
> scx_exit(), similar to what we do with the kf_cpu_valid() check?
Makes sense to me!
>
> Also heads up that locked_rq has been renamed scx_locked_rq_state in 6.17.
Ah, thanks! I'll rebase!
next prev parent reply other threads:[~2025-08-01 14:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-01 14:17 [PATCH 0/3] sched_ext: Harden scx_bpf_cpu_rq() Christian Loehle
2025-08-01 14:17 ` [PATCH 1/3] sched_ext: Mark scx_bpf_cpu_rq as NULL returnable Christian Loehle
2025-08-01 14:17 ` [PATCH 2/3] sched_ext: Provide scx_bpf_remote_curr() Christian Loehle
2025-08-01 14:47 ` Andrea Righi
2025-08-01 14:58 ` Christian Loehle
2025-08-01 14:17 ` [PATCH 3/3] sched_ext: Guarantee rq lock on scx_bpf_cpu_rq() Christian Loehle
2025-08-01 14:51 ` Andrea Righi
2025-08-01 14:54 ` Christian Loehle [this message]
2025-08-01 14:39 ` [PATCH 0/3] sched_ext: Harden scx_bpf_cpu_rq() Andrea Righi
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=cb977466-ad2d-48af-b388-b3c55a5169e2@arm.com \
--to=christian.loehle@arm.com \
--cc=arighi@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=sched-ext@lists.linux.dev \
--cc=tj@kernel.org \
--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®