public inbox for linux-efi@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
Cc: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org,
	ricardo.neri@intel.com, matt@codeblueprint.co.uk,
	Lee Chun-Yi <jlee@suse.com>, Al Stone <astone@redhat.com>,
	Borislav Petkov <bp@alien8.de>, Ingo Molnar <mingo@kernel.org>,
	Andy Lutomirski <luto@kernel.org>,
	Bhupesh Sharma <bhsharma@redhat.com>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH V2 5/6] x86/mm: If in_atomic(), allocate pages without sleeping
Date: Mon, 3 Sep 2018 10:34:59 +0200	[thread overview]
Message-ID: <20180903083459.GT24124@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <1535881594-25469-6-git-send-email-sai.praneeth.prakhya@intel.com>

On Sun, Sep 02, 2018 at 02:46:33AM -0700, Sai Praneeth Prakhya wrote:
> From: Sai Praneeth <sai.praneeth.prakhya@intel.com>
> 
> A page fault occurs when any EFI Runtime Service tries to reference a
> memory region which it shouldn't. If the illegally accessed region
> is EFI_BOOT_SERVICES_<CODE/DATA>, the efi specific page fault handler
> fixes it up by dynamically creating VA->PA mappings using
> efi_map_region().
> 
> Originally, efi_map_region() and hence the functionality of creating
> mappings for efi regions was intended to be used *only* during boot time
> (please note __init modifier) and hence when called during runtime (i.e.
> from efi page fault handler), the page allocators complain. Calling
> efi_map_region() during runtime complains because "gfp_allowed_mask"
> value changes from boot time to runtime (GFP_BOOT_MASK to
> __GFP_BITS_MASK). During boot, even though efi_map_region() calls
> alloc_<pte/pmd>_page with GFP_KERNEL, the page allocator doesn't
> complain because "__GFP_RECLAIM" flag is cleared by "gfp_allowed_mask",
> but during runtime it isn't cleared and hence prints below stack trace.
> 
> BUG: sleeping function called from invalid context at mm/page_alloc.c:4320

> get_zeroed_page+0x12/0x40
> alloc_pmd_page+0x13/0x50
> populate_pmd+0xc0/0x2e0
> __cpa_process_fault+0x2e1/0x5d0
> __change_page_attr_set_clr+0x7c3/0xcd0
> kernel_map_pages_in_pgd+0x8c/0x160
> __map_region+0x3c/0x60
> efi_map_region+0x83/0xd0
> efi_illegal_accesses_fixup+0x1ca/0x1e0
> no_context+0x112/0x390
> __do_page_fault+0xc7/0x4f0

> Fix the above warning by conditionally changing the allocation from
> GFP_KERNEL to GFP_ATOMIC, so that efi page fault handler could use
> efi_map_region() during runtime. This change shouldn't effect any other
> generic page allocations because this allocation is used only by efi
> functions [1].

> diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
> index 3bded76e8d5c..1b28a333c8ce 100644
> --- a/arch/x86/mm/pageattr.c
> +++ b/arch/x86/mm/pageattr.c
> @@ -926,7 +926,13 @@ static void unmap_pud_range(p4d_t *p4d, unsigned long start, unsigned long end)
>  
>  static int alloc_pte_page(pmd_t *pmd)
>  {
> -	pte_t *pte = (pte_t *)get_zeroed_page(GFP_KERNEL);
> +	pte_t *pte;
> +
> +	if (in_atomic())
> +		pte = (pte_t *)get_zeroed_page(GFP_ATOMIC);
> +	else
> +		pte = (pte_t *)get_zeroed_page(GFP_KERNEL);
> +
>  	if (!pte)
>  		return -1;
>  

This looks like tinkering to me..

  reply	other threads:[~2018-09-03  8:34 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-02  9:46 [PATCH V2 0/6] Add efi page fault handler to fix/recover from Sai Praneeth Prakhya
2018-09-02  9:46 ` [PATCH V2 1/6] efi: Make efi_rts_work accessible to efi page fault handler Sai Praneeth Prakhya
2018-09-02  9:46 ` [PATCH V2 2/6] x86/efi: Remove __init attribute from memory mapping functions Sai Praneeth Prakhya
2018-09-02 10:56   ` Borislav Petkov
2018-09-03  5:03     ` Prakhya, Sai Praneeth
2018-09-03  7:12       ` Borislav Petkov
2018-09-03  8:15         ` Prakhya, Sai Praneeth
2018-09-02  9:46 ` [PATCH V2 3/6] x86/efi: Permanently save the EFI_MEMORY_MAP passed by the firmware Sai Praneeth Prakhya
2018-09-02  9:46 ` [PATCH V2 4/6] x86/efi: Add efi page fault handler to fixup/recover from page faults caused by firmware Sai Praneeth Prakhya
2018-09-03  8:58   ` Thomas Gleixner
2018-09-03 17:16     ` Prakhya, Sai Praneeth
2018-09-02  9:46 ` [PATCH V2 5/6] x86/mm: If in_atomic(), allocate pages without sleeping Sai Praneeth Prakhya
2018-09-03  8:34   ` Peter Zijlstra [this message]
2018-09-03  8:53     ` Thomas Gleixner
2018-09-03 17:07       ` Prakhya, Sai Praneeth
2018-09-02  9:46 ` [PATCH V2 6/6] x86/efi: Introduce EFI_WARN_ON_ILLEGAL_ACCESS Sai Praneeth Prakhya

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=20180903083459.GT24124@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=ard.biesheuvel@linaro.org \
    --cc=astone@redhat.com \
    --cc=bhsharma@redhat.com \
    --cc=bp@alien8.de \
    --cc=jlee@suse.com \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=matt@codeblueprint.co.uk \
    --cc=mingo@kernel.org \
    --cc=ricardo.neri@intel.com \
    --cc=sai.praneeth.prakhya@intel.com \
    --cc=tglx@linutronix.de \
    /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