All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: x86@kernel.org, Guenter Roeck <linux@roeck-us.net>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [patch 3/4] x86/topology: Handle the !APIC case gracefully
Date: Fri, 22 Mar 2024 19:56:38 +0100 (CET)	[thread overview]
Message-ID: <20240322185305.242709302@linutronix.de> (raw)
In-Reply-To: 20240322184944.141421692@linutronix.de

If there is no local APIC enumerated and registered then the topology
bitmaps are empty. Therefore topology_init_possible_cpus() will die with a
division by zero exception.

Prevent this by registering a fake APIC id to populate the topology
bitmap. This also allows to use all topology query interfaces
unconditionally. It does not affect the actual APIC code because either the
local APIC address was not registered or no local APIC could be detected.

Fixes: f1f758a80516 ("x86/topology: Add a mechanism to track topology via APIC IDs")
Reported-by: Guenter Roeck <linux@roeck-us.net>
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/kernel/cpu/topology.c |   11 +++++++++++
 1 file changed, 11 insertions(+)

--- a/arch/x86/kernel/cpu/topology.c
+++ b/arch/x86/kernel/cpu/topology.c
@@ -415,6 +415,17 @@ void __init topology_init_possible_cpus(
 	unsigned int total = assigned + disabled;
 	u32 apicid, firstid;
 
+	/*
+	 * If there was no APIC registered, then fake one so that the
+	 * topology bitmap is populated. That ensures that the code below
+	 * is valid and the various query interfaces can be used
+	 * unconditionally. This does not affect the actual APIC code in
+	 * any way because either the local APIC address has not been
+	 * registered or the local APIC was disabled on the command line.
+	 */
+	if (topo_info.boot_cpu_apic_id == BAD_APICID)
+		topology_register_boot_apic(0);
+
 	if (!restrict_to_up()) {
 		if (WARN_ON_ONCE(assigned > nr_cpu_ids)) {
 			disabled += assigned - nr_cpu_ids;


  parent reply	other threads:[~2024-03-22 18:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-22 18:56 [patch 0/4] x86/topology: Cure fallout Thomas Gleixner
2024-03-22 18:56 ` [patch 1/4] x86/cpu: Ensure that CPU info updates are propagated on UP Thomas Gleixner
2024-03-22 21:41   ` Guenter Roeck
2024-03-23 13:24   ` [tip: x86/urgent] " tip-bot2 for Thomas Gleixner
2024-03-22 18:56 ` [patch 2/4] x86/topology: Dont evaluate logical IDs during early boot Thomas Gleixner
2024-03-22 21:41   ` Guenter Roeck
2024-03-23 13:24   ` [tip: x86/urgent] x86/topology: Don't " tip-bot2 for Thomas Gleixner
2024-03-22 18:56 ` Thomas Gleixner [this message]
2024-03-22 21:41   ` [patch 3/4] x86/topology: Handle the !APIC case gracefully Guenter Roeck
2024-03-23 13:24   ` [tip: x86/urgent] " tip-bot2 for Thomas Gleixner
2024-03-22 18:56 ` [patch 4/4] x86/mpparse: Register APIC address only once Thomas Gleixner
2024-03-22 21:41   ` Guenter Roeck
2024-03-23 13:24   ` [tip: x86/urgent] " tip-bot2 for Thomas Gleixner

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=20240322185305.242709302@linutronix.de \
    --to=tglx@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=torvalds@linux-foundation.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.