Cache coherency management subsystem
Subsystems (10)
v5 cover Cache coherency management subsystem
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.
How to merge?
- Current suggestion would be via 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 (3):
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
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 | 15 +++ 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, 439 insertions(+), 8 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
PATCH v5 1/6 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.
---
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v5 2/6 memregion: Support fine grained invalidate by cpu_cache_invalidate_memregion()
In reply to Jonathan CameronFrom: 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().
---
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v5 3/6 lib: Support ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
In reply to Jonathan CameronFrom: 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 viaCONFIG_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.
---
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
@@ -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
@@ -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
@@ -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
PATCH v5 4/6 arm64: Select GENERIC_CPU_CACHE_MAINTENANCE
In reply to Jonathan CameronThe 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.
---
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
@@ -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
PATCH v5 5/6 MAINTAINERS: Add Jonathan Cameron to drivers/cache and add lib/cache_maint.c + header
In reply to Jonathan CameronSeems 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.
---
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
@@ -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
PATCH v5 6/6 cache: Support cache maintenance for HiSilicon SoC Hydra Home Agent
In reply to Jonathan CameronFrom: 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.
---
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 | 15 +++ drivers/cache/Makefile | 2 + drivers/cache/hisi_soc_hha.c | 194 +++++++++++++++++++++++++++++++++++ 3 files changed, 211 insertions(+)
drivers/cache/Kconfig +15 -0
@@ -1,6 +1,21 @@ # SPDX-License-Identifier: GPL-2.0 menu "Cache Drivers" +if GENERIC_CPU_CACHE_MAINTENANCE + +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 + config AX45MP_L2_CACHE bool "Andes Technology AX45MP L2 Cache controller" depends on RISCV
drivers/cache/Makefile +2 -0
@@ -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
Conor Dooley
maintainerArnd,
Quoted 8 lines · Jonathan Cameron
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.
Quoted 6 lines
Includes parameter changes to
cpu_cache_invalidate_memregion()but no functional changes for architectures that already support this call.How to merge?
- Current suggestion would be via Conor'sdrivers/cachetree which routes through the SoC tree.
I was gonna put this in linux-next, but I'm not really sure that Arnd
was satisfied with the discussion on the previous version about
suitability of the directory: https://lore.kernel.org/all/[email protected]/
Arnd, did that response satisfy you, or nah?
Cheers,
Conor.
Quoted 5 lines
* 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.
Quoted 18 lines · On Sat, 8 Nov 2025 20:02:52 +0000 Conor Dooley <[email protected]> wrote:
Arnd,
Quoted 8 lines · Jonathan Cameron
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.
Quoted 6 lines
Includes parameter changes to
cpu_cache_invalidate_memregion()but no functional changes for architectures that already support this call.How to merge?
- Current suggestion would be via Conor'sdrivers/cachetree which routes through the SoC tree.
Quoted 5 lines
I was gonna put this in linux-next, but I'm not really sure that Arnd
was satisfied with the discussion on the previous version about
suitability of the directory: https://lore.kernel.org/all/[email protected]/Arnd, did that response satisfy you, or nah?
Seems Arnd is busy. Conor, if you are happy doing so, maybe push it to a tree linux-next picks up, but hold off on the pull request until Arnd has had a chance to reply?
Jonathan
Quoted 10 lines
Cheers,
Conor.Quoted 5 lines
* 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.
Conor Dooley
maintainerQuoted 25 lines · Jonathan Cameron
Quoted 22 lines · On Sat, 8 Nov 2025 20:02:52 +0000 Conor Dooley <[email protected]> wrote:
Arnd,
Quoted 8 lines · Jonathan Cameron
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.
Quoted 6 lines
Includes parameter changes to
cpu_cache_invalidate_memregion()but no functional changes for architectures that already support this call.How to merge?
- Current suggestion would be via Conor'sdrivers/cachetree which routes through the SoC tree.I was gonna put this in linux-next, but I'm not really sure that Arnd
was satisfied with the discussion on the previous version about
suitability of the directory: https://lore.kernel.org/all/[email protected]/
Quoted 5 lines
Quoted 1 line
Arnd, did that response satisfy you, or nah?
Seems Arnd is busy. Conor, if you are happy doing so, maybe push it to a tree linux-next picks up, but hold off on the pull request until Arnd has had a chance to reply?
Yeah, I did step one of that last night and will put it in linux-next from Monday. Ultimately the PR goes to Arnd, so he can judge it there anyway.
Arnd Bergmann
maintainerQuoted 25 lines · Conor Dooley
Quoted 24 lines · Jonathan Cameron
Quoted 22 lines · On Sat, 8 Nov 2025 20:02:52 +0000 Conor Dooley <[email protected]> wrote:
Quoted 8 lines · Jonathan Cameron
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.
Quoted 6 lines
Includes parameter changes to
cpu_cache_invalidate_memregion()but no functional changes for architectures that already support this call.How to merge?
- Current suggestion would be via Conor'sdrivers/cachetree which routes through the SoC tree.I was gonna put this in linux-next, but I'm not really sure that Arnd
was satisfied with the discussion on the previous version about
suitability of the directory: https://lore.kernel.org/all/[email protected]/Arnd, did that response satisfy you, or nah?
Quoted 7 lines
Quoted 3 lines
Seems Arnd is busy. Conor, if you are happy doing so, maybe push it to a tree linux-next picks up, but hold off on the pull request until Arnd has had a chance to reply?
Yeah, I did step one of that last night and will put it in linux-next from Monday. Ultimately the PR goes to Arnd, so he can judge it there anyway.
Sorry about the delay on my side. I've read up on it again and understand better where we are with this now.
I think the implementation is fine, and placing it in drivers/cache/ is also ok, given that we don't have a better place for it.
However, this does feel sufficiently different from the three existing drivers in drivers/cache that I think we should have separate submenus in Kconfig and describe them differently:
- the arch/riscv drivers are specifically for managing coherency between the CPU and any device driver using the linux/dma-mapping.h interfaces to manage coherency using CPU specific interfaces.
- the new driver does not interface with linux/dma-mapping.h or a CPU specific register set, and as I understand that would make no sense here. The only similarities are that it manages coherency between multiple entities that access the same memory and have private caches for that.
If we can come up with better names for the two things, I'd like them to have distinct submenus. Something like the draft below for the existing drivers would work, in addition to a new menu that only contains the one driver for now. I've moved the 'depends on RISCV' into the 'menu' here, since that is the only thing using it today (32-bit arm has the same thing in arch/arm/mm/cache-*.S with a different interface, most others only have an architected interface).
Arnd
---
drivers/cache/Kconfig +5 -3
@@ -1,9 +1,12 @@ # SPDX-License-Identifier: GPL-2.0 -menu "Cache Drivers" +menu "Cache management for noncoherent DMA" + depends on RISCV + help + These drivers implement support for noncoherent DMA master devices + on platforms that lack the standard CPU interfaces for this. 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 +19,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
Quoted 54 lines · On Fri, 14 Nov 2025 15:07:33 +0100 "Arnd Bergmann" <[email protected]> wrote:
Quoted 25 lines · Conor Dooley
Quoted 24 lines · Jonathan Cameron
Quoted 22 lines · On Sat, 8 Nov 2025 20:02:52 +0000 Conor Dooley <[email protected]> wrote:
Quoted 8 lines · Jonathan Cameron
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.
Quoted 6 lines
Includes parameter changes to
cpu_cache_invalidate_memregion()but no functional changes for architectures that already support this call.How to merge?
- Current suggestion would be via Conor'sdrivers/cachetree which routes through the SoC tree.I was gonna put this in linux-next, but I'm not really sure that Arnd
was satisfied with the discussion on the previous version about
suitability of the directory: https://lore.kernel.org/all/[email protected]/Arnd, did that response satisfy you, or nah?
Quoted 7 lines
Quoted 3 lines
Seems Arnd is busy. Conor, if you are happy doing so, maybe push it to a tree linux-next picks up, but hold off on the pull request until Arnd has had a chance to reply?
Yeah, I did step one of that last night and will put it in linux-next from Monday. Ultimately the PR goes to Arnd, so he can judge it there anyway.
Sorry about the delay on my side. I've read up on it again and understand better where we are with this now.
I think the implementation is fine, and placing it in
drivers/cache/is also ok, given that we don't have a better place for it.However, this does feel sufficiently different from the three existing drivers in
drivers/cachethat I think we should have separate submenus inKconfigand describe them differently:- the
arch/riscvdrivers are specifically for managing coherency between the CPU and any device driver using thelinux/dma-mapping.hinterfaces to manage coherency using CPU specific interfaces.- the new driver does not interface with
linux/dma-mapping.hor a CPU specific register set, and as I understand that would make no sense here. The only similarities are that it manages coherency between multiple entities that access the same memory and have private caches for that.
Quoted 8 lines
If we can come up with better names for the two things, I'd like them to have distinct submenus. Something like the draft below for the existing drivers would work, in addition to a new menu that only contains the one driver for now. I've moved the 'depends on RISCV' into the 'menu' here, since that is the only thing using it today (32-bit arm has the same thing in
arch/arm/mm/cache-*.Swith a different interface, most others only have an architected interface).
Hi Arnd,
Thanks for taking another look.
Agreed splitting the menus reduces chance of confusion, so makes sense to me as well.
Implementation wise I think we have to use menuconfig + bool if we want to have help and dependencies and then an if block under that. The syntax for Kconfig always leaves me finding an example to copy rather than finding it intuitive
menuconfig CACHEMAINT_FOR_DMA
bool "Cache management for noncoherent DMA"
depends on RISCV
help
These drivers implement support for noncoherent DMA master devices on platforms that lack the standard CPU interfaces for this.
if CACHEMAINT_FOR_DMA
... drivers here...
endif #CACHEMAINT_FOR_DMA
menuconfig CACHEMAINT_FOR_HOTPLUG
bool "Cache management for hotplug like operations" depends on GENERIC_CPU_CACHE_MAINTENANCE
help
These drivers implement support for cache management flows as required for action such as memory hotplug on platforms where this is done by platform specific interfaces.
if CACHEMAINT_FOR_HOTPLUG
... drivers here
endif #CACHEMAINT_FOR_HOTPLUG
Alternative would be to hope the short text is enough and use
menu "Cache management for noncoherent DMA"
visible if RISCV
endmenu
I'm not sure if the 'hotplug like' is close enough to all the cases for device drivers that provide the services needed to implement ARCH_HAS_CPU_CACHE_INVALIDATE_MEMEGION
Alternative might be to phrase around pushing beyond the point of coherence, but that seems to be an ARM specific term and would seem to incorporate fine grained sharing where this interface might work but isn't a good solution.
Thanks,
Jonathan
Quoted 32 lines
Arnd
---
drivers/cache/Kconfig +5
-2@@ -1,9 +1,12 @@ # SPDX-License-Identifier: GPL-2.0 -menu "Cache Drivers" +menu "Cache management for noncoherent DMA" + depends on RISCV + help + These drivers implement support for noncoherent DMA master devices + on platforms that lack the standard CPU interfaces for this. config AX45MP_L2_CACHE bool "Andes Technology AX45MP L2 Cache controller" - depends on RISCV select RISCV_NONSTANDARD_CACHE_OPS helpSupport for the L2 cache controller on Andes Technology AX45MP platforms.
drivers/cache/Kconfig +0
-1@@ -16,7 +19,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
Arnd Bergmann
maintainerQuoted 33 lines · Jonathan Cameron
On Fri, 14 Nov 2025 15:07:33 +0100 "Arnd Bergmann" <[email protected]> wrote:
Hi Arnd,Thanks for taking another look.
Agreed splitting the menus reduces chance of confusion, so makes sense to me as well.
Implementation wise I think we have to use menuconfig + bool if we want to have help and dependencies and then an if block under that. The syntax for
Kconfigalways leaves me finding an example to copy rather than finding it intuitivemenuconfig
CACHEMAINT_FOR_DMA
bool "Cache management for noncoherent DMA"
depends on RISCV
help
These drivers implement support for noncoherent DMA master devices on platforms that lack the standard CPU interfaces for this.if
CACHEMAINT_FOR_DMA
... drivers here...endif #CACHEMAINT_FOR_DMA
menuconfig
CACHEMAINT_FOR_HOTPLUG
bool "Cache management for hotplug like operations" depends onGENERIC_CPU_CACHE_MAINTENANCE
help
These drivers implement support for cache management flows as required for action such as memory hotplug on platforms where this is done by platform specific interfaces.
Quoted 4 lines
if
CACHEMAINT_FOR_HOTPLUG
... drivers hereendif #CACHEMAINT_FOR_HOTPLUG
Works for me.
Quoted 3 lines
I'm not sure if the 'hotplug like' is close enough to all the cases for device drivers that provide the services needed to implement
ARCH_HAS_CPU_CACHE_INVALIDATE_MEMEGION
The _FOR_HOTPLUG does feel a little more specific than it should be, but I haven't come up with a better name for it yet. We'll probably figure that out if we ever get a second driver here.
Quoted 4 lines
Alternative might be to phrase around pushing beyond the point of coherence, but that seems to be an ARM specific term and would seem to incorporate fine grained sharing where this interface might work but isn't a good solution.
Agreed.
Arnd