From patchwork Thu Nov 8 18:05:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10674795 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1745214E2 for ; Thu, 8 Nov 2018 18:05:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A4572DB8C for ; Thu, 8 Nov 2018 18:05:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F2C912DDD9; Thu, 8 Nov 2018 18:05:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 754972DC2E for ; Thu, 8 Nov 2018 18:05:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 88E446B0628; Thu, 8 Nov 2018 13:05:19 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 83C646B062A; Thu, 8 Nov 2018 13:05:19 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 754526B062B; Thu, 8 Nov 2018 13:05:19 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by kanga.kvack.org (Postfix) with ESMTP id 2053B6B0628 for ; Thu, 8 Nov 2018 13:05:19 -0500 (EST) Received: by mail-wr1-f69.google.com with SMTP id c16-v6so18693463wrr.8 for ; Thu, 08 Nov 2018 10:05:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:mime-version:content-transfer-encoding; bh=PfIX9iEACWNMz8bi3SaGHe0/ZcpEQEQ5sjogqCaKPQc=; b=lYKv/BnNKF0I1soUcWQz5Qcxvq3PykPRS5fZbpmKyrm0ylWdIDgsKcEhXDaJa8FRSQ 5+SZcRxIcccCENoUzkpxhT0NV0f22evmu5/IwuKzKl1ujolj0/Ky4AsD0jkXQ5zjAEu3 dBsqOWkciBZEqBUWOi32omADRmFp3AMJOkeauCqz5nh0GGR4I1GY6EjHrLAh8uD4pD6U vCgi8WhPVpg4v3kCK3SLg+/X4W4pwV/6NEeTfziUWmQ/CtYooNPM5gkP99FW/nXg8DkQ FyZR8EWdaWV6DcBaylTbLLaSgueTId+hYkhMtyNz8z+g23gSCdNZyL2nLtVQ69zJKwf+ OpYQ== X-Gm-Message-State: AGRZ1gIfuNMiIG+7DAqQUHLj5sr+LT/M+r4yIHpKjXnkPyZxezGahaIa eMQnCuzHJv4+pRGrhdw7UIQl+Ec2ocT+YH4K7jC8oAyAvAkxSUluN/izZBwFfHRU8MLr7BFwHY1 Fv8ml0proI+mPYm54gy1tgtw2pIWEU0i70VhSQVowe8N85v6yUhoZXiRtVB+oS3HAlqGSmMRzl3 HfSu7WLOJXw6FK10D+tEEzrxBOuXK/sevWrq0KtQg3vkukgTEELuraYDeFrxldRRgWo3K+hnNeb DxyO/zOGzFqFRpfJ6QbO9+TIMOKm+zSRTg+iL0fh1pytm/uFa5oQlJMn4xPcJg9D+MeqP1A3pU6 HQ/+QpxI9sWs84amceKM8ZI7g9NMcJMrVIUnO4GUsHNXsR3gz6R4IZb2JNsiQhYK8Hy3AVFyvRR + X-Received: by 2002:a1c:8c8c:: with SMTP id o134-v6mr2052789wmd.35.1541700318628; Thu, 08 Nov 2018 10:05:18 -0800 (PST) X-Received: by 2002:a1c:8c8c:: with SMTP id o134-v6mr2052745wmd.35.1541700317845; Thu, 08 Nov 2018 10:05:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541700317; cv=none; d=google.com; s=arc-20160816; b=CcmAkUzZhZAJ6VSMZ6q21Hm5KAExU69V339B+2R/63RceyRN2dOJQ60w1neiDDxVxT S/VrFWyfyrcVpzHAW9at2DAHgxz9lPYAjIvMiQhnIbyjpkZ4wmXPPqh7pMWPZyoGa+Lo td3FFNoj0Lrc+mO3cAbDQ3CIRzQMX5n+2YQh1GJb00Ti0HG1AXFEQXoOKrve3MENQFZI oYkzYsrnsOrp1kobWSDSb9M5Ui8AiaEwoW/pxn+WVLbWfPdSIiz1iFJRrmDdqL+m0mUh h93sk3ZC+2UQ81AK4wwjME9tjo7dGuC6NQUGQcWWodQSKqOEbtfmRbHnnBSLKD3heK/A GyhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=PfIX9iEACWNMz8bi3SaGHe0/ZcpEQEQ5sjogqCaKPQc=; b=bc2ASwKGIfDjG8GCQoJcbutIhsqd7LF0o4b3F32bY0mqgHR322c55w9g4d5Ofl8b00 q6XVmragdl0fuJFj1byGCW5khd1am/XqLe6oJRriHXD7u2fCjd6s6a+VzGkH7KIBOZUz VWVML/25MaWaSqOqwQz6sQSodSPhXXq37qGm/hygcOLsPVIYLRXWRgw/f0Pn2EmmYOjF ceHJTXQCk016LifMUPo3W7BqeMm79E7/Tqfqj0O8XrsQjlRbGybHwVgURM9P+u8Um0g5 +UUAudvBq5E0T6LGAxn06M+if05w0nSuY/2pfdcfJYxWoSQDYZAuZJt61NLSQR3m0/Tp sTuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Yip7eRnO; spf=pass (google.com: domain of ard.biesheuvel@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ard.biesheuvel@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id j20-v6sor3029732wrd.49.2018.11.08.10.05.17 for (Google Transport Security); Thu, 08 Nov 2018 10:05:17 -0800 (PST) Received-SPF: pass (google.com: domain of ard.biesheuvel@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Yip7eRnO; spf=pass (google.com: domain of ard.biesheuvel@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ard.biesheuvel@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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-Smtp-Source: AJdET5cZah7SML2Xhfux1z2lM4JXvHVCmTcuUx1MQnsF4mO0XIolwML3ZHaZJoNp68f6R7TaybXiAA== 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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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,