Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13476576ybl; Sun, 29 Dec 2019 12:50:11 -0800 (PST) X-Google-Smtp-Source: APXvYqzzfgCTfCDsPTERWa5ubDc2rNecHUnAjvVKejpSPPfucLTMkcooUkD1hDnBI30sOdA4B8Ms X-Received: by 2002:a9d:6d8f:: with SMTP id x15mr62162684otp.322.1577652611720; Sun, 29 Dec 2019 12:50:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577652611; cv=none; d=google.com; s=arc-20160816; b=ISomYXAyNztK36YDkVTIEYrjWIa/Ft4usnsgCs9MeCsZ1rCxzLR0sup+Kfz4RdixGV dlG0+aF9/Z+afKdVYvDyHivS7QBjWBtcvJEsh9XRyVqdxlJAbGWiiXCnBhE6qTA7vM1m cMOIHoeARhyKyvYOd+5yeFXT51qNgp48NX3Zta0bWe/qKHrOeNqYREODyVEqvDXXTkqT FN/XnyZ0EU4OhEFvNdNMlRBSYBNTnI38nVRfI/l+GZ1LTepW4m+oj4Dw0Q21sVMf1Bjm 7s5jrb1VKIIbftyaB1I5GwHCJv2tDvHH0H9HUK75nXvJj3inxRgy4r1HkVQHWMFDVbDZ BoWw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=T13RhV1l5Y6T063RFz3l1eIXmHHQEVzs347+gD6FeiE=; b=riZ7XRsMsSSKC5Q1radlL2rD19ybzkKQWrvTYChQrgRr339F8dVecYotbIoHYbaHUJ KJ5TOPq8VY8pYnOaGVqQcGsy7DclKh6Ch71DYrlN3tVpjjm9gG/uM+plcq4T2TjMSJuU PUmdtH+HoY2GMQEwj5XK+McmwmMVJFBQUfP7I6UpM1GRpOPAmhtuxmJNplTGIdJ3ZMQm AKNbFszNHZqudqIZj5XE9ZPLgU85Wg4Hy2RjGs7yhcWPvFrovp7tkAICyoHLDbV4fqt0 7uIThV0XBdyogUBrCSFgHC3oGUlTyb/e+bBVLZZT7TNaI7e0InteGOuk+m5WXYrbtLEq 7O/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KpCXkdp7; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r4si354222otq.188.2019.12.29.12.50.00; Sun, 29 Dec 2019 12:50:11 -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=@kernel.org header.s=default header.b=KpCXkdp7; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733189AbfL2R5G (ORCPT + 99 others); Sun, 29 Dec 2019 12:57:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:47178 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733176AbfL2R5E (ORCPT ); Sun, 29 Dec 2019 12:57:04 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 95932206A4; Sun, 29 Dec 2019 17:57:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577642223; bh=CtXnZ4O/bMRkIkPF8BOSiIRqPkqxfuL3zIobpbcfuic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KpCXkdp7ntM8lDA4w4Qp68uoMLMcILcBFbl3ceFKfiFOQJ7SSTXYXjzp5UHnh2DcF D1VrXEcX+/gNK9GjWrn8QjbJu3xZIrnr2ZXoC6zJrld8GwVyjXn473nSotNa7+QrMY jzVfokKZVw1uTVG+RdVDFyIAwonVL3PIX1jQ3MlQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masayoshi Mizuma , Bhupesh Sharma , Ard Biesheuvel , Andy Shevchenko , Arvind Sankar , linux-efi@vger.kernel.org, Ingo Molnar Subject: [PATCH 5.4 393/434] efi/memreserve: Register reservations as reserved in /proc/iomem Date: Sun, 29 Dec 2019 18:27:26 +0100 Message-Id: <20191229172728.441663267@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229172702.393141737@linuxfoundation.org> References: <20191229172702.393141737@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel commit ab0eb16205b43ece4c78e2259e681ff3d645ea66 upstream. Memory regions that are reserved using efi_mem_reserve_persistent() are recorded in a special EFI config table which survives kexec, allowing the incoming kernel to honour them as well. However, such reservations are not visible in /proc/iomem, and so the kexec tools that load the incoming kernel and its initrd into memory may overwrite these reserved regions before the incoming kernel has a chance to reserve them from further use. Address this problem by adding these reservations to /proc/iomem as they are created. Note that reservations that are inherited from a previous kernel are memblock_reserve()'d early on, so they are already visible in /proc/iomem. Tested-by: Masayoshi Mizuma Tested-by: Bhupesh Sharma Signed-off-by: Ard Biesheuvel Reviewed-by: Bhupesh Sharma Cc: # v5.4+ Cc: Andy Shevchenko Cc: Arvind Sankar Cc: linux-efi@vger.kernel.org Link: https://lkml.kernel.org/r/20191206165542.31469-2-ardb@kernel.org Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- drivers/firmware/efi/efi.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -970,6 +970,24 @@ static int __init efi_memreserve_map_roo return 0; } +static int efi_mem_reserve_iomem(phys_addr_t addr, u64 size) +{ + struct resource *res, *parent; + + res = kzalloc(sizeof(struct resource), GFP_ATOMIC); + if (!res) + return -ENOMEM; + + res->name = "reserved"; + res->flags = IORESOURCE_MEM; + res->start = addr; + res->end = addr + size - 1; + + /* we expect a conflict with a 'System RAM' region */ + parent = request_resource_conflict(&iomem_resource, res); + return parent ? request_resource(parent, res) : 0; +} + int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size) { struct linux_efi_memreserve *rsv; @@ -994,7 +1012,7 @@ int __ref efi_mem_reserve_persistent(phy rsv->entry[index].size = size; memunmap(rsv); - return 0; + return efi_mem_reserve_iomem(addr, size); } memunmap(rsv); } @@ -1004,6 +1022,12 @@ int __ref efi_mem_reserve_persistent(phy if (!rsv) return -ENOMEM; + rc = efi_mem_reserve_iomem(__pa(rsv), SZ_4K); + if (rc) { + free_page((unsigned long)rsv); + return rc; + } + /* * The memremap() call above assumes that a linux_efi_memreserve entry * never crosses a page boundary, so let's ensure that this remains true @@ -1020,7 +1044,7 @@ int __ref efi_mem_reserve_persistent(phy efi_memreserve_root->next = __pa(rsv); spin_unlock(&efi_mem_reserve_persistent_lock); - return 0; + return efi_mem_reserve_iomem(addr, size); } static int __init efi_memreserve_root_init(void)