Skip to contentSkip to conversation

Cache coherency management subsystem

PATCH In review Jonathan Cameron 3 participants 15 messages Nov 17, 2025 – Nov 20, 2025

Subsystems (10)
lore
Share & tools
lore
#0 lore raw

v6 cover Cache coherency management subsystem

v6: Split the Kconfig menu to differentiate the new type of driver this set
adds from existing riscv cache maintenance drivers for interaction with non coherent DMA master. This provides a good resolution to concerns around mixing different types of driver, whilst avoiding yet another drivers/* directory (Thanks to Arnd Bergmann)

Support system level interfaces for cache maintenance as found on some ARM64 systems. It is expected that systems using other CPU architectures (such as RiscV) that support CXL memory and allow for native OS flows will also use this. This is needed for correct functionality during various forms of memory hotplug (e.g. CXL). Typical hardware has MMIO interface found via ACPI DSDT. A system will often contain multiple hardware instances.

Includes parameter changes to cpu_cache_invalidate_memregion() but no functional changes for architectures that already support this call.

Merge plan. Through Conor's drivers/cache tree which routes through the SoC tree.
* Andrew Morton has expressed he is fine with the MM related changes going via another appropriate tree.
* CXL maintainers expressed that they don't consider it appropriate to go through theit tree.
* The tiny touching of Arm specific code has an ack from Catalin.

v5: Changes called out in individual patches.
Comment and patch description updates to make the following clearer.
- Difference from cache-coherence operations for non-coherent DMA. Longer term it may make sense to share infrastructure but for now we have two parallel systems as there would be near zero overlap in code or functionality.
- Why multiple agent handling is necessary and what that means for the HiSilicon HHAs in our systems + the driver inclued in this set.

v4: (Small changes called out in each patch)
- Drop the ACPI driver. It has done it's job as a second implementation to help with generality testing. I have heard zero interest in actually doing the specification work needed to make that official. Easy to bring back if needed in future. I have it locally still as a second test case.
- Add a cpu_cache_invalidate_all() helper for the 0,-1 case that is used to indicate everything should be flushed as no fine grained range info available.
- Simplify the necessary symbols to be selected by architectures by making CONFIG_GENERIC_CPU_CACHE_MAINTENANCE select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
- Avoid naming mentioning devices as there is no struct device.
- Use a kref so as to have something on which a _put() operation makes sense avoiding rather confusing freeing of an internal structure pointer that was seen in v3.
- Gather tags given.
- Various minor things like typos, header tweaks etc.
Thanks to all who reviewed v3.

On current ARM64 systems (and likely other architectures) the implementation of cache flushing need for actions such as CXL memory hotplug e.g. cpu_cache_invalidate_memregion(), is performed by system components outside of the CPU, controlled via either firmware or MMIO interfaces.

These control units run the necessary coherency protocol operations to cause the write backs and cache flushes to occur asynchronously. They allow filtering by PA range to reduce disruption to the system. Systems supporting this interface must be designed to ensure that, when complete, all cache lines in the range are in invalid state or clean state (prefetches may have raced with the invalidation). This must include memory-side caches and other non architectural caches beyond the Point of Coherence (ARM terminology) such that writes will reach memory even after OS programmable address decoders are modified (for CXL this is any HDM decoders that aren't locked). Software will guarantee that no writes to these memory ranges race with this operation. Whilst this is subtly different from write backs must reach the physical memory that difference probably doesn't matter to those reading this series.

The often distributed nature of the relevant coherency management units (e.g. due to interleaving) requires the appropriate commands to be issued to multiple (potentially heterogeneous) units. To enable this a registration framework is provided to which drivers may register a set of callbacks. Upon a request for a cache maintenance operation the framework iterates over all registered callback sets, calling first a command to write back and invalidate, and then optionally a command to wait for completion. Filtering on relevance if a give request is left to the individual drivers.

In this version only one driver is included. This is the HiSilicon Hydra Home Agent driver which controls hardware found on some of our relevant server SoCs. Also available (I can post if anyone is interested) is an ACPI driver based on a firmware interface that was in a public PSCI specification alpha version

QEMU emulation code at
http://gitlab.com/jic23/qemu cxl-2025-03-20

Notes:
- I don't particularly like defining 'generic' infrastructure with so few implementations. If anyone can point me at docs for another one or two, or confirm that they think this is fine that would be great! The converse to this is I don't want to wait longer for those to surface given the necessity to support this one platform that I do know about!

Jonathan Cameron (4):
memregion: Drop unused IORES_DESC_* parameter from
cpu_cache_invalidate_memregion()
arm64: Select GENERIC_CPU_CACHE_MAINTENANCE
MAINTAINERS: Add Jonathan Cameron to drivers/cache and add
lib/cache_maint.c + header
cache: Make top level Kconfig menu a boolean dependent on RISCV

Yicong Yang (2):
memregion: Support fine grained invalidate by
cpu_cache_invalidate_memregion()
lib: Support ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION

Yushan Wang (1):
cache: Support cache maintenance for HiSilicon SoC Hydra Home Agent

 MAINTAINERS                     |   3 +
 arch/arm64/Kconfig              |   1 +
 arch/x86/mm/pat/set_memory.c    |   2 +-
 drivers/cache/Kconfig           |  37 +++++-
 drivers/cache/Makefile          |   2 +
 drivers/cache/hisi_soc_hha.c    | 194 ++++++++++++++++++++++++++++++++
 drivers/cxl/core/region.c       |   5 +-
 drivers/nvdimm/region.c         |   2 +-
 drivers/nvdimm/region_devs.c    |   2 +-
 include/linux/cache_coherency.h |  61 ++++++++++
 include/linux/memregion.h       |  16 ++-
 lib/Kconfig                     |   4 +
 lib/Makefile                    |   2 +
 lib/cache_maint.c               | 138 +++++++++++++++++++++++
 14 files changed, 457 insertions(+), 12 deletions(-)
 create mode 100644 drivers/cache/hisi_soc_hha.c
 create mode 100644 include/linux/cache_coherency.h
 create mode 100644 lib/cache_maint.c
Signature · 1 line
2.48.1
#1 lore raw

PATCH v6 1/7 memregion: Drop unused IORES_DESC_* parameter from cpu_cache_invalidate_memregion()

The res_desc parameter was originally introduced for documentation purposes and with the idea that with HDM-DB CXL invalidation could be triggered from the device. That has not come to pass and the continued existence of the option is confusing when we add a range in the following patch which might not be a strict subset of the res_desc. So avoid that confusion by dropping the parameter.

---
v6: No change.
v5: No change.
v4: Dan's tag (thanks!)
V3: New patch.
As Dan calls out in the linked mail, an alternative might be to lookup the ranges and enforce the descriptor but his expressed preference was for dropping the parameter.

---
 arch/x86/mm/pat/set_memory.c | 2 +-
 drivers/cxl/core/region.c    | 2 +-
 drivers/nvdimm/region.c      | 2 +-
 drivers/nvdimm/region_devs.c | 2 +-
 include/linux/memregion.h    | 7 +++----
 5 files changed, 7 insertions(+), 8 deletions(-)
arch/x86/mm/pat/set_memory.c +1 -1
index d2d54b8c4dbb..0cfee2544ad4 100644
@@ -368,7 +368,7 @@ bool cpu_cache_has_invalidate_memregion(void)
 }
 EXPORT_SYMBOL_NS_GPL(cpu_cache_has_invalidate_memregion, "DEVMEM");
 
-int cpu_cache_invalidate_memregion(int res_desc)
+int cpu_cache_invalidate_memregion(void)
 {
 	if (WARN_ON_ONCE(!cpu_cache_has_invalidate_memregion()))
 		return -ENXIO;
drivers/cxl/core/region.c +1 -1
index e14c1d305b22..36489cb086f3 100644
@@ -236,7 +236,7 @@ static int cxl_region_invalidate_memregion(struct cxl_region *cxlr)
 		return -ENXIO;
 	}
 
-	cpu_cache_invalidate_memregion(IORES_DESC_CXL);
+	cpu_cache_invalidate_memregion();
 	return 0;
 }
 
drivers/nvdimm/region.c +1 -1
index cd9b52040d7b..47e263ecedf7 100644
@@ -110,7 +110,7 @@ static void nd_region_remove(struct device *dev)
 	 * here is ok.
 	 */
 	if (cpu_cache_has_invalidate_memregion())
-		cpu_cache_invalidate_memregion(IORES_DESC_PERSISTENT_MEMORY);
+		cpu_cache_invalidate_memregion();
 }
 
 static int child_notify(struct device *dev, void *data)
drivers/nvdimm/region_devs.c +1 -1
index a5ceaf5db595..c375b11aea6d 100644
@@ -90,7 +90,7 @@ static int nd_region_invalidate_memregion(struct nd_region *nd_region)
 		}
 	}
 
-	cpu_cache_invalidate_memregion(IORES_DESC_PERSISTENT_MEMORY);
+	cpu_cache_invalidate_memregion();
 out:
 	for (i = 0; i < nd_region->ndr_mappings; i++) {
 		struct nd_mapping *nd_mapping = &nd_region->mapping[i];
include/linux/memregion.h +3 -4
index c01321467789..945646bde825 100644
@@ -26,8 +26,7 @@ static inline void memregion_free(int id)
 
 /**
  * cpu_cache_invalidate_memregion - drop any CPU cached data for
- *     memregions described by @res_desc
- * @res_desc: one of the IORES_DESC_* types
+ *     memregion
  *
  * Perform cache maintenance after a memory event / operation that
  * changes the contents of physical memory in a cache-incoherent manner.
@@ -46,7 +45,7 @@ static inline void memregion_free(int id)
  * the cache maintenance.
  */
 #ifdef CONFIG_ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
-int cpu_cache_invalidate_memregion(int res_desc);
+int cpu_cache_invalidate_memregion(void);
 bool cpu_cache_has_invalidate_memregion(void);
 #else
 static inline bool cpu_cache_has_invalidate_memregion(void)
@@ -54,7 +53,7 @@ static inline bool cpu_cache_has_invalidate_memregion(void)
 	return false;
 }
 
-static inline int cpu_cache_invalidate_memregion(int res_desc)
+static inline int cpu_cache_invalidate_memregion(void)
 {
 	WARN_ON_ONCE("CPU cache invalidation required");
 	return -ENXIO;
Signature · 1 line
2.48.1
#2 lore raw

PATCH v6 2/7 memregion: Support fine grained invalidate by cpu_cache_invalidate_memregion()

In reply to Jonathan Cameron

From: Yicong Yang <[email protected]>

Extend cpu_cache_invalidate_memregion() to support invalidating a particular range of memory by introducing start and length parameters. Control of types of invalidation is left for when use cases turn up. For now everything is Clean and Invalidate.

Where the range is unknown, use the provided cpu_cache_invalidate_all() helper to act as documentation of intent in a fashion that is clearer than passing (0, -1) to cpu_cache_invalidate_memregion().

---
v6: No change
v5: Tiny tweaks to patch description for readability.
v4: Add cpu_cache_invalidate_all() helper for the (0, -1) case that
applies when we don't have the invalidate range so just want to invalidate all caches. - (Thanks to Dan Williams for this suggestion).
v3: Rebase on top of previous patch that removed the IO_RESDESC_*
parameter.

---
 arch/x86/mm/pat/set_memory.c |  2 +-
 drivers/cxl/core/region.c    |  5 ++++-
 drivers/nvdimm/region.c      |  2 +-
 drivers/nvdimm/region_devs.c |  2 +-
 include/linux/memregion.h    | 13 +++++++++++--
 5 files changed, 18 insertions(+), 6 deletions(-)
arch/x86/mm/pat/set_memory.c +1 -1
index 0cfee2544ad4..05e7704f0128 100644
@@ -368,7 +368,7 @@ bool cpu_cache_has_invalidate_memregion(void)
 }
 EXPORT_SYMBOL_NS_GPL(cpu_cache_has_invalidate_memregion, "DEVMEM");
 
-int cpu_cache_invalidate_memregion(void)
+int cpu_cache_invalidate_memregion(phys_addr_t start, size_t len)
 {
 	if (WARN_ON_ONCE(!cpu_cache_has_invalidate_memregion()))
 		return -ENXIO;
drivers/cxl/core/region.c +4 -1
index 36489cb086f3..7d0f6f07352f 100644
@@ -236,7 +236,10 @@ static int cxl_region_invalidate_memregion(struct cxl_region *cxlr)
 		return -ENXIO;
 	}
 
-	cpu_cache_invalidate_memregion();
+	if (!cxlr->params.res)
+		return -ENXIO;
+	cpu_cache_invalidate_memregion(cxlr->params.res->start,
+				       resource_size(cxlr->params.res));
 	return 0;
 }
 
drivers/nvdimm/region.c +1 -1
index 47e263ecedf7..53567f3ed427 100644
@@ -110,7 +110,7 @@ static void nd_region_remove(struct device *dev)
 	 * here is ok.
 	 */
 	if (cpu_cache_has_invalidate_memregion())
-		cpu_cache_invalidate_memregion();
+		cpu_cache_invalidate_all();
 }
 
 static int child_notify(struct device *dev, void *data)
drivers/nvdimm/region_devs.c +1 -1
index c375b11aea6d..1220530a23b6 100644
@@ -90,7 +90,7 @@ static int nd_region_invalidate_memregion(struct nd_region *nd_region)
 		}
 	}
 
-	cpu_cache_invalidate_memregion();
+	cpu_cache_invalidate_all();
 out:
 	for (i = 0; i < nd_region->ndr_mappings; i++) {
 		struct nd_mapping *nd_mapping = &nd_region->mapping[i];
include/linux/memregion.h +11 -2
index 945646bde825..a55f62cc5266 100644
@@ -27,6 +27,9 @@ static inline void memregion_free(int id)
 /**
  * cpu_cache_invalidate_memregion - drop any CPU cached data for
  *     memregion
+ * @start: start physical address of the target memory region.
+ * @len: length of the target memory region. -1 for all the regions of
+ *       the target type.
  *
  * Perform cache maintenance after a memory event / operation that
  * changes the contents of physical memory in a cache-incoherent manner.
@@ -45,7 +48,7 @@ static inline void memregion_free(int id)
  * the cache maintenance.
  */
 #ifdef CONFIG_ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
-int cpu_cache_invalidate_memregion(void);
+int cpu_cache_invalidate_memregion(phys_addr_t start, size_t len);
 bool cpu_cache_has_invalidate_memregion(void);
 #else
 static inline bool cpu_cache_has_invalidate_memregion(void)
@@ -53,10 +56,16 @@ static inline bool cpu_cache_has_invalidate_memregion(void)
 	return false;
 }
 
-static inline int cpu_cache_invalidate_memregion(void)
+static inline int cpu_cache_invalidate_memregion(phys_addr_t start, size_t len)
 {
 	WARN_ON_ONCE("CPU cache invalidation required");
 	return -ENXIO;
 }
 #endif
+
+static inline int cpu_cache_invalidate_all(void)
+{
+	return cpu_cache_invalidate_memregion(0, -1);
+}
+
 #endif /* _MEMREGION_H_ */
Signature · 1 line
2.48.1
#3 lore raw

PATCH v6 3/7 lib: Support ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION

In reply to Jonathan Cameron

From: Yicong Yang <[email protected]>

ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION provides the mechanism for invalidating certain memory regions in a cache-incoherent manner. Currently this is used by NVDIMM and CXL memory drivers in cases where it is necessary to flush all data from caches by physical address range. The operations in question are effectively memory hotplug, where stale data might otherwise remain in the caches.

This is separate from the invalidates done to enable use of non-coherent DMA masters, primarily in terms of when it is needed (not related to DMA mappings) and how deep the flush must push data. The flushes done for non-coherent DMA only need to reach the Point of Coherence of a single host (which is often nearer CPUs and DMA masters than the physical storage). This operation must push the data out of non architectural caches (memory-side caches, write buffers etc) and typically all the way to the memory device.

In some architectures these operations are supported by system components that may become available only later in boot as they are either present on a discoverable bus, or via a firmware description of an MMIO interface (e.g. ACPI DSDT). Provide a framework to handle this case.

Architectures can opt in for this support via
CONFIG_GENERIC_CPU_CACHE_MAINTENANCE

Add a registration framework. Each driver provides an ops structure and the first op is Write Back and Invalidate by PA Range. The driver may over invalidate.

For systems that can perform this operation asynchronously an optional completion check operation is also provided. If present that must be called to ensure that the action has finished. This provides a considerable performance advantage if multiple agents are involved in the maintenance operation.

When multiple agents are present in the system each should register with this framework and the core code will issue the invalidate to all of them before checking for completion on each. This is done to avoid need for filtering in the core code which can become complex when interleave, potentially across different cache coherency hardware is going on, so it is easier to tell everyone and let those who don't care do nothing.

---
v6: No change.
v5: Picked up ack from Conor. Thanks!
Add discussion of difference from the existing operations for working with non-coherent DMA (Arnd)
Expand a little on asynchronous nature and why it matters for some systems.

---
 include/linux/cache_coherency.h |  61 ++++++++++++++
 lib/Kconfig                     |   4 +
 lib/Makefile                    |   2 +
 lib/cache_maint.c               | 138 ++++++++++++++++++++++++++++++++
 4 files changed, 205 insertions(+)
include/linux/cache_coherency.h new file +61 -0
new file mode 100644
index 000000000000..cc81c5733e31
@@ -0,0 +1,61 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Cache coherency maintenance operation device drivers
+ *
+ * Copyright Huawei 2025
+ */
+#ifndef _LINUX_CACHE_COHERENCY_H_
+#define _LINUX_CACHE_COHERENCY_H_
+
+#include <linux/list.h>
+#include <linux/kref.h>
+#include <linux/types.h>
+
+struct cc_inval_params {
+	phys_addr_t addr;
+	size_t size;
+};
+
+struct cache_coherency_ops_inst;
+
+struct cache_coherency_ops {
+	int (*wbinv)(struct cache_coherency_ops_inst *cci,
+		     struct cc_inval_params *invp);
+	int (*done)(struct cache_coherency_ops_inst *cci);
+};
+
+struct cache_coherency_ops_inst {
+	struct kref kref;
+	struct list_head node;
+	const struct cache_coherency_ops *ops;
+};
+
+int cache_coherency_ops_instance_register(struct cache_coherency_ops_inst *cci);
+void cache_coherency_ops_instance_unregister(struct cache_coherency_ops_inst *cci);
+
+struct cache_coherency_ops_inst *
+_cache_coherency_ops_instance_alloc(const struct cache_coherency_ops *ops,
+				    size_t size);
+/**
+ * cache_coherency_ops_instance_alloc - Allocate cache coherency ops instance
+ * @ops: Cache maintenance operations
+ * @drv_struct: structure that contains the struct cache_coherency_ops_inst
+ * @member: Name of the struct cache_coherency_ops_inst member in @drv_struct.
+ *
+ * This allocates a driver specific structure and initializes the
+ * cache_coherency_ops_inst embedded in the drv_struct. Upon success the
+ * pointer must be freed via cache_coherency_ops_instance_put().
+ *
+ * Returns a &drv_struct * on success, %NULL on error.
+ */
+#define cache_coherency_ops_instance_alloc(ops, drv_struct, member)	    \
+	({								    \
+		static_assert(__same_type(struct cache_coherency_ops_inst,  \
+					  ((drv_struct *)NULL)->member));   \
+		static_assert(offsetof(drv_struct, member) == 0);	    \
+		(drv_struct *)_cache_coherency_ops_instance_alloc(ops,	    \
+			sizeof(drv_struct));				    \
+	})
+void cache_coherency_ops_instance_put(struct cache_coherency_ops_inst *cci);
+
+#endif
lib/Kconfig +4 -0
index e629449dd2a3..e11136d188ae 100644
@@ -542,6 +542,10 @@ config MEMREGION
 config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
 	bool
 
+config GENERIC_CPU_CACHE_MAINTENANCE
+	bool
+	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
+
 config ARCH_HAS_MEMREMAP_COMPAT_ALIGN
 	bool
 
lib/Makefile +2 -0
index 1ab2c4be3b66..aaf677cf4527 100644
@@ -127,6 +127,8 @@ obj-$(CONFIG_HAS_IOMEM) += iomap_copy.o devres.o
 obj-$(CONFIG_CHECK_SIGNATURE) += check_signature.o
 obj-$(CONFIG_DEBUG_LOCKING_API_SELFTESTS) += locking-selftest.o
 
+obj-$(CONFIG_GENERIC_CPU_CACHE_MAINTENANCE) += cache_maint.o
+
 lib-y += logic_pio.o
 
 lib-$(CONFIG_INDIRECT_IOMEM) += logic_iomem.o
lib/cache_maint.c new file +138 -0

138 lines not on this page · raw message

Signature · 1 line
2.48.1
#4 lore raw

Re: [PATCH v6 3/7] lib: Support ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION

Hi,

Quoted 5 lines · Jonathan Cameron
lib/Kconfig +0 -0
index e629449dd2a3..e11136d188ae 100644

lib/Kconfig config MEMREGION · line 550

Quoted 9 lines
lib/Kconfig +4 -0
@@ -542,6 +542,10 @@ config MEMREGION
 config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
 	bool
 
+config GENERIC_CPU_CACHE_MAINTENANCE
+	bool
+	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
+
 config ARCH_HAS_MEMREMAP_COMPAT_ALIGN
 	bool

Architectures and/or platforms select ARCH_HAS_*.

With this change above, it becomes the only entry in lib/Kconfig that does "select ARCH_HAS_anytning".

so I think this is wrong, back*wards.

Signature · 1 line
~Randy
maintainer
#5 lore raw

Re: [PATCH v6 3/7] lib: Support ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION

Quoted 20 lines · Randy Dunlap

Hi,

Quoted 5 lines · Jonathan Cameron
lib/Kconfig +0 -0
index e629449dd2a3..e11136d188ae 100644

lib/Kconfig config MEMREGION · line 550

Quoted 9 lines
lib/Kconfig +4 -0
@@ -542,6 +542,10 @@ config MEMREGION
 config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
 	bool
 
+config GENERIC_CPU_CACHE_MAINTENANCE
+	bool
+	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
+
 config ARCH_HAS_MEMREMAP_COMPAT_ALIGN
 	bool

Architectures and/or platforms select ARCH_HAS_*.

Quoted 4 lines

With this change above, it becomes the only entry in lib/Kconfig that does "select ARCH_HAS_anytning".

so I think this is wrong, back*wards.

Maybe it is backwards, but I feel like this way is more logical. ARM64 has memregion invalidation only because this generic approach is enabled, so the arch selects what it needs to get the support. Alternatively, something like

| diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
| index 5f7f63d24931..75b2507f7eb2 100644
| --- a/arch/arm64/Kconfig
| +++ b/arch/arm64/Kconfig
| @@ -21,6 +21,7 @@ config ARM64
|  	select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE
|  	select ARCH_HAS_CACHE_LINE_SIZE
|  	select ARCH_HAS_CC_PLATFORM
| +	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
|  	select ARCH_HAS_CURRENT_STACK_POINTER
|  	select ARCH_HAS_DEBUG_VIRTUAL
|  	select ARCH_HAS_DEBUG_VM_PGTABLE
| @@ -146,7 +147,6 @@ config ARM64
|  	select GENERIC_ARCH_TOPOLOGY
|  	select GENERIC_CLOCKEVENTS_BROADCAST
|  	select GENERIC_CPU_AUTOPROBE
| -	select GENERIC_CPU_CACHE_MAINTENANCE
|  	select GENERIC_CPU_DEVICES
|  	select GENERIC_CPU_VULNERABILITIES
|  	select GENERIC_EARLY_IOREMAP
| diff --git a/lib/Kconfig b/lib/Kconfig
| index 09aec4a1e13f..ac223e627bc5 100644
| --- a/lib/Kconfig
| +++ b/lib/Kconfig
| @@ -544,8 +544,9 @@ config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
|  	bool
|  
|  config GENERIC_CPU_CACHE_MAINTENANCE
| -	bool
| -	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
| +	def_bool y
| +	depends on ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
| +	depends on ARM64
|  
|  config ARCH_HAS_MEMREMAP_COMPAT_ALIGN
|  	bool

implies (to me at least) that arm64 has memregion invalidation as an architectural feature and that the GENERIC_CPU_CACHE_MAINTENANCE option is a just common cross-arch code, like generic entry etc, rather than being the option gating the drivers that provide the feature in the first place.

I didn't really care which way it went, and was gonna post something to squash and avoid another revision, but I found the resultant Kconfig setup to be make less sense to me than what came before. If the switched around version is less likely to be problematic etc, then sure, but I amn't convinced by switching it at a first glance.

#6 lore raw

Re: [PATCH v6 3/7] lib: Support ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION

Quoted 21 lines · On Tue, 18 Nov 2025 00:13:07 +0000 Conor Dooley <[email protected]> wrote:
Quoted 20 lines · Randy Dunlap

Hi,

Quoted 5 lines · Jonathan Cameron
lib/Kconfig +0 -0
index e629449dd2a3..e11136d188ae 100644

lib/Kconfig config MEMREGION · line 550

Quoted 9 lines
lib/Kconfig +4 -0
@@ -542,6 +542,10 @@ config MEMREGION
 config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
 	bool
 
+config GENERIC_CPU_CACHE_MAINTENANCE
+	bool
+	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
+
 config ARCH_HAS_MEMREMAP_COMPAT_ALIGN
 	bool  

Architectures and/or platforms select ARCH_HAS_*.

Quoted 8 lines
Quoted 4 lines

With this change above, it becomes the only entry in lib/Kconfig that does "select ARCH_HAS_anytning".

so I think this is wrong, back*wards.

Maybe it is backwards, but I feel like this way is more logical. ARM64 has memregion invalidation only because this generic approach is enabled, so the arch selects what it needs to get the support.

Exactly this. Catalin requested this form in response to an earlier version where arm64 Kconfig just had both selects for pretty much that reason. This is expected to be used on a subset of architectures. It is similar to things like GENERIC_ARCH_NUMA in this respect (though the arch_numa_init() etc in there are called only from other arch code so no ARCH_HAS_ symbols are associated with them).

Quoted 1 line

Alternatively, something like

I'm fine with this solution if Randy prefers it.

Thanks for your help with this.

Jonathan

Quoted 48 lines
| diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
| index 5f7f63d24931..75b2507f7eb2 100644
| --- a/arch/arm64/Kconfig
| +++ b/arch/arm64/Kconfig
| @@ -21,6 +21,7 @@ config ARM64
|  	select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE
|  	select ARCH_HAS_CACHE_LINE_SIZE
|  	select ARCH_HAS_CC_PLATFORM
| +	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
|  	select ARCH_HAS_CURRENT_STACK_POINTER
|  	select ARCH_HAS_DEBUG_VIRTUAL
|  	select ARCH_HAS_DEBUG_VM_PGTABLE
| @@ -146,7 +147,6 @@ config ARM64
|  	select GENERIC_ARCH_TOPOLOGY
|  	select GENERIC_CLOCKEVENTS_BROADCAST
|  	select GENERIC_CPU_AUTOPROBE
| -	select GENERIC_CPU_CACHE_MAINTENANCE
|  	select GENERIC_CPU_DEVICES
|  	select GENERIC_CPU_VULNERABILITIES
|  	select GENERIC_EARLY_IOREMAP
| diff --git a/lib/Kconfig b/lib/Kconfig
| index 09aec4a1e13f..ac223e627bc5 100644
| --- a/lib/Kconfig
| +++ b/lib/Kconfig
| @@ -544,8 +544,9 @@ config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
|  	bool
|  
|  config GENERIC_CPU_CACHE_MAINTENANCE
| -	bool
| -	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
| +	def_bool y
| +	depends on ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
| +	depends on ARM64
|  
|  config ARCH_HAS_MEMREMAP_COMPAT_ALIGN
|  	bool

implies (to me at least) that arm64 has memregion invalidation as an architectural feature and that the GENERIC_CPU_CACHE_MAINTENANCE option is a just common cross-arch code, like generic entry etc, rather than being the option gating the drivers that provide the feature in the first place.

I didn't really care which way it went, and was gonna post something to squash and avoid another revision, but I found the resultant Kconfig setup to be make less sense to me than what came before. If the switched around version is less likely to be problematic etc, then sure, but I amn't convinced by switching it at a first glance.

#7 lore raw

Re: [PATCH v6 3/7] lib: Support ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION

Quoted 40 lines · Jonathan Cameron
Quoted 21 lines · On Tue, 18 Nov 2025 00:13:07 +0000 Conor Dooley <[email protected]> wrote:
Quoted 20 lines · Randy Dunlap

Hi,

Quoted 5 lines · Jonathan Cameron
lib/Kconfig +0 -0
index e629449dd2a3..e11136d188ae 100644

lib/Kconfig config MEMREGION · line 550

Quoted 9 lines
lib/Kconfig +4 -0
@@ -542,6 +542,10 @@ config MEMREGION
 config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
 	bool
 
+config GENERIC_CPU_CACHE_MAINTENANCE
+	bool
+	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
+
 config ARCH_HAS_MEMREMAP_COMPAT_ALIGN
 	bool  

Architectures and/or platforms select ARCH_HAS_*.

Quoted 8 lines
Quoted 4 lines

With this change above, it becomes the only entry in lib/Kconfig that does "select ARCH_HAS_anytning".

so I think this is wrong, back*wards.

Maybe it is backwards, but I feel like this way is more logical. ARM64 has memregion invalidation only because this generic approach is enabled, so the arch selects what it needs to get the support.

Exactly this. Catalin requested this form in response to an earlier version where arm64 Kconfig just had both selects for pretty much that reason. This is expected to be used on a subset of architectures. It is similar to things like GENERIC_ARCH_NUMA in this respect (though the arch_numa_init() etc in there are called only from other arch code so no ARCH_HAS_ symbols are associated with them).

Quoted 3 lines
Quoted 1 line

Alternatively, something like

I'm fine with this solution if Randy prefers it.

I do much prefer this alternative.

Quoted 1 line

Thanks for your help with this.

Thanks for listening.

Quoted 47 lines
Quoted 47 lines
| diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
| index 5f7f63d24931..75b2507f7eb2 100644
| --- a/arch/arm64/Kconfig
| +++ b/arch/arm64/Kconfig
| @@ -21,6 +21,7 @@ config ARM64
|  	select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE
|  	select ARCH_HAS_CACHE_LINE_SIZE
|  	select ARCH_HAS_CC_PLATFORM
| +	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
|  	select ARCH_HAS_CURRENT_STACK_POINTER
|  	select ARCH_HAS_DEBUG_VIRTUAL
|  	select ARCH_HAS_DEBUG_VM_PGTABLE
| @@ -146,7 +147,6 @@ config ARM64
|  	select GENERIC_ARCH_TOPOLOGY
|  	select GENERIC_CLOCKEVENTS_BROADCAST
|  	select GENERIC_CPU_AUTOPROBE
| -	select GENERIC_CPU_CACHE_MAINTENANCE
|  	select GENERIC_CPU_DEVICES
|  	select GENERIC_CPU_VULNERABILITIES
|  	select GENERIC_EARLY_IOREMAP
| diff --git a/lib/Kconfig b/lib/Kconfig
| index 09aec4a1e13f..ac223e627bc5 100644
| --- a/lib/Kconfig
| +++ b/lib/Kconfig
| @@ -544,8 +544,9 @@ config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
|  	bool
|  
|  config GENERIC_CPU_CACHE_MAINTENANCE
| -	bool
| -	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
| +	def_bool y
| +	depends on ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
| +	depends on ARM64
|  
|  config ARCH_HAS_MEMREMAP_COMPAT_ALIGN
|  	bool

implies (to me at least) that arm64 has memregion invalidation as an architectural feature and that the GENERIC_CPU_CACHE_MAINTENANCE option is a just common cross-arch code, like generic entry etc, rather than being the option gating the drivers that provide the feature in the first place.

I didn't really care which way it went, and was gonna post something to squash and avoid another revision, but I found the resultant Kconfig setup to be make less sense to me than what came before. If the switched around version is less likely to be problematic etc, then sure, but I amn't convinced by switching it at a first glance.

Signature · 1 line
~Randy
author Acked-by
#8 lore raw

Re: [PATCH v6 3/7] lib: Support ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION

Quoted 43 lines · On Tue, 18 Nov 2025 17:18:31 -0800 Randy Dunlap <[email protected]> wrote:
Quoted 42 lines · Jonathan Cameron
Quoted 21 lines · On Tue, 18 Nov 2025 00:13:07 +0000 Conor Dooley <[email protected]> wrote:
Quoted 20 lines · Randy Dunlap

Hi,

Quoted 5 lines · Jonathan Cameron
lib/Kconfig +0 -0
index e629449dd2a3..e11136d188ae 100644

lib/Kconfig config MEMREGION · line 550

Quoted 9 lines
lib/Kconfig +4 -0
@@ -542,6 +542,10 @@ config MEMREGION
 config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
 	bool
 
+config GENERIC_CPU_CACHE_MAINTENANCE
+	bool
+	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
+
 config ARCH_HAS_MEMREMAP_COMPAT_ALIGN
 	bool    

Architectures and/or platforms select ARCH_HAS_*.

Quoted 8 lines
Quoted 4 lines

With this change above, it becomes the only entry in lib/Kconfig that does "select ARCH_HAS_anytning".

so I think this is wrong, back*wards.

Maybe it is backwards, but I feel like this way is more logical. ARM64 has memregion invalidation only because this generic approach is enabled, so the arch selects what it needs to get the support.

Exactly this. Catalin requested this form in response to an earlier version where arm64 Kconfig just had both selects for pretty much that reason. This is expected to be used on a subset of architectures. It is similar to things like GENERIC_ARCH_NUMA in this respect (though the arch_numa_init() etc in there are called only from other arch code so no ARCH_HAS_ symbols are associated with them).

Quoted 1 line

Alternatively, something like

Quoted 7 lines
Quoted 1 line

I'm fine with this solution if Randy prefers it.

I do much prefer this alternative.

Quoted 1 line

Thanks for your help with this.

Thanks for listening.

Conor,

Given it is your proposed solution, I'm guessing you'll either spin a patch on top or squash it into original. If you spin a patch for this.

Thanks again!

Jonathan

Quoted 51 lines
Quoted 49 lines
Quoted 49 lines

| diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
| index 5f7f63d24931..75b2507f7eb2 100644
| --- a/arch/arm64/Kconfig
| +++ b/arch/arm64/Kconfig
| @@ -21,6 +21,7 @@ config ARM64
|  	select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE
|  	select ARCH_HAS_CACHE_LINE_SIZE
|  	select ARCH_HAS_CC_PLATFORM
| +	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
|  	select ARCH_HAS_CURRENT_STACK_POINTER
|  	select ARCH_HAS_DEBUG_VIRTUAL
|  	select ARCH_HAS_DEBUG_VM_PGTABLE
| @@ -146,7 +147,6 @@ config ARM64
|  	select GENERIC_ARCH_TOPOLOGY
|  	select GENERIC_CLOCKEVENTS_BROADCAST
|  	select GENERIC_CPU_AUTOPROBE
| -	select GENERIC_CPU_CACHE_MAINTENANCE
|  	select GENERIC_CPU_DEVICES
|  	select GENERIC_CPU_VULNERABILITIES
|  	select GENERIC_EARLY_IOREMAP
| diff --git a/lib/Kconfig b/lib/Kconfig
| index 09aec4a1e13f..ac223e627bc5 100644
| --- a/lib/Kconfig
| +++ b/lib/Kconfig
| @@ -544,8 +544,9 @@ config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
|  	bool
|  
|  config GENERIC_CPU_CACHE_MAINTENANCE
| -	bool
| -	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
| +	def_bool y
| +	depends on ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
| +	depends on ARM64
|  
|  config ARCH_HAS_MEMREMAP_COMPAT_ALIGN
|  	bool

implies (to me at least) that arm64 has memregion invalidation as an architectural feature and that the GENERIC_CPU_CACHE_MAINTENANCE option is a just common cross-arch code, like generic entry etc, rather than being the option gating the drivers that provide the feature in the first place.

I didn't really care which way it went, and was gonna post something to squash and avoid another revision, but I found the resultant Kconfig setup to be make less sense to me than what came before. If the switched around version is less likely to be problematic etc, then sure, but I amn't convinced by switching it at a first glance.

maintainer
#9 lore raw

Re: [PATCH v6 3/7] lib: Support ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION

Quoted 52 lines · Jonathan Cameron
Quoted 49 lines · On Tue, 18 Nov 2025 17:18:31 -0800 Randy Dunlap <[email protected]> wrote:
Quoted 40 lines · Jonathan Cameron
Quoted 21 lines · On Tue, 18 Nov 2025 00:13:07 +0000 Conor Dooley <[email protected]> wrote:
Quoted 20 lines · Randy Dunlap

Hi,

Quoted 5 lines · Jonathan Cameron
lib/Kconfig +0 -0
index e629449dd2a3..e11136d188ae 100644

lib/Kconfig config MEMREGION · line 550

Quoted 9 lines
lib/Kconfig +4 -0
@@ -542,6 +542,10 @@ config MEMREGION
 config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
 	bool
 
+config GENERIC_CPU_CACHE_MAINTENANCE
+	bool
+	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
+
 config ARCH_HAS_MEMREMAP_COMPAT_ALIGN
 	bool    

Architectures and/or platforms select ARCH_HAS_*.

Quoted 8 lines
Quoted 4 lines

With this change above, it becomes the only entry in lib/Kconfig that does "select ARCH_HAS_anytning".

so I think this is wrong, back*wards.

Maybe it is backwards, but I feel like this way is more logical. ARM64 has memregion invalidation only because this generic approach is enabled, so the arch selects what it needs to get the support.

Exactly this. Catalin requested this form in response to an earlier version where arm64 Kconfig just had both selects for pretty much that reason. This is expected to be used on a subset of architectures. It is similar to things like GENERIC_ARCH_NUMA in this respect (though the arch_numa_init() etc in there are called only from other arch code so no ARCH_HAS_ symbols are associated with them).

Quoted 3 lines
Quoted 1 line

Alternatively, something like

I'm fine with this solution if Randy prefers it.

I do much prefer this alternative.

Quoted 1 line

Thanks for your help with this.

Quoted 8 lines
Quoted 1 line

Thanks for listening.

Conor,

Given it is your proposed solution, I'm guessing you'll either spin a patch on top or squash it into original. If you spin a patch for this.

New patch I think, since you say Catalin specifically asked for the current setup.

Quoted 57 lines

Thanks again!

Jonathan

Quoted 51 lines
Quoted 49 lines
Quoted 49 lines

| diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
| index 5f7f63d24931..75b2507f7eb2 100644
| --- a/arch/arm64/Kconfig
| +++ b/arch/arm64/Kconfig
| @@ -21,6 +21,7 @@ config ARM64
|  	select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE
|  	select ARCH_HAS_CACHE_LINE_SIZE
|  	select ARCH_HAS_CC_PLATFORM
| +	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
|  	select ARCH_HAS_CURRENT_STACK_POINTER
|  	select ARCH_HAS_DEBUG_VIRTUAL
|  	select ARCH_HAS_DEBUG_VM_PGTABLE
| @@ -146,7 +147,6 @@ config ARM64
|  	select GENERIC_ARCH_TOPOLOGY
|  	select GENERIC_CLOCKEVENTS_BROADCAST
|  	select GENERIC_CPU_AUTOPROBE
| -	select GENERIC_CPU_CACHE_MAINTENANCE
|  	select GENERIC_CPU_DEVICES
|  	select GENERIC_CPU_VULNERABILITIES
|  	select GENERIC_EARLY_IOREMAP
| diff --git a/lib/Kconfig b/lib/Kconfig
| index 09aec4a1e13f..ac223e627bc5 100644
| --- a/lib/Kconfig
| +++ b/lib/Kconfig
| @@ -544,8 +544,9 @@ config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
|  	bool
|  
|  config GENERIC_CPU_CACHE_MAINTENANCE
| -	bool
| -	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
| +	def_bool y
| +	depends on ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
| +	depends on ARM64
|  
|  config ARCH_HAS_MEMREMAP_COMPAT_ALIGN
|  	bool

implies (to me at least) that arm64 has memregion invalidation as an architectural feature and that the GENERIC_CPU_CACHE_MAINTENANCE option is a just common cross-arch code, like generic entry etc, rather than being the option gating the drivers that provide the feature in the first place.

I didn't really care which way it went, and was gonna post something to squash and avoid another revision, but I found the resultant Kconfig setup to be make less sense to me than what came before. If the switched around version is less likely to be problematic etc, then sure, but I amn't convinced by switching it at a first glance.

#10 lore raw

Re: [PATCH v6 3/7] lib: Support ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION

Quoted 57 lines · On Wed, 19 Nov 2025 18:44:43 +0000 Conor Dooley <[email protected]> wrote:
Quoted 56 lines · Jonathan Cameron
Quoted 43 lines · On Tue, 18 Nov 2025 17:18:31 -0800 Randy Dunlap <[email protected]> wrote:
Quoted 42 lines · Jonathan Cameron
Quoted 21 lines · On Tue, 18 Nov 2025 00:13:07 +0000 Conor Dooley <[email protected]> wrote:
Quoted 20 lines · Randy Dunlap

Hi,

Quoted 5 lines · Jonathan Cameron
lib/Kconfig +0 -0
index e629449dd2a3..e11136d188ae 100644

lib/Kconfig config MEMREGION · line 550

Quoted 9 lines
lib/Kconfig +4 -0
@@ -542,6 +542,10 @@ config MEMREGION
 config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
 	bool
 
+config GENERIC_CPU_CACHE_MAINTENANCE
+	bool
+	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
+
 config ARCH_HAS_MEMREMAP_COMPAT_ALIGN
 	bool      

Architectures and/or platforms select ARCH_HAS_*.

Quoted 8 lines
Quoted 4 lines

With this change above, it becomes the only entry in lib/Kconfig that does "select ARCH_HAS_anytning".

so I think this is wrong, back*wards.

Maybe it is backwards, but I feel like this way is more logical. ARM64 has memregion invalidation only because this generic approach is enabled, so the arch selects what it needs to get the support.

Exactly this. Catalin requested this form in response to an earlier version where arm64 Kconfig just had both selects for pretty much that reason. This is expected to be used on a subset of architectures. It is similar to things like GENERIC_ARCH_NUMA in this respect (though the arch_numa_init() etc in there are called only from other arch code so no ARCH_HAS_ symbols are associated with them).

Quoted 1 line

Alternatively, something like

Quoted 7 lines
Quoted 1 line

I'm fine with this solution if Randy prefers it.

I do much prefer this alternative.

Quoted 1 line

Thanks for your help with this.

Thanks for listening.

Conor,

Quoted 7 lines
Quoted 4 lines

Given it is your proposed solution, I'm guessing you'll either spin a patch on top or squash it into original. If you spin a patch for this.

New patch I think, since you say Catalin specifically asked for the current setup.

Whilst Catalin proposed the form used, the basis was about having two entrees for effectively the same thing in arm64/Kconfig and this still has the single entry property so should be fine.

Jonathan

Quoted 59 lines
Quoted 58 lines

Thanks again!

Jonathan

Quoted 51 lines
Quoted 49 lines
Quoted 49 lines
  
| diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
| index 5f7f63d24931..75b2507f7eb2 100644
| --- a/arch/arm64/Kconfig
| +++ b/arch/arm64/Kconfig
| @@ -21,6 +21,7 @@ config ARM64
|  	select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE
|  	select ARCH_HAS_CACHE_LINE_SIZE
|  	select ARCH_HAS_CC_PLATFORM
| +	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
|  	select ARCH_HAS_CURRENT_STACK_POINTER
|  	select ARCH_HAS_DEBUG_VIRTUAL
|  	select ARCH_HAS_DEBUG_VM_PGTABLE
| @@ -146,7 +147,6 @@ config ARM64
|  	select GENERIC_ARCH_TOPOLOGY
|  	select GENERIC_CLOCKEVENTS_BROADCAST
|  	select GENERIC_CPU_AUTOPROBE
| -	select GENERIC_CPU_CACHE_MAINTENANCE
|  	select GENERIC_CPU_DEVICES
|  	select GENERIC_CPU_VULNERABILITIES
|  	select GENERIC_EARLY_IOREMAP
| diff --git a/lib/Kconfig b/lib/Kconfig
| index 09aec4a1e13f..ac223e627bc5 100644
| --- a/lib/Kconfig
| +++ b/lib/Kconfig
| @@ -544,8 +544,9 @@ config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
|  	bool
|  
|  config GENERIC_CPU_CACHE_MAINTENANCE
| -	bool
| -	select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
| +	def_bool y
| +	depends on ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
| +	depends on ARM64
|  
|  config ARCH_HAS_MEMREMAP_COMPAT_ALIGN
|  	bool

implies (to me at least) that arm64 has memregion invalidation as an architectural feature and that the GENERIC_CPU_CACHE_MAINTENANCE option is a just common cross-arch code, like generic entry etc, rather than being the option gating the drivers that provide the feature in the first place.

I didn't really care which way it went, and was gonna post something to squash and avoid another revision, but I found the resultant Kconfig setup to be make less sense to me than what came before. If the switched around version is less likely to be problematic etc, then sure, but I amn't convinced by switching it at a first glance.

#11 lore raw

PATCH v6 4/7 arm64: Select GENERIC_CPU_CACHE_MAINTENANCE

In reply to Jonathan Cameron

The generic CPU cache maintenance framework provides a way to register drivers for devices implementing the underlying support for cpu_cache_has_invalidate_memregion(). Enable it for arm64 by selecting GENERIC_CPU_CACHE_MAINTENANCE which provides the implementation for, and in turn selects, ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION.

---
v6: No change.
v5: No change.
v4: Drop select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION as that
is now selected by GENERIC_CPU_CACHE_MAINTENANCE (Catalin Marinas) Picked up tag from Catalin. (thanks!)

---
 arch/arm64/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/Kconfig +1 -0
index 6663ffd23f25..893e0af0bc51 100644
@@ -149,6 +149,7 @@ config ARM64
 	select GENERIC_ARCH_TOPOLOGY
 	select GENERIC_CLOCKEVENTS_BROADCAST
 	select GENERIC_CPU_AUTOPROBE
+	select GENERIC_CPU_CACHE_MAINTENANCE
 	select GENERIC_CPU_DEVICES
 	select GENERIC_CPU_VULNERABILITIES
 	select GENERIC_EARLY_IOREMAP
Signature · 1 line
2.48.1
#12 lore raw

PATCH v6 5/7 MAINTAINERS: Add Jonathan Cameron to drivers/cache and add lib/cache_maint.c + header

In reply to Jonathan Cameron

Seems unfair to inflict the cache-coherency drivers on Conor with out also stepping up as a second maintainer for drivers/cache.

Include the library support for cache-coherency maintenance drivers to the existing entry.

---
v6: No change.
v5: No change.
v4: Tag from Conor (thanks!) Updated commit message to make it
reflect the added files.

---
 MAINTAINERS | 3 +++
 1 file changed, 3 insertions(+)
MAINTAINERS +3 -0
index 46126ce2f968..b517f2703615 100644
@@ -24417,10 +24417,13 @@ F:	drivers/staging/
 
 STANDALONE CACHE CONTROLLER DRIVERS
 M:	Conor Dooley <[email protected]>
+M:	Jonathan Cameron <[email protected]>
 S:	Maintained
 T:	git https://git.kernel.org/pub/scm/linux/kernel/git/conor/linux.git/
 F:	Documentation/devicetree/bindings/cache/
 F:	drivers/cache
+F:	include/cache_coherency.h
+F:	lib/cache_maint.c
 
 STARFIRE/DURALAN NETWORK DRIVER
 M:	Ion Badulescu <[email protected]>
Signature · 1 line
2.48.1
#13 lore raw

PATCH v6 6/7 cache: Make top level Kconfig menu a boolean dependent on RISCV

In reply to Jonathan Cameron

The next patch will add a new type of cache maintenance driver responsible for flushing deeper than is necessary for non coherent DMA (current use case of drivers/cache drivers), as needed when performing operations such as memory hotplug and security unlocking of persistent memory. The two types of operation are similar enough to share a drivers/cache directory and MAINTAINERS but are otherwise currently unrelated.

To avoid confusion have two separate menus. Each has dependencies that are implemented by making them boolean symbols, here CACHEMAINT_FOR_DMA which is dependent on RISCV as all driver are currently for platforms of that architecture. Set new symbol default to y to avoid breaking existing configs. This has no affect on actual code built, just visibility of the menu.

---
v6: New patch as suggested by Arnd.

---
 drivers/cache/Kconfig | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/cache/Kconfig +11 -4
index db51386c663a..59a79df4c0ce 100644
@@ -1,9 +1,17 @@
 # SPDX-License-Identifier: GPL-2.0
-menu "Cache Drivers"
+
+menuconfig CACHEMAINT_FOR_DMA
+	bool "Cache management for noncoherent DMA"
+	depends on RISCV
+	default y
+	help
+	  These drivers implement support for noncoherent DMA master devices
+	  on platforms that lack the standard CPU interfaces for this.
+
+if CACHEMAINT_FOR_DMA
 
 config AX45MP_L2_CACHE
 	bool "Andes Technology AX45MP L2 Cache controller"
-	depends on RISCV
 	select RISCV_NONSTANDARD_CACHE_OPS
 	help
 	  Support for the L2 cache controller on Andes Technology AX45MP platforms.
@@ -16,7 +24,6 @@ config SIFIVE_CCACHE
 
 config STARFIVE_STARLINK_CACHE
 	bool "StarFive StarLink Cache controller"
-	depends on RISCV
 	depends on ARCH_STARFIVE
 	depends on 64BIT
 	select RISCV_DMA_NONCOHERENT
@@ -24,4 +31,4 @@ config STARFIVE_STARLINK_CACHE
 	help
 	  Support for the StarLink cache controller IP from StarFive.
 
-endmenu
+endif #CACHEMAINT_FOR_DMA
Signature · 1 line
2.48.1
#14 lore raw

PATCH v6 7/7 cache: Support cache maintenance for HiSilicon SoC Hydra Home Agent

In reply to Jonathan Cameron

From: Yushan Wang <[email protected]>

Hydra Home Agent is a device used to maintain cache coherency. Add support for explicit cache maintenance operations using it. A system has multiple of these agents. Whilst only one agent is responsible for a given cache line, interleave means that for a range operation, responsibility for the cache lines making up the range will typically be spread across multiple instances.

Put this driver on a new Kconfig menu under drivers/cache. The short description as memory hotplug like operations is intended to cover the somewhat complex set of cases where this unit applies and differentiate it clearly from typical non coherent DMA flows.

---
v6: New menu as suggested by Arnd. The description and naming may want
updating as more drivers are upstreamed and perhaps the usecase based description is not sufficient. (Thanks Arnd!)
v5: Drop stale comment on devm_ioremap_resource() as it is no longer used.
Also drop mention from patch description (Conor)

Add some overview comments to top of driver and improve comment on searching for a cacheline to be explicit about what happens if it is not found (as not in scope for device, or happens not to be in any caches). (Conor)
Also update the commit message to make it clear there are always multiple instances of this unit in a system (Conor)

v4: Update for naming changes around device / instance.
Switch to kref put based freeing via helper.

---
 drivers/cache/Kconfig        |  22 ++++
 drivers/cache/Makefile       |   2 +
 drivers/cache/hisi_soc_hha.c | 194 +++++++++++++++++++++++++++++++++++
 3 files changed, 218 insertions(+)
drivers/cache/Kconfig +22 -0
index 59a79df4c0ce..1518449d47b5 100644
@@ -32,3 +32,25 @@ config STARFIVE_STARLINK_CACHE
 	  Support for the StarLink cache controller IP from StarFive.
 
 endif #CACHEMAINT_FOR_DMA
+
+menuconfig CACHEMAINT_FOR_HOTPLUG
+	bool "Cache management for memory hot plug like operations"
+	depends on GENERIC_CPU_CACHE_MAINTENANCE
+	help
+	  These drivers implement cache management for flows where it is necessary
+	  to flush data from all host caches.
+
+if CACHEMAINT_FOR_HOTPLUG
+
+config HISI_SOC_HHA
+	tristate "HiSilicon Hydra Home Agent (HHA) device driver"
+	depends on (ARM64 && ACPI) || COMPILE_TEST
+	help
+	  The Hydra Home Agent (HHA) is responsible for cache coherency
+	  on the SoC. This drivers enables the cache maintenance functions of
+	  the HHA.
+
+	  This driver can be built as a module. If so, the module will be
+	  called hisi_soc_hha.
+
+endif #CACHEMAINT_FOR_HOTPLUG
drivers/cache/Makefile +2 -0
index 55c5e851034d..b3362b15d6c1 100644
@@ -3,3 +3,5 @@
 obj-$(CONFIG_AX45MP_L2_CACHE)		+= ax45mp_cache.o
 obj-$(CONFIG_SIFIVE_CCACHE)		+= sifive_ccache.o
 obj-$(CONFIG_STARFIVE_STARLINK_CACHE)	+= starfive_starlink_cache.o
+
+obj-$(CONFIG_HISI_SOC_HHA)		+= hisi_soc_hha.o
drivers/cache/hisi_soc_hha.c new file +194 -0

194 lines not on this page · raw message

Signature · 1 line
2.48.1