All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v4 0/8] hw: acpi: RSDP fixes and refactoring
@ 2018-12-17 10:48 Samuel Ortiz
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 1/8] hw: acpi: The RSDP build API can return void Samuel Ortiz
                   ` (8 more replies)
  0 siblings, 9 replies; 20+ messages in thread
From: Samuel Ortiz @ 2018-12-17 10:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Peter Maydell, Marcel Apfelbaum,
	Richard Henderson, Michael S. Tsirkin, Ben Warren, Shannon Zhao,
	qemu-arm, Igor Mammedov, Eduardo Habkost, Paolo Bonzini

This patch serie fixes a couple of RSDP checksum related issues:

- On RSDP rev2, we are not adding the extended checksum and computing
  the checksum on the full table instead of the first 20 bytes.
- On RSDP rev1, we are computing the checksum on 36 bytes instead of 20.
  We're lucky enough that this is only adding zeroes to the checksum.

A guest Linux kernel does not seem to care about RSDP checksums, so
those 2 fixes are mostly for correctness sake.
Any machine type that generates rev2 RSDP will see its RSDP table
modified but since x86 builds RSDP v1 and all ACPI tests only run on
either pc or q35, the ACPI tests tables are not affected by this fix.

The serie also extends the ARM virt ACPI RSDP build routine to support
both RSDP v1 and v2, in order to share this code between x86 and
aarch64. While extending, we also convert the routine to the latest
build_append_foo() API. The new implementation is a closer reflection of
the ACPI spec itself, is endian agnostic and allows for getting rid of the
AcpiRsdpDescriptor structure.

V3 -> V4:
  * Add missing Reviewed-Bys from Igor and Andrew.
  * Removed unneeded white space addition.
  * Added 16 bytes padding to revision 0 RSDP structures for legacy (2.2
    and older) machine types.
  * Fixed a missing break in an ACPI RSDP test switch.

V2 -> V3:
  * Add Reviewed-Bys from Igor and Andrew.
  * Check for valid RSDP and XSDT pointers depending on the revision.
  * Use RSDP initial table len as offset for checksum and pointer
    insertion.
  * Do not explictly pass RSDP revision as the RSDP table parsing test
    utility.

v1 -> v2:
  * Add missing SOBs.
  * Rephrase some commit messages according to the maintainer's input.
  * Replace ACPI spec definitions with hard coded constants.
  * Replace init_rsdp_data() helper with open coded rsdp variable init.
  * Rename acpi_find_[rx]sdt_address to acpi_get_[rx]sdt_address.

Igor Mammedov (2):
  hw: arm: acpi: Fix incorrect checksums in RSDP
  hw: i386: Use correct RSDT length for checksum

Samuel Ortiz (6):
  hw: acpi: The RSDP build API can return void
  hw: arm: Carry RSDP specific data through AcpiRsdpData
  hw: arm: Convert the RSDP build to the buid_append_foo() API
  hw: arm: Support both legacy and current RSDP build
  hw: acpi: Export and share the ARM RSDP build
  hw: acpi: Remove AcpiRsdpDescriptor and fix tests

 include/hw/acpi/acpi-defs.h | 19 ++++-------
 include/hw/acpi/aml-build.h |  2 ++
 tests/acpi-utils.h          |  4 ++-
 hw/acpi/aml-build.c         | 68 +++++++++++++++++++++++++++++++++++++
 hw/arm/virt-acpi-build.c    | 40 +++++-----------------
 hw/i386/acpi-build.c        | 46 +++++++++++--------------
 tests/acpi-utils.c          | 46 ++++++++++++++++++++-----
 tests/bios-tables-test.c    | 22 +++++++++---
 tests/vmgenid-test.c        |  8 +++--
 9 files changed, 168 insertions(+), 87 deletions(-)

-- 
2.19.2

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v4 1/8] hw: acpi: The RSDP build API can return void
  2018-12-17 10:48 [Qemu-devel] [PATCH v4 0/8] hw: acpi: RSDP fixes and refactoring Samuel Ortiz
@ 2018-12-17 10:48 ` Samuel Ortiz
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 2/8] hw: arm: acpi: Fix incorrect checksums in RSDP Samuel Ortiz
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Samuel Ortiz @ 2018-12-17 10:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Peter Maydell, Marcel Apfelbaum,
	Richard Henderson, Michael S. Tsirkin, Ben Warren, Shannon Zhao,
	qemu-arm, Igor Mammedov, Eduardo Habkost, Paolo Bonzini

For both x86 and ARM architectures, the internal RSDP build API can
return void as the current return value is unused.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
---
 hw/arm/virt-acpi-build.c | 4 +---
 hw/i386/acpi-build.c     | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 5785fb697c..fcaa350892 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -367,7 +367,7 @@ static void acpi_dsdt_add_power_button(Aml *scope)
 }
 
 /* RSDP */
-static GArray *
+static void
 build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned xsdt_tbl_offset)
 {
     AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
@@ -392,8 +392,6 @@ build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned xsdt_tbl_offset)
     bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
         (char *)rsdp - rsdp_table->data, sizeof *rsdp,
         (char *)&rsdp->checksum - rsdp_table->data);
-
-    return rsdp_table;
 }
 
 static void
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 236a20eaa8..35f17d0d91 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -2547,7 +2547,7 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker)
                  "IVRS", table_data->len - iommu_start, 1, NULL, NULL);
 }
 
-static GArray *
+static void
 build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned rsdt_tbl_offset)
 {
     AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
@@ -2569,8 +2569,6 @@ build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned rsdt_tbl_offset)
     bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
         (char *)rsdp - rsdp_table->data, sizeof *rsdp,
         (char *)&rsdp->checksum - rsdp_table->data);
-
-    return rsdp_table;
 }
 
 typedef
-- 
2.19.2

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v4 2/8] hw: arm: acpi: Fix incorrect checksums in RSDP
  2018-12-17 10:48 [Qemu-devel] [PATCH v4 0/8] hw: acpi: RSDP fixes and refactoring Samuel Ortiz
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 1/8] hw: acpi: The RSDP build API can return void Samuel Ortiz
@ 2018-12-17 10:48 ` Samuel Ortiz
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 3/8] hw: i386: Use correct RSDT length for checksum Samuel Ortiz
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Samuel Ortiz @ 2018-12-17 10:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Peter Maydell, Marcel Apfelbaum,
	Richard Henderson, Michael S. Tsirkin, Ben Warren, Shannon Zhao,
	qemu-arm, Igor Mammedov, Eduardo Habkost, Paolo Bonzini,
	Ard Biesheuvel

From: Igor Mammedov <imammedo@redhat.com>

When RSDP table was introduced (d4bec5d87), we calculated only legacy
checksum, and that was incorrect as it
 - specified rev=2 and forgot about extended checksum.
 - legacy checksum calculated on full table instead of the 1st 20 bytes

Fix it by adding extended checksum calculation and using correct
size for legacy checksum.

While at it use explicit constants to specify sub/full tables
sizes instead of relying on AcpiRsdpDescriptor size and fields offsets.
The follow up commits will convert this table to build_append_int_noprefix() API,
will use constants anyway and remove unused AcpiRsdpDescriptor structure.

Based on "[PATCH v5 05/24] hw: acpi: Implement XSDT support for  RSDP"
by Samuel Ortiz, who did it right in his impl.

Fixes: d4bec5d87 (hw/arm/virt-acpi-build: Generate RSDP table)
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
CC: Ard Biesheuvel <ard.biesheuvel@linaro.org>
CC: Shannon Zhao <shannon.zhaosl@gmail.com>
Reviewed-by: Samuel Ortiz <sameo@linux.intel.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
---
 hw/arm/virt-acpi-build.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index fcaa350892..0835900052 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -390,8 +390,13 @@ build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned xsdt_tbl_offset)
 
     /* Checksum to be filled by Guest linker */
     bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-        (char *)rsdp - rsdp_table->data, sizeof *rsdp,
+        (char *)rsdp - rsdp_table->data, 20 /* ACPI rev 1.0 RSDP size */,
         (char *)&rsdp->checksum - rsdp_table->data);
+
+    /* Extended checksum to be filled by Guest linker */
+    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
+        (char *)rsdp - rsdp_table->data, 36 /* ACPI rev 2.0 RSDP size */,
+        (char *)&rsdp->extended_checksum - rsdp_table->data);
 }
 
 static void
-- 
2.19.2

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v4 3/8] hw: i386: Use correct RSDT length for checksum
  2018-12-17 10:48 [Qemu-devel] [PATCH v4 0/8] hw: acpi: RSDP fixes and refactoring Samuel Ortiz
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 1/8] hw: acpi: The RSDP build API can return void Samuel Ortiz
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 2/8] hw: arm: acpi: Fix incorrect checksums in RSDP Samuel Ortiz
@ 2018-12-17 10:48 ` Samuel Ortiz
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 4/8] hw: arm: Carry RSDP specific data through AcpiRsdpData Samuel Ortiz
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Samuel Ortiz @ 2018-12-17 10:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Peter Maydell, Marcel Apfelbaum,
	Richard Henderson, Michael S. Tsirkin, Ben Warren, Shannon Zhao,
	qemu-arm, Igor Mammedov, Eduardo Habkost, Paolo Bonzini

From: Igor Mammedov <imammedo@redhat.com>

AcpiRsdpDescriptor describes revision 2 RSDP table so using sizeof(*rsdp)
for checksum calculation isn't correct since we are adding extra 16 bytes.
But acpi_data_push() zeroes out table, so just by luck we are summing up
exta zeros which still yelds correct checksum.

Fix it up by explicitly stating table size instead of using
pointer arithmetics on stucture.

PS:
Extra 16 bytes are still wasted, but droping them will break migration
for machines older than 2.3 due to size mismatch, for 2.3 and older it's
not an issue since they are using resizable memory regions (a1666142d)
for ACPI blobs. So keep wasting memory to avoid breaking old machines.

Fixes: 72c194f7e (i386: ACPI table generation code from seabios)
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Samuel Ortiz <sameo@linux.intel.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
---
 hw/i386/acpi-build.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 35f17d0d91..fb877648ac 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -2550,6 +2550,11 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker)
 static void
 build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned rsdt_tbl_offset)
 {
+    /* AcpiRsdpDescriptor describes revision 2 RSDP table and as result we
+     * allocate extra 16 bytes for pc/q35 RSDP rev1 as well. Keep extra 16 bytes
+     * wasted to make sure we won't breake migration for machine types older
+     * than 2.3 due to size mismatch.
+     */
     AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
     unsigned rsdt_pa_size = sizeof(rsdp->rsdt_physical_address);
     unsigned rsdt_pa_offset =
@@ -2567,7 +2572,7 @@ build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned rsdt_tbl_offset)
 
     /* Checksum to be filled by Guest linker */
     bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-        (char *)rsdp - rsdp_table->data, sizeof *rsdp,
+        (char *)rsdp - rsdp_table->data, 20 /* ACPI rev 1.0 RSDP size */,
         (char *)&rsdp->checksum - rsdp_table->data);
 }
 
-- 
2.19.2

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v4 4/8] hw: arm: Carry RSDP specific data through AcpiRsdpData
  2018-12-17 10:48 [Qemu-devel] [PATCH v4 0/8] hw: acpi: RSDP fixes and refactoring Samuel Ortiz
                   ` (2 preceding siblings ...)
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 3/8] hw: i386: Use correct RSDT length for checksum Samuel Ortiz
@ 2018-12-17 10:48 ` Samuel Ortiz
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 5/8] hw: arm: Convert the RSDP build to the buid_append_foo() API Samuel Ortiz
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Samuel Ortiz @ 2018-12-17 10:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Peter Maydell, Marcel Apfelbaum,
	Richard Henderson, Michael S. Tsirkin, Ben Warren, Shannon Zhao,
	qemu-arm, Igor Mammedov, Eduardo Habkost, Paolo Bonzini

That will allow us to generalize the ARM build_rsdp() routine to support
both legacy RSDP (The current i386 implementation) and extended RSDP
(The ARM implementation).

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
---
 include/hw/acpi/acpi-defs.h |  8 ++++++++
 hw/arm/virt-acpi-build.c    | 18 +++++++++++++-----
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
index af8e023968..8425ecb8c6 100644
--- a/include/hw/acpi/acpi-defs.h
+++ b/include/hw/acpi/acpi-defs.h
@@ -53,6 +53,14 @@ struct AcpiRsdpDescriptor {        /* Root System Descriptor Pointer */
 } QEMU_PACKED;
 typedef struct AcpiRsdpDescriptor AcpiRsdpDescriptor;
 
+typedef struct AcpiRsdpData {
+    uint8_t oem_id[6]; /* OEM identification */
+    uint8_t revision;  /* Must be 0 for 1.0, 2 for 2.0 */
+
+    unsigned *rsdt_tbl_offset;
+    unsigned *xsdt_tbl_offset;
+} AcpiRsdpData;
+
 /* Table structure from Linux kernel (the ACPI tables are under the
    BSD license) */
 
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 0835900052..ce8bfa5a37 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -368,7 +368,7 @@ static void acpi_dsdt_add_power_button(Aml *scope)
 
 /* RSDP */
 static void
-build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned xsdt_tbl_offset)
+build_rsdp(GArray *rsdp_table, BIOSLinker *linker, AcpiRsdpData *rsdp_data)
 {
     AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
     unsigned xsdt_pa_size = sizeof(rsdp->xsdt_physical_address);
@@ -379,14 +379,14 @@ build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned xsdt_tbl_offset)
                              true /* fseg memory */);
 
     memcpy(&rsdp->signature, "RSD PTR ", sizeof(rsdp->signature));
-    memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, sizeof(rsdp->oem_id));
+    memcpy(rsdp->oem_id, rsdp_data->oem_id, sizeof(rsdp->oem_id));
     rsdp->length = cpu_to_le32(sizeof(*rsdp));
-    rsdp->revision = 0x02;
+    rsdp->revision = rsdp_data->revision;
 
     /* Address to be filled by Guest linker */
     bios_linker_loader_add_pointer(linker,
         ACPI_BUILD_RSDP_FILE, xsdt_pa_offset, xsdt_pa_size,
-        ACPI_BUILD_TABLE_FILE, xsdt_tbl_offset);
+        ACPI_BUILD_TABLE_FILE, *rsdp_data->xsdt_tbl_offset);
 
     /* Checksum to be filled by Guest linker */
     bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
@@ -857,7 +857,15 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)
     build_xsdt(tables_blob, tables->linker, table_offsets, NULL, NULL);
 
     /* RSDP is in FSEG memory, so allocate it separately */
-    build_rsdp(tables->rsdp, tables->linker, xsdt);
+    {
+        AcpiRsdpData rsdp_data = {
+            .revision = 2,
+            .oem_id = ACPI_BUILD_APPNAME6,
+            .xsdt_tbl_offset = &xsdt,
+            .rsdt_tbl_offset = NULL,
+        };
+        build_rsdp(tables->rsdp, tables->linker, &rsdp_data);
+    }
 
     /* Cleanup memory that's no longer used. */
     g_array_free(table_offsets, true);
-- 
2.19.2

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v4 5/8] hw: arm: Convert the RSDP build to the buid_append_foo() API
  2018-12-17 10:48 [Qemu-devel] [PATCH v4 0/8] hw: acpi: RSDP fixes and refactoring Samuel Ortiz
                   ` (3 preceding siblings ...)
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 4/8] hw: arm: Carry RSDP specific data through AcpiRsdpData Samuel Ortiz
@ 2018-12-17 10:48 ` Samuel Ortiz
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 6/8] hw: arm: Support both legacy and current RSDP build Samuel Ortiz
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Samuel Ortiz @ 2018-12-17 10:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Peter Maydell, Marcel Apfelbaum,
	Richard Henderson, Michael S. Tsirkin, Ben Warren, Shannon Zhao,
	qemu-arm, Igor Mammedov, Eduardo Habkost, Paolo Bonzini

Instead of filling a mapped and packed C structure field in random order
and being careful about endianness and sizes, build_rsdp() now uses
build_append_int_noprefix() to compose RSDP table.

This makes reviewing and maintaining code easier as this is almost
matching 1:1 the ACPI spec itself.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
---
 hw/arm/virt-acpi-build.c | 42 ++++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index ce8bfa5a37..4a6b53fbfc 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -368,35 +368,39 @@ static void acpi_dsdt_add_power_button(Aml *scope)
 
 /* RSDP */
 static void
-build_rsdp(GArray *rsdp_table, BIOSLinker *linker, AcpiRsdpData *rsdp_data)
+build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data)
 {
-    AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
-    unsigned xsdt_pa_size = sizeof(rsdp->xsdt_physical_address);
-    unsigned xsdt_pa_offset =
-        (char *)&rsdp->xsdt_physical_address - rsdp_table->data;
+    int tbl_off = tbl->len; /* Table offset in the RSDP file */
 
-    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, rsdp_table, 16,
+    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, tbl, 16,
                              true /* fseg memory */);
 
-    memcpy(&rsdp->signature, "RSD PTR ", sizeof(rsdp->signature));
-    memcpy(rsdp->oem_id, rsdp_data->oem_id, sizeof(rsdp->oem_id));
-    rsdp->length = cpu_to_le32(sizeof(*rsdp));
-    rsdp->revision = rsdp_data->revision;
+    g_array_append_vals(tbl, "RSD PTR ", 8); /* Signature */
+    build_append_int_noprefix(tbl, 0, 1); /* Checksum */
+    g_array_append_vals(tbl, rsdp_data->oem_id, 6); /* OEMID */
+    build_append_int_noprefix(tbl, rsdp_data->revision, 1); /* Revision */
+    build_append_int_noprefix(tbl, 0, 4); /* RsdtAddress */
+    build_append_int_noprefix(tbl, 36, 4); /* Length */
 
-    /* Address to be filled by Guest linker */
-    bios_linker_loader_add_pointer(linker,
-        ACPI_BUILD_RSDP_FILE, xsdt_pa_offset, xsdt_pa_size,
-        ACPI_BUILD_TABLE_FILE, *rsdp_data->xsdt_tbl_offset);
+    /* XSDT address to be filled by guest linker */
+    build_append_int_noprefix(tbl, 0, 8); /* XsdtAddress */
+    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
+                                   tbl_off + 24, 8,
+                                   ACPI_BUILD_TABLE_FILE,
+                                   *rsdp_data->xsdt_tbl_offset);
 
-    /* Checksum to be filled by Guest linker */
+    build_append_int_noprefix(tbl, 0, 1); /* Extended Checksum */
+    build_append_int_noprefix(tbl, 0, 3); /* Reserved */
+
+    /* Checksum to be filled by guest linker */
     bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-        (char *)rsdp - rsdp_table->data, 20 /* ACPI rev 1.0 RSDP size */,
-        (char *)&rsdp->checksum - rsdp_table->data);
+                                    tbl_off, 20, /* ACPI rev 1.0 RSDP size */
+                                    8);
 
     /* Extended checksum to be filled by Guest linker */
     bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-        (char *)rsdp - rsdp_table->data, 36 /* ACPI rev 2.0 RSDP size */,
-        (char *)&rsdp->extended_checksum - rsdp_table->data);
+                                    tbl_off, 36, /* ACPI rev 2.0 RSDP size */
+                                    32);
 }
 
 static void
-- 
2.19.2

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v4 6/8] hw: arm: Support both legacy and current RSDP build
  2018-12-17 10:48 [Qemu-devel] [PATCH v4 0/8] hw: acpi: RSDP fixes and refactoring Samuel Ortiz
                   ` (4 preceding siblings ...)
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 5/8] hw: arm: Convert the RSDP build to the buid_append_foo() API Samuel Ortiz
@ 2018-12-17 10:48 ` Samuel Ortiz
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 7/8] hw: acpi: Export and share the ARM " Samuel Ortiz
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Samuel Ortiz @ 2018-12-17 10:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Peter Maydell, Marcel Apfelbaum,
	Richard Henderson, Michael S. Tsirkin, Ben Warren, Shannon Zhao,
	qemu-arm, Igor Mammedov, Eduardo Habkost, Paolo Bonzini

We add the ability to build legacy or current RSDP tables, based on the
AcpiRsdpData revision field passed to build_rsdp().
Although arm/virt only uses RSDP v2, adding that capability to
build_rsdp will allow us to share the RSDP build code between ARM and x86.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
---
 hw/arm/virt-acpi-build.c | 38 +++++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 4a6b53fbfc..05f6654371 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -372,6 +372,20 @@ build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data)
 {
     int tbl_off = tbl->len; /* Table offset in the RSDP file */
 
+    switch (rsdp_data->revision) {
+    case 0:
+        /* With ACPI 1.0, we must have an RSDT pointer */
+        g_assert(rsdp_data->rsdt_tbl_offset);
+        break;
+    case 2:
+        /* With ACPI 2.0+, we must have an XSDT pointer */
+        g_assert(rsdp_data->xsdt_tbl_offset);
+        break;
+    default:
+        /* Only revisions 0 (ACPI 1.0) and 2 (ACPI 2.0+) are valid for RSDP */
+        g_assert_not_reached();
+    }
+
     bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, tbl, 16,
                              true /* fseg memory */);
 
@@ -380,10 +394,29 @@ build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data)
     g_array_append_vals(tbl, rsdp_data->oem_id, 6); /* OEMID */
     build_append_int_noprefix(tbl, rsdp_data->revision, 1); /* Revision */
     build_append_int_noprefix(tbl, 0, 4); /* RsdtAddress */
+    if (rsdp_data->rsdt_tbl_offset) {
+        /* RSDT address to be filled by guest linker */
+        bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
+                                       tbl_off + 16, 4,
+                                       ACPI_BUILD_TABLE_FILE,
+                                       *rsdp_data->rsdt_tbl_offset);
+    }
+
+    /* Checksum to be filled by guest linker */
+    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
+                                    tbl_off, 20, /* ACPI rev 1.0 RSDP size */
+                                    8);
+
+    if (rsdp_data->revision == 0) {
+        /* ACPI 1.0 RSDP, we're done */
+        return;
+    }
+
     build_append_int_noprefix(tbl, 36, 4); /* Length */
 
     /* XSDT address to be filled by guest linker */
     build_append_int_noprefix(tbl, 0, 8); /* XsdtAddress */
+    /* We already validated our xsdt pointer */
     bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
                                    tbl_off + 24, 8,
                                    ACPI_BUILD_TABLE_FILE,
@@ -392,11 +425,6 @@ build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data)
     build_append_int_noprefix(tbl, 0, 1); /* Extended Checksum */
     build_append_int_noprefix(tbl, 0, 3); /* Reserved */
 
-    /* Checksum to be filled by guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    tbl_off, 20, /* ACPI rev 1.0 RSDP size */
-                                    8);
-
     /* Extended checksum to be filled by Guest linker */
     bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
                                     tbl_off, 36, /* ACPI rev 2.0 RSDP size */
-- 
2.19.2

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v4 7/8] hw: acpi: Export and share the ARM RSDP build
  2018-12-17 10:48 [Qemu-devel] [PATCH v4 0/8] hw: acpi: RSDP fixes and refactoring Samuel Ortiz
                   ` (5 preceding siblings ...)
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 6/8] hw: arm: Support both legacy and current RSDP build Samuel Ortiz
@ 2018-12-17 10:48 ` Samuel Ortiz
  2018-12-17 12:20   ` Igor Mammedov
                     ` (2 more replies)
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 8/8] hw: acpi: Remove AcpiRsdpDescriptor and fix tests Samuel Ortiz
  2018-12-18  1:10 ` [Qemu-devel] [PATCH v4 0/8] hw: acpi: RSDP fixes and refactoring Michael S. Tsirkin
  8 siblings, 3 replies; 20+ messages in thread
From: Samuel Ortiz @ 2018-12-17 10:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Peter Maydell, Marcel Apfelbaum,
	Richard Henderson, Michael S. Tsirkin, Ben Warren, Shannon Zhao,
	qemu-arm, Igor Mammedov, Eduardo Habkost, Paolo Bonzini

Now that build_rsdp() supports building both legacy and current RSDP
tables, we can move it to a generic folder (hw/acpi) and have the i386
ACPI code reuse it in order to reduce code duplication.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
---
 include/hw/acpi/aml-build.h |  2 ++
 hw/acpi/aml-build.c         | 68 +++++++++++++++++++++++++++++++++++++
 hw/arm/virt-acpi-build.c    | 65 -----------------------------------
 hw/i386/acpi-build.c        | 49 +++++++++++---------------
 4 files changed, 89 insertions(+), 95 deletions(-)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 6c36903c0a..1a563ad756 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -388,6 +388,8 @@ void acpi_add_table(GArray *table_offsets, GArray *table_data);
 void acpi_build_tables_init(AcpiBuildTables *tables);
 void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre);
 void
+build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data);
+void
 build_rsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets,
            const char *oem_id, const char *oem_table_id);
 void
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 1e43cd736d..555c24f21d 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -1589,6 +1589,74 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre)
     g_array_free(tables->vmgenid, mfre);
 }
 
+/*
+ * ACPI spec 5.2.5.3 Root System Description Pointer (RSDP).
+ * (Revision 1.0 or later)
+ */
+void
+build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data)
+{
+    int tbl_off = tbl->len; /* Table offset in the RSDP file */
+
+    switch (rsdp_data->revision) {
+    case 0:
+        /* With ACPI 1.0, we must have an RSDT pointer */
+        g_assert(rsdp_data->rsdt_tbl_offset);
+        break;
+    case 2:
+        /* With ACPI 2.0+, we must have an XSDT pointer */
+        g_assert(rsdp_data->xsdt_tbl_offset);
+        break;
+    default:
+        /* Only revisions 0 (ACPI 1.0) and 2 (ACPI 2.0+) are valid for RSDP */
+        g_assert_not_reached();
+    }
+
+    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, tbl, 16,
+                             true /* fseg memory */);
+
+    g_array_append_vals(tbl, "RSD PTR ", 8); /* Signature */
+    build_append_int_noprefix(tbl, 0, 1); /* Checksum */
+    g_array_append_vals(tbl, rsdp_data->oem_id, 6); /* OEMID */
+    build_append_int_noprefix(tbl, rsdp_data->revision, 1); /* Revision */
+    build_append_int_noprefix(tbl, 0, 4); /* RsdtAddress */
+    if (rsdp_data->rsdt_tbl_offset) {
+        /* RSDT address to be filled by guest linker */
+        bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
+                                       tbl_off + 16, 4,
+                                       ACPI_BUILD_TABLE_FILE,
+                                       *rsdp_data->rsdt_tbl_offset);
+    }
+
+    /* Checksum to be filled by guest linker */
+    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
+                                    tbl_off, 20, /* ACPI rev 1.0 RSDP size */
+                                    8);
+
+    if (rsdp_data->revision == 0) {
+        /* ACPI 1.0 RSDP, we're done */
+        return;
+    }
+
+    build_append_int_noprefix(tbl, 36, 4); /* Length */
+
+    /* XSDT address to be filled by guest linker */
+    build_append_int_noprefix(tbl, 0, 8); /* XsdtAddress */
+    /* We already validated our xsdt pointer */
+    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
+                                   tbl_off + 24, 8,
+                                   ACPI_BUILD_TABLE_FILE,
+                                   *rsdp_data->xsdt_tbl_offset);
+
+    build_append_int_noprefix(tbl, 0, 1); /* Extended Checksum */
+    build_append_int_noprefix(tbl, 0, 3); /* Reserved */
+
+    /* Extended checksum to be filled by Guest linker */
+    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
+                                    tbl_off, 36, /* ACPI rev 2.0 RSDP size */
+                                    32);
+}
+
 /* Build rsdt table */
 void
 build_rsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets,
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 05f6654371..95fad6f0ce 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -366,71 +366,6 @@ static void acpi_dsdt_add_power_button(Aml *scope)
     aml_append(scope, dev);
 }
 
-/* RSDP */
-static void
-build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data)
-{
-    int tbl_off = tbl->len; /* Table offset in the RSDP file */
-
-    switch (rsdp_data->revision) {
-    case 0:
-        /* With ACPI 1.0, we must have an RSDT pointer */
-        g_assert(rsdp_data->rsdt_tbl_offset);
-        break;
-    case 2:
-        /* With ACPI 2.0+, we must have an XSDT pointer */
-        g_assert(rsdp_data->xsdt_tbl_offset);
-        break;
-    default:
-        /* Only revisions 0 (ACPI 1.0) and 2 (ACPI 2.0+) are valid for RSDP */
-        g_assert_not_reached();
-    }
-
-    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, tbl, 16,
-                             true /* fseg memory */);
-
-    g_array_append_vals(tbl, "RSD PTR ", 8); /* Signature */
-    build_append_int_noprefix(tbl, 0, 1); /* Checksum */
-    g_array_append_vals(tbl, rsdp_data->oem_id, 6); /* OEMID */
-    build_append_int_noprefix(tbl, rsdp_data->revision, 1); /* Revision */
-    build_append_int_noprefix(tbl, 0, 4); /* RsdtAddress */
-    if (rsdp_data->rsdt_tbl_offset) {
-        /* RSDT address to be filled by guest linker */
-        bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
-                                       tbl_off + 16, 4,
-                                       ACPI_BUILD_TABLE_FILE,
-                                       *rsdp_data->rsdt_tbl_offset);
-    }
-
-    /* Checksum to be filled by guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    tbl_off, 20, /* ACPI rev 1.0 RSDP size */
-                                    8);
-
-    if (rsdp_data->revision == 0) {
-        /* ACPI 1.0 RSDP, we're done */
-        return;
-    }
-
-    build_append_int_noprefix(tbl, 36, 4); /* Length */
-
-    /* XSDT address to be filled by guest linker */
-    build_append_int_noprefix(tbl, 0, 8); /* XsdtAddress */
-    /* We already validated our xsdt pointer */
-    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
-                                   tbl_off + 24, 8,
-                                   ACPI_BUILD_TABLE_FILE,
-                                   *rsdp_data->xsdt_tbl_offset);
-
-    build_append_int_noprefix(tbl, 0, 1); /* Extended Checksum */
-    build_append_int_noprefix(tbl, 0, 3); /* Reserved */
-
-    /* Extended checksum to be filled by Guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    tbl_off, 36, /* ACPI rev 2.0 RSDP size */
-                                    32);
-}
-
 static void
 build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
 {
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index fb877648ac..846cb6d755 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -2547,35 +2547,6 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker)
                  "IVRS", table_data->len - iommu_start, 1, NULL, NULL);
 }
 
-static void
-build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned rsdt_tbl_offset)
-{
-    /* AcpiRsdpDescriptor describes revision 2 RSDP table and as result we
-     * allocate extra 16 bytes for pc/q35 RSDP rev1 as well. Keep extra 16 bytes
-     * wasted to make sure we won't breake migration for machine types older
-     * than 2.3 due to size mismatch.
-     */
-    AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
-    unsigned rsdt_pa_size = sizeof(rsdp->rsdt_physical_address);
-    unsigned rsdt_pa_offset =
-        (char *)&rsdp->rsdt_physical_address - rsdp_table->data;
-
-    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, rsdp_table, 16,
-                             true /* fseg memory */);
-
-    memcpy(&rsdp->signature, "RSD PTR ", 8);
-    memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
-    /* Address to be filled by Guest linker */
-    bios_linker_loader_add_pointer(linker,
-        ACPI_BUILD_RSDP_FILE, rsdt_pa_offset, rsdt_pa_size,
-        ACPI_BUILD_TABLE_FILE, rsdt_tbl_offset);
-
-    /* Checksum to be filled by Guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-        (char *)rsdp - rsdp_table->data, 20 /* ACPI rev 1.0 RSDP size */,
-        (char *)&rsdp->checksum - rsdp_table->data);
-}
-
 typedef
 struct AcpiBuildState {
     /* Copy of table in RAM (for patching). */
@@ -2732,7 +2703,25 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
                slic_oem.id, slic_oem.table_id);
 
     /* RSDP is in FSEG memory, so allocate it separately */
-    build_rsdp(tables->rsdp, tables->linker, rsdt);
+    {
+        AcpiRsdpData rsdp_data = {
+            .revision = 0,
+            .oem_id = ACPI_BUILD_APPNAME6,
+            .xsdt_tbl_offset = NULL,
+            .rsdt_tbl_offset = &rsdt,
+        };
+        build_rsdp(tables->rsdp, tables->linker, &rsdp_data);
+        if (!pcmc->rsdp_in_ram) {
+            /*
+             * Legacy machine types (2.2 and older) expect to get a complete
+             * revision 2 RSDP table, even though they only look at the
+             * revision 0 fields (xsdt pointer is not set). So in order to
+             * not break migration to those machine types we waste 16 bytes
+             * that we amend to the RSDP revision 0 structure.
+             */
+            build_append_int_noprefix(tables->rsdp, 0, 16);
+        }
+    }
 
     /* We'll expose it all to Guest so we want to reduce
      * chance of size changes.
-- 
2.19.2

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v4 8/8] hw: acpi: Remove AcpiRsdpDescriptor and fix tests
  2018-12-17 10:48 [Qemu-devel] [PATCH v4 0/8] hw: acpi: RSDP fixes and refactoring Samuel Ortiz
                   ` (6 preceding siblings ...)
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 7/8] hw: acpi: Export and share the ARM " Samuel Ortiz
@ 2018-12-17 10:48 ` Samuel Ortiz
  2018-12-18  1:10 ` [Qemu-devel] [PATCH v4 0/8] hw: acpi: RSDP fixes and refactoring Michael S. Tsirkin
  8 siblings, 0 replies; 20+ messages in thread
From: Samuel Ortiz @ 2018-12-17 10:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Thomas Huth, Peter Maydell, Marcel Apfelbaum,
	Richard Henderson, Michael S. Tsirkin, Ben Warren, Shannon Zhao,
	qemu-arm, Igor Mammedov, Eduardo Habkost, Paolo Bonzini

The only remaining AcpiRsdpDescriptor users are the ACPI utils for the
BIOS table tests.
We remove that dependency and can thus remove the structure itself.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
---
 include/hw/acpi/acpi-defs.h | 13 -----------
 tests/acpi-utils.h          |  4 +++-
 tests/acpi-utils.c          | 46 ++++++++++++++++++++++++++++++-------
 tests/bios-tables-test.c    | 22 ++++++++++++++----
 tests/vmgenid-test.c        |  8 ++++---
 5 files changed, 63 insertions(+), 30 deletions(-)

diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
index 8425ecb8c6..5021cb9e79 100644
--- a/include/hw/acpi/acpi-defs.h
+++ b/include/hw/acpi/acpi-defs.h
@@ -40,19 +40,6 @@ enum {
     ACPI_FADT_F_LOW_POWER_S0_IDLE_CAPABLE,
 };
 
-struct AcpiRsdpDescriptor {        /* Root System Descriptor Pointer */
-    uint64_t signature;              /* ACPI signature, contains "RSD PTR " */
-    uint8_t  checksum;               /* To make sum of struct == 0 */
-    uint8_t  oem_id [6];             /* OEM identification */
-    uint8_t  revision;               /* Must be 0 for 1.0, 2 for 2.0 */
-    uint32_t rsdt_physical_address;  /* 32-bit physical address of RSDT */
-    uint32_t length;                 /* XSDT Length in bytes including hdr */
-    uint64_t xsdt_physical_address;  /* 64-bit physical address of XSDT */
-    uint8_t  extended_checksum;      /* Checksum of entire table */
-    uint8_t  reserved [3];           /* Reserved field must be 0 */
-} QEMU_PACKED;
-typedef struct AcpiRsdpDescriptor AcpiRsdpDescriptor;
-
 typedef struct AcpiRsdpData {
     uint8_t oem_id[6]; /* OEM identification */
     uint8_t revision;  /* Must be 0 for 1.0, 2 for 2.0 */
diff --git a/tests/acpi-utils.h b/tests/acpi-utils.h
index ac52abd0dd..4f4899deb5 100644
--- a/tests/acpi-utils.h
+++ b/tests/acpi-utils.h
@@ -82,6 +82,8 @@ typedef struct {
 
 uint8_t acpi_calc_checksum(const uint8_t *data, int len);
 uint32_t acpi_find_rsdp_address(void);
-void acpi_parse_rsdp_table(uint32_t addr, AcpiRsdpDescriptor *rsdp_table);
+uint32_t acpi_get_rsdt_address(uint8_t *rsdp_table);
+uint64_t acpi_get_xsdt_address(uint8_t *rsdp_table);
+void acpi_parse_rsdp_table(uint32_t addr, uint8_t *rsdp_table);
 
 #endif  /* TEST_ACPI_UTILS_H */
diff --git a/tests/acpi-utils.c b/tests/acpi-utils.c
index 41dc1ea9b4..d07f7487e2 100644
--- a/tests/acpi-utils.c
+++ b/tests/acpi-utils.c
@@ -52,14 +52,44 @@ uint32_t acpi_find_rsdp_address(void)
     return off;
 }
 
-void acpi_parse_rsdp_table(uint32_t addr, AcpiRsdpDescriptor *rsdp_table)
+uint32_t acpi_get_rsdt_address(uint8_t *rsdp_table)
 {
-    ACPI_READ_FIELD(rsdp_table->signature, addr);
-    ACPI_ASSERT_CMP64(rsdp_table->signature, "RSD PTR ");
+    uint32_t rsdt_physical_address;
 
-    ACPI_READ_FIELD(rsdp_table->checksum, addr);
-    ACPI_READ_ARRAY(rsdp_table->oem_id, addr);
-    ACPI_READ_FIELD(rsdp_table->revision, addr);
-    ACPI_READ_FIELD(rsdp_table->rsdt_physical_address, addr);
-    ACPI_READ_FIELD(rsdp_table->length, addr);
+    memcpy(&rsdt_physical_address, &rsdp_table[16 /* RsdtAddress offset */], 4);
+    return le32_to_cpu(rsdt_physical_address);
+}
+
+uint64_t acpi_get_xsdt_address(uint8_t *rsdp_table)
+{
+    uint64_t xsdt_physical_address;
+    uint8_t revision = rsdp_table[15 /* Revision offset */];
+
+    /* We must have revision 2 if we're looking for an XSDT pointer */
+    g_assert(revision == 2);
+
+    memcpy(&xsdt_physical_address, &rsdp_table[24 /* XsdtAddress offset */], 8);
+    return le64_to_cpu(xsdt_physical_address);
+}
+
+void acpi_parse_rsdp_table(uint32_t addr, uint8_t *rsdp_table)
+{
+    uint8_t revision;
+
+    /* Read mandatory revision 0 table data (20 bytes) first */
+    memread(addr, rsdp_table, 20);
+    revision = rsdp_table[15 /* Revision offset */];
+
+    switch (revision) {
+    case 0: /* ACPI 1.0 RSDP */
+        break;
+    case 2: /* ACPI 2.0+ RSDP */
+        /* Read the rest of the RSDP table */
+        memread(addr + 20, rsdp_table + 20, 16);
+        break;
+    default:
+        g_assert_not_reached();
+    }
+
+    ACPI_ASSERT_CMP64(*((uint64_t *)(rsdp_table)), "RSD PTR ");
 }
diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c
index d661d9be62..544a87b55c 100644
--- a/tests/bios-tables-test.c
+++ b/tests/bios-tables-test.c
@@ -27,7 +27,7 @@ typedef struct {
     const char *machine;
     const char *variant;
     uint32_t rsdp_addr;
-    AcpiRsdpDescriptor rsdp_table;
+    uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */];
     AcpiRsdtDescriptorRev1 rsdt_table;
     uint32_t dsdt_addr;
     uint32_t facs_addr;
@@ -85,19 +85,31 @@ static void test_acpi_rsdp_address(test_data *data)
 
 static void test_acpi_rsdp_table(test_data *data)
 {
-    AcpiRsdpDescriptor *rsdp_table = &data->rsdp_table;
+    uint8_t *rsdp_table = data->rsdp_table, revision;
     uint32_t addr = data->rsdp_addr;
 
     acpi_parse_rsdp_table(addr, rsdp_table);
+    revision = rsdp_table[15 /* Revision offset */];
 
-    /* rsdp checksum is not for the whole table, but for the first 20 bytes */
-    g_assert(!acpi_calc_checksum((uint8_t *)rsdp_table, 20));
+    switch (revision) {
+    case 0: /* ACPI 1.0 RSDP */
+        /* With rev 1, checksum is only for the first 20 bytes */
+        g_assert(!acpi_calc_checksum(rsdp_table,  20));
+        break;
+    case 2: /* ACPI 2.0+ RSDP */
+        /* With revision 2, we have 2 checksums */
+        g_assert(!acpi_calc_checksum(rsdp_table, 20));
+        g_assert(!acpi_calc_checksum(rsdp_table, 36));
+        break;
+    default:
+        g_assert_not_reached();
+    }
 }
 
 static void test_acpi_rsdt_table(test_data *data)
 {
     AcpiRsdtDescriptorRev1 *rsdt_table = &data->rsdt_table;
-    uint32_t addr = le32_to_cpu(data->rsdp_table.rsdt_physical_address);
+    uint32_t addr = acpi_get_rsdt_address(data->rsdp_table);
     uint32_t *tables;
     int tables_nr;
     uint8_t checksum;
diff --git a/tests/vmgenid-test.c b/tests/vmgenid-test.c
index 0a6fb55f2e..97219ae86c 100644
--- a/tests/vmgenid-test.c
+++ b/tests/vmgenid-test.c
@@ -35,7 +35,7 @@ static uint32_t acpi_find_vgia(void)
 {
     uint32_t rsdp_offset;
     uint32_t guid_offset = 0;
-    AcpiRsdpDescriptor rsdp_table;
+    uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */];
     uint32_t rsdt, rsdt_table_length;
     AcpiRsdtDescriptorRev1 rsdt_table;
     size_t tables_nr;
@@ -52,9 +52,11 @@ static uint32_t acpi_find_vgia(void)
 
     g_assert_cmphex(rsdp_offset, <, RSDP_ADDR_INVALID);
 
-    acpi_parse_rsdp_table(rsdp_offset, &rsdp_table);
+    acpi_parse_rsdp_table(rsdp_offset, rsdp_table);
+
+    rsdt = acpi_get_rsdt_address(rsdp_table);
+    g_assert(rsdt);
 
-    rsdt = le32_to_cpu(rsdp_table.rsdt_physical_address);
     /* read the header */
     ACPI_READ_TABLE_HEADER(&rsdt_table, rsdt);
     ACPI_ASSERT_CMP(rsdt_table.signature, "RSDT");
-- 
2.19.2

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v4 7/8] hw: acpi: Export and share the ARM RSDP build
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 7/8] hw: acpi: Export and share the ARM " Samuel Ortiz
@ 2018-12-17 12:20   ` Igor Mammedov
  2018-12-17 13:49     ` Samuel Ortiz
  2018-12-17 14:06   ` Samuel Ortiz
  2018-12-17 15:34   ` [Qemu-devel] [PATCH v5 " Samuel Ortiz
  2 siblings, 1 reply; 20+ messages in thread
From: Igor Mammedov @ 2018-12-17 12:20 UTC (permalink / raw)
  To: Samuel Ortiz
  Cc: qemu-devel, Laurent Vivier, Peter Maydell, Thomas Huth,
	Eduardo Habkost, Ben Warren, Michael S. Tsirkin, Shannon Zhao,
	qemu-arm, Paolo Bonzini, Richard Henderson

On Mon, 17 Dec 2018 11:48:37 +0100
Samuel Ortiz <sameo@linux.intel.com> wrote:

> Now that build_rsdp() supports building both legacy and current RSDP
> tables, we can move it to a generic folder (hw/acpi) and have the i386
> ACPI code reuse it in order to reduce code duplication.
> 
> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Reviewed-by: Andrew Jones <drjones@redhat.com>
> Reviewed-by: Igor Mammedov <imammedo@redhat.com>
for future reference, if one changes patch in a significant way,
one is supposed to drop Tested/Reviewed-by tags so that reviewers
would look at it again and we by mistake won't merge not actually
reviewed changes.

[...]

> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index fb877648ac..846cb6d755 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -2547,35 +2547,6 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker)
>                   "IVRS", table_data->len - iommu_start, 1, NULL, NULL);
>  }
>  
> -static void
> -build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned rsdt_tbl_offset)
> -{
> -    /* AcpiRsdpDescriptor describes revision 2 RSDP table and as result we
> -     * allocate extra 16 bytes for pc/q35 RSDP rev1 as well. Keep extra 16 bytes
> -     * wasted to make sure we won't breake migration for machine types older
> -     * than 2.3 due to size mismatch.
> -     */
> -    AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
> -    unsigned rsdt_pa_size = sizeof(rsdp->rsdt_physical_address);
> -    unsigned rsdt_pa_offset =
> -        (char *)&rsdp->rsdt_physical_address - rsdp_table->data;
> -
> -    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, rsdp_table, 16,
> -                             true /* fseg memory */);
> -
> -    memcpy(&rsdp->signature, "RSD PTR ", 8);
> -    memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
> -    /* Address to be filled by Guest linker */
> -    bios_linker_loader_add_pointer(linker,
> -        ACPI_BUILD_RSDP_FILE, rsdt_pa_offset, rsdt_pa_size,
> -        ACPI_BUILD_TABLE_FILE, rsdt_tbl_offset);
> -
> -    /* Checksum to be filled by Guest linker */
> -    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
> -        (char *)rsdp - rsdp_table->data, 20 /* ACPI rev 1.0 RSDP size */,
> -        (char *)&rsdp->checksum - rsdp_table->data);
> -}
> -
>  typedef
>  struct AcpiBuildState {
>      /* Copy of table in RAM (for patching). */
> @@ -2732,7 +2703,25 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
>                 slic_oem.id, slic_oem.table_id);
>  
>      /* RSDP is in FSEG memory, so allocate it separately */
> -    build_rsdp(tables->rsdp, tables->linker, rsdt);
> +    {
> +        AcpiRsdpData rsdp_data = {
> +            .revision = 0,
> +            .oem_id = ACPI_BUILD_APPNAME6,
> +            .xsdt_tbl_offset = NULL,
> +            .rsdt_tbl_offset = &rsdt,
> +        };
> +        build_rsdp(tables->rsdp, tables->linker, &rsdp_data);
> +        if (!pcmc->rsdp_in_ram) {
> +            /*
> +             * Legacy machine types (2.2 and older) expect to get a complete
> +             * revision 2 RSDP table, even though they only look at the
not true, rev is set to 0 for pc machines, the point of the original comment was
that we allocate extra 16 bytes but not actually using them and why it's bad
to drop it suddenly.

> +             * revision 0 fields (xsdt pointer is not set). So in order to
> +             * not break migration to those machine types we waste 16 bytes
> +             * that we amend to the RSDP revision 0 structure.
                          ^^^ added
> +             */
Perhaps amended original comment would be clearer:

   /* We used to allocate extra space for RSDP rev 2 but used only space for
    * legacy RSDP and extra bytes were zeroed out. Keep wasting extra 16 bytes
    * to make sure we won't breake migration for machine types 2.2 and older
    * due to RSDP blob size mismatch.
    */

> +            build_append_int_noprefix(tables->rsdp, 0, 16);
> +        }
> +    }
>  
>      /* We'll expose it all to Guest so we want to reduce
>       * chance of size changes.

With comment fixed:
Reviewed-by: Igor Mammedov <imammedo@redhat.com>

since it's minor fixup and doesn't affect applying remaining patches you can post
v5 7/8 as reply to v4 7/8

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v4 7/8] hw: acpi: Export and share the ARM RSDP build
  2018-12-17 12:20   ` Igor Mammedov
@ 2018-12-17 13:49     ` Samuel Ortiz
  2018-12-17 15:35       ` Igor Mammedov
  0 siblings, 1 reply; 20+ messages in thread
From: Samuel Ortiz @ 2018-12-17 13:49 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: Laurent Vivier, Peter Maydell, Thomas Huth, Eduardo Habkost,
	Ben Warren, Michael S. Tsirkin, qemu-devel, Shannon Zhao,
	qemu-arm, Paolo Bonzini, Richard Henderson

On Mon, Dec 17, 2018 at 01:20:28PM +0100, Igor Mammedov wrote:
> On Mon, 17 Dec 2018 11:48:37 +0100
> Samuel Ortiz <sameo@linux.intel.com> wrote:
> 
> > Now that build_rsdp() supports building both legacy and current RSDP
> > tables, we can move it to a generic folder (hw/acpi) and have the i386
> > ACPI code reuse it in order to reduce code duplication.
> > 
> > Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
> > Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> > Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> > Reviewed-by: Andrew Jones <drjones@redhat.com>
> > Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> for future reference, if one changes patch in a significant way,
> one is supposed to drop Tested/Reviewed-by tags so that reviewers
> would look at it again and we by mistake won't merge not actually
> reviewed changes.
> 
> [...]
> 
> > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > index fb877648ac..846cb6d755 100644
> > --- a/hw/i386/acpi-build.c
> > +++ b/hw/i386/acpi-build.c
> > @@ -2547,35 +2547,6 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker)
> >                   "IVRS", table_data->len - iommu_start, 1, NULL, NULL);
> >  }
> >  
> > -static void
> > -build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned rsdt_tbl_offset)
> > -{
> > -    /* AcpiRsdpDescriptor describes revision 2 RSDP table and as result we
> > -     * allocate extra 16 bytes for pc/q35 RSDP rev1 as well. Keep extra 16 bytes
> > -     * wasted to make sure we won't breake migration for machine types older
> > -     * than 2.3 due to size mismatch.
> > -     */
> > -    AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
> > -    unsigned rsdt_pa_size = sizeof(rsdp->rsdt_physical_address);
> > -    unsigned rsdt_pa_offset =
> > -        (char *)&rsdp->rsdt_physical_address - rsdp_table->data;
> > -
> > -    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, rsdp_table, 16,
> > -                             true /* fseg memory */);
> > -
> > -    memcpy(&rsdp->signature, "RSD PTR ", 8);
> > -    memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
> > -    /* Address to be filled by Guest linker */
> > -    bios_linker_loader_add_pointer(linker,
> > -        ACPI_BUILD_RSDP_FILE, rsdt_pa_offset, rsdt_pa_size,
> > -        ACPI_BUILD_TABLE_FILE, rsdt_tbl_offset);
> > -
> > -    /* Checksum to be filled by Guest linker */
> > -    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
> > -        (char *)rsdp - rsdp_table->data, 20 /* ACPI rev 1.0 RSDP size */,
> > -        (char *)&rsdp->checksum - rsdp_table->data);
> > -}
> > -
> >  typedef
> >  struct AcpiBuildState {
> >      /* Copy of table in RAM (for patching). */
> > @@ -2732,7 +2703,25 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
> >                 slic_oem.id, slic_oem.table_id);
> >  
> >      /* RSDP is in FSEG memory, so allocate it separately */
> > -    build_rsdp(tables->rsdp, tables->linker, rsdt);
> > +    {
> > +        AcpiRsdpData rsdp_data = {
> > +            .revision = 0,
> > +            .oem_id = ACPI_BUILD_APPNAME6,
> > +            .xsdt_tbl_offset = NULL,
> > +            .rsdt_tbl_offset = &rsdt,
> > +        };
> > +        build_rsdp(tables->rsdp, tables->linker, &rsdp_data);
> > +        if (!pcmc->rsdp_in_ram) {
> > +            /*
> > +             * Legacy machine types (2.2 and older) expect to get a complete
> > +             * revision 2 RSDP table, even though they only look at the
> not true, rev is set to 0 for pc machines,
Rev is set to 0 but they effectively expect to get a structure which
size is the rev 2 one. That's what I meant.

> the point of the original comment was
> that we allocate extra 16 bytes but not actually using them and why it's bad
> to drop it suddenly.
>
> > +             * revision 0 fields (xsdt pointer is not set). So in order to
> > +             * not break migration to those machine types we waste 16 bytes
> > +             * that we amend to the RSDP revision 0 structure.
>                           ^^^ added
> > +             */
> Perhaps amended original comment would be clearer:
> 
>    /* We used to allocate extra space for RSDP rev 2 but used only space for
>     * legacy RSDP and extra bytes were zeroed out. Keep wasting extra 16 bytes
>     * to make sure we won't breake migration for machine types 2.2 and older
>     * due to RSDP blob size mismatch.
>     */
> 
> > +            build_append_int_noprefix(tables->rsdp, 0, 16);
> > +        }
> > +    }
> >  
> >      /* We'll expose it all to Guest so we want to reduce
> >       * chance of size changes.
> 
> With comment fixed:
> Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> 
> since it's minor fixup and doesn't affect applying remaining patches you can post
> v5 7/8 as reply to v4 7/8
I'll do that.
Since I assume the 16 bytes addition is a significant change, I'll also remove all
reviewed-by/tested-by tags from this patch, except yours.

Cheers,
Samuel.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v4 7/8] hw: acpi: Export and share the ARM RSDP build
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 7/8] hw: acpi: Export and share the ARM " Samuel Ortiz
  2018-12-17 12:20   ` Igor Mammedov
@ 2018-12-17 14:06   ` Samuel Ortiz
  2018-12-17 15:25     ` Igor Mammedov
  2018-12-17 15:34   ` [Qemu-devel] [PATCH v5 " Samuel Ortiz
  2 siblings, 1 reply; 20+ messages in thread
From: Samuel Ortiz @ 2018-12-17 14:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Peter Maydell, Thomas Huth, Eduardo Habkost,
	Ben Warren, Michael S. Tsirkin, Shannon Zhao, qemu-arm,
	Paolo Bonzini, Igor Mammedov, Richard Henderson


From: Samuel Ortiz <sameo@linux.intel.com>

Now that build_rsdp() supports building both legacy and current RSDP
tables, we can move it to a generic folder (hw/acpi) and have the i386
ACPI code reuse it in order to reduce code duplication.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
---

V4 -> V5:
  * Fixed the 16 bytes padding comment.

---
 include/hw/acpi/aml-build.h |  2 ++
 hw/acpi/aml-build.c         | 68 +++++++++++++++++++++++++++++++++++++
 hw/arm/virt-acpi-build.c    | 65 -----------------------------------
 hw/i386/acpi-build.c        | 49 +++++++++++---------------
 4 files changed, 89 insertions(+), 95 deletions(-)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 6c36903c0a..1a563ad756 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -388,6 +388,8 @@ void acpi_add_table(GArray *table_offsets, GArray *table_data);
 void acpi_build_tables_init(AcpiBuildTables *tables);
 void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre);
 void
+build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data);
+void
 build_rsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets,
            const char *oem_id, const char *oem_table_id);
 void
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 1e43cd736d..555c24f21d 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -1589,6 +1589,74 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre)
     g_array_free(tables->vmgenid, mfre);
 }
 
+/*
+ * ACPI spec 5.2.5.3 Root System Description Pointer (RSDP).
+ * (Revision 1.0 or later)
+ */
+void
+build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data)
+{
+    int tbl_off = tbl->len; /* Table offset in the RSDP file */
+
+    switch (rsdp_data->revision) {
+    case 0:
+        /* With ACPI 1.0, we must have an RSDT pointer */
+        g_assert(rsdp_data->rsdt_tbl_offset);
+        break;
+    case 2:
+        /* With ACPI 2.0+, we must have an XSDT pointer */
+        g_assert(rsdp_data->xsdt_tbl_offset);
+        break;
+    default:
+        /* Only revisions 0 (ACPI 1.0) and 2 (ACPI 2.0+) are valid for RSDP */
+        g_assert_not_reached();
+    }
+
+    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, tbl, 16,
+                             true /* fseg memory */);
+
+    g_array_append_vals(tbl, "RSD PTR ", 8); /* Signature */
+    build_append_int_noprefix(tbl, 0, 1); /* Checksum */
+    g_array_append_vals(tbl, rsdp_data->oem_id, 6); /* OEMID */
+    build_append_int_noprefix(tbl, rsdp_data->revision, 1); /* Revision */
+    build_append_int_noprefix(tbl, 0, 4); /* RsdtAddress */
+    if (rsdp_data->rsdt_tbl_offset) {
+        /* RSDT address to be filled by guest linker */
+        bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
+                                       tbl_off + 16, 4,
+                                       ACPI_BUILD_TABLE_FILE,
+                                       *rsdp_data->rsdt_tbl_offset);
+    }
+
+    /* Checksum to be filled by guest linker */
+    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
+                                    tbl_off, 20, /* ACPI rev 1.0 RSDP size */
+                                    8);
+
+    if (rsdp_data->revision == 0) {
+        /* ACPI 1.0 RSDP, we're done */
+        return;
+    }
+
+    build_append_int_noprefix(tbl, 36, 4); /* Length */
+
+    /* XSDT address to be filled by guest linker */
+    build_append_int_noprefix(tbl, 0, 8); /* XsdtAddress */
+    /* We already validated our xsdt pointer */
+    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
+                                   tbl_off + 24, 8,
+                                   ACPI_BUILD_TABLE_FILE,
+                                   *rsdp_data->xsdt_tbl_offset);
+
+    build_append_int_noprefix(tbl, 0, 1); /* Extended Checksum */
+    build_append_int_noprefix(tbl, 0, 3); /* Reserved */
+
+    /* Extended checksum to be filled by Guest linker */
+    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
+                                    tbl_off, 36, /* ACPI rev 2.0 RSDP size */
+                                    32);
+}
+
 /* Build rsdt table */
 void
 build_rsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets,
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 05f6654371..95fad6f0ce 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -366,71 +366,6 @@ static void acpi_dsdt_add_power_button(Aml *scope)
     aml_append(scope, dev);
 }
 
-/* RSDP */
-static void
-build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data)
-{
-    int tbl_off = tbl->len; /* Table offset in the RSDP file */
-
-    switch (rsdp_data->revision) {
-    case 0:
-        /* With ACPI 1.0, we must have an RSDT pointer */
-        g_assert(rsdp_data->rsdt_tbl_offset);
-        break;
-    case 2:
-        /* With ACPI 2.0+, we must have an XSDT pointer */
-        g_assert(rsdp_data->xsdt_tbl_offset);
-        break;
-    default:
-        /* Only revisions 0 (ACPI 1.0) and 2 (ACPI 2.0+) are valid for RSDP */
-        g_assert_not_reached();
-    }
-
-    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, tbl, 16,
-                             true /* fseg memory */);
-
-    g_array_append_vals(tbl, "RSD PTR ", 8); /* Signature */
-    build_append_int_noprefix(tbl, 0, 1); /* Checksum */
-    g_array_append_vals(tbl, rsdp_data->oem_id, 6); /* OEMID */
-    build_append_int_noprefix(tbl, rsdp_data->revision, 1); /* Revision */
-    build_append_int_noprefix(tbl, 0, 4); /* RsdtAddress */
-    if (rsdp_data->rsdt_tbl_offset) {
-        /* RSDT address to be filled by guest linker */
-        bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
-                                       tbl_off + 16, 4,
-                                       ACPI_BUILD_TABLE_FILE,
-                                       *rsdp_data->rsdt_tbl_offset);
-    }
-
-    /* Checksum to be filled by guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    tbl_off, 20, /* ACPI rev 1.0 RSDP size */
-                                    8);
-
-    if (rsdp_data->revision == 0) {
-        /* ACPI 1.0 RSDP, we're done */
-        return;
-    }
-
-    build_append_int_noprefix(tbl, 36, 4); /* Length */
-
-    /* XSDT address to be filled by guest linker */
-    build_append_int_noprefix(tbl, 0, 8); /* XsdtAddress */
-    /* We already validated our xsdt pointer */
-    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
-                                   tbl_off + 24, 8,
-                                   ACPI_BUILD_TABLE_FILE,
-                                   *rsdp_data->xsdt_tbl_offset);
-
-    build_append_int_noprefix(tbl, 0, 1); /* Extended Checksum */
-    build_append_int_noprefix(tbl, 0, 3); /* Reserved */
-
-    /* Extended checksum to be filled by Guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    tbl_off, 36, /* ACPI rev 2.0 RSDP size */
-                                    32);
-}
-
 static void
 build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
 {
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index fb877648ac..9891b6913b 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -2547,35 +2547,6 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker)
                  "IVRS", table_data->len - iommu_start, 1, NULL, NULL);
 }
 
-static void
-build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned rsdt_tbl_offset)
-{
-    /* AcpiRsdpDescriptor describes revision 2 RSDP table and as result we
-     * allocate extra 16 bytes for pc/q35 RSDP rev1 as well. Keep extra 16 bytes
-     * wasted to make sure we won't breake migration for machine types older
-     * than 2.3 due to size mismatch.
-     */
-    AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
-    unsigned rsdt_pa_size = sizeof(rsdp->rsdt_physical_address);
-    unsigned rsdt_pa_offset =
-        (char *)&rsdp->rsdt_physical_address - rsdp_table->data;
-
-    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, rsdp_table, 16,
-                             true /* fseg memory */);
-
-    memcpy(&rsdp->signature, "RSD PTR ", 8);
-    memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
-    /* Address to be filled by Guest linker */
-    bios_linker_loader_add_pointer(linker,
-        ACPI_BUILD_RSDP_FILE, rsdt_pa_offset, rsdt_pa_size,
-        ACPI_BUILD_TABLE_FILE, rsdt_tbl_offset);
-
-    /* Checksum to be filled by Guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-        (char *)rsdp - rsdp_table->data, 20 /* ACPI rev 1.0 RSDP size */,
-        (char *)&rsdp->checksum - rsdp_table->data);
-}
-
 typedef
 struct AcpiBuildState {
     /* Copy of table in RAM (for patching). */
@@ -2732,7 +2703,25 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
                slic_oem.id, slic_oem.table_id);
 
     /* RSDP is in FSEG memory, so allocate it separately */
-    build_rsdp(tables->rsdp, tables->linker, rsdt);
+    {
+        AcpiRsdpData rsdp_data = {
+            .revision = 0,
+            .oem_id = ACPI_BUILD_APPNAME6,
+            .xsdt_tbl_offset = NULL,
+            .rsdt_tbl_offset = &rsdt,
+        };
+        build_rsdp(tables->rsdp, tables->linker, &rsdp_data);
+        if (!pcmc->rsdp_in_ram) {
+            /* We used to allocate some extra space for RSDP revision 2 but
+             * only used the RSDP revision 0 space. The extra bytes were
+             * zeroed out and not used.
+             * Here we continue wasting those extra 16 bytes to make sure we
+             * don't break migration for machine types 2.2 and older due to
+             * RSDP blob size mismatch.
+             */
+            build_append_int_noprefix(tables->rsdp, 0, 16);
+        }
+    }
 
     /* We'll expose it all to Guest so we want to reduce
      * chance of size changes.
-- 
2.19.2

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v4 7/8] hw: acpi: Export and share the ARM RSDP build
  2018-12-17 14:06   ` Samuel Ortiz
@ 2018-12-17 15:25     ` Igor Mammedov
  2018-12-17 15:32       ` Samuel Ortiz
  0 siblings, 1 reply; 20+ messages in thread
From: Igor Mammedov @ 2018-12-17 15:25 UTC (permalink / raw)
  To: Samuel Ortiz
  Cc: qemu-devel, Laurent Vivier, Peter Maydell, Thomas Huth,
	Eduardo Habkost, Ben Warren, Michael S. Tsirkin, Shannon Zhao,
	qemu-arm, Paolo Bonzini, Richard Henderson

On Mon, 17 Dec 2018 15:06:11 +0100
Samuel Ortiz <sameo@linux.intel.com> wrote:

> 
> From: Samuel Ortiz <sameo@linux.intel.com>

Subject should be
  [Qemu-devel] [PATCH v5 7/8] hw: acpi: Export and share the ARM RSDP build
                      ^^^
and without "Re: "

> 
> Now that build_rsdp() supports building both legacy and current RSDP
> tables, we can move it to a generic folder (hw/acpi) and have the i386
> ACPI code reuse it in order to reduce code duplication.
> 
> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
> Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> ---
> 
> V4 -> V5:
>   * Fixed the 16 bytes padding comment.
> 
> ---
[...]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v4 7/8] hw: acpi: Export and share the ARM RSDP build
  2018-12-17 15:25     ` Igor Mammedov
@ 2018-12-17 15:32       ` Samuel Ortiz
  0 siblings, 0 replies; 20+ messages in thread
From: Samuel Ortiz @ 2018-12-17 15:32 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: Laurent Vivier, Peter Maydell, Thomas Huth, Eduardo Habkost,
	Ben Warren, Michael S. Tsirkin, qemu-devel, Shannon Zhao,
	qemu-arm, Paolo Bonzini, Richard Henderson

On Mon, Dec 17, 2018 at 04:25:47PM +0100, Igor Mammedov wrote:
> On Mon, 17 Dec 2018 15:06:11 +0100
> Samuel Ortiz <sameo@linux.intel.com> wrote:
> 
> > 
> > From: Samuel Ortiz <sameo@linux.intel.com>
> 
> Subject should be
>   [Qemu-devel] [PATCH v5 7/8] hw: acpi: Export and share the ARM RSDP build
>                       ^^^
> and without "Re: "
>
I did not realize it's ok to break a thread's topic/subject. Will
resend.

> > 
> > Now that build_rsdp() supports building both legacy and current RSDP
> > tables, we can move it to a generic folder (hw/acpi) and have the i386
> > ACPI code reuse it in order to reduce code duplication.
> > 
> > Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
> > Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> > 
> > V4 -> V5:
> >   * Fixed the 16 bytes padding comment.
> > 
> > ---
> [...]
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Qemu-devel] [PATCH v5 7/8] hw: acpi: Export and share the ARM RSDP build
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 7/8] hw: acpi: Export and share the ARM " Samuel Ortiz
  2018-12-17 12:20   ` Igor Mammedov
  2018-12-17 14:06   ` Samuel Ortiz
@ 2018-12-17 15:34   ` Samuel Ortiz
  2018-12-17 15:45     ` Andrew Jones
  2 siblings, 1 reply; 20+ messages in thread
From: Samuel Ortiz @ 2018-12-17 15:34 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Peter Maydell, Thomas Huth, Eduardo Habkost,
	Ben Warren, Michael S. Tsirkin, Shannon Zhao, qemu-arm,
	Paolo Bonzini, Igor Mammedov, Richard Henderson


From: Samuel Ortiz <sameo@linux.intel.com>

Now that build_rsdp() supports building both legacy and current RSDP
tables, we can move it to a generic folder (hw/acpi) and have the i386
ACPI code reuse it in order to reduce code duplication.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
---
 include/hw/acpi/aml-build.h |  2 ++
 hw/acpi/aml-build.c         | 68 +++++++++++++++++++++++++++++++++++++
 hw/arm/virt-acpi-build.c    | 65 -----------------------------------
 hw/i386/acpi-build.c        | 49 +++++++++++---------------
 4 files changed, 89 insertions(+), 95 deletions(-)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 6c36903c0a..1a563ad756 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -388,6 +388,8 @@ void acpi_add_table(GArray *table_offsets, GArray *table_data);
 void acpi_build_tables_init(AcpiBuildTables *tables);
 void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre);
 void
+build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data);
+void
 build_rsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets,
            const char *oem_id, const char *oem_table_id);
 void
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 1e43cd736d..555c24f21d 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -1589,6 +1589,74 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre)
     g_array_free(tables->vmgenid, mfre);
 }
 
+/*
+ * ACPI spec 5.2.5.3 Root System Description Pointer (RSDP).
+ * (Revision 1.0 or later)
+ */
+void
+build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data)
+{
+    int tbl_off = tbl->len; /* Table offset in the RSDP file */
+
+    switch (rsdp_data->revision) {
+    case 0:
+        /* With ACPI 1.0, we must have an RSDT pointer */
+        g_assert(rsdp_data->rsdt_tbl_offset);
+        break;
+    case 2:
+        /* With ACPI 2.0+, we must have an XSDT pointer */
+        g_assert(rsdp_data->xsdt_tbl_offset);
+        break;
+    default:
+        /* Only revisions 0 (ACPI 1.0) and 2 (ACPI 2.0+) are valid for RSDP */
+        g_assert_not_reached();
+    }
+
+    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, tbl, 16,
+                             true /* fseg memory */);
+
+    g_array_append_vals(tbl, "RSD PTR ", 8); /* Signature */
+    build_append_int_noprefix(tbl, 0, 1); /* Checksum */
+    g_array_append_vals(tbl, rsdp_data->oem_id, 6); /* OEMID */
+    build_append_int_noprefix(tbl, rsdp_data->revision, 1); /* Revision */
+    build_append_int_noprefix(tbl, 0, 4); /* RsdtAddress */
+    if (rsdp_data->rsdt_tbl_offset) {
+        /* RSDT address to be filled by guest linker */
+        bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
+                                       tbl_off + 16, 4,
+                                       ACPI_BUILD_TABLE_FILE,
+                                       *rsdp_data->rsdt_tbl_offset);
+    }
+
+    /* Checksum to be filled by guest linker */
+    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
+                                    tbl_off, 20, /* ACPI rev 1.0 RSDP size */
+                                    8);
+
+    if (rsdp_data->revision == 0) {
+        /* ACPI 1.0 RSDP, we're done */
+        return;
+    }
+
+    build_append_int_noprefix(tbl, 36, 4); /* Length */
+
+    /* XSDT address to be filled by guest linker */
+    build_append_int_noprefix(tbl, 0, 8); /* XsdtAddress */
+    /* We already validated our xsdt pointer */
+    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
+                                   tbl_off + 24, 8,
+                                   ACPI_BUILD_TABLE_FILE,
+                                   *rsdp_data->xsdt_tbl_offset);
+
+    build_append_int_noprefix(tbl, 0, 1); /* Extended Checksum */
+    build_append_int_noprefix(tbl, 0, 3); /* Reserved */
+
+    /* Extended checksum to be filled by Guest linker */
+    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
+                                    tbl_off, 36, /* ACPI rev 2.0 RSDP size */
+                                    32);
+}
+
 /* Build rsdt table */
 void
 build_rsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets,
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 05f6654371..95fad6f0ce 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -366,71 +366,6 @@ static void acpi_dsdt_add_power_button(Aml *scope)
     aml_append(scope, dev);
 }
 
-/* RSDP */
-static void
-build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data)
-{
-    int tbl_off = tbl->len; /* Table offset in the RSDP file */
-
-    switch (rsdp_data->revision) {
-    case 0:
-        /* With ACPI 1.0, we must have an RSDT pointer */
-        g_assert(rsdp_data->rsdt_tbl_offset);
-        break;
-    case 2:
-        /* With ACPI 2.0+, we must have an XSDT pointer */
-        g_assert(rsdp_data->xsdt_tbl_offset);
-        break;
-    default:
-        /* Only revisions 0 (ACPI 1.0) and 2 (ACPI 2.0+) are valid for RSDP */
-        g_assert_not_reached();
-    }
-
-    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, tbl, 16,
-                             true /* fseg memory */);
-
-    g_array_append_vals(tbl, "RSD PTR ", 8); /* Signature */
-    build_append_int_noprefix(tbl, 0, 1); /* Checksum */
-    g_array_append_vals(tbl, rsdp_data->oem_id, 6); /* OEMID */
-    build_append_int_noprefix(tbl, rsdp_data->revision, 1); /* Revision */
-    build_append_int_noprefix(tbl, 0, 4); /* RsdtAddress */
-    if (rsdp_data->rsdt_tbl_offset) {
-        /* RSDT address to be filled by guest linker */
-        bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
-                                       tbl_off + 16, 4,
-                                       ACPI_BUILD_TABLE_FILE,
-                                       *rsdp_data->rsdt_tbl_offset);
-    }
-
-    /* Checksum to be filled by guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    tbl_off, 20, /* ACPI rev 1.0 RSDP size */
-                                    8);
-
-    if (rsdp_data->revision == 0) {
-        /* ACPI 1.0 RSDP, we're done */
-        return;
-    }
-
-    build_append_int_noprefix(tbl, 36, 4); /* Length */
-
-    /* XSDT address to be filled by guest linker */
-    build_append_int_noprefix(tbl, 0, 8); /* XsdtAddress */
-    /* We already validated our xsdt pointer */
-    bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE,
-                                   tbl_off + 24, 8,
-                                   ACPI_BUILD_TABLE_FILE,
-                                   *rsdp_data->xsdt_tbl_offset);
-
-    build_append_int_noprefix(tbl, 0, 1); /* Extended Checksum */
-    build_append_int_noprefix(tbl, 0, 3); /* Reserved */
-
-    /* Extended checksum to be filled by Guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-                                    tbl_off, 36, /* ACPI rev 2.0 RSDP size */
-                                    32);
-}
-
 static void
 build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
 {
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index fb877648ac..9891b6913b 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -2547,35 +2547,6 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker)
                  "IVRS", table_data->len - iommu_start, 1, NULL, NULL);
 }
 
-static void
-build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned rsdt_tbl_offset)
-{
-    /* AcpiRsdpDescriptor describes revision 2 RSDP table and as result we
-     * allocate extra 16 bytes for pc/q35 RSDP rev1 as well. Keep extra 16 bytes
-     * wasted to make sure we won't breake migration for machine types older
-     * than 2.3 due to size mismatch.
-     */
-    AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
-    unsigned rsdt_pa_size = sizeof(rsdp->rsdt_physical_address);
-    unsigned rsdt_pa_offset =
-        (char *)&rsdp->rsdt_physical_address - rsdp_table->data;
-
-    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, rsdp_table, 16,
-                             true /* fseg memory */);
-
-    memcpy(&rsdp->signature, "RSD PTR ", 8);
-    memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
-    /* Address to be filled by Guest linker */
-    bios_linker_loader_add_pointer(linker,
-        ACPI_BUILD_RSDP_FILE, rsdt_pa_offset, rsdt_pa_size,
-        ACPI_BUILD_TABLE_FILE, rsdt_tbl_offset);
-
-    /* Checksum to be filled by Guest linker */
-    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
-        (char *)rsdp - rsdp_table->data, 20 /* ACPI rev 1.0 RSDP size */,
-        (char *)&rsdp->checksum - rsdp_table->data);
-}
-
 typedef
 struct AcpiBuildState {
     /* Copy of table in RAM (for patching). */
@@ -2732,7 +2703,25 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
                slic_oem.id, slic_oem.table_id);
 
     /* RSDP is in FSEG memory, so allocate it separately */
-    build_rsdp(tables->rsdp, tables->linker, rsdt);
+    {
+        AcpiRsdpData rsdp_data = {
+            .revision = 0,
+            .oem_id = ACPI_BUILD_APPNAME6,
+            .xsdt_tbl_offset = NULL,
+            .rsdt_tbl_offset = &rsdt,
+        };
+        build_rsdp(tables->rsdp, tables->linker, &rsdp_data);
+        if (!pcmc->rsdp_in_ram) {
+            /* We used to allocate some extra space for RSDP revision 2 but
+             * only used the RSDP revision 0 space. The extra bytes were
+             * zeroed out and not used.
+             * Here we continue wasting those extra 16 bytes to make sure we
+             * don't break migration for machine types 2.2 and older due to
+             * RSDP blob size mismatch.
+             */
+            build_append_int_noprefix(tables->rsdp, 0, 16);
+        }
+    }
 
     /* We'll expose it all to Guest so we want to reduce
      * chance of size changes.
-- 
2.19.2

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v4 7/8] hw: acpi: Export and share the ARM RSDP build
  2018-12-17 13:49     ` Samuel Ortiz
@ 2018-12-17 15:35       ` Igor Mammedov
  2018-12-17 16:46         ` Samuel Ortiz
  0 siblings, 1 reply; 20+ messages in thread
From: Igor Mammedov @ 2018-12-17 15:35 UTC (permalink / raw)
  To: Samuel Ortiz
  Cc: Laurent Vivier, Peter Maydell, Thomas Huth, Eduardo Habkost,
	Ben Warren, Michael S. Tsirkin, qemu-devel, Shannon Zhao,
	qemu-arm, Paolo Bonzini, Richard Henderson

On Mon, 17 Dec 2018 14:49:59 +0100
Samuel Ortiz <sameo@linux.intel.com> wrote:

> On Mon, Dec 17, 2018 at 01:20:28PM +0100, Igor Mammedov wrote:
> > On Mon, 17 Dec 2018 11:48:37 +0100
> > Samuel Ortiz <sameo@linux.intel.com> wrote:
> > 
> > > Now that build_rsdp() supports building both legacy and current RSDP
> > > tables, we can move it to a generic folder (hw/acpi) and have the i386
> > > ACPI code reuse it in order to reduce code duplication.
> > > 
> > > Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
> > > Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> > > Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> > > Reviewed-by: Andrew Jones <drjones@redhat.com>
> > > Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> > for future reference, if one changes patch in a significant way,
> > one is supposed to drop Tested/Reviewed-by tags so that reviewers
> > would look at it again and we by mistake won't merge not actually
> > reviewed changes.
> > 
> > [...]
> > 
> > > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > > index fb877648ac..846cb6d755 100644
> > > --- a/hw/i386/acpi-build.c
> > > +++ b/hw/i386/acpi-build.c
> > > @@ -2547,35 +2547,6 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker)
> > >                   "IVRS", table_data->len - iommu_start, 1, NULL, NULL);
> > >  }
> > >  
> > > -static void
> > > -build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned rsdt_tbl_offset)
> > > -{
> > > -    /* AcpiRsdpDescriptor describes revision 2 RSDP table and as result we
> > > -     * allocate extra 16 bytes for pc/q35 RSDP rev1 as well. Keep extra 16 bytes
> > > -     * wasted to make sure we won't breake migration for machine types older
> > > -     * than 2.3 due to size mismatch.
> > > -     */
> > > -    AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
> > > -    unsigned rsdt_pa_size = sizeof(rsdp->rsdt_physical_address);
> > > -    unsigned rsdt_pa_offset =
> > > -        (char *)&rsdp->rsdt_physical_address - rsdp_table->data;
> > > -
> > > -    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, rsdp_table, 16,
> > > -                             true /* fseg memory */);
> > > -
> > > -    memcpy(&rsdp->signature, "RSD PTR ", 8);
> > > -    memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
> > > -    /* Address to be filled by Guest linker */
> > > -    bios_linker_loader_add_pointer(linker,
> > > -        ACPI_BUILD_RSDP_FILE, rsdt_pa_offset, rsdt_pa_size,
> > > -        ACPI_BUILD_TABLE_FILE, rsdt_tbl_offset);
> > > -
> > > -    /* Checksum to be filled by Guest linker */
> > > -    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
> > > -        (char *)rsdp - rsdp_table->data, 20 /* ACPI rev 1.0 RSDP size */,
> > > -        (char *)&rsdp->checksum - rsdp_table->data);
> > > -}
> > > -
> > >  typedef
> > >  struct AcpiBuildState {
> > >      /* Copy of table in RAM (for patching). */
> > > @@ -2732,7 +2703,25 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
> > >                 slic_oem.id, slic_oem.table_id);
> > >  
> > >      /* RSDP is in FSEG memory, so allocate it separately */
> > > -    build_rsdp(tables->rsdp, tables->linker, rsdt);
> > > +    {
> > > +        AcpiRsdpData rsdp_data = {
> > > +            .revision = 0,
> > > +            .oem_id = ACPI_BUILD_APPNAME6,
> > > +            .xsdt_tbl_offset = NULL,
> > > +            .rsdt_tbl_offset = &rsdt,
> > > +        };
> > > +        build_rsdp(tables->rsdp, tables->linker, &rsdp_data);
> > > +        if (!pcmc->rsdp_in_ram) {
> > > +            /*
> > > +             * Legacy machine types (2.2 and older) expect to get a complete
> > > +             * revision 2 RSDP table, even though they only look at the
> > not true, rev is set to 0 for pc machines,
> Rev is set to 0 but they effectively expect to get a structure which
> size is the rev 2 one. That's what I meant.
> 
> > the point of the original comment was
> > that we allocate extra 16 bytes but not actually using them and why it's bad
> > to drop it suddenly.
> >
> > > +             * revision 0 fields (xsdt pointer is not set). So in order to
> > > +             * not break migration to those machine types we waste 16 bytes
> > > +             * that we amend to the RSDP revision 0 structure.
> >                           ^^^ added
> > > +             */
> > Perhaps amended original comment would be clearer:
> > 
> >    /* We used to allocate extra space for RSDP rev 2 but used only space for
> >     * legacy RSDP and extra bytes were zeroed out. Keep wasting extra 16 bytes
> >     * to make sure we won't breake migration for machine types 2.2 and older
> >     * due to RSDP blob size mismatch.
> >     */
> > 
> > > +            build_append_int_noprefix(tables->rsdp, 0, 16);
Looks like I've haven't noticed, it might work but are you sure?
0 here is uint64_t and then it's shifted 16 times which is sort of gray area (undefined behavior)

using g_array_append_val[s]() here might be better

> > > +        }
> > > +    }
> > >  
> > >      /* We'll expose it all to Guest so we want to reduce
> > >       * chance of size changes.
> > 
> > With comment fixed:
> > Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> > 
> > since it's minor fixup and doesn't affect applying remaining patches you can post
> > v5 7/8 as reply to v4 7/8
> I'll do that.
> Since I assume the 16 bytes addition is a significant change, I'll also remove all
> reviewed-by/tested-by tags from this patch, except yours.
> 
> Cheers,
> Samuel.
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v5 7/8] hw: acpi: Export and share the ARM RSDP build
  2018-12-17 15:34   ` [Qemu-devel] [PATCH v5 " Samuel Ortiz
@ 2018-12-17 15:45     ` Andrew Jones
  0 siblings, 0 replies; 20+ messages in thread
From: Andrew Jones @ 2018-12-17 15:45 UTC (permalink / raw)
  To: Samuel Ortiz
  Cc: qemu-devel, Laurent Vivier, Peter Maydell, Thomas Huth,
	Eduardo Habkost, Ben Warren, Michael S. Tsirkin, Shannon Zhao,
	qemu-arm, Igor Mammedov, Paolo Bonzini, Richard Henderson

On Mon, Dec 17, 2018 at 04:34:48PM +0100, Samuel Ortiz wrote:
> 
> From: Samuel Ortiz <sameo@linux.intel.com>
> 
> Now that build_rsdp() supports building both legacy and current RSDP
> tables, we can move it to a generic folder (hw/acpi) and have the i386
> ACPI code reuse it in order to reduce code duplication.
> 
> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
> Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> ---
>  include/hw/acpi/aml-build.h |  2 ++
>  hw/acpi/aml-build.c         | 68 +++++++++++++++++++++++++++++++++++++
>  hw/arm/virt-acpi-build.c    | 65 -----------------------------------
>  hw/i386/acpi-build.c        | 49 +++++++++++---------------
>  4 files changed, 89 insertions(+), 95 deletions(-)
>

Reviewed-by: Andrew Jones <drjones@redhat.com>

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v4 7/8] hw: acpi: Export and share the ARM RSDP build
  2018-12-17 15:35       ` Igor Mammedov
@ 2018-12-17 16:46         ` Samuel Ortiz
  2018-12-17 23:04           ` Michael S. Tsirkin
  0 siblings, 1 reply; 20+ messages in thread
From: Samuel Ortiz @ 2018-12-17 16:46 UTC (permalink / raw)
  To: Igor Mammedov
  Cc: Laurent Vivier, Peter Maydell, Thomas Huth, Eduardo Habkost,
	Ben Warren, Michael S. Tsirkin, qemu-devel, Shannon Zhao,
	qemu-arm, Paolo Bonzini, Richard Henderson

On Mon, Dec 17, 2018 at 04:35:36PM +0100, Igor Mammedov wrote:
> On Mon, 17 Dec 2018 14:49:59 +0100
> Samuel Ortiz <sameo@linux.intel.com> wrote:
> 
> > On Mon, Dec 17, 2018 at 01:20:28PM +0100, Igor Mammedov wrote:
> > > On Mon, 17 Dec 2018 11:48:37 +0100
> > > Samuel Ortiz <sameo@linux.intel.com> wrote:
> > > 
> > > > Now that build_rsdp() supports building both legacy and current RSDP
> > > > tables, we can move it to a generic folder (hw/acpi) and have the i386
> > > > ACPI code reuse it in order to reduce code duplication.
> > > > 
> > > > Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
> > > > Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> > > > Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> > > > Reviewed-by: Andrew Jones <drjones@redhat.com>
> > > > Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> > > for future reference, if one changes patch in a significant way,
> > > one is supposed to drop Tested/Reviewed-by tags so that reviewers
> > > would look at it again and we by mistake won't merge not actually
> > > reviewed changes.
> > > 
> > > [...]
> > > 
> > > > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > > > index fb877648ac..846cb6d755 100644
> > > > --- a/hw/i386/acpi-build.c
> > > > +++ b/hw/i386/acpi-build.c
> > > > @@ -2547,35 +2547,6 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker)
> > > >                   "IVRS", table_data->len - iommu_start, 1, NULL, NULL);
> > > >  }
> > > >  
> > > > -static void
> > > > -build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned rsdt_tbl_offset)
> > > > -{
> > > > -    /* AcpiRsdpDescriptor describes revision 2 RSDP table and as result we
> > > > -     * allocate extra 16 bytes for pc/q35 RSDP rev1 as well. Keep extra 16 bytes
> > > > -     * wasted to make sure we won't breake migration for machine types older
> > > > -     * than 2.3 due to size mismatch.
> > > > -     */
> > > > -    AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
> > > > -    unsigned rsdt_pa_size = sizeof(rsdp->rsdt_physical_address);
> > > > -    unsigned rsdt_pa_offset =
> > > > -        (char *)&rsdp->rsdt_physical_address - rsdp_table->data;
> > > > -
> > > > -    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, rsdp_table, 16,
> > > > -                             true /* fseg memory */);
> > > > -
> > > > -    memcpy(&rsdp->signature, "RSD PTR ", 8);
> > > > -    memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
> > > > -    /* Address to be filled by Guest linker */
> > > > -    bios_linker_loader_add_pointer(linker,
> > > > -        ACPI_BUILD_RSDP_FILE, rsdt_pa_offset, rsdt_pa_size,
> > > > -        ACPI_BUILD_TABLE_FILE, rsdt_tbl_offset);
> > > > -
> > > > -    /* Checksum to be filled by Guest linker */
> > > > -    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
> > > > -        (char *)rsdp - rsdp_table->data, 20 /* ACPI rev 1.0 RSDP size */,
> > > > -        (char *)&rsdp->checksum - rsdp_table->data);
> > > > -}
> > > > -
> > > >  typedef
> > > >  struct AcpiBuildState {
> > > >      /* Copy of table in RAM (for patching). */
> > > > @@ -2732,7 +2703,25 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
> > > >                 slic_oem.id, slic_oem.table_id);
> > > >  
> > > >      /* RSDP is in FSEG memory, so allocate it separately */
> > > > -    build_rsdp(tables->rsdp, tables->linker, rsdt);
> > > > +    {
> > > > +        AcpiRsdpData rsdp_data = {
> > > > +            .revision = 0,
> > > > +            .oem_id = ACPI_BUILD_APPNAME6,
> > > > +            .xsdt_tbl_offset = NULL,
> > > > +            .rsdt_tbl_offset = &rsdt,
> > > > +        };
> > > > +        build_rsdp(tables->rsdp, tables->linker, &rsdp_data);
> > > > +        if (!pcmc->rsdp_in_ram) {
> > > > +            /*
> > > > +             * Legacy machine types (2.2 and older) expect to get a complete
> > > > +             * revision 2 RSDP table, even though they only look at the
> > > not true, rev is set to 0 for pc machines,
> > Rev is set to 0 but they effectively expect to get a structure which
> > size is the rev 2 one. That's what I meant.
> > 
> > > the point of the original comment was
> > > that we allocate extra 16 bytes but not actually using them and why it's bad
> > > to drop it suddenly.
> > >
> > > > +             * revision 0 fields (xsdt pointer is not set). So in order to
> > > > +             * not break migration to those machine types we waste 16 bytes
> > > > +             * that we amend to the RSDP revision 0 structure.
> > >                           ^^^ added
> > > > +             */
> > > Perhaps amended original comment would be clearer:
> > > 
> > >    /* We used to allocate extra space for RSDP rev 2 but used only space for
> > >     * legacy RSDP and extra bytes were zeroed out. Keep wasting extra 16 bytes
> > >     * to make sure we won't breake migration for machine types 2.2 and older
> > >     * due to RSDP blob size mismatch.
> > >     */
> > > 
> > > > +            build_append_int_noprefix(tables->rsdp, 0, 16);
> Looks like I've haven't noticed, it might work but are you sure?
> 0 here is uint64_t and then it's shifted 16 times which is sort of gray area (undefined behavior)
AFAIK shifting by N bits when N > width(left operand) is undefined but
that's not the case here. build_append_int_noprefix(foo, 0, 16) shift a 64 bits
wide unsigned int by 8 bits, for each iterations of a 16 iterations
loop. So we're doing 16 iterations of properly defined behaviour.

Cheers,
Samuel.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v4 7/8] hw: acpi: Export and share the ARM RSDP build
  2018-12-17 16:46         ` Samuel Ortiz
@ 2018-12-17 23:04           ` Michael S. Tsirkin
  0 siblings, 0 replies; 20+ messages in thread
From: Michael S. Tsirkin @ 2018-12-17 23:04 UTC (permalink / raw)
  To: Samuel Ortiz
  Cc: Igor Mammedov, Laurent Vivier, Peter Maydell, Thomas Huth,
	Eduardo Habkost, Ben Warren, qemu-devel, Shannon Zhao, qemu-arm,
	Paolo Bonzini, Richard Henderson

On Mon, Dec 17, 2018 at 05:46:48PM +0100, Samuel Ortiz wrote:
> On Mon, Dec 17, 2018 at 04:35:36PM +0100, Igor Mammedov wrote:
> > On Mon, 17 Dec 2018 14:49:59 +0100
> > Samuel Ortiz <sameo@linux.intel.com> wrote:
> > 
> > > On Mon, Dec 17, 2018 at 01:20:28PM +0100, Igor Mammedov wrote:
> > > > On Mon, 17 Dec 2018 11:48:37 +0100
> > > > Samuel Ortiz <sameo@linux.intel.com> wrote:
> > > > 
> > > > > Now that build_rsdp() supports building both legacy and current RSDP
> > > > > tables, we can move it to a generic folder (hw/acpi) and have the i386
> > > > > ACPI code reuse it in order to reduce code duplication.
> > > > > 
> > > > > Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
> > > > > Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> > > > > Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> > > > > Reviewed-by: Andrew Jones <drjones@redhat.com>
> > > > > Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> > > > for future reference, if one changes patch in a significant way,
> > > > one is supposed to drop Tested/Reviewed-by tags so that reviewers
> > > > would look at it again and we by mistake won't merge not actually
> > > > reviewed changes.
> > > > 
> > > > [...]
> > > > 
> > > > > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> > > > > index fb877648ac..846cb6d755 100644
> > > > > --- a/hw/i386/acpi-build.c
> > > > > +++ b/hw/i386/acpi-build.c
> > > > > @@ -2547,35 +2547,6 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker)
> > > > >                   "IVRS", table_data->len - iommu_start, 1, NULL, NULL);
> > > > >  }
> > > > >  
> > > > > -static void
> > > > > -build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned rsdt_tbl_offset)
> > > > > -{
> > > > > -    /* AcpiRsdpDescriptor describes revision 2 RSDP table and as result we
> > > > > -     * allocate extra 16 bytes for pc/q35 RSDP rev1 as well. Keep extra 16 bytes
> > > > > -     * wasted to make sure we won't breake migration for machine types older
> > > > > -     * than 2.3 due to size mismatch.
> > > > > -     */
> > > > > -    AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp);
> > > > > -    unsigned rsdt_pa_size = sizeof(rsdp->rsdt_physical_address);
> > > > > -    unsigned rsdt_pa_offset =
> > > > > -        (char *)&rsdp->rsdt_physical_address - rsdp_table->data;
> > > > > -
> > > > > -    bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, rsdp_table, 16,
> > > > > -                             true /* fseg memory */);
> > > > > -
> > > > > -    memcpy(&rsdp->signature, "RSD PTR ", 8);
> > > > > -    memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
> > > > > -    /* Address to be filled by Guest linker */
> > > > > -    bios_linker_loader_add_pointer(linker,
> > > > > -        ACPI_BUILD_RSDP_FILE, rsdt_pa_offset, rsdt_pa_size,
> > > > > -        ACPI_BUILD_TABLE_FILE, rsdt_tbl_offset);
> > > > > -
> > > > > -    /* Checksum to be filled by Guest linker */
> > > > > -    bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE,
> > > > > -        (char *)rsdp - rsdp_table->data, 20 /* ACPI rev 1.0 RSDP size */,
> > > > > -        (char *)&rsdp->checksum - rsdp_table->data);
> > > > > -}
> > > > > -
> > > > >  typedef
> > > > >  struct AcpiBuildState {
> > > > >      /* Copy of table in RAM (for patching). */
> > > > > @@ -2732,7 +2703,25 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
> > > > >                 slic_oem.id, slic_oem.table_id);
> > > > >  
> > > > >      /* RSDP is in FSEG memory, so allocate it separately */
> > > > > -    build_rsdp(tables->rsdp, tables->linker, rsdt);
> > > > > +    {
> > > > > +        AcpiRsdpData rsdp_data = {
> > > > > +            .revision = 0,
> > > > > +            .oem_id = ACPI_BUILD_APPNAME6,
> > > > > +            .xsdt_tbl_offset = NULL,
> > > > > +            .rsdt_tbl_offset = &rsdt,
> > > > > +        };
> > > > > +        build_rsdp(tables->rsdp, tables->linker, &rsdp_data);
> > > > > +        if (!pcmc->rsdp_in_ram) {
> > > > > +            /*
> > > > > +             * Legacy machine types (2.2 and older) expect to get a complete
> > > > > +             * revision 2 RSDP table, even though they only look at the
> > > > not true, rev is set to 0 for pc machines,
> > > Rev is set to 0 but they effectively expect to get a structure which
> > > size is the rev 2 one. That's what I meant.
> > > 
> > > > the point of the original comment was
> > > > that we allocate extra 16 bytes but not actually using them and why it's bad
> > > > to drop it suddenly.
> > > >
> > > > > +             * revision 0 fields (xsdt pointer is not set). So in order to
> > > > > +             * not break migration to those machine types we waste 16 bytes
> > > > > +             * that we amend to the RSDP revision 0 structure.
> > > >                           ^^^ added
> > > > > +             */
> > > > Perhaps amended original comment would be clearer:
> > > > 
> > > >    /* We used to allocate extra space for RSDP rev 2 but used only space for
> > > >     * legacy RSDP and extra bytes were zeroed out. Keep wasting extra 16 bytes
> > > >     * to make sure we won't breake migration for machine types 2.2 and older
> > > >     * due to RSDP blob size mismatch.
> > > >     */
> > > > 
> > > > > +            build_append_int_noprefix(tables->rsdp, 0, 16);
> > Looks like I've haven't noticed, it might work but are you sure?
> > 0 here is uint64_t and then it's shifted 16 times which is sort of gray area (undefined behavior)
> AFAIK shifting by N bits when N > width(left operand) is undefined but
> that's not the case here. build_append_int_noprefix(foo, 0, 16) shift a 64 bits
> wide unsigned int by 8 bits, for each iterations of a 16 iterations
> loop. So we're doing 16 iterations of properly defined behaviour.
> 
> Cheers,
> Samuel.

It works fine but is IMHO unnecessarily tricky. Simple

	for (i = 0; i < 16; ++i)
		build_append_byte(tables->rsdp, 0)

is imho clearer.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [Qemu-devel] [PATCH v4 0/8] hw: acpi: RSDP fixes and refactoring
  2018-12-17 10:48 [Qemu-devel] [PATCH v4 0/8] hw: acpi: RSDP fixes and refactoring Samuel Ortiz
                   ` (7 preceding siblings ...)
  2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 8/8] hw: acpi: Remove AcpiRsdpDescriptor and fix tests Samuel Ortiz
@ 2018-12-18  1:10 ` Michael S. Tsirkin
  8 siblings, 0 replies; 20+ messages in thread
From: Michael S. Tsirkin @ 2018-12-18  1:10 UTC (permalink / raw)
  To: Samuel Ortiz
  Cc: qemu-devel, Laurent Vivier, Thomas Huth, Peter Maydell,
	Marcel Apfelbaum, Richard Henderson, Ben Warren, Shannon Zhao,
	qemu-arm, Igor Mammedov, Eduardo Habkost, Paolo Bonzini

On Mon, Dec 17, 2018 at 11:48:30AM +0100, Samuel Ortiz wrote:
> This patch serie fixes a couple of RSDP checksum related issues:
> 
> - On RSDP rev2, we are not adding the extended checksum and computing
>   the checksum on the full table instead of the first 20 bytes.
> - On RSDP rev1, we are computing the checksum on 36 bytes instead of 20.
>   We're lucky enough that this is only adding zeroes to the checksum.
> 
> A guest Linux kernel does not seem to care about RSDP checksums, so
> those 2 fixes are mostly for correctness sake.
> Any machine type that generates rev2 RSDP will see its RSDP table
> modified but since x86 builds RSDP v1 and all ACPI tests only run on
> either pc or q35, the ACPI tests tables are not affected by this fix.
> 
> The serie also extends the ARM virt ACPI RSDP build routine to support
> both RSDP v1 and v2, in order to share this code between x86 and
> aarch64. While extending, we also convert the routine to the latest
> build_append_foo() API. The new implementation is a closer reflection of
> the ACPI spec itself, is endian agnostic and allows for getting rid of the
> AcpiRsdpDescriptor structure.


OK I queued this, so we can proceed to do incremental patches on top.

> V3 -> V4:
>   * Add missing Reviewed-Bys from Igor and Andrew.
>   * Removed unneeded white space addition.
>   * Added 16 bytes padding to revision 0 RSDP structures for legacy (2.2
>     and older) machine types.
>   * Fixed a missing break in an ACPI RSDP test switch.
> 
> V2 -> V3:
>   * Add Reviewed-Bys from Igor and Andrew.
>   * Check for valid RSDP and XSDT pointers depending on the revision.
>   * Use RSDP initial table len as offset for checksum and pointer
>     insertion.
>   * Do not explictly pass RSDP revision as the RSDP table parsing test
>     utility.
> 
> v1 -> v2:
>   * Add missing SOBs.
>   * Rephrase some commit messages according to the maintainer's input.
>   * Replace ACPI spec definitions with hard coded constants.
>   * Replace init_rsdp_data() helper with open coded rsdp variable init.
>   * Rename acpi_find_[rx]sdt_address to acpi_get_[rx]sdt_address.
> 
> Igor Mammedov (2):
>   hw: arm: acpi: Fix incorrect checksums in RSDP
>   hw: i386: Use correct RSDT length for checksum
> 
> Samuel Ortiz (6):
>   hw: acpi: The RSDP build API can return void
>   hw: arm: Carry RSDP specific data through AcpiRsdpData
>   hw: arm: Convert the RSDP build to the buid_append_foo() API
>   hw: arm: Support both legacy and current RSDP build
>   hw: acpi: Export and share the ARM RSDP build
>   hw: acpi: Remove AcpiRsdpDescriptor and fix tests
> 
>  include/hw/acpi/acpi-defs.h | 19 ++++-------
>  include/hw/acpi/aml-build.h |  2 ++
>  tests/acpi-utils.h          |  4 ++-
>  hw/acpi/aml-build.c         | 68 +++++++++++++++++++++++++++++++++++++
>  hw/arm/virt-acpi-build.c    | 40 +++++-----------------
>  hw/i386/acpi-build.c        | 46 +++++++++++--------------
>  tests/acpi-utils.c          | 46 ++++++++++++++++++++-----
>  tests/bios-tables-test.c    | 22 +++++++++---
>  tests/vmgenid-test.c        |  8 +++--
>  9 files changed, 168 insertions(+), 87 deletions(-)
> 
> -- 
> 2.19.2

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2018-12-18  1:11 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-17 10:48 [Qemu-devel] [PATCH v4 0/8] hw: acpi: RSDP fixes and refactoring Samuel Ortiz
2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 1/8] hw: acpi: The RSDP build API can return void Samuel Ortiz
2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 2/8] hw: arm: acpi: Fix incorrect checksums in RSDP Samuel Ortiz
2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 3/8] hw: i386: Use correct RSDT length for checksum Samuel Ortiz
2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 4/8] hw: arm: Carry RSDP specific data through AcpiRsdpData Samuel Ortiz
2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 5/8] hw: arm: Convert the RSDP build to the buid_append_foo() API Samuel Ortiz
2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 6/8] hw: arm: Support both legacy and current RSDP build Samuel Ortiz
2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 7/8] hw: acpi: Export and share the ARM " Samuel Ortiz
2018-12-17 12:20   ` Igor Mammedov
2018-12-17 13:49     ` Samuel Ortiz
2018-12-17 15:35       ` Igor Mammedov
2018-12-17 16:46         ` Samuel Ortiz
2018-12-17 23:04           ` Michael S. Tsirkin
2018-12-17 14:06   ` Samuel Ortiz
2018-12-17 15:25     ` Igor Mammedov
2018-12-17 15:32       ` Samuel Ortiz
2018-12-17 15:34   ` [Qemu-devel] [PATCH v5 " Samuel Ortiz
2018-12-17 15:45     ` Andrew Jones
2018-12-17 10:48 ` [Qemu-devel] [PATCH v4 8/8] hw: acpi: Remove AcpiRsdpDescriptor and fix tests Samuel Ortiz
2018-12-18  1:10 ` [Qemu-devel] [PATCH v4 0/8] hw: acpi: RSDP fixes and refactoring Michael S. Tsirkin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.