Received: from eggs.gnu.org ([2001:4830:134:3::10]:50809) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xz5nq-00073w-C1 for qemu-devel@nongnu.org; Thu, 11 Dec 2014 10:37:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xz5nh-0007l6-BJ for qemu-devel@nongnu.org; Thu, 11 Dec 2014 10:37:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59922) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xz5nh-0007kw-3D for qemu-devel@nongnu.org; Thu, 11 Dec 2014 10:37:09 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBBFb8Xf007865 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 11 Dec 2014 10:37:08 -0500 From: Igor Mammedov Date: Thu, 11 Dec 2014 15:36:59 +0000 Message-Id: <1418312221-13879-3-git-send-email-imammedo@redhat.com> In-Reply-To: <1418312221-13879-1-git-send-email-imammedo@redhat.com> References: <1418312221-13879-1-git-send-email-imammedo@redhat.com> Subject: [Qemu-devel] [PATCH V2 2/4] pc: acpi-build: place RSDT at fixed offset across reboots List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, marcel.a@redhat.com, mst@redhat.com Fixing RSDT location allows pointer to RSDP be constant and we can keep RSDP file immutable for the whole instance lifetime. Which makes this fix suitable for stable, since migration format doesn't change in addition it fixes old machine types as well without breaking compatibility. Signed-off-by: Igor Mammedov --- hw/i386/acpi-build.c | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 4d2b3b9..4b0bc44 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -1431,16 +1431,23 @@ build_dsdt(GArray *table_data, GArray *linker, AcpiMiscInfo *misc) misc->dsdt_size, 1); } -/* Build final rsdt table */ -static void -build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets) +/* reserve space for RSDT */ +static void alloc_rsdt(GArray *table_data, int tables_count) { - AcpiRsdtDescriptorRev1 *rsdt; size_t rsdt_len; + + rsdt_len = sizeof(AcpiRsdtDescriptorRev1) + sizeof(uint32_t) * tables_count; + acpi_data_push(table_data, rsdt_len); +} + +/* fill final rsdt table */ +static void fill_rsdt(GArray *table_data, GArray *linker, + unsigned rsdt_offset, GArray *table_offsets) +{ int i; + AcpiRsdtDescriptorRev1 *rsdt = (void *)(table_data->data + rsdt_offset); + size_t rsdt_len = sizeof(*rsdt) + sizeof(uint32_t) * table_offsets->len; - rsdt_len = sizeof(*rsdt) + sizeof(uint32_t) * table_offsets->len; - rsdt = acpi_data_push(table_data, rsdt_len); memcpy(rsdt->table_offset_entry, table_offsets->data, sizeof(uint32_t) * table_offsets->len); for (i = 0; i < table_offsets->len; ++i) { @@ -1562,6 +1569,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables) PcPciInfo pci; uint8_t *u; size_t aml_len = 0; + int tables_count = 0; acpi_get_cpu_info(&cpu); acpi_get_pm_info(&pm); @@ -1594,6 +1602,23 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables) */ aml_len += tables->table_data->len - dsdt; + /* preallocate RSDT at fixed position to keep its offset + * constant accorss reboots since FACS and DSDT are static. + * This way RSDP referencing it could be kept immutable. + */ + tables_count = 1 /* FADT */ + 1 /* SSDT */ + 1 /* MADT */ + + (misc.has_hpet ? 1 : 0) + + (misc.has_tpm ? 2 : 0) + + (guest_info->numa_nodes ? 1 : 0) + + (acpi_get_mcfg(&mcfg) ? 1 : 0) + + (acpi_has_iommu() ? 1 : 0); + for (u = acpi_table_first(); u; u = acpi_table_next(u)) { + tables_count++; + } + rsdt = tables->table_data->len; + alloc_rsdt(tables->table_data, tables_count); + + /* ACPI tables pointed to by RSDT */ acpi_add_table(table_offsets, tables->table_data); build_fadt(tables->table_data, tables->linker, &pm, facs, dsdt); @@ -1640,8 +1665,7 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables) } /* RSDT is pointed to by RSDP */ - rsdt = tables->table_data->len; - build_rsdt(tables->table_data, tables->linker, table_offsets); + fill_rsdt(tables->table_data, tables->linker, rsdt, table_offsets); /* RSDP is in FSEG memory, so allocate it separately */ build_rsdp(tables->rsdp, tables->linker, rsdt); -- 1.8.3.1