From: "Marek Marczykowski-Górecki" <marmarek@invisiblethingslab.com>
To: Soumyajyotii Ssarkar <soumyajyotisarkar23@gmail.com>
Cc: xen-devel@lists.xenproject.org, sarkarsoumyajyoti23@gmail.com,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Daniel P . Smith" <dpsmith@apertussolutions.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Roger Pau Monné" <roger.pau@citrix.com>
Subject: Re: [RFC PATCH v3 1/3] x86/efi: Add BGRT image preservation infrastructure
Date: Tue, 17 Mar 2026 15:18:28 +0100 [thread overview]
Message-ID: <ablitN6qZAOOG2ZZ@mail-itl> (raw)
In-Reply-To: <20260312111414.17808-2-soumyajyotisarkar23@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3379 bytes --]
On Thu, Mar 12, 2026 at 04:44:12PM +0530, Soumyajyotii Ssarkar wrote:
> 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(+)
>
...
> +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;
Question to MISRA experts here - is this casting away of const okay
here? Or maybe better be done on the `bgrt` local variable? Or some
other way?
> + 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.
--
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2026-03-17 14:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-12 11:14 [RFC PATCH v3 0/3] Fixing ACPI BGRT (Boot Graphics Resource Table) corruption Soumyajyotii Ssarkar
2026-03-12 11:14 ` [RFC PATCH v3 1/3] x86/efi: Add BGRT image preservation infrastructure Soumyajyotii Ssarkar
2026-03-17 14:18 ` Marek Marczykowski-Górecki [this message]
2026-03-17 15:41 ` Andrew Cooper
2026-03-12 11:14 ` [RFC PATCH v3 2/3] x86/acpi: Integrate BGRT preservation with status reporting Soumyajyotii Ssarkar
2026-03-17 13:46 ` Andrew Cooper
2026-03-12 11:14 ` [RFC PATCH v3 3/3] x86/efi: Add opt-out mechanism for BGRT preservation Soumyajyotii Ssarkar
2026-03-17 13:26 ` [RFC PATCH v3 0/3] Fixing ACPI BGRT (Boot Graphics Resource Table) corruption Marek Marczykowski-Górecki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ablitN6qZAOOG2ZZ@mail-itl \
--to=marmarek@invisiblethingslab.com \
--cc=andrew.cooper3@citrix.com \
--cc=dpsmith@apertussolutions.com \
--cc=jbeulich@suse.com \
--cc=roger.pau@citrix.com \
--cc=sarkarsoumyajyoti23@gmail.com \
--cc=soumyajyotisarkar23@gmail.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.