Skip to contentSkip to conversation

tests/qtest: Add RISC-V IOMMU bare-metal test using iommu-testdev

RFC PATCH Superseded Chao Liu 3 participants 9 messages Jan 29 – Feb 3

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Chao Liu

author
#0 lore raw

v2 cover tests/qtest: Add RISC-V IOMMU bare-metal test using iommu-testdev

Hi,

This patch series adds a bare-metal qtest for the RISC-V IOMMU using the iommu-testdev framework. The test exercises address translation paths without requiring a full guest OS boot.

Motivation
----------

The existing RISC-V IOMMU qtest (riscv-iommu-test.c) focuses on PCI device enumeration and register-level validation:
- PCI configuration space verification (vendor/device ID)
- Register reset value checks
- Queue initialization procedures (CQ/FQ/PQ)

However, it does not test the actual address translation functionality. This new test fills that gap by using iommu-testdev to trigger DMA transactions and validate the IOMMU's translation logic.

Comparison with Existing Test
-----------------------------

| Feature               | riscv-iommu-test.c | iommu-riscv-test.c (new) |
|-----------------------|--------------------|--------------------------|
| PCI config            | Yes                | No                       |
| Register reset        | Yes                | No                       |
| Queue init            | Yes                | Yes (via helper)         |
| Bare translation      | No                 | Yes                      |
| S-stage (SV39)        | No                 | Yes                      |
| G-stage (SV39x4)      | No                 | Yes                      |
| Nested translation    | No                 | Yes                      |
| DMA verification      | No                 | Yes                      |
| Uses iommu-testdev    | No                 | Yes                      |

The new test provides:
- Device context (DC) configuration and validation
- SV39 page table walks for S-stage translation
- SV39x4 page table walks for G-stage translation
- Nested translation combining both stages
- FCTL register constraint validation
- End-to-end DMA verification

Note: The current implementation only supports SV39/SV39x4. Support for SV48/SV48x4/SV57/SV57x4 can be added in future patches.

Testing
-------

QTEST_QEMU_BINARY=./build/qemu-system-riscv64 \
./build/tests/qtest/iommu-riscv-test --tap -k

Changes v1 -> v2
----------------
- Removed unused 'mode' parameter from qriommu_get_pte_attrs() function
- Simplified PTE mask definitions in header file by using direct hex values instead of individual bit defines (removed QRIOMMU_PTE_V/R/W/X /U/G/A/D macros), added comment referencing target/riscv/cpu_bits.h
- Cleaned up variable declarations in qriommu_setup_translation_tables() to follow C99 style (declare at point of use)
- Minor code style improvements

Thanks,
Chao

Chao Liu (2):
tests/qtest/libqos: Add RISC-V IOMMU helper library tests/qtest: Add RISC-V IOMMU bare-metal test

 MAINTAINERS                          |   2 +
 tests/qtest/iommu-riscv-test.c       | 279 ++++++++++++++++++
 tests/qtest/libqos/meson.build       |   2 +-
 tests/qtest/libqos/qos-riscv-iommu.c | 405 +++++++++++++++++++++++++++
 tests/qtest/libqos/qos-riscv-iommu.h | 164 +++++++++++
 tests/qtest/meson.build              |   5 +-
 6 files changed, 855 insertions(+), 2 deletions(-)
 create mode 100644 tests/qtest/iommu-riscv-test.c
 create mode 100644 tests/qtest/libqos/qos-riscv-iommu.c
 create mode 100644 tests/qtest/libqos/qos-riscv-iommu.h
Signature · 1 line
2.52.0
author
#1 lore raw

RFC PATCH v2 1/2 tests/qtest/libqos: Add RISC-V IOMMU helper library

Introduce a libqos helper module for RISC-V IOMMU testing with iommu-testdev. The helper provides routines to:

- Build device contexts (DC) and 3-level page tables for SV39/SV39x4
- Program command queue (CQ), fault queue (FQ), and DDTP registers following the RISC-V IOMMU specification
- Execute DMA translations and verify results

The current implementation supports SV39 for S-stage and SV39x4 for G-stage translation. Support for SV48/SV48x4/SV57/SV57x4 can be added in future patches.

---
 MAINTAINERS                          |   1 +
 tests/qtest/libqos/meson.build       |   2 +-
 tests/qtest/libqos/qos-riscv-iommu.c | 405 +++++++++++++++++++++++++++
 tests/qtest/libqos/qos-riscv-iommu.h | 164 +++++++++++
 4 files changed, 571 insertions(+), 1 deletion(-)
 create mode 100644 tests/qtest/libqos/qos-riscv-iommu.c
 create mode 100644 tests/qtest/libqos/qos-riscv-iommu.h
MAINTAINERS +1 -0
index dccdf47888..830f56376b 100644
@@ -3584,6 +3584,7 @@ M: Tao Tang <[email protected]>
 S: Maintained
 F: tests/qtest/libqos/qos-iommu*
 F: tests/qtest/libqos/qos-smmuv3*
+F: tests/qtest/libqos/qos-riscv-iommu*
 
 Device Fuzzing
 M: Alexander Bulekov <[email protected]>
tests/qtest/libqos/meson.build +1 -1
index b4daec808f..4a69acad0d 100644
@@ -71,7 +71,7 @@ if have_virtfs
 endif
 
 if config_all_devices.has_key('CONFIG_RISCV_IOMMU')
-  libqos_srcs += files('riscv-iommu.c')
+  libqos_srcs += files('riscv-iommu.c', 'qos-riscv-iommu.c')
 endif
 if config_all_devices.has_key('CONFIG_TPCI200')
   libqos_srcs += files('tpci200.c')
tests/qtest/libqos/qos-riscv-iommu.c new file +405 -0

405 lines not on this page · raw message

tests/qtest/libqos/qos-riscv-iommu.h new file +164 -0

164 lines not on this page · raw message

Signature · 1 line
2.52.0
Reviewed-by on v2 1/2
#2 lore raw

Re: [RFC PATCH v2 1/2] tests/qtest/libqos: Add RISC-V IOMMU helper library

Hi Chao,

Quoted 56 lines · Chao Liu

Introduce a libqos helper module for RISC-V IOMMU testing with iommu-testdev. The helper provides routines to:

- Build device contexts (DC) and 3-level page tables for SV39/SV39x4
- Program command queue (CQ), fault queue (FQ), and DDTP registers following the RISC-V IOMMU specification
- Execute DMA translations and verify results

The current implementation supports SV39 for S-stage and SV39x4 for G-stage translation. Support for SV48/SV48x4/SV57/SV57x4 can be added in future patches.

---
  MAINTAINERS                          |   1 +
  tests/qtest/libqos/meson.build       |   2 +-
  tests/qtest/libqos/qos-riscv-iommu.c | 405 +++++++++++++++++++++++++++
  tests/qtest/libqos/qos-riscv-iommu.h | 164 +++++++++++
  4 files changed, 571 insertions(+), 1 deletion(-)

create mode 100644 tests/qtest/libqos/qos-riscv-iommu.c create mode 100644 tests/qtest/libqos/qos-riscv-iommu.h

MAINTAINERS +1 -0
index dccdf47888..830f56376b 100644
@@ -3584,6 +3584,7 @@ M: Tao Tang <[email protected]>
  S: Maintained
  F: tests/qtest/libqos/qos-iommu*
  F: tests/qtest/libqos/qos-smmuv3*
+F: tests/qtest/libqos/qos-riscv-iommu*
 
  Device Fuzzing
  M: Alexander Bulekov <[email protected]>
tests/qtest/libqos/meson.build +1 -1
index b4daec808f..4a69acad0d 100644
@@ -71,7 +71,7 @@ if have_virtfs
  endif
 
  if config_all_devices.has_key('CONFIG_RISCV_IOMMU')
-  libqos_srcs += files('riscv-iommu.c')
+  libqos_srcs += files('riscv-iommu.c', 'qos-riscv-iommu.c')
  endif
  if config_all_devices.has_key('CONFIG_TPCI200')
    libqos_srcs += files('tpci200.c')
tests/qtest/libqos/qos-riscv-iommu.c new file +3 -0
new file mode 100644
index 0000000000..6c60889eeb
@@ -0,0 +1,405 @@
+/*
+ * QOS RISC-V IOMMU Module
+ *

tests/qtest/libqos/qos-riscv-iommu.c line 13

Quoted 10 lines
tests/qtest/libqos/qos-riscv-iommu.c new file +10 -0
+ * This module provides RISC-V IOMMU-specific helper functions for libqos tests,
+ * encapsulating RISC-V IOMMU setup, and assertions.
+ *
+ * Copyright (c) 2026 Chao Liu <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/bitops.h"

This include is unnecessary: hw/misc/iommu-testdev.h (pulled in by qos-riscv-iommu.h) already includes hw/pci/pci.h, and hw/pci/pci.h itself includes bitops.h.

tests/qtest/libqos/qos-riscv-iommu.c line 15

Quoted 2 lines
tests/qtest/libqos/qos-riscv-iommu.c new file +2 -0
+#include "hw/riscv/riscv-iommu-bits.h"
+#include "tests/qtest/libqos/pci.h"

Same. qos-iommu-testdev.h has included tests/qtest/libqos/pci.h.

Besides

Thanks,

Tao

Quoted 3 lines
tests/qtest/libqos/qos-riscv-iommu.c new file +3 -0
+#include "qos-iommu-testdev.h"
+#include "qos-riscv-iommu.h"
+
author
#3 lore raw

Re: [RFC PATCH v2 1/2] tests/qtest/libqos: Add RISC-V IOMMU helper library

Quoted 73 lines · Tao Tang

Hi Chao,

Quoted 54 lines · Chao Liu

Introduce a libqos helper module for RISC-V IOMMU testing with iommu-testdev. The helper provides routines to:

- Build device contexts (DC) and 3-level page tables for SV39/SV39x4
- Program command queue (CQ), fault queue (FQ), and DDTP registers following the RISC-V IOMMU specification
- Execute DMA translations and verify results

The current implementation supports SV39 for S-stage and SV39x4 for G-stage translation. Support for SV48/SV48x4/SV57/SV57x4 can be added in future patches.

---
  MAINTAINERS                          |   1 +
  tests/qtest/libqos/meson.build       |   2 +-
  tests/qtest/libqos/qos-riscv-iommu.c | 405 +++++++++++++++++++++++++++
  tests/qtest/libqos/qos-riscv-iommu.h | 164 +++++++++++
  4 files changed, 571 insertions(+), 1 deletion(-)

create mode 100644 tests/qtest/libqos/qos-riscv-iommu.c create mode 100644 tests/qtest/libqos/qos-riscv-iommu.h

MAINTAINERS +1 -0
index dccdf47888..830f56376b 100644
@@ -3584,6 +3584,7 @@ M: Tao Tang <[email protected]>
  S: Maintained
  F: tests/qtest/libqos/qos-iommu*
  F: tests/qtest/libqos/qos-smmuv3*
+F: tests/qtest/libqos/qos-riscv-iommu*
  Device Fuzzing
  M: Alexander Bulekov <[email protected]>
tests/qtest/libqos/meson.build +1 -1
index b4daec808f..4a69acad0d 100644
@@ -71,7 +71,7 @@ if have_virtfs
  endif
  if config_all_devices.has_key('CONFIG_RISCV_IOMMU')
-  libqos_srcs += files('riscv-iommu.c')
+  libqos_srcs += files('riscv-iommu.c', 'qos-riscv-iommu.c')
  endif
  if config_all_devices.has_key('CONFIG_TPCI200')
    libqos_srcs += files('tpci200.c')
tests/qtest/libqos/qos-riscv-iommu.c new file +3 -0
new file mode 100644
index 0000000000..6c60889eeb
@@ -0,0 +1,405 @@
+/*
+ * QOS RISC-V IOMMU Module
+ *

tests/qtest/libqos/qos-riscv-iommu.c line 13

Quoted 10 lines
tests/qtest/libqos/qos-riscv-iommu.c new file +10 -0
+ * This module provides RISC-V IOMMU-specific helper functions for libqos tests,
+ * encapsulating RISC-V IOMMU setup, and assertions.
+ *
+ * Copyright (c) 2026 Chao Liu <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/bitops.h"

This include is unnecessary: hw/misc/iommu-testdev.h (pulled in by qos-riscv-iommu.h) already includes hw/pci/pci.h, and hw/pci/pci.h itself includes bitops.h.

Quoted 5 lines

tests/qtest/libqos/qos-riscv-iommu.c line 15

Quoted 2 lines
tests/qtest/libqos/qos-riscv-iommu.c new file +2 -0
+#include "hw/riscv/riscv-iommu-bits.h"
+#include "tests/qtest/libqos/pci.h"

Same. qos-iommu-testdev.h has included tests/qtest/libqos/pci.h.

Thanks for the review. I'ill fix this in v3.

Thanks,
Chao

Quoted 15 lines

Besides

Thanks,

Tao

Quoted 3 lines
tests/qtest/libqos/qos-riscv-iommu.c new file +3 -0
+#include "qos-iommu-testdev.h"
+#include "qos-riscv-iommu.h"
+
author
#4 lore raw

RFC PATCH v2 2/2 tests/qtest: Add RISC-V IOMMU bare-metal test

In reply to Chao Liu

Add a qtest suite for the RISC-V IOMMU PCI device on the virt machine. The test exercises bare, S-stage, G-stage, and nested translation paths using iommu-testdev and the qos-riscv-iommu helpers.

The test validates:
- Device context (DC) configuration
- SV39 page table walks for S-stage translation
- SV39x4 page table walks for G-stage translation
- Nested translation combining both stages
- FCTL register constraints

This provides regression coverage for the RISC-V IOMMU implementation without requiring a full guest OS boot.

---
 MAINTAINERS                    |   1 +
 tests/qtest/iommu-riscv-test.c | 279 +++++++++++++++++++++++++++++++++
 tests/qtest/meson.build        |   5 +-
 3 files changed, 284 insertions(+), 1 deletion(-)
 create mode 100644 tests/qtest/iommu-riscv-test.c
MAINTAINERS +1 -0
index 830f56376b..73daaad841 100644
@@ -349,6 +349,7 @@ F: common-user/host/riscv*
 F: tests/functional/riscv32
 F: tests/functional/riscv64
 F: tests/tcg/riscv64/
+F: tests/qtest/iommu-riscv-test.c
 
 RISC-V XThead* extensions
 M: Christoph Muellner <[email protected]>
tests/qtest/iommu-riscv-test.c new file +279 -0

279 lines not on this page · raw message

tests/qtest/meson.build +4 -1
index dfb83650c6..25fdbc7980 100644
@@ -287,7 +287,10 @@ qtests_riscv32 = \
   (config_all_devices.has_key('CONFIG_SIFIVE_E_AON') ? ['sifive-e-aon-watchdog-test'] : [])
 
 qtests_riscv64 = ['riscv-csr-test'] + \
-  (unpack_edk2_blobs ? ['bios-tables-test'] : [])
+  (unpack_edk2_blobs ? ['bios-tables-test'] : []) + \
+  (config_all_devices.has_key('CONFIG_IOMMU_TESTDEV') and
+   config_all_devices.has_key('CONFIG_RISCV_IOMMU') ?
+   ['iommu-riscv-test'] : [])
 
 qos_test_ss = ss.source_set()
 qos_test_ss.add(
Signature · 1 line
2.52.0
Reviewed-by on v2 2/2
#5 lore raw

Re: [RFC PATCH v2 2/2] tests/qtest: Add RISC-V IOMMU bare-metal test

Hi Chao,

Quoted 44 lines · Chao Liu

Add a qtest suite for the RISC-V IOMMU PCI device on the virt machine. The test exercises bare, S-stage, G-stage, and nested translation paths using iommu-testdev and the qos-riscv-iommu helpers.

The test validates:
- Device context (DC) configuration
- SV39 page table walks for S-stage translation
- SV39x4 page table walks for G-stage translation
- Nested translation combining both stages
- FCTL register constraints

This provides regression coverage for the RISC-V IOMMU implementation without requiring a full guest OS boot.

---
  MAINTAINERS                    |   1 +
  tests/qtest/iommu-riscv-test.c | 279 +++++++++++++++++++++++++++++++++
  tests/qtest/meson.build        |   5 +-
  3 files changed, 284 insertions(+), 1 deletion(-)

create mode 100644 tests/qtest/iommu-riscv-test.c

MAINTAINERS +1 -0
index 830f56376b..73daaad841 100644
@@ -349,6 +349,7 @@ F: common-user/host/riscv*
  F: tests/functional/riscv32
  F: tests/functional/riscv64
  F: tests/tcg/riscv64/
+F: tests/qtest/iommu-riscv-test.c
 
  RISC-V XThead* extensions
  M: Christoph Muellner <[email protected]>
tests/qtest/iommu-riscv-test.c new file +4 -0
new file mode 100644
index 0000000000..5a86b18db9
@@ -0,0 +1,279 @@
+/*
+ * QTest testcase for RISC-V IOMMU with iommu-testdev
+ *
+ * This QTest file is used to test the RISC-V IOMMU with iommu-testdev so that

tests/qtest/iommu-riscv-test.c line 14

Quoted 10 lines
tests/qtest/iommu-riscv-test.c new file +10 -0
+ * we can test RISC-V IOMMU without any guest kernel or firmware.
+ *
+ * Copyright (c) 2026 Chao Liu <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "libqtest.h"
+#include "libqos/pci.h"

libqtest.h and libqos/pci.h are redundant because they are already pulled in by libqos/generic-pcihost.h (libqos/pci.h itself includes libqtest.h)

Besides

Thanks,

Tao

Quoted 8 lines
tests/qtest/iommu-riscv-test.c new file +8 -0
+#include "libqos/generic-pcihost.h"
+#include "hw/pci/pci_regs.h"
+#include "hw/misc/iommu-testdev.h"
+#include "hw/riscv/riscv-iommu-bits.h"
+#include "libqos/qos-riscv-iommu.h"
+#include "libqos/riscv-iommu.h"
+
+#define DMA_LEN           4
author
#6 lore raw

Re: [RFC PATCH v2 2/2] tests/qtest: Add RISC-V IOMMU bare-metal test

Hi Tao,

Quoted 52 lines · Tao Tang

Hi Chao,

Quoted 49 lines · Chao Liu

Add a qtest suite for the RISC-V IOMMU PCI device on the virt machine. The test exercises bare, S-stage, G-stage, and nested translation paths using iommu-testdev and the qos-riscv-iommu helpers.

The test validates:
- Device context (DC) configuration
- SV39 page table walks for S-stage translation
- SV39x4 page table walks for G-stage translation
- Nested translation combining both stages
- FCTL register constraints

This provides regression coverage for the RISC-V IOMMU implementation without requiring a full guest OS boot.

---
  MAINTAINERS                    |   1 +
  tests/qtest/iommu-riscv-test.c | 279 +++++++++++++++++++++++++++++++++
  tests/qtest/meson.build        |   5 +-
  3 files changed, 284 insertions(+), 1 deletion(-)

create mode 100644 tests/qtest/iommu-riscv-test.c

MAINTAINERS +1 -0
index 830f56376b..73daaad841 100644
@@ -349,6 +349,7 @@ F: common-user/host/riscv*
  F: tests/functional/riscv32
  F: tests/functional/riscv64
  F: tests/tcg/riscv64/
+F: tests/qtest/iommu-riscv-test.c
  RISC-V XThead* extensions
  M: Christoph Muellner <[email protected]>
tests/qtest/iommu-riscv-test.c new file +10 -0
new file mode 100644
index 0000000000..5a86b18db9
@@ -0,0 +1,279 @@
+/*
+ * QTest testcase for RISC-V IOMMU with iommu-testdev
+ *
+ * This QTest file is used to test the RISC-V IOMMU with iommu-testdev so that
+ * we can test RISC-V IOMMU without any guest kernel or firmware.
+ *
+ * Copyright (c) 2026 Chao Liu <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
Quoted 10 lines

tests/qtest/iommu-riscv-test.c line 14

Quoted 4 lines
tests/qtest/iommu-riscv-test.c new file +4 -0
+
+#include "qemu/osdep.h"
+#include "libqtest.h"
+#include "libqos/pci.h"

libqtest.h and libqos/pci.h are redundant because they are already pulled in by libqos/generic-pcihost.h (libqos/pci.h itself includes libqtest.h)

Thanks for the review. I'ill fix this in v3.

Thanks,
Chao

Quoted 18 lines

Besides

Thanks,

Tao

Quoted 8 lines
tests/qtest/iommu-riscv-test.c new file +8 -0
+#include "libqos/generic-pcihost.h"
+#include "hw/pci/pci_regs.h"
+#include "hw/misc/iommu-testdev.h"
+#include "hw/riscv/riscv-iommu-bits.h"
+#include "libqos/qos-riscv-iommu.h"
+#include "libqos/riscv-iommu.h"
+
+#define DMA_LEN           4
Reviewed-by on v2 2/2
#7 lore raw

Re: [RFC PATCH v2 2/2] tests/qtest: Add RISC-V IOMMU bare-metal test

In reply to Chao Liu
Quoted 15 lines · Chao Liu

Add a qtest suite for the RISC-V IOMMU PCI device on the virt machine. The test exercises bare, S-stage, G-stage, and nested translation paths using iommu-testdev and the qos-riscv-iommu helpers.

The test validates:
- Device context (DC) configuration
- SV39 page table walks for S-stage translation
- SV39x4 page table walks for G-stage translation
- Nested translation combining both stages
- FCTL register constraints

This provides regression coverage for the RISC-V IOMMU implementation without requiring a full guest OS boot.

...

Quoted 11 lines
tests/qtest/iommu-riscv-test.c new file +11 -0
+static bool riscv_iommu_test_setup(RiscvIommuTestState *state)
+{
+    if (!qtest_has_machine("virt")) {
+        g_test_skip("virt machine not available");
+        return false;
+    }
+
+    state->qts = qtest_init("-machine virt,acpi=off "
+                            "-cpu max -smp 1 -m 512 -net none "
+                            "-device riscv-iommu-pci "
+                            "-device iommu-testdev");

tests/qtest/iommu-riscv-test.c line 136

Quoted 10 lines
tests/qtest/iommu-riscv-test.c new file +10 -0
+
+    qpci_init_generic(&state->gbus, state->qts, NULL, false);
+    riscv_config_qpci_bus(&state->gbus);
+
+    state->iommu_dev = find_riscv_iommu_pci(&state->gbus, &state->iommu_base);
+    g_assert(state->iommu_dev);
+
+    state->testdev = find_iommu_testdev(&state->gbus, &state->testdev_bar);
+    g_assert(state->testdev);
+

These two will leak. Otherwise, looks good.

author
#8 lore raw

Re: [RFC PATCH v2 2/2] tests/qtest: Add RISC-V IOMMU bare-metal test

Hi Fabiano,

Quoted 35 lines · Fabiano Rosas
Quoted 15 lines · Chao Liu

Add a qtest suite for the RISC-V IOMMU PCI device on the virt machine. The test exercises bare, S-stage, G-stage, and nested translation paths using iommu-testdev and the qos-riscv-iommu helpers.

The test validates:
- Device context (DC) configuration
- SV39 page table walks for S-stage translation
- SV39x4 page table walks for G-stage translation
- Nested translation combining both stages
- FCTL register constraints

This provides regression coverage for the RISC-V IOMMU implementation without requiring a full guest OS boot.

...

Quoted 15 lines
tests/qtest/iommu-riscv-test.c new file +15 -0
+static bool riscv_iommu_test_setup(RiscvIommuTestState *state)
+{
+    if (!qtest_has_machine("virt")) {
+        g_test_skip("virt machine not available");
+        return false;
+    }
+
+    state->qts = qtest_init("-machine virt,acpi=off "
+                            "-cpu max -smp 1 -m 512 -net none "
+                            "-device riscv-iommu-pci "
+                            "-device iommu-testdev");
+
+    qpci_init_generic(&state->gbus, state->qts, NULL, false);
+    riscv_config_qpci_bus(&state->gbus);
+
Quoted 9 lines

tests/qtest/iommu-riscv-test.c line 136

Quoted 6 lines
tests/qtest/iommu-riscv-test.c new file +6 -0
+    state->iommu_dev = find_riscv_iommu_pci(&state->gbus, &state->iommu_base);
+    g_assert(state->iommu_dev);
+
+    state->testdev = find_iommu_testdev(&state->gbus, &state->testdev_bar);
+    g_assert(state->testdev);
+

These two will leak. Otherwise, looks good.

Thanks for the review. I'ill fix this in v3.

Thanks,
Chao

Quoted 1 line