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,