From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A598EC433ED for ; Thu, 29 Apr 2021 13:37:40 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 025166144E for ; Thu, 29 Apr 2021 13:37:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 025166144E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=gqQ4ckYSUeICqxoCLQI/ngN4NsAyDgd6ujsYXxnrcRo=; b=SgoPo722yQpCtlgBfZEtIUxsh ikljU7u//a5NfuEZk16UrhNUjWPpDcxFlj0Se54Mp4TCeLNQzCfTAE4acvNKABsycvam4JUENGK77 R/Ah98lYPmFy8AXE7IiWnvwr9Zt9bSuyZMFrAZ34C4gS2qPbNQFhmeqxmcs9P2OgisKMUtj2bvINX AIzd7/OwZc1fvIA+eC41qHMEwwjL2FgBSiOm+HvP71NIWg4yjGZNSZpg/mQinLIITPHOy90G3lqeM wnqfcejgg7SNQTCUXermMRtenLB7ZN+CKKy++ANe4YaQxISl2jqeqHywbpHGoTcPegzH1rOk0Khj+ Hmy2Mznqw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lc6pp-005hqr-TJ; Thu, 29 Apr 2021 13:36:06 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lc6pY-005hpV-9U; Thu, 29 Apr 2021 13:35:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=l0k/zDIC42/Lu8oBFm7LaM60lzz/X6UmBf61UJ+9KnQ=; b=akGIwQsso6f9wyUXr1gGMPOgP1 5rX/nnPCn4p4XtaB1wkfkNL1PJzVkFj1lVhnmp8jzocaLqg1M1tFpMH0+gOur7n5i4boPISvhyRa2 NblV5Q5khyIk1cmnrRRqY+ZBUXEhdwd+j+wIZMNMB86hgkPIjzvJmqg0glLYOVpWH4uM2QpmvqJu3 StP3brJWwx3Bd9/yMveWDCoQn4PsMyy7oBUi1ewMHQe9CV8eFOmcTWI/kmSV+Ep/Y1iM5+BHydBZo +s2wecjePW8VVFVhwLPkaVguxtFz1dCvSvVxveQ182rC/XKK6ePxi6bVrwDIwa5r07mHHZzlqLcnN 6hq+ILJQ==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lc6pV-000eiU-PZ; Thu, 29 Apr 2021 13:35:47 +0000 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (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 2055961445; Thu, 29 Apr 2021 13:35:45 +0000 (UTC) Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1lc6pT-00A21L-9h; Thu, 29 Apr 2021 14:35:43 +0100 From: Marc Zyngier To: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org Cc: Catalin Marinas , Will Deacon , Ard Biesheuvel , Mark Rutland , James Morse , Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , Eric Biederman , Bhupesh Sharma , AKASHI Takahiro , kernel-team@android.com Subject: [PATCH 1/2] firmware/efi: Tell memblock about EFI reservations Date: Thu, 29 Apr 2021 14:35:32 +0100 Message-Id: <20210429133533.1750721-2-maz@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210429133533.1750721-1-maz@kernel.org> References: <20210429133533.1750721-1-maz@kernel.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, will@kernel.org, ardb@kernel.org, mark.rutland@arm.com, james.morse@arm.com, lorenzo.pieralisi@arm.com, guohanjun@huawei.com, sudeep.holla@arm.com, ebiederm@xmission.com, bhsharma@redhat.com, takahiro.akashi@linaro.org, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210429_063545_916945_3F5205B5 X-CRM114-Status: GOOD ( 17.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org kexec_load_file() relies on the memblock infrastructure to avoid stamping over regions of memory that are essential to the survival of the system. However, nobody seems to agree how to flag these regions as reserved, and (for example) EFI only publishes its reservations in /proc/iomem for the benefit of the traditional, userspace based kexec tool. On arm64 platforms with GICv3, this can result in the payload being placed at the location of the LPI tables. Shock, horror! Let's augment the EFI reservation code with a memblock_reserve() call, protecting our dear tables from the secondary kernel invasion. At some point, someone will have to go and figure out a way to unify these multiple reservation trees, because sprinkling random reservation calls is only a temporary workaround. Signed-off-by: Marc Zyngier --- drivers/firmware/efi/efi.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 4b7ee3fa9224..026b02f5f7d8 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -896,11 +896,25 @@ static int __init efi_memreserve_map_root(void) static int efi_mem_reserve_iomem(phys_addr_t addr, u64 size) { struct resource *res, *parent; + int ret; res = kzalloc(sizeof(struct resource), GFP_ATOMIC); if (!res) return -ENOMEM; + /* + * Given that efi_mem_reserve_iomem() can be called at any + * time, only call memblock_reserve() if the architecture + * keeps the infrastructure around. + */ + if (IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK)) { + ret = memblock_reserve(addr, size); + if (ret) { + kfree(res); + return ret; + } + } + res->name = "reserved"; res->flags = IORESOURCE_MEM; res->start = addr; @@ -908,7 +922,14 @@ static int efi_mem_reserve_iomem(phys_addr_t addr, u64 size) /* we expect a conflict with a 'System RAM' region */ parent = request_resource_conflict(&iomem_resource, res); - return parent ? request_resource(parent, res) : 0; + ret = parent ? request_resource(parent, res) : 0; + if (ret) { + kfree(res); + if (IS_ENABLED(CONFIG_ARCH_KEEP_MEMBLOCK)) + memblock_free(addr, size); + } + + return ret; } int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size) -- 2.29.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel