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

Tao Tang <[email protected]>
Newsgroups org.nongnu.qemu-devel,org.nongnu.qemu-arm
Message-ID <[email protected]>
This is v5 of the qtest memory-access attributes series. Thanks to everyone who
reviewed v4 and provided feedback.

Since v4:
- server-side attrs handling has been simplified
- raw response handling has been split into a preparatory patch, and reusable
libqtest assertions and typed failure helpers have been added
- raw commands are now used only for malformed protocol forms.

This series is also available in a branch below:
https://gitlab.com/TaoTang/qemu/tree/qtest-secure-v5

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


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/[email protected]/

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 4 patches are the upstreamable API and test additions
- The 5th 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. There is an experimental branch that already uses
this API to validate secure/non-secure SMMU behaviour:

https://gitlab.com/TaoTang/qemu/tree/integration/secure-smmu-v5-qtest


Tao Tang (5):
  tests/qtest: Add attrs support to qtest server memory commands
  tests/qtest: Add libqtest attrs helpers for memory accesses
  tests/qtest: Add raw command response helper
  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                  |  27 ++
 include/hw/pci-host/q35.h          |   8 +
 system/qtest.c                     | 349 +++++++++++++++++++++----
 tests/qtest/libqtest-single.h      | 156 +++++++++++
 tests/qtest/libqtest.c             | 402 +++++++++++++++++++++++++----
 tests/qtest/libqtest.h             | 288 +++++++++++++++++++++
 tests/qtest/meson.build            |   8 +-
 tests/qtest/qtest-attrs-test.c     | 305 ++++++++++++++++++++++
 tests/qtest/qtest-x86-attrs-test.c | 170 ++++++++++++
 9 files changed, 1600 insertions(+), 113 deletions(-)
 create mode 100644 tests/qtest/qtest-attrs-test.c
 create mode 100644 tests/qtest/qtest-x86-attrs-test.c

--
2.34.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.