:p
atchew
Login
This series fixes ACPI BGRT (Boot Graphics Resource Table) corruption, that occured when Xen reuses the memory containing the boot logo image before dom0 is able to parse ACPI tables. The BGRT table contains a pointer to a BMP image stored in BootServicesData memory. When Xen reclaims this memory early in boot, the pointer becomes invalid, causing Linux dom0 to report: Xen: `(XEN) ACPI: BGRT: invalidating v1 image at 0x47cc2018` Linux (dom0): `ACPI BIOS Warning (bug): Incorrect checksum in table [BGRT] - 0xF9, should be 0xB4 (20250807/utcksum-58)` This series: 1. Adds BGRT image preservation during EFI boot (similar to ESRT) 2. Removes the now-unnecessary invalidation code 3. Provides an opt-out mechanism (efi=no-bgrt) for servers The preservation is enabled by default to fix the corruption for all users, with minimal overhead (~1MB). Also, servers that don't need boot graphics can disable it using the "efi=no-bgrt" option. Testing: - Verified on Intel UEFI system with Fedora 43 dom0 - Before: ACPI checksum errors in dom0 - After: Clean boot, no ACPI warnings - Memory overhead: ~972 KB (preserved image size) Signed-off-by: Soumyajyotii Ssarkar <soumyajyotisarkar23@gmail.com> Soumyajyotii Ssarkar (3): x86/efi: Add BGRT image preservation during boot x86/acpi: Remove BGRT invalidation code x86/efi: Add opt-out mechanism for BGRT preservation xen/arch/x86/acpi/boot.c | 23 ----- xen/arch/x86/efi/efi-boot.h | 2 + xen/common/efi/boot.c | 199 ++++++++++++++++++++++++++++++++++++ 3 files changed, 201 insertions(+), 23 deletions(-) -- 2.53.0
The ACPI BGRT (Boot Graphics Resource Table) contains a pointer to a boot logo image stored in BootServicesData memory. When Xen reclaims this memory during boot, the image is lost and the BGRT table becomes invalid, causing Linux dom0 to report ACPI checksum errors. Add preservation logic similar to ESRT table handling: - Locate BGRT table via XSDT during EFI boot services phase - Validate BMP image signature and size (max 16 MB) - Copy image to EfiACPIReclaimMemory (safe from reclamation) - Update BGRT table with new image address - Recalculate ACPI table checksum The preservation runs automatically during efi_exit_boot() before Boot Services are terminated. This ensures the image remains accessible to dom0. Open coded ACPI parsing is used because Xen's ACPI subsystem is not available during the EFI boot phase. The RSDP is obtained from the EFI System Table, and the XSDT is walked manually to find BGRT. Signed-off-by: Soumyajyotii Ssarkar <soumyajyotisarkar23@gmail.com> --- xen/arch/x86/efi/efi-boot.h | 2 + xen/common/efi/boot.c | 187 ++++++++++++++++++++++++++++++++++++ 2 files changed, 189 insertions(+) diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index XXXXXXX..XXXXXXX 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -XXX,XX +XXX,XX @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, efi_relocate_esrt(SystemTable); + efi_preserve_bgrt_img(SystemTable); + efi_exit_boot(ImageHandle, SystemTable); } diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index XXXXXXX..XXXXXXX 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -XXX,XX +XXX,XX @@ #include <xen/ctype.h> #include <xen/dmi.h> #include <xen/domain_page.h> +#include <xen/errno.h> #include <xen/init.h> #include <xen/keyhandler.h> #include <xen/lib.h> @@ -XXX,XX +XXX,XX @@ static struct file __initdata ramdisk; static struct file __initdata xsm; static const CHAR16 __initconst newline[] = L"\r\n"; +static __initdata struct { + bool preserved; + uint64_t old_addr; + uint64_t new_addr; + uint32_t size; + const char *failure_reason; +} bgrt_debug_info; + static void __init PrintStr(const CHAR16 *s) { StdOut->OutputString(StdOut, (CHAR16 *)s ); @@ -XXX,XX +XXX,XX @@ static void __init efi_relocate_esrt(EFI_SYSTEM_TABLE *SystemTable) efi_bs->FreePool(memory_map); } +struct bmp_header { + uint16_t signature; + uint32_t file_size; + uint16_t reserved_1; + uint16_t reserved_2; + uint32_t data_offset; +} __attribute__((packed)); + +/* + * ACPI Structures - defined locally, + * since we cannot include acpi headers + * in EFI Context. + */ + +struct acpi_rsdp { + char signature[8]; + uint8_t checksum; + char oem_id[6]; + uint8_t revision; + uint32_t rsdt_physical_address; + uint32_t length; + uint64_t xsdt_physical_address; + uint8_t extended_checksum; + uint8_t reserved[3]; +} __attribute__((packed)); + +struct acpi_table_header { + char signature[4]; + uint32_t length; + uint8_t revision; + uint8_t checksum; + char oem_id[6]; + char oem_table_id[8]; + uint32_t oem_revision; + uint32_t asl_compiler_id; + uint32_t asl_compiler_revision; +} __attribute__((packed)); + +struct acpi_xsdt { + struct acpi_table_header header; + uint64_t table_offset_entry[1]; /* Variable array length */ +} __attribute__((packed)); + +struct acpi_bgrt { + struct acpi_table_header header; + uint16_t version; + uint8_t status; + uint8_t image_type; + uint64_t image_address; + uint32_t image_offset_x; + uint32_t image_offset_y; +} __attribute__((packed)); + +static struct acpi_bgrt* __init find_bgrt_table(EFI_SYSTEM_TABLE *SystemTable) +{ + EFI_GUID acpi2_guid = ACPI_20_TABLE_GUID; + struct acpi_rsdp *rsdp = NULL; + struct acpi_xsdt *xsdt; + struct acpi_bgrt *bgrt; + uint32_t entry_count, actual_size; + unsigned int i; + + for ( i = 0; i < SystemTable->NumberOfTableEntries; i++ ) + { + if ( match_guid(&acpi2_guid, &SystemTable->ConfigurationTable[i].VendorGuid) ) + { + rsdp = SystemTable->ConfigurationTable[i].VendorTable; + break; + } + } + + if ( !rsdp || !rsdp->xsdt_physical_address ) + return NULL; + + xsdt = (struct acpi_xsdt *)rsdp->xsdt_physical_address; + if ( !xsdt ) + return NULL; + + actual_size = (xsdt->header.length - sizeof(struct acpi_table_header)); + entry_count = (actual_size / sizeof(uint64_t)); + + for ( i = 0; i < entry_count; i++ ) + { + struct acpi_table_header *header = (struct acpi_table_header *)xsdt->table_offset_entry[i]; + + if ( header->signature[0] == 'B' + && header->signature[1] == 'G' + && header->signature[2] == 'R' + && header->signature[3] == 'T' ) + { + bgrt = (struct acpi_bgrt *)header; + return bgrt; + } + } + return NULL; +} + +#define MAX_IMAGE_SIZE (16 * 1024 * 1024) /* Sanity check: reject if bigger */ + +static void __init efi_preserve_bgrt_img(EFI_SYSTEM_TABLE *SystemTable) +{ + struct acpi_bgrt *bgrt; + struct bmp_header *bmp; + void *old_image, *new_image; + uint32_t image_size; + EFI_STATUS status; + uint8_t checksum; + unsigned int i; + + bgrt_debug_info.preserved = false; + bgrt_debug_info.failure_reason = NULL; + + bgrt = find_bgrt_table(SystemTable); + if ( !bgrt ) + { + bgrt_debug_info.failure_reason = "BGRT table not found in XSDT"; + return; + } + + if ( !bgrt->image_address ) + { + bgrt_debug_info.failure_reason = "BGRT image_address is NULL"; + return; + } + + old_image = (void *)bgrt->image_address; + bmp = (struct bmp_header *)old_image; + + if ( bmp->signature != 0x4D42 ) + { + bgrt_debug_info.failure_reason = "Invalid BMP signature"; + return; + } + + image_size = bmp->file_size; + if ( !image_size || image_size > MAX_IMAGE_SIZE ) + { + bgrt_debug_info.failure_reason = "Invalid image size"; + return; + } + + status = efi_bs->AllocatePool(EfiACPIReclaimMemory, image_size, &new_image); + if ( status != EFI_SUCCESS || !new_image ) + { + bgrt_debug_info.failure_reason = "Memory allocation failed"; + return; + } + + memcpy(new_image, old_image, image_size); + + bgrt->image_address = (uint64_t)new_image; + bgrt->status |= 0x01; + + bgrt->header.checksum = 0; + checksum = 0; + for ( i = 0; i < bgrt->header.length; i++ ) + checksum += ((uint8_t *)bgrt)[i]; + bgrt->header.checksum = (uint8_t)(0 - checksum); + + bgrt_debug_info.preserved = true; + bgrt_debug_info.old_addr = (uint64_t)old_image; + bgrt_debug_info.new_addr = (uint64_t)new_image; + bgrt_debug_info.size = image_size; +} + /* * Include architecture specific implementation here, which references the * static globals defined above. @@ -XXX,XX +XXX,XX @@ void __init efi_init_memory(void) if ( !efi_enabled(EFI_BOOT) ) return; + if ( bgrt_debug_info.preserved ) + { + printk(XENLOG_INFO "EFI: BGRT image preserved: %u KB\n", + bgrt_debug_info.size / 1024); + printk(XENLOG_INFO "EFI: BGRT relocated from %#" PRIx64 " to %#" PRIx64 "\n", + bgrt_debug_info.old_addr, bgrt_debug_info.new_addr); + } + else if ( bgrt_debug_info.failure_reason ) + { + printk(XENLOG_WARNING "EFI: BGRT preservation failed: %s\n", + bgrt_debug_info.failure_reason); + } + printk(XENLOG_DEBUG "EFI memory map:%s\n", map_bs ? " (mapping BootServices)" : ""); for ( i = 0; i < efi_memmap_size; i += efi_mdesc_size ) -- 2.53.0
Now that BGRT images are preserved during EFI boot (via EfiACPIReclaimMemory allocation), the invalidation code in acpi_parse_bgrt() is no longer needed. The BGRT table remains valid throughout boot. This removes the code that was marking BGRT invalid when the image memory was detected as unavailable, which was causing ACPI warnings in Linux dom0. Signed-off-by: Soumyajyotii Ssarkar <soumyajyotisarkar23@gmail.com> --- xen/arch/x86/acpi/boot.c | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/xen/arch/x86/acpi/boot.c b/xen/arch/x86/acpi/boot.c index XXXXXXX..XXXXXXX 100644 --- a/xen/arch/x86/acpi/boot.c +++ b/xen/arch/x86/acpi/boot.c @@ -XXX,XX +XXX,XX @@ static int __init cf_check acpi_parse_hpet(struct acpi_table_header *table) return 0; } -static int __init cf_check acpi_invalidate_bgrt(struct acpi_table_header *table) -{ - struct acpi_table_bgrt *bgrt_tbl = - container_of(table, struct acpi_table_bgrt, header); - - if (table->length < sizeof(*bgrt_tbl)) - return -1; - - if (bgrt_tbl->version == 1 && bgrt_tbl->image_address - && !page_is_ram_type(PFN_DOWN(bgrt_tbl->image_address), - RAM_TYPE_CONVENTIONAL)) - return 0; - - printk(KERN_INFO PREFIX "BGRT: invalidating v%d image at %#"PRIx64"\n", - bgrt_tbl->version, bgrt_tbl->image_address); - bgrt_tbl->image_address = 0; - bgrt_tbl->status &= ~1; - - return 0; -} - #define acpi_fadt_copy_address(dst, src, len) do { \ if (fadt->header.revision >= FADT2_REVISION_ID && \ fadt->header.length >= ACPI_FADT_V2_SIZE) \ @@ -XXX,XX +XXX,XX @@ int __init acpi_boot_init(void) acpi_hest_init(); - acpi_table_parse(ACPI_SIG_BGRT, acpi_invalidate_bgrt); - return 0; } -- 2.53.0
As described in the task, BGRT preservation is now enabled by default to fix ACPI corruption for desktop/workstation systems (similar to ESRT). Add an opt-out parameter 'efi=no-bgrt' to allow disabling BGRT preservation on systems where the ~1MB memory overhead is not desired. The parameter is parsed during normal Xen boot (not during EFI phase), so it only affects diagnostic logging. The opt-out flag is checked at the start of efi_preserve_bgrt_img(). Usage: Default: BGRT preserved automatically Opt-out: Add 'efi=no-bgrt' in Xen command line Signed-off-by: Soumyajyotii Ssarkar <soumyajyotisarkar23@gmail.com> --- xen/common/efi/boot.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index XXXXXXX..XXXXXXX 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -XXX,XX +XXX,XX @@ static SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdErr; static UINT32 __initdata mdesc_ver; static bool __initdata map_bs; +static bool __initdata opt_bgrt_disabled = false; static struct file __initdata cfg; static struct file __initdata kernel; @@ -XXX,XX +XXX,XX @@ static void __init efi_preserve_bgrt_img(EFI_SYSTEM_TABLE *SystemTable) bgrt_debug_info.preserved = false; bgrt_debug_info.failure_reason = NULL; + if ( opt_bgrt_disabled ) + return; + bgrt = find_bgrt_table(SystemTable); if ( !bgrt ) { @@ -XXX,XX +XXX,XX @@ static int __init cf_check parse_efi_param(const char *s) else __clear_bit(EFI_RS, &efi_flags); } + else if ( (ss - s) == 7 && !memcmp(s, "no-bgrt", 7) ) + { + opt_bgrt_disabled = true; + } else if ( (ss - s) > 5 && !memcmp(s, "attr=", 5) ) { if ( !cmdline_strcmp(s + 5, "uc") ) @@ -XXX,XX +XXX,XX @@ void __init efi_init_memory(void) if ( !efi_enabled(EFI_BOOT) ) return; - if ( bgrt_debug_info.preserved ) + if ( opt_bgrt_disabled ) + { + printk(XENLOG_INFO "EFI: BGRT preservation disabled\n"); + } + else if ( bgrt_debug_info.preserved ) { printk(XENLOG_INFO "EFI: BGRT image preserved: %u KB\n", bgrt_debug_info.size / 1024); -- 2.53.0
This RFC series plans to addres ACPI BGRT (Boot Graphics Resource Table) corruption, that occured when Xen reuses the memory containing the boot logo image before dom0 is able to parse ACPI tables. The BGRT table contains a pointer to a BMP image stored in BootServicesData memory. When Xen reclaims this memory early in boot, the pointer becomes invalid, causing Linux dom0 to report: Xen: `(XEN) ACPI: BGRT: invalidating v1 image at 0x47cc2018` Linux (dom0): `ACPI BIOS Warning (bug): Incorrect checksum in table [BGRT] - 0xF9, should be 0xB4 (20250807/utcksum-58)` This series: 1. Adds BGRT image preservation infrastructure during EFI boot (validates BMP format, allocates EfiACPIReclaimMemory, stores pointers) 2. Integrates preservation with ACPI subsystem (clarifies acpi_invalidate_bgrt() safety net behavior, adds status reporting via efi_bgrt_status_info()) 3. Provides opt-out mechanism (-nobgrt for xen.efi direct boot, efi=no-bgrt for multiboot2, both via early EFI-phase parsing) The preservation is enabled by default to fix the corruption for all users, with minimal overhead (~1MB). Also, servers that don't need boot graphics can disable it using the "efi=no-bgrt" option. Thank you everyone for the constructive feedback! It is really helpful, I hope this RFC series is upto standards, I would greatly appriciate further feedback. Changes since v1: - The BGRT invalidation behaviour should still presist and server as a safety net when "efi=no-bgrt" or the preservation fails for some reason thus: Add Clarify comment for BGRT invalidation behavior with preservation. Reported-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com> Changes since v2: - Use existing ACPI headers (actbl.h, actbl3.h) instead of custom structs - Modify the function names and code in function to conform with Coding Style. - Reuse efi.acpi20 from efi_tables() instead of manual RSDP search - Use appropriate types: EFI types for firmware code, unsigned int for loop counters (matching ESRT pattern) - Used of sizeof(<expression>) over sizeof(<type>) - Remove fixed-type widths & limited typecasting - Add Blank line ahead of the main return statement of a function. - Better wording error message for image cap size - Remove parse_boolean(no-bgrt) since it could be bit misleading - Add const qualifiers throughout for safety - Use %p format for pointers (32-bit compatibility) - Initialize failure_reason with string literal for proper relocation - Use memcmp() with ACPI_SIG_* constants for signature checks - Add direct Xen.efi calling. - Add opt-out mechanism with proper early parsing during EFI phase. Reported-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com> Reported-by: Jan Beulich <jbeulich@suse.com> Please refer to QubesOS Issue for more context: https://github.com/QubesOS/qubes-issues/issues/10764 This is a companion series to Linux Kernel side at https://patchew.org/linux/cover.751f45ebbb644244b1d9da3aff289d6b66db4c6b.1773058629.git-series.marmarek@invisiblethingslab.com/ Testing: - Verified on Intel UEFI system with Fedora 43 dom0 - Before: ACPI checksum errors in dom0 - After: Clean boot, no ACPI warnings - Memory overhead: ~972 KB (preserved image size) Signed-off-by: Soumyajyotii Ssarkar <soumyajyotisarkar23@gmail.com> Soumyajyotii Ssarkar (3): x86/efi: Add BGRT image preservation infrastructure x86/acpi: Integrate BGRT preservation with status reporting x86/efi: Add opt-out mechanism for BGRT preservation xen/arch/x86/acpi/boot.c | 8 ++ xen/arch/x86/efi/efi-boot.h | 5 ++ xen/common/efi/boot.c | 158 ++++++++++++++++++++++++++++++++++++ xen/include/xen/efi.h | 1 + 4 files changed, 172 insertions(+) -- 2.53.0
Add core EFI boot services code to preserve BGRT (Boot Graphics Resource Table) images during Xen boot. The BGRT contains a pointer to a boot logo stored in BootServicesData memory. Without preservation, this memory is reclaimed causing ACPI checksum errors in dom0. Implementation: - Walk XSDT to locate BGRT table (reusing efi.acpi20 from efi_tables()) - Validate BMP image signature and size constraints (max 16MB) - Allocate EfiACPIReclaimMemory and copy image data - Update BGRT table with new address and recalculate checksum The preservation follows the ESRT pattern, running before ExitBootServices() to ensure image remains accessible. Signed-off-by: Soumyajyotii Ssarkar <soumyajyotisarkar23@gmail.com> --- xen/arch/x86/efi/efi-boot.h | 2 + xen/common/efi/boot.c | 133 ++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index XXXXXXX..XXXXXXX 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -XXX,XX +XXX,XX @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, efi_relocate_esrt(SystemTable); + efi_preserve_bgrt_img(); + efi_exit_boot(ImageHandle, SystemTable); } diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index XXXXXXX..XXXXXXX 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -XXX,XX +XXX,XX @@ #include "efi.h" #include <efi/efiprot.h> #include <efi/efipciio.h> +#include <acpi/acconfig.h> +#include <acpi/actbl.h> +#include <acpi/actbl3.h> #include <public/xen.h> #include <xen/bitops.h> #include <xen/compile.h> #include <xen/ctype.h> #include <xen/dmi.h> #include <xen/domain_page.h> +#include <xen/errno.h> #include <xen/init.h> #include <xen/keyhandler.h> #include <xen/lib.h> @@ -XXX,XX +XXX,XX @@ static void __init efi_relocate_esrt(EFI_SYSTEM_TABLE *SystemTable) efi_bs->FreePool(memory_map); } +typedef struct { + UINT16 signature; + UINT32 file_size; + UINT16 reserved[2]; + UINT32 data_offset; +} __attribute__((packed)) BMP_HEADER; + +static __initdata struct { + bool preserved; + const void *old_addr; + const void *new_addr; + UINTN size; + const char *failure_reason; +} bgrt_info = { + /* We would prefer the failure_reason to print */ + .failure_reason = "", +}; + +static const struct acpi_table_bgrt *__init efi_get_bgrt(void) +{ + const struct acpi_table_rsdp *rsdp; + const struct acpi_table_xsdt *xsdt; + UINTN entry_count; + unsigned int i; + + if ( efi.acpi20 == EFI_INVALID_TABLE_ADDR ) + return NULL; + + rsdp = (const void *)(UINTN)efi.acpi20; + if ( !rsdp || !rsdp->xsdt_physical_address ) + return NULL; + + xsdt = (const void *)rsdp->xsdt_physical_address; + + if ( memcmp(xsdt->header.signature, ACPI_SIG_XSDT, 4) != 0 ) + return NULL; + + if ( xsdt->header.length < sizeof(xsdt->header) ) + return NULL; + entry_count = (xsdt->header.length - sizeof(xsdt->header)) / + sizeof(xsdt->table_offset_entry[0]); + + for ( i = 0; i < entry_count; i++ ) + { + const struct acpi_table_header *hdr; + + hdr = (const void *)xsdt->table_offset_entry[i]; + if ( !hdr ) + continue; + + if ( memcmp(hdr->signature, ACPI_SIG_BGRT, 4) == 0 && + hdr->length >= sizeof(struct acpi_table_bgrt) ) + return (const struct acpi_table_bgrt *)hdr; + } + + return NULL; +} + +#define BMP_SIGNATURE 0x4D42 +#define MAX_BGRT_IMAGE_SIZE (16 * 1024 * 1024) + +static void __init efi_preserve_bgrt_img(void) +{ + const struct acpi_table_bgrt *bgrt; + const BMP_HEADER *bmp; + const void *old_image; + void *new_image; + UINTN image_size; + EFI_STATUS status; + UINT8 checksum; + unsigned int i; + + bgrt_info.preserved = false; + + bgrt = efi_get_bgrt(); + if ( !bgrt ) + { + bgrt_info.failure_reason = "BGRT table not found"; + return; + } + + if ( !bgrt->image_address ) + return; + + old_image = (const void *)bgrt->image_address; + bmp = old_image; + + if ( bmp->signature != BMP_SIGNATURE ) + { + bgrt_info.failure_reason = "Invalid BMP signature"; + return; + } + + image_size = bmp->file_size; + if ( !image_size || image_size > MAX_BGRT_IMAGE_SIZE ) + { + bgrt_info.failure_reason = "Image size exceeds limit"; + return; + } + + /* + * Allocate memory of type EfiACPIReclaimMemory so that the image + * will remain available for the OS after ExitBootServices(). + */ + status = efi_bs->AllocatePool(EfiACPIReclaimMemory, image_size, &new_image); + if ( EFI_ERROR(status) ) + { + bgrt_info.failure_reason = "Memory allocation failed"; + return; + } + memcpy(new_image, old_image, image_size); + ((struct acpi_table_bgrt *)bgrt)->image_address = (UINTN)new_image; + ((struct acpi_table_bgrt *)bgrt)->header.checksum = 0; + checksum = 0; + + for ( i = 0; i < bgrt->header.length; i++ ) + checksum += ((const UINT8 *)bgrt)[i]; + + ((struct acpi_table_bgrt *)bgrt)->header.checksum = -checksum; + + /* Filling the debug struct for printing later */ + bgrt_info.preserved = true; + bgrt_info.old_addr = old_image; + bgrt_info.new_addr = new_image; + bgrt_info.size = image_size; +} + /* * Include architecture specific implementation here, which references the * static globals defined above. @@ -XXX,XX +XXX,XX @@ void EFIAPI __init noreturn efi_start(EFI_HANDLE ImageHandle, efi_relocate_esrt(SystemTable); + efi_preserve_bgrt_img(); + efi_exit_boot(ImageHandle, SystemTable); efi_arch_post_exit_boot(); /* Doesn't return. */ -- 2.53.0
Add status reporting for BGRT preservation and integrate with Xen's ACPI subsystem: - efi_bgrt_status_info() prints preservation status (success/failure) - Called from acpi_boot_init() after ACPI tables are processed - Clarifying comment explains why invalidation code remains The invalidation code in acpi_invalidate_bgrt() now acts as a safety net: if preservation fails, the image remains in conventional RAM and gets invalidated. If preservation succeeds, the image is in EfiACPIReclaimMemory which won't match the RAM_TYPE_CONVENTIONAL check, leaving the table valid. Signed-off-by: Soumyajyotii Ssarkar <soumyajyotisarkar23@gmail.com> --- xen/arch/x86/acpi/boot.c | 8 ++++++++ xen/common/efi/boot.c | 16 ++++++++++++++++ xen/include/xen/efi.h | 1 + 3 files changed, 25 insertions(+) diff --git a/xen/arch/x86/acpi/boot.c b/xen/arch/x86/acpi/boot.c index XXXXXXX..XXXXXXX 100644 --- a/xen/arch/x86/acpi/boot.c +++ b/xen/arch/x86/acpi/boot.c @@ -XXX,XX +XXX,XX @@ #include <xen/mm.h> #include <xen/param.h> #include <xen/dmi.h> +#include <xen/efi.h> #include <asm/fixmap.h> #include <asm/page.h> #include <asm/apic.h> @@ -XXX,XX +XXX,XX @@ static int __init cf_check acpi_parse_hpet(struct acpi_table_header *table) return 0; } +/* + * Invalidate BGRT if image is in conventional RAM (preservation failed). + * If preservation succeeded, image is in EfiACPIReclaimMemory, which + * won't match RAM_TYPE_CONVENTIONAL check, so table remains valid. + */ static int __init cf_check acpi_invalidate_bgrt(struct acpi_table_header *table) { struct acpi_table_bgrt *bgrt_tbl = @@ -XXX,XX +XXX,XX @@ int __init acpi_boot_init(void) acpi_table_parse(ACPI_SIG_BGRT, acpi_invalidate_bgrt); + efi_bgrt_status_info(); + return 0; } diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index XXXXXXX..XXXXXXX 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -XXX,XX +XXX,XX @@ static bool __init cf_check rt_range_valid(unsigned long smfn, unsigned long emf return true; } +void __init efi_bgrt_status_info(void) +{ + if ( !efi_enabled(EFI_BOOT) ) + return; + + if ( bgrt_info.preserved ) + { + printk(XENLOG_INFO "EFI: BGRT image preserved: %lu KB\n", + bgrt_info.size / 1024); + printk(XENLOG_INFO "EFI: BGRT relocated from %p to %p\n", + bgrt_info.old_addr, bgrt_info.new_addr); + } + else if ( bgrt_info.failure_reason[0] ) + printk(XENLOG_WARNING "EFI: BGRT preservation failed: %s\n", + bgrt_info.failure_reason); +} void __init efi_init_memory(void) { diff --git a/xen/include/xen/efi.h b/xen/include/xen/efi.h index XXXXXXX..XXXXXXX 100644 --- a/xen/include/xen/efi.h +++ b/xen/include/xen/efi.h @@ -XXX,XX +XXX,XX @@ static inline bool efi_enabled(unsigned int feature) extern bool efi_secure_boot; void efi_init_memory(void); +void efi_bgrt_status_info(void); bool efi_boot_mem_unused(unsigned long *start, unsigned long *end); bool efi_rs_using_pgtables(void); unsigned long efi_get_time(void); -- 2.53.0
BGRT preservation is now enabled by default to fix ACPI corruption for desktop/workstation systems (similar to ESRT). As described in the task: https://github.com/QubesOS/qubes-issues/issues/10764 Add an opt-out parameter to allow disabling BGRT preservation on systems where the ~1MB memory overhead is not desired. The opt-out is implemented through two boot paths with early parsing during the EFI boot phase before preservation runs: 1. xen.efi direct boot: '-nobgrt' command line option (parsed in efi_start()) 2. Multiboot2 (GRUB): 'efi=no-bgrt' peeked from mb2 cmdline tag using get_option() in efi_multiboot2() The flag is checked at the start of efi_preserve_bgrt_img() to skip preservation entirely when disabled. Status logging indicates whether preservation was disabled, succeeded, or failed. Usage: Default: BGRT preserved automatically xen.efi: Add '-nobgrt' option GRUB/MB2: Add 'efi=no-bgrt' to Xen command line Signed-off-by: Soumyajyotii Ssarkar <soumyajyotisarkar23@gmail.com> --- xen/arch/x86/efi/efi-boot.h | 3 +++ xen/common/efi/boot.c | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index XXXXXXX..XXXXXXX 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -XXX,XX +XXX,XX @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, efi_arch_edid(gop_handle); } + if ( cmdline && get_option(cmdline, "efi=no-bgrt") ) + opt_bgrt_disabled = true; + efi_arch_edd(); efi_arch_cpu(); diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index XXXXXXX..XXXXXXX 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -XXX,XX +XXX,XX @@ static SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdErr; static UINT32 __initdata mdesc_ver; static bool __initdata map_bs; +static bool __initdata opt_bgrt_disabled = false; static struct file __initdata cfg; static struct file __initdata kernel; @@ -XXX,XX +XXX,XX @@ static void __init efi_preserve_bgrt_img(void) bgrt_info.preserved = false; + if ( opt_bgrt_disabled ) + return; + bgrt = efi_get_bgrt(); if ( !bgrt ) { @@ -XXX,XX +XXX,XX @@ void EFIAPI __init noreturn efi_start(EFI_HANDLE ImageHandle, base_video = true; else if ( wstrcmp(ptr + 1, L"mapbs") == 0 ) map_bs = true; + else if ( wstrcmp(ptr + 1, L"nobgrt") == 0 ) + opt_bgrt_disabled = true; else if ( wstrncmp(ptr + 1, L"cfg=", 4) == 0 ) cfg_file_name = ptr + 5; else if ( i + 1 < argc && wstrcmp(ptr + 1, L"cfg") == 0 ) @@ -XXX,XX +XXX,XX @@ void EFIAPI __init noreturn efi_start(EFI_HANDLE ImageHandle, PrintStr(L"Xen EFI Loader options:\r\n"); PrintStr(L"-basevideo retain current video mode\r\n"); PrintStr(L"-mapbs map EfiBootServices{Code,Data}\r\n"); + PrintStr(L"-nobgrt disable BGRT preservation\r\n"); PrintStr(L"-cfg=<file> specify configuration file\r\n"); PrintStr(L"-help, -? display this help\r\n"); blexit(NULL); @@ -XXX,XX +XXX,XX @@ void __init efi_bgrt_status_info(void) if ( !efi_enabled(EFI_BOOT) ) return; - if ( bgrt_info.preserved ) + if ( opt_bgrt_disabled ) + printk(XENLOG_INFO "EFI: BGRT preservation disabled\n"); + else if ( bgrt_info.preserved ) { printk(XENLOG_INFO "EFI: BGRT image preserved: %lu KB\n", bgrt_info.size / 1024); -- 2.53.0