From nobody Sun Apr 5 16:33:03 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1774355621; cv=none; d=zohomail.com; s=zohoarc; b=ZU6+Jp+XvyS3RGNR6pmUodYFgjTpxJLvsMz6WOIun9G3CLIHkHboTsLMp08/aXzPDWZ7TYewCCA01AVqihkFs/A/o/lvsp5x3s4uiQTCaAGafAGoQPbeNw9kJnCs7QeJi/nd8JpvPwDcT8XpdnYPMoxUcfpHh44cMp6HeU7g77Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774355621; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=aApGw00bRTG9YsHWYvBcAcOhWcCCk5rQkMe0Q+McyP8=; b=Sa53Wyci6hwIY6AQcyUsHkWjArpgmro7/cGkW+sbvl2ZBrF3+lhgiv5QF1JCtBdcncDpU4c20kfYYvoreiuLHg4nyvYLU5TGLlUUVrUarVugiOfXtBbr7dQnp6TFzCLoXJwm2fer6H2/7Sim8Ndf1cm3dW9a9UUII6qrPtXbHjU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1774355621154301.7956278693738; Tue, 24 Mar 2026 05:33:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1260633.1553894 (Exim 4.92) (envelope-from ) id 1w50wr-00055k-Ay; Tue, 24 Mar 2026 12:33:29 +0000 Received: by outflank-mailman (output) from mailman id 1260633.1553894; Tue, 24 Mar 2026 12:33:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w50wr-00055d-87; Tue, 24 Mar 2026 12:33:29 +0000 Received: by outflank-mailman (input) for mailman id 1260633; Tue, 24 Mar 2026 12:33:27 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w50wp-00054y-R0 for xen-devel@lists.xenproject.org; Tue, 24 Mar 2026 12:33:27 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1w50wp-008yL3-6w for xen-devel@lists.xenproject.org; Tue, 24 Mar 2026 13:33:27 +0100 Received: from [10.42.69.2] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69c28491-e002-0a2a0a5209dd-0a2a4502c964-30 for ; Tue, 24 Mar 2026 13:33:27 +0100 Received: from [209.85.216.67] (helo=mail-pj1-f67.google.com) by tlsNG-720697.mxtls.expurgate.net with ESMTPS (eXpurgate 4.55.2) (envelope-from ) id 69c28495-63bb-0a2a45020019-d155d843edb7-3 for ; Tue, 24 Mar 2026 13:33:26 +0100 Received: by mail-pj1-f67.google.com with SMTP id 98e67ed59e1d1-35bb7afdc38so650535a91.1 for ; Tue, 24 Mar 2026 05:33:26 -0700 (PDT) Received: from fedora ([103.2.232.250]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35c031ed04esm2215792a91.12.2026.03.24.05.33.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2026 05:33:24 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774355605; x=1774960405; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aApGw00bRTG9YsHWYvBcAcOhWcCCk5rQkMe0Q+McyP8=; b=JtY+fYDFRURyFGgS4bpLD9TptIZjH9FaN0FJsyacnDZABHBR/qxZ6ZJN6uFPTJaF3A /W1GeINxbO7HJifougO1ZJK6fwlEp19I+uYgjL5jcCe2+njDyPOTgnyOaLk5rmP1ZS5F 9GHPkZGJS0ppklThu0IdEFoIwfHkdZs3A5/wO6qwUjO2d5YZWpsgckf4FJ0Xga5YB65m NleYz5DA4nhSt0F0zxwMBTBAwXyc7jf4KybDFgYhCAjXgXOlH8n6/Lo1cCJxNSLAOcLY +817qJwMTvDM/Fj7QgCT5PssJoKibnD+sCFVMk/IBSMtsQ4apnk5KKw95csNMaSOIkdV oXxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774355605; x=1774960405; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=aApGw00bRTG9YsHWYvBcAcOhWcCCk5rQkMe0Q+McyP8=; b=p+RfmXK6eplp2MAfGQfphr3eKV4EQc9T6/dTcAMwIXXwXou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GS5Cv V8jkg+deEp/zqkqhPeGgF8Y1rXa8aI1wBT+oiGqNk/Nhd/WUBl2m2m2jCaKUtL4et1Fz++bMQ== X-Received: by 2002:a17:90b:4fcd:b0:35b:e553:9cc2 with SMTP id 98e67ed59e1d1-35be5539ff7mr7766870a91.26.1774355604739; Tue, 24 Mar 2026 05:33:24 -0700 (PDT) From: Soumyajyotii Ssarkar To: sarkarsoumyajyoti23@gmail.com, xen-devel@lists.xenproject.org Cc: Andrew Cooper , Jan Beulich , "Daniel P . Smith" , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Soumyajyotii Ssarkar Subject: [PATCH v5 1/3] x86/efi: Add BGRT image preservation infrastructure Date: Tue, 24 Mar 2026 18:03:10 +0530 Message-ID: <20260324123312.11076-2-soumyajyotisarkar23@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260324123312.11076-1-soumyajyotisarkar23@gmail.com> References: <20260324123312.11076-1-soumyajyotisarkar23@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-720697/1774355607-42A84DB8-B697ED9A/0/0 X-purgate-type: clean X-purgate-size: 6310 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1774355622733158500 Content-Type: text/plain; charset="utf-8" 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 --- 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(+) diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index 42a2c46b5e..0547d845cd 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -910,6 +910,8 @@ 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 967094994d..47d5b9b2a8 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -1,12 +1,16 @@ #include "efi.h" #include #include +#include +#include +#include #include #include #include #include #include #include +#include #include #include #include @@ -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; + +static __initdata struct { + bool preserved; + const void *old_addr; + const void *new_addr; + UINTN size; + const char *failure_reason; +} bgrt_info =3D { + /* We would prefer the failure_reason to print */ + .failure_reason =3D "", +}; + +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 =3D=3D EFI_INVALID_TABLE_ADDR ) + return NULL; + + rsdp =3D (const void *)(UINTN)efi.acpi20; + if ( !rsdp || !rsdp->xsdt_physical_address ) + return NULL; + + xsdt =3D (const void *)rsdp->xsdt_physical_address; + + if ( memcmp(xsdt->header.signature, ACPI_SIG_XSDT, 4) !=3D 0 ) + return NULL; + + if ( xsdt->header.length < sizeof(xsdt->header) ) + return NULL; + entry_count =3D (xsdt->header.length - sizeof(xsdt->header)) / + sizeof(xsdt->table_offset_entry[0]); + + for ( i =3D 0; i < entry_count; i++ ) + { + const struct acpi_table_header *hdr; + + hdr =3D (const void *)xsdt->table_offset_entry[i]; + if ( !hdr ) + continue; + + if ( memcmp(hdr->signature, ACPI_SIG_BGRT, 4) =3D=3D 0 && + hdr->length >=3D sizeof(struct acpi_table_bgrt) ) + return (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) +{ + 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 =3D false; + + bgrt =3D efi_get_bgrt(); + if ( !bgrt ) + { + bgrt_info.failure_reason =3D "BGRT table not found"; + return; + } + + if ( !bgrt->image_address ) + return; + + old_image =3D (const void *)bgrt->image_address; + bmp =3D old_image; + + if ( bmp->signature !=3D BMP_SIGNATURE ) + { + bgrt_info.failure_reason =3D "Invalid BMP signature"; + return; + } + + image_size =3D bmp->file_size; + if ( !image_size || image_size > MAX_BGRT_IMAGE_SIZE ) + { + bgrt_info.failure_reason =3D "Image size exceeds limit"; + return; + } + + /* + * Allocate memory of type EfiACPIReclaimMemory so that the image + * will remain available for the OS after ExitBootServices(). + */ + status =3D efi_bs->AllocatePool(EfiACPIReclaimMemory, image_size, &new= _image); + if ( EFI_ERROR(status) ) + { + bgrt_info.failure_reason =3D "Memory allocation failed"; + return; + } + memcpy(new_image, old_image, image_size); + bgrt->image_address =3D (UINTN)new_image; + bgrt->header.checksum =3D 0; + checksum =3D 0; + + for ( i =3D 0; i < bgrt->header.length; i++ ) + checksum +=3D ((const UINT8 *)bgrt)[i]; + + bgrt->header.checksum =3D -checksum; + + /* Filling the debug struct for printing later */ + bgrt_info.preserved =3D true; + bgrt_info.old_addr =3D old_image; + bgrt_info.new_addr =3D new_image; + bgrt_info.size =3D image_size; +} + /* * Include architecture specific implementation here, which references the * static globals defined above. @@ -1671,6 +1802,8 @@ void EFIAPI __init noreturn efi_start(EFI_HANDLE Imag= eHandle, efi_relocate_esrt(SystemTable); + efi_preserve_bgrt_img(); + efi_exit_boot(ImageHandle, SystemTable); efi_arch_post_exit_boot(); /* Doesn't return. */ diff --git a/xen/common/efi/common-stub.c b/xen/common/efi/common-stub.c index 9dc8aa538c..155a973f21 100644 --- a/xen/common/efi/common-stub.c +++ b/xen/common/efi/common-stub.c @@ -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