Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp421197imu; Thu, 8 Nov 2018 10:05:59 -0800 (PST) X-Google-Smtp-Source: AJdET5eoa9m0YFvCrCKu1/kHUe/tN7nxq1TxFahNm1mKEQeuL8BLhPaNrRUv88+T1rtXD8i4QdbN X-Received: by 2002:a65:6447:: with SMTP id s7mr4503068pgv.226.1541700359903; Thu, 08 Nov 2018 10:05:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541700359; cv=none; d=google.com; s=arc-20160816; b=CMErRcaS3wN2s3rucnZaSMhK7caySPnSYzrPNfapIdU7ABNEqNc0pW4ok1bktiqkWJ 6dR14BVX+NXnlxL5diQZ1owwl5RXOhHiETpJaHY/BcWydrzTPDcy3V3rtlDEGBok4al5 iksvgeJBe3qsJM+yqQJP2U4GNYTvHAFlFQwr0cmaQx/7/Rw56zsW/PkzLWXi5ix0CLy6 x++uZlvou3Kphp4xZQgx55Ze8lspFpXzYee0SZjOZu5FxZM64zWomci1yWnzMOBohdFp ifgFJHL7UNXZvE9qgNXrKRrcTJHbs/gtsEKbcGEuXeRQvsRzgQottyRw9jwE2S7XwL/R R5bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=PfIX9iEACWNMz8bi3SaGHe0/ZcpEQEQ5sjogqCaKPQc=; b=KJZpUwhH52BahqdL5ElTUtf3fSkKSYzKofTEAd9pMT1q5AXoBhTCwGnZaSz9f1u6JG 2XfXEIU60Zdd9wqAtWuShihQScvZYsHQGeyocLB9p0H4PFBjEwJtt5iLYSMrZH8Byg/9 EYWylqK3ttpnf25HMiDMxp61ti4GaQBnfbsXbboJ/22tQQLRUchUxz+6fIMbV+2eNST3 O1j5RfuLG8TjeSPRJM0xZjQZzwArZ4Fu9QFqxNID3+UaKcuEkfgiwADcSrgKN4sIw3FW VkgEgej4Mz8jq2W12cH2mEXkwGHDCNtmf3GKOCRv7fNPJHW7AzKGWIsjRxdpB/0oUf15 AkeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Yip7eRnO; 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 t2-v6si4712808plz.427.2018.11.08.10.05.44; Thu, 08 Nov 2018 10:05:59 -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=Yip7eRnO; 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 S1727080AbeKIDl6 (ORCPT + 99 others); Thu, 8 Nov 2018 22:41:58 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:39414 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726751AbeKIDl6 (ORCPT ); Thu, 8 Nov 2018 22:41:58 -0500 Received: by mail-wr1-f68.google.com with SMTP id r10-v6so22242672wrv.6 for ; Thu, 08 Nov 2018 10:05:18 -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:mime-version :content-transfer-encoding; bh=PfIX9iEACWNMz8bi3SaGHe0/ZcpEQEQ5sjogqCaKPQc=; b=Yip7eRnOLlLQEF7ZU4z6209Jqz6gMnpNLfInKPLrlZJy9pdV2f2jem15HOEAffxpjN 8A5FmJd9GUhgpCqAeHRhl3ZCWBbXlsCgfnls9ZCL9JgmZfQuaJRRjZN5S/Fnbjdkyqjc PZRwXjg25SinSdQwtKzwSkDqwvWV3Lj4011VU= 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:mime-version :content-transfer-encoding; bh=PfIX9iEACWNMz8bi3SaGHe0/ZcpEQEQ5sjogqCaKPQc=; b=hPowVRuZv87xwImtrflREdC6oJOtl60PdGaNGPeFPqXGMx43Z0/N35VsTwU0mwrX8+ Q+wtnwxakA8Y18LJekWNpFQH14uguevYVmYbT9daK4RSsF8VkesEyooNBrrXVrayXetg 5jm7uvL7uaC+Sr+W0DdtkXSazwMo/o8wIdhvz8Or1mhIGP4ACVVlNNxTg/wSutxQZXns /6sBnwyr74WyQC5CkhYYs57UFmn4Cpxhz+J8kNOm3e75m/+7DDbw5seUYzZFm8Kwh5tl kqhVS1Q2fwz74Cv6udJlsRY8zlprz8gsojMQhldLtIen6QYqvLydTnsvqUOkLp3j9AV+ R0Ew== X-Gm-Message-State: AGRZ1gLTRdxcalRVD1u7NjU4j0zSVaPqnTBbiI8EqGmogx55mdzTXrV/ LOhypEMNEBSvu+lK1ZMFdxePIw== X-Received: by 2002:a5d:4512:: with SMTP id s18-v6mr4893245wrq.86.1541700317376; Thu, 08 Nov 2018 10:05:17 -0800 (PST) Received: from harold.home ([2a01:cb1d:112:6f00:744a:cf78:9aaa:a66d]) by smtp.gmail.com with ESMTPSA id m16-v6sm6792902wmd.35.2018.11.08.10.05.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 10:05:16 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, cai@gmx.us, linux-mm@kvack.org, linux-kernel@vger.kernel.org, marc.zyngier@arm.com, will.deacon@arm.com, Ard Biesheuvel Subject: [PATCH] efi: permit calling efi_mem_reserve_persistent from atomic context Date: Thu, 8 Nov 2018 19:05:11 +0100 Message-Id: <20181108180511.30239-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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(-) 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_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, -- 2.19.1