linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] arm64: Drop support for VPIPT i-cache policy
@ 2023-11-27 17:26 Marc Zyngier
  2023-11-27 17:26 ` [PATCH v2 1/3] KVM: arm64: Remove VPIPT I-cache handling Marc Zyngier
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Marc Zyngier @ 2023-11-27 17:26 UTC (permalink / raw)
  To: kvmarm, linux-arm-kernel, kvm
  Cc: Will Deacon, Catalin Marinas, Mark Rutland, Ard Biesheuvel,
	James Morse, Suzuki K Poulose, Oliver Upton, Zenghui Yu

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(-)

-- 
2.39.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/3] KVM: arm64: Remove VPIPT I-cache handling
  2023-11-27 17:26 [PATCH v2 0/3] arm64: Drop support for VPIPT i-cache policy Marc Zyngier
@ 2023-11-27 17:26 ` Marc Zyngier
  2023-11-29  7:36   ` Anshuman Khandual
  2023-11-27 17:26 ` [PATCH v2 2/3] arm64: Kill detection of VPIPT i-cache policy Marc Zyngier
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Marc Zyngier @ 2023-11-27 17:26 UTC (permalink / raw)
  To: kvmarm, linux-arm-kernel, kvm
  Cc: Will Deacon, Catalin Marinas, Mark Rutland, Ard Biesheuvel,
	James Morse, Suzuki K Poulose, Oliver Upton, Zenghui Yu

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

Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 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(-)

diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h
index 49e0d4b36bd0..e3e793d0ec30 100644
--- a/arch/arm64/include/asm/kvm_mmu.h
+++ b/arch/arm64/include/asm/kvm_mmu.h
@@ -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
diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c
index 9d23a51d7f75..b29f15418c0a 100644
--- a/arch/arm64/kvm/hyp/nvhe/pkvm.c
+++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c
@@ -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(). */
diff --git a/arch/arm64/kvm/hyp/nvhe/tlb.c b/arch/arm64/kvm/hyp/nvhe/tlb.c
index 1b265713d6be..a60fb13e2192 100644
--- a/arch/arm64/kvm/hyp/nvhe/tlb.c
+++ b/arch/arm64/kvm/hyp/nvhe/tlb.c
@@ -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);
 }
diff --git a/arch/arm64/kvm/hyp/vhe/tlb.c b/arch/arm64/kvm/hyp/vhe/tlb.c
index b636b4111dbf..b32e2940df7d 100644
--- a/arch/arm64/kvm/hyp/vhe/tlb.c
+++ b/arch/arm64/kvm/hyp/vhe/tlb.c
@@ -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);
 }
-- 
2.39.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 2/3] arm64: Kill detection of VPIPT i-cache policy
  2023-11-27 17:26 [PATCH v2 0/3] arm64: Drop support for VPIPT i-cache policy Marc Zyngier
  2023-11-27 17:26 ` [PATCH v2 1/3] KVM: arm64: Remove VPIPT I-cache handling Marc Zyngier
@ 2023-11-27 17:26 ` Marc Zyngier
  2023-11-29  7:25   ` Anshuman Khandual
  2023-11-27 17:26 ` [PATCH v2 3/3] arm64: Rename reserved values for CTR_EL0.L1Ip Marc Zyngier
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Marc Zyngier @ 2023-11-27 17:26 UTC (permalink / raw)
  To: kvmarm, linux-arm-kernel, kvm
  Cc: Will Deacon, Catalin Marinas, Mark Rutland, Ard Biesheuvel,
	James Morse, Suzuki K Poulose, Oliver Upton, Zenghui Yu

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

Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 arch/arm64/include/asm/cache.h | 6 ------
 arch/arm64/kernel/cpuinfo.c    | 5 -----
 2 files changed, 11 deletions(-)

diff --git a/arch/arm64/include/asm/cache.h b/arch/arm64/include/asm/cache.h
index ceb368d33bf4..06a4670bdb0b 100644
--- a/arch/arm64/include/asm/cache.h
+++ b/arch/arm64/include/asm/cache.h
@@ -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());
diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c
index a257da7b56fe..47043c0d95ec 100644
--- a/arch/arm64/kernel/cpuinfo.c
+++ b/arch/arm64/kernel/cpuinfo.c
@@ -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 */
-- 
2.39.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 3/3] arm64: Rename reserved values for CTR_EL0.L1Ip
  2023-11-27 17:26 [PATCH v2 0/3] arm64: Drop support for VPIPT i-cache policy Marc Zyngier
  2023-11-27 17:26 ` [PATCH v2 1/3] KVM: arm64: Remove VPIPT I-cache handling Marc Zyngier
  2023-11-27 17:26 ` [PATCH v2 2/3] arm64: Kill detection of VPIPT i-cache policy Marc Zyngier
@ 2023-11-27 17:26 ` Marc Zyngier
  2023-11-29  7:13   ` Anshuman Khandual
  2023-11-29  6:31 ` [PATCH v2 0/3] arm64: Drop support for VPIPT i-cache policy Anshuman Khandual
  2023-12-04 13:09 ` Zenghui Yu
  4 siblings, 1 reply; 10+ messages in thread
From: Marc Zyngier @ 2023-11-27 17:26 UTC (permalink / raw)
  To: kvmarm, linux-arm-kernel, kvm
  Cc: Will Deacon, Catalin Marinas, Mark Rutland, Ard Biesheuvel,
	James Morse, Suzuki K Poulose, Oliver Upton, Zenghui Yu

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...

Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 arch/arm64/tools/sysreg | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/tools/sysreg b/arch/arm64/tools/sysreg
index 96cbeeab4eec..5a217e0fce45 100644
--- a/arch/arm64/tools/sysreg
+++ b/arch/arm64/tools/sysreg
@@ -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
-- 
2.39.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/3] arm64: Drop support for VPIPT i-cache policy
  2023-11-27 17:26 [PATCH v2 0/3] arm64: Drop support for VPIPT i-cache policy Marc Zyngier
                   ` (2 preceding siblings ...)
  2023-11-27 17:26 ` [PATCH v2 3/3] arm64: Rename reserved values for CTR_EL0.L1Ip Marc Zyngier
@ 2023-11-29  6:31 ` Anshuman Khandual
  2023-12-04 13:09 ` Zenghui Yu
  4 siblings, 0 replies; 10+ messages in thread
From: Anshuman Khandual @ 2023-11-29  6:31 UTC (permalink / raw)
  To: Marc Zyngier, kvmarm, linux-arm-kernel, kvm
  Cc: Will Deacon, Catalin Marinas, Mark Rutland, Ard Biesheuvel,
	James Morse, Suzuki K Poulose, Oliver Upton, Zenghui Yu



On 11/27/23 22:56, Marc Zyngier wrote:
> 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.

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.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 3/3] arm64: Rename reserved values for CTR_EL0.L1Ip
  2023-11-27 17:26 ` [PATCH v2 3/3] arm64: Rename reserved values for CTR_EL0.L1Ip Marc Zyngier
@ 2023-11-29  7:13   ` Anshuman Khandual
  2023-11-29 13:06     ` Marc Zyngier
  0 siblings, 1 reply; 10+ messages in thread
From: Anshuman Khandual @ 2023-11-29  7:13 UTC (permalink / raw)
  To: Marc Zyngier, kvmarm, linux-arm-kernel, kvm
  Cc: Will Deacon, Catalin Marinas, Mark Rutland, Ard Biesheuvel,
	James Morse, Suzuki K Poulose, Oliver Upton, Zenghui Yu



On 11/27/23 22:56, Marc Zyngier wrote:
> 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...
> 
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> ---
>  arch/arm64/tools/sysreg | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/tools/sysreg b/arch/arm64/tools/sysreg
> index 96cbeeab4eec..5a217e0fce45 100644
> --- a/arch/arm64/tools/sysreg
> +++ b/arch/arm64/tools/sysreg
> @@ -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.

>  	0b10	VIPT
>  	0b11	PIPT
>  EndEnum

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 2/3] arm64: Kill detection of VPIPT i-cache policy
  2023-11-27 17:26 ` [PATCH v2 2/3] arm64: Kill detection of VPIPT i-cache policy Marc Zyngier
@ 2023-11-29  7:25   ` Anshuman Khandual
  0 siblings, 0 replies; 10+ messages in thread
From: Anshuman Khandual @ 2023-11-29  7:25 UTC (permalink / raw)
  To: Marc Zyngier, kvmarm, linux-arm-kernel, kvm
  Cc: Will Deacon, Catalin Marinas, Mark Rutland, Ard Biesheuvel,
	James Morse, Suzuki K Poulose, Oliver Upton, Zenghui Yu



On 11/27/23 22:56, Marc Zyngier wrote:
> Since the kernel will never run on a system with the VPIPT i-cache
> policy, drop the detection code altogether.
> 
> Signed-off-by: Marc Zyngier <maz@kernel.org>

Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>

> ---
>  arch/arm64/include/asm/cache.h | 6 ------
>  arch/arm64/kernel/cpuinfo.c    | 5 -----
>  2 files changed, 11 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/cache.h b/arch/arm64/include/asm/cache.h
> index ceb368d33bf4..06a4670bdb0b 100644
> --- a/arch/arm64/include/asm/cache.h
> +++ b/arch/arm64/include/asm/cache.h
> @@ -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());
> diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c
> index a257da7b56fe..47043c0d95ec 100644
> --- a/arch/arm64/kernel/cpuinfo.c
> +++ b/arch/arm64/kernel/cpuinfo.c
> @@ -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 */

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/3] KVM: arm64: Remove VPIPT I-cache handling
  2023-11-27 17:26 ` [PATCH v2 1/3] KVM: arm64: Remove VPIPT I-cache handling Marc Zyngier
@ 2023-11-29  7:36   ` Anshuman Khandual
  0 siblings, 0 replies; 10+ messages in thread
From: Anshuman Khandual @ 2023-11-29  7:36 UTC (permalink / raw)
  To: Marc Zyngier, kvmarm, linux-arm-kernel, kvm
  Cc: Will Deacon, Catalin Marinas, Mark Rutland, Ard Biesheuvel,
	James Morse, Suzuki K Poulose, Oliver Upton, Zenghui Yu


On 11/27/23 22:56, Marc Zyngier wrote:
> We have some special handling for VPIPT I-cache in critical parts
> of the cache and TLB maintenance. Remove it.

Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>

> 
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> ---
>  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(-)
> 
> diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h
> index 49e0d4b36bd0..e3e793d0ec30 100644
> --- a/arch/arm64/include/asm/kvm_mmu.h
> +++ b/arch/arm64/include/asm/kvm_mmu.h
> @@ -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
> diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> index 9d23a51d7f75..b29f15418c0a 100644
> --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c
> +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> @@ -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(). */
> diff --git a/arch/arm64/kvm/hyp/nvhe/tlb.c b/arch/arm64/kvm/hyp/nvhe/tlb.c
> index 1b265713d6be..a60fb13e2192 100644
> --- a/arch/arm64/kvm/hyp/nvhe/tlb.c
> +++ b/arch/arm64/kvm/hyp/nvhe/tlb.c
> @@ -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);
>  }
> diff --git a/arch/arm64/kvm/hyp/vhe/tlb.c b/arch/arm64/kvm/hyp/vhe/tlb.c
> index b636b4111dbf..b32e2940df7d 100644
> --- a/arch/arm64/kvm/hyp/vhe/tlb.c
> +++ b/arch/arm64/kvm/hyp/vhe/tlb.c
> @@ -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);
>  }

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 3/3] arm64: Rename reserved values for CTR_EL0.L1Ip
  2023-11-29  7:13   ` Anshuman Khandual
@ 2023-11-29 13:06     ` Marc Zyngier
  0 siblings, 0 replies; 10+ messages in thread
From: Marc Zyngier @ 2023-11-29 13:06 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: kvmarm, linux-arm-kernel, kvm, Will Deacon, Catalin Marinas,
	Mark Rutland, Ard Biesheuvel, James Morse, Suzuki K Poulose,
	Oliver Upton, Zenghui Yu

On Wed, 29 Nov 2023 07:13:57 +0000,
Anshuman Khandual <anshuman.khandual@arm.com> wrote:
> 
> 
> 
> On 11/27/23 22:56, Marc Zyngier wrote:
> > 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...
> > 
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > ---
> >  arch/arm64/tools/sysreg | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/arm64/tools/sysreg b/arch/arm64/tools/sysreg
> > index 96cbeeab4eec..5a217e0fce45 100644
> > --- a/arch/arm64/tools/sysreg
> > +++ b/arch/arm64/tools/sysreg
> > @@ -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.

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

	M.

-- 
Without deviation from the norm, progress is not possible.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/3] arm64: Drop support for VPIPT i-cache policy
  2023-11-27 17:26 [PATCH v2 0/3] arm64: Drop support for VPIPT i-cache policy Marc Zyngier
                   ` (3 preceding siblings ...)
  2023-11-29  6:31 ` [PATCH v2 0/3] arm64: Drop support for VPIPT i-cache policy Anshuman Khandual
@ 2023-12-04 13:09 ` Zenghui Yu
  4 siblings, 0 replies; 10+ messages in thread
From: Zenghui Yu @ 2023-12-04 13:09 UTC (permalink / raw)
  To: Marc Zyngier
  Cc: kvmarm, linux-arm-kernel, kvm, Will Deacon, Catalin Marinas,
	Mark Rutland, Ard Biesheuvel, James Morse, Suzuki K Poulose,
	Oliver Upton

On 2023/11/28 1:26, Marc Zyngier wrote:
> 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

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

Reviewed-by: Zenghui Yu <yuzenghui@huawei.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-12-04 13:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-27 17:26 [PATCH v2 0/3] arm64: Drop support for VPIPT i-cache policy Marc Zyngier
2023-11-27 17:26 ` [PATCH v2 1/3] KVM: arm64: Remove VPIPT I-cache handling Marc Zyngier
2023-11-29  7:36   ` Anshuman Khandual
2023-11-27 17:26 ` [PATCH v2 2/3] arm64: Kill detection of VPIPT i-cache policy Marc Zyngier
2023-11-29  7:25   ` Anshuman Khandual
2023-11-27 17:26 ` [PATCH v2 3/3] arm64: Rename reserved values for CTR_EL0.L1Ip Marc Zyngier
2023-11-29  7:13   ` Anshuman Khandual
2023-11-29 13:06     ` Marc Zyngier
2023-11-29  6:31 ` [PATCH v2 0/3] arm64: Drop support for VPIPT i-cache policy Anshuman Khandual
2023-12-04 13:09 ` Zenghui Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).