[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250805111036.130121-4-christian.loehle@arm.com>
Date: Tue, 5 Aug 2025 12:10:36 +0100
From: Christian Loehle <christian.loehle@....com>
To: tj@...nel.org,
arighi@...dia.com,
void@...ifault.com
Cc: linux-kernel@...r.kernel.org,
sched-ext@...ts.linux.dev,
changwoo@...lia.com,
hodgesd@...a.com,
mingo@...hat.com,
peterz@...radead.org,
Christian Loehle <christian.loehle@....com>
Subject: [PATCH v3 3/3] sched_ext: Guarantee rq lock on scx_bpf_cpu_rq()
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() if we hold rq lock of that rq.
All upstream scx schedulers can be converted into the new
scx_bpf_task_acquire_remote_curr() instead.
Signed-off-by: Christian Loehle <christian.loehle@....com>
---
kernel/sched/ext.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 3e2fa0b1eb57..a66cf654f33e 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -7420,10 +7420,20 @@ __bpf_kfunc s32 scx_bpf_task_cpu(const struct task_struct *p)
*/
__bpf_kfunc struct rq *scx_bpf_cpu_rq(s32 cpu)
{
+ struct rq *rq;
+
if (!kf_cpu_valid(cpu, NULL))
return NULL;
- return cpu_rq(cpu);
+ preempt_disable();
+ rq = cpu_rq(cpu);
+ if (rq != scx_locked_rq()) {
+ scx_kf_error("Accessing not locked rq %d", cpu);
+ rq = NULL;
+ }
+ preempt_enable();
+
+ return rq;
}
/**
--
2.34.1
Powered by blists - more mailing lists