From patchwork Tue Nov 20 19:16:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 151614 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp996568ljp; Tue, 20 Nov 2018 11:16:43 -0800 (PST) X-Google-Smtp-Source: AFSGD/UBTf3LJq1LvYrSi6+hppd2sTReLyc7W6905PrKBI0Z8svrXKaZWfJAEVqpsWQj1MQBqLr/ X-Received: by 2002:a63:2054:: with SMTP id r20mr3028340pgm.328.1542741403674; Tue, 20 Nov 2018 11:16:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542741403; cv=none; d=google.com; s=arc-20160816; b=xow4oSyibM1EFIKNEPQrfaRSeAwcy8p2i3X+1rFL7Jr7rmSp1PPu16Z4rHdUx6EKcn CcZt0uWvPdwXyVDUUQyq4xILkCCpMHIkF75DSZE+a/kz5hzeSRSFiS/9Y6K1kf618wPN 4d1XtgM+IG2OmxgdEIRnVF/9nO5b6Bywf6ilGP2FDuCGyn7/8BjctEjMC9bttq6V6muA ttHe15ncgFJkBGFSZGYwKpSJl61n9q7es0AfjH9/gUULv8bncB9GvrHjxyrfWEkAqwBL mV7fryBOidRlFWc5ZYk0H95ioH0V1BW6Rj+EfW9Z1qY6L97PUzlyselkwy1/9I04O1gQ NsQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=uccvkBgiBgMWg+wRsgVoOX/QRDRZoIfKZEK3tlNIlYk=; b=jxJu5VjAtlquVN7/Dqi2/vvbgqW/uxwedi0cWLIhpqtmvp/djHF/wdeTcTbJhmw5kk jjueMrJb98kwKURD7LblV5n8TbmMQjFVwLoPzF8ikAx/RDiOHF1bM5CnErmGzIiWja0e APunl68KhpP/qjX9EJwNC3/vMYdwnpvSUtLmfbp9RBoQlbR0qgJG9kUytbZDC7yStyYS 4JQbHJRkfwJPOs9M+DrKyE7udL2lbknBbilRYxCstKraW7UZplMLN94kQoBJ9aSCQY/F +JCHXy9Hv9f7vUceCKzSpQB1W/CZN8MjcoX1WHsvQUX5gxJY9QAh27gsWjm3EMTSMgI4 ZCxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Rgzqp1ct; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-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 m3si43745603pgs.8.2018.11.20.11.16.43; Tue, 20 Nov 2018 11:16:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-efi-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=Rgzqp1ct; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-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 S1726105AbeKUFrY (ORCPT + 3 others); Wed, 21 Nov 2018 00:47:24 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:42544 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725913AbeKUFrY (ORCPT ); Wed, 21 Nov 2018 00:47:24 -0500 Received: by mail-ed1-f66.google.com with SMTP id j6so2886208edp.9 for ; Tue, 20 Nov 2018 11:16:41 -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; bh=uccvkBgiBgMWg+wRsgVoOX/QRDRZoIfKZEK3tlNIlYk=; b=Rgzqp1ctsTIi68m+JerU2mHUYZk927BS7/hTDT2BhPDEvlTMBGK9l7USyf8xeEsR2f Sz2P74FleVTtUcou3g83Jd081bMXTfmEctCaeMnKhUUcR+YglVGhPGSHFeKdtet84BS9 qTJzqbTe53WM0usBYShU2CZ4mlmdezHier1kE= 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; bh=uccvkBgiBgMWg+wRsgVoOX/QRDRZoIfKZEK3tlNIlYk=; b=YNKtp2tk1d4amw+GYXKslPSehTWKyvfgtDcVR2BonT+4SeoSUfqF33bVTrzDaxIgTh T1HmH2FnNbYyBXhhvM7V3D+0VK2yBVohflSfLeJ3ag8dIP4bEApYVfIu5xZ3pTRJTkzF 5TRg7Ki0Tyns0SMd38RUVqxsveZTr1N3uWFzqnVqNmjBzDy2adSkAMZUQh1IyNon9IMP wRMGMHrozUBX8k6XJdZpN1i0LK5T8veB+7CPvNNi59W/OkKYH+BXHBONeXHJ030fGynZ fSMfE55cMS8wPuO1t7ysbghIKGBquQx2q+01LFn6zcGG9X2TTUCKca/fzhRY/H72d77j WORA== X-Gm-Message-State: AGRZ1gKxg3AARCGcQgwWstiTf794HBNLA7PwJYuPTkILk4jqd5+N3mqh PsRCNLam89TMuMmTSDhuvOupFLa555EPfQ== X-Received: by 2002:a17:906:7692:: with SMTP id o18-v6mr2864760ejm.63.1542741400654; Tue, 20 Nov 2018 11:16:40 -0800 (PST) Received: from mba13.wifi.ns.nl (dhcp-077-251-017-237.chello.nl. [77.251.17.237]) by smtp.gmail.com with ESMTPSA id l18sm40184edq.87.2018.11.20.11.16.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 11:16:39 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, marc.zyngier@arm.com, Jan.Glauber@cavium.com, john.garry@huawei.com, Ard Biesheuvel Subject: [RFT PATCH v2] efi: map memreserve table before first use Date: Tue, 20 Nov 2018 20:16:34 +0100 Message-Id: <20181120191634.7376-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Mapping the MEMRESERVE EFI configuration table from an early initcall is too late: the GICv3 ITS code that creates persistent reservations for the boot CPU's LPI tables is invoked from init_IRQ(), which runs much earlier than the handling of the initcalls. So instead, move the initialization performed by the initcall into efi_mem_reserve_persistent() itself, but keep the initcall as well so that the init is guaranteed to have been called before SMP boot. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efi.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) -- 2.17.1 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index fad7c62cfc0e..0e2d52a0c50e 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -969,13 +969,33 @@ 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) +static int __init efi_memreserve_map_root(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 (WARN_ON_ONCE(!efi_memreserve_root)) + return -ENOMEM; + return 0; +} + +int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size) { struct linux_efi_memreserve *rsv; + int rc; - if (!efi_memreserve_root) + if (efi_memreserve_root == (void *)ULONG_MAX) return -ENODEV; + if (!efi_memreserve_root) { + rc = efi_memreserve_map_root(); + if (rc) + return rc; + } + rsv = kmalloc(sizeof(*rsv), GFP_ATOMIC); if (!rsv) return -ENOMEM; @@ -993,14 +1013,12 @@ int efi_mem_reserve_persistent(phys_addr_t addr, u64 size) static int __init efi_memreserve_root_init(void) { - if (efi.mem_reserve == EFI_INVALID_TABLE_ADDR) - return -ENODEV; + if (efi_memreserve_root) + return 0; - efi_memreserve_root = memremap(efi.mem_reserve, - sizeof(*efi_memreserve_root), - MEMREMAP_WB); + efi_memreserve_map_root(); if (!efi_memreserve_root) - return -ENOMEM; + efi_memreserve_root = (void *)ULONG_MAX; return 0; } early_initcall(efi_memreserve_root_init);