From nobody Sun Apr 5 16:16:12 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=1774346968; cv=none; d=zohomail.com; s=zohoarc; b=mRWHZKLYW8ByqB+OOpYpCyNnJznqv0TPiTP/C2Vp14cTQrOUb3XsvMYbBSma7/0icOzoc1l1dLLV0rH3P1iL3/9jaN5j086Z9H9zHqZN2HOZJhgaK0N16ytsLAIdRYlng0C5ngPx4Uehnw5YOixOUcrUd8IdNATNf9MApuXcagE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774346968; 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=LIXS1eG90Y2BxFL9pSpTatOIYRi0/NeL/1/dn5db+dbPOxr7r5AT8IyffAkzQAafbCCXMBzpOC1N0ZYac7niC7+rqkCfjWY2uqFTqWyaDsIZhETf/jBszH+WFBFGH9IxhXAcbsnwIlqqizMXEL1I0BbYOh1nct1oEWnvlAA9Y7k= 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 1774346968214377.8807431799146; Tue, 24 Mar 2026 03:09:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1260230.1553594 (Exim 4.92) (envelope-from ) id 1w4yhG-0001bC-EY; Tue, 24 Mar 2026 10:09:14 +0000 Received: by outflank-mailman (output) from mailman id 1260230.1553594; Tue, 24 Mar 2026 10:09:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w4yhG-0001b5-AU; Tue, 24 Mar 2026 10:09:14 +0000 Received: by outflank-mailman (input) for mailman id 1260230; Tue, 24 Mar 2026 10:09:13 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w4yhF-0001aD-DP for xen-devel@lists.xenproject.org; Tue, 24 Mar 2026 10:09:13 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1w4yhE-008S3o-MA for xen-devel@lists.xenproject.org; Tue, 24 Mar 2026 11:09:12 +0100 Received: from [10.42.69.3] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69c262c6-e002-0a2a0a5209dd-0a2a4503e28c-20 for ; Tue, 24 Mar 2026 11:09:12 +0100 Received: from [209.85.215.195] (helo=mail-pg1-f195.google.com) by tlsNG-33051d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.55.2) (envelope-from ) id 69c262c7-1947-0a2a45030019-d155d7c3dc1a-3 for ; Tue, 24 Mar 2026 11:09:12 +0100 Received: by mail-pg1-f195.google.com with SMTP id 41be03b00d2f7-c70f91776fcso503565a12.0 for ; Tue, 24 Mar 2026 03:09:12 -0700 (PDT) Received: from fedora ([103.2.232.250]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c74665ca206sm11377434a12.18.2026.03.24.03.09.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2026 03:09:09 -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=1774346950; x=1774951750; 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=AKZWX3ZWK3oLzSbH+SIp9CXq3QzB2TmHr4Tl9jvw1zmJBFvlNuBsX4mROuHdxYJPXq HmisRTXYaeOh3ARMYoqOXdeib82KmG1DH8Vr9+piomd0/qkP8yrNkFUHxjSnza7/aHTI VoaW+9v0G8u13nSsr7KMgorERYlTG1Ow0xnB1rfZMWwyOrbE39DEEF42IQ/EQnjOKGqq BnUuwJErvTC8wZw/hakKFMJF4Lja6BrLPjeMAmeT32U/UOr3yT+Ix62rU01QuHQF5KdU fmkEIgZX1qepWjxWGuFsr9G+Ro4iE9HASduWUZTcLXfhRIPSPKf4egVbJ96H0HSZ2T+S TVLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774346950; x=1774951750; 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=h/888kkzI+S5yXpCEJ4GM8lPrZc0KFnT/+Grrew8dy+M4iM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6d9e:b0:39b:e84a:962a with SMTP id adf61e73a8af0-39be84ab96bmr10990598637.13.1774346950025; Tue, 24 Mar 2026 03:09:10 -0700 (PDT) From: Soumyajyotii Ssarkar To: xen-devel@lists.xenproject.org, sarkarsoumyajyoti23@gmail.com Cc: "Daniel P . Smith" , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Andrew Cooper , Jan Beulich , =?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:38:54 +0530 Message-ID: <20260324100856.6691-2-soumyajyotisarkar23@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260324100856.6691-1-soumyajyotisarkar23@gmail.com> References: <20260324100856.6691-1-soumyajyotisarkar23@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-33051d/1774346952-EAA8372C-29AC70D4/0/0 X-purgate-type: clean X-purgate-size: 6339 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1774346970326158500 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