mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nikita Kiryushin <kiryushin@ancud.ru>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Nikita Kiryushin <kiryushin@ancud.ru>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ashok Raj <ashok.raj@intel.com>,
	David Woodhouse <dwmw@amazon.co.uk>,
	linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org
Subject: [PATCH] x86/smpboot: Add map vars allocation check in smp_prepare_cpus_common
Date: Tue,  9 Apr 2024 21:29:39 +0300	[thread overview]
Message-ID: <20240409182940.664482-1-kiryushin@ancud.ru> (raw)

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


             reply	other threads:[~2024-04-09 18:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-09 18:29 Nikita Kiryushin [this message]
2024-04-10 13:30 ` Ingo Molnar
2024-04-10 18:00   ` Nikita Kiryushin
2024-04-11  8:43     ` Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240409182940.664482-1-kiryushin@ancud.ru \
    --to=kiryushin@ancud.ru \
    --cc=ashok.raj@intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dwmw@amazon.co.uk \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®