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

Tao Tang posted 4 patches 1 day, 18 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260331040659.401397-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>
There is a newer version of this series
hw/pci-host/q35.c                  |  26 ++
include/hw/pci-host/q35.h          |   8 +
system/qtest.c                     | 420 +++++++++++++++++++++++++----
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     | 350 ++++++++++++++++++++++++
tests/qtest/qtest-x86-attrs-test.c | 170 ++++++++++++
9 files changed, 1452 insertions(+), 109 deletions(-)
create mode 100644 tests/qtest/qtest-attrs-test.c
create mode 100644 tests/qtest/qtest-x86-attrs-test.c
[PATCH 0/4] tests/qtest: Add memory-access attributes (secure/space)
Posted by Tao Tang 1 day, 18 hours ago
This is v4 of the qtest attrs support series. The main changes from v3 are
improvements to error handling validation and negative-case coverage.

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

This series is also available in a branch below:
https://gitlab.com/TaoTang/qemu/-/commits/series/qtest-secure-api-v4-2

CI is all green:
https://gitlab.com/TaoTang/qemu/-/pipelines/2418450703

The remainder of this cover letter is unchanged from the previous version.

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.


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                  |  26 ++
 include/hw/pci-host/q35.h          |   8 +
 system/qtest.c                     | 420 +++++++++++++++++++++++++----
 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     | 350 ++++++++++++++++++++++++
 tests/qtest/qtest-x86-attrs-test.c | 170 ++++++++++++
 9 files changed, 1452 insertions(+), 109 deletions(-)
 create mode 100644 tests/qtest/qtest-attrs-test.c
 create mode 100644 tests/qtest/qtest-x86-attrs-test.c

-- 
2.34.1