From patchwork Wed Nov 14 17:55:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 151107 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5992690ljp; Wed, 14 Nov 2018 09:56:04 -0800 (PST) X-Google-Smtp-Source: AJdET5cHa0TpsZ3T+MESMaVm6RnKiMPEzPS16pCBH+OfwUao4C628i8bOexNvJxB2AccMdNMg6NE X-Received: by 2002:aa7:8254:: with SMTP id e20-v6mr2997523pfn.164.1542218163915; Wed, 14 Nov 2018 09:56:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542218163; cv=none; d=google.com; s=arc-20160816; b=VAQl3oc/mQYwjpn240UIMGKD9Aa+vYvT/6UDMP3P7KAaz52YXSrH0gp7Z0hrkERAge XwbT6e7gafZx16e/sTj1awpHJIMZ4KY9wvpMkxcEIZmYqqX1u7DUTwfZ4qNU8YDVx3Ot 7xEON83AMKmiTQo94BZlxA2kuaqxIOQxh6M0/U20fskHas+zpGCl58w0CGzvQ4/c2UAz UiyJBoEOPSYSX855MQtZvn/JEbdrA5wDD7F33bXr5K0CQW02mhu/O1RpGIli1PbIEcl4 eDpguGPU6P2AX7M9J5te9Ygl99JkgbFWlwF9P/Frl5dcRHXYrJIeBXQWDnE5DxM6cJL4 mrIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=5g/w6IYjjrc1ur3xQUnZUzYfp3xOHO2eoNh7QjFs/U8=; b=0wI9S74RQVrTWyIY4aArhV6zx8LHVOoMUid1b4zdGaQ/Xp8hldPIXE1hobdUxiW74g 8oyFqPKFEUNGgirakMNUAwOF5yMLd7Cs9UxdGTwoWRgArvhwTFgFet66JXHo4YxRy1nI D/NI5PnhaO0bI8IDpJ6aL2zf+evQYSzw2q4cWHW/e1XybSN1SaLmDo9PajIAz+vHUiXX PJiSe0gP/uTYT+YvHLZDWAlXMa2HmCeLFHq4sMWWTW15YrnRB5GDYN6JcCcUZHynOozj 2mlBNSl6E4lYYrqJAU5xKSpxPkr4Lv2LUonbLR3DdKMsv4Ho8/b7eJWLxhwJkqA6Ylwm ySfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MrKpp9DK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r12si24051442pgf.22.2018.11.14.09.56.03; Wed, 14 Nov 2018 09:56:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MrKpp9DK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733185AbeKOEAM (ORCPT + 32 others); Wed, 14 Nov 2018 23:00:12 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:40151 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731710AbeKOEAL (ORCPT ); Wed, 14 Nov 2018 23:00:11 -0500 Received: by mail-pg1-f194.google.com with SMTP id z10so7700490pgp.7 for ; Wed, 14 Nov 2018 09:56:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5g/w6IYjjrc1ur3xQUnZUzYfp3xOHO2eoNh7QjFs/U8=; b=MrKpp9DKH5DVuMf8JhGmxTgjqkfLlM95C5KSSjf8vnCZ9vtDaRQhVbk0gKrxhUY3lB LoQH4pvAeuJSeXnhGHW93lD8g1K73BYk+COEGaBZJbmiOPeUlWI1tuBhvspI7BuuYVQ0 5kn6J9uKxmROHwQqBO5gtX7hIc704F1drXjyU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5g/w6IYjjrc1ur3xQUnZUzYfp3xOHO2eoNh7QjFs/U8=; b=W3nuHHnaPX7G5H/tYq4Qr/LeiJt+5dGA99ZmH2lYYG5VcnDHmZSzsvN5E4WeQcXShB gKWIimpI4nqxx74WqQ3We3xizLxjxReNahknRxGzmwKXumsRnOU/20IdVnBoY25G/D7W 9DqSKvq+k8NYDzkXIb9Fsig/lONirxInBwNpfXwZvYY6NYNkQL4p/57It9Nu/KxZkF7c R+vM+euHG9UG9aIFiAPPAB97A3sxr4Z3AOqltSj7AiTLIkbzIE/l0mJAFj0E+s3fEhAr 5yLsBUj2A3orQma+nJbdL9e7JSWF7pWRAOFP2pgccICBW+5ekOJczp3JwmatpHIojLcB VDXQ== X-Gm-Message-State: AGRZ1gKsYD8P3GrTuiMnB/6Ra2LqvkVi1hUAPsRkIOJ3e8Q/Gyk9uMc6 pMeP17zVoYMMB3FTfX95MG3THYctwKoBqA== X-Received: by 2002:a63:4f5e:: with SMTP id p30mr2646680pgl.71.1542218159419; Wed, 14 Nov 2018 09:55:59 -0800 (PST) Received: from mba13.psav.com ([64.114.255.97]) by smtp.gmail.com with ESMTPSA id i2-v6sm21301738pgq.35.2018.11.14.09.55.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 09:55:58 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 2/5] efi: arm: revert deferred unmap of early memmap mapping Date: Wed, 14 Nov 2018 09:55:41 -0800 Message-Id: <20181114175544.12860-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181114175544.12860-1-ard.biesheuvel@linaro.org> References: <20181114175544.12860-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 3ea86495aef2 ("efi/arm: preserve early mapping of UEFI memory map longer for BGRT") deferred the unmap of the early mapping of the UEFI memory map to accommodate the ACPI BGRT code, which looks up the memory type that backs the BGRT table to validate it against the requirements of the UEFI spec. Unfortunately, this causes problems on ARM, which does not permit early mappings to persist after paging_init() is called, resulting in a WARN() splat. Since we don't support the BGRT table on ARM anway, let's revert ARM to the old behaviour, which is to take down the early mapping at the end of efi_init(). Fixes: 3ea86495aef2 ("efi/arm: preserve early mapping of UEFI memory ...") Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/arm-init.c | 4 ++++ drivers/firmware/efi/arm-runtime.c | 2 +- drivers/firmware/efi/memmap.c | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/firmware/efi/arm-init.c b/drivers/firmware/efi/arm-init.c index 388a929baf95..1a6a77df8a5e 100644 --- a/drivers/firmware/efi/arm-init.c +++ b/drivers/firmware/efi/arm-init.c @@ -265,6 +265,10 @@ void __init efi_init(void) (params.mmap & ~PAGE_MASK))); init_screen_info(); + + /* ARM does not permit early mappings to persist across paging_init() */ + if (IS_ENABLED(CONFIG_ARM)) + efi_memmap_unmap(); } static int __init register_gop_device(void) diff --git a/drivers/firmware/efi/arm-runtime.c b/drivers/firmware/efi/arm-runtime.c index 922cfb813109..a00934d263c5 100644 --- a/drivers/firmware/efi/arm-runtime.c +++ b/drivers/firmware/efi/arm-runtime.c @@ -110,7 +110,7 @@ static int __init arm_enable_runtime_services(void) { u64 mapsize; - if (!efi_enabled(EFI_BOOT) || !efi_enabled(EFI_MEMMAP)) { + if (!efi_enabled(EFI_BOOT)) { pr_info("EFI services will not be available.\n"); return 0; } diff --git a/drivers/firmware/efi/memmap.c b/drivers/firmware/efi/memmap.c index fa2904fb841f..38b686c67b17 100644 --- a/drivers/firmware/efi/memmap.c +++ b/drivers/firmware/efi/memmap.c @@ -118,6 +118,9 @@ int __init efi_memmap_init_early(struct efi_memory_map_data *data) void __init efi_memmap_unmap(void) { + if (!efi_enabled(EFI_MEMMAP)) + return; + if (!efi.memmap.late) { unsigned long size; From patchwork Wed Nov 14 17:55:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 151109 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5992751ljp; Wed, 14 Nov 2018 09:56:07 -0800 (PST) X-Google-Smtp-Source: AJdET5d6QWBYN6x/hQOH6MsFtlVYofk2jTcQNAjZKyLr617HD5LHfIRRSLzycw6ZZtN1lDWRK7rr X-Received: by 2002:a17:902:1103:: with SMTP id d3-v6mr2752692pla.249.1542218167447; Wed, 14 Nov 2018 09:56:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542218167; cv=none; d=google.com; s=arc-20160816; b=vJWHKNluW9FNE8jMVro+LA9T0Y0RoE6Wv4ydnoXHWglXavnxi2DfFSKWn291/IOl8M bqy003t+jECW1Mo0O54MGVXukVCnwmpFppUC1n4BzL8hVDeVw5fA7K5nvi69umR1keTk n62XRBOpDbAzHCHRCDdo7iMb9EmHR98afOgTBOjYtmCQCCP7zEmQYF1BT8ZrlIIpXAk0 nq3XQIk8wUvShpySUNnPAIeG06HaZUgh7pevQTZhVrPBVIxOtw+Gl9mK1EAxinRRS6LR A+NgZrg793lAxZgq4v6TCxAoOoAufgaB9GKD9fx/d/chRMHOaXy3pHbrDqcsO0ZfbGmD xXXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=wgQ6lhA7RkEviiHkwSDj/bCPpNPjF7ngHY8ighWmwmU=; b=mr8bGQfT0YlESjIuKXRol/ZZI/0+WHTLuPig+FSIAXGcortOhSkLTXUcRaAqz/Pcgp w8Y0zOvE6+oNuzzVX9/akDX9TDG6XZcwm4WvSqYWc78MQxkpvSu4zXr3Tp2N+E8ip47O 0sb0bY7iGTHcFb6CdiMjqaAcPvUXGbZiC9a4Ht7SNgHf9VQu3yiAR8AQg5aoaHN8WKCb krYGW1pDSMVcxyE40Q5gZR4Ujz+PjNx36i9ZGmzeJ7iammaPfx9ecK3hU/R9eBbinhvF xBLz81jQ8gnzlDB2EBhx44Q+NXDmOBIDwnlvY9YItpe3F1V5IoxBpcBYOlGFVY5mlmh/ XJYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a4UHeMEI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g12-v6si24801909pla.351.2018.11.14.09.56.06; Wed, 14 Nov 2018 09:56:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a4UHeMEI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387526AbeKOEAP (ORCPT + 32 others); Wed, 14 Nov 2018 23:00:15 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:45133 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732981AbeKOEAO (ORCPT ); Wed, 14 Nov 2018 23:00:14 -0500 Received: by mail-pg1-f194.google.com with SMTP id y4so7688059pgc.12 for ; Wed, 14 Nov 2018 09:56:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wgQ6lhA7RkEviiHkwSDj/bCPpNPjF7ngHY8ighWmwmU=; b=a4UHeMEIcEfzBqqcqd4pUkBF9vuauDlV2NEaWs78ydREPZ79oDz8FfibpMYXeslbSj ancDmlMg3dM+9a+cWz2jhfj7h93DmNKU0COq3wRXsh+m9J+pSMmBt0IF+4qeGiRp/Mh7 /aHI060CNmHiJXTnuLAOnrzLVveApFqf7aA6k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wgQ6lhA7RkEviiHkwSDj/bCPpNPjF7ngHY8ighWmwmU=; b=eUki05OwvbUMuiyeklkTnkQ/J8Xu83swQS1R1NtSVzCg4OziXwuDR5CtXaK/Xo/lEZ Jpxi9WmVUcOjKp1rpQbK+ipdthsSVovO7lU+ZVO+4eh/2rq9vQr2eii7DHnKjJW0haGp LB0/NuD8KQq65iajqCItzkX2G4Js5vNpcfI5WoRyWCI30Y88ERpqN6IS00oB11HvknVt XWJhpGfAj8t+InCVuP7yi1X6iKjYdJojSsRyhQjgwgKUeH/nKa3HCMl1WjMKD/rxDYfL v1XSZW7EkpnVQc6Ekkoo0JUBBh/4ZXZou/P0Sx9Y6hu+MjbjoqtG7m5J8XqZRsR+rqvE 5YCg== X-Gm-Message-State: AGRZ1gJA6YczhLJQCzq3hXA+37Y3kbTV7ulFoRrBI3jtOmUhPPXJ5T1s wmWbBHHoqsEi5m1pfsHOoFKkfg== X-Received: by 2002:a63:42c1:: with SMTP id p184mr2648383pga.202.1542218163043; Wed, 14 Nov 2018 09:56:03 -0800 (PST) Received: from mba13.psav.com ([64.114.255.97]) by smtp.gmail.com with ESMTPSA id i2-v6sm21301738pgq.35.2018.11.14.09.56.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 09:56:00 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 4/5] efi/arm: defer persistent reservations until after paging_init() Date: Wed, 14 Nov 2018 09:55:43 -0800 Message-Id: <20181114175544.12860-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181114175544.12860-1-ard.biesheuvel@linaro.org> References: <20181114175544.12860-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The new memory EFI reservation feature we introduced to allow memory reservations to persist across kexec may trigger an unbounded number of calls to memblock_reserve(). The memblock subsystem can deal with this fine, but not before memblock resizing is enabled, which we can only do after paging_init(), when the memory we reallocate the array into is actually mapped. So break out the memreserve table processing into a separate routine and call it after paging_init() on arm64. On ARM, because of limited reviewing bandwidth of the maintainer, we cannot currently fix this, so instead, disable the EFI persistent memreserve entirely on ARM so we can fix it later. Tested-by: Marc Zyngier Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/setup.c | 1 + drivers/firmware/efi/efi.c | 4 ++++ drivers/firmware/efi/libstub/arm-stub.c | 3 +++ include/linux/efi.h | 7 +++++++ 4 files changed, 15 insertions(+) -- 2.17.1 diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 953e316521fc..f4fc1e0544b7 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -313,6 +313,7 @@ void __init setup_arch(char **cmdline_p) arm64_memblock_init(); paging_init(); + efi_apply_persistent_mem_reservations(); acpi_table_upgrade(); diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 249eb70691b0..72a4da76d274 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -592,7 +592,11 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz, early_memunmap(tbl, sizeof(*tbl)); } + return 0; +} +int __init efi_apply_persistent_mem_reservations(void) +{ if (efi.mem_reserve != EFI_INVALID_TABLE_ADDR) { unsigned long prsv = efi.mem_reserve; diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c index 30ac0c975f8a..3d36142cf812 100644 --- a/drivers/firmware/efi/libstub/arm-stub.c +++ b/drivers/firmware/efi/libstub/arm-stub.c @@ -75,6 +75,9 @@ void install_memreserve_table(efi_system_table_t *sys_table_arg) efi_guid_t memreserve_table_guid = LINUX_EFI_MEMRESERVE_TABLE_GUID; efi_status_t status; + if (IS_ENABLED(CONFIG_ARM)) + return; + status = efi_call_early(allocate_pool, EFI_LOADER_DATA, sizeof(*rsv), (void **)&rsv); if (status != EFI_SUCCESS) { diff --git a/include/linux/efi.h b/include/linux/efi.h index 845174e113ce..100ce4a4aff6 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1167,6 +1167,8 @@ static inline bool efi_enabled(int feature) extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused); extern bool efi_is_table_address(unsigned long phys_addr); + +extern int efi_apply_persistent_mem_reservations(void); #else static inline bool efi_enabled(int feature) { @@ -1185,6 +1187,11 @@ static inline bool efi_is_table_address(unsigned long phys_addr) { return false; } + +static inline int efi_apply_persistent_mem_reservations(void) +{ + return 0; +} #endif extern int efi_status_to_err(efi_status_t status); From patchwork Wed Nov 14 17:55:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 151110 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5992763ljp; Wed, 14 Nov 2018 09:56:08 -0800 (PST) X-Google-Smtp-Source: AJdET5ci1UfRyvG6OvwN8rb4oGTq3f3ZoZrs9FHyiF5Y9SIUIPObNR6oafEqTNs3g/1il6VDLFpd X-Received: by 2002:a63:c942:: with SMTP id y2mr2623852pgg.331.1542218167990; Wed, 14 Nov 2018 09:56:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542218167; cv=none; d=google.com; s=arc-20160816; b=Wxp5iuog2M98hprytHytcroh2n8qvUtnML+PLOB3pLDwFhFYMvKlM0LwVz03Uet5WP dXCQRlww0k8pSv2LvQVlyYqYJfNJ5rkPjBRZfNZixvuPWy+OwKhIdIEX1dJ9KNNHMiDn /9diG0duFXD2ACEBSfiqgi2xrML5yiDNPAykEQydSw7DjjBMx2n6E3xeIKUkvbJo1Iyi I8Foyn2ncyFo1kYVdKRk2fvw9VFkMwR7attxXW0FyR0OXeSwWMiyYQyGXu3LVlsS7Izb IHTYUTXCkCxrz+mOC1NtMNk86WJvFV1hWe7ubu+9J8xY3orIaVwCJzuluBncSD2s2/ox fDhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=y5+MZn1DLLZ77dFsQDhm0oDAc8e59ns2BiFEM+0UUsQ=; b=zdaC2+yJjU71eKajrw0YdeQ2Vf1xYjYPA7D58djT6XpcZMnz5XT/Gl4UKQEJXgbQTG CPuyykSZA5Tn0k9jfFRGL1IPoHIrjm3JaVwDhcuz5yPf67SiJPaKiuNkLzm0sCfqfAA9 p5qPXpqEk1djoUqXRPucgRN86JqLT3YRo9+7GceC3+DAFUO1Mkeav7kn8fKuvB/Xs5Nh 9+y6raxwTpMstcC2GKssGFXPLWn+3+iYREiaOcKzhYdlnumiKk1z3R6OoLsW+sbpHpKN nAZPUKvLNcFrD17gcBNx1Z7Ox1YrnpSeQNyUYbG5DYzfEpUwFeDnh687WSMn/onre8TQ zlxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ML1/RI8+"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g12-v6si24801909pla.351.2018.11.14.09.56.07; Wed, 14 Nov 2018 09:56:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ML1/RI8+"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387568AbeKOEAQ (ORCPT + 32 others); Wed, 14 Nov 2018 23:00:16 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:42552 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732950AbeKOEAP (ORCPT ); Wed, 14 Nov 2018 23:00:15 -0500 Received: by mail-pf1-f196.google.com with SMTP id 64so3808126pfr.9 for ; Wed, 14 Nov 2018 09:56:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=y5+MZn1DLLZ77dFsQDhm0oDAc8e59ns2BiFEM+0UUsQ=; b=ML1/RI8+lYgh8Lfbu5JQi/zaKuBY8GRTmrtpTLQ3eqqnjJGfyDNJ4ny/6/e6aNYtTF jbCMPs80U71EVjWOc/3PeyqPP/va0oh8Tb7gsIP9FeEO4svIb+21EpfBGNQn1a5vq3d4 seANI8GpvQBuJESY+0dGsY4LyJy7jrQlFrh2w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=y5+MZn1DLLZ77dFsQDhm0oDAc8e59ns2BiFEM+0UUsQ=; b=sk5Tm0Y4jb89KrfuNTkT6MXE8myqJBbQV/4LX4YLEaq41vOTbro0osJzRzEQJyA8vP ek5HsN/LtIEviuP9bcirvLtZk+RupSM9RzbL6PlpmPnkRvL6KiBqzf1nZhCyq9zKwfqm DozFS9CE/8r5RskBPqXWs41EnpHzu4lJsqa2+OMqlNXqxJygizm10G+d/QgIUa4A3z2Y hrnNN6znlbgm2cmWROEskoJlZAPLT0tqpT6bDurTdbz5mIWtXUNqkQnFPLP0ASXEdmrS 1DmjpEHHi3rmVoEushLpllCTZVMwFEUpK5KSZbJ89Tp8VO6ZY8WGsg+K1SFeHxxitEBK MV4g== X-Gm-Message-State: AGRZ1gJnJ9+AkkMfP+KJCfAziGDPtEqOqE2z3kKKRn5viHP2RoBkHPpM 6eUx0qLl/6fMJAbGcisn5zw4ug== X-Received: by 2002:a63:8b4b:: with SMTP id j72mr2669319pge.126.1542218164233; Wed, 14 Nov 2018 09:56:04 -0800 (PST) Received: from mba13.psav.com ([64.114.255.97]) by smtp.gmail.com with ESMTPSA id i2-v6sm21301738pgq.35.2018.11.14.09.56.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 09:56:03 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org Subject: [PATCH 5/5] efi: permit calling efi_mem_reserve_persistent from atomic context Date: Wed, 14 Nov 2018 09:55:44 -0800 Message-Id: <20181114175544.12860-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181114175544.12860-1-ard.biesheuvel@linaro.org> References: <20181114175544.12860-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, efi_mem_reserve_persistent() may not be called from atomic context, since both the kmalloc() call and the memremap() call may sleep. 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. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efi.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) -- 2.17.1 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 72a4da76d274..fad7c62cfc0e 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -967,36 +967,43 @@ bool efi_is_table_address(unsigned long phys_addr) } static DEFINE_SPINLOCK(efi_mem_reserve_persistent_lock); +static struct linux_efi_memreserve *efi_memreserve_root __ro_after_init; int efi_mem_reserve_persistent(phys_addr_t addr, u64 size) { - struct linux_efi_memreserve *rsv, *parent; + struct linux_efi_memreserve *rsv; - if (efi.mem_reserve == EFI_INVALID_TABLE_ADDR) + if (!efi_memreserve_root) return -ENODEV; - rsv = kmalloc(sizeof(*rsv), GFP_KERNEL); + rsv = kmalloc(sizeof(*rsv), GFP_ATOMIC); if (!rsv) return -ENOMEM; - parent = memremap(efi.mem_reserve, sizeof(*rsv), MEMREMAP_WB); - if (!parent) { - kfree(rsv); - return -ENOMEM; - } - rsv->base = addr; rsv->size = size; spin_lock(&efi_mem_reserve_persistent_lock); - rsv->next = parent->next; - parent->next = __pa(rsv); + rsv->next = efi_memreserve_root->next; + efi_memreserve_root->next = __pa(rsv); spin_unlock(&efi_mem_reserve_persistent_lock); - memunmap(parent); + return 0; +} +static int __init efi_memreserve_root_init(void) +{ + if (efi.mem_reserve == EFI_INVALID_TABLE_ADDR) + return -ENODEV; + + efi_memreserve_root = memremap(efi.mem_reserve, + sizeof(*efi_memreserve_root), + MEMREMAP_WB); + if (!efi_memreserve_root) + return -ENOMEM; return 0; } +early_initcall(efi_memreserve_root_init); #ifdef CONFIG_KEXEC static int update_efi_random_seed(struct notifier_block *nb,