Skip to contentSkip to conversation

arm64, lib: make ARM64 select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION not GENERIC_CPU_CACHE_MAINTENANCE

PATCH In review Conor Dooley 4 participants 9 messages Nov 19, 2025 – Nov 21, 2025

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

PATCH 1/1 arm64, lib: make ARM64 select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION not GENERIC_CPU_CACHE_MAINTENANCE

From: Conor Dooley <[email protected]>

Randy pointed out that the newly added GENERIC_CPU_CACHE_MAINTENANCE was unusual, in that it selected an ARCH_HAS_... option, unlikely anything else in lib/Kconfig. Switch things around, so that arm64 selects ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION and then GENERIC_CPU_CACHE_MAINENANCE will in turn be automatically enabled.

---
Catalin, you voiced a take on this already apparently that lead to the current implementation so I'd like an ack from you or Will here. My comment on the original thread, in response to Randy saying it was backwards, that accompanied the diff was:
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 was here) 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.
Ultimately, the .config produced is the same either way, just depends on what impression you want to give in the arch Kconfig, which might not really be a big deal, just semantics. Either way, I'd like an ack :)

Cheers,
Conor.

---
 arch/arm64/Kconfig | 2 +-
 lib/Kconfig        | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)
arch/arm64/Kconfig +1 -1
index 5f7f63d24931..75b2507f7eb2 100644
@@ -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
lib/Kconfig +3 -2
index 09aec4a1e13f..ac223e627bc5 100644
@@ -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
Signature · 1 line
2.51.0
Acked-by on v1 1/1
#1 lore raw
Quoted 28 lines · Conor Dooley

From: Conor Dooley <[email protected]>

Randy pointed out that the newly added GENERIC_CPU_CACHE_MAINTENANCE was unusual, in that it selected an ARCH_HAS_... option, unlikely anything else in lib/Kconfig. Switch things around, so that arm64 selects ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION and then GENERIC_CPU_CACHE_MAINENANCE will in turn be automatically enabled.

---
Catalin, you voiced a take on this already apparently that lead to the current implementation so I'd like an ack from you or Will here. My comment on the original thread, in response to Randy saying it was backwards, that accompanied the diff was:
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 was here) 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.
Ultimately, the .config produced is the same either way, just depends on what impression you want to give in the arch Kconfig, which might not really be a big deal, just semantics. Either way, I'd like an ack :)

Quoted 7 lines

Cheers,
Conor.

Thanks.

Quoted 41 lines
---
 arch/arm64/Kconfig | 2 +-
 lib/Kconfig        | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)
arch/arm64/Kconfig +1 -1
index 5f7f63d24931..75b2507f7eb2 100644
@@ -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
lib/Kconfig +3 -2
index 09aec4a1e13f..ac223e627bc5 100644
@@ -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
Signature · 1 line
~Randy
maintainer
#2 lore raw
In reply to Conor Dooley
Quoted 11 lines · Conor Dooley

From: Conor Dooley <[email protected]>

Randy pointed out that the newly added GENERIC_CPU_CACHE_MAINTENANCE was unusual, in that it selected an ARCH_HAS_... option, unlikely anything else in lib/Kconfig. Switch things around, so that arm64 selects ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION and then GENERIC_CPU_CACHE_MAINENANCE will in turn be automatically enabled.

Quoted 16 lines

---
Catalin, you voiced a take on this already apparently that lead to the current implementation so I'd like an ack from you or Will here. My comment on the original thread, in response to Randy saying it was backwards, that accompanied the diff was:
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 was here) 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.
Ultimately, the .config produced is the same either way, just depends on what impression you want to give in the arch Kconfig, which might not really be a big deal, just semantics. Either way, I'd like an ack :)

I really don't remember what I said before ;). As you describe above, there are two somewhat complementary options - ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION where an arch port can provide this API and GENERIC_CPU_CACHE_MAINTENANCE as a generic way of providing the same API. arm64 does the latter.

Quoted 25 lines
arch/arm64/Kconfig +1 -1
index 5f7f63d24931..75b2507f7eb2 100644
@@ -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
lib/Kconfig +0 -0
index 09aec4a1e13f..ac223e627bc5 100644

lib/Kconfig config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION · line 549

Quoted 8 lines
lib/Kconfig +3 -2
@@ -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

That's what we do if GENERIC_CPU_CACHE_MAINTENANCE depends on some arch code but that's not the case here. GENERIC_CPU_CACHE_MAINTENANCE is an alternative implementation that an arch can select if it does not provide its own. I find the current code without the above patch better.

Maybe what gets confusing here is that the core code uses ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION directly. A more involved fix would be something like:

config CPU_CACHE_INVALIDATE_MEMREGION

	def_bool y
	depends on ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION ||
		GENERIC_CPU_CACHE_MAINTENANCE

and then go and change all the uses of
ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION.

Up to you, the current code also works for me.

Signature · 1 line
Catalin
#3 lore raw
Quoted 7 lines · Catalin Marinas
Quoted 6 lines · Conor Dooley

index 09aec4a1e13f..ac223e627bc5 100644

lib/Kconfig +0 -0
@@ -544,8 +544,9 @@ config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
 	bool
 
Quoted 11 lines

lib/Kconfig config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION · line 549

Quoted 6 lines
lib/Kconfig +3 -2
 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

That's what we do if GENERIC_CPU_CACHE_MAINTENANCE depends on some arch code but that's not the case here. GENERIC_CPU_CACHE_MAINTENANCE is an alternative implementation that an arch can select if it does not provide its own. I find the current code without the above patch better.

Right, I am going to leave it as-is for now then. That's both you and I (and presumably Jonathan) finding the current form more natural. Sorry Randy!

Quoted 17 lines

Maybe what gets confusing here is that the core code uses ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION directly. A more involved fix would be something like:

config CPU_CACHE_INVALIDATE_MEMREGION

	def_bool y
	depends on ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION ||
		GENERIC_CPU_CACHE_MAINTENANCE

and then go and change all the uses of
ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION.

Up to you, the current code also works for me.

Signature · 1 line
Catalin
#4 lore raw
Quoted 20 lines · Conor Dooley
Quoted 7 lines · Catalin Marinas
Quoted 6 lines · Conor Dooley

index 09aec4a1e13f..ac223e627bc5 100644

lib/Kconfig +0 -0
@@ -544,8 +544,9 @@ config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
 	bool
 
Quoted 11 lines

lib/Kconfig config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION · line 549

Quoted 6 lines
lib/Kconfig +3 -2
 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

That's what we do if GENERIC_CPU_CACHE_MAINTENANCE depends on some arch code but that's not the case here. GENERIC_CPU_CACHE_MAINTENANCE is an alternative implementation that an arch can select if it does not provide its own. I find the current code without the above patch better.

Quoted 3 lines

Right, I am going to leave it as-is for now then. That's both you and I (and presumably Jonathan) finding the current form more natural. Sorry Randy!

Thanks. I tried.

I still say that it makes no sense for something generic (GENERIC_CPU_CACHE_MAINTENANCE in lib/Kconfig) to inform the config system that the config has something $ARCH-specific (ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION).

Quoted 17 lines
Quoted 17 lines

Maybe what gets confusing here is that the core code uses ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION directly. A more involved fix would be something like:

config CPU_CACHE_INVALIDATE_MEMREGION

	def_bool y
	depends on ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION ||
		GENERIC_CPU_CACHE_MAINTENANCE

and then go and change all the uses of
ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION.

Up to you, the current code also works for me.

Signature · 1 line
Catalin
Signature · 1 line
~Randy
maintainer
#5 lore raw
Quoted 25 lines · Randy Dunlap
Quoted 20 lines · Conor Dooley
Quoted 7 lines · Catalin Marinas
Quoted 6 lines · Conor Dooley

index 09aec4a1e13f..ac223e627bc5 100644

lib/Kconfig +0 -0
@@ -544,8 +544,9 @@ config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
 	bool
 
Quoted 11 lines

lib/Kconfig config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION · line 549

Quoted 6 lines
lib/Kconfig +3 -2
 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

That's what we do if GENERIC_CPU_CACHE_MAINTENANCE depends on some arch code but that's not the case here. GENERIC_CPU_CACHE_MAINTENANCE is an alternative implementation that an arch can select if it does not provide its own. I find the current code without the above patch better.

Quoted 3 lines

Right, I am going to leave it as-is for now then. That's both you and I (and presumably Jonathan) finding the current form more natural. Sorry Randy!

Quoted 6 lines

Thanks. I tried.

I still say that it makes no sense for something generic (GENERIC_CPU_CACHE_MAINTENANCE in lib/Kconfig) to inform the config system that the config has something $ARCH-specific (ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION).

Yes, that's not great either but the solution with the GENERIC depending on ARCH does work since there's no actual dependency between them.

As an alternative, I'm happy for arm64 to select both the ARCH and GENERIC options if you think that works better.

Signature · 1 line
Catalin
#6 lore raw
Quoted 33 lines · Catalin Marinas
Quoted 25 lines · Randy Dunlap
Quoted 20 lines · Conor Dooley
Quoted 7 lines · Catalin Marinas
Quoted 6 lines · Conor Dooley

index 09aec4a1e13f..ac223e627bc5 100644

lib/Kconfig +0 -0
@@ -544,8 +544,9 @@ config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
 	bool
 
Quoted 11 lines

lib/Kconfig config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION · line 549

Quoted 6 lines
lib/Kconfig +3 -2
 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

That's what we do if GENERIC_CPU_CACHE_MAINTENANCE depends on some arch code but that's not the case here. GENERIC_CPU_CACHE_MAINTENANCE is an alternative implementation that an arch can select if it does not provide its own. I find the current code without the above patch better.

Quoted 3 lines

Right, I am going to leave it as-is for now then. That's both you and I (and presumably Jonathan) finding the current form more natural. Sorry Randy!

Quoted 6 lines

Thanks. I tried.

I still say that it makes no sense for something generic (GENERIC_CPU_CACHE_MAINTENANCE in lib/Kconfig) to inform the config system that the config has something $ARCH-specific (ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION).

Quoted 6 lines

Yes, that's not great either but the solution with the GENERIC depending on ARCH does work since there's no actual dependency between them.

As an alternative, I'm happy for arm64 to select both the ARCH and GENERIC options if you think that works better.

Yes, I think that would be much better.
Thanks.

Signature · 1 line
~Randy
#7 lore raw
Quoted 37 lines · On Thu, 20 Nov 2025 15:25:46 -0800 Randy Dunlap <[email protected]> wrote:
Quoted 36 lines · Catalin Marinas
Quoted 25 lines · Randy Dunlap
Quoted 20 lines · Conor Dooley
Quoted 7 lines · Catalin Marinas
Quoted 6 lines · Conor Dooley

index 09aec4a1e13f..ac223e627bc5 100644

lib/Kconfig +0 -0
@@ -544,8 +544,9 @@ config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
 	bool
 
Quoted 11 lines

lib/Kconfig config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION · line 549

Quoted 6 lines
lib/Kconfig +3 -2
 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  

That's what we do if GENERIC_CPU_CACHE_MAINTENANCE depends on some arch code but that's not the case here. GENERIC_CPU_CACHE_MAINTENANCE is an alternative implementation that an arch can select if it does not provide its own. I find the current code without the above patch better.

Quoted 3 lines

Right, I am going to leave it as-is for now then. That's both you and I (and presumably Jonathan) finding the current form more natural. Sorry Randy!

Quoted 6 lines

Thanks. I tried.

I still say that it makes no sense for something generic (GENERIC_CPU_CACHE_MAINTENANCE in lib/Kconfig) to inform the config system that the config has something $ARCH-specific (ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION).

Yes, that's not great either but the solution with the GENERIC depending on ARCH does work since there's no actual dependency between them.

Quoted 7 lines
Quoted 3 lines

As an alternative, I'm happy for arm64 to select both the ARCH and GENERIC options if you think that works better.

Yes, I think that would be much better.
Thanks.

I'm fine with that as well (was where we were in earlier versions). I'm offline for 10 days from tomorrow, but wangyushan +CC has been heavily involved in this series throughout if we need to test anything etc.

For a patch that is basically just (this to me seems fine to squash as well if that is easier)

arch/arm64/Kconfig +1 -0
index 893e0af0bc51..b4507eeabc4c 100644
@@ -20,6 +20,7 @@ config ARM64
        select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2
        select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE
        select ARCH_HAS_CACHE_LINE_SIZE
+       select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
        select ARCH_HAS_CC_PLATFORM
        select ARCH_HAS_CURRENT_STACK_POINTER
        select ARCH_HAS_DEBUG_VIRTUAL
lib/Kconfig +0 -1
index e11136d188ae..2923924bea78 100644
@@ -544,7 +544,6 @@ config ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
 
 config GENERIC_CPU_CACHE_MAINTENANCE
        bool
-       select ARCH_HAS_CPU_CACHE_INVALIDATE_MEMREGION
 
 config ARCH_HAS_MEMREMAP_COMPAT_ALIGN
        bool

If not I'm guessing no one will mind too much if we tidy this up post or late in merge window.

Thanks,

Jonathan

#8 lore raw
Quoted 12 lines · Jonathan Cameron
Quoted 9 lines · On Thu, 20 Nov 2025 15:25:46 -0800 Randy Dunlap <[email protected]> wrote:
Quoted 3 lines · Catalin Marinas

As an alternative, I'm happy for arm64 to select both the ARCH and GENERIC options if you think that works better.

Yes, I think that would be much better.
Thanks.

Quoted 6 lines

I'm fine with that as well (was where we were in earlier versions). I'm offline for 10 days from tomorrow, but wangyushan +CC has been heavily involved in this series throughout if we need to test anything etc.

For a patch that is basically just (this to me seems fine to squash as well if that is easier)

Right, 3 votes for both, so I squashed that in.

Thanks guys.