From nobody Mon Mar 23 19:54:36 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 Reported-by: Jan Beulich=C2=A0 Reported-by: Marek Marczykowski-G=C3=B3recki --- 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 From nobody Mon Mar 23 19:54:36 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=IpTrP8NbH3sGE7Wu7+f004CvWGmKH8jKp7a8f8zR6NirZhNOTxC6ucWUY7MgZyRjjQe+iS1cGjpaNU+4hvbIVje+iRXQYq71FoDGySm0PTq2j6ffJVNsjgpszMt+3RdvqIl+DsvNGXFy2yXXU0mlNFOKW/kSbYhzburHTND2ZHI= 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=tr7F9R+tUqPLczRWKCRwjM4O+ic73FL25ctZpaWIvEA=; b=Eds+Gfx6iNoOPJ31YQlEA51lwEdxeVGHKLWKB3SnR5M2ArNrE4IQRM2JL/Du+bmJSvjPC10iis6NSy9A3DmOpuQ3GLBKvkE4pTyvlJeihurpod2nhxDRNs1OlnSzWcWs7pBJP60V4ajLvbIDguLX+nG1o0w3c1m3U3fGbwYQyqQ= 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 1773314089745744.5405427782813; Thu, 12 Mar 2026 04:14:49 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1252015.1548813 (Exim 4.92) (envelope-from ) id 1w0dzr-0002dN-Ls; Thu, 12 Mar 2026 11:14:31 +0000 Received: by outflank-mailman (output) from mailman id 1252015.1548813; Thu, 12 Mar 2026 11:14:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w0dzr-0002dG-Ir; Thu, 12 Mar 2026 11:14:31 +0000 Received: by outflank-mailman (input) for mailman id 1252015; Thu, 12 Mar 2026 11:14:30 +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 1w0dzq-00028I-Bv for xen-devel@lists.xenproject.org; Thu, 12 Mar 2026 11:14:30 +0000 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [2607:f8b0:4864:20::644]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a2c9b25f-1e04-11f1-b164-2bf370ae4941; Thu, 12 Mar 2026 12:14:29 +0100 (CET) Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-2ae5423b02aso6538255ad.1 for ; Thu, 12 Mar 2026 04:14:29 -0700 (PDT) Received: from fedora ([103.2.232.250]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2aeae34eaacsm49271645ad.49.2026.03.12.04.14.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2026 04:14:26 -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: a2c9b25f-1e04-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773314067; x=1773918867; 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=tr7F9R+tUqPLczRWKCRwjM4O+ic73FL25ctZpaWIvEA=; b=gcLWqtKAyWpapckl7CL+iy5G8nSwyQsgMBFzDTAif4ntcsiXMFde1zXvzMEUxbgVT9 3FjWkjM+65hrCdad0RTUuuVxwiP/JnC/AsVpNMad/a3OhWS7hT6F8ZerkoQ6nwUmMMER GW8E2793ZzkvSL2SqEXH09Xz2BnkG0ASk1iiDvn47UU2d/tsSJqM4vZIrTPr5Da3gHTy xeXlnbIZYUpOlzeW5TwCUD7M2ryEVBvFZzEct8mreDtTdssT/KuxokoPIuae6Wz52761 kuDl2pw8e/1nDDG4eapRqSJovwOdSGG1Yqrol8Imt6sEQGrXn1ZzxruDKJ14cDf4ltLr cheA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773314067; x=1773918867; 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=tr7F9R+tUqPLczRWKCRwjM4O+ic73FL25ctZpaWIvEA=; b=xPF/eJjMiOFSBhx1X1QuwF97pSyJULJp0DrOmA9qPQgDSQ1TQLRqp+iUisvGBcfv95 33NVGncIcNnsC9A4x0O40htyJPje/1S7bUr01LRorqvAArxSNVQTqnIURHNrkFhAHh06 qlzSRSoXNEW4IVeT2ZN+y/3H1fGaa5aUMb6ZgDRreilWSnYrPQ58n66V7zUvJHK1kdQ2 YslMZ6YdFy6HlEaVnQrhpZYsNHfx7QPUKojjC1+IJGKFuBuh6BI7+skas+bxsvR+CVMW d39XzODXnAJIOSkvczq1B0dQrhbKXS6TOtE42Nao9tAeRcWJZpNUnXPNzAddnsRJ5lFc VgBQ== X-Gm-Message-State: AOJu0YxFXm3HxnzG4nSoia7m1vr1A+JrO6zd6WVJDyetMc1EZ3irs/7e YF/9YAZf21x3P2Z0Gz8EyEI/wuEA05bgTQGyBc0sb4Dnd29WzHUOYMyvFRfpfCqm X-Gm-Gg: ATEYQzzOdJ1+q8cg2bqE0z3iENms+VHTfegSZJf2uk8vog1hpdHXvnYibuABojbx9xU eL+sBBiqtq4m+q1sAI/x/UAFRb76NMSdGW7Lk3d4a3Fl2V/MftbqGVMG/zK/gof08J3Y8QFbmSt OaQIiiZ6RZESwSLWrm57Tie84V4/3hKNQ8OFvP8Aw9XnuYIfDIkpwlYims2TqlTAT9qK7CLVd85 b47hpeJS8a4VywwCQLp0wyAjdMCUvSv5WTp1uaqEs3BP7N+GdsewJnCm+ZNKuHsNZ/kduO/oUdh TaVEMX35efmIY7GV1p24mLXnivmuPwlXw8FV7oohOXe1cDwvwjV/UscD1DXzcTncVSIfSmP7ijn CT+SiPS27CCox5T1+seGkJvkoYFjzZP9vLe+hSrJQZKHRBWChMgFlP0mBfoguGaOr1Xo3lmmACQ bX59WWX9pDS2jeGIT8iID/ADTNIes4/8khiO7AmSAdsMzVQ0r+NkDuy9yncUr4vJmkIKK8msDIj BX74TveDlnR9UCaixRPsT18EnF/W8CgiXLpWF5zFLg+5Llx92XtbErrXpren3+h8BLeUv6sXWFF LtqUJvyJ X-Received: by 2002:a17:902:f712:b0:2ae:6092:8d93 with SMTP id d9443c01a7336-2aeae890c0amr60376925ad.28.1773314067415; Thu, 12 Mar 2026 04:14:27 -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 2/3] x86/acpi: Integrate BGRT preservation with status reporting Date: Thu, 12 Mar 2026 16:44:13 +0530 Message-ID: <20260312111414.17808-3-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: 1773314091313154100 Content-Type: text/plain; charset="utf-8" Add status reporting for BGRT preservation and integrate with Xen's ACPI subsystem: - efi_bgrt_status_info() prints preservation status (success/failure) - Called from acpi_boot_init() after ACPI tables are processed - Clarifying comment explains why invalidation code remains The invalidation code in acpi_invalidate_bgrt() now acts as a safety net: if preservation fails, the image remains in conventional RAM and gets invalidated. If preservation succeeds, the image is in EfiACPIReclaimMemory which won't match the RAM_TYPE_CONVENTIONAL check, leaving the table valid. Signed-off-by: Soumyajyotii Ssarkar Reported-by: Jan Beulich=C2=A0 Reported-by: Marek Marczykowski-G=C3=B3recki --- xen/arch/x86/acpi/boot.c | 8 ++++++++ xen/common/efi/boot.c | 16 ++++++++++++++++ xen/include/xen/efi.h | 1 + 3 files changed, 25 insertions(+) diff --git a/xen/arch/x86/acpi/boot.c b/xen/arch/x86/acpi/boot.c index 1ca2360e00..20afe79db9 100644 --- a/xen/arch/x86/acpi/boot.c +++ b/xen/arch/x86/acpi/boot.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -327,6 +328,11 @@ static int __init cf_check acpi_parse_hpet(struct acpi= _table_header *table) return 0; } +/* + * Invalidate BGRT if image is in conventional RAM (preservation failed). + * If preservation succeeded, image is in EfiACPIReclaimMemory, which + * won't match RAM_TYPE_CONVENTIONAL check, so table remains valid. + */ static int __init cf_check acpi_invalidate_bgrt(struct acpi_table_header *= table) { struct acpi_table_bgrt *bgrt_tbl =3D @@ -754,5 +760,7 @@ int __init acpi_boot_init(void) acpi_table_parse(ACPI_SIG_BGRT, acpi_invalidate_bgrt); + efi_bgrt_status_info(); + return 0; } diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index e6451130ce..68e06d707c 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -1911,6 +1911,22 @@ static bool __init cf_check rt_range_valid(unsigned = long smfn, unsigned long emf return true; } +void __init efi_bgrt_status_info(void) +{ + if ( !efi_enabled(EFI_BOOT) ) + return; + + if ( bgrt_info.preserved ) + { + printk(XENLOG_INFO "EFI: BGRT image preserved: %lu KB\n", + bgrt_info.size / 1024); + printk(XENLOG_INFO "EFI: BGRT relocated from %p to %p\n", + bgrt_info.old_addr, bgrt_info.new_addr); + } + else if ( bgrt_info.failure_reason[0] ) + printk(XENLOG_WARNING "EFI: BGRT preservation failed: %s\n", + bgrt_info.failure_reason); +} void __init efi_init_memory(void) { diff --git a/xen/include/xen/efi.h b/xen/include/xen/efi.h index 723cb80852..e72ab3c6b5 100644 --- a/xen/include/xen/efi.h +++ b/xen/include/xen/efi.h @@ -39,6 +39,7 @@ static inline bool efi_enabled(unsigned int feature) extern bool efi_secure_boot; void efi_init_memory(void); +void efi_bgrt_status_info(void); bool efi_boot_mem_unused(unsigned long *start, unsigned long *end); bool efi_rs_using_pgtables(void); unsigned long efi_get_time(void); -- 2.53.0 From nobody Mon Mar 23 19:54:36 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=1773314095; cv=none; d=zohomail.com; s=zohoarc; b=WvAHDSvMf7wFq0XKkolpmv0A2yvBVbJE/TzGH2By8SpQng23RnHu3gwXhHtVILeDTRgDziKzhvPveJAWliQOM1ppYOUZFH78QwDcapMSXVbuSA/JABHMUnJtYJ0E9f+HWrLy+6y1MzCQqGiUH993LM259ZUebz+oOKLcio2EF+M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773314095; 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=1cDGQruln6tADqd5GJFoKiZEDSzQNLfuESS4cK4O5GU=; b=BmzSf0T2txJKuG6V7Q+DzVJO9hL99jjzs7Z80PkhLJYXOSuDbtnmSOJnPOSHBskoTmXIB+txQdG3A5vJK35thxj1XA6FN9/6jBhL1Mc+5EUe+OdT4p77yFKwFtVRPEVt0psEU1wknMMI0XLeHGwpaTI3AcoNmSpwdYIPCyBpJxs= 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 1773314095733957.4260363165208; Thu, 12 Mar 2026 04:14:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1252017.1548823 (Exim 4.92) (envelope-from ) id 1w0dzw-0002vV-UD; Thu, 12 Mar 2026 11:14:36 +0000 Received: by outflank-mailman (output) from mailman id 1252017.1548823; Thu, 12 Mar 2026 11:14:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w0dzw-0002vO-PT; Thu, 12 Mar 2026 11:14:36 +0000 Received: by outflank-mailman (input) for mailman id 1252017; Thu, 12 Mar 2026 11:14:35 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w0dzv-0002tK-79 for xen-devel@lists.xenproject.org; Thu, 12 Mar 2026 11:14:35 +0000 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [2607:f8b0:4864:20::644]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a4e39ee7-1e04-11f1-9ccf-f158ae23cfc8; Thu, 12 Mar 2026 12:14:33 +0100 (CET) Received: by mail-pl1-x644.google.com with SMTP id d9443c01a7336-2ab39b111b9so4112565ad.1 for ; Thu, 12 Mar 2026 04:14:32 -0700 (PDT) Received: from fedora ([103.2.232.250]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2aeae34eaacsm49271645ad.49.2026.03.12.04.14.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2026 04:14:30 -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: a4e39ee7-1e04-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773314071; x=1773918871; 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=1cDGQruln6tADqd5GJFoKiZEDSzQNLfuESS4cK4O5GU=; b=i/Y93/TheXEqQDXW/9BrSmZcO5qI5NuQlvONMeYLP/QMZGOz+s8b7FoRfVKvZQhiOT HxnV4WfgXmb7MaIWDC4nKRecpGhUHygB6ugUFJ0SuKEW3MIrn3lrAGKxCrmNJcqn80Fp EvXNPT027RCDiUE3tDQYt+N8edG65scxFGZ3d/y9jme+RnIQv7cte8/OI0yEmfGiVOvN BvnWrr2i/xL+YMSoYjRA2d3Gjy1ZmuTjSSuZtFHHaQonWZsBzOr0hbSJNIPGorzJakL3 0PcfBD4qX8Qka+is1mbVC6VYfxD+CZBjusMe/R+2fCyvSMmlaQIis8rKN89tXa3KirNd CjZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773314071; x=1773918871; 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=1cDGQruln6tADqd5GJFoKiZEDSzQNLfuESS4cK4O5GU=; b=HlYNMcwnZLGoi47kEwvhtCMp35hIJB/EhRS8UeFvbqo0q2qiszJujckA6A2QHtykA0 ha45VfDNPDh7pG8QXsp5BS3GovUW94jIj9R7fH6T1R/5tazZDaVlz+NXWhu6TpeZ5skU cGiTCMItm5E0EwKBi5DNtvKqnbSKVEKRHQaAp6djdEftDyAXdagcL+0XtJdQOJmgH9Es imeHEjY2LN1IDNH4Z+ta58npU4Ap3WlGQDidhAjZXvPZY9YStBsscg93YVgn/x1w3jG5 FnQslpsNFxvntXDKna5bPKh/5TYGujlrqZQxJyywzeLaQ00nujxoA/MviXg8fBFSHZRH hHhw== X-Gm-Message-State: AOJu0Yw3iRPoRmR61WVoDv/dZhVKZGa2Umu+6y5/z4u3jnBxn4uVcYUB FsPrPcqOwqsDNCTXpN+jgtaOd8zaiAWUHqMZoEIg7OdDhtbr1RYUUoMlANDrn4C8 X-Gm-Gg: ATEYQzy4SxhvbE6I4Zx3CXPUVLF6j1BV+BgaIghZPlqRUWbtnnmUzZdsFxNeIej516f WxeAdy2rwmg/PbASzZgQprIeuasgzs3L9zmk8oQs/tg8MNnSjItvXy2tkwyrCvrSBzLrKidzuwy jEBj4TtfmsOLLWkYphmc+XpJXveniK/7Gh8DyNkVpRQok63n5eaHr6lDuOX2yjkWN95UND+bxvy 9ZWf/yz3BnD3gifyOqkAbeP5qsQ3IHWLprGCD1uRxCGfAws4PJM4jbKqDwHckmaGtglICjgZzYX ftc3+/7vDdq8XsnbVlafDTbn2tda5XQLYc3ztmW7rPG14y5CdaLdeG63JBhRhC9kftV/lUBoo+f J1Tyn+aD53GWLAMybvAK/KbKvvSlvio7a4RMrJCQXsQe7YkA7xoVIeu6aypdv8yzyCicZjQA0oJ UnagT44FGnBHEvlbZ9MUVegZfrRs1tpxD0XzFFFk2bTWqn5f2JBh2+DJK0p/sVQyr+LqR5+txCG sQH7xBQTH3mlcaFm05HKO+NrKgxReX+FIMIPChUZx10G/fRaGPYXTP5aYS+ZvC4Tf7SbKrhAQ== X-Received: by 2002:a17:902:f68d:b0:2ae:5ec4:2f80 with SMTP id d9443c01a7336-2aeae8eaf1emr54731745ad.47.1773314070986; Thu, 12 Mar 2026 04:14:30 -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 3/3] x86/efi: Add opt-out mechanism for BGRT preservation Date: Thu, 12 Mar 2026 16:44:14 +0530 Message-ID: <20260312111414.17808-4-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: 1773314097499154100 Content-Type: text/plain; charset="utf-8" BGRT preservation is now enabled by default to fix ACPI corruption for desktop/workstation systems (similar to ESRT). As described in the task: https://github.com/QubesOS/qubes-issues/issues/10764 Add an opt-out parameter to allow disabling BGRT preservation on systems where the ~1MB memory overhead is not desired. The opt-out is implemented through two boot paths with early parsing during the EFI boot phase before preservation runs: 1. xen.efi direct boot: '-nobgrt' command line option (parsed in efi_start()) 2. Multiboot2 (GRUB): 'efi=3Dno-bgrt' peeked from mb2 cmdline tag using get_option() in efi_multiboot2() The flag is checked at the start of efi_preserve_bgrt_img() to skip preservation entirely when disabled. Status logging indicates whether preservation was disabled, succeeded, or failed. Usage: Default: BGRT preserved automatically xen.efi: Add '-nobgrt' option GRUB/MB2: Add 'efi=3Dno-bgrt' to Xen command line Signed-off-by: Soumyajyotii Ssarkar Reported-by: Jan Beulich=C2=A0 Reported-by: Marek Marczykowski-G=C3=B3recki --- xen/arch/x86/efi/efi-boot.h | 3 +++ xen/common/efi/boot.c | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index 0547d845cd..6c986cf6c0 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -897,6 +897,9 @@ void __init efi_multiboot2(EFI_HANDLE ImageHandle, efi_arch_edid(gop_handle); } + if ( cmdline && get_option(cmdline, "efi=3Dno-bgrt") ) + opt_bgrt_disabled =3D true; + efi_arch_edd(); efi_arch_cpu(); diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 68e06d707c..dc46e783f3 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -170,6 +170,7 @@ static SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdErr; static UINT32 __initdata mdesc_ver; static bool __initdata map_bs; +static bool __initdata opt_bgrt_disabled =3D false; static struct file __initdata cfg; static struct file __initdata kernel; @@ -825,6 +826,9 @@ static void __init efi_preserve_bgrt_img(void) bgrt_info.preserved =3D false; + if ( opt_bgrt_disabled ) + return; + bgrt =3D efi_get_bgrt(); if ( !bgrt ) { @@ -1582,6 +1586,8 @@ void EFIAPI __init noreturn efi_start(EFI_HANDLE Imag= eHandle, base_video =3D true; else if ( wstrcmp(ptr + 1, L"mapbs") =3D=3D 0 ) map_bs =3D true; + else if ( wstrcmp(ptr + 1, L"nobgrt") =3D=3D 0 ) + opt_bgrt_disabled =3D true; else if ( wstrncmp(ptr + 1, L"cfg=3D", 4) =3D=3D 0 ) cfg_file_name =3D ptr + 5; else if ( i + 1 < argc && wstrcmp(ptr + 1, L"cfg") =3D=3D = 0 ) @@ -1592,6 +1598,7 @@ void EFIAPI __init noreturn efi_start(EFI_HANDLE Imag= eHandle, PrintStr(L"Xen EFI Loader options:\r\n"); PrintStr(L"-basevideo retain current video mode\r\n"= ); PrintStr(L"-mapbs map EfiBootServices{Code,Data}= \r\n"); + PrintStr(L"-nobgrt disable BGRT preservation\r\n"= ); PrintStr(L"-cfg=3D specify configuration file\r= \n"); PrintStr(L"-help, -? display this help\r\n"); blexit(NULL); @@ -1916,7 +1923,9 @@ void __init efi_bgrt_status_info(void) if ( !efi_enabled(EFI_BOOT) ) return; - if ( bgrt_info.preserved ) + if ( opt_bgrt_disabled ) + printk(XENLOG_INFO "EFI: BGRT preservation disabled\n"); + else if ( bgrt_info.preserved ) { printk(XENLOG_INFO "EFI: BGRT image preserved: %lu KB\n", bgrt_info.size / 1024); -- 2.53.0