[PATCH] cache: Make cpu_cache_invalidate_memregion() error out if there are no handlers
From: Bence Csokas
Date: Thu Oct 01 2026 - 07:04:20 EST
Currently, if there are no registered handlers,
cpu_cache_invalidate_memregion() returns 0. Callers are expected to check
cpu_cache_has_invalidate_memregion() and return -ENXIO themselves, instead
of calling this function. If a caller forgets to do this, they may
erroneously think the operation succeeded. This is in contrast to x86,
where cpu_cache_invalidate_memregion() itself checks if the operation is
supported, and returns -ENXIO if it is not.
Reviewed-by: Jonathan Cameron <jonathan.cameron@xxxxxxxxxxxxxxxx>
Signed-off-by: Bence Csokas <bence.csokas@xxxxxxx>
---
I noticed cpu_cache_invalidate_memregion() returns 0 if there are no
registered `cache_coherency_ops_inst`s, which I find counter-intuitive.
>From what I've seen, there are no in-tree users who do not check
cpu_cache_has_invalidate_memregion(). However, IMO the better solution
would be if the function would perform this check, and not the callee.
Furthermore, arch/x86/mm/pat/set_memory.c also implements this function,
but actually does the feature check, and WARNs and returns -ENXIO if it
fails that check.
This patch that provides a low-overhead fix.
---
Changes in v1:
- Rebased to master
- Collected tags
- Link to RFC: https://patch.msgid.link/20260922-cci_enxio-v1-0-00bade212729@xxxxxxx
To: Conor Dooley <conor@xxxxxxxxxx>
To: Jonathan Cameron <jic23@xxxxxxxxxx>
To: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: linux-kernel@xxxxxxxxxxxxxxx
---
lib/cache_maint.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/cache_maint.c b/lib/cache_maint.c
index 9256a9ffc34c..132d2816d6b1 100644
--- a/lib/cache_maint.c
+++ b/lib/cache_maint.c
@@ -59,12 +59,12 @@ static int cache_inval_done_one(struct cache_coherency_ops_inst *cci)
static int cache_invalidate_memregion(phys_addr_t addr, size_t size)
{
- int ret;
struct cache_coherency_ops_inst *cci;
struct cc_inval_params params = {
.addr = addr,
.size = size,
};
+ int ret = -ENXIO;
guard(rwsem_read)(&cache_ops_instance_list_lock);
list_for_each_entry(cci, &cache_ops_instance_list, node) {
@@ -78,7 +78,7 @@ static int cache_invalidate_memregion(phys_addr_t addr, size_t size)
return ret;
}
- return 0;
+ return ret;
}
struct cache_coherency_ops_inst *
---
base-commit: 551c722f40809618230001baccf219193e22fc5a
change-id: 20260921-cci_enxio-f3d31d9acec7
Best regards,
--
Bence Csokas <bence.csokas@xxxxxxx>