Skip to contentSkip to conversation

Add SMCCC cache clean/invalidate provider

PATCH Superseded Srirangan Madhavan 2 participants 5 messages Jun 2

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover Add SMCCC cache clean/invalidate provider

This series adds an arm64 backend for memregion cache invalidation users based on the Arm SMCCC cache clean+invalidate interface.

Per DEN0028, this interface targets systems where a Normal Cacheable memory region can be modified in ways that are not handled by usual PE coherency mechanisms, and where VA-based CMOs may be too slow or insufficient for large ranges and/or system-cache implementations.

Representative use cases include device-backed memory state transitions where stale CPU/system cache lines must be invalidated reliably (for example secure erase, reset/offline flows, and dynamic memory reconfiguration).

Patch 1 introduces the Arm SMCCC cache clean/invalidate function IDs and transient return codes needed by callers [1].

Patch 2 adds a cache maintenance provider that:
- discovers SMCCC support and attributes at init time
- registers with the generic cache coherency framework used by cpu_cache_invalidate_memregion()
- handles transient BUSY/RATE_LIMITED responses with bounded retries

This patch set does not add a software fallback path; when firmware does not implement the SMCCC cache maintenance interface, the provider is not registered and existing behavior is preserved.

Reference:
[1] https://developer.arm.com/documentation/den0028/latest

Changes since RFC:
- Dropped the RFC tag.
- Moved the provider from arch/arm64/mm to drivers/cache.
- Added a dedicated CONFIG_ARM_SMCCC_CACHE option under the existing CACHEMAINT_FOR_HOTPLUG menu.
- Dropped the global-operation coalescing optimization.
- Dropped provider handling for SMCCC_RET_NOT_REQUIRED.
- Removed the unnecessary global provider pointer.
- Removed arm64_ prefixes from static provider-local names.
- Documented why these SMCCC Arch cache maintenance calls use SMC64.
- Anchored the SMCCC return-code comment to DEN0028 v1.7.
- Used fsleep() for retry backoff.
- Used unsigned long for retry delay values passed to fsleep().
- Skipped the final backoff sleep when no retry remains.
- Documented the bounded mutex hold time across the serialized retry sequence.
- Added mutex_destroy() on the registration failure path.

Srirangan Madhavan (2):
arm64: smccc: add cache clean/invalidate IDs and return codes
cache: add SMCCC-backed cache invalidate provider

 drivers/cache/Kconfig           |  11 +++
 drivers/cache/Makefile          |   1 +
 drivers/cache/arm_smccc_cache.c | 160 ++++++++++++++++++++++++++++++++
 include/linux/arm-smccc.h       |  21 ++++-
 tools/include/linux/arm-smccc.h |  21 ++++-
 5 files changed, 210 insertions(+), 4 deletions(-)
 create mode 100644 drivers/cache/arm_smccc_cache.c

base-commit: 3b3bea6d4b9c162f9e555905d96b8c1da67ecd5b

Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 arm64: smccc: add cache clean/invalidate IDs and return codes

Define SMCCC Arch function IDs for CLEAN_INV_MEMREGION and its ATTRIBUTES call, and add RATE_LIMITED/BUSY return codes from DEN0028 for callers that need transient error handling.

---
 include/linux/arm-smccc.h       | 21 +++++++++++++++++++--
 tools/include/linux/arm-smccc.h | 21 +++++++++++++++++++--
 2 files changed, 38 insertions(+), 4 deletions(-)
include/linux/arm-smccc.h +19 -2
index 50b47eba7d01..8cba040e0816 100644
@@ -105,6 +105,22 @@
 			   ARM_SMCCC_SMC_32,				\
 			   0, 0x3fff)
 
+/*
+ * DEN0028 v1.7 defines these cache maintenance functions as SMC64
+ * because they carry 64-bit memory range arguments.
+ */
+#define ARM_SMCCC_ARCH_CLEAN_INV_MEMREGION				\
+	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,				\
+			   ARM_SMCCC_SMC_64,				\
+			   ARM_SMCCC_OWNER_ARCH,			\
+			   0x5)
+
+#define ARM_SMCCC_ARCH_CLEAN_INV_MEMREGION_ATTRIBUTES			\
+	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,				\
+			   ARM_SMCCC_SMC_64,				\
+			   ARM_SMCCC_OWNER_ARCH,			\
+			   0x6)
+
 #define ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID				\
 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,				\
 			   ARM_SMCCC_SMC_32,				\
@@ -294,13 +310,14 @@
 			   0x53)
 
 /*
- * Return codes defined in ARM DEN 0070A
- * ARM DEN 0070A is now merged/consolidated into ARM DEN 0028 C
+ * Return codes defined by Arm SMCCC (DEN0028 v1.7).
  */
 #define SMCCC_RET_SUCCESS			0
 #define SMCCC_RET_NOT_SUPPORTED			-1
 #define SMCCC_RET_NOT_REQUIRED			-2
 #define SMCCC_RET_INVALID_PARAMETER		-3
+#define SMCCC_RET_RATE_LIMITED			-4
+#define SMCCC_RET_BUSY				-5
 
 #ifndef __ASSEMBLY__
 
tools/include/linux/arm-smccc.h +19 -2
index 63ce9bebccd3..ae5637b3240f 100644
@@ -96,6 +96,22 @@
 			   ARM_SMCCC_SMC_32,				\
 			   0, 0x3fff)
 
+/*
+ * DEN0028 v1.7 defines these cache maintenance functions as SMC64
+ * because they carry 64-bit memory range arguments.
+ */
+#define ARM_SMCCC_ARCH_CLEAN_INV_MEMREGION				\
+	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,				\
+			   ARM_SMCCC_SMC_64,				\
+			   ARM_SMCCC_OWNER_ARCH,			\
+			   0x5)
+
+#define ARM_SMCCC_ARCH_CLEAN_INV_MEMREGION_ATTRIBUTES			\
+	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,				\
+			   ARM_SMCCC_SMC_64,				\
+			   ARM_SMCCC_OWNER_ARCH,			\
+			   0x6)
+
 #define ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID				\
 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,				\
 			   ARM_SMCCC_SMC_32,				\
@@ -182,12 +198,13 @@
 			   0x53)
 
 /*
- * Return codes defined in ARM DEN 0070A
- * ARM DEN 0070A is now merged/consolidated into ARM DEN 0028 C
+ * Return codes defined by Arm SMCCC (DEN0028 v1.7).
  */
 #define SMCCC_RET_SUCCESS			0
 #define SMCCC_RET_NOT_SUPPORTED			-1
 #define SMCCC_RET_NOT_REQUIRED			-2
 #define SMCCC_RET_INVALID_PARAMETER		-3
+#define SMCCC_RET_RATE_LIMITED			-4
+#define SMCCC_RET_BUSY				-5
 
 #endif /*__LINUX_ARM_SMCCC_H*/
Signature · 1 line
2.43.0
#3 lore raw

PATCH 2/2 cache: add SMCCC-backed cache invalidate provider

In reply to Srirangan Madhavan

Add a cache maintenance provider for the Arm SMCCC cache clean+invalidate interface.

The provider discovers SMCCC support and attributes at init time, serializes firmware calls, handles transient BUSY and RATE_LIMITED responses with bounded retries, and registers with the generic cache coherency framework used by memregion callers.

---
 drivers/cache/Kconfig           |  11 +++
 drivers/cache/Makefile          |   1 +
 drivers/cache/arm_smccc_cache.c | 160 ++++++++++++++++++++++++++++++++
 3 files changed, 172 insertions(+)
 create mode 100644 drivers/cache/arm_smccc_cache.c
drivers/cache/Kconfig +11 -0
index 1518449d47b5..5d7ef3d15979 100644
@@ -42,6 +42,17 @@ menuconfig CACHEMAINT_FOR_HOTPLUG
 
 if CACHEMAINT_FOR_HOTPLUG
 
+config ARM_SMCCC_CACHE
+	bool "Arm SMCCC cache maintenance provider"
+	depends on ARM64 && HAVE_ARM_SMCCC_DISCOVERY
+	help
+	  Enable support for the Arm SMCCC cache clean+invalidate
+	  interface as a provider for memory hotplug-like cache
+	  maintenance operations.
+	  The provider registers only when firmware advertises the
+	  SMCCC calls and attributes, so systems without firmware support
+	  continue without a registered provider.
+
 config HISI_SOC_HHA
 	tristate "HiSilicon Hydra Home Agent (HHA) device driver"
 	depends on (ARM64 && ACPI) || COMPILE_TEST
drivers/cache/Makefile +1 -0
index b3362b15d6c1..6d91085aafe4 100644
@@ -4,4 +4,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_ARM_SMCCC_CACHE)		+= arm_smccc_cache.o
 obj-$(CONFIG_HISI_SOC_HHA)		+= hisi_soc_hha.o
drivers/cache/arm_smccc_cache.c new file +160 -0

160 lines not on this page · raw message

Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH v1 1/2] arm64: smccc: add cache clean/invalidate IDs and return codes

In reply to Srirangan Madhavan
Quoted 5 lines · On Tue, 2 Jun 2026 08:21:44 +0000 Srirangan Madhavan <[email protected]>…

Define SMCCC Arch function IDs for CLEAN_INV_MEMREGION and its ATTRIBUTES call, and add RATE_LIMITED/BUSY return codes from DEN0028 for callers that need transient error handling.

I assume beta spec is enough to merge this? Probably just need someone from Arm to confirm. Last time we had this feature and it got ripped out it only made it to an alpha spec (which is not enough!)

Jonathan

maintainer Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH v1 2/2] cache: add SMCCC-backed cache invalidate provider

In reply to Srirangan Madhavan
Quoted 9 lines · On Tue, 2 Jun 2026 08:21:45 +0000 Srirangan Madhavan <[email protected]>…

Add a cache maintenance provider for the Arm SMCCC cache clean+invalidate interface.

The provider discovers SMCCC support and attributes at init time, serializes firmware calls, handles transient BUSY and RATE_LIMITED responses with bounded retries, and registers with the generic cache coherency framework used by memregion callers.

3 things inline.

With the loop style updated to either drop that optimization of eliding of the last sleep or use a while (1) loop and the kconfig modified to not imply there are _no_ registered providers.

The comment in Makefile isn't really about this patch, just something I noticed whilst wondering why it wasn't ordered.

Quoted 15 lines
---
 drivers/cache/Kconfig           |  11 +++
 drivers/cache/Makefile          |   1 +
 drivers/cache/arm_smccc_cache.c | 160 ++++++++++++++++++++++++++++++++
 3 files changed, 172 insertions(+)
 create mode 100644 drivers/cache/arm_smccc_cache.c
drivers/cache/Kconfig +0 -0
index 1518449d47b5..5d7ef3d15979 100644
@@ -42,6 +42,17 @@ menuconfig CACHEMAINT_FOR_HOTPLUG
 
 if CACHEMAINT_FOR_HOTPLUG
 

drivers/cache/Kconfig menuconfig CACHEMAINT_FOR_HOTPLUG · line 54

Quoted 10 lines
drivers/cache/Kconfig +10 -0
+config ARM_SMCCC_CACHE
+	bool "Arm SMCCC cache maintenance provider"
+	depends on ARM64 && HAVE_ARM_SMCCC_DISCOVERY
+	help
+	  Enable support for the Arm SMCCC cache clean+invalidate
+	  interface as a provider for memory hotplug-like cache
+	  maintenance operations.
+	  The provider registers only when firmware advertises the
+	  SMCCC calls and attributes, so systems without firmware support
+	  continue without a registered provider.

"without this registered provider". or "without registering a provider."

We need to be careful that we don't give the impressions this is the only option for Arm64 systems that do SMCCC and need a cache maintenance provider. The HiSilcon systems that use HISI_SOC_HHA meet all those conditions - except that they don't use this service.

drivers/cache/Makefile obj-$(CONFIG_AX45MP_L2_CACHE) += ax45mp_cache.o · line 6

Quoted 12 lines
drivers/cache/Kconfig +1 -0
+
 config HISI_SOC_HHA
 	tristate "HiSilicon Hydra Home Agent (HHA) device driver"
 	depends on (ARM64 && ACPI) || COMPILE_TEST
drivers/cache/Makefile +0 -0
index b3362b15d6c1..6d91085aafe4 100644
@@ -4,4 +4,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
 

Maybe we should add a comment here
# Depend on CACHEMAINT_FOR_HOTPLUG

or something like that to avoid them being 'sorted' into the group above at somepoint in future.

Quoted 32 lines
drivers/cache/Makefile +1 -0
+obj-$(CONFIG_ARM_SMCCC_CACHE)		+= arm_smccc_cache.o
 obj-$(CONFIG_HISI_SOC_HHA)		+= hisi_soc_hha.o
drivers/cache/arm_smccc_cache.c new file +23 -0
new file mode 100644
index 000000000000..ff6bca91a1a1
@@ -0,0 +1,160 @@
 
+ static int smccc_cache_wbinv(struct cache_coherency_ops_inst *cci,
+			     struct cc_inval_params *invp)
+{
+	struct smccc_cache *cache = container_of(cci, struct smccc_cache, cci);
+	struct arm_smccc_res res = {};
+	unsigned long delay_us = smccc_cache_delay_us(cache);
+	int ret;
+
+	if (!invp->size)
+		return -EINVAL;
+
+	/*
+	 * Serialize the full retry sequence. With the default bounds, a caller
+	 * may hold the mutex across up to four 20ms backoff sleeps.
+	 */
+	guard(mutex)(&cache->lock);
+
+	for (unsigned int i = 0; i < SMCCC_CACHE_MAX_RETRIES; i++) {
+		/* Long firmware operations can trigger watchdog checks. */
+		touch_nmi_watchdog();
+
+		arm_smccc_1_1_invoke(ARM_SMCCC_ARCH_CLEAN_INV_MEMREGION,
+				     invp->addr, invp->size, 0UL, &res);

drivers/cache/arm_smccc_cache.c line 100

Quoted 10 lines
drivers/cache/arm_smccc_cache.c new file +10 -0
+
+		ret = smccc_cache_status_to_errno((s32)res.a0);
+		if (!ret)
+			return 0;
+
+		if (ret != -EBUSY && ret != -EAGAIN)
+			return ret;
+
+		if (i + 1 == SMCCC_CACHE_MAX_RETRIES)
+			break;

The for loop bound makes little sense if you are going to do this. Use a while loop. Or don't worry about optimising out the final sleep as we never expect to hit this.

Quoted 6 lines
drivers/cache/arm_smccc_cache.c new file +6 -0
+
+		fsleep(delay_us);
+	}
+
+	return -EBUSY;
+}