All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] qfw/acpi & efi_loader: Fix linker cleanup, RSDP bounds, and absent/offset ACPI handling
@ 2026-12-03  2:21 Dan Holmes-Mitra
  2026-12-03  2:21 ` [PATCH 1/4] qfw/acpi: Do not free non-heap addresses on linker error Dan Holmes-Mitra
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Dan Holmes-Mitra @ 2026-12-03  2:21 UTC (permalink / raw)
  To: u-boot; +Cc: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas

Four targeted fixes for QEMU fw_cfg ACPI loading and EFI ACPI/FDT
registration:

1. qfw/acpi: On BIOS linker error, walk only processed ALLOCATE entries,
   free only ZONE_HIGH heap buffers when CONFIG_BLOBLIST_TABLES is
   disabled (never bloblist or ZONE_FSEG addresses), and clear ctx->rsdp.
2. qfw/acpi: Compute the 20-byte base RSDP checksum first, guard the
   ACPI 2.0 length/ext_checksum writes behind revision >= 2 so 20-byte
   ACPI 1.0 RSDPs (e.g. QEMU i440fx) do not overflow by 16 bytes, and
   guard NULL in acpi_get_rsdp_addr().
3. qfw/acpi: Skip adding BLOBLISTT_ACPI_TABLES when etc/table-loader is
   absent (e.g. QEMU -M virt,acpi=off). Keep the 64 KiB reservation when
   CONFIG_BLOBLIST_TABLES is disabled (so default 0x20000 bloblists are
   unaffected) and dynamically sum aligned ALLOCATE entry sizes from
   etc/table-loader when CONFIG_BLOBLIST_TABLES is enabled.
4. efi_loader: Prefer gd_acpi_start() when non-zero (while falling back
   to map_to_sysmem(tab) for prior-stage bloblist ACPI handoffs) so
   EFI_ACPI_TABLE_GUID points to the actual RSDP inside BLOBLISTT_ACPI_TABLES,
   treat absent runtime ACPI tables (!tab / !gd_acpi_start()) as a
   non-fatal no-op in efi_acpi_register(), and check whether
   EFI_ACPI_TABLE_GUID was actually installed in efi_install_fdt() so
   FDT boot works when firmware supplies no ACPI tables while preserving
   EBBR for prior-stage bloblist ACPI handoffs.

Tested:
- Live QEMU arm64 (qemu_arm64_defconfig + CONFIG_ACPI + CONFIG_GENERATE_ACPI_TABLE):
  - CONFIG_BLOBLIST_TABLES=y (CONFIG_BLOBLIST_SIZE_RELOC=0x40000), -M virt,acpi=on:
    bloblist sized dynamically to 0x21000; `acpi list` and `efidebug tables`
    report valid RSDP/XSDT/DSDT/FACP/APIC/GTDT/MCFG/SPCR/DBG2/IORT.
  - CONFIG_BLOBLIST_TABLES=y, -M virt,acpi=off: `bloblist list` omits
    BLOBLISTT_ACPI_TABLES and `efidebug tables` succeeds cleanly.
  - Default CONFIG_BLOBLIST_TABLES=n (CONFIG_BLOBLIST_SIZE_RELOC=0x20000),
    -M virt,acpi=on: 0x10000 bloblist, `acpi list` and `efidebug tables` pass.
- Stock qemu-x86_64_defconfig (CONFIG_BLOBLIST_SIZE_RELOC=0x40000, ACPI_SIZE=192K):
  built cleanly (no arch/x86/lib/tables.c size change).
- Checked with scripts/checkpatch.pl --strict --u-boot (0 errors, 0 warnings).

Dan Holmes-Mitra (4):
  qfw/acpi: Do not free non-heap addresses on linker error
  qfw/acpi: Guard ACPI 1.0 RSDP bounds and NULL lookup
  qfw/acpi: Skip absent ACPI bloblist and size from table-loader
  efi_loader: Handle offset or absent runtime ACPI tables

 drivers/misc/qfw_acpi.c     | 88 +++++++++++++++++++++++++++++++------
 lib/efi_loader/efi_acpi.c   |  6 ++-
 lib/efi_loader/efi_helper.c |  9 +++-
 3 files changed, 87 insertions(+), 16 deletions(-)


base-commit: d1caced3a435607435cb7969e34499051a4ac1e6
-- 
2.56.1.911.g883d8bcb20-goog


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

* [PATCH 1/4] qfw/acpi: Do not free non-heap addresses on linker error
  2026-12-03  2:21 [PATCH 0/4] qfw/acpi & efi_loader: Fix linker cleanup, RSDP bounds, and absent/offset ACPI handling Dan Holmes-Mitra
@ 2026-12-03  2:21 ` Dan Holmes-Mitra
  2026-12-03  2:21 ` [PATCH 2/4] qfw/acpi: Guard ACPI 1.0 RSDP bounds and NULL lookup Dan Holmes-Mitra
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Dan Holmes-Mitra @ 2026-12-03  2:21 UTC (permalink / raw)
  To: u-boot; +Cc: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas

On a BIOS linker error, write_acpi_tables() previously iterated every
fw_cfg file with a non-zero addr and passed it to free(). When
CONFIG_BLOBLIST_TABLES is enabled all file addresses lie inside the
bloblist, and without it ZONE_FSEG allocations lie in the caller's
table buffer rather than the heap; freeing them corrupts the allocator.
In addition, ctx->rsdp was left pointing at the invalidated RSDP.

Walk only the processed ALLOCATE entries, call free() solely for
ZONE_HIGH heap allocations when CONFIG_BLOBLIST_TABLES is disabled, and
clear ctx->rsdp on error.

Signed-off-by: Dan Holmes-Mitra <dholmesm@google.com>
---
 drivers/misc/qfw_acpi.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/drivers/misc/qfw_acpi.c b/drivers/misc/qfw_acpi.c
index afa3b82039..7cb81eb222 100644
--- a/drivers/misc/qfw_acpi.c
+++ b/drivers/misc/qfw_acpi.c
@@ -245,15 +245,23 @@ ulong write_acpi_tables(ulong addr)
 
 out:
 	if (ret) {
-		struct fw_cfg_file_iter iter;
-		for (file = qfw_file_iter_init(dev, &iter);
-		     !qfw_file_iter_end(&iter);
-		     file = qfw_file_iter_next(&iter)) {
-			if (file->addr) {
+		int j;
+
+		for (j = 0; j < i; j++) {
+			entry = table_loader + j;
+			if (le32_to_cpu(entry->command) !=
+			    BIOS_LINKER_LOADER_COMMAND_ALLOCATE)
+				continue;
+			file = qfw_find_file(dev, entry->alloc.file);
+			if (!file || !file->addr)
+				continue;
+			if (!IS_ENABLED(CONFIG_BLOBLIST_TABLES) &&
+			    entry->alloc.zone ==
+			    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH)
 				free((void *)file->addr);
-				file->addr = 0;
-			}
+			file->addr = 0;
 		}
+		ctx->rsdp = NULL;
 	}
 
 	free(table_loader);
-- 
2.56.1.911.g883d8bcb20-goog


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

* [PATCH 2/4] qfw/acpi: Guard ACPI 1.0 RSDP bounds and NULL lookup
  2026-12-03  2:21 [PATCH 0/4] qfw/acpi & efi_loader: Fix linker cleanup, RSDP bounds, and absent/offset ACPI handling Dan Holmes-Mitra
  2026-12-03  2:21 ` [PATCH 1/4] qfw/acpi: Do not free non-heap addresses on linker error Dan Holmes-Mitra
@ 2026-12-03  2:21 ` Dan Holmes-Mitra
  2026-12-03  2:21 ` [PATCH 3/4] qfw/acpi: Skip absent ACPI bloblist and size from table-loader Dan Holmes-Mitra
  2026-12-03  2:21 ` [PATCH 4/4] efi_loader: Handle offset or absent runtime ACPI tables Dan Holmes-Mitra
  3 siblings, 0 replies; 5+ messages in thread
From: Dan Holmes-Mitra @ 2026-12-03  2:21 UTC (permalink / raw)
  To: u-boot; +Cc: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas

QEMU x86 i440fx provides a 20-byte ACPI 1.0 RSDP (revision 0) in
etc/acpi/rsdp. Unconditionally writing rsdp->length (offset 20) and
rsdp->ext_checksum (offset 32) overflowed 16 bytes past the end of the
allocation into adjacent table memory.

Only update the ACPI 2.0 extended fields when rsdp->revision >=
ACPI_RSDP_REV_ACPI_2_0, recompute the 20-byte base checksum, and guard
against a NULL file pointer in acpi_get_rsdp_addr() when etc/acpi/rsdp
is absent.

Signed-off-by: Dan Holmes-Mitra <dholmesm@google.com>
---
 drivers/misc/qfw_acpi.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/misc/qfw_acpi.c b/drivers/misc/qfw_acpi.c
index 7cb81eb222..580bef4adb 100644
--- a/drivers/misc/qfw_acpi.c
+++ b/drivers/misc/qfw_acpi.c
@@ -272,9 +272,14 @@ out:
 	}
 	struct acpi_rsdp *rsdp = ctx->rsdp;
 
-	rsdp->length = sizeof(*rsdp);
-	rsdp->ext_checksum = 0;
-	rsdp->ext_checksum = table_compute_checksum((u8 *)rsdp, sizeof(*rsdp));
+	rsdp->checksum = 0;
+	rsdp->checksum = table_compute_checksum((u8 *)rsdp, 20);
+	if (rsdp->revision >= ACPI_RSDP_REV_ACPI_2_0) {
+		rsdp->length = sizeof(*rsdp);
+		rsdp->ext_checksum = 0;
+		rsdp->ext_checksum = table_compute_checksum((u8 *)rsdp,
+							    sizeof(*rsdp));
+	}
 
 	gd_set_acpi_start(acpi_get_rsdp_addr());
 
@@ -294,7 +299,7 @@ ulong acpi_get_rsdp_addr(void)
 	}
 
 	file = qfw_find_file(dev, "etc/acpi/rsdp");
-	return file->addr;
+	return file ? file->addr : 0;
 }
 
 void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt,
-- 
2.56.1.911.g883d8bcb20-goog


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

* [PATCH 3/4] qfw/acpi: Skip absent ACPI bloblist and size from table-loader
  2026-12-03  2:21 [PATCH 0/4] qfw/acpi & efi_loader: Fix linker cleanup, RSDP bounds, and absent/offset ACPI handling Dan Holmes-Mitra
  2026-12-03  2:21 ` [PATCH 1/4] qfw/acpi: Do not free non-heap addresses on linker error Dan Holmes-Mitra
  2026-12-03  2:21 ` [PATCH 2/4] qfw/acpi: Guard ACPI 1.0 RSDP bounds and NULL lookup Dan Holmes-Mitra
@ 2026-12-03  2:21 ` Dan Holmes-Mitra
  2026-12-03  2:21 ` [PATCH 4/4] efi_loader: Handle offset or absent runtime ACPI tables Dan Holmes-Mitra
  3 siblings, 0 replies; 5+ messages in thread
From: Dan Holmes-Mitra @ 2026-12-03  2:21 UTC (permalink / raw)
  To: u-boot; +Cc: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas

When QEMU is launched with ACPI disabled (for example -M virt,acpi=off),
etc/table-loader is not exposed over fw_cfg, yet evt_write_acpi_tables()
still created an empty BLOBLISTT_ACPI_TABLES entry.

In addition, when CONFIG_BLOBLIST_TABLES is enabled, all ALLOCATE files
(such as 128 KiB etc/acpi/tables plus optional TPM log and RSDP) are
placed into the bloblist, exceeding the fixed 64 KiB reservation, while
a fixed 256 KiB reservation overflows smaller CONFIG_BLOBLIST_SIZE_RELOC
budgets (such as 0x20000 or 0x40000).

Check for etc/table-loader before creating BLOBLISTT_ACPI_TABLES, keep
the 64 KiB reservation when CONFIG_BLOBLIST_TABLES is disabled, and sum
the aligned ALLOCATE entry sizes from etc/table-loader when enabled.

Signed-off-by: Dan Holmes-Mitra <dholmesm@google.com>
---
 drivers/misc/qfw_acpi.c | 53 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 51 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/qfw_acpi.c b/drivers/misc/qfw_acpi.c
index 580bef4adb..9553d89e06 100644
--- a/drivers/misc/qfw_acpi.c
+++ b/drivers/misc/qfw_acpi.c
@@ -326,13 +326,62 @@ void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt,
 }
 
 #ifndef CONFIG_X86
+static u32 qfw_acpi_blob_size(struct udevice *dev, struct fw_file *loader)
+{
+	struct bios_linker_entry *entries;
+	u32 size, total = 0;
+	int i;
+
+	if (!IS_ENABLED(CONFIG_BLOBLIST_TABLES))
+		return SZ_64K;
+
+	size = be32_to_cpu(loader->cfg.size);
+	entries = malloc(size);
+	if (!entries)
+		return SZ_64K;
+
+	qfw_read_entry(dev, be16_to_cpu(loader->cfg.select), size, entries);
+	for (i = 0; i < size / sizeof(*entries); i++) {
+		struct bios_linker_entry *entry = entries + i;
+		struct fw_file *file;
+		u32 align;
+
+		if (le32_to_cpu(entry->command) !=
+		    BIOS_LINKER_LOADER_COMMAND_ALLOCATE)
+			continue;
+		file = qfw_find_file(dev, entry->alloc.file);
+		if (!file)
+			continue;
+		align = le32_to_cpu(entry->alloc.align);
+		if (align && !(align & (align - 1))) {
+			if (align > SZ_4K)
+				total += align - SZ_4K;
+			total = ALIGN(total, align);
+		}
+		total += be32_to_cpu(file->cfg.size);
+	}
+	free(entries);
+
+	return max_t(u32, ALIGN(total, SZ_4K), SZ_64K);
+}
+
 static int evt_write_acpi_tables(void)
 {
+	struct udevice *dev;
+	struct fw_file *loader;
 	ulong addr, end;
 	void *ptr;
 
-	/* Reserve 64K for ACPI tables, aligned to a 4K boundary */
-	ptr = bloblist_add(BLOBLISTT_ACPI_TABLES, SZ_64K, 12);
+	if (qfw_get_dev(&dev) || qfw_read_firmware_list(dev))
+		return 0;
+
+	loader = qfw_find_file(dev, "etc/table-loader");
+	if (!loader)
+		return 0;
+
+	/* Reserve space for ACPI tables, aligned to a 4K boundary */
+	ptr = bloblist_add(BLOBLISTT_ACPI_TABLES,
+			   qfw_acpi_blob_size(dev, loader), 12);
 	if (!ptr)
 		return -ENOBUFS;
 	addr = map_to_sysmem(ptr);
-- 
2.56.1.911.g883d8bcb20-goog


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

* [PATCH 4/4] efi_loader: Handle offset or absent runtime ACPI tables
  2026-12-03  2:21 [PATCH 0/4] qfw/acpi & efi_loader: Fix linker cleanup, RSDP bounds, and absent/offset ACPI handling Dan Holmes-Mitra
                   ` (2 preceding siblings ...)
  2026-12-03  2:21 ` [PATCH 3/4] qfw/acpi: Skip absent ACPI bloblist and size from table-loader Dan Holmes-Mitra
@ 2026-12-03  2:21 ` Dan Holmes-Mitra
  3 siblings, 0 replies; 5+ messages in thread
From: Dan Holmes-Mitra @ 2026-12-03  2:21 UTC (permalink / raw)
  To: u-boot; +Cc: Tom Rini, Heinrich Schuchardt, Ilias Apalodimas

When QFW loads QEMU ACPI tables into BLOBLISTT_ACPI_TABLES, the RSDP is
placed after etc/acpi/tables rather than at offset 0 of the bloblist.
efi_acpi_register() previously passed map_to_sysmem(tab) to
efi_install_configuration_table() instead of gd_acpi_start(), handing
payloads raw DSDT/FACP bytes instead of the RSDP.

Prefer gd_acpi_start() when non-zero (while falling back to
map_to_sysmem(tab) so prior-stage bloblist ACPI handoffs keep working),
and treat absent runtime ACPI tables (!tab in bloblist mode, or
!gd_acpi_start() otherwise) as a non-fatal no-op in efi_acpi_register().
In efi_install_fdt(), check whether EFI_ACPI_TABLE_GUID was actually
installed so platforms built with CONFIG_GENERATE_ACPI_TABLE fall back
to FDT when no ACPI tables exist while still honoring EBBR for
prior-stage bloblist ACPI handoffs.

Signed-off-by: Dan Holmes-Mitra <dholmesm@google.com>
---
 lib/efi_loader/efi_acpi.c   | 6 +++++-
 lib/efi_loader/efi_helper.c | 9 +++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/efi_loader/efi_acpi.c b/lib/efi_loader/efi_acpi.c
index 046986a751..af7b38934e 100644
--- a/lib/efi_loader/efi_acpi.c
+++ b/lib/efi_loader/efi_acpi.c
@@ -40,14 +40,18 @@ efi_status_t efi_acpi_register(void)
 		void *tab = bloblist_get_blob(BLOBLISTT_ACPI_TABLES, &size);
 
 		if (!tab)
-			return EFI_NOT_FOUND;
+			return EFI_SUCCESS;
 		addr = map_to_sysmem(tab);
 
 		ret = efi_add_memory_map(addr, size,
 					 EFI_ACPI_RECLAIM_MEMORY);
 		if (ret != EFI_SUCCESS)
 			return ret;
+		if (gd_acpi_start())
+			addr = gd_acpi_start();
 	} else {
+		if (!gd_acpi_start())
+			return EFI_SUCCESS;
 		/* Mark space used for tables */
 		start = ALIGN_DOWN(gd->arch.table_start, EFI_PAGE_MASK);
 		end = ALIGN(gd->arch.table_end, EFI_PAGE_MASK);
diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c
index 44b806aadc..928863af66 100644
--- a/lib/efi_loader/efi_helper.c
+++ b/lib/efi_loader/efi_helper.c
@@ -544,14 +544,19 @@ void *efi_get_configuration_table(const efi_guid_t *guid)
  */
 efi_status_t efi_install_fdt(void *fdt)
 {
+	static const efi_guid_t acpi_guid = EFI_ACPI_TABLE_GUID;
 	struct bootm_headers img = { 0 };
+	bool has_acpi;
 	efi_status_t ret;
 
+	has_acpi = CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) &&
+		   efi_get_configuration_table(&acpi_guid);
+
 	/*
 	 * The EBBR spec requires that we have either an FDT or an ACPI table
 	 * but not both.
 	 */
-	if (CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) && fdt)
+	if (has_acpi && fdt)
 		log_warning("Can't have ACPI table and device tree - ignoring DT.\n");
 
 	if (fdt == EFI_FDT_USE_INTERNAL) {
@@ -582,7 +587,7 @@ efi_status_t efi_install_fdt(void *fdt)
 		return EFI_LOAD_ERROR;
 	}
 
-	if (CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE)) {
+	if (has_acpi) {
 		/* Create memory reservations as indicated by the device tree */
 		efi_carve_out_dt_rsv(fdt);
 		return EFI_SUCCESS;
-- 
2.56.1.911.g883d8bcb20-goog


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

end of thread, other threads:[~2026-12-03  5:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03  2:21 [PATCH 0/4] qfw/acpi & efi_loader: Fix linker cleanup, RSDP bounds, and absent/offset ACPI handling Dan Holmes-Mitra
2026-12-03  2:21 ` [PATCH 1/4] qfw/acpi: Do not free non-heap addresses on linker error Dan Holmes-Mitra
2026-12-03  2:21 ` [PATCH 2/4] qfw/acpi: Guard ACPI 1.0 RSDP bounds and NULL lookup Dan Holmes-Mitra
2026-12-03  2:21 ` [PATCH 3/4] qfw/acpi: Skip absent ACPI bloblist and size from table-loader Dan Holmes-Mitra
2026-12-03  2:21 ` [PATCH 4/4] efi_loader: Handle offset or absent runtime ACPI tables Dan Holmes-Mitra

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.