[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250801141741.355059-4-christian.loehle@arm.com>
Date: Fri, 1 Aug 2025 15:17:41 +0100
From: Christian Loehle <christian.loehle@....com>
To: christian.loehle@....com,
linux-kernel@...r.kernel.org,
sched-ext@...ts.linux.dev,
tj@...nel.org,
void@...ifault.com,
arighi@...dia.com
Cc: mingo@...hat.com,
peterz@...radead.org
Subject: [PATCH 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() 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@....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;
}
/**
--
2.34.1
Powered by blists - more mailing lists