[PATCH] openrisc: cacheinfo: Index cpuinfo_or1k by target cpu

From: Karl Mehltretter

Date: Sat Nov 07 2026 - 14:59:02 EST


init_cache_level() and populate_cache_leaves() take a target cpu
parameter, pass it to get_cpu_cacheinfo(), and then index cpuinfo_or1k
with smp_processor_id(). On UP kernels with PREEMPT and DEBUG_PREEMPT
enabled, cacheinfo_sysfs_init() invokes init_cache_level() from the
preemptible swapper/0 thread via cpuhp_setup_state(), triggering a
debug_smp_processor_id() diagnostic.

Index cpuinfo_or1k with cpu in both functions.

Fixes: 4e6d24a309e6 ("openrisc: Add cacheinfo support")
Signed-off-by: Karl Mehltretter <kmehltretter@xxxxxxxxx>
---
Assisted by an LLM.

Tested on v7.4-rc1 (d48723711bae) under QEMU or1k (or1k-sim) with
or1ksim_defconfig plus PREEMPT and DEBUG_PREEMPT. Without this patch,
two consecutive boots emit "BUG: using smp_processor_id() in
preemptible [00000000] code: swapper/0/1" at init_cache_level+0x28/0x1f4.
With this patch, two consecutive boots complete without the
debug_smp_processor_id() diagnostic.

arch/openrisc/kernel/cacheinfo.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/openrisc/kernel/cacheinfo.c b/arch/openrisc/kernel/cacheinfo.c
index 61230545e4ff6..7c2c38beecd99 100644
--- a/arch/openrisc/kernel/cacheinfo.c
+++ b/arch/openrisc/kernel/cacheinfo.c
@@ -28,7 +28,7 @@ static inline void ci_leaf_init(struct cacheinfo *this_leaf, enum cache_type typ

int init_cache_level(unsigned int cpu)
{
- struct cpuinfo_or1k *cpuinfo = &cpuinfo_or1k[smp_processor_id()];
+ struct cpuinfo_or1k *cpuinfo = &cpuinfo_or1k[cpu];
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
int leaves = 0, levels = 0;
unsigned long upr = mfspr(SPR_UPR);
@@ -83,7 +83,7 @@ int init_cache_level(unsigned int cpu)

int populate_cache_leaves(unsigned int cpu)
{
- struct cpuinfo_or1k *cpuinfo = &cpuinfo_or1k[smp_processor_id()];
+ struct cpuinfo_or1k *cpuinfo = &cpuinfo_or1k[cpu];
struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
struct cacheinfo *this_leaf = this_cpu_ci->info_list;
int level = 1;
base-commit: d48723711bae9b8cdc56719c448ba42fef28cbee

--
2.39.5 (Apple Git-154)