From nobody Sun Apr 5 13:27:56 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 Reported-by: Andrew Cooper 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 +++++++++++++++++++++++++++++++++++ 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 From nobody Sun Apr 5 13:27:56 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=1774346977; cv=none; d=zohomail.com; s=zohoarc; b=LU9z5fP2BYaOvRTHSweLcYuum8IdO5KsxADZAYhhT9l3V7wg+dpivAoZ8nMTLRfjIfBvX05AvyCEfXbuPau2jVJhFegXgc+uZMZcwDXCdCAgBoX3GKz3LQ7HZp8mwq22478r3gD1qRrd0BL+Mv0tPImVmIVeRKMURaeAqRMMoAc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774346977; 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=S7lJOGAyXgWXm5RAImeMolbrvF/QPjaKzs3OuvcIdvo=; b=erSOt9pVszNKx2weJ/kfHIHlw7aWHsnG9Rtaip9Up6iaKKznhZ/9G/VPCixfuZF7oBmlyd4GKMcHxSg/UiYquuS9Z8QEiMfuqqZZpYfoMLxCNwY7x6INpfAl6zAwnJmg7iKni0+d2DHAc1stgdU13QFhQ3x6Th5tbPFwhzVUn+Q= 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 1774346977892413.34725478558016; Tue, 24 Mar 2026 03:09:37 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1260231.1553602 (Exim 4.92) (envelope-from ) id 1w4yhL-0001rk-LN; Tue, 24 Mar 2026 10:09:19 +0000 Received: by outflank-mailman (output) from mailman id 1260231.1553602; Tue, 24 Mar 2026 10:09:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w4yhL-0001rV-HT; Tue, 24 Mar 2026 10:09:19 +0000 Received: by outflank-mailman (input) for mailman id 1260231; Tue, 24 Mar 2026 10:09:18 +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 1w4yhK-0001Nh-7r for xen-devel@lists.xenproject.org; Tue, 24 Mar 2026 10:09:18 +0000 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 835e60d7-2769-11f1-9ccf-f158ae23cfc8; Tue, 24 Mar 2026 11:09:16 +0100 (CET) Received: by mail-pf1-f196.google.com with SMTP id d2e1a72fcca58-82c4b5dfe6cso948241b3a.2 for ; Tue, 24 Mar 2026 03:09:16 -0700 (PDT) Received: from fedora ([103.2.232.250]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c74665ca206sm11377434a12.18.2026.03.24.03.09.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2026 03:09:13 -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: 835e60d7-2769-11f1-9ccf-f158ae23cfc8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774346954; x=1774951754; 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=S7lJOGAyXgWXm5RAImeMolbrvF/QPjaKzs3OuvcIdvo=; b=YxPwxc2SlyXElmo7X+3rbbmq6Fu192D7n9jpOa/CKoJ99PbxKGW6xRGzHYBIkY4mKi UdNVLkHXgvbRGoN0kAAUp179XYDxMDGxSZylGLmE0sQ4NV24WJdoRLghpUfMTyKbGoQJ TreSwjGP1P09OjE/Mze1R9pWeIlPi+6ojeuItg+zLJpzTGRZrqFOO5RCQnMYtUNOlYTS YfGGIhsh09dwyJExrXaDeG9gRuIPNivqlEuw71xj2/pOExJ4UTCvO20/AzlQaQ5VzZOu jb0r9sM1cOgLaVDQofyQr7UymDRXxI4INhi8D/B5y4tsVgwa3kQ75UTWLzLFf2slR1el h9yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774346954; x=1774951754; 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=S7lJOGAyXgWXm5RAImeMolbrvF/QPjaKzs3OuvcIdvo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pk8ashgNmqRDpvRTzico0HWtvNjw== X-Received: by 2002:a05:6a20:9189:b0:398:c170:1c7 with SMTP id adf61e73a8af0-39bcea27c41mr14127397637.26.1774346954322; Tue, 24 Mar 2026 03:09:14 -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 2/3] x86/acpi: Integrate BGRT preservation with status reporting Date: Tue, 24 Mar 2026 15:38:55 +0530 Message-ID: <20260324100856.6691-3-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-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1774346979962158500 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: Andrew Cooper 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 47d5b9b2a8..e22a42c15b 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 Sun Apr 5 13:27:56 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=1774346977; cv=none; d=zohomail.com; s=zohoarc; b=Hcl7Ji9t4vDK+w53BfavgH5cJ1UHfI86ssqtlkQnOIE0OBhR3cJrsp5N5dX0yJLODfH2q//V2c7Acbt+CV1tY5hqsc5EWmEt5gj7rRn1HS4WEv7rWCwNUQxJULOYQgRnD3SAqqyLcnn/c3QCM7iprQOiylOXN+hMQcGRYsefKfo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774346977; 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=6/EFfTLPPvtpKfYbDxMVwQU9jDgu7ScMy19tpR6gQjI=; b=XGPFnQj+ZfxS749Q3Ej0R3DfJ8ti7lsuy4AI2HhbQr5jXlAhk+oASHX5yQSxhPavG4+lLd7HV+QercDimDLm4YFHjZqsc0TC8VpcpG5qT9Qp9jJf6IaNP/6FiIH+MsV5H/u+YN65q8WGVfFhOhUKcKHqijUJ8AMLPoURh/paCsE= 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 177434697767558.00880317978135; Tue, 24 Mar 2026 03:09:37 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1260233.1553611 (Exim 4.92) (envelope-from ) id 1w4yhO-00028D-TQ; Tue, 24 Mar 2026 10:09:22 +0000 Received: by outflank-mailman (output) from mailman id 1260233.1553611; Tue, 24 Mar 2026 10:09:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w4yhO-00027y-PI; Tue, 24 Mar 2026 10:09:22 +0000 Received: by outflank-mailman (input) for mailman id 1260233; Tue, 24 Mar 2026 10:09:21 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1w4yhN-00026j-QF for xen-devel@lists.xenproject.org; Tue, 24 Mar 2026 10:09:21 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1w4yhN-00DoZ0-5o for xen-devel@lists.xenproject.org; Tue, 24 Mar 2026 11:09:21 +0100 Received: from [10.42.69.1] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69c262cc-5cb7-0a2a0a5109dd-0a2a4501c010-38 for ; Tue, 24 Mar 2026 11:09:21 +0100 Received: from [209.85.215.195] (helo=mail-pg1-f195.google.com) by tlsNG-d62444.mxtls.expurgate.net with ESMTPS (eXpurgate 4.55.2) (envelope-from ) id 69c262cf-6400-0a2a45010019-d155d7c3b9bd-3 for ; Tue, 24 Mar 2026 11:09:20 +0100 Received: by mail-pg1-f195.google.com with SMTP id 41be03b00d2f7-b6ce6d1d3dcso1718830a12.3 for ; Tue, 24 Mar 2026 03:09:20 -0700 (PDT) Received: from fedora ([103.2.232.250]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c74665ca206sm11377434a12.18.2026.03.24.03.09.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2026 03:09:18 -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=1774346958; x=1774951758; 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=6/EFfTLPPvtpKfYbDxMVwQU9jDgu7ScMy19tpR6gQjI=; b=iO+M95tGN3SrZhIKEBrDAqOk/orMML6o2EbcUwCf/L1IM34n6/fZWyf5ow4qI+4QNa ZFCBdM0aSHOKHX/FxfnQ2uEHkdBoaelXzCqT8oT0gbq6bjvLV+JF+1dgGnXkVfNHshND O97Lj6vvvG0jH+9e+vVAspUyQs58xolJ2Jef6DmjnhtGO2M1XhCRhf2tWJD9GMRYEbj3 qFLDmtBvKQgsf0Mh0j+CYnHsZZIPTxC/Z3kkr75TqXQnTMOGwsXNOj+2HtMmagEC9Uw/ RXDRh2/guUl2liKb2ypyGe0spXpgIqCG8hG8NGcfSmHK2tTkAQW8AYjyIAcBYWzB7kqN +B6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774346958; x=1774951758; 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=6/EFfTLPPvtpKfYbDxMVwQU9jDgu7ScMy19tpR6gQjI=; b=sjTXw13tI9AVwLnexsBk/e2y2dgIhqBJV4eS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:398:9ae9:710f with SMTP id adf61e73a8af0-39bce9b4fecmr13718713637.13.1774346958490; Tue, 24 Mar 2026 03:09:18 -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 3/3] x86/efi: Add opt-out mechanism for BGRT preservation Date: Tue, 24 Mar 2026 15:38:56 +0530 Message-ID: <20260324100856.6691-4-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-d62444/1774346961-204F7DF3-C8C0A6EB/0/0 X-purgate-type: clean X-purgate-size: 3800 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1774346981764154100 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: Andrew Cooper 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 e22a42c15b..a4db7ee516 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