[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[XEN][PATCH v5 2/8] xen/arm: skip the stage-1 TLBI after IPA flush with FEAT_nTLBPA



From: Haseeb Ashraf <haseeb.ashraf@xxxxxxxxxxx>

Without FEAT_nTLBPA, intermediate caching of translation table walks
might include non-coherent physical translation caches. These caches
can hold previously valid entries indexed by the physical address of a
table entry or, for stage-1 walks, by its intermediate physical address.
An IPA-based stage-2 invalidation does not remove the stage-1 entries,
so it must be followed by a stage-1 invalidation.

FEAT_nTLBPA (ID_AA64MMFR1_EL1.nTLBPA) says that the implementation has
no such caches. Detect it as a CPU capability and skip the follow-up
stage-1 invalidation in flush_guest_tlb_range_ipa() when it is present.
The broadcast TLBI completion sequence remains explicit.

The local flush used when a pCPU switches between vCPUs of a domain
stays unconditional. It drops the prior vCPU's stage-1 translations;
FEAT_nTLBPA does not change that requirement.

Suggested-by: Mohamed Mediouni <mohamed@xxxxxxxxxxxxxxxx>
Signed-off-by: Haseeb Ashraf <haseeb.ashraf@xxxxxxxxxxx>
---
Changes in v5:
- Skip only the stage-1 invalidation that follows IPA invalidation.
- Keep the local vCPU-switch flush unconditional.
- Base the description on the ID register field.

 xen/arch/arm/cpufeature.c                 | 12 ++++++++++++
 xen/arch/arm/include/asm/arm64/flushtlb.h |  7 +++++--
 xen/arch/arm/include/asm/cpufeature.h     |  6 ++++--
 xen/arch/arm/include/asm/processor.h      |  2 ++
 xen/arch/arm/mmu/p2m.c                    |  2 ++
 5 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/xen/arch/arm/cpufeature.c b/xen/arch/arm/cpufeature.c
index 8d8cd19a96..0a87186a7e 100644
--- a/xen/arch/arm/cpufeature.c
+++ b/xen/arch/arm/cpufeature.c
@@ -18,6 +18,11 @@ DECLARE_BITMAP(cpu_hwcaps, ARM_NCAPS);
 struct cpuinfo_arm __read_mostly domain_cpuinfo;
 
 #ifdef CONFIG_ARM_64
+static bool has_ntlbpa(const struct arm_cpu_capabilities *entry)
+{
+    return system_cpuinfo.mm64.ntlbpa == MM64_NTLBPA_SUPPORT_IMP;
+}
+
 static bool has_sb_instruction(const struct arm_cpu_capabilities *entry)
 {
     return system_cpuinfo.isa64.sb;
@@ -25,6 +30,13 @@ static bool has_sb_instruction(const struct 
arm_cpu_capabilities *entry)
 #endif
 
 static const struct arm_cpu_capabilities arm_features[] = {
+#ifdef CONFIG_ARM_64
+    {
+        .desc = "Intermediate caching of translation table walks (nTLBPA)",
+        .capability = ARM_HAS_NTLBPA,
+        .matches = has_ntlbpa,
+    },
+#endif
 #ifdef CONFIG_ARM_64
     {
         .desc = "Speculation barrier instruction (SB)",
diff --git a/xen/arch/arm/include/asm/arm64/flushtlb.h 
b/xen/arch/arm/include/asm/arm64/flushtlb.h
index b3bce7baf2..ff2ce2bae2 100644
--- a/xen/arch/arm/include/asm/arm64/flushtlb.h
+++ b/xen/arch/arm/include/asm/arm64/flushtlb.h
@@ -188,8 +188,11 @@ static inline void flush_guest_tlb_range_ipa(paddr_t ipa, 
unsigned long size)
      * with stage-1 and the old stage-2 translation. Linux does the same (see
      * __kvm_tlb_flush_vmid_ipa()).
      */
-    dsb(ish);
-    tlbi_vmalle1is();
+    if ( !cpus_have_const_cap(ARM_HAS_NTLBPA) )
+    {
+        dsb(ish);
+        tlbi_vmalle1is();
+    }
 
     tlbi_complete_broadcast();
 }
diff --git a/xen/arch/arm/include/asm/cpufeature.h 
b/xen/arch/arm/include/asm/cpufeature.h
index c554686415..97e371724f 100644
--- a/xen/arch/arm/include/asm/cpufeature.h
+++ b/xen/arch/arm/include/asm/cpufeature.h
@@ -76,8 +76,9 @@
 #define ARM_WORKAROUND_BHB_SMCC_3 15
 #define ARM_HAS_SB 16
 #define ARM64_WORKAROUND_1508412 17
+#define ARM_HAS_NTLBPA 18
 
-#define ARM_NCAPS           18
+#define ARM_NCAPS           19
 
 #ifndef __ASSEMBLER__
 
@@ -288,7 +289,8 @@ struct cpuinfo_arm {
             unsigned long ets:4;
             unsigned long __res2:4;
             unsigned long afp:4;
-            unsigned long __res3:12;
+            unsigned long ntlbpa:4;
+            unsigned long __res3:8;
             unsigned long ecbhb:4;
 
             /* MMFR2 */
diff --git a/xen/arch/arm/include/asm/processor.h 
b/xen/arch/arm/include/asm/processor.h
index 8ee8f88fb4..49774b65eb 100644
--- a/xen/arch/arm/include/asm/processor.h
+++ b/xen/arch/arm/include/asm/processor.h
@@ -487,6 +487,8 @@
 #ifdef CONFIG_ARM_64
 #define MM64_VMID_8_BITS_SUPPORT    0x0
 #define MM64_VMID_16_BITS_SUPPORT   0x2
+#define MM64_NTLBPA_SUPPORT_NI      0x0
+#define MM64_NTLBPA_SUPPORT_IMP     0x1
 #endif
 
 #define MM64_MSA_PMSA_SUPPORT       0xf
diff --git a/xen/arch/arm/mmu/p2m.c b/xen/arch/arm/mmu/p2m.c
index b93ead6c46..3b1b9b394c 100644
--- a/xen/arch/arm/mmu/p2m.c
+++ b/xen/arch/arm/mmu/p2m.c
@@ -236,6 +236,8 @@ void p2m_restore_state(struct vcpu *n)
      * All vCPUs of the domain share the same p2m and the same effective
      * stage-2 translation regime. The stage-1 translations of the vCPU that
      * ran last on this pCPU must not be used by this one.
+     * This remains necessary with FEAT_nTLBPA, which only removes the
+     * stage-1 invalidation following an IPA-based stage-2 invalidation.
      */
     if ( *last_vcpu_ran != INVALID_VCPU_ID && *last_vcpu_ran != n->vcpu_id )
         flush_guest_tlb_s1_local();



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.