From: Shrikanth Hegde <sshegde@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
driver-core@lists.linux.dev, christophe.leroy@csgroup.eu
Cc: 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,
maddy@linux.ibm.com
Subject: Re: [PATCH v2 5/6] powerpc/cacheinfo: Move to generic cacheinfo
Date: Tue, 1 Dec 2026 16:20:45 +0530 [thread overview]
Message-ID: <a6d89b18-8ae4-478d-903d-592b26bbb4dd@linux.ibm.com> (raw)
In-Reply-To: <20261127152242.306333-6-sshegde@linux.ibm.com>
Posting reply to shashiko review at
https://sashiko.dev/#/patchset/20261127152242.306333-1-sshegde%40linux.ibm.com
Summary: Only two are worth fixing at this moment.
Christophe, Please see below a possible issue on 85xx. Would like your comments
on it.
> +int cacheinfo_get_arch_id(unsigned int cpu, unsigned int level,
> + unsigned int *id)
> {
> + const struct cpumask *mask = NULL;
> + mask = per_cpu(thread_group_l1_cache_map, cpu);
> + mask = per_cpu(thread_group_l2_cache_map, cpu);
> + mask = per_cpu(thread_group_l3_cache_map, cpu);
> + if (!mask || cpumask_empty(mask))
> + return -ENOENT;
Review:
=======
Does falling back to -ENOENT whenever thread-group masks are not used
cause quadratic device-tree scans during boot and Live Partition Mobility
rebuilds?
Reply:
======
Possible. But this happens during online or bootup time. Improvements can be
taken up post the initial series.
> + *id = cpumask_first(mask);
> + if (*id >= nr_cpu_ids)
> + return -ENOENT;
>
Review:
=======
When thread_group_shares_l2 or thread_group_shares_l3 is false (such as on
POWER8/POWER9 topologies without ibm,thread-groups property 2), can
returning -ENOENT here produce inconsistent L2/L3 cache IDs across pSeries
DLPAR operations?
On -ENOENT, cache_of_set_id() sets leaf->id and CACHE_ID from the minimum
hardware ID among CPU nodes currently attached in the device tree that
reference the cache node. When multiple CPU nodes share an L2 or L3 cache
node and the lowest-hwid CPU node is added via dlpar_cpu_add() or detached
via dlpar_cpu_remove() (where pseries_cpuhp_detach_nodes() keeps shared
cache nodes attached when pseries_cpuhp_cache_use_count(dn) > 1), newly
populated leaves compute a different min_id from the id retained by
already-online CPUs sharing that cache node. Because
cache_leaves_are_shared() compares only leaf->id when CACHE_ID is set and
ignores fw_token, CPUs sharing the same cache node no longer match,
splitting shared_cpu_map and miscalculating per_cpu_data_slice_size and
scheduler llc_bytes.
Reply:
======
For the current topologies support DLPAR, cache heirarchy doesn't spawn across
nodes.
CPU DLPAR operates on a complete firmware CPU node, which represents the
full core. Cache sharing is within that core. On Power11, ibm,thread-groups
further divides the eight threads into the two
physical cache-sharing groups 0,2,4,6 and 1,3,5,7, for which the
architecture hook supplies explicit IDs.
On systems without thread-group information, I am not sure if DLPAR
is possible. Even if it is, since full core is removed/added and leaves
don't span across a node, I don't think there will be a leave retaining
old minimal firmware based ID.
So I don't this this is an issue.
> -static void remove_cache_dir(struct cache_dir *cache_dir)
> +int populate_cache_leaves(unsigned int cpu)
> {
> - remove_index_dirs(cache_dir);
> + struct cpu_cacheinfo *ci = get_cpu_cacheinfo(cpu);
> + struct cacheinfo *leaf = ci->info_list;
> + struct device_node *next;
> + struct device_node *np;
> + unsigned int index = 0;
> + unsigned int level = 1;
>
> - /* Remove cache dir from sysfs */
> - kobject_del(cache_dir->kobj);
> + np = of_get_cpu_node(cpu, NULL);
> + if (!np)
> + return -ENOENT;
>
> - kobject_put(cache_dir->kobj);
> + for (;;) {
> + bool unified = of_property_read_bool(np, "cache-unified");
>
Review:
=======
Does checking only "cache-unified" break cacheinfo and CPU online on
PowerPC device trees whose unified L2/L3 cache nodes omit that property?
Unlike of_count_cache_leaves() in drivers/base/cacheinfo.c, which also
treats a node with "cache-size" as unified, powerpc_cache_leaves() and
populate_cache_leaves() emit two leaves (CACHE_TYPE_DATA and
CACHE_TYPE_INST) at the same level > 1 whenever "cache-unified" is absent.
Many in-tree PowerPC 44x, 85xx, and QorIQ device trees (for example
arch/powerpc/boot/dts/xpedite5370.dts) describe unified L2 caches using
"cache-size" and "cache-line-size" without "cache-unified".
When two leaves share a level > 1, cache_setup_of_node() advances to the
next cache node on every non-L1 leaf:
drivers/base/cacheinfo.c:cache_setup_of_node() {
while (index < cache_leaves(cpu)) {
this_leaf = per_cpu_cacheinfo_idx(cpu, index);
if (this_leaf->level != 1) {
struct device_node *prev __free(device_node) = np;
np = of_find_next_cache_node(np);
if (!np)
break;
}
...
index++;
}
if (index != cache_leaves(cpu)) /* not all OF nodes populated */
return -ENOENT;
}
Advancing np twice for a single L2 node exhausts the cache node chain and
returns -ENOENT, which rolls back cacheinfo sysfs creation for all CPUs at
boot and causes runtime CPU online operations to fail.
Reply: Possible if such device tree structures exists.
Christophe, or anyone having 85xx, 44xx can you please try the
series and see if cacheinfo structures are compatible?
If not, could you please try with the below diff?
---
diff --git a/arch/powerpc/kernel/cacheinfo.c b/arch/powerpc/kernel/cacheinfo.c
index e77e613bcf44..fa475e059705 100644
--- a/arch/powerpc/kernel/cacheinfo.c
+++ b/arch/powerpc/kernel/cacheinfo.c
@@ -52,17 +52,23 @@ static void powerpc_cache_leaf_init(struct cacheinfo *leaf,
leaf->type = type;
}
+
/*
* A node carrying cache-unified represents one unified cache leaf.
* Other nodes represent separate data and instruction cache leaves.
*
- * Cache property availability does not determine whether a leaf
- * exists. Missing optional properties are handled by generic
- * cacheinfo.
+ * Few older powerpc implementation may have unified cache without
+ * explicit cache-unified and only specify cache-size.
*/
+static bool powerpc_cache_is_unified(struct device_node *np)
+{
+ return of_property_read_bool(np, "cache-unified") ||
+ of_property_read_bool(np, "cache-size");
+}
+
static unsigned int powerpc_cache_leaves(struct device_node *np)
{
- return of_property_read_bool(np, "cache-unified") ? 1 : 2;
+ return powerpc_cache_is_unified(np) ? 1 : 2;
}
int init_cache_level(unsigned int cpu)
@@ -112,7 +118,7 @@ int populate_cache_leaves(unsigned int cpu)
return -ENOENT;
for (;;) {
- bool unified = of_property_read_bool(np, "cache-unified");
+ bool unified = powerpc_cache_is_unified(np);
if (unified) {
if (index >= ci->num_leaves)
> - kfree(cache_dir);
> -}
> + if (unified) {
> + if (index >= ci->num_leaves)
> + goto err;
>
...
> +static void dlpar_invalidate_cpu_cacheinfo(struct device_node *dn)
> +{
> + const __be32 *intserv;
> + unsigned int cpu;
> + int len, nthreads, i;
> + u32 thread;
> +
> + intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s", &len);
> + if (!intserv)
> + return;
> +
> + nthreads = len / sizeof(u32);
> +
> + for (i = 0; i < nthreads; i++) {
> + thread = be32_to_cpu(intserv[i]);
> + for_each_present_cpu(cpu) {
> + if (get_hard_smp_processor_id(cpu) != thread)
> + continue;
> +
> + cacheinfo_invalidate_cpu(cpu);
> + break;
> + }
> + }
> +}
Review:
=======
Can a boot-present CPU thread that was already offline when its core was
removed via dlpar_cpu_remove() retain a stale get_cpu_device(cpu)->of_node
and fail to come online when re-added?
At boot, topology_init() -> register_cpu() populates cpu->dev.of_node for
every present thread, even if the thread stays offline (for example under
reduced SMT or maxcpus). During dlpar_cpu_remove(), dlpar_offline_cpu()
skips threads that are not online, so unregister_cpu_of_node() never runs
to release and clear dev->of_node. When a new core is later added with
dlpar_cpu_add() reusing those logical CPU IDs, register_cpu_of_node() sees
a non-NULL dev->of_node and leaves the detached node in place:
arch/powerpc/kernel/sysfs.c:register_cpu_of_node() {
struct device *dev = get_cpu_device(cpu);
if (!dev->of_node)
dev->of_node = of_get_cpu_node(cpu, NULL);
return 0;
}
When that thread is brought online, init_cache_level() and
populate_cache_leaves() walk the new attached CPU node via
of_get_cpu_node(cpu, NULL), while cache_setup_of_node() walks the stale
detached dev->of_node via of_cpu_device_node_get(cpu). Looking up the
detached L2 phandle in of_find_next_cache_node() then returns NULL,
failing cache_setup_of_node() with -ENOENT and aborting dlpar_cpu_add().
Reply:
Yes. Good catch. register_cpu() associates dev->of_node for every present CPU,
including threads that are offline at boot. Such a thread is skipped by
dlpar_offline_cpu(), so it does not execute unregister_cpu_of_node() and
can retain a reference to the CPU node being detached.
So, I am thinking below to address it. Just check it again at online and fix it
if it is different.
diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
index 44ae42989b6a..57c0e015a684 100644
--- a/arch/powerpc/kernel/sysfs.c
+++ b/arch/powerpc/kernel/sysfs.c
@@ -836,6 +836,7 @@ static void remove_idle_spurr_file(struct device *s)
static int register_cpu_of_node(unsigned int cpu)
{
struct device *dev = get_cpu_device(cpu);
+ struct device_node *np;
if (!dev)
return -ENODEV;
@@ -845,12 +846,18 @@ static int register_cpu_of_node(unsigned int cpu)
* 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)
+ np = of_get_cpu_node(cpu, NULL);
+ if (!np)
return -ENOENT;
+ /* A previously offline CPU may hold older device node referrence */
+ if (dev->of_node != np) {
+ of_node_put(dev->of_node);
+ dev->of_node = np;
+ } else {
+ of_node_put(np);
+ }
+
return 0;
}
next prev parent reply other threads:[~2026-12-01 10:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 15:22 [PATCH v2 0/6] cacheinfo, powerpc, sched: Move powerpc " 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 ` [PATCH v2 4/6] powerpc: Set CPU device OF node before generic cacheinfo setup Shrikanth Hegde
2026-11-27 15:22 ` [PATCH v2 5/6] powerpc/cacheinfo: Move to generic cacheinfo Shrikanth Hegde
2026-12-01 10:50 ` Shrikanth Hegde [this message]
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=a6d89b18-8ae4-478d-903d-592b26bbb4dd@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®