Skip to contentSkip to conversation

arm64: Drop support for VPIPT i-cache policy

PATCH Superseded Marc Zyngier 3 participants 10 messages Nov 27, 2023 – Dec 4, 2023

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Marc Zyngier

author maintainer
#0 lore raw

v2 cover arm64: Drop support for VPIPT i-cache policy

ARMv8.2 introduced support for VPIPT i-caches, the V standing for VMID-tagged. Although this looks like a reasonable idea, no implementation has ever made it into the wild.

Linux has supported this for over 6 years (amusingly, just as the architecture was dropping support for AVIVT i-caches), but we had no way to even test it, and it is likely that this code was just bit-rotting.

However, in a recent breakthrough (XML drop 2023-09, tagged as d55f5af8e09052abe92a02adf820deea2eaed717), the architecture has finally been purged of this option, making VIPT and PIPT the only two valid options.

This really means this code is just dead code. Nobody will ever come up with such an implementation, and we can just get rid of it.

Most of the impact is on KVM, where we drop a few large comment blocks (and a bit of code), while the core arch code loses the detection code itself.

Marc Zyngier (3):
KVM: arm64: Remove VPIPT I-cache handling
arm64: Kill detection of VPIPT i-cache policy
arm64: Rename reserved values for CTR_EL0.L1Ip

 arch/arm64/include/asm/cache.h   |  6 ----
 arch/arm64/include/asm/kvm_mmu.h |  7 ----
 arch/arm64/kernel/cpuinfo.c      |  5 ---
 arch/arm64/kvm/hyp/nvhe/pkvm.c   |  2 +-
 arch/arm64/kvm/hyp/nvhe/tlb.c    | 61 --------------------------------
 arch/arm64/kvm/hyp/vhe/tlb.c     | 13 -------
 arch/arm64/tools/sysreg          |  5 +--
 7 files changed, 4 insertions(+), 95 deletions(-)
Signature · 1 line
2.39.2
author maintainer
#1 lore raw

PATCH v2 1/3 KVM: arm64: Remove VPIPT I-cache handling

We have some special handling for VPIPT I-cache in critical parts of the cache and TLB maintenance. Remove it.

---
 arch/arm64/include/asm/kvm_mmu.h |  7 ----
 arch/arm64/kvm/hyp/nvhe/pkvm.c   |  2 +-
 arch/arm64/kvm/hyp/nvhe/tlb.c    | 61 --------------------------------
 arch/arm64/kvm/hyp/vhe/tlb.c     | 13 -------
 4 files changed, 1 insertion(+), 82 deletions(-)
arch/arm64/include/asm/kvm_mmu.h +0 -7
index 49e0d4b36bd0..e3e793d0ec30 100644
@@ -243,13 +243,6 @@ static inline size_t __invalidate_icache_max_range(void)
 
 static inline void __invalidate_icache_guest_page(void *va, size_t size)
 {
-	/*
-	 * VPIPT I-cache maintenance must be done from EL2. See comment in the
-	 * nVHE flavor of __kvm_tlb_flush_vmid_ipa().
-	 */
-	if (icache_is_vpipt() && read_sysreg(CurrentEL) != CurrentEL_EL2)
-		return;
-
 	/*
 	 * Blow the whole I-cache if it is aliasing (i.e. VIPT) or the
 	 * invalidation range exceeds our arbitrary limit on invadations by
arch/arm64/kvm/hyp/nvhe/pkvm.c +1 -1
index 9d23a51d7f75..b29f15418c0a 100644
@@ -12,7 +12,7 @@
 #include <nvhe/pkvm.h>
 #include <nvhe/trap_handler.h>
 
-/* Used by icache_is_vpipt(). */
+/* Used by icache_is_aliasing(). */
 unsigned long __icache_flags;
 
 /* Used by kvm_get_vttbr(). */
arch/arm64/kvm/hyp/nvhe/tlb.c +0 -61

84 lines not on this page · raw message

arch/arm64/kvm/hyp/vhe/tlb.c +0 -13
index b636b4111dbf..b32e2940df7d 100644
@@ -216,18 +216,5 @@ void __kvm_flush_vm_context(void)
 {
 	dsb(ishst);
 	__tlbi(alle1is);
-
-	/*
-	 * VIPT and PIPT caches are not affected by VMID, so no maintenance
-	 * is necessary across a VMID rollover.
-	 *
-	 * VPIPT caches constrain lookup and maintenance to the active VMID,
-	 * so we need to invalidate lines with a stale VMID to avoid an ABA
-	 * race after multiple rollovers.
-	 *
-	 */
-	if (icache_is_vpipt())
-		asm volatile("ic ialluis");
-
 	dsb(ish);
 }
Signature · 1 line
2.39.2
author maintainer
#3 lore raw

PATCH v2 2/3 arm64: Kill detection of VPIPT i-cache policy

In reply to Marc Zyngier

Since the kernel will never run on a system with the VPIPT i-cache policy, drop the detection code altogether.

---
 arch/arm64/include/asm/cache.h | 6 ------
 arch/arm64/kernel/cpuinfo.c    | 5 -----
 2 files changed, 11 deletions(-)
arch/arm64/include/asm/cache.h +0 -6
index ceb368d33bf4..06a4670bdb0b 100644
@@ -58,7 +58,6 @@ static inline unsigned int arch_slab_minalign(void)
 #define CTR_L1IP(ctr)		SYS_FIELD_GET(CTR_EL0, L1Ip, ctr)
 
 #define ICACHEF_ALIASING	0
-#define ICACHEF_VPIPT		1
 extern unsigned long __icache_flags;
 
 /*
@@ -70,11 +69,6 @@ static inline int icache_is_aliasing(void)
 	return test_bit(ICACHEF_ALIASING, &__icache_flags);
 }
 
-static __always_inline int icache_is_vpipt(void)
-{
-	return test_bit(ICACHEF_VPIPT, &__icache_flags);
-}
-
 static inline u32 cache_type_cwg(void)
 {
 	return SYS_FIELD_GET(CTR_EL0, CWG, read_cpuid_cachetype());
arch/arm64/kernel/cpuinfo.c +0 -5
index a257da7b56fe..47043c0d95ec 100644
@@ -36,8 +36,6 @@ static struct cpuinfo_arm64 boot_cpu_data;
 static inline const char *icache_policy_str(int l1ip)
 {
 	switch (l1ip) {
-	case CTR_EL0_L1Ip_VPIPT:
-		return "VPIPT";
 	case CTR_EL0_L1Ip_VIPT:
 		return "VIPT";
 	case CTR_EL0_L1Ip_PIPT:
@@ -388,9 +386,6 @@ static void cpuinfo_detect_icache_policy(struct cpuinfo_arm64 *info)
 	switch (l1ip) {
 	case CTR_EL0_L1Ip_PIPT:
 		break;
-	case CTR_EL0_L1Ip_VPIPT:
-		set_bit(ICACHEF_VPIPT, &__icache_flags);
-		break;
 	case CTR_EL0_L1Ip_VIPT:
 	default:
 		/* Assume aliasing */
Signature · 1 line
2.39.2
author maintainer
#5 lore raw

PATCH v2 3/3 arm64: Rename reserved values for CTR_EL0.L1Ip

In reply to Marc Zyngier

We now have *two* values for CTR_EL0.L1Ip that are reserved. Which makes things a bit awkward. In order to lift the ambiguity, rename RESERVED (0b01) to RESERVED_AIVIVT, and VPIPT (0b00) to RESERVED_VPIPT.

This makes it clear which of these meant what, and I'm sure archeologists will find it useful...

---
 arch/arm64/tools/sysreg | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/tools/sysreg +3 -2
index 96cbeeab4eec..5a217e0fce45 100644
@@ -2004,9 +2004,10 @@ Field	27:24	CWG
 Field	23:20	ERG
 Field	19:16	DminLine
 Enum	15:14	L1Ip
-	0b00	VPIPT
+	# This was named as VPIPT in the ARM but now documented as reserved
+	0b00	RESERVED_VPIPT
 	# This is named as AIVIVT in the ARM but documented as reserved
-	0b01	RESERVED
+	0b01	RESERVED_AVIVT
 	0b10	VIPT
 	0b11	PIPT
 EndEnum
Signature · 1 line
2.39.2
#8 lore raw
In reply to Marc Zyngier
Quoted 9 lines · Marc Zyngier

ARMv8.2 introduced support for VPIPT i-caches, the V standing for VMID-tagged. Although this looks like a reasonable idea, no implementation has ever made it into the wild.

Linux has supported this for over 6 years (amusingly, just as the architecture was dropping support for AVIVT i-caches), but we had no way to even test it, and it is likely that this code was just bit-rotting.

Quoted 4 lines

However, in a recent breakthrough (XML drop 2023-09, tagged as d55f5af8e09052abe92a02adf820deea2eaed717), the architecture has finally been purged of this option, making VIPT and PIPT the only two valid options.

Indeed, FEAT_VPIPT has been dropped from the 2023-09 document release.

https://developer.arm.com/documentation/ddi0601/2023-06/AArch64-Registers/CTR-EL0--Cache-Type-Register

CTR_EL0.L1Ip[15:14] = 00 - VMID aware Physical Index, Physical tag (VPIPT) with FEAT_VPIPT

https://developer.arm.com/documentation/ddi0601/2023-09/AArch64-Registers/CTR-EL0--Cache-Type-Register

CTR_EL0.L1Ip[15:14] = 00 - Reserved.

#6 lore raw

Re: [PATCH v2 3/3] arm64: Rename reserved values for CTR_EL0.L1Ip

In reply to Marc Zyngier
Quoted 18 lines · Marc Zyngier

We now have *two* values for CTR_EL0.L1Ip that are reserved. Which makes things a bit awkward. In order to lift the ambiguity, rename RESERVED (0b01) to RESERVED_AIVIVT, and VPIPT (0b00) to RESERVED_VPIPT.

This makes it clear which of these meant what, and I'm sure archeologists will find it useful...

---
 arch/arm64/tools/sysreg | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/tools/sysreg +0 -0
index 96cbeeab4eec..5a217e0fce45 100644

arch/arm64/tools/sysreg Field 27:24 CWG · line 2010

Quoted 9 lines
arch/arm64/tools/sysreg +3 -2
@@ -2004,9 +2004,10 @@ Field	27:24	CWG
 Field	23:20	ERG
 Field	19:16	DminLine
 Enum	15:14	L1Ip
-	0b00	VPIPT
+	# This was named as VPIPT in the ARM but now documented as reserved
+	0b00	RESERVED_VPIPT
 	# This is named as AIVIVT in the ARM but documented as reserved
-	0b01	RESERVED
+	0b01	RESERVED_AVIVT

s/RESERVED_AVIVT/RESERVED_AIVIVT - matches the spec. Commit message has got this right.

Quoted 3 lines
arch/arm64/tools/sysreg +0 -0
 	0b10	VIPT
 	0b11	PIPT
 EndEnum
Reviewed-by on v2 2/3
#4 lore raw

Re: [PATCH v2 2/3] arm64: Kill detection of VPIPT i-cache policy

In reply to Marc Zyngier
Quoted 4 lines · Marc Zyngier

Since the kernel will never run on a system with the VPIPT i-cache policy, drop the detection code altogether.

Quoted 52 lines
---
 arch/arm64/include/asm/cache.h | 6 ------
 arch/arm64/kernel/cpuinfo.c    | 5 -----
 2 files changed, 11 deletions(-)
arch/arm64/include/asm/cache.h +0 -6
index ceb368d33bf4..06a4670bdb0b 100644
@@ -58,7 +58,6 @@ static inline unsigned int arch_slab_minalign(void)
 #define CTR_L1IP(ctr)		SYS_FIELD_GET(CTR_EL0, L1Ip, ctr)
 
 #define ICACHEF_ALIASING	0
-#define ICACHEF_VPIPT		1
 extern unsigned long __icache_flags;
 
 /*
@@ -70,11 +69,6 @@ static inline int icache_is_aliasing(void)
 	return test_bit(ICACHEF_ALIASING, &__icache_flags);
 }
 
-static __always_inline int icache_is_vpipt(void)
-{
-	return test_bit(ICACHEF_VPIPT, &__icache_flags);
-}
-
 static inline u32 cache_type_cwg(void)
 {
 	return SYS_FIELD_GET(CTR_EL0, CWG, read_cpuid_cachetype());
arch/arm64/kernel/cpuinfo.c +0 -5
index a257da7b56fe..47043c0d95ec 100644
@@ -36,8 +36,6 @@ static struct cpuinfo_arm64 boot_cpu_data;
 static inline const char *icache_policy_str(int l1ip)
 {
 	switch (l1ip) {
-	case CTR_EL0_L1Ip_VPIPT:
-		return "VPIPT";
 	case CTR_EL0_L1Ip_VIPT:
 		return "VIPT";
 	case CTR_EL0_L1Ip_PIPT:
@@ -388,9 +386,6 @@ static void cpuinfo_detect_icache_policy(struct cpuinfo_arm64 *info)
 	switch (l1ip) {
 	case CTR_EL0_L1Ip_PIPT:
 		break;
-	case CTR_EL0_L1Ip_VPIPT:
-		set_bit(ICACHEF_VPIPT, &__icache_flags);
-		break;
 	case CTR_EL0_L1Ip_VIPT:
 	default:
 		/* Assume aliasing */
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] KVM: arm64: Remove VPIPT I-cache handling

In reply to Marc Zyngier
Quoted 2 lines · Marc Zyngier

We have some special handling for VPIPT I-cache in critical parts of the cache and TLB maintenance. Remove it.

Quoted 155 lines
---
 arch/arm64/include/asm/kvm_mmu.h |  7 ----
 arch/arm64/kvm/hyp/nvhe/pkvm.c   |  2 +-
 arch/arm64/kvm/hyp/nvhe/tlb.c    | 61 --------------------------------
 arch/arm64/kvm/hyp/vhe/tlb.c     | 13 -------
 4 files changed, 1 insertion(+), 82 deletions(-)
arch/arm64/include/asm/kvm_mmu.h +0 -7
index 49e0d4b36bd0..e3e793d0ec30 100644
@@ -243,13 +243,6 @@ static inline size_t __invalidate_icache_max_range(void)
 
 static inline void __invalidate_icache_guest_page(void *va, size_t size)
 {
-	/*
-	 * VPIPT I-cache maintenance must be done from EL2. See comment in the
-	 * nVHE flavor of __kvm_tlb_flush_vmid_ipa().
-	 */
-	if (icache_is_vpipt() && read_sysreg(CurrentEL) != CurrentEL_EL2)
-		return;
-
 	/*
 	 * Blow the whole I-cache if it is aliasing (i.e. VIPT) or the
 	 * invalidation range exceeds our arbitrary limit on invadations by
arch/arm64/kvm/hyp/nvhe/pkvm.c +1 -1
index 9d23a51d7f75..b29f15418c0a 100644
@@ -12,7 +12,7 @@
 #include <nvhe/pkvm.h>
 #include <nvhe/trap_handler.h>
 
-/* Used by icache_is_vpipt(). */
+/* Used by icache_is_aliasing(). */
 unsigned long __icache_flags;
 
 /* Used by kvm_get_vttbr(). */
arch/arm64/kvm/hyp/nvhe/tlb.c +0 -61
index 1b265713d6be..a60fb13e2192 100644
@@ -105,28 +105,6 @@ void __kvm_tlb_flush_vmid_ipa(struct kvm_s2_mmu *mmu,
 	dsb(ish);
 	isb();
 
-	/*
-	 * If the host is running at EL1 and we have a VPIPT I-cache,
-	 * then we must perform I-cache maintenance at EL2 in order for
-	 * it to have an effect on the guest. Since the guest cannot hit
-	 * I-cache lines allocated with a different VMID, we don't need
-	 * to worry about junk out of guest reset (we nuke the I-cache on
-	 * VMID rollover), but we do need to be careful when remapping
-	 * executable pages for the same guest. This can happen when KSM
-	 * takes a CoW fault on an executable page, copies the page into
-	 * a page that was previously mapped in the guest and then needs
-	 * to invalidate the guest view of the I-cache for that page
-	 * from EL1. To solve this, we invalidate the entire I-cache when
-	 * unmapping a page from a guest if we have a VPIPT I-cache but
-	 * the host is running at EL1. As above, we could do better if
-	 * we had the VA.
-	 *
-	 * The moral of this story is: if you have a VPIPT I-cache, then
-	 * you should be running with VHE enabled.
-	 */
-	if (icache_is_vpipt())
-		icache_inval_all_pou();
-
 	__tlb_switch_to_host(&cxt);
 }
 
@@ -157,28 +135,6 @@ void __kvm_tlb_flush_vmid_ipa_nsh(struct kvm_s2_mmu *mmu,
 	dsb(nsh);
 	isb();
 
-	/*
-	 * If the host is running at EL1 and we have a VPIPT I-cache,
-	 * then we must perform I-cache maintenance at EL2 in order for
-	 * it to have an effect on the guest. Since the guest cannot hit
-	 * I-cache lines allocated with a different VMID, we don't need
-	 * to worry about junk out of guest reset (we nuke the I-cache on
-	 * VMID rollover), but we do need to be careful when remapping
-	 * executable pages for the same guest. This can happen when KSM
-	 * takes a CoW fault on an executable page, copies the page into
-	 * a page that was previously mapped in the guest and then needs
-	 * to invalidate the guest view of the I-cache for that page
-	 * from EL1. To solve this, we invalidate the entire I-cache when
-	 * unmapping a page from a guest if we have a VPIPT I-cache but
-	 * the host is running at EL1. As above, we could do better if
-	 * we had the VA.
-	 *
-	 * The moral of this story is: if you have a VPIPT I-cache, then
-	 * you should be running with VHE enabled.
-	 */
-	if (icache_is_vpipt())
-		icache_inval_all_pou();
-
 	__tlb_switch_to_host(&cxt);
 }
 
@@ -205,10 +161,6 @@ void __kvm_tlb_flush_vmid_range(struct kvm_s2_mmu *mmu,
 	dsb(ish);
 	isb();
 
-	/* See the comment in __kvm_tlb_flush_vmid_ipa() */
-	if (icache_is_vpipt())
-		icache_inval_all_pou();
-
 	__tlb_switch_to_host(&cxt);
 }
 
@@ -246,18 +198,5 @@ void __kvm_flush_vm_context(void)
 	/* Same remark as in __tlb_switch_to_guest() */
 	dsb(ish);
 	__tlbi(alle1is);
-
-	/*
-	 * VIPT and PIPT caches are not affected by VMID, so no maintenance
-	 * is necessary across a VMID rollover.
-	 *
-	 * VPIPT caches constrain lookup and maintenance to the active VMID,
-	 * so we need to invalidate lines with a stale VMID to avoid an ABA
-	 * race after multiple rollovers.
-	 *
-	 */
-	if (icache_is_vpipt())
-		asm volatile("ic ialluis");
-
 	dsb(ish);
 }
arch/arm64/kvm/hyp/vhe/tlb.c +0 -13
index b636b4111dbf..b32e2940df7d 100644
@@ -216,18 +216,5 @@ void __kvm_flush_vm_context(void)
 {
 	dsb(ishst);
 	__tlbi(alle1is);
-
-	/*
-	 * VIPT and PIPT caches are not affected by VMID, so no maintenance
-	 * is necessary across a VMID rollover.
-	 *
-	 * VPIPT caches constrain lookup and maintenance to the active VMID,
-	 * so we need to invalidate lines with a stale VMID to avoid an ABA
-	 * race after multiple rollovers.
-	 *
-	 */
-	if (icache_is_vpipt())
-		asm volatile("ic ialluis");
-
 	dsb(ish);
 }
author maintainer
#7 lore raw

Re: [PATCH v2 3/3] arm64: Rename reserved values for CTR_EL0.L1Ip

In reply to Anshuman Khandual
Quoted 26 lines · Anshuman Khandual
Quoted 22 lines · Marc Zyngier

We now have *two* values for CTR_EL0.L1Ip that are reserved. Which makes things a bit awkward. In order to lift the ambiguity, rename RESERVED (0b01) to RESERVED_AIVIVT, and VPIPT (0b00) to RESERVED_VPIPT.

This makes it clear which of these meant what, and I'm sure archeologists will find it useful...

---
 arch/arm64/tools/sysreg | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/tools/sysreg +0 -1
index 96cbeeab4eec..5a217e0fce45 100644
@@ -2004,9 +2004,10 @@ Field	27:24	CWG
 Field	23:20	ERG
 Field	19:16	DminLine
 Enum	15:14	L1Ip
-	0b00	VPIPT
Quoted 8 lines

arch/arm64/tools/sysreg Field 27:24 CWG · line 2010

Quoted 5 lines
arch/arm64/tools/sysreg +3 -1
+	# This was named as VPIPT in the ARM but now documented as reserved
+	0b00	RESERVED_VPIPT
 	# This is named as AIVIVT in the ARM but documented as reserved
-	0b01	RESERVED
+	0b01	RESERVED_AVIVT

s/RESERVED_AVIVT/RESERVED_AIVIVT - matches the spec. Commit message has got this right.

Huh, how embarrassing. Thanks for pointing this out, I'll fix it in the next round.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
reviewer Reviewed-by on the v2 series
#9 lore raw
In reply to Marc Zyngier
Quoted 17 lines · Marc Zyngier

ARMv8.2 introduced support for VPIPT i-caches, the V standing for VMID-tagged. Although this looks like a reasonable idea, no implementation has ever made it into the wild.

Linux has supported this for over 6 years (amusingly, just as the architecture was dropping support for AVIVT i-caches), but we had no way to even test it, and it is likely that this code was just bit-rotting.

However, in a recent breakthrough (XML drop 2023-09, tagged as d55f5af8e09052abe92a02adf820deea2eaed717), the architecture has finally been purged of this option, making VIPT and PIPT the only two valid options.

This really means this code is just dead code. Nobody will ever come up with such an implementation, and we can just get rid of it.

Quoted 8 lines

Most of the impact is on KVM, where we drop a few large comment blocks (and a bit of code), while the core arch code loses the detection code itself.

Marc Zyngier (3):
KVM: arm64: Remove VPIPT I-cache handling
arm64: Kill detection of VPIPT i-cache policy
arm64: Rename reserved values for CTR_EL0.L1Ip

Series looks good to me. With Anshuman's comment addressed,