> This series adds support for automatic updates of page-table accessed
> (A) and dirty (D) bits in the RISC-V IOMMU, as specified by the RISC-V
> IOMMU architecture. The feature is advertised through the AMO_HWAD
> capability and controlled by the SADE and GADE bits in device contexts.
>
> The first two patches fix implicit G-stage page-table access handling
> and IOATC permission checks. The third patch implements atomic A/D bit
> updates using CAS, with page-table walk retries on concurrent
> modifications and G-stage permission checks for implicit writes during
> nested translation.
>
> The implementation has been validated with QTests, Linux DMA tests under
> KVM and TCG, and concurrency tests covering CAS retries, PTE
> modifications, and G-stage mapping changes.
>
> ---
> Changes in v2:
> - Set iotval2 to zero for S-stage page faults, as suggested by
> Daniel Henrique Barboza.
> - Avoid duplicate implicit_read calculations, as suggested by Nutty Liu.
> - Document the new amo-hwad device property.
>
> v1: https://lore.kernel.org/qemu-devel/20261108143934.129923-1-tanchi25@mails.ucas.ac.cn/
>
> Tan Chi (3):
> hw/riscv: iommu: Fix implicit G-stage page-table accesses
> hw/riscv: iommu: Check permissions on IOATC hits
> hw/riscv: iommu: Support automatic PTE A/D updates
Hi Tan Chi,
Thanks for your work.
I have tested this series on my nested IOMMU setup.
- Outer QEMU: this series on top of master, -M virt,...,iommu-sys=on,
-global riscv-iommu.amo-hwad=on, emulated NVMe
- Inner QEMU: needs accel=on support for riscv-iommu-pci, and
vfio-pci with iommufd
- Outer Linux host: needs hardware dirty tracking and nested IOMMU
support
Test flow:
1. Boot host and guest, do NVMe I/O
2. Clear host S2 D bits and trigger GVMA inval in the inner QEMU monitor,
use command: calc_dirty_rate -b 1
3. Back to guest shell and do another NVMe I/O
It completed without a guest hang or I/O error. With temporary local
debug prints I could see en_s=1/en_g=1 and implicit G-stage page-table
walks.
One host-side workaround is that on the host I need
echo never > /sys/kernel/mm/transparent_hugepage/enabled
to avoid an hang with THP; otherwise calc_dirty_rate -b can leave the
guest stuck.
This is only a limited positive test. A Linux guest is not suitable for
constructing negative cases so I would not claim full Tested-by coverage.
Thanks,
Shuai
>
> docs/specs/riscv-iommu.rst | 2 +
> hw/riscv/riscv-iommu.c | 254 +++++++++++++++++++++++++++++++++----
> hw/riscv/riscv-iommu.h | 1 +
> 3 files changed, 232 insertions(+), 25 deletions(-)
>
> --
> 2.53.0
>