| From: |
| Jonathan Cameron <Jonathan.Cameron-AT-huawei.com> |
| To: |
| Conor Dooley <conor-AT-kernel.org>, Catalin Marinas <catalin.marinas-AT-arm.com>, <linux-cxl-AT-vger.kernel.org>, <linux-arm-kernel-AT-lists.infradead.org>, <linux-arch-AT-vger.kernel.org>, <linux-mm-AT-kvack.org>, Dan Williams <dan.j.williams-AT-intel.com>, "H . Peter Anvin" <hpa-AT-zytor.com>, Peter Zijlstra <peterz-AT-infradead.org>, Andrew Morton <akpm-AT-linux-foundation.org> |
| Subject: |
| [PATCH v4 0/6] Cache coherency management subsystem |
| Date: |
| Wed, 22 Oct 2025 12:33:43 +0100 |
| Message-ID: |
| <20251022113349.1711388-1-Jonathan.Cameron@huawei.com> |
| Cc: |
| <james.morse-AT-arm.com>, Will Deacon <will-AT-kernel.org>, Davidlohr Bueso <dave-AT-stgolabs.net>, <linuxarm-AT-huawei.com>, Yushan Wang <wangyushan12-AT-huawei.com>, Lorenzo Pieralisi <lpieralisi-AT-kernel.org>, Mark Rutland <mark.rutland-AT-arm.com>, Dave Hansen <dave.hansen-AT-linux.intel.com>, Thomas Gleixner <tglx-AT-linutronix.de>, Ingo Molnar <mingo-AT-redhat.com>, Borislav Petkov <bp-AT-alien8.de>, <x86-AT-kernel.org>, Andy Lutomirski <luto-AT-kernel.org>, Dave Jiang <dave.jiang-AT-intel.com> |
| Archive-link: |
| Article |
Support system level interfaces for cache maintenance as found on some
ARM64 systems. This is needed for correct functionality during various
forms of memory hotplug (e.g. CXL). Typical hardware has MMIO interface
found via ACPI DSDT.
Includes parameter changes to cpu_cache_invalidate_memregion() but no
functional changes for architectures that already support this call.
How to merge? When this is ready to proceed (so subject to review
feedback on this version), I'm not sure what the best route into the
kernel is. Conor could take the lot via his tree for drivers/cache but
the generic changes perhaps suggest it might be better if Andrew
handles this? Any merge conflicts in drivers/cache will be trivial
build file stuff. Or maybe even take it throug one of the affected
trees such as CXL.
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 | 191 ++++++++++++++++++++++++++++++++
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, 436 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
--
2.48.1