From nobody Mon Apr 13 03:42:54 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=1772738337; cv=none; d=zohomail.com; s=zohoarc; b=gzdTNZkQLfr8vCbzQQUO8se2GI4lq1hjrX4DcFUT8RvAM2Musenxkso1qsPGaPfhevHKt6c3cNbnRqIdpw80QPHek52gO8Ms1xcS5eDiFkqKMOCba4SgBIdMo2O831U5+Tem7yRrO9JHPX05hGsQp6rknu0Qgvd30V2zOWMWZ0Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772738337; 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=OwGP8ee4LidY7BRMCtYUVmJPzJVamR1lF04CTiEUcS8=; b=Ba7y45FJQHVBo+hb7MlK5IBpmU8TRDGH+KAV/aRSUxeSFyT0iVPRSMtSVcGunk56RtRUC5k08Pm1pYTdF6Wd7LoyjbSTpV+5QGC46nirNK4318pIqzXZSj3fd8w1Z4qLH2yjgor012RbG1WP6/b2nPXvA4WPQLp5++koIv6MQlY= 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 1772738337297440.5782180572638; Thu, 5 Mar 2026 11:18:57 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.1247047.1545941 (Exim 4.92) (envelope-from ) id 1vyEDJ-00049O-LQ; Thu, 05 Mar 2026 19:18:25 +0000 Received: by outflank-mailman (output) from mailman id 1247047.1545941; Thu, 05 Mar 2026 19:18:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1vyEDJ-00049H-Ic; Thu, 05 Mar 2026 19:18:25 +0000 Received: by outflank-mailman (input) for mailman id 1247047; Thu, 05 Mar 2026 19:18:24 +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 1vyEDI-00048o-Ks for xen-devel@lists.xenproject.org; Thu, 05 Mar 2026 19:18:24 +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 13a29844-18c8-11f1-b164-2bf370ae4941; Thu, 05 Mar 2026 20:18:23 +0100 (CET) Received: by mail-pl1-x641.google.com with SMTP id d9443c01a7336-2addb31945aso61081585ad.1 for ; Thu, 05 Mar 2026 11:18:23 -0800 (PST) Received: from fedora ([103.2.232.250]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ae4d3113e0sm142965715ad.79.2026.03.05.11.18.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2026 11:18:21 -0800 (PST) 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: 13a29844-18c8-11f1-b164-2bf370ae4941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772738301; x=1773343101; 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=OwGP8ee4LidY7BRMCtYUVmJPzJVamR1lF04CTiEUcS8=; b=mVj/HPLH59ySa0qeybCGo8aweuZ9xWgK7HiIqoTHs93KCxnD/2VkGlS8lvHcxLk7Jq MvAim8d3kAKxrDDEM8oS703uzFhNrO3S6zJ+hYENZJTMvtHUm6yrbiBcKJ7ybzTrl+rf fDtkaAiNJMrtxtQzRMI0YQ9VhSgKQ6UZE8uGlzumoYjiQX1SXeeRcM3IjrA1nc8sTkB7 P6NZMbEPQTNG+6BbysgdfyhS2NEltH1KSGL2EhWQRaX6VU+nLRQsJgyUibDNWDKpZm12 O7FrexFPwr2vAaseBoHsQsn0NDyIpHa+qJSUmOH742te63LIa93+X71cPKLkg2Z5oQ++ BAsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772738301; x=1773343101; 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=OwGP8ee4LidY7BRMCtYUVmJPzJVamR1lF04CTiEUcS8=; b=K6FSGe94V8qADGoMhrOFMAKHRZEN9qwjqwgpisG1vNRQIgDFiODRCRbIZXTAE73ghr vqxN3XsJAqCj5NfBL2Zxky1c2uFMwHAimMFwQBnjd66BQG/rPqOznd7Zau96/gGJ0Gjf qdb3qVRRTOfCXu//LPZq8zsitV6OXGOGmu94qQa3bUH8lif3s4MQ0NufWxKXjI3ysrnY QPYPQccvy6r/fSjgE2ejBIl12FwgDZmeSQKsuSy5mj8VyRYs4uafBaUEY1pZNVAbTSaT ofeEVnnwyBgZ1Z2gyuoeqdjpu/CyBtIesslQS/WFLC4ddgtoQTNrPUeByCrM4i2T8tSg 0rTw== X-Gm-Message-State: AOJu0Yz3VEP/emR705QWaDHelpsjbbDwYlm97xYud3HzC+I+0i7y4kDz ON1yXoW88rMy3FB0V8JITM9jK3EkRVshWBtuB0eHFliwqb+ttDlCBwaCH1Vn845y X-Gm-Gg: ATEYQzztpCTLf0LcoIHOLgJbCn3B+iJrStgzicq/A8wY6oq4xXHN00b1kST5hD0zOCf mZLh3x8nrar7Rn8Wd14+eRKrJPx8JMMm4hHFdG5PgjOGB3fCvCpcUrBMNJx9ydjdez0Y0n14AnF cMbXUNu1TV8Kv+WJ0dPfmgd9w6S/DSqmDZjPudw/klt2F+zvab/Yoqt0ABhMG9TUZr/dY1GtKeG jKNF2LrXHtrOCoD/9d4SSjPviwM+rQIayMgXVKUIQgvPJybu7hSU/oi5OPbCRRYCUBm+Qs/BBXx MlT+oK04aF1YDbcq5KmzrkqJY8gxssbE0hWfu2Gk3nTrpouBocgBznxZH30KPNuE1iyu1zQo0Lv vN+QOIE47+W4wRJj87h7K51UuVul7UUmeon2gg0UqcLppbbQAULYGNe+Nhkr16Inz14UfGQljVp 3S8DJhVzJtvfG5+CkGlTnwRs4PF7z7u6h6q/qci/IrVEGbgCxRBksS7FzmR1QuHzhy6L9w+vvLs HL7DactnZfDDbOgk38lzFAAt/LHmb3ioZzm8NDjTa8MJ8a678grpX0zUlJi+c1C1NCX9wTHMw== X-Received: by 2002:a17:903:2445:b0:2ae:588a:f3e5 with SMTP id d9443c01a7336-2ae6aaae636mr70140825ad.30.1772738301473; Thu, 05 Mar 2026 11:18:21 -0800 (PST) From: Soumyajyotii Ssarkar To: xen-devel@lists.xenproject.org, sarkarsoumyajyoti23@gmail.com Cc: Jan Beulich , "Daniel P . Smith" , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Andrew Cooper , Soumyajyotii Ssarkar Subject: [PATCH 1/3] x86/efi: Add BGRT image preservation during boot Date: Fri, 6 Mar 2026 00:48:08 +0530 Message-ID: <20260305191810.31033-2-soumyajyotisarkar23@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260305191810.31033-1-soumyajyotisarkar23@gmail.com> References: <20260305191810.31033-1-soumyajyotisarkar23@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1772738339362158500 Content-Type: text/plain; charset="utf-8" The ACPI BGRT (Boot Graphics Resource Table) contains a pointer to a boot logo image stored in BootServicesData memory. When Xen reclaims this memory during boot, the image is lost and the BGRT table becomes invalid, causing Linux dom0 to report ACPI checksum errors. Add preservation logic similar to ESRT table handling: - Locate BGRT table via XSDT during EFI boot services phase - Validate BMP image signature and size (max 16 MB) - Copy image to EfiACPIReclaimMemory (safe from reclamation) - Update BGRT table with new image address - Recalculate ACPI table checksum The preservation runs automatically during efi_exit_boot() before Boot Services are terminated. This ensures the image remains accessible to dom0. Open coded ACPI parsing is used because Xen's ACPI subsystem is not available during the EFI boot phase. The RSDP is obtained from the EFI System Table, and the XSDT is walked manually to find BGRT. Signed-off-by: Soumyajyotii Ssarkar --- xen/arch/x86/efi/efi-boot.h | 2 + xen/common/efi/boot.c | 187 ++++++++++++++++++++++++++++++++++++ 2 files changed, 189 insertions(+) diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index 42a2c46b5e..27792a56ff 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(SystemTable); + efi_exit_boot(ImageHandle, SystemTable); } diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c index 967094994d..1e3489e902 100644 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -173,6 +174,14 @@ static struct file __initdata ramdisk; static struct file __initdata xsm; static const CHAR16 __initconst newline[] =3D L"\r\n"; +static __initdata struct { + bool preserved; + uint64_t old_addr; + uint64_t new_addr; + uint32_t size; + const char *failure_reason; +} bgrt_debug_info; + static void __init PrintStr(const CHAR16 *s) { StdOut->OutputString(StdOut, (CHAR16 *)s ); @@ -747,6 +756,171 @@ static void __init efi_relocate_esrt(EFI_SYSTEM_TABLE= *SystemTable) efi_bs->FreePool(memory_map); } +struct bmp_header { + uint16_t signature; + uint32_t file_size; + uint16_t reserved_1; + uint16_t reserved_2; + uint32_t data_offset; +} __attribute__((packed)); + +/* + * ACPI Structures - defined locally, + * since we cannot include acpi headers + * in EFI Context. + */ + +struct acpi_rsdp { + char signature[8]; + uint8_t checksum; + char oem_id[6]; + uint8_t revision; + uint32_t rsdt_physical_address; + uint32_t length; + uint64_t xsdt_physical_address; + uint8_t extended_checksum; + uint8_t reserved[3]; +} __attribute__((packed)); + +struct acpi_table_header { + char signature[4]; + uint32_t length; + uint8_t revision; + uint8_t checksum; + char oem_id[6]; + char oem_table_id[8]; + uint32_t oem_revision; + uint32_t asl_compiler_id; + uint32_t asl_compiler_revision; +} __attribute__((packed)); + +struct acpi_xsdt { + struct acpi_table_header header; + uint64_t table_offset_entry[1]; /* Variable array length */ +} __attribute__((packed)); + +struct acpi_bgrt { + struct acpi_table_header header; + uint16_t version; + uint8_t status; + uint8_t image_type; + uint64_t image_address; + uint32_t image_offset_x; + uint32_t image_offset_y; +} __attribute__((packed)); + +static struct acpi_bgrt* __init find_bgrt_table(EFI_SYSTEM_TABLE *SystemTa= ble) +{ + EFI_GUID acpi2_guid =3D ACPI_20_TABLE_GUID; + struct acpi_rsdp *rsdp =3D NULL; + struct acpi_xsdt *xsdt; + struct acpi_bgrt *bgrt; + uint32_t entry_count, actual_size; + unsigned int i; + + for ( i =3D 0; i < SystemTable->NumberOfTableEntries; i++ ) + { + if ( match_guid(&acpi2_guid, &SystemTable->ConfigurationTable[i].V= endorGuid) ) + { + rsdp =3D SystemTable->ConfigurationTable[i].VendorTable; + break; + } + } + + if ( !rsdp || !rsdp->xsdt_physical_address ) + return NULL; + + xsdt =3D (struct acpi_xsdt *)rsdp->xsdt_physical_address; + if ( !xsdt ) + return NULL; + + actual_size =3D (xsdt->header.length - sizeof(struct acpi_table_header= )); + entry_count =3D (actual_size / sizeof(uint64_t)); + + for ( i =3D 0; i < entry_count; i++ ) + { + struct acpi_table_header *header =3D (struct acpi_table_header *)x= sdt->table_offset_entry[i]; + + if ( header->signature[0] =3D=3D 'B' + && header->signature[1] =3D=3D 'G' + && header->signature[2] =3D=3D 'R' + && header->signature[3] =3D=3D 'T' ) + { + bgrt =3D (struct acpi_bgrt *)header; + return bgrt; + } + } + return NULL; +} + +#define MAX_IMAGE_SIZE (16 * 1024 * 1024) /* Sanity check: reject if b= igger */ + +static void __init efi_preserve_bgrt_img(EFI_SYSTEM_TABLE *SystemTable) +{ + struct acpi_bgrt *bgrt; + struct bmp_header *bmp; + void *old_image, *new_image; + uint32_t image_size; + EFI_STATUS status; + uint8_t checksum; + unsigned int i; + + bgrt_debug_info.preserved =3D false; + bgrt_debug_info.failure_reason =3D NULL; + + bgrt =3D find_bgrt_table(SystemTable); + if ( !bgrt ) + { + bgrt_debug_info.failure_reason =3D "BGRT table not found in XSDT"; + return; + } + + if ( !bgrt->image_address ) + { + bgrt_debug_info.failure_reason =3D "BGRT image_address is NULL"; + return; + } + + old_image =3D (void *)bgrt->image_address; + bmp =3D (struct bmp_header *)old_image; + + if ( bmp->signature !=3D 0x4D42 ) + { + bgrt_debug_info.failure_reason =3D "Invalid BMP signature"; + return; + } + + image_size =3D bmp->file_size; + if ( !image_size || image_size > MAX_IMAGE_SIZE ) + { + bgrt_debug_info.failure_reason =3D "Invalid image size"; + return; + } + + status =3D efi_bs->AllocatePool(EfiACPIReclaimMemory, image_size, &new= _image); + if ( status !=3D EFI_SUCCESS || !new_image ) + { + bgrt_debug_info.failure_reason =3D "Memory allocation failed"; + return; + } + + memcpy(new_image, old_image, image_size); + + bgrt->image_address =3D (uint64_t)new_image; + bgrt->status |=3D 0x01; + + bgrt->header.checksum =3D 0; + checksum =3D 0; + for ( i =3D 0; i < bgrt->header.length; i++ ) + checksum +=3D ((uint8_t *)bgrt)[i]; + bgrt->header.checksum =3D (uint8_t)(0 - checksum); + + bgrt_debug_info.preserved =3D true; + bgrt_debug_info.old_addr =3D (uint64_t)old_image; + bgrt_debug_info.new_addr =3D (uint64_t)new_image; + bgrt_debug_info.size =3D image_size; +} + /* * Include architecture specific implementation here, which references the * static globals defined above. @@ -1794,6 +1968,19 @@ void __init efi_init_memory(void) if ( !efi_enabled(EFI_BOOT) ) return; + if ( bgrt_debug_info.preserved ) + { + printk(XENLOG_INFO "EFI: BGRT image preserved: %u KB\n", + bgrt_debug_info.size / 1024); + printk(XENLOG_INFO "EFI: BGRT relocated from %#" PRIx64 " to %#" P= RIx64 "\n", + bgrt_debug_info.old_addr, bgrt_debug_info.new_addr); + } + else if ( bgrt_debug_info.failure_reason ) + { + printk(XENLOG_WARNING "EFI: BGRT preservation failed: %s\n", + bgrt_debug_info.failure_reason); + } + printk(XENLOG_DEBUG "EFI memory map:%s\n", map_bs ? " (mapping BootServices)" : ""); for ( i =3D 0; i < efi_memmap_size; i +=3D efi_mdesc_size ) -- 2.53.0