AMD IOMMU
v18 cover AMD IOMMU
Hi all,
This patchset adds basic AMD IOMMU emulation support to Qemu.
Changes since v17
-removed host dependent defines in bitfields and replaced that with 'extract64/extract32' [Peter, Michael]
Changes since v16 - this is mainly supposed to come as a ping :-)
-minor endian-ness fixes
Changes since v15
-Endian-ness issue fix
-cleaned up unused macros
-removed guest frame number(gfn) from cache entry
Changes 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.
[1] https://github.com/aslaq/qemu v18
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 | 1201 +++++++++++++++++++++++++++++++++++++++++++ hw/i386/amd_iommu.h | 289 +++++++++++ hw/i386/intel_iommu.c | 1 + hw/i386/trace-events | 29 ++ 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 | 3 + 11 files changed, 1611 insertions(+), 10 deletions(-) create mode 100644 hw/i386/amd_iommu.c create mode 100644 hw/i386/amd_iommu.h
Signature · 1 line
2.1.4
PATCH v18 1/4 hw/pci: Prepare for AMD IOMMU
Introduce PCI macros from for use by AMD IOMMU
--- include/hw/pci/pci.h | 3 +++ 1 file changed, 3 insertions(+)
include/hw/pci/pci.h +3 -0
@@ -13,9 +13,12 @@/* 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 v18 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
Re: [Qemu-devel] [V18 2/4] hw/i386/trace-events: Add AMD IOMMU trace events
Quoted 10 lines · David Kiarie
Signed-off-by David Kiarie <[email protected]>--- hw/i386/trace-events | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)hw/i386/trace-events +0
-0
hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) "0x%"PRIx64 · line 21
Quoted 9 lines
hw/i386/trace-events +6
-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
unsigned long offset should be printed with %0lx not PRIx64.
There are a bunch of other bugs I fixed silenty in this file, I don't remember where exactly pls go over and and fix all you can find.
Quoted 25 lines
hw/i386/trace-events +23
-0+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%"PRIx64Signature · 1 line
2.1.4
Re: [Qemu-devel] [V18 2/4] hw/i386/trace-events: Add AMD IOMMU trace events
Quoted 30 lines · Michael S. Tsirkin
hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr)
Quoted 10 lines · David Kiarie
Signed-off-by David Kiarie <[email protected]>--- hw/i386/trace-events | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)hw/i386/trace-events +0
-0@@ -13,3 +13,32 @@ mhp_pc_dimm_assigned_address(uint64_t addr)"0x%"PRIx64
hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) · line 14
Quoted 3 lines
hw/i386/trace-events +0
-0# 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/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) "0x%"PRIx64
Quoted 3 lines
hw/i386/trace-events +3
-0+ +# hw/i386/amd_iommu.c +amdvi_evntlog_fail(uint64_t addr, uint32_t head) "error: fail to writeat addr 0x%"PRIx64 " + offset 0x%"PRIx32
hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) · line 18
Quoted 1 line
hw/i386/trace-events +1
-0+amdvi_cache_update(uint16_t domid, uint32_t bus, uint32_t slot,
uint32_tfunc,uint64_tgpa,uint64_ttxaddr) " update iotlb domid 0x%"PRIx16" devid: %02x:%02x.%x gpa 0x%"PRIx64 " hpa 0x%"PRIx64hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) · line 19
Quoted 1 line
hw/i386/trace-events +1
-0+amdvi_completion_wait_fail(uint64_t addr) "error: fail to write ataddress 0x%"PRIx64
hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) · line 20
Quoted 1 line
hw/i386/trace-events +1
-0+amdvi_mmio_write(const char *reg, uint64_t addr, unsigned size,
uint64_tval, unsigned long offset) "%s write addr 0x%"PRIx64 ", size %d, val 0x%"PRIx64 ", offset 0x%"PRIx64
Quoted 7 lines
unsigned long offset should be printed with %0lx not PRIx64.
There are a bunch of other bugs I fixed silenty in this file, I don't remember where exactly pls go over and and fix all you can find.
Separately resending this patch in the meantime just in case the rest of the patchset happens not to have any more issues.
Quoted 44 lines
hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) · line 21
Quoted 2 lines
hw/i386/trace-events +1
-0+amdvi_mmio_read(const char *reg, uint64_t addr, unsigned size, uint64_toffset) "%s read addr 0x%"PRIx64", size %d offset 0x%"PRIx64
hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) · line 22
Quoted 1 line
hw/i386/trace-events +1
-0+amdvi_command_error(uint64_t status) "error: Executing commands withcommand buffer disabled 0x%"PRIx64
hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) · line 23
Quoted 1 line
hw/i386/trace-events +1
-0+amdvi_command_read_fail(uint64_t addr, uint32_t head) "error: fail toaccess memory at 0x%"PRIx64" + 0x%"PRIu32
hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) · line 24
Quoted 1 line
hw/i386/trace-events +1
-0+amdvi_command_exec(uint32_t head, uint32_t tail, uint64_t buf) "commandbuffer head at 0x%"PRIx32 " command buffer tail at 0x%"PRIx32" command buffer base at 0x%" PRIx64
hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) "0x%"PRIx64
Quoted 5 lines
hw/i386/trace-events +5
-0+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"
hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) "0x%"PRIx64
Quoted 3 lines
hw/i386/trace-events +3
-0+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) "devicetable entry for devid: %02x:%02x.%x invalidated"
hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) · line 33
Quoted 1 line
hw/i386/trace-events +1
-0+amdvi_completion_wait(uint64_t addr, uint64_t data) "completion waitrequested with store address 0x%"PRIx64" and store data 0x%"PRIx64
hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) "0x%"PRIx64
Quoted 3 lines
hw/i386/trace-events +3
-0+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) "completionwait requested with store address 0x%"PRIx64" and store data 0x%"PRIx64
hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) · line 37
Quoted 1 line
hw/i386/trace-events +1
-0+amdvi_dte_get_fail(uint64_t addr, uint32_t offset) "error: failed toaccess Device Entry devtab 0x%"PRIx64" offset 0x%"PRIx32
hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) · line 39
Quoted 2 lines
hw/i386/trace-events +2
-0+amdvi_invalid_dte(uint64_t addr) "PTE entry at 0x%"PRIx64" is invalid " +amdvi_get_pte_hwerror(uint64_t addr) "hardware error eccessing PTE ataddr 0x%"PRIx64
hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) · line 40
Quoted 1 line
hw/i386/trace-events +1
-0+amdvi_mode_invalid(unsigned level, uint64_t addr)"error: translationlevel 0x%"PRIu8" translating addr 0x%"PRIx64
hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) · line 41
Quoted 1 line
hw/i386/trace-events +1
-0+amdvi_page_fault(uint64_t addr) "error: page fault accessing guestphysical address 0x%"PRIx64
hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) · line 42
Quoted 1 line
hw/i386/trace-events +1
-0+amdvi_iotlb_hit(uint16_t bus, uint16_t slot, uint16_t func, uint64_taddr,
uint64_ttxaddr) "hit iotlb devid %02x:%02x.%x gpa 0x%"PRIx64 " hpa 0x%"PRIx64hw/i386/trace-events mhp_pc_dimm_assigned_address(uint64_t addr) · line 43
Quoted 1 line
hw/i386/trace-events +1
-0+amdvi_translation_result(uint16_t bus, uint16_t slot, uint16_t func,
uint64_taddr,uint64_ttxaddr) "devid: %02x:%02x.%x gpa 0x%"PRIx64 " hpa 0x%"PRIx64Quoted 2 lines
hw/i386/trace-events +0
-1--2.1.4
Re: [Qemu-devel] [V18 2/4] hw/i386/trace-events: Add AMD IOMMU trace events
Quoted 71 lines · David Kiarie
On Tue, Sep 20, 2016 at 3:09 AM, Michael S. Tsirkin <[email protected]> wrote:
On Tue, Sep 20, 2016 at 03:05:02AM +0300, David Kiarie wrote: > Signed-off-by: David Kiarie <[email protected]> > --- > hw/i386/trace-events | 29 +++++++++++++++++++++++++++++ > 1 file changed, 29 insertions(+) > > diff --git a/hw/i386/trace-events b/hw/i386/trace-events > index 5b99eba..ddeda02 100644 > --- a/hw/i386/trace-events > +++ b/hw/i386/trace-events > @@ -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 unsigned long offset should be printed with %0lx not PRIx64. There are a bunch of other bugs I fixed silenty in this file, I don't remember where exactly pls go over and and fix all you can find.Separately resending this patch in the meantime just in case the rest of the patchset happens not to have any more issues.
Quoted 1 line
+amdvi_mmio_read(const char *reg,
uint64_taddr, unsigned size,uint64_toffset) "%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_thead) "error: fail to access memory at 0x%"PRIx64" + 0x%"PRIu32
> +amdvi_command_exec(uint32_t head,uint32_ttail,uint64_tbuf) "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_tslot,uint16_tfunc) "device table entry for devid: %02x:%02x.%x invalidated"
> +amdvi_completion_wait(uint64_t addr,uint64_tdata) "completion wait requested with store address 0x%"PRIx64" and store data 0x%"PRIx64 > +amdvi_control_status(uint64_t val) "MMIO_STATUSstate 0x%"PRIx64 > +amdvi_iotlb_reset(void) "IOTLB exceed size limit - reset " > +amdvi_completion_wait_exec(uint64_t addr,uint64_tdata) "completion
Quoted 8 lines
wait requested with store address 0x%"PRIx64" and store data 0x%"PRIx64 > +amdvi_dte_get_fail(uint64_t addr,
uint32_toffset) "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_taddr)"error: translation level 0x%"PRIu8" translating addr 0x%"PRIx64
This is also wrong. Can you pls go over the traces? Also, you can check Peter Maydell's rejects of the pulls that included these patches.
Quoted 12 lines
Quoted 1 line
+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 > -- > 2.1.4
Re: [Qemu-devel] [V18 2/4] hw/i386/trace-events: Add AMD IOMMU trace events
Quoted 43 lines · Michael S. Tsirkin
Quoted 3 lines · David Kiarie
On Tue, Sep 20, 2016 at 3:09 AM, Michael S. Tsirkin <[email protected]>
Quoted 16 lines · wrote:
On Tue, Sep 20, 2016 at 03:05:02AM +0300, David Kiarie wrote: > Signed-off-by: David Kiarie <[email protected]> > --- > hw/i386/trace-events | 29 +++++++++++++++++++++++++++++ > 1 file changed, 29 insertions(+) > > diff --git a/hw/i386/trace-events b/hw/i386/trace-events > index 5b99eba..ddeda02 100644 > --- a/hw/i386/trace-events > +++ b/hw/i386/trace-events > @@ -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
Quoted 4 lines
IEC invalidation: global=%d index=%" PRIu32 " mask=%" PRIu32 > +
> +#hw/i386/amd_iommu.c
> +amdvi_evntlog_fail(uint64_t addr,uint32_thead) "error: fail towrite
Quoted 2 lines
at addr 0x%"PRIx64 " + offset 0x%"PRIx32 > +amdvi_cache_update(uint16_t domid, uint32_t bus, uint32_t slot,
uint32_tQuoted 3 lines
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 writeat
Quoted 2 lines
address 0x%"PRIx64
> +amdvi_mmio_write(const char *reg,uint64_taddr, unsigned size,
uint64_tQuoted 6 lines
val, unsigned long offset) "%s write addr 0x%"PRIx64 ", size %d, val 0x%"PRIx64 ", offset 0x%"PRIx64 unsigned long offset should be printed with %0lx not PRIx64.
Quoted 12 lines
Quoted 7 lines
There are a bunch of other bugs I fixed silenty in this file, I don't remember where exactly pls go over and and fix all you can find.
Separately resending this patch in the meantime just in case the rest of
the
Quoted 3 lines
patchset happens not to have any more issues.
Hi Michael,
Quoted 41 lines
Quoted 1 line
+amdvi_mmio_read(const char *reg,
uint64_taddr, unsigned size,
uint64_tQuoted 2 lines
offset) "%s read addr 0x%"PRIx64", size %d offset 0x%"PRIx64 > +amdvi_command_error(uint64_t status) "error: Executing commands
with
Quoted 2 lines
command buffer disabled 0x%"PRIx64
> +amdvi_command_read_fail(uint64_t addr,uint32_thead) "error:fail to
Quoted 2 lines
access memory at 0x%"PRIx64" + 0x%"PRIu32 > +amdvi_command_exec(uint32_t head, uint32_t tail, uint64_t buf)"command
Quoted 1 line
buffer head at 0x%"PRIx32 " command buffer tail at 0x%"PRIx32"command
Quoted 6 lines
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 domain0x%"PRIx16 "
Quoted 2 lines
invalidated"
> +amdvi_all_inval(void) "Invalidation of all AMD-Vi cache requested"
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+amdvi_ppr_exec(void) "Execution of PPR queue requested " +amdvi_devtab_inval(uint16_t bus, uint16_t slot, uint16_t func)"device
Quoted 2 lines
table entry for devid: %02x:%02x.%x invalidated"
> +amdvi_completion_wait(uint64_t addr,uint64_tdata) "completionwait
Quoted 4 lines
requested with store address 0x%"PRIx64" and store data 0x%"PRIx64 > +amdvi_control_status(uint64_t val) "
MMIO_STATUSstate 0x%"PRIx64 > +amdvi_iotlb_reset(void) "IOTLB exceed size limit - reset " > +amdvi_completion_wait_exec(uint64_t addr,uint64_tdata)"completion
Quoted 1 line
wait requested with store address 0x%"PRIx64" and store data0x%"PRIx64
Quoted 1 line
Quoted 1 line
+amdvi_dte_get_fail(uint64_t addr,
uint32_toffset) "error: failedto
Quoted 2 lines
access Device Entry devtab 0x%"PRIx64" offset 0x%"PRIx32 > +amdvi_invalid_dte(uint64_t addr) "PTE entry at 0x%"PRIx64" isinvalid "
Quoted 9 lines
Quoted 1 line
Quoted 1 line
+amdvi_get_pte_hwerror(uint64_t addr) "hardware error eccessing
PTE at
Quoted 2 lines
addr 0x%"PRIx64
> +amdvi_mode_invalid(unsigned level,uint64_taddr)"error:translation
Quoted 1 line
level 0x%"PRIu8" translating addr 0x%"PRIx64This is also wrong. Can you pls go over the traces?
I think you might be looking the wrong patch here.
Quoted 2 lines
Also, you can check Peter Maydell's rejects of the pulls that included these patches.
I did look at the reject. The initial code wasn't actually broken but that discussion wasn't really relevant since 'extract64/extract32' is more decent.
Quoted 17 lines
Quoted 3 lines
Quoted 1 line
+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_tQuoted 1 line
addr, uint64_t txaddr) "hit iotlb devid %02x:%02x.%x gpa 0x%"PRIx64" hpa
Quoted 2 lines
0x%"PRIx64
> +amdvi_translation_result(uint16_t bus,uint16_tslot,uint16_tfunc,
Quoted 1 line
uint64_t addr, uint64_t txaddr) "devid: %02x:%02x.%x gpa 0x%"PRIx64" hpa
Quoted 5 lines
0x%"PRIx64 > -- > 2.1.4
Re: [Qemu-devel] [V18 2/4] hw/i386/trace-events: Add AMD IOMMU trace events
Quoted 8 lines · David Kiarie
Quoted 1 line
> +amdvi_mode_invalid(unsigned level,
uint64_taddr)"error:translation
> level 0x%"PRIu8" translating addr 0x%"PRIx64This is also wrong. Can you pls go over the traces?
I think you might be looking the wrong patch here.
OK, must be the HTML in your mail messing things up. Please post plain-text patches and I'll review.
Quoted 7 lines
Also, you can check Peter Maydell's rejects of the pulls that included these patches.
I did look at the reject. The initial code wasn't actually broken but that discussion wasn't really relevant since 'extract64/extract32' is more decent.
There were some failures around traces too though. Pls check them out.
Signature · 1 line
MST
PATCH v18 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, uint8_t bus, uint8_t slot, uint8_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, uint64_t offset) "%s write addr 0x%"PRIx64", size %u, 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 %u 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%"PRIx32 +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 0x%"PRIx8 +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(uint8_t bus, uint8_t slot, uint8_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(uint8_t level, uint64_t addr)"error: translation level 0x%"PRIx8" translating addr 0x%"PRIx64 +amdvi_page_fault(uint64_t addr) "error: page fault accessing guest physical address 0x%"PRIx64 +amdvi_iotlb_hit(uint8_t bus, uint8_t slot, uint8_t func, uint64_t addr, uint64_t txaddr) "hit iotlb devid %02x:%02x.%x gpa 0x%"PRIx64" hpa 0x%"PRIx64 +amdvi_translation_result(uint8_t bus, uint8_t slot, uint8_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 v18 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 | 1199 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/amd_iommu.h | 289 ++++++++++++ 3 files changed, 1489 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 +1199 -0
1,199 lines not on this page · raw message
hw/i386/amd_iommu.h new file +289 -0
289 lines not on this page · raw message
Signature · 1 line
2.1.4