|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [XEN][PATCH v5 3/8] xen/arm32: use IPA-based TLBI when supported with FEAT_nTLBPA
From: Haseeb Ashraf <haseeb.ashraf@xxxxxxxxxxx>
Detect TLBI by IPA from ID_MMFR2.UniTLB, which reports the Arm32
instruction support. ID_MMFR5.nTLBPA reports whether intermediate
translation-table walk caches are absent.
Use TLBI IPAS2IS in the p2m range-flush helper only when both
capabilities are present. Without FEAT_nTLBPA, a stage-2-only
invalidation would need a separate stage-1 invalidation, which Arm32
cannot issue for the guest; keep the full guest flush in that case.
Bound the per-page loop with TLBI_MAX_PAGE_OPS, like the Arm64 fallback.
Suggested-by: Julien Grall <julien@xxxxxxx>
Signed-off-by: Haseeb Ashraf <haseeb.ashraf@xxxxxxxxxxx>
---
Changes in v5:
- Bound the loop with TLBI_MAX_PAGE_OPS.
- Put the TLBI instruction in a helper and cite DDI 0487 M.d.
xen/arch/arm/cpufeature.c | 21 +++++++++++-
xen/arch/arm/include/asm/arm32/flushtlb.h | 42 ++++++++++++++++++++---
xen/arch/arm/include/asm/cpregs.h | 1 +
xen/arch/arm/include/asm/cpufeature.h | 21 +++++++++++-
xen/arch/arm/include/asm/processor.h | 7 ++++
5 files changed, 86 insertions(+), 6 deletions(-)
diff --git a/xen/arch/arm/cpufeature.c b/xen/arch/arm/cpufeature.c
index 0a87186a7e..e4e0dd0922 100644
--- a/xen/arch/arm/cpufeature.c
+++ b/xen/arch/arm/cpufeature.c
@@ -17,6 +17,18 @@ DECLARE_BITMAP(cpu_hwcaps, ARM_NCAPS);
struct cpuinfo_arm __read_mostly domain_cpuinfo;
+#ifdef CONFIG_ARM_32
+static bool has_tlb_ipa_instruction(const struct arm_cpu_capabilities *entry)
+{
+ return system_cpuinfo.mm32.unitlb == MM32_UNITLB_BY_IPA;
+}
+
+static bool has_ntlbpa(const struct arm_cpu_capabilities *entry)
+{
+ return system_cpuinfo.mm32.ntlbpa == MM32_NTLBPA_SUPPORT_IMP;
+}
+#endif
+
#ifdef CONFIG_ARM_64
static bool has_ntlbpa(const struct arm_cpu_capabilities *entry)
{
@@ -30,7 +42,14 @@ static bool has_sb_instruction(const struct
arm_cpu_capabilities *entry)
#endif
static const struct arm_cpu_capabilities arm_features[] = {
-#ifdef CONFIG_ARM_64
+#ifdef CONFIG_ARM_32
+ {
+ .desc = "IPA-based TLB Invalidation",
+ .capability = ARM32_HAS_TLB_IPA,
+ .matches = has_tlb_ipa_instruction,
+ },
+#endif
+#if defined(CONFIG_ARM_32) || defined(CONFIG_ARM_64)
{
.desc = "Intermediate caching of translation table walks (nTLBPA)",
.capability = ARM_HAS_NTLBPA,
diff --git a/xen/arch/arm/include/asm/arm32/flushtlb.h
b/xen/arch/arm/include/asm/arm32/flushtlb.h
index 374b8bfe54..b2a96372a4 100644
--- a/xen/arch/arm/include/asm/arm32/flushtlb.h
+++ b/xen/arch/arm/include/asm/arm32/flushtlb.h
@@ -77,6 +77,13 @@ static inline void __flush_xen_tlb_one(vaddr_t va)
/* Only for ARM64_WORKAROUND_REPEAT_TLBI */
static inline void __tlb_repeat_sync(void) {}
+/* TLBI IPAS2IS: invalidate the stage-2 entries of one IPA of the VMID. */
+static inline void tlbi_ipas2is(paddr_t ipa)
+{
+ asm volatile ( STORE_CP32(0, TLBIIPAS2IS)
+ : : "r" (ipa >> PAGE_SHIFT) : "memory" );
+}
+
/*
* Flush a range of IPA's mappings from the TLB of all processors in the
* inner-shareable domain.
@@ -85,12 +92,39 @@ static inline void flush_guest_tlb_range_ipa(paddr_t ipa,
unsigned long size)
{
/*
- * Following can invalidate both stage-1 and stage-2 TLBs depending upon
- * the execution mode.
+ * IPA-based stage-2 invalidation is only useful when FEAT_nTLBPA is
+ * present. Without FEAT_nTLBPA, invalidating stage-2 alone may still
+ * require discarding associated stage-1 side effects, and Arm32 does not
+ * provide a separate guest stage-1 TLBI for that case.
*
- * See Arm ARM (DDI 0487 M.d), G5.9.5, Table G5-23.
+ * A range of TLBI_MAX_PAGE_OPS pages or more is flushed with the whole
+ * VMID, to bound the number of broadcast TLBIs like on Arm64.
*/
- flush_guest_tlb();
+ if ( cpus_have_const_cap(ARM_HAS_NTLBPA) &&
+ cpus_have_const_cap(ARM32_HAS_TLB_IPA) &&
+ (size >> PAGE_SHIFT) < TLBI_MAX_PAGE_OPS )
+ {
+ paddr_t end = ipa + size;
+
+ dsb(ishst); /* Ensure prior page-tables updates have completed */
+ for ( ; ipa < end; ipa += PAGE_SIZE )
+ {
+ /* Flush stage-2 TLBs for this IPA. */
+ tlbi_ipas2is(ipa);
+ }
+ dsb(ish);
+ isb();
+ }
+ else
+ {
+ /*
+ * Following can invalidate both stage-1 and stage-2 TLBs depending
+ * upon the execution mode.
+ *
+ * See Arm ARM (DDI 0487 M.d), G5.9.5, Table G5-23.
+ */
+ flush_guest_tlb();
+ }
}
#endif /* __ASM_ARM_ARM32_FLUSHTLB_H__ */
diff --git a/xen/arch/arm/include/asm/cpregs.h
b/xen/arch/arm/include/asm/cpregs.h
index 7e559253d7..9869bc7d3c 100644
--- a/xen/arch/arm/include/asm/cpregs.h
+++ b/xen/arch/arm/include/asm/cpregs.h
@@ -223,6 +223,7 @@
#define TLBIMVA p15,0,c8,c7,1 /* invalidate unified TLB entry by MVA
*/
#define TLBIASID p15,0,c8,c7,2 /* invalid unified TLB by ASID match */
#define TLBIMVAA p15,0,c8,c7,3 /* invalidate unified TLB entries by
MVA all ASID */
+#define TLBIIPAS2IS p15,4,c8,c0,1 /* Invalidate unified TLB entry for
stage 2 by IPA inner shareable */
#define TLBIALLHIS p15,4,c8,c3,0 /* Invalidate Entire Hyp. Unified TLB
inner shareable */
#define TLBIMVAHIS p15,4,c8,c3,1 /* Invalidate Unified Hyp. TLB by MVA
inner shareable */
#define TLBIALLNSNHIS p15,4,c8,c3,4 /* Invalidate Entire Non-Secure
Non-Hyp. Unified TLB inner shareable */
diff --git a/xen/arch/arm/include/asm/cpufeature.h
b/xen/arch/arm/include/asm/cpufeature.h
index 97e371724f..38e01aa94d 100644
--- a/xen/arch/arm/include/asm/cpufeature.h
+++ b/xen/arch/arm/include/asm/cpufeature.h
@@ -77,8 +77,9 @@
#define ARM_HAS_SB 16
#define ARM64_WORKAROUND_1508412 17
#define ARM_HAS_NTLBPA 18
+#define ARM32_HAS_TLB_IPA 19
-#define ARM_NCAPS 19
+#define ARM_NCAPS 20
#ifndef __ASSEMBLER__
@@ -454,6 +455,24 @@ struct cpuinfo_arm {
struct {
register_t bits[6];
+ struct {
+ /* MMFR0 */
+ unsigned long __res0:32;
+ /* MMFR1 */
+ unsigned long __res1:32;
+ /* MMFR2 */
+ unsigned long __res2:16;
+ unsigned long unitlb:4;
+ unsigned long __res3:12;
+ /* MMFR3 */
+ unsigned long __res4:32;
+ /* MMFR4 */
+ unsigned long __res5:32;
+ /* MMFR5 */
+ unsigned long __res6:4;
+ unsigned long ntlbpa:4;
+ unsigned long __res7:24;
+ };
} mm32;
struct {
diff --git a/xen/arch/arm/include/asm/processor.h
b/xen/arch/arm/include/asm/processor.h
index 49774b65eb..6899f91ef0 100644
--- a/xen/arch/arm/include/asm/processor.h
+++ b/xen/arch/arm/include/asm/processor.h
@@ -484,6 +484,13 @@
/* FSR long format */
#define FSRL_STATUS_DEBUG (_AC(0x22,UL)<<0)
+#ifdef CONFIG_ARM_32
+#define MM32_UNITLB_NI 0x0
+#define MM32_UNITLB_BY_IPA 0x6
+
+#define MM32_NTLBPA_SUPPORT_NI 0x0
+#define MM32_NTLBPA_SUPPORT_IMP 0x1
+#endif
#ifdef CONFIG_ARM_64
#define MM64_VMID_8_BITS_SUPPORT 0x0
#define MM64_VMID_16_BITS_SUPPORT 0x2
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |