Skip to contentSkip to conversation

qtest/bios-tables: Add DMAR unit test on intel_iommu for q35

PATCH In review Vasilis Liaskovitis 2 participants 3 messages Nov 24, 2014 – Dec 2, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 qtest/bios-tables: Add DMAR unit test on intel_iommu for q35

The test enables intel_iommu on q35, looks for and reads the DMAR table as well as its only DRHC structure (for now), checking the header and checksums.

---
 tests/bios-tables-test.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)
tests/bios-tables-test.c +45 -1
index 9e4d205..93b4b3f 100644
@@ -45,6 +45,8 @@ typedef struct {
     AcpiRsdtDescriptorRev1 rsdt_table;
     AcpiFadtDescriptorRev1 fadt_table;
     AcpiFacsDescriptorRev1 facs_table;
+    AcpiTableDmar dmar_table;
+    AcpiDmarHardwareUnit drhd;
     uint32_t *rsdt_tables_addr;
     int rsdt_tables_nr;
     GArray *tables;
@@ -371,6 +373,45 @@ static void test_acpi_dsdt_table(test_data *data)
     g_array_append_val(data->tables, dsdt_table);
 }
 
+static void test_acpi_dmar_table(test_data *data)
+{
+    AcpiTableDmar *dmar_table = &data->dmar_table;
+    AcpiDmarHardwareUnit *drhd = &data->drhd;
+    struct AcpiTableHeader *header = (struct AcpiTableHeader *) dmar_table;
+    uint32_t addr, signature_le;
+    bool found_dmar = false;
+    char signature_str[5] = {};
+    int i;
+
+    memset(dmar_table, 0, sizeof(*dmar_table));
+
+    /* look for DMAR signature in the tables, FADT comes first so we skip it */
+    for (i = 1; i < data->rsdt_tables_nr; i++) {
+        addr = data->rsdt_tables_addr[i];
+        ACPI_READ_TABLE_HEADER(dmar_table, addr);
+        signature_le = cpu_to_le32(header->signature);
+        memcpy(signature_str, &signature_le, 4);
+        if (!g_strcmp0(signature_str, "DMAR")) {
+            found_dmar = true;
+            break;
+        }
+    }
+    g_assert(found_dmar);
+    ACPI_READ_FIELD(dmar_table->host_address_width, addr);
+    ACPI_READ_FIELD(dmar_table->flags, addr);
+    ACPI_READ_ARRAY_PTR(dmar_table->reserved, 10, addr);
+
+    memset(drhd, 0, sizeof(*drhd));
+    ACPI_READ_FIELD(drhd->type, addr);
+    ACPI_READ_FIELD(drhd->length, addr);
+    ACPI_READ_FIELD(drhd->flags, addr);
+    ACPI_READ_FIELD(drhd->pci_segment, addr);
+    ACPI_READ_FIELD(drhd->address, addr);
+    g_assert(!acpi_checksum((uint8_t *)dmar_table, sizeof(AcpiTableDmar) +
+        drhd->length));
+
+}
+
 static void test_acpi_tables(test_data *data)
 {
     int tables_nr = data->rsdt_tables_nr - 1; /* fadt is first */
@@ -747,6 +788,9 @@ static void test_acpi_one(const char *params, test_data *data)
     test_acpi_fadt_table(data);
     test_acpi_facs_table(data);
     test_acpi_dsdt_table(data);
+    if (strstr(params, "iommu=on")) {
+        test_acpi_dmar_table(data);
+    }
     test_acpi_tables(data);
 
     if (iasl) {
@@ -779,7 +823,7 @@ static void test_acpi_tcg(void)
 
     memset(&data, 0, sizeof(data));
     data.machine = MACHINE_Q35;
-    test_acpi_one("-machine q35,accel=tcg", &data);
+    test_acpi_one("-machine q35,accel=tcg,iommu=on", &data);
     free_test_data(&data);
 }
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 2 lines · Vasilis Liaskovitis

The test enables intel_iommu on q35, looks for and reads the DMAR table as well as its only DRHC structure (for now), checking the header and checksums.

Hi Vaisilis,
I had a deeper look to your patch and the code already checks header and checksum for DMAR, all you had to do is to add your latest chunk:

@@ -779,7 +823,7 @@ static void test_acpi_tcg(void)

tests/bios-tables-test.c static void test_acpi_tcg(void) · line 827

Quoted 6 lines
 
     memset(&data, 0, sizeof(data));
     data.machine = MACHINE_Q35;
tests/bios-tables-test.c +1 -1
-    test_acpi_one("-machine q35,accel=tcg", &data);
+    test_acpi_one("-machine q35,accel=tcg,iommu=on", &data);
     free_test_data(&data);

You can check that it is automatically done by test_dst_table function. You can add there a print to convince yourself.

However what is missing is a DMAR binary table to compare the content with an expected one. You can create it by running:
tests/acpi-test-data/rebuild-expected-aml.sh

Then add the newly created file to tests/acpi-test-data/q35/DMAR

Thanks,
Marcel

Quoted 84 lines
---
 tests/bios-tables-test.c | 46 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 45 insertions(+), 1 deletion(-)
tests/bios-tables-test.c +45 -1
index 9e4d205..93b4b3f 100644
@@ -45,6 +45,8 @@ typedef struct {
     AcpiRsdtDescriptorRev1 rsdt_table;
     AcpiFadtDescriptorRev1 fadt_table;
     AcpiFacsDescriptorRev1 facs_table;
+    AcpiTableDmar dmar_table;
+    AcpiDmarHardwareUnit drhd;
     uint32_t *rsdt_tables_addr;
     int rsdt_tables_nr;
     GArray *tables;
@@ -371,6 +373,45 @@ static void test_acpi_dsdt_table(test_data *data)
     g_array_append_val(data->tables, dsdt_table);
 }
 
+static void test_acpi_dmar_table(test_data *data)
+{
+    AcpiTableDmar *dmar_table = &data->dmar_table;
+    AcpiDmarHardwareUnit *drhd = &data->drhd;
+    struct AcpiTableHeader *header = (struct AcpiTableHeader *) dmar_table;
+    uint32_t addr, signature_le;
+    bool found_dmar = false;
+    char signature_str[5] = {};
+    int i;
+
+    memset(dmar_table, 0, sizeof(*dmar_table));
+
+    /* look for DMAR signature in the tables, FADT comes first so we skip it */
+    for (i = 1; i < data->rsdt_tables_nr; i++) {
+        addr = data->rsdt_tables_addr[i];
+        ACPI_READ_TABLE_HEADER(dmar_table, addr);
+        signature_le = cpu_to_le32(header->signature);
+        memcpy(signature_str, &signature_le, 4);
+        if (!g_strcmp0(signature_str, "DMAR")) {
+            found_dmar = true;
+            break;
+        }
+    }
+    g_assert(found_dmar);
+    ACPI_READ_FIELD(dmar_table->host_address_width, addr);
+    ACPI_READ_FIELD(dmar_table->flags, addr);
+    ACPI_READ_ARRAY_PTR(dmar_table->reserved, 10, addr);
+
+    memset(drhd, 0, sizeof(*drhd));
+    ACPI_READ_FIELD(drhd->type, addr);
+    ACPI_READ_FIELD(drhd->length, addr);
+    ACPI_READ_FIELD(drhd->flags, addr);
+    ACPI_READ_FIELD(drhd->pci_segment, addr);
+    ACPI_READ_FIELD(drhd->address, addr);
+    g_assert(!acpi_checksum((uint8_t *)dmar_table, sizeof(AcpiTableDmar) +
+        drhd->length));
+
+}
+
 static void test_acpi_tables(test_data *data)
 {
     int tables_nr = data->rsdt_tables_nr - 1; /* fadt is first */
@@ -747,6 +788,9 @@ static void test_acpi_one(const char *params, test_data *data)
     test_acpi_fadt_table(data);
     test_acpi_facs_table(data);
     test_acpi_dsdt_table(data);
+    if (strstr(params, "iommu=on")) {
+        test_acpi_dmar_table(data);
+    }
     test_acpi_tables(data);
 
     if (iasl) {
@@ -779,7 +823,7 @@ static void test_acpi_tcg(void)
 
     memset(&data, 0, sizeof(data));
     data.machine = MACHINE_Q35;
-    test_acpi_one("-machine q35,accel=tcg", &data);
+    test_acpi_one("-machine q35,accel=tcg,iommu=on", &data);
     free_test_data(&data);
 }
 
#2 lore raw
Quoted 16 lines · Marcel Apfelbaum
Quoted 2 lines · Vasilis Liaskovitis

The test enables intel_iommu on q35, looks for and reads the DMAR table as well as its only DRHC structure (for now), checking the header and checksums.

Hi Vaisilis,
I had a deeper look to your patch and the code already checks header and checksum for DMAR, all you had to do is to add your latest chunk:

(quoted diff) +0 -0
@@ -779,7 +823,7 @@ static void test_acpi_tcg(void)

tests/bios-tables-test.c static void test_acpi_tcg(void) · line 827

Quoted 6 lines
 
     memset(&data, 0, sizeof(data));
     data.machine = MACHINE_Q35;
tests/bios-tables-test.c +1 -1
-    test_acpi_one("-machine q35,accel=tcg", &data);
+    test_acpi_one("-machine q35,accel=tcg,iommu=on", &data);
     free_test_data(&data);
Quoted 8 lines

You can check that it is automatically done by test_dst_table function. You can add there a print to convince yourself.

However what is missing is a DMAR binary table to compare the content with an expected one. You can create it by running:
tests/acpi-test-data/rebuild-expected-aml.sh

Then add the newly created file to tests/acpi-test-data/q35/DMAR

sorry for the delay. thanks, I missed this. I sent v3 simply with the addition of the DMAR aml file and just the "iommu=on" chunk, as you suggested.

- Vasilis