Skip to contentSkip to conversation

target/arm: Add support for FEAT_TLBIOS and FEAT_TLBIRANGE

PATCH Superseded Rebecca Cran 3 participants 7 messages Mar 16, 2021

v4 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v4 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 v3 to v4:

o Adapted code from the existing flush_page_bits_* functions to support flushing a range of addresses.
o Changed the API from num_pages to length.
o Removed the exception generation from tlbi_aa64_range_get_num_pages.
o The addr is no longer passed into tlbi_aa64_range_get_num_pages.
o Other changes based on feedback.

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      | 135 +++++++
 include/exec/exec-all.h |  45 +++
 target/arm/cpu.h        |  10 +
 target/arm/cpu64.c      |   1 +
 target/arm/helper.c     | 393 ++++++++++++++++++++
 5 files changed, 584 insertions(+)
Signature · 1 line
2.26.2
#1 lore raw

PATCH v4 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      | 135 +++++++++
 include/exec/exec-all.h |  45 +++
 target/arm/cpu.h        |   5 +
 target/arm/helper.c     | 318 ++++++++++++++++++++
 4 files changed, 503 insertions(+)
accel/tcg/cputlb.c +135 -0
index 8a7b779270a4..5ef2a562f4d3 100644
@@ -943,6 +943,141 @@ void tlb_flush_page_bits_by_mmuidx_all_cpus_synced(CPUState *src_cpu,
     }
 }
 
+typedef struct {
+    target_ulong addr;
+    target_ulong length;
+    uint16_t idxmap;
+    uint16_t bits;
+}  TLBFlushPageRangeBitsByMMUIdxData;
+
+static void
+tlb_flush_page_range_bits_by_mmuidx_async_0(CPUState *cpu,
+                                            target_ulong addr,
+                                            target_ulong length,
+                                            uint16_t idxmap,
+                                            unsigned bits)
+{
+    CPUArchState *env = cpu->env_ptr;
+    int mmu_idx;
+    target_ulong page;
+
+    assert_cpu_is_self(cpu);
+
+    tlb_debug("page addr:" TARGET_FMT_lx "/%u len: " TARGET_FMT_lx
+              " mmu_map:0x%x\n",
+              addr, bits, length, idxmap);
+
+    qemu_spin_lock(&env_tlb(env)->c.lock);
+    for (page = addr; page < (addr + length); page += TARGET_PAGE_SIZE) {
+        for (mmu_idx = 0; mmu_idx < NB_MMU_MODES; mmu_idx++) {
+            if ((idxmap >> mmu_idx) & 1) {
+                tlb_flush_page_bits_locked(env, mmu_idx, page, bits);
+                tb_flush_jmp_cache(cpu, page);
+            }
+        }
+    }
+    qemu_spin_unlock(&env_tlb(env)->c.lock);
+}
+
+static void
+tlb_flush_page_range_bits_by_mmuidx_async_1(CPUState *cpu,
+                                            run_on_cpu_data data)
+{
+    TLBFlushPageRangeBitsByMMUIdxData *d = data.host_ptr;
+
+    tlb_flush_page_range_bits_by_mmuidx_async_0(cpu, d->addr, d->length,
+                                                d->idxmap, d->bits);
+
+    g_free(d);
+}
+
+void tlb_flush_page_range_bits_by_mmuidx(CPUState *cpu,
+                                         target_ulong addr,
+                                         target_ulong length,
+                                         uint16_t idxmap,
+                                         unsigned bits)
+{
+    TLBFlushPageRangeBitsByMMUIdxData d;
+    TLBFlushPageRangeBitsByMMUIdxData *p;
+
+    /* This should already be page aligned */
+    addr &= TARGET_PAGE_BITS;
+
+    /* If all bits are significant, this devolves to tlb_flush_page. */
+    if (bits >= TARGET_LONG_BITS) {
+        tlb_flush_page_by_mmuidx(cpu, addr, idxmap);
+        return;
+    }
+    /* If no page bits are significant, this devolves to tlb_flush. */
+    if (bits < TARGET_PAGE_BITS) {
+        tlb_flush_by_mmuidx(cpu, idxmap);
+        return;
+    }
+
+    d.addr = addr & TARGET_PAGE_MASK;
+    d.idxmap = idxmap;
+    d.bits = bits;
+    d.length = length;
+
+    if (qemu_cpu_is_self(cpu)) {
+        tlb_flush_page_range_bits_by_mmuidx_async_0(cpu, addr, length,
+                                                    idxmap, bits);
+    } else {
+        p = g_new(TLBFlushPageRangeBitsByMMUIdxData, 1);
+
+        /* Allocate a structure, freed by the worker.  */
+        *p = d;
+        async_run_on_cpu(cpu, tlb_flush_page_range_bits_by_mmuidx_async_1,
+                         RUN_ON_CPU_HOST_PTR(p));
+    }
+}
+
+void tlb_flush_page_range_bits_by_mmuidx_all_cpus_synced(CPUState *src_cpu,
+                                                         target_ulong addr,
+                                                         target_ulong length,
+                                                         uint16_t idxmap,
+                                                         unsigned bits)
+{
+    TLBFlushPageRangeBitsByMMUIdxData d;
+    TLBFlushPageRangeBitsByMMUIdxData *p;
+    CPUState *dst_cpu;
+
+    /* This should already be page aligned */
+    addr &= TARGET_PAGE_BITS;
+
+    /* If all bits are significant, this devolves to tlb_flush_page. */
+    if (bits >= TARGET_LONG_BITS) {
+        tlb_flush_page_by_mmuidx_all_cpus_synced(src_cpu, addr, idxmap);
+        return;
+    }
+    /* If no page bits are significant, this devolves to tlb_flush. */
+    if (bits < TARGET_PAGE_BITS) {
+        tlb_flush_by_mmuidx_all_cpus_synced(src_cpu, idxmap);
+        return;
+    }
+
+    d.addr = addr;
+    d.idxmap = idxmap;
+    d.bits = bits;
+    d.length = length;
+
+    /* Allocate a separate data block for each destination cpu.  */
+    CPU_FOREACH(dst_cpu) {
+        if (dst_cpu != src_cpu) {
+            p = g_new(TLBFlushPageRangeBitsByMMUIdxData, 1);
+            *p = d;
+            async_run_on_cpu(dst_cpu,
+                             tlb_flush_page_range_bits_by_mmuidx_async_1,
+                             RUN_ON_CPU_HOST_PTR(p));
+        }
+    }
+
+    p = g_new(TLBFlushPageRangeBitsByMMUIdxData, 1);
+    *p = d;
+    async_safe_run_on_cpu(src_cpu, tlb_flush_page_range_bits_by_mmuidx_async_1,
+                            RUN_ON_CPU_HOST_PTR(p));
+}
+
 /* update the TLBs so that writes to code in the virtual page 'addr'
    can be detected */
 void tlb_protect_code(ram_addr_t ram_addr)
include/exec/exec-all.h +45 -0

57 lines not on this page · raw message

target/arm/cpu.h +5 -0
index 193a49ec7fac..32b78a4ef587 100644
@@ -4038,6 +4038,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 +318 -0

336 lines not on this page · raw message

Signature · 1 line
2.26.2
#2 lore raw

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

Quoted 1 line · Rebecca Cran

+ for (page = addr; page < (addr + length); page += TARGET_PAGE_SIZE) {

This test means that it's impossible to flush the last page of the address space (addr + length == 0). I think better to do

  for (l = 0; l < length; l += TARGET_PAGE_SIZE)
      page = addr + l;
      ...

accel/tcg/cputlb.c void tlb_flush_page_bits_by_mmuidx_all_cpus_synced(CPUState *src_cpu, · line 974

Quoted 3 lines
accel/tcg/cputlb.c +3 -0
+        for (mmu_idx = 0; mmu_idx < NB_MMU_MODES; mmu_idx++) {
+            if ((idxmap >> mmu_idx) & 1) {
+                tlb_flush_page_bits_locked(env, mmu_idx, page, bits);

Hmm. I'm not keen on this. You're not able to notice the special cases within, where we flush the entire tlb -- and therefore you do not need to continue the outer loop for this mmuidx.

Quoted 1 line

+ tb_flush_jmp_cache(cpu, page);

This does not need to be in the mmuidx loop. But since above means that the mmuidx loop should be the outer loop, this would go in a separate page loop by itself.

Quoted 7 lines
accel/tcg/cputlb.c +7 -0
+void tlb_flush_page_range_bits_by_mmuidx(CPUState *cpu,
+                                         target_ulong addr,
+                                         target_ulong length,
+                                         uint16_t idxmap,
+                                         unsigned bits)
+{
+    TLBFlushPageRangeBitsByMMUIdxData d;

accel/tcg/cputlb.c void tlb_flush_page_bits_by_mmuidx_all_cpus_synced(CPUState *src_cpu, · line 1010

Quoted 10 lines
accel/tcg/cputlb.c +10 -0
+    TLBFlushPageRangeBitsByMMUIdxData *p;
+
+    /* This should already be page aligned */
+    addr &= TARGET_PAGE_BITS;
+
+    /* If all bits are significant, this devolves to tlb_flush_page. */
+    if (bits >= TARGET_LONG_BITS) {
+        tlb_flush_page_by_mmuidx(cpu, addr, idxmap);
+        return;
+    }

This case is incorrect.

The cputlb changes should have remained a separate patch.

Quoted 12 lines
target/arm/helper.c +8 -0
@@ -4759,6 +4759,241 @@ static void tlbi_aa64_vae3is_write(CPUARMState *env, const ARMCPRegInfo *ri,
                                                    ARMMMUIdxBit_SE3, bits);
  }
 
+#ifdef TARGET_AARCH64
+static uint64_t tlbi_aa64_range_get_length(CPUARMState *env,
+                                           uint64_t value)
+{
+    unsigned int page_size;
+    unsigned int page_size_granule;
+    uint64_t num;
+    uint64_t scale;

target/arm/helper.c static void tlbi_aa64_vae3is_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 4779

Quoted 10 lines
target/arm/helper.c +10 -0
+    uint64_t exponent;
+    uint64_t length;
+
+    num = extract64(value, 39, 4);
+    scale = extract64(value, 44, 2);
+    page_size_granule = extract64(value, 46, 2);
+
+    switch (page_size_granule) {
+    case 1:
+      page_size = 4096;

Indentation is off?

target/arm/helper.c static void tlbi_aa64_vae3is_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 4785

Quoted 6 lines
target/arm/helper.c +6 -0
+      break;
+    case 2:
+      page_size = 16384;
+      break;
+    case 3:
+      page_size = 65536;

You might as well have this as page_shift = {12,14,16}, or perhaps page_shift = page_size_granule * 2 + 10 instead of the full switch.

target/arm/helper.c static void tlbi_aa64_vae3is_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 4794

Quoted 2 lines
target/arm/helper.c +2 -0
+    exponent = (5 * scale) + 1;
+    length = ((num + 1) << exponent) * page_size;
  length = (num + 1) << (exponent + page_shift);

Review static void tlbi_aa64_vae3is_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 4789

Quoted 2 lines
(quoted diff) +2 -0
+    mask = vae1_tlbmask(env);
+    if (regime_has_2_ranges(mask)) {

You can't pass in mask.

All of the mmuidx will have the same form, so ctz32(mask) would pick out the mmuidx for the first bit.

Review static void tlbi_aa64_vae3is_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 4790

Quoted 1 line
(quoted diff) +1 -0
+    if (regime_has_2_ranges(secure ? ARMMMUIdxBit_SE2 : ARMMMUIdxBit_E2)) {

again. Only this time we know that E2 & SE2 have one range. Only (S)EL1&0 and (S)EL2&0 have two ranges.

Review static void tlbi_aa64_vae3is_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 4791

Quoted 1 line
(quoted diff) +1 -0
+    if (regime_has_2_ranges(ARMMMUIdxBit_SE3)) {

Likewise, E3 has only one range.

r~

#3 lore raw

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

Quoted 10 lines · Richard Henderson
Quoted 2 lines · Rebecca Cran

+    for (page = addr; page < (addr + length); page += TARGET_PAGE_SIZE) {

This test means that it's impossible to flush the last page of the address space (addr + length == 0).  I think better to do

  for (l = 0; l < length; l += TARGET_PAGE_SIZE)
      page = addr + l;
      ...

Quoted 5 lines
Quoted 3 lines

+        for (mmu_idx = 0; mmu_idx < NB_MMU_MODES; mmu_idx++) { +            if ((idxmap >> mmu_idx) & 1) {
+                tlb_flush_page_bits_locked(env, mmu_idx, page, bits);

Hmm.  I'm not keen on this.  You're not able to notice the special cases within, where we flush the entire tlb -- and therefore you do not need to continue the outer loop for this mmuidx.

Would you be happy to have tlb_flush_page_bits_locked updated to return a bool, indicating if an entire flush has been done?

Quoted 1 line

The cputlb changes should have remained a separate patch.

Ok, I'll split it out.

Signature · 1 line
Rebecca Cran
#4 lore raw

PATCH v4 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    |  5 ++
 target/arm/helper.c | 75 ++++++++++++++++++++
 2 files changed, 80 insertions(+)
target/arm/cpu.h +5 -0
index 32b78a4ef587..272fde83ca4e 100644
@@ -4043,6 +4043,11 @@ 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) != 0;
+}
+
 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
#5 lore raw

PATCH v4 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 f0a9e968c9c1..f42803ecaf1d 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); /* FEAT_TLBIRANGE */
         t = FIELD_DP64(t, ID_AA64ISAR0, RNDR, 1);
         cpu->isar.id_aa64isar0 = t;
 
Signature · 1 line
2.26.2
#6 lore raw
In reply to Rebecca Cran
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [PATCH v4 0/3] target/arm: Add support for FEAT_TLBIOS and FEAT_TLBIRANGE

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu

 - [tag update]      patchew/[email protected] -> patchew/[email protected]
 - [tag update]      patchew/[email protected] -> patchew/[email protected]
 - [tag update]      patchew/[email protected] -> patchew/[email protected]
 - [tag update]      patchew/[email protected] -> patchew/[email protected]
 * [new tag]         patchew/[email protected] -> patchew/[email protected]

Switched to a new branch 'test'
e9f3e00 target/arm: set ID_AA64ISAR0.TLB to 2 for max AARCH64 CPU type 8bcac4c target/arm: Add support for FEAT_TLBIOS
f171966 target/arm: Add support for FEAT_TLBIRANGE

=== OUTPUT BEGIN ===
1/3 Checking commit f17196657ee3 (target/arm: Add support for FEAT_TLBIRANGE)
WARNING: line over 80 characters
#218: FILE: include/exec/exec-all.h:354:
+static inline void tlb_flush_page_range_bits_by_mmuidx_all_cpus_synced(CPUState *src_cpu,

WARNING: line over 80 characters
#219: FILE: include/exec/exec-all.h:355:
+ target_ulong addr,

ERROR: line over 90 characters
#220: FILE: include/exec/exec-all.h:356:
+ target_ulong length,

WARNING: line over 80 characters
#221: FILE: include/exec/exec-all.h:357:
+ uint16_t idxmap,

WARNING: line over 80 characters
#222: FILE: include/exec/exec-all.h:358:
+ unsigned bits)

total: 1 errors, 4 warnings, 545 lines checked

Patch 1/3 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

2/3 Checking commit 8bcac4c04c8e (target/arm: Add support for FEAT_TLBIOS)
3/3 Checking commit e9f3e002d73d (target/arm: set ID_AA64ISAR0.TLB to 2 for max AARCH64 CPU type) === OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]