Fixing ACPI BGRT (Boot Graphics Resource Table) corruption
v5 cover Fixing ACPI BGRT (Boot Graphics Resource Table) corruption
This patch series plans to address 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.
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.
Changes since v3:
- Fix casting away const issue.
- Add Stub function
Changes since v4:
Fixed the merge conflicts raised due to removal of efi_halt_system()
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)
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/common/efi/common-stub.c | 1 + xen/include/xen/efi.h | 1 + 5 files changed, 173 insertions(+)
--
2.53.0
PATCH v5 1/3 x86/efi: Add BGRT image preservation infrastructure
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.
--- xen/arch/x86/efi/efi-boot.h | 2 + xen/common/efi/boot.c | 133 +++++++++++++++++++++++++++++++++++ xen/common/efi/common-stub.c | 1 + 3 files changed, 136 insertions(+)
xen/arch/x86/efi/efi-boot.h +2 -0
@@ -910,6 +910,8 @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle,efi_relocate_esrt (SystemTable); +efi_preserve_bgrt_img (); +efi_exit_boot (ImageHandle, SystemTable); }
xen/common/efi/boot.c +133 -0
157 lines not on this page · raw message
xen/common/efi/common-stub.c +1 -0
@@ -19,6 +19,7 @@ unsigned long efi_get_time(void) }void efi_reset_system (bool warm) { } +void __init efi_bgrt_status_info (void ) { }int efi_get_info (uint32_t idx,union xenpf_efi_info *info) {
--
2.53.0
Re: [PATCH v5 1/3] x86/efi: Add BGRT image preservation infrastructure
xen/common/efi/boot.c line 6
Quoted 9 lines · Soumyajyotii Ssarkar
xen/common/efi/boot.c +3
-0@@ -1,12 +1,16 @@#include "efi.h" #include <efi/efiprot.h> #include <efi/efipciio.h> +#include <acpi/acconfig.h> +#include <acpi/actbl.h> +#include <acpi/actbl3.h>
I fear this is pretty fragile. acpi/acpi.h is what is supposed to be included from outside of (the little bit of) ACPICA code that we have got. Which in turn may conflict with efi/*.h, which is why previously I had suggested to put the ACPI parsing code elsewhere (if indeed nothing we already have can be reused).
xen/common/efi/boot.c line 13
Quoted 7 lines
xen/common/efi/boot.c +1
-0#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>
Is this really needed? Afaict it's included implicitly already.
xen/common/efi/boot.c static void __init efi_relocate_esrt(EFI_SYSTEM_TABLE *SystemTable) · line 759
Quoted 10 lines
xen/common/efi/boot.c +6
-0@@ -747,6 +751,133 @@ 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 ;
All capitals identifiers are by convention #define-s. bmp_header_t perhaps?
xen/common/efi/boot.c static void __init efi_relocate_esrt(EFI_SYSTEM_TABLE *SystemTable) · line 770
Quoted 10 lines
xen/common/efi/boot.c +10
-0+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 ="" , +};
I don't understand what the comment is supposed to be telling the reader. Clearly it's not about the relocation subtlety which (imo) absolutely needs commenting on.
xen/common/efi/boot.c static void __init efi_relocate_esrt(EFI_SYSTEM_TABLE *SystemTable) · line 782
Quoted 11 lines
xen/common/efi/boot.c +11
-0+static 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;
Why the intermediate cast to UINTN?
xen/common/efi/boot.c static void __init efi_relocate_esrt(EFI_SYSTEM_TABLE *SystemTable) · line 786
Quoted 4 lines
xen/common/efi/boot.c +4
-0+if ( !rsdp || !rsdp->xsdt_physical_address ) +return NULL ; + + xsdt = (const void *)rsdp->xsdt_physical_address;
What if only an RSDT is supplied?
xen/common/efi/boot.c static void __init efi_relocate_esrt(EFI_SYSTEM_TABLE *SystemTable) · line 796
Quoted 9 lines
xen/common/efi/boot.c +9
-0+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++ )
This calls for i and entry_count to have the same type.
xen/common/efi/boot.c static void __init efi_relocate_esrt(EFI_SYSTEM_TABLE *SystemTable) · line 806
Quoted 10 lines
xen/common/efi/boot.c +10
-0+ { +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 (struct acpi_table_bgrt *)hdr;
Please use container_of() in favor of casts.
xen/common/efi/boot.c static void __init efi_relocate_esrt(EFI_SYSTEM_TABLE *SystemTable) · line 813
Quoted 7 lines
xen/common/efi/boot.c +7
-0+ } + +return NULL ; +} + +#define BMP_SIGNATURE 0x4D42 +#define MAX_BGRT_IMAGE_SIZE (16 * 1024 * 1024)
Still an uncommented arbitrary constant.
Quoted 26 lines
xen/common/efi/boot.c +26
-0+static void __init efi_preserve_bgrt_img (void ) +{ +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; +
xen/common/efi/boot.c static void __init efi_relocate_esrt(EFI_SYSTEM_TABLE *SystemTable) · line 850
Quoted 10 lines
xen/common/efi/boot.c +10
-0+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" ;
Does it, when it's zero?
Quoted 5 lines
xen/common/efi/boot.c +5
-0+return ; + } + +/* +* Allocate memory of type EfiACPIReclaimMemory so that the image
xen/common/efi/boot.c static void __init efi_relocate_esrt(EFI_SYSTEM_TABLE *SystemTable) · line 865
Quoted 10 lines
xen/common/efi/boot.c +10
-0+* 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); + bgrt->image_address = (UINTN )new_image;
This looks like the wrong cast to me, even if in practice this likely is going to be fine even on 32-bit EFI.
xen/common/efi/boot.c static void __init efi_relocate_esrt(EFI_SYSTEM_TABLE *SystemTable) · line 878
Quoted 13 lines
xen/common/efi/boot.c +13
-0+ bgrt->header.checksum =0 ; + checksum =0 ; + +for ( i =0 ; i < bgrt->header.length; i++ ) + checksum += ((const UINT8 *)bgrt)[i]; + + 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;
I'd suggest to drop "debug" from the comment.
xen/common/efi/common-stub.c unsigned long efi_get_time(void) · line 22
Quoted 7 lines
xen/common/efi/common-stub.c +1
-0@@ -19,6 +19,7 @@ unsigned long efi_get_time(void) }void efi_reset_system (bool warm) { } +void __init efi_bgrt_status_info (void ) { }
What is this? Does this belong into a later patch? And did you pay attention to Marek's earlier comment (as to the use of __init)?
Jan
Re: [PATCH v5 1/3] x86/efi: Add BGRT image preservation infrastructure
In reply to Soumyajyotii SsarkarQuoted 11 lines · Soumyajyotii Ssarkar
xen/common/efi/boot.c +7
-0@@ -747,6 +751,133 @@ 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 ; +
xen/common/efi/boot.c static void __init efi_relocate_esrt(EFI_SYSTEM_TABLE *SystemTable) · line 770
Quoted 10 lines
xen/common/efi/boot.c +10
-0+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 ="" , +};
Noticed only while looking at patch 3: With this initializer, ...
xen/common/efi/boot.c static void __init efi_relocate_esrt(EFI_SYSTEM_TABLE *SystemTable) · line 826
Quoted 12 lines
xen/common/efi/boot.c +12
-0+static void __init efi_preserve_bgrt_img (void ) +{ +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;
... why would this be needed?
Jan
PATCH v5 2/3 x86/acpi: Integrate BGRT preservation with status reporting
In reply to Soumyajyotii SsarkarAdd 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.
--- xen/arch/x86/acpi/boot.c | 8 ++++++++ xen/common/efi/boot.c | 16 ++++++++++++++++ xen/include/xen/efi.h | 1 + 3 files changed, 25 insertions(+)
xen/arch/x86/acpi/boot.c +8 -0
@@ -29,6 +29,7 @@#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>
@@ -327,6 +328,11 @@ 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 =
@@ -754,5 +760,7 @@ int __init acpi_boot_init(void)acpi_table_parse (ACPI_SIG_BGRT , acpi_invalidate_bgrt); +efi_bgrt_status_info (); +return 0 ; }
xen/common/efi/boot.c +16 -0
@@ -1911,6 +1911,22 @@ static bool __init cf_check rt_range_valid(unsigned long smfn, unsigned long emfreturn 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 ) {
xen/include/xen/efi.h +1 -0
@@ -39,6 +39,7 @@ 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
Re: [PATCH v5 2/3] x86/acpi: Integrate BGRT preservation with status reporting
Quoted 13 lines · Soumyajyotii Ssarkar
xen/arch/x86/acpi/boot.c +5
-0@@ -327,6 +328,11 @@ 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 =
xen/arch/x86/acpi/boot.c int __init acpi_boot_init(void) · line 766
Quoted 7 lines
xen/arch/x86/acpi/boot.c +2
-0@@ -754,5 +760,7 @@ int __init acpi_boot_init(void)acpi_table_parse (ACPI_SIG_BGRT , acpi_invalidate_bgrt); +efi_bgrt_status_info (); +return 0 ; }
Does this really need doing from here? If you called it ...
Quoted 15 lines
xen/common/efi/boot.c +9
-0@@ -1911,6 +1911,22 @@ static bool __init cf_check rt_range_valid(unsigned long smfn, unsigned long emfreturn 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 );
xen/common/efi/boot.c static bool __init cf_check rt_range_valid(unsigned long smfn, unsigned long emf · line 1932
Quoted 10 lines
xen/common/efi/boot.c +7
-0+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 ) {
... out of this function, it could be static and no stub (misplaced in the earlier patch) would be needed either.
Furthermore, is the EFI_BOOT check really needed? Without taking either of the EFI boot paths, neither bgrt_info.preserved nor bgrt_info.failure_reason[0] would have been altered from their initial values.
Jan
Re: [PATCH v5 2/3] x86/acpi: Integrate BGRT preservation with status reporting
Quoted 47 lines · Jan Beulich
Quoted 13 lines · Soumyajyotii Ssarkar
xen/arch/x86/acpi/boot.c +5
-0@@ -327,6 +328,11 @@ 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 =xen/arch/x86/acpi/boot.c int __init acpi_boot_init(void) · line 766
Quoted 7 lines
xen/arch/x86/acpi/boot.c +2
-0@@ -754,5 +760,7 @@ int __init acpi_boot_init(void)acpi_table_parse (ACPI_SIG_BGRT , acpi_invalidate_bgrt); +efi_bgrt_status_info (); +return 0 ; }Does this really need doing from here? If you called it ...
Quoted 23 lines
xen/common/efi/boot.c +16
-0@@ -1911,6 +1911,22 @@ static bool __init cf_check rt_range_valid(unsigned long smfn, unsigned long emfreturn 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); +}
Quoted 5 lines
xen/common/efi/boot.c static bool __init cf_check rt_range_valid(unsigned long smfn, unsigned long emf · line 1932
Quoted 2 lines
xen/common/efi/boot.c +0
-0void __init efi_init_memory (void ) {... out of this function, it could be static and no stub (misplaced in the earlier patch) would be needed either.
It was here before, and I complained about it, because it printed the invalidation reason way later than the actual invalidation.
Quoted 6 lines
Furthermore, is the
EFI_BOOTcheck really needed? Without taking either of the EFI boot paths, neither bgrt_info.preserved nor bgrt_info.failure_reason[0] would have been altered from their initial values.Jan
Signature · 3 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab
Re: [PATCH v5 2/3] x86/acpi: Integrate BGRT preservation with status reporting
Quoted 48 lines · Marek Marczykowski-Górecki
Quoted 47 lines · Jan Beulich
Quoted 13 lines · Soumyajyotii Ssarkar
xen/arch/x86/acpi/boot.c +5
-0@@ -327,6 +328,11 @@ 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 =xen/arch/x86/acpi/boot.c int __init acpi_boot_init(void) · line 766
Quoted 7 lines
xen/arch/x86/acpi/boot.c +2
-0@@ -754,5 +760,7 @@ int __init acpi_boot_init(void)acpi_table_parse (ACPI_SIG_BGRT , acpi_invalidate_bgrt); +efi_bgrt_status_info (); +return 0 ; }Does this really need doing from here? If you called it ...
Quoted 23 lines
xen/common/efi/boot.c +16
-0@@ -1911,6 +1911,22 @@ static bool __init cf_check rt_range_valid(unsigned long smfn, unsigned long emfreturn 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); +}
Quoted 8 lines
Quoted 5 lines
xen/common/efi/boot.c static bool __init cf_check rt_range_valid(unsigned long smfn, unsigned long emf · line 1932
Quoted 2 lines
xen/common/efi/boot.c +0
-0void __init efi_init_memory (void ) {... out of this function, it could be static and no stub (misplaced in the earlier patch) would be needed either.
It was here before, and I complained about it, because it printed the invalidation reason way later than the actual invalidation.
Sadly now I complain about this call out of acpi_boot_init(). What's wrong with logging the BGRT stuff together with the memory map?
Jan
Re: [PATCH v5 2/3] x86/acpi: Integrate BGRT preservation with status reporting
Quoted 55 lines · Jan Beulich
Quoted 54 lines · Marek Marczykowski-Górecki
Quoted 52 lines · Jan Beulich
Quoted 13 lines · Soumyajyotii Ssarkar
xen/arch/x86/acpi/boot.c +5
-0@@ -327,6 +328,11 @@ 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 =xen/arch/x86/acpi/boot.c int __init acpi_boot_init(void) · line 766
Quoted 7 lines
xen/arch/x86/acpi/boot.c +2
-0@@ -754,5 +760,7 @@ int __init acpi_boot_init(void)acpi_table_parse (ACPI_SIG_BGRT , acpi_invalidate_bgrt); +efi_bgrt_status_info (); +return 0 ; }Does this really need doing from here? If you called it ...
Quoted 15 lines
xen/common/efi/boot.c +9
-0@@ -1911,6 +1911,22 @@ static bool __init cf_check rt_range_valid(unsigned long smfn, unsigned long emfreturn 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 );xen/common/efi/boot.c static bool __init cf_check rt_range_valid(unsigned long smfn, unsigned long emf · line 1932
Quoted 10 lines
xen/common/efi/boot.c +7
-0+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 ) {... out of this function, it could be static and no stub (misplaced in the earlier patch) would be needed either.
Quoted 5 lines
Quoted 2 lines
It was here before, and I complained about it, because it printed the invalidation reason way later than the actual invalidation.
Sadly now I complain about this call out of
acpi_boot_init(). What's wrong with logging the BGRT stuff together with the memory map?
If you try to diagnose what went wrong with BGRT, that's not very intuitive to find - for example on my system it's 32 messages later. It's even worse if system happens to crash between those two points. IMO it makes sense to log reason for BGRT invalidation together with the actual invalidation (message). I would be okay with moving it before the actual invalidation, but I don't think there is a place like this in xen/common/efi/boot.c (at a point where normal printk can be used already).
Signature · 3 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab
Re: [PATCH v5 2/3] x86/acpi: Integrate BGRT preservation with status reporting
Quoted 56 lines · Marek Marczykowski-Górecki
Quoted 55 lines · Jan Beulich
Quoted 54 lines · Marek Marczykowski-Górecki
Quoted 52 lines · Jan Beulich
Quoted 13 lines · Soumyajyotii Ssarkar
xen/arch/x86/acpi/boot.c +5
-0@@ -327,6 +328,11 @@ 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 =xen/arch/x86/acpi/boot.c int __init acpi_boot_init(void) · line 766
Quoted 7 lines
xen/arch/x86/acpi/boot.c +2
-0@@ -754,5 +760,7 @@ int __init acpi_boot_init(void)acpi_table_parse (ACPI_SIG_BGRT , acpi_invalidate_bgrt); +efi_bgrt_status_info (); +return 0 ; }Does this really need doing from here? If you called it ...
Quoted 15 lines
xen/common/efi/boot.c +9
-0@@ -1911,6 +1911,22 @@ static bool __init cf_check rt_range_valid(unsigned long smfn, unsigned long emfreturn 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 );xen/common/efi/boot.c static bool __init cf_check rt_range_valid(unsigned long smfn, unsigned long emf · line 1932
Quoted 10 lines
xen/common/efi/boot.c +7
-0+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 ) {... out of this function, it could be static and no stub (misplaced in the earlier patch) would be needed either.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
It was here before, and I complained about it, because it printed the invalidation reason way later than the actual invalidation.
Sadly now I complain about this call out of
acpi_boot_init(). What's wrong with logging the BGRT stuff together with the memory map?If you try to diagnose what went wrong with BGRT, that's not very intuitive to find - for example on my system it's 32 messages later.
Simply grep the log for BGRT?
Quoted 1 line
It's even worse if system happens to crash between those two points.
Hmm, perhaps.
Quoted 4 lines
IMO it makes sense to log reason for BGRT invalidation together with the actual invalidation (message). I would be okay with moving it before the actual invalidation, but I don't think there is a place like this in
xen/common/efi/boot.c(at a point where normal printk can be used already).
I guess what you really mean is printk() output actually going out (i.e. not just to the ring buffer).
While still requiring the function to be extern (and there to be a stub), how about adding the call much earlier in __start_xen, in here:
else if ( efi_enabled(EFI_BOOT) )
memmap_type = "EFI";
? Or alternatively anywhere between setting system_state to SYS_STATE_boot and the call to acpi_boot_init()? Or re-using the other EFI_BOOT check that we have in __start_xen()?
Jan
Re: [PATCH v5 2/3] x86/acpi: Integrate BGRT preservation with status reporting
Quoted 83 lines · Jan Beulich
Quoted 56 lines · Marek Marczykowski-Górecki
Quoted 55 lines · Jan Beulich
Quoted 54 lines · Marek Marczykowski-Górecki
Quoted 52 lines · Jan Beulich
Quoted 13 lines · Soumyajyotii Ssarkar
xen/arch/x86/acpi/boot.c +5
-0@@ -327,6 +328,11 @@ 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 =xen/arch/x86/acpi/boot.c int __init acpi_boot_init(void) · line 766
Quoted 7 lines
xen/arch/x86/acpi/boot.c +2
-0@@ -754,5 +760,7 @@ int __init acpi_boot_init(void)acpi_table_parse (ACPI_SIG_BGRT , acpi_invalidate_bgrt); +efi_bgrt_status_info (); +return 0 ; }Does this really need doing from here? If you called it ...
Quoted 15 lines
xen/common/efi/boot.c +9
-0@@ -1911,6 +1911,22 @@ static bool __init cf_check rt_range_valid(unsigned long smfn, unsigned long emfreturn 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 );xen/common/efi/boot.c static bool __init cf_check rt_range_valid(unsigned long smfn, unsigned long emf · line 1932
Quoted 10 lines
xen/common/efi/boot.c +7
-0+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 ) {... out of this function, it could be static and no stub (misplaced in the earlier patch) would be needed either.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
It was here before, and I complained about it, because it printed the invalidation reason way later than the actual invalidation.
Sadly now I complain about this call out of
acpi_boot_init(). What's wrong with logging the BGRT stuff together with the memory map?If you try to diagnose what went wrong with BGRT, that's not very intuitive to find - for example on my system it's 32 messages later.
Simply grep the log for BGRT?
Quoted 1 line
It's even worse if system happens to crash between those two points.
Hmm, perhaps.
Quoted 4 lines
IMO it makes sense to log reason for BGRT invalidation together with the actual invalidation (message). I would be okay with moving it before the actual invalidation, but I don't think there is a place like this in
xen/common/efi/boot.c(at a point where normal printk can be used already).I guess what you really mean is
printk()output actually going out (i.e. not just to the ring buffer).While still requiring the function to be extern (and there to be a stub), how about adding the call much earlier in
__start_xen, in here:
Quoted 6 lines
else if (
efi_enabled(EFI_BOOT))
memmap_type= "EFI";? Or alternatively anywhere between setting
system_statetoSYS_STATE_bootand the call toacpi_boot_init()? Or re-using the otherEFI_BOOTcheck that we have in__start_xen()?
Yes, either of those would be okay for me. I just want to avoid potentially loosing important piece of information that Xen already has at the point of invalidating BGRT.
Signature · 3 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab
PATCH v5 3/3 x86/efi: Add opt-out mechanism for BGRT preservation
In reply to Soumyajyotii SsarkarBGRT 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
--- xen/arch/x86/efi/efi-boot.h | 3 +++ xen/common/efi/boot.c | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-)
xen/arch/x86/efi/efi-boot.h +3 -0
@@ -897,6 +897,9 @@ 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 ();
xen/common/efi/boot.c +10 -1
@@ -170,6 +170,7 @@ 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;
@@ -825,6 +826,9 @@ static void __init efi_preserve_bgrt_img(void) bgrt_info.preserved = false; +if ( opt_bgrt_disabled ) +return ; + bgrt =efi_get_bgrt ();if ( !bgrt ) {
@@ -1582,6 +1586,8 @@ 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 )
@@ -1592,6 +1598,7 @@ 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 );
@@ -1916,7 +1923,9 @@ 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
Re: [PATCH v5 3/3] x86/efi: Add opt-out mechanism for BGRT preservation
xen/arch/x86/efi/efi-boot.h void __init efi_multiboot2(EFI_HANDLE ImageHandle, · line 901
Quoted 8 lines · Soumyajyotii Ssarkar
xen/arch/x86/efi/efi-boot.h +2
-0@@ -897,6 +897,9 @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle,efi_arch_edid (gop_handle); } +if ( cmdline &&get_option (cmdline,"efi=no-bgrt" ) ) + opt_bgrt_disabled = true;
Had you updated docs/misc/xen-command-line.pandoc as necessary, it likely would have occurred to you that it's not this simple.
"efi=" already is a known top-level option. Hence for one, its parsing function (parse_efi_param()) needs updating to not choke on finding a "no-bgrt" sub-option. And then combinations with other sub-options will want to be permitted, e.g. "efi=no-rs,no-bgrt".
xen/common/efi/boot.c static SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdErr; · line 173
Quoted 7 lines
xen/common/efi/boot.c +1
-0@@ -170,6 +170,7 @@ static SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdErr;static UINT32 __initdata mdesc_ver;static bool __initdata map_bs; +static bool __initdata opt_bgrt_disabled = false;
Nit: No need for the initializer (as can be seen from the other two variables in context).
I also consider the variable name problematic. The (sub-)option is "bgrt" with its negative form "no-bgrt". We generally aim at having opt_<name> match (in <name>) with the corresponding command line (sub)option. IOW I think this wants to be opt_bgrt, initialized to true.
Jan