mbox series

[v2,0/9] Add MTE stubs for aarch64 user mode

Message ID 20240613172103.2987519-1-gustavo.romero@linaro.org
Headers show
Series Add MTE stubs for aarch64 user mode | expand

Message

Gustavo Romero June 13, 2024, 5:20 p.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, for
example, this way:

make GDB=~/.local/bin/gdb run-tcg-tests-aarch64-linux-user -j 32

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


Cheers,
Gustavo

Gustavo Romero (9):
  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 get cpu and hex conversion functions non-internal
  gdbstub: Add support for MTE in user mode
  tests/tcg/aarch64: Add MTE gdbstub tests

 configs/targets/aarch64-linux-user.mak |   2 +-
 gdb-xml/aarch64-mte.xml                |  11 ++
 gdbstub/gdbstub.c                      | 211 +++++++++++----------
 gdbstub/internals.h                    |  24 ---
 gdbstub/syscalls.c                     |   7 +-
 gdbstub/system.c                       |   7 +-
 gdbstub/user-target.c                  |  25 +--
 gdbstub/user.c                         |   7 +-
 include/exec/gdbstub.h                 |   5 +
 include/gdbstub/commands.h             | 102 ++++++++++
 linux-user/aarch64/target_prctl.h      |  22 +--
 target/arm/cpu.c                       |   1 +
 target/arm/gdbstub.c                   | 253 +++++++++++++++++++++++++
 target/arm/internals.h                 |   2 +
 target/arm/mte.h                       |  53 ++++++
 target/arm/tcg/mte_helper.c            | 181 +-----------------
 target/arm/tcg/mte_helper.h            | 211 +++++++++++++++++++++
 tests/tcg/aarch64/Makefile.target      |  11 +-
 tests/tcg/aarch64/gdbstub/test-mte.py  |  86 +++++++++
 tests/tcg/aarch64/mte-8.c              | 102 ++++++++++
 20 files changed, 975 insertions(+), 348 deletions(-)
 create mode 100644 gdb-xml/aarch64-mte.xml
 create mode 100644 include/gdbstub/commands.h
 create mode 100644 target/arm/mte.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 14, 2024, 3:49 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.
>
> 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, for
> example, this way:
>
> make GDB=~/.local/bin/gdb run-tcg-tests-aarch64-linux-user -j 32

It looks like there might be some BSD build failures as well:

  https://gitlab.com/stsquad/qemu/-/pipelines/1332635371/failures

>
> 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
>
>
> Cheers,
> Gustavo
>
> Gustavo Romero (9):
>   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 get cpu and hex conversion functions non-internal
>   gdbstub: Add support for MTE in user mode
>   tests/tcg/aarch64: Add MTE gdbstub tests
>
>  configs/targets/aarch64-linux-user.mak |   2 +-
>  gdb-xml/aarch64-mte.xml                |  11 ++
>  gdbstub/gdbstub.c                      | 211 +++++++++++----------
>  gdbstub/internals.h                    |  24 ---
>  gdbstub/syscalls.c                     |   7 +-
>  gdbstub/system.c                       |   7 +-
>  gdbstub/user-target.c                  |  25 +--
>  gdbstub/user.c                         |   7 +-
>  include/exec/gdbstub.h                 |   5 +
>  include/gdbstub/commands.h             | 102 ++++++++++
>  linux-user/aarch64/target_prctl.h      |  22 +--
>  target/arm/cpu.c                       |   1 +
>  target/arm/gdbstub.c                   | 253 +++++++++++++++++++++++++
>  target/arm/internals.h                 |   2 +
>  target/arm/mte.h                       |  53 ++++++
>  target/arm/tcg/mte_helper.c            | 181 +-----------------
>  target/arm/tcg/mte_helper.h            | 211 +++++++++++++++++++++
>  tests/tcg/aarch64/Makefile.target      |  11 +-
>  tests/tcg/aarch64/gdbstub/test-mte.py  |  86 +++++++++
>  tests/tcg/aarch64/mte-8.c              | 102 ++++++++++
>  20 files changed, 975 insertions(+), 348 deletions(-)
>  create mode 100644 gdb-xml/aarch64-mte.xml
>  create mode 100644 include/gdbstub/commands.h
>  create mode 100644 target/arm/mte.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
Gustavo Romero June 14, 2024, 4:01 p.m. UTC | #2
On 6/14/24 12:49 PM, Alex Bennée wrote:
> Gustavo Romero <gustavo.romero@linaro.org> writes:
> 
>> 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, for
>> example, this way:
>>
>> make GDB=~/.local/bin/gdb run-tcg-tests-aarch64-linux-user -j 32
> 
> It looks like there might be some BSD build failures as well:
> 
>    https://gitlab.com/stsquad/qemu/-/pipelines/1332635371/failures

Thanks, I'm looking at them.


Cheers,
Gustavo
Gustavo Romero June 17, 2024, 7:02 a.m. UTC | #3
Hi Alex,

On 6/14/24 12:49 PM, Alex Bennée wrote:
> Gustavo Romero <gustavo.romero@linaro.org> writes:
> 
>> 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, for
>> example, this way:
>>
>> make GDB=~/.local/bin/gdb run-tcg-tests-aarch64-linux-user -j 32
> 
> It looks like there might be some BSD build failures as well:
> 
>    https://gitlab.com/stsquad/qemu/-/pipelines/1332635371/failures

I fixed the build for the BSD target in v3, however I think that the GDB in
the test containers need to be bumped to GDB 15 so the MTE tests can pass,
because support for IsAddressTagged packet is necessary. GDB 15 branch
is created by it's not released yet, so I don't know to proceed..


Cheers,
Gustavo
Alex Bennée June 17, 2024, 9:50 a.m. UTC | #4
Gustavo Romero <gustavo.romero@linaro.org> writes:

> Hi Alex,
>
> On 6/14/24 12:49 PM, Alex Bennée wrote:
>> Gustavo Romero <gustavo.romero@linaro.org> writes:
>> 
>>> 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, for
>>> example, this way:
>>>
>>> make GDB=~/.local/bin/gdb run-tcg-tests-aarch64-linux-user -j 32
>> It looks like there might be some BSD build failures as well:
>>    https://gitlab.com/stsquad/qemu/-/pipelines/1332635371/failures
>
> I fixed the build for the BSD target in v3, however I think that the GDB in
> the test containers need to be bumped to GDB 15 so the MTE tests can pass,
> because support for IsAddressTagged packet is necessary. GDB 15 branch
> is created by it's not released yet, so I don't know to proceed..

Two potential approaches, you could extend the configure segment:

if test -n "$gdb_bin"; then
    gdb_version=$($gdb_bin --version | head -n 1)
    if version_ge ${gdb_version##* } 9.1; then
        gdb_arches=$($python "$source_path/scripts/probe-gdb-support.py" $gdb_bin)
    else
        gdb_bin=""
    fi
fi

and set a variable exported to config-host.mak to then test in the tcg
test makefiles.

Or you could implement a gdb-version-test command in
tests/tcg/Makefile.target which you could use like the existing
cc-test/cc-option commands to extend config-cc.mak and use that to gate
the tests.
Gustavo Romero June 24, 2024, 5:40 a.m. UTC | #5
Hi Alex,

On 6/17/24 6:50 AM, Alex Bennée wrote:
> Gustavo Romero <gustavo.romero@linaro.org> writes:
> 
>> Hi Alex,
>>
>> On 6/14/24 12:49 PM, Alex Bennée wrote:
>>> Gustavo Romero <gustavo.romero@linaro.org> writes:
>>>
>>>> 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, for
>>>> example, this way:
>>>>
>>>> make GDB=~/.local/bin/gdb run-tcg-tests-aarch64-linux-user -j 32
>>> It looks like there might be some BSD build failures as well:
>>>     https://gitlab.com/stsquad/qemu/-/pipelines/1332635371/failures
>>
>> I fixed the build for the BSD target in v3, however I think that the GDB in
>> the test containers need to be bumped to GDB 15 so the MTE tests can pass,
>> because support for IsAddressTagged packet is necessary. GDB 15 branch
>> is created by it's not released yet, so I don't know to proceed..
> 
> Two potential approaches, you could extend the configure segment:
> 
> if test -n "$gdb_bin"; then
>      gdb_version=$($gdb_bin --version | head -n 1)
>      if version_ge ${gdb_version##* } 9.1; then
>          gdb_arches=$($python "$source_path/scripts/probe-gdb-support.py" $gdb_bin)
>      else
>          gdb_bin=""
>      fi
> fi
> 
> and set a variable exported to config-host.mak to then test in the tcg
> test makefiles.

Done in v4. Thanks for the suggestions!


Cheers,
Gustavo

> Or you could implement a gdb-version-test command in
> tests/tcg/Makefile.target which you could use like the existing
> cc-test/cc-option commands to extend config-cc.mak and use that to gate
> the tests.