From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) by kanga.kvack.org (Postfix) with ESMTP id 3F9686B0006 for ; Mon, 12 Nov 2018 03:33:02 -0500 (EST) Received: by mail-ot1-f71.google.com with SMTP id v12so6269134otf.5 for ; Mon, 12 Nov 2018 00:33:02 -0800 (PST) Received: from foss.arm.com (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id r13si8122672oth.245.2018.11.12.00.33.00 for ; Mon, 12 Nov 2018 00:33:00 -0800 (PST) Date: Mon, 12 Nov 2018 08:32:54 +0000 Message-ID: <86muqeelvt.wl-marc.zyngier@arm.com> From: Marc Zyngier Subject: Re: [PATCH] efi: permit calling efi_mem_reserve_persistent from atomic context In-Reply-To: References: <20181108180511.30239-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sender: owner-linux-mm@kvack.org List-ID: To: Qian Cai Cc: Ard Biesheuvel , linux-mm@kvack.org, linux-efi@vger.kernel.org, will.deacon@arm.com, linux kernel , linux-arm-kernel@lists.infradead.org On Mon, 12 Nov 2018 02:45:48 +0000, Qian Cai wrote: >=20 >=20 >=20 > > On Nov 9, 2018, at 9:45 PM, Qian Cai wrote: > >=20 > >=20 > > On 11/8/18 at 1:05 PM, Ard Biesheuvel wrote: > >=20 > >> Currently, efi_mem_reserve_persistent() may not be called from atomic > >> context, since both the kmalloc() call and the memremap() call may > >> sleep. > >>=20 > >> The kmalloc() call is easy enough to fix, but the memremap() call > >> needs to be moved into an init hook since we cannot control the > >> memory allocation behavior of memremap() at the call site. > >>=20 > >> Signed-off-by: Ard Biesheuvel > >> --- > >> drivers/firmware/efi/efi.c | 31 +++++++++++++++++++------------ > >> 1 file changed, 19 insertions(+), 12 deletions(-) > >>=20 > >> diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c > >> index 249eb70691b0..cfc876e0b67b 100644 > >> --- a/drivers/firmware/efi/efi.c > >> +++ b/drivers/firmware/efi/efi.c > >> @@ -963,36 +963,43 @@ bool efi_is_table_address(unsigned long phys_add= r) > >> } > >>=20 > >> static DEFINE_SPINLOCK(efi_mem_reserve_persistent_lock); > >> +static struct linux_efi_memreserve *efi_memreserve_root __ro_after_in= it; > >>=20 > >> int efi_mem_reserve_persistent(phys_addr_t addr, u64 size) > >> { > >> - struct linux_efi_memreserve *rsv, *parent; > >> + struct linux_efi_memreserve *rsv; > >>=20 > >> - if (efi.mem_reserve =3D=3D EFI_INVALID_TABLE_ADDR) > >> + if (!efi_memreserve_root) > >> return -ENODEV; > >>=20 > >> - rsv =3D kmalloc(sizeof(*rsv), GFP_KERNEL); > >> + rsv =3D kmalloc(sizeof(*rsv), GFP_ATOMIC); > >> if (!rsv) > >> return -ENOMEM; > >>=20 > >> - parent =3D memremap(efi.mem_reserve, sizeof(*rsv), MEMREMAP_WB); > >> - if (!parent) { > >> - kfree(rsv); > >> - return -ENOMEM; > >> - } > >> - > >> rsv->base =3D addr; > >> rsv->size =3D size; > >>=20 > >> spin_lock(&efi_mem_reserve_persistent_lock); > >> - rsv->next =3D parent->next; > >> - parent->next =3D __pa(rsv); > >> + rsv->next =3D efi_memreserve_root->next; > >> + efi_memreserve_root->next =3D __pa(rsv); > >> spin_unlock(&efi_mem_reserve_persistent_lock); > >>=20 > >> - memunmap(parent); > >> + return 0; > >> +} > >>=20 > >> +static int __init efi_memreserve_root_init(void) > >> +{ > >> + if (efi.mem_reserve =3D=3D EFI_INVALID_TABLE_ADDR) > >> + return -ENODEV; > >> + > >> + efi_memreserve_root =3D memremap(efi.mem_reserve, > >> + sizeof(*efi_memreserve_root), > >> + MEMREMAP_WB); > >> + if (!efi_memreserve_root) > >> + return -ENOMEM; > >> return 0; > >> } > >> +early_initcall(efi_memreserve_root_init); > >>=20 > >> #ifdef CONFIG_KEXEC > >> static int update_efi_random_seed(struct notifier_block *nb, > >> --=20 > >> 2.19.1 > > BTW, I won=E2=80=99t be able to apply this patch on top of this series = [1]. After applied that series, the original BUG sleep from atomic is gone = as well as two other GIC warnings. Do you think a new patch is needed here? > >=20 > > [1] https://www.spinics.net/lists/arm-kernel/msg685751.html > OK, I was able to apply this patch on top of latest mainline (ccda4af0f4b= 9) > which also include one patch (1/6) from the above series, >=20 > However, the efi-related patches from the series (4/6, 5/6, and 6/6) are = no > longer able to be cleanly applied.=20 >=20 > As the results, the above patch did fix the original BUG: sleep from atom= ic, > but it introduces 2 new warnings. [...] These are the warnings you've already reported, aren't they? And we've established that if you apply the whole series, everything work as intended at least on the GIC side (the timer issue is a different story altogether). Or am I missing something? Thanks, M. --=20 Jazz is not dead, it just smell funny.