Skip to contentSkip to conversation

riscv: cacheinfo: Fix using smp_processor_id() in preemptible

PATCH In review Kefeng Wang 3 participants 4 messages Dec 22, 2020 – Jan 13, 2021 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 riscv: cacheinfo: Fix using smp_processor_id() in preemptible

Use raw_smp_processor_id instead of smp_processor_id() to fix warning,

BUG: using smp_processor_id() in preemptible [00000000] code: init/1
caller is debug_smp_processor_id+0x1c/0x26
CPU: 0 PID: 1 Comm: init Not tainted 5.10.0-rc4 #211
Call Trace:
  walk_stackframe+0x0/0xaa
  show_stack+0x32/0x3e
  dump_stack+0x76/0x90
  check_preemption_disabled+0xaa/0xac
  debug_smp_processor_id+0x1c/0x26
  get_cache_size+0x18/0x68
  load_elf_binary+0x868/0xece
  bprm_execve+0x224/0x498
  kernel_execve+0xdc/0x142
  run_init_process+0x90/0x9e
  try_to_run_init_process+0x12/0x3c
  kernel_init+0xb4/0xf8
  ret_from_exception+0x0/0xc

The issue is found when CONFIG_DEBUG_PREEMPT enabled.

---
 arch/riscv/kernel/cacheinfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/cacheinfo.c +1 -1
index de59dd457b41..9b5a8a347434 100644
@@ -26,7 +26,7 @@ cache_get_priv_group(struct cacheinfo *this_leaf)
 
 static struct cacheinfo *get_cacheinfo(u32 level, enum cache_type type)
 {
-	struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(smp_processor_id());
+	struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(raw_smp_processor_id());
 	struct cacheinfo *this_leaf;
 	int index;
 
Signature · 7 lines
2.26.2


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#1 lore raw
Quoted 21 lines · Kefeng Wang

Use raw_smp_processor_id instead of smp_processor_id() to fix warning,

BUG: using smp_processor_id() in preemptible [00000000] code: init/1
caller is debug_smp_processor_id+0x1c/0x26
CPU: 0 PID: 1 Comm: init Not tainted 5.10.0-rc4 #211
Call Trace:
  walk_stackframe+0x0/0xaa
  show_stack+0x32/0x3e
  dump_stack+0x76/0x90
  check_preemption_disabled+0xaa/0xac
  debug_smp_processor_id+0x1c/0x26
  get_cache_size+0x18/0x68
  load_elf_binary+0x868/0xece
  bprm_execve+0x224/0x498
  kernel_execve+0xdc/0x142
  run_init_process+0x90/0x9e
  try_to_run_init_process+0x12/0x3c
  kernel_init+0xb4/0xf8
  ret_from_exception+0x0/0xc
Quoted 1 line

The issue is found when CONFIG_DEBUG_PREEMPT enabled.

The warning sounds legitimate.

arch/riscv/kernel/cacheinfo.c cache_get_priv_group(struct cacheinfo *this_leaf) · line 29

Quoted 4 lines

static struct cacheinfo *get_cacheinfo(u32 level, enum cache_type type) {

arch/riscv/kernel/cacheinfo.c +1 -1
-       struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(smp_processor_id());
+       struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(raw_smp_processor_id());

And this just hides the warning if someone calls this function without disabling preemption first.

If you cannot use the normal get_cpu()/put_cpu() interfaces or the cacheinfo of the boot CPU, maybe add a comment to explain why raw_smp_processor_id() is necessary here.

Arnd

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#2 lore raw
Quoted 31 lines · On Tue, 22 Dec 2020 08:23:06 PST (-0800), [email protected] wrote:
Quoted 21 lines · Kefeng Wang

Use raw_smp_processor_id instead of smp_processor_id() to fix warning,

BUG: using smp_processor_id() in preemptible [00000000] code: init/1
caller is debug_smp_processor_id+0x1c/0x26
CPU: 0 PID: 1 Comm: init Not tainted 5.10.0-rc4 #211
Call Trace:
  walk_stackframe+0x0/0xaa
  show_stack+0x32/0x3e
  dump_stack+0x76/0x90
  check_preemption_disabled+0xaa/0xac
  debug_smp_processor_id+0x1c/0x26
  get_cache_size+0x18/0x68
  load_elf_binary+0x868/0xece
  bprm_execve+0x224/0x498
  kernel_execve+0xdc/0x142
  run_init_process+0x90/0x9e
  try_to_run_init_process+0x12/0x3c
  kernel_init+0xb4/0xf8
  ret_from_exception+0x0/0xc
Quoted 1 line

The issue is found when CONFIG_DEBUG_PREEMPT enabled.

The warning sounds legitimate.

arch/riscv/kernel/cacheinfo.c cache_get_priv_group(struct cacheinfo *this_leaf) · line 29

Quoted 4 lines

static struct cacheinfo *get_cacheinfo(u32 level, enum cache_type type) {

arch/riscv/kernel/cacheinfo.c +1 -1
-       struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(smp_processor_id());
+       struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(raw_smp_processor_id());
Quoted 6 lines

And this just hides the warning if someone calls this function without disabling preemption first.

If you cannot use the normal get_cpu()/put_cpu() interfaces or the cacheinfo of the boot CPU, maybe add a comment to explain why raw_smp_processor_id() is necessary here.

The problem is actually bigger: the interface we're using to provide this information to userspace just assumes there's a homogeneous cache hierarchy (and a fixed number of levels). There's nothing we can do with the hart ID to fix that, so at a bare minimum we need some mechanism to stop providing this information when it can't be accurate. That would likely sort out this issue as well, as we wouldn't be coupling this to the current processor ID.

That said, I'm somewhat inclined to take this (or something like it), as the warning is somewhat noisy and the real problem is something different. We probably need a new interface at some point, but we don't have any systems that violate the current one so it's not likely to be all that high priority.

Certainly warrants a comment, though (and I also had mine just using a static hart id, so at least users get deterministic results).

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#3 lore raw
In reply to Kefeng Wang
Quoted 34 lines · On Tue, 22 Dec 2020 08:01:52 PST (-0800), [email protected] wrote:

Use raw_smp_processor_id instead of smp_processor_id() to fix warning,

BUG: using smp_processor_id() in preemptible [00000000] code: init/1
caller is debug_smp_processor_id+0x1c/0x26
CPU: 0 PID: 1 Comm: init Not tainted 5.10.0-rc4 #211
Call Trace:
  walk_stackframe+0x0/0xaa
  show_stack+0x32/0x3e
  dump_stack+0x76/0x90
  check_preemption_disabled+0xaa/0xac
  debug_smp_processor_id+0x1c/0x26
  get_cache_size+0x18/0x68
  load_elf_binary+0x868/0xece
  bprm_execve+0x224/0x498
  kernel_execve+0xdc/0x142
  run_init_process+0x90/0x9e
  try_to_run_init_process+0x12/0x3c
  kernel_init+0xb4/0xf8
  ret_from_exception+0x0/0xc

The issue is found when CONFIG_DEBUG_PREEMPT enabled.

---
 arch/riscv/kernel/cacheinfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/cacheinfo.c +0 -0
index de59dd457b41..9b5a8a347434 100644

arch/riscv/kernel/cacheinfo.c cache_get_priv_group(struct cacheinfo *this_leaf) · line 31

Quoted 7 lines
arch/riscv/kernel/cacheinfo.c +1 -1
@@ -26,7 +26,7 @@ cache_get_priv_group(struct cacheinfo *this_leaf)
 
 static struct cacheinfo *get_cacheinfo(u32 level, enum cache_type type)
 {
-	struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(smp_processor_id());
+	struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(raw_smp_processor_id());
 	struct cacheinfo *this_leaf;
 	int index;

Thanks, this is on fixes with a comment about why we need the raw_.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv