[PATCH v6 00/35] hw/arm/smmuv3: Support Secure state for SMMUv3

Tao Tang posted 35 patches 1 week, 1 day ago
docs/system/arm/virt.rst       |   11 +
hw/arm/smmu-internal.h         |   13 +
hw/arm/smmuv3-internal.h       |   39 +-
include/hw/arm/smmu-common.h   |   80 ++-
include/hw/arm/smmuv3-common.h |   71 +-
include/hw/arm/smmuv3.h        |   44 +-
include/hw/arm/virt.h          |    1 +
include/hw/pci/pci_device.h    |    3 +
hw/arm/sbsa-ref.c              |    8 +
hw/arm/smmu-common.c           |  426 ++++++++++--
hw/arm/smmuv3-accel.c          |   77 ++-
hw/arm/smmuv3.c                | 1184 +++++++++++++++++++++++---------
hw/arm/tegra241-cmdqv.c        |    6 +-
hw/arm/virt-acpi-build.c       |    3 +-
hw/arm/virt.c                  |    7 +
hw/core/machine.c              |    1 +
hw/pci/pci.c                   |   48 ++
hw/arm/trace-events            |   37 +-
18 files changed, 1597 insertions(+), 462 deletions(-)
[PATCH v6 00/35] hw/arm/smmuv3: Support Secure state for SMMUv3
Posted by Tao Tang 1 week, 1 day ago
Hi all,

This is v6 of the Secure SMMUv3 series.

Many thanks to everyone who reviewed the earlier versions. This version contains
35 commits in total. Most of them are confined to the Arm SMMU model. But a few
commits also touch the PCI device model, and the virt machine model.

Secure Stage 2 is not implemented. Secure STEs which enable Stage 2 are
rejected with C_BAD_STE. Realm and Root programming interfaces are outside the
scope of this series.


Commits layout:
---------------
The commits are roughly grouped as follows:

1. (#30, hw/pci only) Add a PCIDevice "sec-sid" property so boards can mark a
   device's SEC_SID (system integration knob).
2. (#1-2, #31-35) Core data-structure and plumbing refactors.
3. (#3-8) Introduce SEC_SID through caches, notifiers, and helpers.
4. (#9-12) Page table walk related updates (e.g. NSCFG/PTE helpers).
5. (#13-20) EVTQ/CMDQ handling and invalidation paths.
6. (#21-29) MMIO/register access checks and architectural corner cases.


Changes since v5:
----------------
- Split the invalidation and register-check patches, separate secure-impl
  from migration, and move S2 walker changes into the page-table walk patch.
- Add fixes for Secure S1 VMID tagging (#18) and ATC_INV checks (#20).
- Validate sec-sid in the PCI setter, reject incompatible devices through
  the PCI IOMMU check, and refresh SEC_SID on device reuse.
- Wire Secure IRQs on virt and sbsa-ref, and update CMDQV IRQ indexing.
- Document secure-impl and preserve the previous default for older
  machine types.
- Drop the temporary [NOT-MERGE] Hafnium bring-up patch.


Testing notes:
--------------
- Testing MMIO accesses
I also tested Secure-bank register reads and writes using Hafnium
firmware as described in [1].

- Testing DMA translation
I integrated this series with the latest RFCing QTest memory-attribute
extensions from [2]. The test integration also includes the iommu-testdev DMA
readback fix and the SMMUv3 security-space tests. It is available in [3].

All five SMMUv3 test cases passed:
-- Non-secure Stage 1.
-- Non-secure Stage 2.
-- Non-secure nested translation.
-- Secure Stage 1.
-- Secure Stage 2 rejection with C_BAD_STE.

The first three cases has upstreamed. For the last two cases:

    QTEST_QEMU_BINARY=./build/qemu-system-aarch64 \
      ./build/tests/qtest/iommu-smmuv3-test --tap -k \
      -p /aarch64/iommu-testdev/translation/secure-s1-only

    QTEST_QEMU_BINARY=./build/qemu-system-aarch64 \
      ./build/tests/qtest/iommu-smmuv3-test --tap -k \
      -p /aarch64/iommu-testdev/translation/secure-s2-only-bad-ste


The patches also available at [4]. The CI [5] passed with warnings from two jobs,
which also occured in upstream CI.

Best regards,
Tao

[1] https://hnusdr.github.io/2025/08/09/Test-Secure-SMMU-with-Hafnium-ENG/
[2] https://gitlab.com/TaoTang/qemu/-/tree/series/qtest-secure-v6
[3] https://gitlab.com/TaoTang/qemu/-/tree/integration/secure-smmu-v6-qtest
[4] https://gitlab.com/TaoTang/qemu/-/tree/series/secure-smmu-v6
[5] https://gitlab.com/TaoTang/qemu/-/pipelines/3065596056

Tao Tang (35):
  hw/arm/smmuv3: Introduce Secure registers
  hw/arm/smmuv3: Introduce banked registers for SMMUv3 state
  hw/arm/smmuv3: Thread SEC_SID through helper APIs
  hw/arm/smmuv3: Track SEC_SID in configs and events
  hw/arm/smmu-common: Add security-aware address space selector
  hw/arm/smmuv3: Plumb transaction attributes into config helpers
  hw/arm/smmuv3: Reject Secure STEs with stage-2 enabled
  hw/arm/smmu-common: Key configuration cache on SMMUDevice and SEC_SID
  hw/arm/smmu: Add PTE NS/NSTable helpers
  hw/arm/smmuv3: Store CD NSCFG in TT info
  hw/arm/smmu-common: Implement Secure state handling in ptw
  hw/arm/smmuv3: Tag IOTLB cache keys with SEC_SID
  hw/arm/smmuv3: Pass sec_sid into cmdq consume path
  hw/arm/smmuv3: Make evtq producer use SEC_SID
  hw/arm/smmuv3: Limit IOMMU notifications to Non-secure targets
  hw/arm/smmuv3: Scope configuration invalidation by SEC_SID
  hw/arm/smmuv3: Scope IOTLB invalidation by SEC_SID
  hw/arm/smmuv3: Fix VMID tagging for Secure stage 1
  hw/arm/smmuv3: Keep accelerated invalidation Non-secure-only
  hw/arm/smmuv3: Fix ATC invalidation command checks
  hw/arm/smmuv3: Make GERROR_IRQ_CFG registers RES0 without MSI
  hw/arm/smmuv3: Ignore CR2 writes while the SMMU is enabled
  hw/arm/smmuv3: Guard stream table register writes
  hw/arm/smmuv3: Guard command queue register writes
  hw/arm/smmuv3: Guard event queue register writes
  hw/arm/smmuv3: Determine register bank from MMIO offset
  hw/arm/smmuv3: Route IRQ and GERROR handling by SEC_SID
  hw/arm/smmuv3: Implement SMMU_S_INIT register
  hw/arm/smmuv3: Harden security checks in MMIO handlers
  hw/pci: Add sec-sid property to PCIDevice
  hw/arm/smmuv3: Select sec-sid from PCI property and validate
    SECURE_IMPL
  hw/arm/smmuv3: Reject IOMMU notifiers for non-NS devices
  hw/arm/smmuv3: Initialize the Secure register bank
  hw/arm/smmuv3: Add the secure-impl property
  hw/arm/smmuv3: Migrate the Secure register bank

 docs/system/arm/virt.rst       |   11 +
 hw/arm/smmu-internal.h         |   13 +
 hw/arm/smmuv3-internal.h       |   39 +-
 include/hw/arm/smmu-common.h   |   80 ++-
 include/hw/arm/smmuv3-common.h |   71 +-
 include/hw/arm/smmuv3.h        |   44 +-
 include/hw/arm/virt.h          |    1 +
 include/hw/pci/pci_device.h    |    3 +
 hw/arm/sbsa-ref.c              |    8 +
 hw/arm/smmu-common.c           |  426 ++++++++++--
 hw/arm/smmuv3-accel.c          |   77 ++-
 hw/arm/smmuv3.c                | 1184 +++++++++++++++++++++++---------
 hw/arm/tegra241-cmdqv.c        |    6 +-
 hw/arm/virt-acpi-build.c       |    3 +-
 hw/arm/virt.c                  |    7 +
 hw/core/machine.c              |    1 +
 hw/pci/pci.c                   |   48 ++
 hw/arm/trace-events            |   37 +-
 18 files changed, 1597 insertions(+), 462 deletions(-)

--
2.34.1