Skip to contentSkip to conversation

target/arm: Remove some TARGET_AARCH64 uses (MTE & gdbstub)

PATCH In review Philippe Mathieu-Daudé 2 participants 18 messages Apr 4, 2025 – Apr 5, 2025 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover target/arm: Remove some TARGET_AARCH64 uses (MTE & gdbstub)

We'd like to reduce the use on TARGET_$arch definitions. This series convert few to runtime checks, mostly in MTE and gdbstub.

Philippe Mathieu-Daudé (9):
target/arm: Remove uses of TARGET_AARCH64 in arch_dump.c target/arm: Remove use of TARGET_AARCH64 in dump.c target/arm: Remove use of TARGET_AARCH64 in arm_cpu_initfn() target/arm/mte: Include missing headers for GETPC() target/arm/mte: Reduce address_with_allocation_tag() scope target/arm/mte: Rename 'mte_helper.h' as generic 'mte.h' target/arm/mte: Restrict MTE declarations linux-user/arm: Implement MTE stubs for 32-bit user emulation target/arm: Build Aarch64 gdbstub helpers indistinctly

 linux-user/aarch64/mte_user_helper.h |  27 +---
 linux-user/arm/mte_user_helper.h     |  34 +++++
 target/arm/internals.h               | 128 +-----------------
 target/arm/tcg/mte.h                 | 190 +++++++++++++++++++++++++++
 target/arm/tcg/mte_helper.h          |  66 ----------
 target/arm/tcg/sve_ldst_internal.h   |   1 +
 linux-user/arm/mte_user_helper.c     |  13 ++
 target/arm/arch_dump.c               |   6 -
 target/arm/cpu.c                     |  38 +++---
 target/arm/gdbstub.c                 |   4 -
 target/arm/gdbstub64.c               |   2 +-
 target/arm/tcg/helper-a64.c          |   1 +
 target/arm/tcg/mte.c                 | 175 ++++++++++++++++++++++++
 target/arm/tcg/mte_helper.c          | 170 ++----------------------
 target/arm/tcg/sve_helper.c          |   1 +
 target/arm/tcg/translate-a64.c       |   1 +
 target/arm/tcg/translate-sve.c       |   1 +
 linux-user/arm/meson.build           |   2 +
 target/arm/meson.build               |   2 +-
 target/arm/tcg/meson.build           |   1 +
 20 files changed, 450 insertions(+), 413 deletions(-)
 create mode 100644 linux-user/arm/mte_user_helper.h
 create mode 100644 target/arm/tcg/mte.h
 delete mode 100644 target/arm/tcg/mte_helper.h
 create mode 100644 linux-user/arm/mte_user_helper.c
 create mode 100644 target/arm/tcg/mte.c
Signature · 1 line
2.47.1
#1 lore raw

PATCH 1/9 target/arm: Remove uses of TARGET_AARCH64 in arch_dump.c

It is safe to remove TARGET_AARCH64 #ifdef'ry for code guarded by runtime check on aa64_sve ISA feature, which is only available for Aarch64 CPUs.

---
 target/arm/arch_dump.c | 6 ------
 1 file changed, 6 deletions(-)
target/arm/arch_dump.c +0 -6
index c40df4e7fd7..1dd79849c13 100644
@@ -143,7 +143,6 @@ static int aarch64_write_elf64_prfpreg(WriteCoreDumpFunction f,
     return 0;
 }
 
-#ifdef TARGET_AARCH64
 static off_t sve_zreg_offset(uint32_t vq, int n)
 {
     off_t off = sizeof(struct aarch64_user_sve_header);
@@ -231,7 +230,6 @@ static int aarch64_write_elf64_sve(WriteCoreDumpFunction f,
 
     return 0;
 }
-#endif
 
 int arm_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs,
                              int cpuid, DumpState *s)
@@ -273,11 +271,9 @@ int arm_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs,
         return ret;
     }
 
-#ifdef TARGET_AARCH64
     if (cpu_isar_feature(aa64_sve, cpu)) {
         ret = aarch64_write_elf64_sve(f, env, cpuid, s);
     }
-#endif
 
     return ret;
 }
@@ -451,11 +447,9 @@ ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
     if (class == ELFCLASS64) {
         note_size = AARCH64_PRSTATUS_NOTE_SIZE;
         note_size += AARCH64_PRFPREG_NOTE_SIZE;
-#ifdef TARGET_AARCH64
         if (cpu_isar_feature(aa64_sve, cpu)) {
             note_size += AARCH64_SVE_NOTE_SIZE(&cpu->env);
         }
-#endif
     } else {
         note_size = ARM_PRSTATUS_NOTE_SIZE;
         if (cpu_isar_feature(aa32_vfp_simd, cpu)) {
Signature · 1 line
2.47.1
Reviewed-by on v1 1/9
#2 lore raw

Re: [PATCH-for-10.1 1/9] target/arm: Remove uses of TARGET_AARCH64 in arch_dump.c

Quoted 8 lines · Philippe Mathieu-Daudé

It is safe to remove TARGET_AARCH64 #ifdef'ry for code guarded by runtime check on aa64_sve ISA feature, which is only available for Aarch64 CPUs.

---
  target/arm/arch_dump.c | 6 ------
  1 file changed, 6 deletions(-)

r~

#3 lore raw

PATCH 2/9 target/arm: Remove use of TARGET_AARCH64 in dump.c

In reply to Philippe Mathieu-Daudé

It is safe to remove TARGET_AARCH64 #ifdef'ry for code guarded by runtime check on aa64_sve ISA feature, which is only available for Aarch64 CPUs.

---
 target/arm/cpu.c | 11 -----------
 1 file changed, 11 deletions(-)
target/arm/cpu.c +0 -11
index 377791c84dd..95afa9b72f1 100644
@@ -1213,8 +1213,6 @@ static void arm_disas_set_info(CPUState *cpu, disassemble_info *info)
 #endif
 }
 
-#ifdef TARGET_AARCH64
-
 static void aarch64_cpu_dump_state(CPUState *cs, FILE *f, int flags)
 {
     ARMCPU *cpu = ARM_CPU(cs);
@@ -1372,15 +1370,6 @@ static void aarch64_cpu_dump_state(CPUState *cs, FILE *f, int flags)
     }
 }
 
-#else
-
-static inline void aarch64_cpu_dump_state(CPUState *cs, FILE *f, int flags)
-{
-    g_assert_not_reached();
-}
-
-#endif
-
 static void arm_cpu_dump_state(CPUState *cs, FILE *f, int flags)
 {
     ARMCPU *cpu = ARM_CPU(cs);
Signature · 1 line
2.47.1
Reviewed-by on v1 2/9
#4 lore raw

Re: [PATCH-for-10.1 2/9] target/arm: Remove use of TARGET_AARCH64 in dump.c

Quoted 8 lines · Philippe Mathieu-Daudé

It is safe to remove TARGET_AARCH64 #ifdef'ry for code guarded by runtime check on aa64_sve ISA feature, which is only available for Aarch64 CPUs.

---
  target/arm/cpu.c | 11 -----------
  1 file changed, 11 deletions(-)

r~

#5 lore raw

PATCH 3/9 target/arm: Remove use of TARGET_AARCH64 in arm_cpu_initfn()

In reply to Philippe Mathieu-Daudé

Introduce the QOM arm_cpu_is_64bit() helper, which checks whether a vCPU parent class is TYPE_AARCH64_CPU. Use it in arm_cpu_initfn() to remove a TARGET_AARCH64 definition use.

---
 target/arm/cpu.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)
target/arm/cpu.c +17 -10
index 95afa9b72f1..ef95f31f249 100644
@@ -1471,6 +1471,13 @@ uint64_t arm_cpu_mp_affinity(ARMCPU *cpu)
     return cpu->mp_affinity;
 }
 
+#ifdef CONFIG_USER_ONLY
+static bool arm_cpu_is_64bit(ARMCPU *cpu)
+{
+    return !!object_dynamic_cast(OBJECT(cpu), TYPE_AARCH64_CPU);
+}
+#endif
+
 static void arm_cpu_initfn(Object *obj)
 {
     ARMCPU *cpu = ARM_CPU(obj);
@@ -1482,16 +1489,16 @@ static void arm_cpu_initfn(Object *obj)
     QLIST_INIT(&cpu->el_change_hooks);
 
 #ifdef CONFIG_USER_ONLY
-# ifdef TARGET_AARCH64
-    /*
-     * The linux kernel defaults to 512-bit for SVE, and 256-bit for SME.
-     * These values were chosen to fit within the default signal frame.
-     * See documentation for /proc/sys/abi/{sve,sme}_default_vector_length,
-     * and our corresponding cpu property.
-     */
-    cpu->sve_default_vq = 4;
-    cpu->sme_default_vq = 2;
-# endif
+    if (arm_cpu_is_64bit(cpu)) {
+        /*
+         * The linux kernel defaults to 512-bit for SVE, and 256-bit for SME.
+         * These values were chosen to fit within the default signal frame.
+         * See documentation for /proc/sys/abi/{sve,sme}_default_vector_length,
+         * and our corresponding cpu property.
+         */
+        cpu->sve_default_vq = 4;
+        cpu->sme_default_vq = 2;
+    }
 #else
     /* Our inbound IRQ and FIQ lines */
     if (kvm_enabled()) {
Signature · 1 line
2.47.1
#6 lore raw

Re: [PATCH-for-10.1 3/9] target/arm: Remove use of TARGET_AARCH64 in arm_cpu_initfn()

Quoted 8 lines · Philippe Mathieu-Daudé
  static void arm_cpu_initfn(Object *obj)
  {
      ARMCPU *cpu = ARM_CPU(obj);
target/arm/cpu.c +0 -1
@@ -1482,16 +1489,16 @@ static void arm_cpu_initfn(Object *obj)
      QLIST_INIT(&cpu->el_change_hooks);
 
  #ifdef CONFIG_USER_ONLY
-# ifdef TARGET_AARCH64

target/arm/cpu.c static void arm_cpu_initfn(Object *obj) · line 1492

Quoted 10 lines
target/arm/cpu.c +1 -9
-    /*
-     * The linux kernel defaults to 512-bit for SVE, and 256-bit for SME.
-     * These values were chosen to fit within the default signal frame.
-     * See documentation for /proc/sys/abi/{sve,sme}_default_vector_length,
-     * and our corresponding cpu property.
-     */
-    cpu->sve_default_vq = 4;
-    cpu->sme_default_vq = 2;
-# endif
+    if (arm_cpu_is_64bit(cpu)) {
    arm_feature(&cpu->env, ARM_FEATURE_AARCH64)

is a better test, but env->features is initialized by the child instance_init. We could move this to arm_cpu_post_init, so that features is initialized.

Alternately, we could just make this unconditional, since these fields are always present but only read from aarch64 code.

r~

#7 lore raw

PATCH 4/9 target/arm/mte: Include missing headers for GETPC()

In reply to Philippe Mathieu-Daudé

Some headers are indirectly pulled in. Make their inclusion explicit, otherwise next commit triggers:

target/arm/tcg/mte_helper.c:188:26: error: call to undeclared function 'GETPC' [-Wimplicit-function-declaration]

    188 |     do_stg(env, ptr, xt, GETPC(), store_tag1);
        |                          ^
---
 target/arm/tcg/mte_helper.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/arm/tcg/mte_helper.c +2 -1
index 7dc5fb776b3..9dcdc1d91c1 100644
@@ -22,7 +22,7 @@
 #include "cpu.h"
 #include "internals.h"
 #include "exec/exec-all.h"
-#include "exec/page-protection.h"
+#include "exec/target_page.h"
 #ifdef CONFIG_USER_ONLY
 #include "user/cpu_loop.h"
 #include "user/page-protection.h"
@@ -33,6 +33,7 @@
 #include "exec/helper-proto.h"
 #include "exec/tlb-flags.h"
 #include "accel/tcg/cpu-ops.h"
+#include "accel/tcg/getpc.h"
 #include "qapi/error.h"
 #include "qemu/guest-random.h"
 #include "mte_helper.h"
Signature · 1 line
2.47.1
Reviewed-by on v1 4/9
#8 lore raw

Re: [PATCH-for-10.1 4/9] target/arm/mte: Include missing headers for GETPC()

Quoted 26 lines · Philippe Mathieu-Daudé

Some headers are indirectly pulled in. Make their inclusion explicit, otherwise next commit triggers:

target/arm/tcg/mte_helper.c:188:26: error: call to undeclared function 'GETPC' [-Wimplicit-function-declaration]

     188 |     do_stg(env, ptr, xt, GETPC(), store_tag1);
         |                          ^
---
  target/arm/tcg/mte_helper.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
target/arm/tcg/mte_helper.c +1 -1
index 7dc5fb776b3..9dcdc1d91c1 100644
@@ -22,7 +22,7 @@
  #include "cpu.h"
  #include "internals.h"
  #include "exec/exec-all.h"
-#include "exec/page-protection.h"
+#include "exec/target_page.h"
  #ifdef CONFIG_USER_ONLY
  #include "user/cpu_loop.h"
  #include "user/page-protection.h"

target/arm/tcg/mte_helper.c line 39

Quoted 7 lines
target/arm/tcg/mte_helper.c +1 -0
@@ -33,6 +33,7 @@
  #include "exec/helper-proto.h"
  #include "exec/tlb-flags.h"
  #include "accel/tcg/cpu-ops.h"
+#include "accel/tcg/getpc.h"
  #include "qapi/error.h"
  #include "qemu/guest-random.h"
  #include "mte_helper.h"

r~

#9 lore raw

PATCH 5/9 target/arm/mte: Reduce address_with_allocation_tag() scope

In reply to Philippe Mathieu-Daudé

address_with_allocation_tag() is only used in mte_helper.c, move it there.

---
 target/arm/internals.h      | 5 -----
 target/arm/tcg/mte_helper.c | 5 +++++
 2 files changed, 5 insertions(+), 5 deletions(-)
target/arm/internals.h +0 -5
index 01408e40a34..0728e5c5348 100644
@@ -1701,11 +1701,6 @@ static inline int allocation_tag_from_addr(uint64_t ptr)
     return extract64(ptr, 56, 4);
 }
 
-static inline uint64_t address_with_allocation_tag(uint64_t ptr, int rtag)
-{
-    return deposit64(ptr, 56, 4, rtag);
-}
-
 /* Return true if tbi bits mean that the access is checked.  */
 static inline bool tbi_check(uint32_t desc, int bit55)
 {
target/arm/tcg/mte_helper.c +5 -0
index 9dcdc1d91c1..8a6e6e4719d 100644
@@ -205,6 +205,11 @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx,
                                     ptr_size, tag_access, false, ra);
 }
 
+static inline uint64_t address_with_allocation_tag(uint64_t ptr, int rtag)
+{
+    return deposit64(ptr, 56, 4, rtag);
+}
+
 uint64_t HELPER(irg)(CPUARMState *env, uint64_t rn, uint64_t rm)
 {
     uint16_t exclude = extract32(rm | env->cp15.gcr_el1, 0, 16);
Signature · 1 line
2.47.1
Reviewed-by on v1 5/9
#10 lore raw

Re: [PATCH-for-10.1 5/9] target/arm/mte: Reduce address_with_allocation_tag() scope

Quoted 8 lines · Philippe Mathieu-Daudé

address_with_allocation_tag() is only used in mte_helper.c, move it there.

---
  target/arm/internals.h      | 5 -----
  target/arm/tcg/mte_helper.c | 5 +++++
  2 files changed, 5 insertions(+), 5 deletions(-)
#11 lore raw

PATCH 6/9 target/arm/mte: Rename 'mte_helper.h' as generic 'mte.h'

In reply to Philippe Mathieu-Daudé

"tcg/mte_helper.h" header name is a bit misleading, since it isn't restricted to TCG helpers. Rename it as "tcg/mte.h" which is a bit more generic.

---
 target/arm/tcg/{mte_helper.h => mte.h} | 0
 target/arm/gdbstub64.c                 | 2 +-
 target/arm/tcg/mte_helper.c            | 2 +-
 3 files changed, 2 insertions(+), 2 deletions(-)
 rename target/arm/tcg/{mte_helper.h => mte.h} (100%)
target/arm/tcg/mte.h renamed from target/arm/tcg/mte_helper.h +0 -0
similarity index 100%
rename from target/arm/tcg/mte_helper.h
rename to target/arm/tcg/mte.h
target/arm/gdbstub64.c +1 -1
index 64ee9b3b567..65540cffd2c 100644
@@ -22,7 +22,6 @@
 #include "internals.h"
 #include "gdbstub/helpers.h"
 #include "gdbstub/commands.h"
-#include "tcg/mte_helper.h"
 #if defined(CONFIG_USER_ONLY) && defined(CONFIG_LINUX)
 #include <sys/prctl.h>
 #include "mte_user_helper.h"
@@ -30,6 +29,7 @@
 #ifdef CONFIG_TCG
 #include "accel/tcg/cpu-mmu-index.h"
 #include "exec/target_page.h"
+#include "tcg/mte.h"
 #endif
 
 int aarch64_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
target/arm/tcg/mte_helper.c +1 -1
index 8a6e6e4719d..b70f23e2047 100644
@@ -36,7 +36,7 @@
 #include "accel/tcg/getpc.h"
 #include "qapi/error.h"
 #include "qemu/guest-random.h"
-#include "mte_helper.h"
+#include "mte.h"
 
 
 static int choose_nonexcluded_tag(int tag, int offset, uint16_t exclude)
Signature · 1 line
2.47.1
Reviewed-by on v1 6/9
#12 lore raw

Re: [PATCH-for-10.1 6/9] target/arm/mte: Rename 'mte_helper.h' as generic 'mte.h'

Quoted 11 lines · Philippe Mathieu-Daudé

"tcg/mte_helper.h" header name is a bit misleading, since it isn't restricted to TCG helpers. Rename it as "tcg/mte.h" which is a bit more generic.

---
  target/arm/tcg/{mte_helper.h => mte.h} | 0
  target/arm/gdbstub64.c                 | 2 +-
  target/arm/tcg/mte_helper.c            | 2 +-
  3 files changed, 2 insertions(+), 2 deletions(-)

rename target/arm/tcg/{mte_helper.h => mte.h} (100%)

r~

#13 lore raw

PATCH 7/9 target/arm/mte: Restrict MTE declarations

In reply to Philippe Mathieu-Daudé

Move MTE declarations out of "internals.h" to TCG "mte.h". Include "mte.h" when necessary.

---
 target/arm/internals.h             | 121 --------------------
 target/arm/tcg/mte.h               | 124 ++++++++++++++++++++
 target/arm/tcg/sve_ldst_internal.h |   1 +
 target/arm/tcg/helper-a64.c        |   1 +
 target/arm/tcg/mte.c               | 175 +++++++++++++++++++++++++++++
 target/arm/tcg/mte_helper.c        | 160 +-------------------------
 target/arm/tcg/sve_helper.c        |   1 +
 target/arm/tcg/translate-a64.c     |   1 +
 target/arm/tcg/translate-sve.c     |   1 +
 target/arm/tcg/meson.build         |   1 +
 10 files changed, 306 insertions(+), 280 deletions(-)
 create mode 100644 target/arm/tcg/mte.c
target/arm/internals.h +0 -121
index 0728e5c5348..5e549b95e14 100644
@@ -1624,127 +1624,6 @@ FIELD(PREDDESC, OPRSZ, 0, 6)
 FIELD(PREDDESC, ESZ, 6, 2)
 FIELD(PREDDESC, DATA, 8, 24)
 
-/*
- * The SVE simd_data field, for memory ops, contains either
- * rd (5 bits) or a shift count (2 bits).
- */
-#define SVE_MTEDESC_SHIFT 5
-
-/* Bits within a descriptor passed to the helper_mte_check* functions. */
-FIELD(MTEDESC, MIDX,  0, 4)
-FIELD(MTEDESC, TBI,   4, 2)
-FIELD(MTEDESC, TCMA,  6, 2)
-FIELD(MTEDESC, WRITE, 8, 1)
-FIELD(MTEDESC, ALIGN, 9, 3)
-FIELD(MTEDESC, SIZEM1, 12, SIMD_DATA_BITS - SVE_MTEDESC_SHIFT - 12)  /* size - 1 */
-
-bool mte_probe(CPUARMState *env, uint32_t desc, uint64_t ptr);
-uint64_t mte_check(CPUARMState *env, uint32_t desc, uint64_t ptr, uintptr_t ra);
-
-/**
- * mte_mops_probe: Check where the next MTE failure is for a FEAT_MOPS operation
- * @env: CPU env
- * @ptr: start address of memory region (dirty pointer)
- * @size: length of region (guaranteed not to cross a page boundary)
- * @desc: MTEDESC descriptor word (0 means no MTE checks)
- * Returns: the size of the region that can be copied without hitting
- *          an MTE tag failure
- *
- * Note that we assume that the caller has already checked the TBI
- * and TCMA bits with mte_checks_needed() and an MTE check is definitely
- * required.
- */
-uint64_t mte_mops_probe(CPUARMState *env, uint64_t ptr, uint64_t size,
-                        uint32_t desc);
-
-/**
- * mte_mops_probe_rev: Check where the next MTE failure is for a FEAT_MOPS
- *                     operation going in the reverse direction
- * @env: CPU env
- * @ptr: *end* address of memory region (dirty pointer)
- * @size: length of region (guaranteed not to cross a page boundary)
- * @desc: MTEDESC descriptor word (0 means no MTE checks)
- * Returns: the size of the region that can be copied without hitting
- *          an MTE tag failure
- *
- * Note that we assume that the caller has already checked the TBI
- * and TCMA bits with mte_checks_needed() and an MTE check is definitely
- * required.
- */
-uint64_t mte_mops_probe_rev(CPUARMState *env, uint64_t ptr, uint64_t size,
-                            uint32_t desc);
-
-/**
- * mte_check_fail: Record an MTE tag check failure
- * @env: CPU env
- * @desc: MTEDESC descriptor word
- * @dirty_ptr: Failing dirty address
- * @ra: TCG retaddr
- *
- * This may never return (if the MTE tag checks are configured to fault).
- */
-void mte_check_fail(CPUARMState *env, uint32_t desc,
-                    uint64_t dirty_ptr, uintptr_t ra);
-
-/**
- * mte_mops_set_tags: Set MTE tags for a portion of a FEAT_MOPS operation
- * @env: CPU env
- * @dirty_ptr: Start address of memory region (dirty pointer)
- * @size: length of region (guaranteed not to cross page boundary)
- * @desc: MTEDESC descriptor word
- */
-void mte_mops_set_tags(CPUARMState *env, uint64_t dirty_ptr, uint64_t size,
-                       uint32_t desc);
-
-static inline int allocation_tag_from_addr(uint64_t ptr)
-{
-    return extract64(ptr, 56, 4);
-}
-
-/* Return true if tbi bits mean that the access is checked.  */
-static inline bool tbi_check(uint32_t desc, int bit55)
-{
-    return (desc >> (R_MTEDESC_TBI_SHIFT + bit55)) & 1;
-}
-
-/* Return true if tcma bits mean that the access is unchecked.  */
-static inline bool tcma_check(uint32_t desc, int bit55, int ptr_tag)
-{
-    /*
-     * We had extracted bit55 and ptr_tag for other reasons, so fold
-     * (ptr<59:55> == 00000 || ptr<59:55> == 11111) into a single test.
-     */
-    bool match = ((ptr_tag + bit55) & 0xf) == 0;
-    bool tcma = (desc >> (R_MTEDESC_TCMA_SHIFT + bit55)) & 1;
-    return tcma && match;
-}
-
-/*
- * For TBI, ideally, we would do nothing.  Proper behaviour on fault is
- * for the tag to be present in the FAR_ELx register.  But for user-only
- * mode, we do not have a TLB with which to implement this, so we must
- * remove the top byte.
- */
-static inline uint64_t useronly_clean_ptr(uint64_t ptr)
-{
-#ifdef CONFIG_USER_ONLY
-    /* TBI0 is known to be enabled, while TBI1 is disabled. */
-    ptr &= sextract64(ptr, 0, 56);
-#endif
-    return ptr;
-}
-
-static inline uint64_t useronly_maybe_clean_ptr(uint32_t desc, uint64_t ptr)
-{
-#ifdef CONFIG_USER_ONLY
-    int64_t clean_ptr = sextract64(ptr, 0, 56);
-    if (tbi_check(desc, clean_ptr < 0)) {
-        ptr = clean_ptr;
-    }
-#endif
-    return ptr;
-}
-
 /* Values for M-profile PSR.ECI for MVE insns */
 enum MVEECIState {
     ECI_NONE = 0, /* No completed beats */
target/arm/tcg/mte.h +124 -0

135 lines not on this page · raw message

target/arm/tcg/sve_ldst_internal.h +1 -0
index f2243daf370..a201f6b0393 100644
@@ -21,6 +21,7 @@
 #define TARGET_ARM_SVE_LDST_INTERNAL_H
 
 #include "accel/tcg/cpu-ldst.h"
+#include "mte.h"
 
 /*
  * Load one element into @vd + @reg_off from @host.
target/arm/tcg/helper-a64.c +1 -0
index 08d8f63ffea..bcd116e2a16 100644
@@ -41,6 +41,7 @@
 #include "user/page-protection.h"
 #endif
 #include "vec_internal.h"
+#include "mte.h"
 
 /* C2.4.7 Multiply and divide */
 /* special cases for 0 and LLONG_MIN are mandated by the standard */
target/arm/tcg/mte.c new file +175 -0

175 lines not on this page · raw message

target/arm/tcg/mte_helper.c +1 -159

191 lines not on this page · raw message

target/arm/tcg/sve_helper.c +1 -0
index 87b6b4b3e64..19b09d9f33f 100644
@@ -35,6 +35,7 @@
 #ifdef CONFIG_USER_ONLY
 #include "user/page-protection.h"
 #endif
+#include "mte.h"
 
 
 /* Return a value for NZCV as per the ARM PredTest pseudofunction.
target/arm/tcg/translate-a64.c +1 -0
index 43408c71bbd..c320501c507 100644
@@ -25,6 +25,7 @@
 #include "arm_ldst.h"
 #include "semihosting/semihost.h"
 #include "cpregs.h"
+#include "mte.h"
 
 static TCGv_i64 cpu_X[32];
 static TCGv_i64 cpu_pc;
target/arm/tcg/translate-sve.c +1 -0
index d23be477b4d..7f91874abd2 100644
@@ -21,6 +21,7 @@
 #include "translate.h"
 #include "translate-a64.h"
 #include "fpu/softfloat.h"
+#include "mte.h"
 
 
 typedef void GVecGen2sFn(unsigned, uint32_t, uint32_t,
target/arm/tcg/meson.build +1 -0
index dd12ccedb18..72750d57a7d 100644
@@ -34,6 +34,7 @@ arm_ss.add(files(
   'hflags.c',
   'iwmmxt_helper.c',
   'm_helper.c',
+  'mte.c',
   'mve_helper.c',
   'neon_helper.c',
   'op_helper.c',
Signature · 1 line
2.47.1
#14 lore raw

Re: [PATCH-for-10.1 7/9] target/arm/mte: Restrict MTE declarations

Quoted 11 lines · Philippe Mathieu-Daudé

Move MTE declarations out of "internals.h" to TCG "mte.h". Include "mte.h" when necessary.

---
  target/arm/internals.h             | 121 --------------------
  target/arm/tcg/mte.h               | 124 ++++++++++++++++++++
  target/arm/tcg/sve_ldst_internal.h |   1 +
  target/arm/tcg/helper-a64.c        |   1 +
  target/arm/tcg/mte.c               | 175 +++++++++++++++++++++++++++++
  target/arm/tcg/mte_helper.c        | 160 +-------------------------

This moves more than declarations...

r~

#15 lore raw

PATCH 8/9 linux-user/arm: Implement MTE stubs for 32-bit user emulation

In reply to Philippe Mathieu-Daudé

We want to build MTE code once, but on linux-user it calls arm_set_mte_tcf0() which is only defined for Aarch64. Expose the declaration on 32-bit ARM by renaming aarch64/mte_user_helper.h -> arm/mte_user_helper.h, then add a stub in arm/mte_user_helper.c.

---
 linux-user/aarch64/mte_user_helper.h | 27 +---------------------
 linux-user/arm/mte_user_helper.h     | 34 ++++++++++++++++++++++++++++
 linux-user/arm/mte_user_helper.c     | 13 +++++++++++
 linux-user/arm/meson.build           |  2 ++
 4 files changed, 50 insertions(+), 26 deletions(-)
 create mode 100644 linux-user/arm/mte_user_helper.h
 create mode 100644 linux-user/arm/mte_user_helper.c
linux-user/aarch64/mte_user_helper.h +1 -26
index 0c53abda222..63f63abff62 100644
@@ -6,29 +6,4 @@
  * SPDX-License-Identifier: LGPL-2.1-or-later
  */
 
-#ifndef AARCH64_MTE_USER_HELPER_H
-#define AARCH64_MTE USER_HELPER_H
-
-#include "user/abitypes.h"
-
-#ifndef PR_MTE_TCF_SHIFT
-# define PR_MTE_TCF_SHIFT       1
-# define PR_MTE_TCF_NONE        (0UL << PR_MTE_TCF_SHIFT)
-# define PR_MTE_TCF_SYNC        (1UL << PR_MTE_TCF_SHIFT)
-# define PR_MTE_TCF_ASYNC       (2UL << PR_MTE_TCF_SHIFT)
-# define PR_MTE_TCF_MASK        (3UL << PR_MTE_TCF_SHIFT)
-# define PR_MTE_TAG_SHIFT       3
-# define PR_MTE_TAG_MASK        (0xffffUL << PR_MTE_TAG_SHIFT)
-#endif
-
-/**
- * arm_set_mte_tcf0 - Set TCF0 field in SCTLR_EL1 register
- * @env: The CPU environment
- * @value: The value to be set for the Tag Check Fault in EL0 field.
- *
- * Only SYNC and ASYNC modes can be selected. If ASYMM mode is given, the SYNC
- * mode is selected instead. So, there is no way to set the ASYMM mode.
- */
-void arm_set_mte_tcf0(CPUArchState *env, abi_long value);
-
-#endif /* AARCH64_MTE_USER_HELPER_H */
+#include "../arm/mte_user_helper.h"
linux-user/arm/mte_user_helper.h new file +34 -0
new file mode 100644
index 00000000000..0c53abda222
@@ -0,0 +1,34 @@
+/*
+ * ARM MemTag convenience functions.
+ *
+ * This code is licensed under the GNU GPL v2 or later.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#ifndef AARCH64_MTE_USER_HELPER_H
+#define AARCH64_MTE USER_HELPER_H
+
+#include "user/abitypes.h"
+
+#ifndef PR_MTE_TCF_SHIFT
+# define PR_MTE_TCF_SHIFT       1
+# define PR_MTE_TCF_NONE        (0UL << PR_MTE_TCF_SHIFT)
+# define PR_MTE_TCF_SYNC        (1UL << PR_MTE_TCF_SHIFT)
+# define PR_MTE_TCF_ASYNC       (2UL << PR_MTE_TCF_SHIFT)
+# define PR_MTE_TCF_MASK        (3UL << PR_MTE_TCF_SHIFT)
+# define PR_MTE_TAG_SHIFT       3
+# define PR_MTE_TAG_MASK        (0xffffUL << PR_MTE_TAG_SHIFT)
+#endif
+
+/**
+ * arm_set_mte_tcf0 - Set TCF0 field in SCTLR_EL1 register
+ * @env: The CPU environment
+ * @value: The value to be set for the Tag Check Fault in EL0 field.
+ *
+ * Only SYNC and ASYNC modes can be selected. If ASYMM mode is given, the SYNC
+ * mode is selected instead. So, there is no way to set the ASYMM mode.
+ */
+void arm_set_mte_tcf0(CPUArchState *env, abi_long value);
+
+#endif /* AARCH64_MTE_USER_HELPER_H */
linux-user/arm/mte_user_helper.c new file +13 -0
new file mode 100644
index 00000000000..6fd19dc1073
@@ -0,0 +1,13 @@
+/*
+ * ARM ARM MemTag user emulation stubs.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "mte_user_helper.h"
+
+void arm_set_mte_tcf0(CPUArchState *env, abi_long value)
+{
+    g_assert_not_reached();
+}
linux-user/arm/meson.build +2 -0
index 348ffb810d7..95e8c078e29 100644
@@ -24,3 +24,5 @@ vdso_le_inc = gen_vdso.process('vdso-le.so',
 linux_user_ss.add(when: 'TARGET_ARM', if_true: [
     vdso_be8_inc, vdso_be32_inc, vdso_le_inc
 ])
+
+linux_user_ss.add(when: 'TARGET_ARM', if_true: [files('mte_user_helper.c')])
Signature · 1 line
2.47.1
#16 lore raw

PATCH 9/9 target/arm: Build Aarch64 gdbstub helpers indistinctly

In reply to Philippe Mathieu-Daudé

The Aarch64 gdbstub code is guarded by checks on ARM_FEATURE_AARCH64 and isar_feature_aa64_sve(), only enabled for Aarch64 CPUs. Remove TARGET_AARCH64 #ifdef'ry and build gdbstub64.c once.

---
 target/arm/internals.h | 2 +-
 target/arm/gdbstub.c   | 4 ----
 target/arm/meson.build | 2 +-
 3 files changed, 2 insertions(+), 6 deletions(-)
target/arm/internals.h +1 -1
index 5e549b95e14..5fd2631e8e2 100644
@@ -1682,7 +1682,6 @@ static inline uint64_t pmu_counter_mask(CPUARMState *env)
   return (1ULL << 31) | ((1ULL << pmu_num_counters(env)) - 1);
 }
 
-#ifdef TARGET_AARCH64
 GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *cpu, int base_reg);
 int aarch64_gdb_get_sve_reg(CPUState *cs, GByteArray *buf, int reg);
 int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg);
@@ -1692,6 +1691,7 @@ int aarch64_gdb_get_pauth_reg(CPUState *cs, GByteArray *buf, int reg);
 int aarch64_gdb_set_pauth_reg(CPUState *cs, uint8_t *buf, int reg);
 int aarch64_gdb_get_tag_ctl_reg(CPUState *cs, GByteArray *buf, int reg);
 int aarch64_gdb_set_tag_ctl_reg(CPUState *cs, uint8_t *buf, int reg);
+#ifdef TARGET_AARCH64
 void arm_cpu_sve_finalize(ARMCPU *cpu, Error **errp);
 void arm_cpu_sme_finalize(ARMCPU *cpu, Error **errp);
 void arm_cpu_pauth_finalize(ARMCPU *cpu, Error **errp);
target/arm/gdbstub.c +0 -4
index 30068c22627..e76142e8ddb 100644
@@ -482,10 +482,8 @@ void arm_cpu_register_gdb_commands(ARMCPU *cpu)
     g_autoptr(GString) qsupported_features = g_string_new(NULL);
 
     if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
-    #ifdef TARGET_AARCH64
         aarch64_cpu_register_gdb_commands(cpu, qsupported_features, query_table,
                                           set_table);
-    #endif
     }
 
     /* Set arch-specific handlers for 'q' commands. */
@@ -514,7 +512,6 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)
          * The lower part of each SVE register aliases to the FPU
          * registers so we don't need to include both.
          */
-#ifdef TARGET_AARCH64
         if (isar_feature_aa64_sve(&cpu->isar)) {
             GDBFeature *feature = arm_gen_dynamic_svereg_feature(cs, cs->gdb_num_regs);
             gdb_register_coprocessor(cs, aarch64_gdb_get_sve_reg,
@@ -546,7 +543,6 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)
                                      gdb_find_static_feature("aarch64-mte.xml"),
                                      0);
         }
-#endif
 #endif
     } else {
         if (arm_feature(env, ARM_FEATURE_NEON)) {
target/arm/meson.build +1 -1
index 3065081d241..503d106b588 100644
@@ -3,6 +3,7 @@ arm_ss.add(files(
   'cpu.c',
   'debug_helper.c',
   'gdbstub.c',
+  'gdbstub64.c',
   'helper.c',
   'vfp_fpscr.c',
 ))
@@ -13,7 +14,6 @@ arm_ss.add(when: 'CONFIG_HVF', if_true: files('hyp_gdbstub.c'))
 
 arm_ss.add(when: 'TARGET_AARCH64', if_true: files(
   'cpu64.c',
-  'gdbstub64.c',
 ))
 
 arm_system_ss = ss.source_set()
Signature · 1 line
2.47.1
#17 lore raw

Re: [PATCH-for-10.1 9/9] target/arm: Build Aarch64 gdbstub helpers indistinctly

Quoted 13 lines · Philippe Mathieu-Daudé
target/arm/meson.build +1 -0
index 3065081d241..503d106b588 100644
@@ -3,6 +3,7 @@ arm_ss.add(files(
    'cpu.c',
    'debug_helper.c',
    'gdbstub.c',
+  'gdbstub64.c',
    'helper.c',
    'vfp_fpscr.c',
  ))

target/arm/meson.build arm_ss.add(when: 'CONFIG_HVF', if_true: files('hyp_gdbstub.c')) · line 17

Quoted 5 lines
target/arm/meson.build +0 -1
@@ -13,7 +14,6 @@ arm_ss.add(when: 'CONFIG_HVF', if_true: files('hyp_gdbstub.c'))
 
  arm_ss.add(when: 'TARGET_AARCH64', if_true: files(
    'cpu64.c',
-  'gdbstub64.c',
  ))

This doesn't do what you say is does. The object file is still in arm_ss, though unconditionally instead of conditionally. Which causes all of the other follow-on problems you saw.

I'm not fond of either this or the previous patch. I'm surprised that you're touching anything wrt CONFIG_USER_ONLY.

r~