From nobody Mon Mar 23 21:25:17 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=1773314089; cv=none; d=zohomail.com; s=zohoarc; b=f8q36TMMTt1QOaErkX7hZrP/Uf7XEoRIU8DRldq4DmdP6GNT9c1Ok2CVAorLh6TPjziHlshfPpZoc+5nFJw2MlWXd+P1e9P8mfKCVIcF7JIr/kDKnm/8F5ywCL85UK58aYYnTVtO+D7kYRHyoflDszwx8lIslNL8PQah6IFuFFg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773314089; 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=RPerCwQjjELYfGowH6evflvClMRzfpgAd8/IYGd3nUo=; b=a33YMrbnEzWRrOsbrKjFD0qg/+92Trcq+qleEOZ8DEftPLTGBOeemCbAxjUoJ4Te1DOqVJIH9RCsF3Iug+wNWH1ehAfKmBeszkutgBjRvJOr1nBOJLC/6DDxV1fv6nLw55ai4eQ20c+jtvHeVz/yTdJ0Fgh6mJJBXNbIjyxaiFc= 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 1773314089915707.3417236238065; Thu, 12 Mar 2026 04:14:49 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1252014.1548804 (Exim 4.92) (envelope-from ) id 1w0dzn-0002NZ-ET; Thu, 12 Mar 2026 11:14:27 +0000 Received: by outflank-mailman (output) from mailman id 1252014.1548804; Thu, 12 Mar 2026 11:14:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w0dzn-0002NN-BD; Thu, 12 Mar 2026 11:14:27 +0000 Received: by outflank-mailman (input) for mailman id 1252014; Thu, 12 Mar 2026 11:14:26 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w0dzm-00028I-U6 for xen-devel@lists.xenproject.org; Thu, 12 Mar 2026 11:14:26 +0000 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [2607:f8b0:4864:20::641]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a0bd6a30-1e04-11f1-b164-2bf370ae4941; Thu, 12 Mar 2026 12:14:26 +0100 (CET) Received: by mail-pl1-x641.google.com with SMTP id d9443c01a7336-2ae88e16485so7067395ad.0 for ; Thu, 12 Mar 2026 04:14:26 -0700 (PDT) Received: from fedora ([103.2.232.250]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2aeae34eaacsm49271645ad.49.2026.03.12.04.14.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2026 04:14:23 -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" X-Inumbo-ID: a0bd6a30-1e04-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773314064; x=1773918864; 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=RPerCwQjjELYfGowH6evflvClMRzfpgAd8/IYGd3nUo=; b=mDebFh2bQ5yIw+y0cb2hdOzNRGLJ8VTeuY5SUkV0+B5rSOrHh7bUKwGALpygOKehm2 mgl16lGkVUB9o11mQKVjaZYiylI22UBvJpYkF25sblHu3m4qUgKRjsWeUC/W7YHMfgIf BnYAMC/smos1C8pbz1MpcOKbADAZGzE4p8nW3aN56M0pAGdlBc6VL0BV6TtF+nBijyoh g4wGPn2zXE3t4gkj5E7onZgsPGHNvLnUWguqBOuvGFMAKXFuU7+6mWF3GGgF1zg0vx1n NSQAZQXrbmXvwKjOx0+Yq81NOFwi1G+eA/PXghEbxchUylXxAa+0UdTz0YhQ4FlxlKDy fcxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773314064; x=1773918864; 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=RPerCwQjjELYfGowH6evflvClMRzfpgAd8/IYGd3nUo=; b=NhR/j5JaT2BMnF1zOpYindi9vN+JCeu2pdSFHEb3Aa/OsLioSLlgXdRpsL6rSH0cip UYAyJHJg0ExGD7/YtCT5FSosPg3/4vrcZ4mT8XQKyHt0nmBI8JYRcF9aggTyaXU6j48R omqtpcN0Xkm41rxTTcn7IAjaEdPSpLSS8KlA5oWY1n2YrLTEPDq8MLgj1cAjUIBET9Gq U/3rQPPPPirv35dUEkeR/vCSwo/0bKwP4x/kKFo7qcxgc0lEP9B0emrdN9MHQXpMXxWM dt5Njtp+oRwpqqpGgC9LWqTVcewKpHwReqKOEcFL6M2+stttIwR1W48olA7ul0lIosQP KldA== X-Gm-Message-State: AOJu0Yw27j4aQYyOiIL/6rDcJ9gxtzI7gqBQ/qCMOp4sprBQhxA5TB8B HtTUhWGIbUdkAyQQeo6UINo4f55D056zlvawOf0bY9nFUZvX5l3Yp9/ELlL1oCAz X-Gm-Gg: ATEYQzxfeqe7Z1UxsO5Q8FPraMxIiDABdVQX7WUjcg3suIgmzKF/1PpCiZ5ecoYSpKk GCzz7b74CmI2BvcsoUEkoBHFeZeamVFkxHwFZj4c1GWc2ta+UdyFVEzbanifhKtd071fx5oQRxB PcH5g+I/1gpiH7U46DgbaFUnc0lYtH0C4YQkwUsmVcOLAyYGelP35yTDDDKOpOmOfVPhoHuNw14 mTbatBZOnVyjWCitf+O/KBd/qUJtHFv2c88Lua0ajJV/KLDyMAt6Dd/GN9gho5eBv2CAf+7ZTrS 7aIrNsUrQ5UgVZJIbydbXCv9nHx5il5nWcfNHYO9O9tDbx3c1/fbuBMWFYPBL6x85l4bmNdXBny Q9FSTzGv2zwkxjniJPqGnyAlnU+FiSFhXjc5O1otiXvAn3dHLQ5Nm3BMTm9M25X6luNzhARSQcN NugBi36N3QUlauLpjr1Ml+Gbwwd6bxkQILR8HvdWd4DaK/tRKRBn6F6+3pFczKKl0ZgXJXpu1W7 FcMdjMXBsWUZYRIWEaTXsJCML9J1Il/thsWgd8+2cYgtfDfKqiX6ALZKyZTSpYDrKsA6jTt5g== X-Received: by 2002:a17:903:1a30:b0:2ae:4d23:334d with SMTP id d9443c01a7336-2aeae9207f4mr58137715ad.56.1773314064003; Thu, 12 Mar 2026 04:14:24 -0700 (PDT) From: Soumyajyotii Ssarkar To: xen-devel@lists.xenproject.org, sarkarsoumyajyoti23@gmail.com Cc: Andrew Cooper , "Daniel P . Smith" , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Soumyajyotii Ssarkar Subject: [RFC PATCH v3 1/3] x86/efi: Add BGRT image preservation infrastructure Date: Thu, 12 Mar 2026 16:44:12 +0530 Message-ID: <20260312111414.17808-2-soumyajyotisarkar23@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260312111414.17808-1-soumyajyotisarkar23@gmail.com> References: <20260312111414.17808-1-soumyajyotisarkar23@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1773314091547158501 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 ++++++++++++++++++++++++++++++++++++ 2 files changed, 135 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..e6451130ce 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 const 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 (const 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) +{ + 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 =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); + ((struct acpi_table_bgrt *)bgrt)->image_address =3D (UINTN)new_image; + ((struct acpi_table_bgrt *)bgrt)->header.checksum =3D 0; + checksum =3D 0; + + for ( i =3D 0; i < bgrt->header.length; i++ ) + checksum +=3D ((const UINT8 *)bgrt)[i]; + + ((struct acpi_table_bgrt *)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. */ -- 2.53.0