Skip to contentSkip to conversation

AMD IOMMU

PATCH Superseded David Kiarie 6 participants 14 messages Apr 24, 2016 – May 4, 2016

v9 of 19 Superseded Latest is v19 →

lore
Share & tools
lore
#0 lore raw

v9 cover AMD IOMMU

Hi all,

The current AMD IOMMU patches that fixes Igor's comments. I got rid of structs and instead added individual integer fields into the table data directly, as suggested.

I have also got rid of some un-used macros and fixed a few other miscellaneous things.

David Kiarie (4):
hw/i386: Introduce AMD IOMMU
hw/i386: ACPI table for AMD IOMMU
hw/core: Add AMD IOMMU to machine properties
hw/pci-host: Emulate AMD IOMMU

 hw/acpi/aml-build.c           |    2 +-
 hw/acpi/core.c                |   13 -
 hw/core/machine.c             |   32 +-
 hw/i386/Makefile.objs         |    1 +
 hw/i386/acpi-build.c          |  101 ++-
 hw/i386/amd_iommu.c           | 1426 +++++++++++++++++++++++++++++++++++++++++
 hw/i386/amd_iommu.h           |  398 ++++++++++++
 hw/pci-host/q35.c             |   21 +-
 include/hw/acpi/acpi-defs.h   |   14 +
 include/hw/acpi/acpi.h        |   16 +
 include/hw/acpi/aml-build.h   |    1 +
 include/hw/boards.h           |    1 +
 include/hw/i386/intel_iommu.h |    1 +
 include/hw/pci/pci.h          |    2 +
 qemu-options.hx               |    7 +-
 util/qemu-config.c            |    8 +-
 16 files changed, 2010 insertions(+), 34 deletions(-)
 create mode 100644 hw/i386/amd_iommu.c
 create mode 100644 hw/i386/amd_iommu.h
Signature · 1 line
2.1.4
#2 lore raw

PATCH v9 2/4 hw/i386: ACPI table for AMD IOMMU

Add IVRS table for AMD IOMMU. Generate IVRS or DMAR depending on emulated IOMMU

---
 hw/acpi/aml-build.c         |   2 +-
 hw/acpi/core.c              |  13 ------
 hw/i386/acpi-build.c        | 101 +++++++++++++++++++++++++++++++++++++++-----
 include/hw/acpi/acpi-defs.h |  14 ++++++
 include/hw/acpi/acpi.h      |  16 +++++++
 include/hw/acpi/aml-build.h |   1 +
 6 files changed, 122 insertions(+), 25 deletions(-)
hw/acpi/aml-build.c +1 -1
index ab89ca6..da11bf8 100644
@@ -227,7 +227,7 @@ static void build_extop_package(GArray *package, uint8_t op)
     build_prepend_byte(package, 0x5B); /* ExtOpPrefix */
 }
 
-static void build_append_int_noprefix(GArray *table, uint64_t value, int size)
+void build_append_int_noprefix(GArray *table, uint64_t value, int size)
 {
     int i;
 
hw/acpi/core.c +0 -13
index 7925a1a..ee0e687 100644
@@ -29,19 +29,6 @@
 #include "qapi-visit.h"
 #include "qapi-event.h"
 
-struct acpi_table_header {
-    uint16_t _length;         /* our length, not actual part of the hdr */
-                              /* allows easier parsing for fw_cfg clients */
-    char sig[4];              /* ACPI signature (4 ASCII characters) */
-    uint32_t length;          /* Length of table, in bytes, including header */
-    uint8_t revision;         /* ACPI Specification minor version # */
-    uint8_t checksum;         /* To make sum of entire table == 0 */
-    char oem_id[6];           /* OEM identification */
-    char oem_table_id[8];     /* OEM table identification */
-    uint32_t oem_revision;    /* OEM revision number */
-    char asl_compiler_id[4];  /* ASL compiler vendor ID */
-    uint32_t asl_compiler_revision; /* ASL compiler revision number */
-} QEMU_PACKED;
 
 #define ACPI_TABLE_HDR_SIZE sizeof(struct acpi_table_header)
 #define ACPI_TABLE_PFX_SIZE sizeof(uint16_t)  /* size of the extra prefix */
hw/i386/acpi-build.c +90 -11

137 lines not on this page · raw message

include/hw/acpi/acpi-defs.h +14 -0
index c7a03d4..114227a 100644
@@ -570,4 +570,18 @@ typedef struct AcpiDmarHardwareUnit AcpiDmarHardwareUnit;
 /* Masks for Flags field above */
 #define ACPI_DMAR_INCLUDE_PCI_ALL   1
 
+/* IVRS constants */
+#define AMD_IOMMU_HOST_ADDRESS_WIDTH 39UL
+
+/* flags in the IVHD headers */
+#define IVHD_HT_TUNEN    (1UL << 0)
+#define IVHD_IOTLBSUP    (1UL << 4)
+#define IVHD_PREFSUP     (1UL << 6)
+#define IVHD_PPRSUP      (1UL << 7)
+
+/* features in the IVHD headers */
+#define IVHD_EFR_HATS       48
+#define IVHD_EFR_GATS       48
+#define IVHD_EFR_GTSUP  (1UL << 2)
+
 #endif
include/hw/acpi/acpi.h +16 -0
index e0978c8..a708b84 100644
@@ -201,4 +201,20 @@ struct AcpiSlicOem {
 };
 int acpi_get_slic_oem(AcpiSlicOem *oem);
 
+struct acpi_table_header {
+    uint16_t _length;         /* our length, not actual part of the hdr */
+                              /* allows easier parsing for fw_cfg clients */
+    char sig[4];              /* ACPI signature (4 ASCII characters) */
+    uint32_t length;          /* Length of table, in bytes, including header */
+    uint8_t revision;         /* ACPI Specification minor version # */
+    uint8_t checksum;         /* To make sum of entire table == 0 */
+    char oem_id[6];           /* OEM identification */
+    char oem_table_id[8];     /* OEM table identification */
+    uint32_t oem_revision;    /* OEM revision number */
+    char asl_compiler_id[4];  /* ASL compiler vendor ID */
+    uint32_t asl_compiler_revision; /* ASL compiler revision number */
+} QEMU_PACKED;
+
+typedef struct acpi_table_header acpi_table_header;
+
 #endif /* !QEMU_HW_ACPI_H */
include/hw/acpi/aml-build.h +1 -0
index 2c994b3..d25e9a5 100644
@@ -355,6 +355,7 @@ Aml *aml_derefof(Aml *arg);
 Aml *aml_sizeof(Aml *arg);
 Aml *aml_concatenate(Aml *source1, Aml *source2, Aml *target);
 
+void build_append_int_noprefix(GArray *table, uint64_t value, int size);
 void
 build_header(GArray *linker, GArray *table_data,
              AcpiTableHeader *h, const char *sig, int len, uint8_t rev,
Signature · 1 line
2.1.4
#7 lore raw

PATCH v9 3/4 hw/core: Add AMD IOMMU to machine properties

In reply to David Kiarie

Added a bool, subject to review to machine properties which it used to override iommu emulated from Intel to AMD.

---
 hw/core/machine.c             | 32 +++++++++++++++++++++++++++++---
 include/hw/boards.h           |  1 +
 include/hw/i386/intel_iommu.h |  1 +
 qemu-options.hx               |  7 +++++--
 util/qemu-config.c            |  8 ++++++--
 5 files changed, 42 insertions(+), 7 deletions(-)
hw/core/machine.c +29 -3
index 6dbbc85..792641b 100644
@@ -15,6 +15,8 @@
 #include "qapi/error.h"
 #include "qapi-visit.h"
 #include "qapi/visitor.h"
+#include "hw/i386/amd_iommu.h"
+#include "hw/i386/intel_iommu.h"
 #include "hw/sysbus.h"
 #include "sysemu/sysemu.h"
 #include "qemu/error-report.h"
@@ -300,6 +302,26 @@ static void machine_set_iommu(Object *obj, bool value, Error **errp)
     ms->iommu = value;
 }
 
+static void machine_set_iommu_override(Object *obj, const char *value,
+                                       Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+    Error *err = NULL;
+
+    ms->x_iommu_type = false;
+    /* ensure a valid iommu type */
+    if (g_strcmp0(value, AMD_IOMMU_STR) &&
+            g_strcmp0(value, INTEL_IOMMU_STR)) {
+        error_setg(errp, "Invalid IOMMU type %s", value);
+        error_propagate(errp, err);
+        return;
+    }
+
+    if ((g_strcmp0(value, AMD_IOMMU_STR) == 0)) {
+        ms->x_iommu_type = true;
+    }
+}
+
 static void machine_set_suppress_vmdesc(Object *obj, bool value, Error **errp)
 {
     MachineState *ms = MACHINE(obj);
@@ -473,10 +495,14 @@ static void machine_initfn(Object *obj)
                                     "Firmware image",
                                     NULL);
     object_property_add_bool(obj, "iommu",
-                             machine_get_iommu,
-                             machine_set_iommu, NULL);
+                             machine_get_iommu, machine_set_iommu, NULL);
     object_property_set_description(obj, "iommu",
-                                    "Set on/off to enable/disable Intel IOMMU (VT-d)",
+                                    "Set on to enable IOMMU emulation",
+                                    NULL);
+    object_property_add_str(obj, "x-iommu-type",
+                            NULL, machine_set_iommu_override, NULL);
+    object_property_set_description(obj, "x-iommu-type",
+                                    "Set on to override emulated IOMMU to AMD IOMMU",
                                     NULL);
     object_property_add_bool(obj, "suppress-vmdesc",
                              machine_get_suppress_vmdesc,
include/hw/boards.h +1 -0
index 8d4fe56..5a12a1c 100644
@@ -152,6 +152,7 @@ struct MachineState {
     bool igd_gfx_passthru;
     char *firmware;
     bool iommu;
+    bool x_iommu_type;
     bool suppress_vmdesc;
     bool enforce_config_section;
 
include/hw/i386/intel_iommu.h +1 -0
index b024ffa..7e511e1 100644
@@ -24,6 +24,7 @@
 #include "hw/qdev.h"
 #include "sysemu/dma.h"
 
+#define INTEL_IOMMU_STR "intel"
 #define TYPE_INTEL_IOMMU_DEVICE "intel-iommu"
 #define INTEL_IOMMU_DEVICE(obj) \
      OBJECT_CHECK(IntelIOMMUState, (obj), TYPE_INTEL_IOMMU_DEVICE)
qemu-options.hx +5 -2
index 6106520..81217d3 100644
@@ -38,7 +38,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
     "                kvm_shadow_mem=size of KVM shadow MMU\n"
     "                dump-guest-core=on|off include guest memory in a core dump (default=on)\n"
     "                mem-merge=on|off controls memory merge support (default: on)\n"
-    "                iommu=on|off controls emulated Intel IOMMU (VT-d) support (default=off)\n"
+    "                iommu=on|off controls emulated IOMMU support(default: off)\n"
+    "                x-iommu-type=amd|intel overrides emulated IOMMU to AMD IOMMU (default: intel)\n"
     "                igd-passthru=on|off controls IGD GFX passthrough support (default=off)\n"
     "                aes-key-wrap=on|off controls support for AES key wrapping (default=on)\n"
     "                dea-key-wrap=on|off controls support for DEA key wrapping (default=on)\n"
@@ -74,7 +75,9 @@ Enables or disables memory merge support. This feature, when supported by
 the host, de-duplicates identical memory pages among VMs instances
 (enabled by default).
 @item iommu=on|off
-Enables or disables emulated Intel IOMMU (VT-d) support. The default is off.
+Enables and disables IOMMU emulation. The default is off.
+@item x-iommu-type=on|off
+Overrides emulated IOMMU from AMD IOMMU. By default Intel IOMMU is emulated.
 @item aes-key-wrap=on|off
 Enables or disables AES key wrapping support on s390-ccw hosts. This feature
 controls whether AES wrapping keys will be created to allow
util/qemu-config.c +6 -2
index fb97307..8886abf 100644
@@ -213,8 +213,12 @@ static QemuOptsList machine_opts = {
             .help = "firmware image",
         },{
             .name = "iommu",
-            .type = QEMU_OPT_BOOL,
-            .help = "Set on/off to enable/disable Intel IOMMU (VT-d)",
+            .type =  QEMU_OPT_BOOL,
+            .help = "Set on/off to enable iommu",
+        },{
+            .name = "x-iommu-type",
+            .type =  QEMU_OPT_STRING,
+            .help = "Overrides emulated IOMMU from Intel to AMD",
         },{
             .name = "suppress-vmdesc",
             .type = QEMU_OPT_BOOL,
Signature · 1 line
2.1.4
#9 lore raw

PATCH v9 4/4 hw/pci-host: Emulate AMD IOMMU

In reply to David Kiarie

Add AMD IOMMU emulation support to q35 chipset

---
 hw/pci-host/q35.c             | 21 +++++++++++++++++++--
 include/hw/i386/intel_iommu.h |  2 +-
 2 files changed, 20 insertions(+), 3 deletions(-)
hw/pci-host/q35.c +19 -2
index 70f897e..37f8a84 100644
@@ -32,6 +32,7 @@
 #include "hw/pci-host/q35.h"
 #include "qapi/error.h"
 #include "qapi/visitor.h"
+#include "hw/i386/amd_iommu.h"
 
 /****************************************************************************
  * Q35 host
@@ -448,6 +449,19 @@ static void mch_init_dmar(MCHPCIState *mch)
     pci_setup_iommu(pci_bus, q35_host_dma_iommu, mch->iommu);
 }
 
+static void mch_init_amdvi(MCHPCIState *mch)
+{
+    AMDIOMMUState *iommu_state;
+    PCIBus *bus = PCI_BUS(qdev_get_parent_bus(DEVICE(mch)));
+    PCIDevice *iommu;
+
+    iommu = pci_create_simple(bus, 0x20, TYPE_AMD_IOMMU_DEVICE);
+
+    iommu_state = AMD_IOMMU_DEVICE(iommu);
+
+    pci_setup_iommu(bus, bridge_host_amd_iommu, iommu_state);
+}
+
 static void mch_realize(PCIDevice *d, Error **errp)
 {
     int i;
@@ -506,8 +520,11 @@ static void mch_realize(PCIDevice *d, Error **errp)
                  mch->pci_address_space, &mch->pam_regions[i+1],
                  PAM_EXPAN_BASE + i * PAM_EXPAN_SIZE, PAM_EXPAN_SIZE);
     }
-    /* Intel IOMMU (VT-d) */
-    if (object_property_get_bool(qdev_get_machine(), "iommu", NULL)) {
+
+    if (object_property_get_bool(qdev_get_machine(), "iommu", NULL) &&
+        MACHINE(qdev_get_machine())->x_iommu_type) {
+        mch_init_amdvi(mch);
+    } else if (object_property_get_bool(qdev_get_machine(), "iommu", NULL)) {
         mch_init_dmar(mch);
     }
 }
include/hw/i386/intel_iommu.h +1 -1
index 7e511e1..539530c 100644
@@ -24,10 +24,10 @@
 #include "hw/qdev.h"
 #include "sysemu/dma.h"
 
-#define INTEL_IOMMU_STR "intel"
 #define TYPE_INTEL_IOMMU_DEVICE "intel-iommu"
 #define INTEL_IOMMU_DEVICE(obj) \
      OBJECT_CHECK(IntelIOMMUState, (obj), TYPE_INTEL_IOMMU_DEVICE)
+#define INTEL_IOMMU_STR "intel"
 
 /* DMAR Hardware Unit Definition address (IOMMU unit) */
 #define Q35_HOST_BRIDGE_IOMMU_ADDR  0xfed90000ULL
Signature · 1 line
2.1.4
#1 lore raw

PATCH v9 1/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

---
 hw/i386/Makefile.objs |    1 +
 hw/i386/amd_iommu.c   | 1426 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/i386/amd_iommu.h   |  398 ++++++++++++++
 include/hw/pci/pci.h  |    2 +
 4 files changed, 1827 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 +1426 -0

1,426 lines not on this page · raw message

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

398 lines not on this page · raw message

include/hw/pci/pci.h +2 -0
index ef6ba51..266cd7e 100644
@@ -12,6 +12,8 @@
 
 /* PCI bus */
 
+#define PCI_BUS_NUM(x)          (((x) >> 8) & 0xff)
+#define PCI_DEVID(bus, devfn)   ((((uint16_t)(bus)) << 8) | (devfn))
 #define PCI_DEVFN(slot, func)   ((((slot) & 0x1f) << 3) | ((func) & 0x07))
 #define PCI_SLOT(devfn)         (((devfn) >> 3) & 0x1f)
 #define PCI_FUNC(devfn)         ((devfn) & 0x07)
Signature · 1 line
2.1.4
#11 lore raw
In reply to David Kiarie

Sorry, I keep missing Jan's email...

Quoted 36 lines · David Kiarie

Hi all,

The current AMD IOMMU patches that fixes Igor's comments. I got rid of structs and instead added individual integer fields into the table data directly, as suggested.

I have also got rid of some un-used macros and fixed a few other miscellaneous things.

David Kiarie (4):
hw/i386: Introduce AMD IOMMU
hw/i386: ACPI table for AMD IOMMU
hw/core: Add AMD IOMMU to machine properties
hw/pci-host: Emulate AMD IOMMU

 hw/acpi/aml-build.c           |    2 +-
 hw/acpi/core.c                |   13 -
 hw/core/machine.c             |   32 +-
 hw/i386/Makefile.objs         |    1 +
 hw/i386/acpi-build.c          |  101 ++-
 hw/i386/amd_iommu.c           | 1426 +++++++++++++++++++++++++++++++++++++++++
 hw/i386/amd_iommu.h           |  398 ++++++++++++
 hw/pci-host/q35.c             |   21 +-
 include/hw/acpi/acpi-defs.h   |   14 +
 include/hw/acpi/acpi.h        |   16 +
 include/hw/acpi/aml-build.h   |    1 +
 include/hw/boards.h           |    1 +
 include/hw/i386/intel_iommu.h |    1 +
 include/hw/pci/pci.h          |    2 +
 qemu-options.hx               |    7 +-
 util/qemu-config.c            |    8 +-
 16 files changed, 2010 insertions(+), 34 deletions(-)
 create mode 100644 hw/i386/amd_iommu.c
 create mode 100644 hw/i386/amd_iommu.h

--
2.1.4

#8 lore raw

Re: [Qemu-devel] [V9 3/4] hw/core: Add AMD IOMMU to machine properties

In reply to David Kiarie
Quoted 37 lines · David Kiarie

Added a bool, subject to review to machine properties which it used to override iommu emulated from Intel to AMD.

---
 hw/core/machine.c             | 32 +++++++++++++++++++++++++++++---
 include/hw/boards.h           |  1 +
 include/hw/i386/intel_iommu.h |  1 +
 qemu-options.hx               |  7 +++++--
 util/qemu-config.c            |  8 ++++++--
 5 files changed, 42 insertions(+), 7 deletions(-)
hw/core/machine.c +10 -0
index 6dbbc85..792641b 100644
@@ -15,6 +15,8 @@
 #include "qapi/error.h"
 #include "qapi-visit.h"
 #include "qapi/visitor.h"
+#include "hw/i386/amd_iommu.h"
+#include "hw/i386/intel_iommu.h"
 #include "hw/sysbus.h"
 #include "sysemu/sysemu.h"
 #include "qemu/error-report.h"
@@ -300,6 +302,26 @@ static void machine_set_iommu(Object *obj, bool value, Error **errp)
     ms->iommu = value;
 }
 
+static void machine_set_iommu_override(Object *obj, const char *value,
+                                       Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+    Error *err = NULL;
+
+    ms->x_iommu_type = false;
+    /* ensure a valid iommu type */

hw/core/machine.c static void machine_set_iommu(Object *obj, bool value, Error **errp) · line 322

Quoted 10 lines
hw/core/machine.c +10 -0
+    if (g_strcmp0(value, AMD_IOMMU_STR) &&
+            g_strcmp0(value, INTEL_IOMMU_STR)) {
+        error_setg(errp, "Invalid IOMMU type %s", value);
+        error_propagate(errp, err);
+        return;
+    }
+
+    if ((g_strcmp0(value, AMD_IOMMU_STR) == 0)) {
+        ms->x_iommu_type = true;
+    }

Would it be clearer to use:

    if (g_strcmp0(value, AMD_IOMMU_STR) == 0) {
        ...
    } else if (g_strcmp0(value, INTEL_IOMMU_STR) == 0) {
        ...
    } else {
        error...
    }

?

Thanks.

-- peterx

#10 lore raw

Re: [Qemu-devel] [V9 4/4] hw/pci-host: Emulate AMD IOMMU

In reply to David Kiarie
Quoted 43 lines · David Kiarie

Add AMD IOMMU emulation support to q35 chipset

---
 hw/pci-host/q35.c             | 21 +++++++++++++++++++--
 include/hw/i386/intel_iommu.h |  2 +-
 2 files changed, 20 insertions(+), 3 deletions(-)
hw/pci-host/q35.c +14 -0
index 70f897e..37f8a84 100644
@@ -32,6 +32,7 @@
 #include "hw/pci-host/q35.h"
 #include "qapi/error.h"
 #include "qapi/visitor.h"
+#include "hw/i386/amd_iommu.h"
 
 /****************************************************************************
  * Q35 host
@@ -448,6 +449,19 @@ static void mch_init_dmar(MCHPCIState *mch)
     pci_setup_iommu(pci_bus, q35_host_dma_iommu, mch->iommu);
 }
 
+static void mch_init_amdvi(MCHPCIState *mch)
+{
+    AMDIOMMUState *iommu_state;
+    PCIBus *bus = PCI_BUS(qdev_get_parent_bus(DEVICE(mch)));
+    PCIDevice *iommu;
+
+    iommu = pci_create_simple(bus, 0x20, TYPE_AMD_IOMMU_DEVICE);
+
+    iommu_state = AMD_IOMMU_DEVICE(iommu);
+
+    pci_setup_iommu(bus, bridge_host_amd_iommu, iommu_state);
+}
+
 static void mch_realize(PCIDevice *d, Error **errp)
 {
     int i;
@@ -506,8 +520,11 @@ static void mch_realize(PCIDevice *d, Error **errp)
                  mch->pci_address_space, &mch->pam_regions[i+1],
                  PAM_EXPAN_BASE + i * PAM_EXPAN_SIZE, PAM_EXPAN_SIZE);

hw/pci-host/q35.c static void mch_realize(PCIDevice *d, Error **errp) · line 529

Quoted 10 lines
hw/pci-host/q35.c +5 -2
     }
-    /* Intel IOMMU (VT-d) */
-    if (object_property_get_bool(qdev_get_machine(), "iommu", NULL)) {
+
+    if (object_property_get_bool(qdev_get_machine(), "iommu", NULL) &&
+        MACHINE(qdev_get_machine())->x_iommu_type) {
+        mch_init_amdvi(mch);
+    } else if (object_property_get_bool(qdev_get_machine(), "iommu", NULL)) {
         mch_init_dmar(mch);
     }

Like patch 3's comment, I would prefer this:

    if (object_property_get_bool(qdev_get_machine(), "iommu", NULL)) {
        if (MACHINE(qdev_get_machine())->x_iommu_type) {
            mch_init_amdvi(mch);
        } else {
            mch_init_dmar(mch);
        }
    }

Thanks.

-- peterx

#12 lore raw
In reply to David Kiarie
Quoted 1 line · David Kiarie

Sorry, I keep missing Jan's email...

No problem.

I'm planning to give this version a try soon and will also look into some details for a review.

Jan

Quoted 38 lines · David Kiarie
Quoted 36 lines

Hi all,

The current AMD IOMMU patches that fixes Igor's comments. I got rid of structs and instead added individual integer fields into the table data directly, as suggested.

I have also got rid of some un-used macros and fixed a few other miscellaneous things.

David Kiarie (4):
hw/i386: Introduce AMD IOMMU
hw/i386: ACPI table for AMD IOMMU
hw/core: Add AMD IOMMU to machine properties
hw/pci-host: Emulate AMD IOMMU

 hw/acpi/aml-build.c           |    2 +-
 hw/acpi/core.c                |   13 -
 hw/core/machine.c             |   32 +-
 hw/i386/Makefile.objs         |    1 +
 hw/i386/acpi-build.c          |  101 ++-
 hw/i386/amd_iommu.c           | 1426 +++++++++++++++++++++++++++++++++++++++++
 hw/i386/amd_iommu.h           |  398 ++++++++++++
 hw/pci-host/q35.c             |   21 +-
 include/hw/acpi/acpi-defs.h   |   14 +
 include/hw/acpi/acpi.h        |   16 +
 include/hw/acpi/aml-build.h   |    1 +
 include/hw/boards.h           |    1 +
 include/hw/i386/intel_iommu.h |    1 +
 include/hw/pci/pci.h          |    2 +
 qemu-options.hx               |    7 +-
 util/qemu-config.c            |    8 +-
 16 files changed, 2010 insertions(+), 34 deletions(-)
 create mode 100644 hw/i386/amd_iommu.c
 create mode 100644 hw/i386/amd_iommu.h

--
2.1.4

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA ITP SES-DE
Corporate Competence Center Embedded Linux
#13 lore raw
In reply to David Kiarie
Quoted 6 lines · David Kiarie

Hi all,

The current AMD IOMMU patches that fixes Igor's comments. I got rid of structs and instead added individual integer fields into the table data directly, as suggested.

I have also got rid of some un-used macros and fixed a few other miscellaneous things.

My comments for V8 still stand. I don't see them addressed in this version. Thanks,
Marcel

Quoted 27 lines

David Kiarie (4):
hw/i386: Introduce AMD IOMMU
hw/i386: ACPI table for AMD IOMMU
hw/core: Add AMD IOMMU to machine properties
hw/pci-host: Emulate AMD IOMMU

  hw/acpi/aml-build.c           |    2 +-
  hw/acpi/core.c                |   13 -
  hw/core/machine.c             |   32 +-
  hw/i386/Makefile.objs         |    1 +
  hw/i386/acpi-build.c          |  101 ++-
  hw/i386/amd_iommu.c           | 1426 +++++++++++++++++++++++++++++++++++++++++
  hw/i386/amd_iommu.h           |  398 ++++++++++++
  hw/pci-host/q35.c             |   21 +-
  include/hw/acpi/acpi-defs.h   |   14 +
  include/hw/acpi/acpi.h        |   16 +
  include/hw/acpi/aml-build.h   |    1 +
  include/hw/boards.h           |    1 +
  include/hw/i386/intel_iommu.h |    1 +
  include/hw/pci/pci.h          |    2 +
  qemu-options.hx               |    7 +-
  util/qemu-config.c            |    8 +-
  16 files changed, 2010 insertions(+), 34 deletions(-)

create mode 100644 hw/i386/amd_iommu.c
create mode 100644 hw/i386/amd_iommu.h

#3 lore raw

Re: [Qemu-devel] [V9 2/4] hw/i386: ACPI table for AMD IOMMU

In reply to David Kiarie
Quoted 2 lines · David Kiarie

Add IVRS table for AMD IOMMU. Generate IVRS or DMAR depending on emulated IOMMU

It seems you lack scope descriptions for the PCI devices in the system. At least, this is what our jailhouse config generator complains about right now (didn't look into details yet). If so, the guest OS will likely not configure the IOMMU appropriately as it thinks that the devices are passed through anyway.

On Intel, there is an easy way to state "catch them all" in the ACPI table. Maybe AMD has this as well so that you don't need to add individual devices.

Jan

#4 lore raw

Re: [Qemu-devel] [V9 2/4] hw/i386: ACPI table for AMD IOMMU

Quoted 10 lines · Jan Kiszka
Quoted 2 lines · David Kiarie

Add IVRS table for AMD IOMMU. Generate IVRS or DMAR depending on emulated IOMMU

It seems you lack scope descriptions for the PCI devices in the system. At least, this is what our jailhouse config generator complains about right now (didn't look into details yet). If so, the guest OS will likely not configure the IOMMU appropriately as it thinks that the devices are passed through anyway.

Quoted 3 lines

On Intel, there is an easy way to state "catch them all" in the ACPI table. Maybe AMD has this as well so that you don't need to add individual devices.

This is what am currently doing. From what I can see, linux correctly detects the range but I will have a look at it again before sending the next version.

There was another issue raised by Michael about denying VFIO in case a user requests for IOMMU support. I did look at this but since VFIO is started with '-device' I didn't find a way to deny it in case of IOMMU support except by parsing command line arguments which turned out to be a bit ugly.

We could exclude VFIO from translation by IOMMU by excluding it from the scope descriptions but am not quite sure this will remedy all the problems relating to VFIO and IOMMU. This will also require the device scope to explicitly list all the devices.

Quoted 2 lines

Jan

#6 lore raw

Re: [Qemu-devel] [V9 2/4] hw/i386: ACPI table for AMD IOMMU

In reply to Jan Kiszka
Quoted 10 lines · Jan Kiszka
Quoted 2 lines · David Kiarie

Add IVRS table for AMD IOMMU. Generate IVRS or DMAR depending on emulated IOMMU

It seems you lack scope descriptions for the PCI devices in the system. At least, this is what our jailhouse config generator complains about right now (didn't look into details yet). If so, the guest OS will likely not configure the IOMMU appropriately as it thinks that the devices are passed through anyway.

Quoted 3 lines

On Intel, there is an easy way to state "catch them all" in the ACPI table. Maybe AMD has this as well so that you don't need to add individual devices.

There is. IVHD Device Entry Type 1 does just that.

Valentine

#5 lore raw

Re: [Qemu-devel] [V9 2/4] hw/i386: ACPI table for AMD IOMMU

In reply to David Kiarie
Quoted 25 lines · David Kiarie
Quoted 10 lines · Jan Kiszka
Quoted 2 lines · David Kiarie

Add IVRS table for AMD IOMMU. Generate IVRS or DMAR depending on emulated IOMMU

It seems you lack scope descriptions for the PCI devices in the system. At least, this is what our jailhouse config generator complains about right now (didn't look into details yet). If so, the guest OS will likely not configure the IOMMU appropriately as it thinks that the devices are passed through anyway.

Quoted 3 lines

On Intel, there is an easy way to state "catch them all" in the ACPI table. Maybe AMD has this as well so that you don't need to add individual devices.

This is what am currently doing. From what I can see, linux correctly detects the range but I will have a look at it again before sending the next version.

There was another issue raised by Michael about denying VFIO in case a user requests for IOMMU support. I did look at this but since VFIO is started with '-device' I didn't find a way to deny it in case of IOMMU support except by parsing command line arguments which turned out to be a bit ugly.

Quoted 4 lines

We could exclude VFIO from translation by IOMMU by excluding it from the scope descriptions but am not quite sure this will remedy all the problems relating to VFIO and IOMMU. This will also require the device scope to explicitly list all the devices.

You may also try listing everything "up to" VFIO, then everything "after" the VFIO, I guess.

Valentine