[RFC v3 0/4] tests/qtest: Add memory-access attributes (secure/space)

Tao Tang posted 4 patches 1 week, 2 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260323133210.1523868-1-tangtao1634@phytium.com.cn
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
hw/pci-host/q35.c                  |  24 ++
include/hw/pci-host/q35.h          |   8 +
system/qtest.c                     | 517 ++++++++++++++++++++++++++---
tests/qtest/libqtest-single.h      | 156 +++++++++
tests/qtest/libqtest.c             | 246 +++++++++++---
tests/qtest/libqtest.h             | 177 ++++++++++
tests/qtest/meson.build            |   8 +-
tests/qtest/qtest-attrs-test.c     | 305 +++++++++++++++++
tests/qtest/qtest-x86-attrs-test.c | 109 ++++++
9 files changed, 1439 insertions(+), 111 deletions(-)
create mode 100644 tests/qtest/qtest-attrs-test.c
create mode 100644 tests/qtest/qtest-x86-attrs-test.c
[RFC v3 0/4] tests/qtest: Add memory-access attributes (secure/space)
Posted by Tao Tang 1 week, 2 days ago
This is v3 of the patch series adding support for memory access attributes
(secure / security-space selection) in the qtest framework.

Thanks to everyone who reviewed the previous version and provided valuable
feedback.

The main change from v2 is that the series is now structured around verifying
that attrs select the intended AddressSpace, rather than only extending the
qtest syntax. To make that explicit, v3 splits the implementation by layer and
strengthens the tests around real address-space differences on both Arm and x86.

The major changes from v2 include:

- split the old combined protocol/libqtest change into separate qtest server
  and libqtest helper patches
- refactor libqtest response parsing and add qtest_raw_cmd(), so tests can
  inspect non-OK replies directly
- make qtest memory access failures return ERR via qtest_send_memtx_error(),
  enabling negative testing of address-space mismatches
- rework qtest-attrs-test on Arm to target the virt secure-only RAM window,
  and add negative coverage for space=realm and for non-secure accesses into
  secure-only RAM
- switch x86 coverage to q35,smm=on and add a NOT-MERGE q35-only SMM test RAM
  path plus a dedicated qtest-x86-attrs-test, so secure accesses can be
  cross-checked against an address visible only in the SMM address space


Motivation
----------

IOMMU functional testing is always stack-heavy: for example, even for the
Non-secure Arm SMMU model, end-to-end validation can require a fairly involved
software stack. To keep the testing loop tight and reproducible, I previously
proposed using iommu-testdev + QTest to validate IOMMU/SMMU behaviour without
booting a guest [1].

[1] https://www.qemu.org/docs/master/specs/iommu-testdev.html

However, the current QTest interface cannot tag memory accesses with MemTxAttrs,
so it is hard to write targeted tests for security-sensitive paths. This becomes
a bigger issue for Secure SMMU work, which is RFCing in [2], and for future Arm
RME-DA enablement.

[2] https://lore.kernel.org/qemu-devel/20260221100250.2976287-1-tangtao1634@phytium.com.cn/

This series therefore extends qtest memory access commands with an optional
attrs argument, adds matching libqtest helpers, and introduces tests that
exercise the new APIs against address spaces that actually differ by security
context.

In particular:
- on Arm virt,secure=on, the test now uses the secure-only RAM window so the
  requested attrs must select the correct AddressSpace
- on x86 q35,smm=on, the API series covers normal RAM, and an extra NOT-MERGE
  validation patch adds an SMM-only RAM window so the secure path can be
  cross-checked against a location not visible from the default address space


Compatibility
-------------

This series is additive for existing qtest users:
- Existing qtest memory commands keep their current forms; attrs is an optional
  extra argument
- Existing libqtest memory helpers remain available and are kept as wrappers
  passing NULL attrs
- The first three patches are the upstreamable API and test additions
- The fourth patch is explicitly marked NOT-MERGE and only provides extra x86
  RFC coverage by wiring in a q35 test-only SMM RAM window

One behavioural improvement is that memory access failures on the new paths are
now reported consistently as ERR, which lets tests validate address-space
selection failures directly.


Testing
-------

The API series was exercised with:

  meson test -C build \
      "qtest-aarch64/qtest-attrs-test" \
      "qtest-i386/qtest-attrs-test" \
      "qtest-x86_64/qtest-attrs-test"

The extra x86 cross-check from the NOT-MERGE patch was exercised with:

  meson test -C build \
      "qtest-i386/qtest-x86-attrs-test" \
      "qtest-x86_64/qtest-x86-attrs-test"


Future work
-----------

Once the Secure SMMU series lands, I plan to build on this qtest API to extend
iommu-testdev-based tests to cover more security contexts while still avoiding
a full guest software stack.

This series is also available in a branch below [3]:
[3] https://gitlab.com/TaoTang/qemu/-/tree/series/qtest-secure-api-v3-6

CI is all green [4]:
[4] https://gitlab.com/TaoTang/qemu/-/pipelines/2399350916


Tao Tang (4):
  tests/qtest: Add attrs support to qtest server memory commands
  tests/qtest: Add libqtest attrs helpers for memory accesses
  tests/qtest: Add qtest-attrs-test for memory access attrs
  [NOT-MERGE] tests/qtest: add q35 SMM-only x86 attrs coverage

 hw/pci-host/q35.c                  |  24 ++
 include/hw/pci-host/q35.h          |   8 +
 system/qtest.c                     | 517 ++++++++++++++++++++++++++---
 tests/qtest/libqtest-single.h      | 156 +++++++++
 tests/qtest/libqtest.c             | 246 +++++++++++---
 tests/qtest/libqtest.h             | 177 ++++++++++
 tests/qtest/meson.build            |   8 +-
 tests/qtest/qtest-attrs-test.c     | 305 +++++++++++++++++
 tests/qtest/qtest-x86-attrs-test.c | 109 ++++++
 9 files changed, 1439 insertions(+), 111 deletions(-)
 create mode 100644 tests/qtest/qtest-attrs-test.c
 create mode 100644 tests/qtest/qtest-x86-attrs-test.c

-- 
2.34.1