mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ardb@kernel.org>
To: "Eshaan Deshmukh" <eshaan2031@icloud.com>,
	"Thomas Gleixner" <tglx@kernel.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>,
	dave.hansen@linux.intel.com, x86@kernel.org
Cc: "Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
	"H . Peter Anvin" <hpa@zytor.com>,
	linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86/efi: Handle errors for efi_map_region_fixed()
Date: Thu, 10 Sep 2026 09:53:12 +0200	[thread overview]
Message-ID: <c321dc7d-7cee-4222-a346-fa0448ce4f74@app.fastmail.com> (raw)
In-Reply-To: <20260810102237.2167872-1-eshaan2031@icloud.com>

Hello Eshaan,

On Mon, 10 Aug 2026, at 12:22, Eshaan Deshmukh wrote:
> The function efi_map_region_fixed() ignores the errors returned from
> kernel_map_pages_in_pgd(). If mapping failes, this can cause page
> faults. Update __map_region() and efi_map_region_fixed() to return the
> error code from kernel_map_pages_in_pgd(). If there is an error,
> efi_map_region_fixed() logs an error message using pr_err(), disables
> EFI runtime services, and returns.
>

Does this solve an actual problem that you observed?

> Signed-off-by: Eshaan Deshmukh <eshaan2031@icloud.com>
> ---
>  arch/x86/include/asm/efi.h     |  2 +-
>  arch/x86/platform/efi/efi.c    | 10 ++++++++--
>  arch/x86/platform/efi/efi_32.c |  6 +++++-
>  arch/x86/platform/efi/efi_64.c | 20 ++++++++++++++------
>  4 files changed, 28 insertions(+), 10 deletions(-)
>
> diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h
> index be58b7f5c..04952e064 100644
> --- a/arch/x86/include/asm/efi.h
> +++ b/arch/x86/include/asm/efi.h
> @@ -128,7 +128,7 @@ extern bool efi_disable_ibt_for_runtime;
>  extern int __init efi_memblock_x86_reserve_range(void);
>  extern void __init efi_print_memmap(void);
>  extern void __init efi_map_region(efi_memory_desc_t *md);
> -extern void __init efi_map_region_fixed(efi_memory_desc_t *md);
> +extern int __init efi_map_region_fixed(efi_memory_desc_t *md);
>  extern void efi_sync_low_kernel_mappings(void);
>  extern int __init efi_alloc_page_tables(void);
>  extern int __init efi_setup_page_tables(unsigned long pa_memmap, 
> unsigned num_pages);
> diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
> index 0c39adb96..4b875843a 100644
> --- a/arch/x86/platform/efi/efi.c
> +++ b/arch/x86/platform/efi/efi.c
> @@ -735,8 +735,14 @@ static void __init kexec_enter_virtual_mode(void)
>  	* Map efi regions which were passed via setup_data. The virt_addr is a
>  	* fixed addr which was used in first kernel of a kexec boot.
>  	*/
> -	for_each_efi_memory_desc(md)
> -		efi_map_region_fixed(md); /* FIXME: add error handling */
> +	for_each_efi_memory_desc(md) {
> +		if (efi_map_region_fixed(md)) {
> +			pr_err("Failed to map fixed EFI region\n");
> +			clear_bit(EFI_RUNTIME_SERVICES, &efi.flags);
> +			return;
> +		}
> +
> +	}
> 
>  	/*
>  	 * Unregister the early EFI memmap from efi_init() and install
> diff --git a/arch/x86/platform/efi/efi_32.c 
> b/arch/x86/platform/efi/efi_32.c
> index b2cc7b455..9307999b9 100644
> --- a/arch/x86/platform/efi/efi_32.c
> +++ b/arch/x86/platform/efi/efi_32.c
> @@ -84,7 +84,11 @@ int __init efi_setup_page_tables(unsigned long 
> pa_memmap, unsigned num_pages)
>  	return 0;
>  }
> 
> -void __init efi_map_region_fixed(efi_memory_desc_t *md) {}
> +int __init efi_map_region_fixed(efi_memory_desc_t *md)
> +{
> +	return 0;
> +}
> +
>  void __init parse_efi_setup(u64 phys_addr, u32 data_len) {}
> 
>  efi_status_t efi_call_svam(efi_runtime_services_t * const *,
> diff --git a/arch/x86/platform/efi/efi_64.c 
> b/arch/x86/platform/efi/efi_64.c
> index 5861008ea..05f1df6ca 100644
> --- a/arch/x86/platform/efi/efi_64.c
> +++ b/arch/x86/platform/efi/efi_64.c
> @@ -269,12 +269,12 @@ int __init efi_setup_page_tables(unsigned long 
> pa_memmap, unsigned num_pages)
>  	return 0;
>  }
> 
> -static void __init __map_region(efi_memory_desc_t *md, u64 va)
> +static int __init __map_region(efi_memory_desc_t *md, u64 va)
>  {
>  	unsigned long flags = _PAGE_RW;
>  	unsigned long pfn;
>  	pgd_t *pgd = efi_mm.pgd;
> -
> +	int error;
>  	/*
>  	 * EFI_RUNTIME_SERVICES_CODE regions typically cover PE/COFF
>  	 * executable images in memory that consist of both R-X and
> @@ -299,9 +299,11 @@ static void __init __map_region(efi_memory_desc_t 
> *md, u64 va)
>  		flags |= _PAGE_ENC;
> 
>  	pfn = md->phys_addr >> PAGE_SHIFT;
> -	if (kernel_map_pages_in_pgd(pgd, pfn, va, md->num_pages, flags))
> +	error = kernel_map_pages_in_pgd(pgd, pfn, va, md->num_pages, flags);
> +	if (error)
>  		pr_warn("Error mapping PA 0x%llx -> VA 0x%llx!\n",
>  			   md->phys_addr, va);
> +	return error;
>  }
> 
>  void __init efi_map_region(efi_memory_desc_t *md)
> @@ -357,10 +359,16 @@ void __init efi_map_region(efi_memory_desc_t *md)
>   * md->virt_addr is the original virtual address which had been mapped in kexec
>   * 1st kernel.
>   */
> -void __init efi_map_region_fixed(efi_memory_desc_t *md)
> +int __init efi_map_region_fixed(efi_memory_desc_t *md)
>  {
> -	__map_region(md, md->phys_addr);
> -	__map_region(md, md->virt_addr);
> +	int error;
> +
> +	error = __map_region(md, md->phys_addr);
> +
> +	if (error)
> +		return error;
> +
> +	return __map_region(md, md->virt_addr);
>  }
> 
>  void __init parse_efi_setup(u64 phys_addr, u32 data_len)
> -- 
> 2.55.0

      reply	other threads:[~2026-09-10  7:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-10 10:22 Eshaan Deshmukh
2026-09-10  7:53 ` Ard Biesheuvel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c321dc7d-7cee-4222-a346-fa0448ce4f74@app.fastmail.com \
    --to=ardb@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=eshaan2031@icloud.com \
    --cc=hpa@zytor.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®