Linux-mediatek Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kernel/watchdog_hld.c: Fix access percpu in preemptible context
@ 2020-12-17 13:06 Lecopzer Chen
  2020-12-19 13:59 ` [kernel/watchdog_hld.c] 6e37d53a67: BUG:sleeping_function_called_from_invalid_context_at_include/linux/sched/mm.h kernel test robot
  0 siblings, 1 reply; 4+ messages in thread
From: Lecopzer Chen @ 2020-12-17 13:06 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel
  Cc: sumit.garg, Lecopzer Chen, will, yj.chiang, linux-mediatek,
	matthias.bgg, alexandru.elisei

commit 367c820ef08082 ("arm64: Enable perf events based hard lockup detector")
reinitilizes lockup detector after arm64 PMU is initialized and provide
another chance for access smp_processor_id() in preemptible context.
Since hardlockup_detector_event_create() use many percpu relative variable,
just try to fix this by get/put_cpu()

    BUG: using smp_processor_id() in preemptible [00000000] code: swapper/0/1
    caller is debug_smp_processor_id+0x20/0x2c
    CPU: 2 PID: 1 Comm: swapper/0 Not tainted 5.10.0+ #276
    Hardware name: linux,dummy-virt (DT)
    Call trace:
      dump_backtrace+0x0/0x3c0
      show_stack+0x20/0x6c
      dump_stack+0x2f0/0x42c
      check_preemption_disabled+0x1cc/0x1dc
      debug_smp_processor_id+0x20/0x2c
      hardlockup_detector_event_create+0x34/0x18c
      hardlockup_detector_perf_init+0x2c/0x134
      watchdog_nmi_probe+0x18/0x24
      lockup_detector_init+0x44/0xa8
      armv8_pmu_driver_init+0x54/0x78
      do_one_initcall+0x184/0x43c
      kernel_init_freeable+0x368/0x380
      kernel_init+0x1c/0x1cc
      ret_from_fork+0x10/0x30


Fixes: 367c820ef08082 ("arm64: Enable perf events based hard lockup detector")
Signed-off-by: Lecopzer Chen <lecopzer.chen@mediatek.com>
Cc: Sumit Garg <sumit.garg@linaro.org>

---
 kernel/watchdog_hld.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/watchdog_hld.c b/kernel/watchdog_hld.c
index 247bf0b1582c..c591a1ea8eb3 100644
--- a/kernel/watchdog_hld.c
+++ b/kernel/watchdog_hld.c
@@ -165,7 +165,7 @@ static void watchdog_overflow_callback(struct perf_event *event,
 
 static int hardlockup_detector_event_create(void)
 {
-	unsigned int cpu = smp_processor_id();
+	unsigned int cpu = get_cpu();
 	struct perf_event_attr *wd_attr;
 	struct perf_event *evt;
 
@@ -176,11 +176,13 @@ static int hardlockup_detector_event_create(void)
 	evt = perf_event_create_kernel_counter(wd_attr, cpu, NULL,
 					       watchdog_overflow_callback, NULL);
 	if (IS_ERR(evt)) {
+		put_cpu();
 		pr_debug("Perf event create on CPU %d failed with %ld\n", cpu,
 			 PTR_ERR(evt));
 		return PTR_ERR(evt);
 	}
 	this_cpu_write(watchdog_ev, evt);
+	put_cpu();
 	return 0;
 }
 
-- 
2.25.1
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-12-19 15:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-17 13:06 [PATCH] kernel/watchdog_hld.c: Fix access percpu in preemptible context Lecopzer Chen
2020-12-19 13:59 ` [kernel/watchdog_hld.c] 6e37d53a67: BUG:sleeping_function_called_from_invalid_context_at_include/linux/sched/mm.h kernel test robot
2020-12-19 15:02   ` [PATCH] kernel/watchdog_hld.c: Fix access percpu in preemptible context Lecopzer Chen
2020-12-19 15:04   ` Lecopzer Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox