linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] vmstat: disable vmstat_work on vmstat_cpu_down_prep()
@ 2024-12-21  3:33 Koichiro Den
  2025-01-03 23:33 ` Lorenzo Stoakes
  0 siblings, 1 reply; 22+ messages in thread
From: Koichiro Den @ 2024-12-21  3:33 UTC (permalink / raw)
  To: linux-mm; +Cc: akpm, linux-kernel

Even after mm/vmstat:online teardown, shepherd may still queue work for
the dying cpu until the cpu is removed from online mask. While it's
quite rare, this means that after unbind_workers() unbinds a per-cpu
kworker, it potentially runs vmstat_update for the dying CPU on an
irrelevant cpu before entering atomic AP states.
When CONFIG_DEBUG_PREEMPT=y, it results in the following error with the
backtrace.

  BUG: using smp_processor_id() in preemptible [00000000] code: \
                                               kworker/7:3/1702
  caller is refresh_cpu_vm_stats+0x235/0x5f0
  CPU: 0 UID: 0 PID: 1702 Comm: kworker/7:3 Tainted: G
  Tainted: [N]=TEST
  Workqueue: mm_percpu_wq vmstat_update
  Call Trace:
   <TASK>
   dump_stack_lvl+0x8d/0xb0
   check_preemption_disabled+0xce/0xe0
   refresh_cpu_vm_stats+0x235/0x5f0
   vmstat_update+0x17/0xa0
   process_one_work+0x869/0x1aa0
   worker_thread+0x5e5/0x1100
   kthread+0x29e/0x380
   ret_from_fork+0x2d/0x70
   ret_from_fork_asm+0x1a/0x30
   </TASK>

So, for mm/vmstat:online, disable vmstat_work reliably on teardown and
symmetrically enable it on startup.

Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
---
v1: https://lore.kernel.org/all/20241220134234.3809621-1-koichiro.den@canonical.com/
---
 mm/vmstat.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/vmstat.c b/mm/vmstat.c
index 4d016314a56c..0889b75cef14 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -2148,13 +2148,14 @@ static int vmstat_cpu_online(unsigned int cpu)
 	if (!node_state(cpu_to_node(cpu), N_CPU)) {
 		node_set_state(cpu_to_node(cpu), N_CPU);
 	}
+	enable_delayed_work(&per_cpu(vmstat_work, cpu));
 
 	return 0;
 }
 
 static int vmstat_cpu_down_prep(unsigned int cpu)
 {
-	cancel_delayed_work_sync(&per_cpu(vmstat_work, cpu));
+	disable_delayed_work_sync(&per_cpu(vmstat_work, cpu));
 	return 0;
 }
 
-- 
2.43.0



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

end of thread, other threads:[~2025-01-08  3:58 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-21  3:33 [PATCH v2] vmstat: disable vmstat_work on vmstat_cpu_down_prep() Koichiro Den
2025-01-03 23:33 ` Lorenzo Stoakes
2025-01-04  4:00   ` Koichiro Den
2025-01-06  2:18     ` Charalampos Mitrodimas
2025-01-06 10:04     ` Mark Rutland
2025-01-06 10:18     ` Geert Uytterhoeven
2025-01-06 10:52     ` Lorenzo Stoakes
2025-01-06 12:53       ` Charalampos Mitrodimas
2025-01-06 12:58         ` Lorenzo Stoakes
2025-01-06 13:03       ` Koichiro Den
2025-01-06 13:53         ` Koichiro Den
2025-01-07  1:18         ` [PATCH] Simple fix Huacai Chen
2025-01-07  3:35           ` Matthew Wilcox
2025-01-07  3:58             ` Huacai Chen
2025-01-07  8:47           ` Lorenzo Stoakes
2025-01-07 10:29             ` Huacai Chen
2025-01-07 11:00               ` Lorenzo Stoakes
2025-01-08  2:22                 ` Koichiro Den
2025-01-08  2:26                   ` Koichiro Den
2025-01-08  2:31                   ` Huacai Chen
2025-01-08  3:41                     ` Koichiro Den
2025-01-08  3:57                       ` Huacai Chen

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