public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/smpboot: Add map vars allocation check in smp_prepare_cpus_common
@ 2024-04-09 18:29 Nikita Kiryushin
  2024-04-10 13:30 ` Ingo Molnar
  0 siblings, 1 reply; 4+ messages in thread
From: Nikita Kiryushin @ 2024-04-09 18:29 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Nikita Kiryushin, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Peter Zijlstra, Ashok Raj, David Woodhouse,
	linux-kernel, lvc-project

As of now, zalloc_cpumask_var for various maps in smp_prepare_cpus_common
is not checked.

If allocation fails, it will not be known, unless the not-allocated map
will be accessed. The situation seems not very realistic now, but could
get more relevant in the future, as number of cores (and amount of
allocated resources) grows.

Add a cumulative status for all zalloc_cpumask_var() calls in
smp_prepare_cpus_common() and error message in case the status signals
that any of the map var allocations failed (per cpu).

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Nikita Kiryushin <kiryushin@ancud.ru>
---
 arch/x86/kernel/smpboot.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 76bb65045c64..3b24c2e1fa3b 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -1042,11 +1042,16 @@ void __init smp_prepare_cpus_common(void)
 	}
 
 	for_each_possible_cpu(i) {
-		zalloc_cpumask_var(&per_cpu(cpu_sibling_map, i), GFP_KERNEL);
-		zalloc_cpumask_var(&per_cpu(cpu_core_map, i), GFP_KERNEL);
-		zalloc_cpumask_var(&per_cpu(cpu_die_map, i), GFP_KERNEL);
-		zalloc_cpumask_var(&per_cpu(cpu_llc_shared_map, i), GFP_KERNEL);
-		zalloc_cpumask_var(&per_cpu(cpu_l2c_shared_map, i), GFP_KERNEL);
+		bool ret = true;
+
+		ret &= zalloc_cpumask_var(&per_cpu(cpu_sibling_map, i), GFP_KERNEL);
+		ret &= zalloc_cpumask_var(&per_cpu(cpu_core_map, i), GFP_KERNEL);
+		ret &= zalloc_cpumask_var(&per_cpu(cpu_die_map, i), GFP_KERNEL);
+		ret &= zalloc_cpumask_var(&per_cpu(cpu_llc_shared_map, i), GFP_KERNEL);
+		ret &= zalloc_cpumask_var(&per_cpu(cpu_l2c_shared_map, i), GFP_KERNEL);
+
+		if (!ret)
+			pr_err("Failed to allocate map for CPU%u\n", i);
 	}
 
 	set_cpu_sibling_map(0);
-- 
2.34.1


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

end of thread, other threads:[~2024-04-11  8:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-09 18:29 [PATCH] x86/smpboot: Add map vars allocation check in smp_prepare_cpus_common Nikita Kiryushin
2024-04-10 13:30 ` Ingo Molnar
2024-04-10 18:00   ` Nikita Kiryushin
2024-04-11  8:43     ` Ingo Molnar

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