Skip to contentSkip to conversation

target/arm: Add support for FEAT_TLBIOS and FEAT_TLBIRANGE

PATCH Superseded Rebecca Cran 1 participant 5 messages Mar 8, 2021 – Mar 9, 2021

v2 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v2 cover target/arm: Add support for FEAT_TLBIOS and FEAT_TLBIRANGE

ARMv8.4 adds the mandatory FEAT_TLBIOS and FEAT_TLBIRANGE. They provides TLBI maintenance instructions that extend to the Outer Shareable domain and that apply to a range of input addresses.

Changes from v1 to v2:

o Split new instructions into different ARMCPRegInfo sections, and only add them if ID_AA64ISAR0.TLB indicates they're supported.
o Improve the performance of the new code in cputlb.c.

Testing:
o Ran scripts/checkpatch.pl: functions in exec-all.h fail, but I think that's acceptable?
o Built all targets
o Ran test code that executed the new instructions
o Ran "make test": a qtest-sparc repeatedly timed out, but that's unlikely to be due to my changes.

Rebecca Cran (3):
target/arm: Add support for FEAT_TLBIRANGE target/arm: Add support for FEAT_TLBIOS
target/arm: set ID_AA64ISAR0.TLB to 2 for max AARCH64 CPU type

 accel/tcg/cputlb.c      |  67 ++++
 include/exec/exec-all.h |  41 +++
 target/arm/cpu.h        |  11 +
 target/arm/cpu64.c      |   1 +
 target/arm/helper.c     | 323 ++++++++++++++++++++
 5 files changed, 443 insertions(+)
Signature · 1 line
2.26.2
#1 lore raw

PATCH v2 1/3 target/arm: Add support for FEAT_TLBIRANGE

ARMv8.4 adds the mandatory FEAT_TLBIRANGE. It provides TLBI maintenance instructions that apply to a range of input addresses.

---
 accel/tcg/cputlb.c      |  67 ++++++
 include/exec/exec-all.h |  41 ++++
 target/arm/cpu.h        |   5 +
 target/arm/helper.c     | 248 ++++++++++++++++++++
 4 files changed, 361 insertions(+)
accel/tcg/cputlb.c +67 -0
index 8a7b779270a4..ebf91cc4757f 100644
@@ -590,6 +590,24 @@ static void tlb_flush_page_by_mmuidx_async_2(CPUState *cpu,
     g_free(d);
 }
 
+typedef struct {
+    target_ulong addr;
+    unsigned int num_pages;
+    uint16_t idxmap;
+} TLBFlushPageRangeByMMUIdxData;
+
+static void tlb_flush_page_range_by_mmuidx_async_0(CPUState *cpu,
+                                                   run_on_cpu_data data)
+{
+    TLBFlushPageRangeByMMUIdxData *d = data.host_ptr;
+
+    tlb_flush_page_range_by_mmuidx(cpu,
+                                   d->addr,
+                                   d->num_pages,
+                                   d->idxmap);
+    g_free(d);
+}
+
 void tlb_flush_page_by_mmuidx(CPUState *cpu, target_ulong addr, uint16_t idxmap)
 {
     tlb_debug("addr: "TARGET_FMT_lx" mmu_idx:%" PRIx16 "\n", addr, idxmap);
@@ -623,6 +641,55 @@ void tlb_flush_page(CPUState *cpu, target_ulong addr)
     tlb_flush_page_by_mmuidx(cpu, addr, ALL_MMUIDX_BITS);
 }
 
+void tlb_flush_page_range_by_mmuidx(CPUState *cpu, target_ulong addr,
+                                    unsigned int num_pages, uint16_t idxmap)
+{
+    int i;
+    int mmu_idx;
+    target_ulong p;
+    CPUArchState *env = cpu->env_ptr;
+
+    /* This should already be page aligned */
+    addr &= TARGET_PAGE_MASK;
+
+    assert_cpu_is_self(cpu);
+
+    tlb_debug("page addr:" TARGET_FMT_lx " mmu_map:0x%x\n", addr, idxmap);
+
+    qemu_spin_lock(&env_tlb(env)->c.lock);
+    for (i = 0; i < num_pages; i++) {
+        for (mmu_idx = 0; mmu_idx < NB_MMU_MODES; mmu_idx++) {
+            if ((idxmap >> mmu_idx) & 1) {
+                p = addr + (i * TARGET_PAGE_SIZE);
+                tlb_flush_page_locked(env, mmu_idx, p);
+                tb_flush_jmp_cache(cpu, addr);
+            }
+        }
+    }
+    qemu_spin_unlock(&env_tlb(env)->c.lock);
+}
+
+void tlb_flush_page_range_by_mmuidx_all_cpus_synced(CPUState *src_cpu,
+                                                    target_ulong addr,
+                                                    unsigned int num_pages,
+                                                    uint16_t idxmap)
+{
+    CPUState *dst_cpu;
+    TLBFlushPageRangeByMMUIdxData *d;
+
+    CPU_FOREACH(dst_cpu) {
+        d = g_new(TLBFlushPageRangeByMMUIdxData, 1);
+
+        d->addr = addr;
+        d->num_pages = num_pages;
+        d->idxmap = idxmap;
+
+        async_run_on_cpu(dst_cpu,
+                         tlb_flush_page_range_by_mmuidx_async_0,
+                         RUN_ON_CPU_HOST_PTR(d));
+    }
+}
+
 void tlb_flush_page_by_mmuidx_all_cpus(CPUState *src_cpu, target_ulong addr,
                                        uint16_t idxmap)
 {
include/exec/exec-all.h +41 -0

53 lines not on this page · raw message

target/arm/cpu.h +5 -0
index efa1618c4d51..782a77c7ca3b 100644
@@ -4030,6 +4030,11 @@ static inline bool isar_feature_aa64_pauth_arch(const ARMISARegisters *id)
     return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, APA) != 0;
 }
 
+static inline bool isar_feature_aa64_tlbirange(const ARMISARegisters *id)
+{
+    return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TLB) == 2;
+}
+
 static inline bool isar_feature_aa64_sb(const ARMISARegisters *id)
 {
     return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, SB) != 0;
target/arm/helper.c +248 -0

266 lines not on this page · raw message

Signature · 1 line
2.26.2
#2 lore raw

Re: [PATCH v2 1/3] target/arm: Add support for FEAT_TLBIRANGE

Quoted 4 lines · Rebecca Cran

ARMv8.4 adds the mandatory FEAT_TLBIRANGE. It provides TLBI maintenance instructions that apply to a range of input addresses.

I realized this only partially addresses the feedback from v1. Specifically, it still doesn't take TBI into account.

Signature · 1 line
Rebecca Cran
#3 lore raw

PATCH v2 2/3 target/arm: Add support for FEAT_TLBIOS

In reply to Rebecca Cran

ARMv8.4 adds the mandatory FEAT_TLBIOS. It provides TLBI maintenance instructions that extend to the Outer Shareable domain.

---
 target/arm/cpu.h    |  6 ++
 target/arm/helper.c | 75 ++++++++++++++++++++
 2 files changed, 81 insertions(+)
target/arm/cpu.h +6 -0
index 782a77c7ca3b..1cab297f0fa6 100644
@@ -4035,6 +4035,12 @@ static inline bool isar_feature_aa64_tlbirange(const ARMISARegisters *id)
     return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TLB) == 2;
 }
 
+static inline bool isar_feature_aa64_tlbios(const ARMISARegisters *id)
+{
+    return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TLB) == 1 ||
+           FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TLB) == 2;
+}
+
 static inline bool isar_feature_aa64_sb(const ARMISARegisters *id)
 {
     return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, SB) != 0;
target/arm/helper.c +75 -0

87 lines not on this page · raw message

Signature · 1 line
2.26.2
#4 lore raw

PATCH v2 3/3 target/arm: set ID_AA64ISAR0.TLB to 2 for max AARCH64 CPU type

In reply to Rebecca Cran

Indicate support for FEAT_TLBIOS and FEAT_TLBIRANGE by setting ID_AA64ISAR0.TLB to 2 for the max AARCH64 CPU type.

---
 target/arm/cpu64.c | 1 +
 1 file changed, 1 insertion(+)
target/arm/cpu64.c +1 -0
index c255f1bcc393..e1003fd96138 100644
@@ -651,6 +651,7 @@ static void aarch64_max_initfn(Object *obj)
         t = FIELD_DP64(t, ID_AA64ISAR0, DP, 1);
         t = FIELD_DP64(t, ID_AA64ISAR0, FHM, 1);
         t = FIELD_DP64(t, ID_AA64ISAR0, TS, 2); /* v8.5-CondM */
+        t = FIELD_DP64(t, ID_AA64ISAR0, TLB, 2);
         t = FIELD_DP64(t, ID_AA64ISAR0, RNDR, 1);
         cpu->isar.id_aa64isar0 = t;
 
Signature · 1 line
2.26.2