From nobody Tue Apr 8 22:18:33 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515678302487312.80965606229574; Thu, 11 Jan 2018 05:45:02 -0800 (PST) Received: from localhost ([::1]:44004 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZdAD-0004VM-L2 for importer@patchew.org; Thu, 11 Jan 2018 08:45:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52098) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZd3z-0007Q8-Cb for qemu-devel@nongnu.org; Thu, 11 Jan 2018 08:38:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZd3y-0008VP-6D for qemu-devel@nongnu.org; Thu, 11 Jan 2018 08:38:35 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:45842) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eZd3x-0008Ns-V0 for qemu-devel@nongnu.org; Thu, 11 Jan 2018 08:38:34 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eZd3v-0005em-PO for qemu-devel@nongnu.org; Thu, 11 Jan 2018 13:38:31 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 11 Jan 2018 13:38:05 +0000 Message-Id: <1515677902-23436-10-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515677902-23436-1-git-send-email-peter.maydell@linaro.org> References: <1515677902-23436-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 09/26] Virt: ACPI: fix qemu assert due to re-assigned table data address X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Zhaoshenglong acpi_data_push uses g_array_set_size to resize the memory size. If there is no enough contiguous memory, the address will be changed. If we use the old value, it will assert. qemu-kvm: hw/acpi/bios-linker-loader.c:214: bios_linker_loader_add_checksum: Assertion `start_offset < file->blob->len' failed.` This issue only happens in building SRAT table now but here we unify the pattern for other tables as well to avoid possible issues in the future. Signed-off-by: Zhaoshenglong Reviewed-by: Andrew Jones Signed-off-by: Peter Maydell --- hw/arm/virt-acpi-build.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index 3d78ff6..f7fa795 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -453,6 +453,7 @@ build_spcr(GArray *table_data, BIOSLinker *linker, Virt= MachineState *vms) AcpiSerialPortConsoleRedirection *spcr; const MemMapEntry *uart_memmap =3D &vms->memmap[VIRT_UART]; int irq =3D vms->irqmap[VIRT_UART] + ARM_SPI_BASE; + int spcr_start =3D table_data->len; =20 spcr =3D acpi_data_push(table_data, sizeof(*spcr)); =20 @@ -476,8 +477,8 @@ build_spcr(GArray *table_data, BIOSLinker *linker, Virt= MachineState *vms) spcr->pci_device_id =3D 0xffff; /* PCI Device ID: not a PCI device */ spcr->pci_vendor_id =3D 0xffff; /* PCI Vendor ID: not a PCI device */ =20 - build_header(linker, table_data, (void *)spcr, "SPCR", sizeof(*spcr), = 2, - NULL, NULL); + build_header(linker, table_data, (void *)(table_data->data + spcr_star= t), + "SPCR", table_data->len - spcr_start, 2, NULL, NULL); } =20 static void @@ -512,8 +513,8 @@ build_srat(GArray *table_data, BIOSLinker *linker, Virt= MachineState *vms) mem_base +=3D numa_info[i].node_mem; } =20 - build_header(linker, table_data, (void *)srat, "SRAT", - table_data->len - srat_start, 3, NULL, NULL); + build_header(linker, table_data, (void *)(table_data->data + srat_star= t), + "SRAT", table_data->len - srat_start, 3, NULL, NULL); } =20 static void @@ -522,6 +523,7 @@ build_mcfg(GArray *table_data, BIOSLinker *linker, Virt= MachineState *vms) AcpiTableMcfg *mcfg; const MemMapEntry *memmap =3D vms->memmap; int len =3D sizeof(*mcfg) + sizeof(mcfg->allocation[0]); + int mcfg_start =3D table_data->len; =20 mcfg =3D acpi_data_push(table_data, len); mcfg->allocation[0].address =3D cpu_to_le64(memmap[VIRT_PCIE_ECAM].bas= e); @@ -532,7 +534,8 @@ build_mcfg(GArray *table_data, BIOSLinker *linker, Virt= MachineState *vms) mcfg->allocation[0].end_bus_number =3D (memmap[VIRT_PCIE_ECAM].size / PCIE_MMCFG_SIZE_MIN) - 1; =20 - build_header(linker, table_data, (void *)mcfg, "MCFG", len, 1, NULL, N= ULL); + build_header(linker, table_data, (void *)(table_data->data + mcfg_star= t), + "MCFG", table_data->len - mcfg_start, 1, NULL, NULL); } =20 /* GTDT */ @@ -651,6 +654,7 @@ build_madt(GArray *table_data, BIOSLinker *linker, Virt= MachineState *vms) static void build_fadt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms, unsigned dsdt_tbl_offset) { + int fadt_start =3D table_data->len; AcpiFadtDescriptorRev5_1 *fadt =3D acpi_data_push(table_data, sizeof(*= fadt)); unsigned xdsdt_entry_offset =3D (char *)&fadt->x_dsdt - table_data->da= ta; uint16_t bootflags; @@ -681,8 +685,8 @@ static void build_fadt(GArray *table_data, BIOSLinker *= linker, ACPI_BUILD_TABLE_FILE, xdsdt_entry_offset, sizeof(fadt->x_dsdt), ACPI_BUILD_TABLE_FILE, dsdt_tbl_offset); =20 - build_header(linker, table_data, - (void *)fadt, "FACP", sizeof(*fadt), 5, NULL, NULL); + build_header(linker, table_data, (void *)(table_data->data + fadt_star= t), + "FACP", table_data->len - fadt_start, 5, NULL, NULL); } =20 /* DSDT */ --=20 2.7.4