Hi Srikar. Thanks for going through the patches.
On 11/19/26 12:06 PM, Srikar Dronamraju wrote:
* Shrikanth Hegde <[email protected]> [2026-11-18 22:06:35]:
On PowerPC, a firmware cache node does not always correspond to a single
hardware cache instance.
---
drivers/base/cacheinfo.c | 43 +++++++++++++++++++++++++++++++--------
include/linux/cacheinfo.h | 1 +
2 files changed, 35 insertions(+), 9 deletions(-)
diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c
index eb8a907f6d50..10a9bbce899e 100644
--- a/drivers/base/cacheinfo.c
+++ b/drivers/base/cacheinfo.c
@@ -243,22 +243,46 @@ static bool match_cache_node(struct device_node *cpu,
#define arch_compact_of_hwid(_x) (_x)
#endif
+/*
+ * Return an architecture-specific cache ID for @cpu and @level.
+ *
+ * Return 0 and store the ID in @id when the architecture provides the
+ * cache identity. Return an error to use the generic firmware-derived
+ * cache ID instead.
+ *
If the return is only going to be bool, then does it make sense to return
bool instead of a int, esp does it need to return -ENOENT
or may be returning the id itself would be better.
It follows current signature of other hooks. I think we can keep as is.
+ * The ID must uniquely identify a cache among caches of the same level
+ * and type.
+ */
+int __weak cacheinfo_get_arch_id(unsigned int cpu, unsigned int level,
+ unsigned int *id)
+{
+ return -ENOENT;
+}
+
Can we use the #define, #ifndef way instead of the weak function
or is there a reason why only weak would work?
Same comment here. All Other arch hooks in this file are defined as weak
functions.
cacheinfo_get_arch_id doesn't need a special treatment.
static void cache_of_set_id(struct cacheinfo *this_leaf,
- struct device_node *cache_node)
+ struct device_node *cache_node,
+ unsigned int cpu)
{
- struct device_node *cpu;
+ struct device_node *cpu_node;
u32 min_id = ~0;
+ unsigned int arch_id;
+
+ if (!cacheinfo_get_arch_id(cpu, this_leaf->level, &arch_id)) {
+ this_leaf->id = arch_id;
+ this_leaf->attributes |= CACHE_ID;
+ return;
+ }
- for_each_of_cpu_node(cpu) {
- u64 id = of_get_cpu_hwid(cpu, 0);
+ for_each_of_cpu_node(cpu_node) {
+ u64 id = of_get_cpu_hwid(cpu_node, 0);
id = arch_compact_of_hwid(id);
if (FIELD_GET(GENMASK_ULL(63, 32), id)) {
- of_node_put(cpu);
+ of_node_put(cpu_node);
return;
}
- if (match_cache_node(cpu, cache_node))
+ if (match_cache_node(cpu_node, cache_node))
min_id = min(min_id, id);
}
@@ -269,7 +293,8 @@ static void cache_of_set_id(struct cacheinfo *this_leaf,
}
static void cache_of_set_props(struct cacheinfo *this_leaf,
- struct device_node *np)
+ struct device_node *np,
+ unsigned int cpu)
{
/*
* init_cache_level must setup the cache level correctly
@@ -283,7 +308,7 @@ static void cache_of_set_props(struct cacheinfo *this_leaf,
cache_get_line_size(this_leaf, np);
cache_nr_sets(this_leaf, np);
cache_associativity(this_leaf);
- cache_of_set_id(this_leaf, np);
+ cache_of_set_id(this_leaf, np, cpu);
}
static int cache_setup_of_node(unsigned int cpu)
@@ -309,7 +334,7 @@ static int cache_setup_of_node(unsigned int cpu)
if (!np)
break;
}
- cache_of_set_props(this_leaf, np);
+ cache_of_set_props(this_leaf, np, cpu);
Would it make sense to get the cacheinfo arch id here.
That way we could avoid lot of this changes just to pass a CPU, or renaming
of the variable etc. We will probably will need a check in cache_of_set_id
to see if the this_leaf->id is set to bail out
Since it is id set by arch, i think it is better to do this in cache_of_set_id.
I think some are sensible. It is better to name device node of cpu as cpu_node
rather than cpu.
this_leaf->fw_token = np;
index++;
}
diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h
index 56fa646df0d1..d3557a1b464b 100644
--- a/include/linux/cacheinfo.h
+++ b/include/linux/cacheinfo.h
@@ -93,6 +93,7 @@ bool last_level_cache_is_shared(unsigned int cpu_x, unsigned
int cpu_y);
struct cacheinfo *get_cpu_cacheinfo_llc(unsigned int cpu);
int fetch_cache_info(unsigned int cpu);
int detect_cache_attributes(unsigned int cpu);
+int cacheinfo_get_arch_id(unsigned int cpu, unsigned int level, unsigned int
*id);
#ifndef CONFIG_ACPI_PPTT
/*
* acpi_get_cache_info() is only called on ACPI enabled
--
2.54.0