[PATCH 3/3] x86/efi: Add opt-out mechanism for BGRT preservation

Soumyajyotii Ssarkar posted 3 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH 3/3] x86/efi: Add opt-out mechanism for BGRT preservation
Posted by Soumyajyotii Ssarkar 1 month, 1 week ago
As described in the task, BGRT preservation is now enabled by default to fix ACPI corruption
for desktop/workstation systems (similar to ESRT).

Add an opt-out parameter 'efi=no-bgrt' to allow disabling BGRT
preservation on systems where the ~1MB memory overhead is not
desired.

The parameter is parsed during normal Xen boot (not during EFI
phase), so it only affects diagnostic logging. The opt-out flag
is checked at the start of efi_preserve_bgrt_img().

Usage:
  Default: BGRT preserved automatically
  Opt-out: Add 'efi=no-bgrt' in Xen command line

Signed-off-by: Soumyajyotii Ssarkar <soumyajyotisarkar23@gmail.com>
---
 xen/common/efi/boot.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
index 1e3489e902..b735eac6b2 100644
--- a/xen/common/efi/boot.c
+++ b/xen/common/efi/boot.c
@@ -167,6 +167,7 @@ static SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdErr;

 static UINT32 __initdata mdesc_ver;
 static bool __initdata map_bs;
+static bool __initdata opt_bgrt_disabled = false;

 static struct file __initdata cfg;
 static struct file __initdata kernel;
@@ -868,6 +869,9 @@ static void __init efi_preserve_bgrt_img(EFI_SYSTEM_TABLE *SystemTable)
     bgrt_debug_info.preserved = false;
     bgrt_debug_info.failure_reason = NULL;

+    if ( opt_bgrt_disabled )
+        return;
+
     bgrt = find_bgrt_table(SystemTable);
     if ( !bgrt )
     {
@@ -1873,6 +1877,10 @@ static int __init cf_check parse_efi_param(const char *s)
             else
                 __clear_bit(EFI_RS, &efi_flags);
         }
+        else if ( (ss - s) == 7 && !memcmp(s, "no-bgrt", 7) )
+        {
+            opt_bgrt_disabled = true;
+        }
         else if ( (ss - s) > 5 && !memcmp(s, "attr=", 5) )
         {
             if ( !cmdline_strcmp(s + 5, "uc") )
@@ -1968,7 +1976,11 @@ void __init efi_init_memory(void)
     if ( !efi_enabled(EFI_BOOT) )
         return;

-    if ( bgrt_debug_info.preserved )
+    if ( opt_bgrt_disabled )
+    {
+        printk(XENLOG_INFO "EFI: BGRT preservation disabled\n");
+    }
+    else if ( bgrt_debug_info.preserved )
     {
         printk(XENLOG_INFO "EFI: BGRT image preserved: %u KB\n",
                bgrt_debug_info.size / 1024);
--
2.53.0
Re: [PATCH 3/3] x86/efi: Add opt-out mechanism for BGRT preservation
Posted by Marek Marczykowski-Górecki 1 month ago
On Fri, Mar 06, 2026 at 12:48:10AM +0530, Soumyajyotii Ssarkar wrote:
> As described in the task, BGRT preservation is now enabled by default to fix ACPI corruption
> for desktop/workstation systems (similar to ESRT).
> 
> Add an opt-out parameter 'efi=no-bgrt' to allow disabling BGRT
> preservation on systems where the ~1MB memory overhead is not
> desired.
> 
> The parameter is parsed during normal Xen boot (not during EFI
> phase), so it only affects diagnostic logging. The opt-out flag
> is checked at the start of efi_preserve_bgrt_img().
> 
> Usage:
>   Default: BGRT preserved automatically
>   Opt-out: Add 'efi=no-bgrt' in Xen command line
> 
> Signed-off-by: Soumyajyotii Ssarkar <soumyajyotisarkar23@gmail.com>
> ---
>  xen/common/efi/boot.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/common/efi/boot.c b/xen/common/efi/boot.c
> index 1e3489e902..b735eac6b2 100644
> --- a/xen/common/efi/boot.c
> +++ b/xen/common/efi/boot.c
> @@ -167,6 +167,7 @@ static SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdErr;
> 
>  static UINT32 __initdata mdesc_ver;
>  static bool __initdata map_bs;
> +static bool __initdata opt_bgrt_disabled = false;
> 
>  static struct file __initdata cfg;
>  static struct file __initdata kernel;
> @@ -868,6 +869,9 @@ static void __init efi_preserve_bgrt_img(EFI_SYSTEM_TABLE *SystemTable)
>      bgrt_debug_info.preserved = false;
>      bgrt_debug_info.failure_reason = NULL;
> 
> +    if ( opt_bgrt_disabled )
> +        return;
> +
>      bgrt = find_bgrt_table(SystemTable);
>      if ( !bgrt )
>      {
> @@ -1873,6 +1877,10 @@ static int __init cf_check parse_efi_param(const char *s)
>              else
>                  __clear_bit(EFI_RS, &efi_flags);
>          }
> +        else if ( (ss - s) == 7 && !memcmp(s, "no-bgrt", 7) )
> +        {
> +            opt_bgrt_disabled = true;
> +        }

This is too late - standard param parsing happens after efi_exit_boot()
already. See early cmdline parsing in efi_multiboot2() and also in
efi_start() (but note the latter is about options to xen.efi, which
isn't exactly the same as standard xen cmdline...)

>          else if ( (ss - s) > 5 && !memcmp(s, "attr=", 5) )
>          {
>              if ( !cmdline_strcmp(s + 5, "uc") )
> @@ -1968,7 +1976,11 @@ void __init efi_init_memory(void)
>      if ( !efi_enabled(EFI_BOOT) )
>          return;
> 
> -    if ( bgrt_debug_info.preserved )
> +    if ( opt_bgrt_disabled )
> +    {
> +        printk(XENLOG_INFO "EFI: BGRT preservation disabled\n");
> +    }
> +    else if ( bgrt_debug_info.preserved )
>      {
>          printk(XENLOG_INFO "EFI: BGRT image preserved: %u KB\n",
>                 bgrt_debug_info.size / 1024);
> --
> 2.53.0
> 

-- 
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab