AMD IOMMU
v15 cover AMD IOMMU
Hi all,
This patchset adds basic AMD IOMMU emulation support to Qemu.
Change since v14
-MMIO register reading/write bug fix [Peter]
-Endian-ness issue fix[Peter]
-Bitfields layouts in IOMMU commands fix[Peter]
-IVRS changed IVHD device entry from type 3 to 1 to save a few bytes -coding style issues, comment grammer and other miscellaneous fixes.
Changes since v13
-Added an error to make AMD IOMMU incompatible with device assignment.[Alex] -Converted AMD IOMMU into a composite PCI and System Bus device. This helps with:
-We can now inherit from X86 IOMMU base class(which is implemented as a System Bus device). -We can now reserve MMIO region for IOMMU without a BAR register and without a hack.
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 | 76 ++- hw/i386/amd_iommu.c | 1401 +++++++++++++++++++++++++++++++++++++++++++ hw/i386/amd_iommu.h | 390 ++++++++++++ hw/i386/intel_iommu.c | 1 + hw/i386/trace-events | 36 ++ hw/i386/x86-iommu.c | 6 + include/hw/acpi/aml-build.h | 1 + include/hw/i386/x86-iommu.h | 12 + include/hw/pci/pci.h | 4 +- 11 files changed, 1919 insertions(+), 11 deletions(-) create mode 100644 hw/i386/amd_iommu.c create mode 100644 hw/i386/amd_iommu.h
Signature · 1 line
2.1.4
PATCH v15 1/4 hw/pci: Prepare for AMD IOMMU
Introduce PCI macros from for use by AMD IOMMU
--- include/hw/pci/pci.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/hw/pci/pci.h +3 -1
@@ -11,11 +11,13 @@#include "hw/pci/pcie.h" /* PCI bus */ -#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
PATCH v15 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
@@ -13,3 +13,32 @@ mhp_pc_dimm_assigned_address(uint64_t addr) "0x%"PRIx64 # hw/i386/x86-iommu.c x86_iommu_iec_notify(bool global, uint32_t index, uint32_t mask) "Notify IEC invalidation: global=%d index=%" PRIu32 " mask=%" PRIu32 + +# 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
PATCH v15 3/4 hw/i386: Introduce AMD IOMMU
In reply to David KiarieAdd 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 | 1399 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/amd_iommu.h | 390 ++++++++++++++ hw/i386/trace-events | 7 + 4 files changed, 1797 insertions(+) create mode 100644 hw/i386/amd_iommu.c create mode 100644 hw/i386/amd_iommu.h
hw/i386/Makefile.objs +1 -0
@@ -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 += x86-iommu.o intel_iommu.o +obj-y += amd_iommu.o obj-$(CONFIG_XEN) += ../xenpv/ xen/ obj-y += kvmvapic.o
hw/i386/amd_iommu.c new file +1399 -0
1,399 lines not on this page · raw message
hw/i386/amd_iommu.h new file +390 -0
390 lines not on this page · raw message
hw/i386/trace-events +7 -0
@@ -42,3 +42,10 @@ amdvi_mode_invalid(unsigned level, uint64_t addr)"error: translation level 0x%"P 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 +amdvi_irte_get_fail(uint64_t addr, uint64_t offset) "couldn't access device table entry 0x%"PRIx64" + offset 0x%"PRIx64 +amdvi_invalid_irte_entry(uint16_t devid, uint64_t offset) "devid %x requested IRTE offset 0x%"PRIx64" Outside IR table range" +amdvi_ir_request(uint32_t data, uint64_t addr, uint16_t sid) "IR request data 0x%"PRIx32" address 0x%"PRIx64" SID %x" +amdvi_ir_remap(uint32_t data, uint64_t addr, uint16_t sid) "IR remap data 0x%"PRIx32" address 0x%"PRIx64" SID %x" +amdvi_ir_target_abort(uint32_t data, uint64_t addr, uint16_t sid) "IR target abort data 0x%"PRIx32" address 0x%"PRIx64" SID %x" +amdvi_ir_write_fail(uint64_t addr, uint32_t data) "fail to write to addr 0x%"PRIx64 " value 0x%"PRIx32 +amdvi_ir_read_fail(uint64_t addr) " fail to read from addr 0x%"PRIx64
Signature · 1 line
2.1.4
Quoted 9 lines · David Kiarie
Hi all,
This patchset adds basic AMD IOMMU emulation support to Qemu.
Change since v14
-MMIO register reading/write bug fix [Peter] -Endian-ness issue fix[Peter] -Bitfields layouts in IOMMU commands fix[Peter]
I seem to have left out a few of this.
-IVRS changed IVHD device entry from type 3 to 1 to save a few bytes
Quoted 88 lines
-coding style issues, comment grammer and other miscellaneous fixes.
Changes since v13
-Added an error to make AMD IOMMU incompatible with device
assignment.[Alex]
-Converted AMD IOMMU into a composite PCI and System Bus device. This
helps with:
-We can now inherit from X86 IOMMU base class(which is implemented
as a System Bus device).
-We can now reserve MMIO region for IOMMU without a BAR register and
without a hack.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 toAMD_IOMMUhas 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 tablehw/acpi/aml-build.c | 2 +- hw/i386/Makefile.objs | 1 + hw/i386/acpi-build.c | 76 ++- hw/i386/amd_iommu.c | 1401 ++++++++++++++++++++++++++++++ +++++++++++++ hw/i386/amd_iommu.h | 390 ++++++++++++ hw/i386/intel_iommu.c | 1 + hw/i386/trace-events | 36 ++ hw/i386/x86-iommu.c | 6 + include/hw/acpi/aml-build.h | 1 + include/hw/i386/x86-iommu.h | 12 + include/hw/pci/pci.h | 4 +- 11 files changed, 1919 insertions(+), 11 deletions(-) create mode 100644 hw/i386/amd_iommu.c create mode 100644 hw/i386/amd_iommu.h--
2.1.4