mbox series

[v6,00/11] Add MTE stubs for aarch64 user mode

Message ID 20240628050850.536447-1-gustavo.romero@linaro.org (mailing list archive)
Headers show
Series Add MTE stubs for aarch64 user mode | expand

Message

Gustavo Romero June 28, 2024, 5:08 a.m. UTC
This patchset adds the stubs necessary to support GDB memory tagging
commands on QEMU aarch64 user mode.

These new stubs handle the qIsAddressTagged, qMemTag, and QMemTag
packets, which allow GDB memory tagging subcommands 'check',
'print-allocation-tag', and 'set-allocation-tag' to work. The remaining
memory tagging commands ('print-logical-tag' and 'with-logical-tag')
will also work, but they don't rely on any stub because they perform
local operations.

Since the memory tagging stubs are not common to all architectures, this
patchset also introduces three functions: gdb_extend_qsupported_features,
gdb_extend_query_table, and gdb_extend_set_table. These functions can be
used to extend the target-specific 'qSupported' feature string and the
handlers for the 'q' (query) and 'Q' (set) packets. These new functions
are used to add the MTE stubs for the aarch64 gdbstub.
 
Note that this patchset requires a GDB that supports the
qIsAddressTagged packet (recently added to GDB), so the gdbstub MTE
tests introduced by it must be run using GDB's master branch, since the
GDB in the distros hasn't picked up the change yet.

Once GDB is built and installed locally, the tests can be exercised,
this way:

$ make run-tcg-tests-aarch64-linux-user -j 32

after running QEMU's configure script with the --gdb=<GDB_BINARY_PATH>
option to specify the proper GDB binary.

v2:
 - Addressed comments from Richard, Phil, and Alex
 - Made the series more granular by splitting it into more patches
 - Moved gdbstub command-specific structs and functions into a new header, gdbstub/commands.h
 - Fixed exception in allocation_tag_mem_probe()
 - Used MTE helpers ({store,load}_tag1 and allocation_tag_mem_probe) in the MTE stubs
 - Factored out MTE code to set TCF0, avoiding duplication (both prctl and gdbstub code use it)
 - Hoisted sscanf() out of loop in handle_Q_memtag stub and use gdb_hextomem instead
 - Rebased this series on Alex's gdb/next branch
 
v3:
 - Moved stubs to gdbstub64.c
 - Fixed build for BSD target
 - Fixed license tags in the new header files
 - Use of only function prototypes in mte_helpers.h
 - Added prefix to arm_set_mte_tcf0 and marked it inline
 - Moved target/arm/mte.h -> target/arm/tcg/mte_user_helper.h
 - Cleaned up leftover in mte-8 test
 
v4:
 - Don't run tests when GDB < 15 (i.e., lacks most recent MTE changes) (Alex's review)
 - Added g_assert()s in new gdb_extend_* API functions to ensure all CPUs have the same features/query/set tables (Alex's review)
 - Move load_tag1 and store_tag1 to mte_helpers.h marking them as "static inline" (Richard's review)
 - Move mte_user_helper.h to linux-user/aarch64/ and include it from gdbstub64.c (Richard's review)

v5:
 - Made load_tag1, store_tag1, and arm_set_mte_tcf0 non-inlined for code modularity (Phil's review)
 - MTE tests: GDB_HAS_MTE is now only set for aarch64 targets (Alex's suggestion)
 
 v6:
 - Remove dead code (Phil's review)
 - Pass CPU context via user_ctx (Phil and Alex's review)
 - Cleanup: in gdbstub.c use 'true' to set startswith instead of 1


Cheers,
Gustavo

Gustavo Romero (11):
  gdbstub: Clean up process_string_cmd
  gdbstub: Move GdbCmdParseEntry into a new header file
  gdbstub: Add support for target-specific stubs
  target/arm: Fix exception case in allocation_tag_mem_probe
  target/arm: Make some MTE helpers widely available
  target/arm: Factor out code for setting MTE TCF0 field
  gdbstub: Make hex conversion function non-internal
  gdbstub: Pass CPU context to command handler
  gdbstub: Use true to set cmd_startswith
  gdbstub: Add support for MTE in user mode
  tests/tcg/aarch64: Add MTE gdbstub tests

 configs/targets/aarch64-linux-user.mak |   2 +-
 configure                              |   4 +
 gdb-xml/aarch64-mte.xml                |  11 +
 gdbstub/gdbstub.c                      | 341 +++++++++++++++----------
 gdbstub/internals.h                    |  23 --
 gdbstub/syscalls.c                     |   7 +-
 gdbstub/system.c                       |   7 +-
 gdbstub/user-target.c                  |  25 +-
 gdbstub/user.c                         |   7 +-
 include/gdbstub/commands.h             | 103 ++++++++
 linux-user/aarch64/meson.build         |   2 +
 linux-user/aarch64/mte_user_helper.c   |  34 +++
 linux-user/aarch64/mte_user_helper.h   |  25 ++
 linux-user/aarch64/target_prctl.h      |  22 +-
 target/arm/cpu.c                       |   1 +
 target/arm/gdbstub.c                   |  46 ++++
 target/arm/gdbstub64.c                 | 223 ++++++++++++++++
 target/arm/internals.h                 |   6 +
 target/arm/tcg/mte_helper.c            |  48 +---
 target/arm/tcg/mte_helper.h            |  66 +++++
 tests/tcg/aarch64/Makefile.target      |  14 +-
 tests/tcg/aarch64/gdbstub/test-mte.py  |  86 +++++++
 tests/tcg/aarch64/mte-8.c              |  98 +++++++
 23 files changed, 956 insertions(+), 245 deletions(-)
 create mode 100644 gdb-xml/aarch64-mte.xml
 create mode 100644 include/gdbstub/commands.h
 create mode 100644 linux-user/aarch64/mte_user_helper.c
 create mode 100644 linux-user/aarch64/mte_user_helper.h
 create mode 100644 target/arm/tcg/mte_helper.h
 create mode 100644 tests/tcg/aarch64/gdbstub/test-mte.py
 create mode 100644 tests/tcg/aarch64/mte-8.c

Comments

Alex Bennée June 28, 2024, 12:34 p.m. UTC | #1
Gustavo Romero <gustavo.romero@linaro.org> writes:

> This patchset adds the stubs necessary to support GDB memory tagging
> commands on QEMU aarch64 user mode.

Queued to gdbstub/next, thanks. I've manually fixed up the include
issues and moved the PR defines to avoid using prctl.