Skip to contentSkip to conversation

AMD IOMMU

PATCH Superseded David Kiarie 2 participants 6 messages Jul 8, 2016 – Jul 11, 2016

v13 of 19 Superseded Latest is v19 →

lore
Share & tools
lore
#0 lore raw

v13 cover AMD IOMMU

Hi all,

This patchset adds basic AMD IOMMU emulation support to Qemu.

Changes since v12

-Coding style fixes [Jan, Michael]
-Error logging fix to avoid using a macro[Jan] -moved some PCI macros to PCI header[Jan]
-Use a lookup table for MMIO register names when tracing[Jan]

Changes since V11
-AMD IOMMU is not started with -device amd-iommu (with a dependency on Marcel's patches). -IOMMU commands are represented using bitfields which is less error prone and more readable[Peter] -Changed from debug fprintfs to tracing[Jan]

Changes since V10

-Support for huge pages including some obscure AMD IOMMU feature that allows default page size override[Jan].
-Fixed an issue with generation of interrupts. We noted that AMD IOMMU has BusMaster- and is therefore not able to generate interrupts like any other PCI device. We have resulted in writing directly to system address but this could be fixed by some patches which have not been merged yet.

Changes since v9

-amd_iommu prefixes have been renamed to a shorter 'amdvi' both in the macros
and in the functions/code. The register macros have not been moved to the implementation file since almost the macros there are basically macros and I reckoned renaming them should suffice.
-taken care of byte order in the use of 'dma_memory_read'[Michael]
-Taken care of invalid DTE entries to ensure no DMA unless a device is configured to allow it. -An issue with the emulate IOMMU defaulting to AMD_IOMMU has been fixed[Marcel]

You can test[1] this patches by starting with parameters
qemu-system-x86_64 -M -device amd-iommu -m 2G -enable-kvm -smp 4 -cpu host -hda file.img -soundhw ac97
emulating whatever devices you want.

Not passing any command line parameters to linux should be enough to test this patches since the devices are basically passes-through but to the 'host' (l1 guest). You can still go ahead pass command line parameter 'iommu=pt iommu=1' and try to pass a device to L2 guest. This can also done without passing any iommu related parameters to the kernel.

David Kiarie (4):
hw/pci: Prepare for AMD IOMMU hw/i386/trace-events: Add AMD IOMMU trace events hw/i386: Introduce AMD IOMMU
hw/i386: AMD IOMMU IVRS table

 hw/acpi/aml-build.c         |    2 +-
 hw/i386/Makefile.objs       |    1 +
 hw/i386/acpi-build.c        |  102 +++-
 hw/i386/amd_iommu.c         | 1384 +++++++++++++++++++++++++++++++++++++++++++
 hw/i386/amd_iommu.h         |  285 +++++++++
 hw/i386/trace-events        |   29 +
 include/hw/acpi/aml-build.h |    1 +
 include/hw/pci/pci.h        |    5 +-
 8 files changed, 1796 insertions(+), 13 deletions(-)
 create mode 100644 hw/i386/amd_iommu.c
 create mode 100644 hw/i386/amd_iommu.h
Signature · 1 line
2.1.4
#1 lore raw

PATCH v13 1/4 hw/pci: Prepare for AMD IOMMU

Introduce PCI macros from for use by AMD IOMMU

---
 include/hw/pci/pci.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/hw/pci/pci.h +4 -1
index 9ed1624..959d05b 100644
@@ -11,11 +11,14 @@
 #include "hw/pci/pcie.h"
 
 /* PCI bus */
-
+#define PCI_BDF(bus, devfn)     ((((uint16_t)(bus)) << 8) | (devfn))
 #define PCI_DEVFN(slot, func)   ((((slot) & 0x1f) << 3) | ((func) & 0x07))
+#define PCI_BUS_NUM(x)          (((x) >> 8) & 0xff)
 #define PCI_SLOT(devfn)         (((devfn) >> 3) & 0x1f)
 #define PCI_FUNC(devfn)         ((devfn) & 0x07)
 #define PCI_BUILD_BDF(bus, devfn)     ((bus << 8) | (devfn))
+#define PCI_BUS_MAX             256
+#define PCI_DEVFN_MAX           256
 #define PCI_SLOT_MAX            32
 #define PCI_FUNC_MAX            8
 
Signature · 1 line
2.1.4
#2 lore raw

PATCH v13 2/4 hw/i386/trace-events: Add AMD IOMMU trace events

In reply to David Kiarie
---
 hw/i386/trace-events | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
hw/i386/trace-events +29 -0
index ea77bc2..a2f529e 100644
@@ -10,3 +10,32 @@ xen_pv_mmio_write(uint64_t addr) "WARNING: write to Xen PV Device MMIO space (ad
 # hw/i386/pc.c
 mhp_pc_dimm_assigned_slot(int slot) "0x%d"
 mhp_pc_dimm_assigned_address(uint64_t addr) "0x%"PRIx64
+
+# hw/i386/amd_iommu.c
+amdvi_evntlog_fail(uint64_t addr, uint32_t head) "error: fail to write at addr 0x%"PRIx64 " +  offset 0x%"PRIx32
+amdvi_cache_update(uint16_t domid, uint32_t bus, uint32_t slot, uint32_t func, uint64_t gpa, uint64_t txaddr) " update iotlb domid 0x%"PRIx16" devid: %02x:%02x.%x gpa 0x%"PRIx64 " hpa 0x%"PRIx64
+amdvi_completion_wait_fail(uint64_t addr) "error: fail to write at address 0x%"PRIx64
+amdvi_mmio_write(const char *reg, uint64_t addr, unsigned size, uint64_t val, unsigned long offset) "%s write addr 0x%"PRIx64 ", size %d, val 0x%"PRIx64 ", offset 0x%"PRIx64
+amdvi_mmio_read(const char *reg, uint64_t addr, unsigned size, uint64_t offset) "%s read addr 0x%"PRIx64", size %d offset 0x%"PRIx64
+amdvi_command_error(uint64_t status) "error: Executing commands with command buffer disabled 0x%"PRIx64
+amdvi_command_read_fail(uint64_t addr, uint32_t head) "error: fail to access memory at 0x%"PRIx64" + 0x%"PRIu32
+amdvi_command_exec(uint32_t head, uint32_t tail, uint64_t buf) "command buffer head at 0x%"PRIx32 " command buffer tail at 0x%"PRIx32" command buffer base at 0x%" PRIx64
+amdvi_unhandled_command(uint8_t type) "unhandled command %d"
+amdvi_intr_inval(void) "Interrupt table invalidated"
+amdvi_iotlb_inval(void) "IOTLB pages invalidated"
+amdvi_prefetch_pages(void) "Pre-fetch of AMD-Vi pages requested"
+amdvi_pages_inval(uint16_t domid) "AMD-Vi pages for domain 0x%"PRIx16 " invalidated"
+amdvi_all_inval(void) "Invalidation of all AMD-Vi cache requested "
+amdvi_ppr_exec(void) "Execution of PPR queue requested "
+amdvi_devtab_inval(uint16_t bus, uint16_t slot, uint16_t func) "device table entry for devid: %02x:%02x.%x invalidated"
+amdvi_completion_wait(uint64_t addr, uint64_t data) "completion wait requested with store address 0x%"PRIx64" and store data 0x%"PRIx64
+amdvi_control_status(uint64_t val) "MMIO_STATUS state 0x%"PRIx64
+amdvi_iotlb_reset(void) "IOTLB exceed size limit - reset "
+amdvi_completion_wait_exec(uint64_t addr, uint64_t data) "completion wait requested with store address 0x%"PRIx64" and store data 0x%"PRIx64
+amdvi_dte_get_fail(uint64_t addr, uint32_t offset) "error: failed to access Device Entry devtab 0x%"PRIx64" offset 0x%"PRIx32
+amdvi_invalid_dte(uint64_t addr) "PTE entry at 0x%"PRIx64" is invalid "
+amdvi_get_pte_hwerror(uint64_t addr) "hardware error eccessing PTE at addr 0x%"PRIx64
+amdvi_mode_invalid(unsigned level, uint64_t addr)"error: translation level 0x%"PRIu8" translating addr 0x%"PRIx64
+amdvi_page_fault(uint64_t addr) "error: page fault accessing guest physical address 0x%"PRIx64
+amdvi_iotlb_hit(uint16_t bus, uint16_t slot, uint16_t func, uint64_t addr, uint64_t txaddr) "hit iotlb devid %02x:%02x.%x gpa 0x%"PRIx64 " hpa 0x%"PRIx64
+amdvi_translation_result(uint16_t bus, uint16_t slot, uint16_t func, uint64_t addr, uint64_t txaddr) "devid: %02x:%02x.%x gpa 0x%"PRIx64 " hpa 0x%"PRIx64
Signature · 1 line
2.1.4
#3 lore raw

PATCH v13 3/4 hw/i386: Introduce AMD IOMMU

In reply to David Kiarie

Add AMD IOMMU emulaton to Qemu in addition to Intel IOMMU. The IOMMU does basic translation, error checking and has a minimal IOTLB implementation. This IOMMU bypassed the need for target aborts by responding with IOMMU_NONE access rights and exempts the region 0xfee00000-0xfeefffff from translation as it is the q35 interrupt region.

We advertise features that are not yet implemented to please the Linux IOMMU driver.

IOTLB aims at implementing commands on real IOMMUs which is essential for debugging and may not offer any performance benefits

---
 hw/i386/Makefile.objs |    1 +
 hw/i386/amd_iommu.c   | 1384 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/i386/amd_iommu.h   |  285 ++++++++++
 3 files changed, 1670 insertions(+)
 create mode 100644 hw/i386/amd_iommu.c
 create mode 100644 hw/i386/amd_iommu.h
hw/i386/Makefile.objs +1 -0
index b52d5b8..2f1a265 100644
@@ -3,6 +3,7 @@ obj-y += multiboot.o
 obj-y += pc.o pc_piix.o pc_q35.o
 obj-y += pc_sysfw.o
 obj-y += intel_iommu.o
+obj-y += amd_iommu.o
 obj-$(CONFIG_XEN) += ../xenpv/ xen/
 
 obj-y += kvmvapic.o
hw/i386/amd_iommu.c new file +1384 -0

1,384 lines not on this page · raw message

hw/i386/amd_iommu.h new file +285 -0

285 lines not on this page · raw message

Signature · 1 line
2.1.4
#4 lore raw

Re: [Qemu-devel] [V13 3/4] hw/i386: Introduce AMD IOMMU

Quoted 14 lines · On Fri, 8 Jul 2016 11:18:22 +0300 David Kiarie <[email protected]> wrote:

Add AMD IOMMU emulaton to Qemu in addition to Intel IOMMU. The IOMMU does basic translation, error checking and has a minimal IOTLB implementation. This IOMMU bypassed the need for target aborts by responding with IOMMU_NONE access rights and exempts the region 0xfee00000-0xfeefffff from translation as it is the q35 interrupt region.

We advertise features that are not yet implemented to please the Linux IOMMU driver.

IOTLB aims at implementing commands on real IOMMUs which is essential for debugging and may not offer any performance benefits

Quoted 8 lines
---
 hw/i386/Makefile.objs |    1 +
 hw/i386/amd_iommu.c   | 1384 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/i386/amd_iommu.h   |  285 ++++++++++
 3 files changed, 1670 insertions(+)
 create mode 100644 hw/i386/amd_iommu.c
 create mode 100644 hw/i386/amd_iommu.h

Hi,

Please consider an update or follow-on patch which adds something similar to:

commit 3cb3b1549f5401dc3a5e1d073e34063dc274136f

Author: Alex Williamson <[email protected]>
Date:   Thu Jun 30 13:00:24 2016 -0600

intel_iommu: Throw hw_error on notify_started

http://git.qemu.org/?p=qemu.git;a=commit;h=3cb3b1549f5401dc3a5e1d073e34063dc274136f

This would simply make amd_iommu incompatible with device assignment until someone tackles adding the proper code to support it. Thanks,

Alex

#5 lore raw

Re: [Qemu-devel] [V13 3/4] hw/i386: Introduce AMD IOMMU

Quoted 26 lines · Alex Williamson
Quoted 14 lines · On Fri, 8 Jul 2016 11:18:22 +0300 David Kiarie <[email protected]> wrote:

Add AMD IOMMU emulaton to Qemu in addition to Intel IOMMU. The IOMMU does basic translation, error checking and has a minimal IOTLB implementation. This IOMMU bypassed the need for target aborts by responding with IOMMU_NONE access rights and exempts the region 0xfee00000-0xfeefffff from translation as it is the q35 interrupt region.

We advertise features that are not yet implemented to please the Linux IOMMU driver.

IOTLB aims at implementing commands on real IOMMUs which is essential for debugging and may not offer any performance benefits

Quoted 8 lines
---
 hw/i386/Makefile.objs |    1 +
 hw/i386/amd_iommu.c   | 1384 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/i386/amd_iommu.h   |  285 ++++++++++
 3 files changed, 1670 insertions(+)
 create mode 100644 hw/i386/amd_iommu.c
 create mode 100644 hw/i386/amd_iommu.h
Quoted 1 line

Hi,

Hello,

Quoted 8 lines

Please consider an update or follow-on patch which adds something similar to:

commit 3cb3b1549f5401dc3a5e1d073e34063dc274136f

Author: Alex Williamson <[email protected]>
Date:   Thu Jun 30 13:00:24 2016 -0600
Quoted 6 lines

intel_iommu: Throw hw_error on notify_started

http://git.qemu.org/?p=qemu.git;a=commit;h=3cb3b1549f5401dc3a5e1d073e34063dc274136f

This would simply make amd_iommu incompatible with device assignment until someone tackles adding the proper code to support it. Thanks,

Thanks, this will be incorporated in the next series.

Quoted 2 lines

Alex