From nobody Sun Apr 5 16:32:50 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=1774347488; cv=none; d=zohomail.com; s=zohoarc; b=QdoLWyYNAvPFeAzQRMYTyXMohrsnOW+ASUuWK/qfIClR0BKLF9uKvkVLUVg/FYzCS67LwxGv3wQsZcYy9KrPRgvNnHD4KAF+tCFbXm2ZEQBLCponQWWWP1BemvFEJVp7Qg+V1aDfH/lytMbaaDBimkFXpDkYPeGGGf4nFmDFZ4Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774347488; 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=vMyU7Zt+Npx8war2PFOLJHgfUteMUgErNfOEenK+5EA=; b=hoqSkledWCpUlcdayobFf7ybQnAw2K3MYiWzJMuMq8qcxoTX+tig1aJ5NX69e/E0Z67cKhsUhNc2985XNSmdihUeJ1Mh/sFaOfCdElEfT6L63HpYJjMHXqueQmJOvq+bq0Q/PfGY2Mx6VBkrct6NIIkBWuPnHSsgGLHqRMbRTPc= 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 1774347488225365.36436229452806; Tue, 24 Mar 2026 03:18:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1260275.1553638 (Exim 4.92) (envelope-from ) id 1w4ypS-0005Le-6Y; Tue, 24 Mar 2026 10:17:42 +0000 Received: by outflank-mailman (output) from mailman id 1260275.1553638; Tue, 24 Mar 2026 10:17:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w4ypS-0005LX-3i; Tue, 24 Mar 2026 10:17:42 +0000 Received: by outflank-mailman (input) for mailman id 1260275; Tue, 24 Mar 2026 10:17:41 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w4ypR-0005L7-5g for xen-devel@lists.xenproject.org; Tue, 24 Mar 2026 10:17:41 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1w4ypQ-0063h1-I8 for xen-devel@lists.xenproject.org; Tue, 24 Mar 2026 11:17:40 +0100 Received: from [10.42.69.7] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69c264c4-2eae-0a2a0a5409dd-0a2a4507e97c-0 for ; Tue, 24 Mar 2026 11:17:40 +0100 Received: from [209.85.216.66] (helo=mail-pj1-f66.google.com) by tlsNG-ef75cf.mxtls.expurgate.net with ESMTPS (eXpurgate 4.55.2) (envelope-from ) id 69c264c2-fd74-0a2a45070019-d155d842cce5-3 for ; Tue, 24 Mar 2026 11:17:40 +0100 Received: by mail-pj1-f66.google.com with SMTP id 98e67ed59e1d1-35a1f549e7eso2174018a91.0 for ; Tue, 24 Mar 2026 03:17:39 -0700 (PDT) Received: from fedora ([103.2.232.250]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35c031412f2sm1939382a91.7.2026.03.24.03.17.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2026 03:17:37 -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=1774347458; x=1774952258; 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=vMyU7Zt+Npx8war2PFOLJHgfUteMUgErNfOEenK+5EA=; b=hFgvvYm7JK4qpzrHClfHA2EgU2oGJeIj8TNTsQHRr549XY6B6NzyBCd3I8gCW3apB7 Fn4+mrbaIyPwBH5yqbrFtwDwRmLkc8fnJL+BXJaCTsSz0vOIxYOogO2TT7z6hjdQHKWf KUdv70bfh2dMdPM3DxnY8VISbAjnTZRdnDFjEZbtIjk3HknC29svknlJojRYIfZnwveo yUEICIhTD/ngKYNI5+XbUp3Q9lxXmwZOREdv+23N/tHWcN63uDaUeqh95/eG0vItx8fn Wh51ggrWy2oyu7tAcZbmnE+oKOnUuhjPiSxDPcdy8S6VSnMThgBHfgLuJykDFgEWwLSi t+fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774347458; x=1774952258; 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=vMyU7Zt+Npx8war2PFOLJHgfUteMUgErNfOEenK+5EA=; b=dHWnV5+HBASObTZhrfGkUuvpVO2GMvAiCaKNo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0:35b:9682:51dd with SMTP id 98e67ed59e1d1-35bd2cde5a4mr12713503a91.24.1774347457887; Tue, 24 Mar 2026 03:17:37 -0700 (PDT) From: Soumyajyotii Ssarkar To: xen-devel@lists.xenproject.org, sarkarsoumyajyoti23@gmail.com Cc: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Andrew Cooper , Jan Beulich , "Daniel P . Smith" , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Soumyajyotii Ssarkar Subject: [PATCH v4 1/3] x86/efi: Add BGRT image preservation infrastructure Date: Tue, 24 Mar 2026 15:47:24 +0530 Message-ID: <20260324101726.6929-2-soumyajyotisarkar23@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260324101726.6929-1-soumyajyotisarkar23@gmail.com> References: <20260324101726.6929-1-soumyajyotisarkar23@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-ef75cf/1774347460-576A7303-9BBDAAFE/0/0 X-purgate-type: clean X-purgate-size: 6339 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1774347490596154100 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 77f138a6c5..9e595600d7 100644 --- a/xen/common/efi/common-stub.c +++ b/xen/common/efi/common-stub.c @@ -20,6 +20,7 @@ unsigned long efi_get_time(void) void efi_halt_system(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