All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@gmail.com>
To: tglx@linutronix.de
Cc: adobriyan@gmail.com, mingo@redhat.com, bp@alien8.de,
	dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
	linux-kernel@vger.kernel.org, peterz@infradead.org,
	Jonathan.Cameron@huawei.com, linuxarm@huawei.com,
	linux@roeck-us.net,
	Jonathan Cameron <Jonathan.Cameron@Huawei.com>
Subject: [PATCH 1/2] x86/cpu/topology: don't write to immutable cpu_present_mask
Date: Sun,  7 Apr 2024 18:26:43 +0300	[thread overview]
Message-ID: <20240407152643.3245-1-adobriyan@gmail.com> (raw)

Workaround the following oops:

	topology_hotplug_apic
	topo_set_cpuids
		set_cpu_possible(cpu, true);
		// write to __ro_after_init section after init

adobriyan: I'm not sure what's going on, can it set unset bit here?
If not, then why does it repeat the job and set already set bits.

Anyhow, let's not oops peoples' machines for now.

Reported-by: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
Suggested-by: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
 arch/x86/kernel/cpu/topology.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/cpu/topology.c b/arch/x86/kernel/cpu/topology.c
index aaca8d235dc2..42f4a17f8019 100644
--- a/arch/x86/kernel/cpu/topology.c
+++ b/arch/x86/kernel/cpu/topology.c
@@ -117,13 +117,18 @@ static __init int topo_get_cpunr(u32 apic_id)
 	return topo_info.nr_assigned_cpus++;
 }
 
-static void topo_set_cpuids(unsigned int cpu, u32 apic_id, u32 acpi_id)
+static void topo_set_cpuids(unsigned int cpu, u32 apic_id, u32 acpi_id, bool from_init)
 {
 #if defined(CONFIG_SMP) || defined(CONFIG_X86_64)
 	early_per_cpu(x86_cpu_to_apicid, cpu) = apic_id;
 	early_per_cpu(x86_cpu_to_acpiid, cpu) = acpi_id;
 #endif
-	set_cpu_possible(cpu, true);
+	if (from_init) {
+		set_cpu_possible(cpu, true);
+	} else {
+		/* cpu_possible_mask is supposed to be fixed by now. */
+		WARN_ON(!cpumask_test_cpu(cpu, cpu_possible_mask));
+	}
 	set_cpu_present(cpu, true);
 }
 
@@ -191,7 +196,7 @@ static __init void topo_register_apic(u32 apic_id, u32 acpi_id, bool present)
 			cpu = topo_get_cpunr(apic_id);
 
 		cpuid_to_apicid[cpu] = apic_id;
-		topo_set_cpuids(cpu, apic_id, acpi_id);
+		topo_set_cpuids(cpu, apic_id, acpi_id, true);
 	} else {
 		u32 pkgid = topo_apicid(apic_id, TOPO_PKG_DOMAIN);
 
@@ -343,7 +348,7 @@ int topology_hotplug_apic(u32 apic_id, u32 acpi_id)
 		return -ENOSPC;
 
 	set_bit(apic_id, phys_cpu_present_map);
-	topo_set_cpuids(cpu, apic_id, acpi_id);
+	topo_set_cpuids(cpu, apic_id, acpi_id, false);
 	cpu_mark_primary_thread(cpu, apic_id);
 	return cpu;
 }
-- 
2.43.2


             reply	other threads:[~2024-04-07 15:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-07 15:26 Alexey Dobriyan [this message]
2024-04-08 13:31 ` [PATCH 1/2] x86/cpu/topology: don't write to immutable cpu_present_mask Thomas Gleixner
2024-04-09  8:42   ` Ingo Molnar
2024-04-09  9:24     ` Peter Zijlstra
2024-04-10 13:33   ` [tip: x86/alternatives] x86/topology: Don't update cpu_possible_map in topo_set_cpuids() tip-bot2 for Thomas Gleixner
2024-04-10 13:41   ` [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=20240407152643.3245-1-adobriyan@gmail.com \
    --to=adobriyan@gmail.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=linuxarm@huawei.com \
    --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 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.