Skip to contentSkip to conversation

enable ATS per pcie root port, not globally

PATCH In review Ani Sinha 2 participants 8 messages Aug 22, 2022 – Aug 25, 2022

lore
Share & tools
lore

Ani Sinha

author
#0 lore raw

cover enable ATS per pcie root port, not globally

This is towards a possible fix for RedHat ticket
https://bugzilla.redhat.com/show_bug.cgi?id=2089545 .

Michael suggested we try to enable ATS per pcie root port instead of enabling it globally by setting the ALL_PORTS flag to 1 in the Root Port ATS capability structure. This patchset makes this happen.

Ani Sinha (4):
hw/acpi: allow changes to DSDT and DMAR tables
hw/acpi: set ATS capability explicitly per pcie root port tests/acpi/bios-table-test: add pcie root port device for DMAR test tests/acpi/bios-tables-test: update DSDT and DMAR table blobs

 hw/i386/acpi-build.c           |  74 ++++++++++++++++++++++++++++++++-
 tests/data/acpi/q35/DMAR.dmar  | Bin 120 -> 136 bytes
 tests/data/acpi/q35/DSDT.dmar  | Bin 0 -> 8421 bytes
 tests/qtest/bios-tables-test.c |   3 +-
 4 files changed, 74 insertions(+), 3 deletions(-)
 create mode 100644 tests/data/acpi/q35/DSDT.dmar
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 1/4 hw/acpi: allow changes to DSDT and DMAR tables

Our next change modifies DMAR and DSDT tables. Make sure we whitelist those changes so that bios-table-test does not break.

---
 tests/data/acpi/q35/DSDT.dmar               | 0
 tests/qtest/bios-tables-test-allowed-diff.h | 2 ++
 2 files changed, 2 insertions(+)
 create mode 100644 tests/data/acpi/q35/DSDT.dmar
tests/data/acpi/q35/DSDT.dmar new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
tests/qtest/bios-tables-test-allowed-diff.h +2 -0
index dfb8523c8b..4efed12b59 100644
@@ -1 +1,3 @@
 /* List of comma-separated changed AML files to ignore */
+"tests/data/acpi/q35/DSDT.dmar",
+"tests/data/acpi/q35/DMAR.dmar",
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH 2/4 hw/acpi: set ATS capability explicitly per pcie root port

In reply to Ani Sinha

Currently the bit 0 of the flags field of Root Port ATS capability reporting structure sub-table under the DMAR table is set to 1. This indicates ALL_PORTS, thus enabling ATS capability for all pcie roots without the ability to turn off ATS for some ports and leaving ATS on for others.

This change clears the bit 0 of the flags field of the above structure and explicitly adds scopes for every pcie root port in the structure so that ATS is enabled for all of them. In future, we might add new attribite to the root ports so that we can selectively enable ATS for some and leave ATS off for others.

---
 hw/i386/acpi-build.c | 74 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 72 insertions(+), 2 deletions(-)
hw/i386/acpi-build.c +72 -2
index 0355bd3dda..9c5a555536 100644
@@ -60,6 +60,7 @@
 #include "hw/i386/fw_cfg.h"
 #include "hw/i386/ich9.h"
 #include "hw/pci/pci_bus.h"
+#include "hw/pci/pcie_port.h"
 #include "hw/pci-host/q35.h"
 #include "hw/i386/x86-iommu.h"
 
@@ -2118,6 +2119,60 @@ dmar_host_bridges(Object *obj, void *opaque)
     return 0;
 }
 
+/*
+ * Insert DMAR scope for PCIE root ports
+ */
+static void
+insert_pcie_root_port_scope(PCIBus *bus, PCIDevice *dev, void *opaque)
+{
+    const size_t device_scope_size = 6 + 2;
+                                   /* device scope structure + 1 path entry */
+    GArray *scope_blob = opaque;
+
+    /*
+     * We are only interested in PCIE root ports. We can extend
+     * this to check for specific properties of PCIE root ports and based
+     * on that remove some ports from having ATS capability.
+     */
+    if (!object_dynamic_cast(OBJECT(dev), TYPE_PCIE_ROOT_PORT)) {
+        return;
+    }
+
+    /* Dmar Scope Type: 0x02 for all PCIE root ports */
+    build_append_int_noprefix(scope_blob, 0x02, 1);
+
+    /* length */
+    build_append_int_noprefix(scope_blob, device_scope_size, 1);
+    /* reserved */
+    build_append_int_noprefix(scope_blob, 0, 2);
+    /* enumeration_id */
+    build_append_int_noprefix(scope_blob, 0, 1);
+    /* bus */
+    build_append_int_noprefix(scope_blob, pci_bus_num(bus), 1);
+    /* device */
+    build_append_int_noprefix(scope_blob, PCI_SLOT(dev->devfn), 1);
+    /* function */
+    build_append_int_noprefix(scope_blob, PCI_FUNC(dev->devfn), 1);
+}
+
+/* For a given PCI host bridge, walk and insert DMAR scope */
+static int
+dmar_pcie_root_ports(Object *obj, void *opaque)
+{
+    GArray *scope_blob = opaque;
+
+    if (object_dynamic_cast(obj, TYPE_PCI_HOST_BRIDGE)) {
+        PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus;
+
+        if (bus && !pci_bus_bypass_iommu(bus)) {
+            pci_for_each_device_under_bus(bus, insert_pcie_root_port_scope,
+                                          scope_blob);
+        }
+    }
+
+    return 0;
+}
+
 /*
  * Intel ® Virtualization Technology for Directed I/O
  * Architecture Specification. Revision 3.3
@@ -2190,11 +2245,26 @@ build_dmar_q35(GArray *table_data, BIOSLinker *linker, const char *oem_id,
 
     if (iommu->dt_supported) {
         /* 8.5 Root Port ATS Capability Reporting Structure */
+        /*
+         * A PCI bus walk, for each PCIE root port.
+         * Since we did not enable ALL_PORTS bit in the flags above, we
+         * need to add the scope for each pcie root port explicitly
+         * that are attached to bus0 with iommu enabled.
+         */
+        scope_blob = g_array_new(false, true, 1);
+        object_child_foreach_recursive(object_get_root(),
+                                       dmar_pcie_root_ports, scope_blob);
+
         build_append_int_noprefix(table_data, 2, 2); /* Type */
-        build_append_int_noprefix(table_data, 8, 2); /* Length */
-        build_append_int_noprefix(table_data, 1 /* ALL_PORTS */, 1); /* Flags */
+        build_append_int_noprefix(table_data,
+                                  8 + scope_blob->len, 2); /* Length */
+        build_append_int_noprefix(table_data, 0, 1); /* Flags */
         build_append_int_noprefix(table_data, 0, 1); /* Reserved */
         build_append_int_noprefix(table_data, 0, 2); /* Segment Number */
+
+        /* now add the scope to the sub-table */
+        g_array_append_vals(table_data, scope_blob->data, scope_blob->len);
+        g_array_free(scope_blob, true);
     }
 
     acpi_table_end(linker, &table);
Signature · 1 line
2.25.1
#3 lore raw

Re: [PATCH 2/4] hw/acpi: set ATS capability explicitly per pcie root port

Quoted 10 lines · On Mon, 22 Aug 2022 14:38:09 +0530 Ani Sinha <[email protected]> wrote:

Currently the bit 0 of the flags field of Root Port ATS capability reporting structure sub-table under the DMAR table is set to 1. This indicates ALL_PORTS, thus enabling ATS capability for all pcie roots without the ability to turn off ATS for some ports and leaving ATS on for others.

This change clears the bit 0 of the flags field of the above structure and explicitly adds scopes for every pcie root port in the structure so that ATS is enabled for all of them. In future, we might add new attribite to the root ports so that we can selectively enable ATS for some and leave ATS off for others.

Thanks, it was worth a try,
unfortunately since we are shooting in dark this time it was a miss.

Quoted 108 lines
---
 hw/i386/acpi-build.c | 74 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 72 insertions(+), 2 deletions(-)
hw/i386/acpi-build.c +72 -2
index 0355bd3dda..9c5a555536 100644
@@ -60,6 +60,7 @@
 #include "hw/i386/fw_cfg.h"
 #include "hw/i386/ich9.h"
 #include "hw/pci/pci_bus.h"
+#include "hw/pci/pcie_port.h"
 #include "hw/pci-host/q35.h"
 #include "hw/i386/x86-iommu.h"
 
@@ -2118,6 +2119,60 @@ dmar_host_bridges(Object *obj, void *opaque)
     return 0;
 }
 
+/*
+ * Insert DMAR scope for PCIE root ports
+ */
+static void
+insert_pcie_root_port_scope(PCIBus *bus, PCIDevice *dev, void *opaque)
+{
+    const size_t device_scope_size = 6 + 2;
+                                   /* device scope structure + 1 path entry */
+    GArray *scope_blob = opaque;
+
+    /*
+     * We are only interested in PCIE root ports. We can extend
+     * this to check for specific properties of PCIE root ports and based
+     * on that remove some ports from having ATS capability.
+     */
+    if (!object_dynamic_cast(OBJECT(dev), TYPE_PCIE_ROOT_PORT)) {
+        return;
+    }
+
+    /* Dmar Scope Type: 0x02 for all PCIE root ports */
+    build_append_int_noprefix(scope_blob, 0x02, 1);
+
+    /* length */
+    build_append_int_noprefix(scope_blob, device_scope_size, 1);
+    /* reserved */
+    build_append_int_noprefix(scope_blob, 0, 2);
+    /* enumeration_id */
+    build_append_int_noprefix(scope_blob, 0, 1);
+    /* bus */
+    build_append_int_noprefix(scope_blob, pci_bus_num(bus), 1);
+    /* device */
+    build_append_int_noprefix(scope_blob, PCI_SLOT(dev->devfn), 1);
+    /* function */
+    build_append_int_noprefix(scope_blob, PCI_FUNC(dev->devfn), 1);
+}
+
+/* For a given PCI host bridge, walk and insert DMAR scope */
+static int
+dmar_pcie_root_ports(Object *obj, void *opaque)
+{
+    GArray *scope_blob = opaque;
+
+    if (object_dynamic_cast(obj, TYPE_PCI_HOST_BRIDGE)) {
+        PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus;
+
+        if (bus && !pci_bus_bypass_iommu(bus)) {
+            pci_for_each_device_under_bus(bus, insert_pcie_root_port_scope,
+                                          scope_blob);
+        }
+    }
+
+    return 0;
+}
+
 /*
  * Intel ® Virtualization Technology for Directed I/O
  * Architecture Specification. Revision 3.3
@@ -2190,11 +2245,26 @@ build_dmar_q35(GArray *table_data, BIOSLinker *linker, const char *oem_id,
 
     if (iommu->dt_supported) {
         /* 8.5 Root Port ATS Capability Reporting Structure */
+        /*
+         * A PCI bus walk, for each PCIE root port.
+         * Since we did not enable ALL_PORTS bit in the flags above, we
+         * need to add the scope for each pcie root port explicitly
+         * that are attached to bus0 with iommu enabled.
+         */
+        scope_blob = g_array_new(false, true, 1);
+        object_child_foreach_recursive(object_get_root(),
+                                       dmar_pcie_root_ports, scope_blob);
+
         build_append_int_noprefix(table_data, 2, 2); /* Type */
-        build_append_int_noprefix(table_data, 8, 2); /* Length */
-        build_append_int_noprefix(table_data, 1 /* ALL_PORTS */, 1); /* Flags */
+        build_append_int_noprefix(table_data,
+                                  8 + scope_blob->len, 2); /* Length */
+        build_append_int_noprefix(table_data, 0, 1); /* Flags */
         build_append_int_noprefix(table_data, 0, 1); /* Reserved */
         build_append_int_noprefix(table_data, 0, 2); /* Segment Number */
+
+        /* now add the scope to the sub-table */
+        g_array_append_vals(table_data, scope_blob->data, scope_blob->len);
+        g_array_free(scope_blob, true);
     }
 
     acpi_table_end(linker, &table);
author
#4 lore raw

Re: [PATCH 2/4] hw/acpi: set ATS capability explicitly per pcie root port

Quoted 15 lines · Igor Mammedov
Quoted 1 line · On Mon, 22 Aug 2022 14:38:09 +0530 Ani Sinha <[email protected]> wrote:

Currently the bit 0 of the flags field of Root Port ATS capability

reporting

Quoted 1 line

structure sub-table under the DMAR table is set to 1. This indicates

ALL_PORTS,

Quoted 1 line

thus enabling ATS capability for all pcie roots without the ability to

turn off

Quoted 3 lines

ATS for some ports and leaving ATS on for others.

This change clears the bit 0 of the flags field of the above structure

and

Quoted 1 line

explicitly adds scopes for every pcie root port in the structure so that

ATS

Quoted 8 lines
Quoted 1 line

is enabled for all of them. In future, we might add new attribite to the

root

Quoted 1 line

ports so that we can selectively enable ATS for some and leave ATS off

for

Quoted 1 line

others.

Thanks, it was worth a try,
unfortunately since we are shooting in dark this time it was a miss.

So I take it that even with this patch Windows still exhibited the issue? Is it worth pushing the patch anyway?

Quoted 120 lines
Quoted 22 lines
---
 hw/i386/acpi-build.c | 74 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 72 insertions(+), 2 deletions(-)
hw/i386/acpi-build.c +1 -0
index 0355bd3dda..9c5a555536 100644
@@ -60,6 +60,7 @@
 #include "hw/i386/fw_cfg.h"
 #include "hw/i386/ich9.h"
 #include "hw/pci/pci_bus.h"
+#include "hw/pci/pcie_port.h"
 #include "hw/pci-host/q35.h"
 #include "hw/i386/x86-iommu.h"
 
@@ -2118,6 +2119,60 @@ dmar_host_bridges(Object *obj, void *opaque)
     return 0;

hw/i386/acpi-build.c dmar_host_bridges(Object *obj, void *opaque) · line 2129

Quoted 10 lines
hw/i386/acpi-build.c +8 -0
 }
 
+/*
+ * Insert DMAR scope for PCIE root ports
+ */
+static void
+insert_pcie_root_port_scope(PCIBus *bus, PCIDevice *dev, void *opaque)
+{
+    const size_t device_scope_size = 6 + 2;
+                                   /* device scope structure + 1 path

entry */

hw/i386/acpi-build.c dmar_host_bridges(Object *obj, void *opaque)

Quoted 5 lines
hw/i386/acpi-build.c +5 -0
+    GArray *scope_blob = opaque;
+
+    /*
+     * We are only interested in PCIE root ports. We can extend
+     * this to check for specific properties of PCIE root ports and

based

Quoted 24 lines
hw/i386/acpi-build.c +24 -0
+     * on that remove some ports from having ATS capability.
+     */
+    if (!object_dynamic_cast(OBJECT(dev), TYPE_PCIE_ROOT_PORT)) {
+        return;
+    }
+
+    /* Dmar Scope Type: 0x02 for all PCIE root ports */
+    build_append_int_noprefix(scope_blob, 0x02, 1);
+
+    /* length */
+    build_append_int_noprefix(scope_blob, device_scope_size, 1);
+    /* reserved */
+    build_append_int_noprefix(scope_blob, 0, 2);
+    /* enumeration_id */
+    build_append_int_noprefix(scope_blob, 0, 1);
+    /* bus */
+    build_append_int_noprefix(scope_blob, pci_bus_num(bus), 1);
+    /* device */
+    build_append_int_noprefix(scope_blob, PCI_SLOT(dev->devfn), 1);
+    /* function */
+    build_append_int_noprefix(scope_blob, PCI_FUNC(dev->devfn), 1);
+}
+
+/* For a given PCI host bridge, walk and insert DMAR scope */

hw/i386/acpi-build.c dmar_host_bridges(Object *obj, void *opaque)

Quoted 10 lines
hw/i386/acpi-build.c +10 -0
+static int
+dmar_pcie_root_ports(Object *obj, void *opaque)
+{
+    GArray *scope_blob = opaque;
+
+    if (object_dynamic_cast(obj, TYPE_PCI_HOST_BRIDGE)) {
+        PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus;
+
+        if (bus && !pci_bus_bypass_iommu(bus)) {
+            pci_for_each_device_under_bus(bus,

insert_pcie_root_port_scope,

hw/i386/acpi-build.c build_dmar_q35(GArray *table_data, BIOSLinker

Quoted 11 lines
hw/i386/acpi-build.c +7 -0
+                                          scope_blob);
+        }
+    }
+
+    return 0;
+}
+
 /*
  * Intel ® Virtualization Technology for Directed I/O
  * Architecture Specification. Revision 3.3
@@ -2190,11 +2245,26 @@ build_dmar_q35(GArray *table_data, BIOSLinker

*linker, const char *oem_id,

hw/i386/acpi-build.c build_dmar_q35(GArray *table_data, BIOSLinker *linker, const char *oem_id,

Quoted 12 lines
hw/i386/acpi-build.c +9 -0
     if (iommu->dt_supported) {
         /* 8.5 Root Port ATS Capability Reporting Structure */
+        /*
+         * A PCI bus walk, for each PCIE root port.
+         * Since we did not enable ALL_PORTS bit in the flags above, we
+         * need to add the scope for each pcie root port explicitly
+         * that are attached to bus0 with iommu enabled.
+         */
+        scope_blob = g_array_new(false, true, 1);
+        object_child_foreach_recursive(object_get_root(),
+                                       dmar_pcie_root_ports,

scope_blob);

hw/i386/acpi-build.c build_dmar_q35(GArray *table_data, BIOSLinker *linker, const char *oem_id,

Quoted 4 lines
hw/i386/acpi-build.c +1 -2
+
         build_append_int_noprefix(table_data, 2, 2); /* Type */
-        build_append_int_noprefix(table_data, 8, 2); /* Length */
-        build_append_int_noprefix(table_data, 1 /* ALL_PORTS */, 1); /*

Flags */

hw/i386/acpi-build.c build_dmar_q35(GArray *table_data, BIOSLinker *linker, const char *oem_id,

Quoted 5 lines
hw/i386/acpi-build.c +3 -0
+        build_append_int_noprefix(table_data,
+                                  8 + scope_blob->len, 2); /* Length */
+        build_append_int_noprefix(table_data, 0, 1); /* Flags */
         build_append_int_noprefix(table_data, 0, 1); /* Reserved */
         build_append_int_noprefix(table_data, 0, 2); /* Segment Number

*/

hw/i386/acpi-build.c build_dmar_q35(GArray *table_data, BIOSLinker *linker, const char *oem_id,

Quoted 3 lines
hw/i386/acpi-build.c +3 -0
+
+        /* now add the scope to the sub-table */
+        g_array_append_vals(table_data, scope_blob->data,

scope_blob->len);

Quoted 4 lines
hw/i386/acpi-build.c +1 -0
+        g_array_free(scope_blob, true);
     }
 
     acpi_table_end(linker, &table);
#5 lore raw

Re: [PATCH 2/4] hw/acpi: set ATS capability explicitly per pcie root port

Quoted 20 lines · On Wed, 24 Aug 2022 21:46:58 +0530 Ani Sinha <[email protected]> wrote:
Quoted 18 lines · Igor Mammedov
Quoted 1 line · On Mon, 22 Aug 2022 14:38:09 +0530 Ani Sinha <[email protected]> wrote:

Currently the bit 0 of the flags field of Root Port ATS capability

reporting

Quoted 1 line

structure sub-table under the DMAR table is set to 1. This indicates

ALL_PORTS,

Quoted 1 line

thus enabling ATS capability for all pcie roots without the ability to

turn off

Quoted 3 lines

ATS for some ports and leaving ATS on for others.

This change clears the bit 0 of the flags field of the above structure

and

Quoted 1 line

explicitly adds scopes for every pcie root port in the structure so that

ATS

Quoted 1 line

is enabled for all of them. In future, we might add new attribite to the

root

Quoted 1 line

ports so that we can selectively enable ATS for some and leave ATS off

Quoted 8 lines
Quoted 5 lines

for

Quoted 1 line

others.

Thanks, it was worth a try,
unfortunately since we are shooting in dark this time it was a miss.

So I take it that even with this patch Windows still exhibited the issue?

unfortunately, yep

Quoted 1 line

Is it worth pushing the patch anyway?

it will extra cpu time and guest RAM,
so unless we have to have to I'd rather not.

Quoted 121 lines
Quoted 121 lines
Quoted 23 lines
---
 hw/i386/acpi-build.c | 74 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 72 insertions(+), 2 deletions(-)
hw/i386/acpi-build.c +1 -0
index 0355bd3dda..9c5a555536 100644
@@ -60,6 +60,7 @@
 #include "hw/i386/fw_cfg.h"
 #include "hw/i386/ich9.h"
 #include "hw/pci/pci_bus.h"
+#include "hw/pci/pcie_port.h"
 #include "hw/pci-host/q35.h"
 #include "hw/i386/x86-iommu.h"
 
@@ -2118,6 +2119,60 @@ dmar_host_bridges(Object *obj, void *opaque)
     return 0;

hw/i386/acpi-build.c dmar_host_bridges(Object *obj, void *opaque) · line 2129

Quoted 10 lines
hw/i386/acpi-build.c +8 -0
 }
 
+/*
+ * Insert DMAR scope for PCIE root ports
+ */
+static void
+insert_pcie_root_port_scope(PCIBus *bus, PCIDevice *dev, void *opaque)
+{
+    const size_t device_scope_size = 6 + 2;
+                                   /* device scope structure + 1 path  

entry */

hw/i386/acpi-build.c dmar_host_bridges(Object *obj, void *opaque)

Quoted 5 lines
hw/i386/acpi-build.c +5 -0
+    GArray *scope_blob = opaque;
+
+    /*
+     * We are only interested in PCIE root ports. We can extend
+     * this to check for specific properties of PCIE root ports and  

based

Quoted 24 lines
hw/i386/acpi-build.c +24 -0
+     * on that remove some ports from having ATS capability.
+     */
+    if (!object_dynamic_cast(OBJECT(dev), TYPE_PCIE_ROOT_PORT)) {
+        return;
+    }
+
+    /* Dmar Scope Type: 0x02 for all PCIE root ports */
+    build_append_int_noprefix(scope_blob, 0x02, 1);
+
+    /* length */
+    build_append_int_noprefix(scope_blob, device_scope_size, 1);
+    /* reserved */
+    build_append_int_noprefix(scope_blob, 0, 2);
+    /* enumeration_id */
+    build_append_int_noprefix(scope_blob, 0, 1);
+    /* bus */
+    build_append_int_noprefix(scope_blob, pci_bus_num(bus), 1);
+    /* device */
+    build_append_int_noprefix(scope_blob, PCI_SLOT(dev->devfn), 1);
+    /* function */
+    build_append_int_noprefix(scope_blob, PCI_FUNC(dev->devfn), 1);
+}
+
+/* For a given PCI host bridge, walk and insert DMAR scope */

hw/i386/acpi-build.c dmar_host_bridges(Object *obj, void *opaque)

Quoted 10 lines
hw/i386/acpi-build.c +10 -0
+static int
+dmar_pcie_root_ports(Object *obj, void *opaque)
+{
+    GArray *scope_blob = opaque;
+
+    if (object_dynamic_cast(obj, TYPE_PCI_HOST_BRIDGE)) {
+        PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus;
+
+        if (bus && !pci_bus_bypass_iommu(bus)) {
+            pci_for_each_device_under_bus(bus,  

insert_pcie_root_port_scope,

hw/i386/acpi-build.c build_dmar_q35(GArray *table_data, BIOSLinker

Quoted 11 lines
hw/i386/acpi-build.c +7 -0
+                                          scope_blob);
+        }
+    }
+
+    return 0;
+}
+
 /*
  * Intel ® Virtualization Technology for Directed I/O
  * Architecture Specification. Revision 3.3
@@ -2190,11 +2245,26 @@ build_dmar_q35(GArray *table_data, BIOSLinker  

*linker, const char *oem_id,

hw/i386/acpi-build.c build_dmar_q35(GArray *table_data, BIOSLinker *linker, const char *oem_id,

Quoted 12 lines
hw/i386/acpi-build.c +9 -0
     if (iommu->dt_supported) {
         /* 8.5 Root Port ATS Capability Reporting Structure */
+        /*
+         * A PCI bus walk, for each PCIE root port.
+         * Since we did not enable ALL_PORTS bit in the flags above, we
+         * need to add the scope for each pcie root port explicitly
+         * that are attached to bus0 with iommu enabled.
+         */
+        scope_blob = g_array_new(false, true, 1);
+        object_child_foreach_recursive(object_get_root(),
+                                       dmar_pcie_root_ports,  

scope_blob);

hw/i386/acpi-build.c build_dmar_q35(GArray *table_data, BIOSLinker *linker, const char *oem_id,

Quoted 4 lines
hw/i386/acpi-build.c +1 -2
+
         build_append_int_noprefix(table_data, 2, 2); /* Type */
-        build_append_int_noprefix(table_data, 8, 2); /* Length */
-        build_append_int_noprefix(table_data, 1 /* ALL_PORTS */, 1); /*  

Flags */

hw/i386/acpi-build.c build_dmar_q35(GArray *table_data, BIOSLinker *linker, const char *oem_id,

Quoted 5 lines
hw/i386/acpi-build.c +3 -0
+        build_append_int_noprefix(table_data,
+                                  8 + scope_blob->len, 2); /* Length */
+        build_append_int_noprefix(table_data, 0, 1); /* Flags */
         build_append_int_noprefix(table_data, 0, 1); /* Reserved */
         build_append_int_noprefix(table_data, 0, 2); /* Segment Number  

*/

hw/i386/acpi-build.c build_dmar_q35(GArray *table_data, BIOSLinker *linker, const char *oem_id,

Quoted 3 lines
hw/i386/acpi-build.c +3 -0
+
+        /* now add the scope to the sub-table */
+        g_array_append_vals(table_data, scope_blob->data,  

scope_blob->len);

Quoted 4 lines
hw/i386/acpi-build.c +1 -0
+        g_array_free(scope_blob, true);
     }
 
     acpi_table_end(linker, &table);  
author
#6 lore raw

PATCH 3/4 tests/acpi/bios-table-test: add pcie root port device for DMAR test

In reply to Ani Sinha

In the previos commit, we are explicitly adding scopes for pcie root ports in Root Port ATS capability reporting structure. We add a pcie root port in the QEMU test command line for DMAR tests so that we can verify that the scope of the root port has been correctly added and structure looks sane.

After the changes, the above structure will look like this:

+[078h 0120 2] Subtable Type : 0002 [Root Port ATS Capability]
+[07Ah 0122 2] Length : 0010
+

+[07Ch 0124   1]                        Flags : 00
+[07Dh 0125   1]                     Reserved : 00
+[07Eh 0126   2]           PCI Segment Number : 0000
+
+[080h 0128   1]            Device Scope Type : 02 [PCI Bridge Device]
+[081h 0129   1]                 Entry Length : 08
+[082h 0130   2]                     Reserved : 0000
+[084h 0132   1]               Enumeration ID : 00
+[085h 0133   1]               PCI Bus Number : 00

+
+[086h 0134 2] PCI Path : 02,00
+
+

---
 tests/qtest/bios-tables-test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tests/qtest/bios-tables-test.c +2 -1
index 7c5f736b51..dc79eafbb5 100644
@@ -1141,7 +1141,8 @@ static void test_acpi_q35_kvm_dmar(void)
     data.machine = MACHINE_Q35;
     data.variant = ".dmar";
     test_acpi_one("-machine kernel-irqchip=split -accel kvm"
-                  " -device intel-iommu,intremap=on,device-iotlb=on", &data);
+                  " -device intel-iommu,intremap=on,device-iotlb=on"
+                  " -device pcie-root-port,bus=pcie.0", &data);
     free_test_data(&data);
 }
 
Signature · 1 line
2.25.1
author
#7 lore raw

PATCH 4/4 tests/acpi/bios-tables-test: update DSDT and DMAR table blobs

In reply to Ani Sinha

Changes include explicit addition of pcie root ports in the ATS capability reporting structure and addition of a single pcie root port device in the DMAR bios table tests.

The following DSDT and DMAR table changes happen as a result of the above changes:

DMAR:

 [000h 0000   4]                    Signature : "DMAR"    [DMA Remapping table]
-[004h 0004   4]                 Table Length : 00000078
+[004h 0004   4]                 Table Length : 00000088
 [008h 0008   1]                     Revision : 01
-[009h 0009   1]                     Checksum : 15
+[009h 0009   1]                     Checksum : DE
 [00Ah 0010   6]                       Oem ID : "BOCHS "
 [010h 0016   8]                 Oem Table ID : "BXPC    "
 [018h 0024   4]                 Oem Revision : 00000001
 [01Ch 0028   4]              Asl Compiler ID : "BXPC"
 [020h 0032   4]        Asl Compiler Revision : 00000001

[024h 0036 1] Host Address Width : 26
[025h 0037 1] Flags : 01
[026h 0038 10] Reserved : 00 00 00 00 00 00 00 00 00 00

 [030h 0048   2]                Subtable Type : 0000 [Hardware Unit Definition]
-[032h 0050   2]                       Length : 0040
+[032h 0050   2]                       Length : 0048
 [034h 0052   1]                        Flags : 00
 [035h 0053   1]                     Reserved : 00
 [036h 0054   2]           PCI Segment Number : 0000
 [038h 0056   8]        Register Base Address : 00000000FED90000
 [040h 0064   1]            Device Scope Type : 03 [IOAPIC Device]
 [041h 0065   1]                 Entry Length : 08
 [042h 0066   2]                     Reserved : 0000
 [044h 0068   1]               Enumeration ID : 00
 [045h 0069   1]               PCI Bus Number : FF

[046h 0070 2] PCI Path : 00,00

[048h 0072 1] Device Scope Type : 01 [PCI Endpoint Device]
@@ -46,60 +46,79 @@

 [04Ah 0074   2]                     Reserved : 0000
 [04Ch 0076   1]               Enumeration ID : 00
 [04Dh 0077   1]               PCI Bus Number : 00

[04Eh 0078 2] PCI Path : 00,00

 [050h 0080   1]            Device Scope Type : 01 [PCI Endpoint Device]
 [051h 0081   1]                 Entry Length : 08
 [052h 0082   2]                     Reserved : 0000
 [054h 0084   1]               Enumeration ID : 00
 [055h 0085   1]               PCI Bus Number : 00

[056h 0086 2] PCI Path : 01,00

-[058h 0088   1]            Device Scope Type : 01 [PCI Endpoint Device]
+[058h 0088   1]            Device Scope Type : 02 [PCI Bridge Device]
 [059h 0089   1]                 Entry Length : 08
 [05Ah 0090   2]                     Reserved : 0000
 [05Ch 0092   1]               Enumeration ID : 00
 [05Dh 0093   1]               PCI Bus Number : 00
-[05Eh 0094   2]                     PCI Path : 1F,00
+[05Eh 0094   2]                     PCI Path : 02,00
 [060h 0096   1]            Device Scope Type : 01 [PCI Endpoint Device]
 [061h 0097   1]                 Entry Length : 08
 [062h 0098   2]                     Reserved : 0000
 [064h 0100   1]               Enumeration ID : 00
 [065h 0101   1]               PCI Bus Number : 00
-[066h 0102   2]                     PCI Path : 1F,02
+[066h 0102   2]                     PCI Path : 1F,00
 [068h 0104   1]            Device Scope Type : 01 [PCI Endpoint Device]
 [069h 0105   1]                 Entry Length : 08
 [06Ah 0106   2]                     Reserved : 0000
 [06Ch 0108   1]               Enumeration ID : 00
 [06Dh 0109   1]               PCI Bus Number : 00
-[06Eh 0110   2]                     PCI Path : 1F,03
+[06Eh 0110   2]                     PCI Path : 1F,02
-[070h 0112   2]                Subtable Type : 0002 [Root Port ATS Capability]
-[072h 0114   2]                       Length : 0008
+[070h 0112   1]            Device Scope Type : 01 [PCI Endpoint Device]
+[071h 0113   1]                 Entry Length : 08
+[072h 0114   2]                     Reserved : 0000
+[074h 0116   1]               Enumeration ID : 00
+[075h 0117   1]               PCI Bus Number : 00
-[074h 0116   1]                        Flags : 01
-[075h 0117   1]                     Reserved : 00
-[076h 0118   2]           PCI Segment Number : 0000
+[076h 0118   2]                     PCI Path : 1F,03

-Raw Table Data: Length 120 (0x78)

- 0000: 44 4D 41 52 78 00 00 00 01 15 42 4F 43 48 53 20 // DMARx.....BOCHS
+[078h 0120 2] Subtable Type : 0002 [Root Port ATS Capability]
+[07Ah 0122 2] Length : 0010
+

+[07Ch 0124   1]                        Flags : 00
+[07Dh 0125   1]                     Reserved : 00
+[07Eh 0126   2]           PCI Segment Number : 0000
+
+[080h 0128   1]            Device Scope Type : 02 [PCI Bridge Device]
+[081h 0129   1]                 Entry Length : 08
+[082h 0130   2]                     Reserved : 0000
+[084h 0132   1]               Enumeration ID : 00
+[085h 0133   1]               PCI Bus Number : 00

+
+[086h 0134 2] PCI Path : 02,00
+

DSDT:

DefinitionBlock ("", "DSDT", 1, "BOCHS ", "BXPC ", 0x00000001)

 {
     Scope (\)
     {
         OperationRegion (DBG, SystemIO, 0x0402, One)
         Field (DBG, ByteAcc, NoLock, Preserve)
         {
             DBGB,   8
         }

@@ -3261,23 +3261,59 @@

                 Method (_S1D, 0, NotSerialized)  // _S1D: S1 Device State
                 {
                     Return (Zero)
                 }

                 Method (_S2D, 0, NotSerialized)  // _S2D: S2 Device State
                 {
                     Return (Zero)
                 }

                 Method (_S3D, 0, NotSerialized)  // _S3D: S3 Device State
                 {
                     Return (Zero)
                 }
             }

+ Device (S10)
+ {

+                Name (_ADR, 0x00020000)  // _ADR: Address
+                Name (BSEL, Zero)
+                Device (S00)
+                {
+                    Name (_SUN, Zero)  // _SUN: Slot User Number
+                    Name (_ADR, Zero)  // _ADR: Address
+                    Method (_EJ0, 1, NotSerialized)  // _EJx: Eject Device, x=0-9
+                    {

+ PCEJ (BSEL, _SUN)
+ }
+
+ Method (_DSM, 4, Serialized) // _DSM: Device-Specific Method
+ {
+ Return (PDSM (Arg0, Arg1, Arg2, Arg3, BSEL, _SUN))
+ }
+ }
+
+ Method (DVNT, 2, NotSerialized)
+ {
+ If ((Arg0 & One))
+ {
+ Notify (S00, Arg1)
+ }
+ }
+
+ Method (PCNT, 0, NotSerialized)
+ {

+                    BNUM = Zero
+                    DVNT (PCIU, One)
+                    DVNT (PCID, 0x03)

+ }
+ }
+
Method (PCNT, 0, NotSerialized)
{
+ ^S10.PCNT ()

             }
         }
     }

}

---
 tests/data/acpi/q35/DMAR.dmar               | Bin 120 -> 136 bytes
 tests/data/acpi/q35/DSDT.dmar               | Bin 0 -> 8421 bytes
 tests/qtest/bios-tables-test-allowed-diff.h |   2 --
 3 files changed, 2 deletions(-)
tests/data/acpi/q35/DMAR.dmar binary +0 -0
index 0dca6e68ad8a8ca5b981bcfbc745385a63e9f216..1c1a935ddab174059b8570f67f3b4cfbe3df2193 100644
GIT binary patch
tests/data/acpi/q35/DSDT.dmar binary +0 -0
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..a1f0285904f62c0de437fbbae5a7bccbdd6c669a 100644
GIT binary patch
tests/qtest/bios-tables-test-allowed-diff.h +0 -2
index 4efed12b59..dfb8523c8b 100644
@@ -1,3 +1 @@
 /* List of comma-separated changed AML files to ignore */
-"tests/data/acpi/q35/DSDT.dmar",
-"tests/data/acpi/q35/DMAR.dmar",
Signature · 1 line
2.25.1