From: Shrikanth Hegde <sshegde@linux.ibm.com>
To: maddy@linux.ibm.com, linuxppc-dev@lists.ozlabs.org,
linux-kernel@vger.kernel.org, driver-core@lists.linux.dev
Cc: sshegde@linux.ibm.com, christophe.leroy@csgroup.eu,
ritesh.list@gmail.com, tim.c.chen@linux.intel.com,
yu.c.chen@intel.com, gregkh@linuxfoundation.org,
rafael@kernel.org, dakr@kernel.org, johan@kernel.org,
sudeep.holla@kernel.org, peterz@infradead.org, tglx@kernel.org,
kprateek.nayak@amd.com, srikar@linux.ibm.com
Subject: [PATCH v2 4/6] powerpc: Set CPU device OF node before generic cacheinfo setup
Date: Fri, 27 Nov 2026 20:52:40 +0530 [thread overview]
Message-ID: <20261127152242.306333-5-sshegde@linux.ibm.com> (raw)
In-Reply-To: <20261127152242.306333-1-sshegde@linux.ibm.com>
PowerPC currently associates a CPU device with its device-tree node from
register_cpu_online(), which runs in the CPUHP_AP_ONLINE_DYN range.
Generic cacheinfo runs earlier at CPUHP_AP_BASE_CACHEINFO_ONLINE. For a
CPU added through pSeries DLPAR, the CPU device already exists but its
of_node is still NULL. Consequently, of_cpu_device_node_get() cannot find
the CPU node and generic cacheinfo prevents the CPU from coming online.
Add an explicit PowerPC CPU hotplug state immediately before
CPUHP_AP_BASE_CACHEINFO_ONLINE and move the CPU-device OF-node association
there. Keep the remaining PowerPC sysfs setup at its existing dynamic
state.
This also provides the correct teardown ordering: generic cacheinfo is
removed before PowerPC releases the CPU device's OF-node reference.
[Both draft changelog and code are written by LLM under guidance]
Assisted-by: LLM
Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
arch/powerpc/kernel/sysfs.c | 51 ++++++++++++++++++++++++++++++++-----
include/linux/cpuhotplug.h | 1 +
2 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
index 2100c5e2c821..092312163b35 100644
--- a/arch/powerpc/kernel/sysfs.c
+++ b/arch/powerpc/kernel/sysfs.c
@@ -834,6 +834,40 @@ static void remove_idle_spurr_file(struct device *s)
#define remove_idle_spurr_file(s)
#endif /* CONFIG_PPC_PSERIES */
+static int register_cpu_of_node(unsigned int cpu)
+{
+ struct device *dev = get_cpu_device(cpu);
+
+ if (!dev)
+ return -ENODEV;
+
+ /*
+ * CPUs present at boot already acquire this reference from
+ * register_cpu(). DLPAR-added and re-onlined CPUs may not have
+ * the OF node associated with the CPU device yet.
+ */
+ if (!dev->of_node)
+ dev->of_node = of_get_cpu_node(cpu, NULL);
+
+ if (!dev->of_node)
+ return -ENOENT;
+
+ return 0;
+}
+
+static int unregister_cpu_of_node(unsigned int cpu)
+{
+ struct device *dev = get_cpu_device(cpu);
+
+ if (!dev)
+ return 0;
+
+ of_node_put(dev->of_node);
+ dev->of_node = NULL;
+
+ return 0;
+}
+
static int register_cpu_online(unsigned int cpu)
{
struct cpu *c = &per_cpu(cpu_devices, cpu);
@@ -841,10 +875,6 @@ static int register_cpu_online(unsigned int cpu)
struct device_attribute *attrs, *pmc_attrs;
int i, nattrs;
- /* For cpus present at boot a reference was already grabbed in register_cpu() */
- if (!s->of_node)
- s->of_node = of_get_cpu_node(cpu, NULL);
-
#ifdef CONFIG_PPC64
if (cpu_has_feature(CPU_FTR_SMT))
device_create_file(s, &dev_attr_smt_snooze_delay);
@@ -1025,8 +1055,6 @@ static int unregister_cpu_online(unsigned int cpu)
}
#endif
cacheinfo_cpu_offline(cpu);
- of_node_put(s->of_node);
- s->of_node = NULL;
return 0;
}
#else /* !CONFIG_HOTPLUG_CPU */
@@ -1173,6 +1201,17 @@ static int __init topology_init(void)
device_create_file(&c->dev, &dev_attr_physical_id);
}
}
+
+ /*
+ * This must precede generic cacheinfo so
+ * of_cpu_device_node_get() can use cpu_dev->of_node.
+ */
+ r = cpuhp_setup_state_nocalls(CPUHP_AP_POWERPC_OF_NODE_ONLINE,
+ "powerpc/of_node:online",
+ register_cpu_of_node,
+ unregister_cpu_of_node);
+ WARN_ON(r < 0);
+
r = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "powerpc/topology:online",
register_cpu_online, unregister_cpu_online);
WARN_ON(r < 0);
diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h
index 1b6dba159bb2..617ad3cde57f 100644
--- a/include/linux/cpuhotplug.h
+++ b/include/linux/cpuhotplug.h
@@ -231,6 +231,7 @@ enum cpuhp_state {
CPUHP_AP_RANDOM_ONLINE,
CPUHP_AP_RCUTREE_ONLINE,
CPUHP_AP_KTHREADS_ONLINE,
+ CPUHP_AP_POWERPC_OF_NODE_ONLINE,
CPUHP_AP_BASE_CACHEINFO_ONLINE,
CPUHP_AP_ONLINE_DYN,
CPUHP_AP_ONLINE_DYN_END = CPUHP_AP_ONLINE_DYN + 40,
--
2.52.0
next prev parent reply other threads:[~2026-11-27 15:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 15:22 [PATCH v2 0/6] cacheinfo, powerpc, sched: Move powerpc to generic cacheinfo Shrikanth Hegde
2026-11-27 15:22 ` [PATCH v2 1/6] cacheinfo: Allow architectures to provide custom cache IDs Shrikanth Hegde
2026-11-27 15:22 ` [PATCH v2 2/6] cacheinfo: Support unified caches described by d-cache properties Shrikanth Hegde
2026-11-27 15:22 ` [PATCH v2 3/6] cacheinfo: Add firmware topology replacement helpers Shrikanth Hegde
2026-11-27 15:22 ` Shrikanth Hegde [this message]
2026-11-27 15:22 ` [PATCH v2 5/6] powerpc/cacheinfo: Move to generic cacheinfo Shrikanth Hegde
2026-11-27 15:22 ` [PATCH v2 6/6] sched/topology: Remove stale comment around llc_bytes on powerpc Shrikanth Hegde
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=20261127152242.306333-5-sshegde@linux.ibm.com \
--to=sshegde@linux.ibm.com \
--cc=christophe.leroy@csgroup.eu \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=peterz@infradead.org \
--cc=rafael@kernel.org \
--cc=ritesh.list@gmail.com \
--cc=srikar@linux.ibm.com \
--cc=sudeep.holla@kernel.org \
--cc=tglx@kernel.org \
--cc=tim.c.chen@linux.intel.com \
--cc=yu.c.chen@intel.com \
/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®