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=-14.7 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 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 E9958C433B4 for ; Thu, 13 May 2021 11:14:18 +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 71E40613CB for ; Thu, 13 May 2021 11:14:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 71E40613CB 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:Subject:Cc:To: From:Message-ID:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=avzmmogoJzwu0zjEO1S3nMXfG8mKN43QFqYliDTQ3wA=; b=rRqTvG2FoGlDuFz3yLl/rwHu1 +2d4pF1dl/bOiS4CQxv1az927ZWy9NuhN8zwx7UItbijhZOi6/Hwf2JckMWK6Unbi1BvtskpkQ8Hb Mwh9iVYqgN3xDhFBWKXvwU7jmr4MZi5DH7X2f6yU1HOKOhZ4Ul9BaOZd+GkrRUEbrAR11FJ3klyQr LJrSY5YgKPpSMRSpWZhjugq8IhlCOPnRO3XSKWijn6HChCEuacfZUezHXOs/RLFh0C9nTIijFZrGL UGQRDIMkjcKQV1nnBHhf8JwGMEB7q7t6erFiTJ9tGFHdk4WKVvcps7ing/0sr6uqlkwD5Z5A2VTb/ IXah3Gx8A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lh9GA-005OfH-S6; Thu, 13 May 2021 11:12:07 +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 1lh9G7-005Oeh-70; Thu, 13 May 2021 11:12:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Type:MIME-Version:References: In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Mm1wxGrRTwmAZG61r6g0nScOFO/HZtHCPBOwdFxfsZI=; b=St02mZk33W7j9tNBONRiJf2P/f d+FR7FXvkj2SDpTYuSpNlgHZEIb5k/5KwR4yuH/3FU8d5lZl7L417lZ6WhPkmxMksnn4ABobChYD2 XbTGcSBlVSlUKT74fS0YoeTS2ORyGgfK6nJzz/MwGA6MpHW6cyzSGQ/eB4A88oHtHsFXoIghufKGt lDx/Yo7ZLW3CFSa49tnqL+A5d0KabySlOJuMiLueIoKCTD0Bu2A/LoU/1qCTztHqn76Mwy6BKzvuY ggQVjxAjtxh/W4U5qtn6Ly6HBOiAlGV6a46ZoHvKRztzJ6UPyMPsCmtkcKIcbf8Z5dFJBj4QNKFsL jLo7OkPQ==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lh9G4-00BCA9-HP; Thu, 13 May 2021 11:12:01 +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 3EEE2613CB; Thu, 13 May 2021 11:12:00 +0000 (UTC) Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1lh9G2-001C0s-DJ; Thu, 13 May 2021 12:11:58 +0100 Date: Thu, 13 May 2021 12:11:57 +0100 Message-ID: <87cztuopky.wl-maz@kernel.org> From: Marc Zyngier To: Dave Young Cc: Moritz Fischer , kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Catalin Marinas , Will Deacon , Ard Biesheuvel , Mark Rutland , James Morse , Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , Eric Biederman , AKASHI Takahiro , kernel-team@android.com Subject: Re: [PATCH 1/2] firmware/efi: Tell memblock about EFI reservations In-Reply-To: <20210513031958.GD45898@dhcp-128-65.nay.redhat.com> References: <20210429133533.1750721-1-maz@kernel.org> <20210429133533.1750721-2-maz@kernel.org> <20210513031958.GD45898@dhcp-128-65.nay.redhat.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: dyoung@redhat.com, mdf@kernel.org, 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, 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-20210513_041200_647954_805D7FD6 X-CRM114-Status: GOOD ( 36.83 ) 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 On Thu, 13 May 2021 04:20:21 +0100, Dave Young wrote: > > On 05/03/21 at 11:56am, Moritz Fischer wrote: > > Marc, > > > > On Thu, Apr 29, 2021 at 02:35:32PM +0100, Marc Zyngier wrote: > > > 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. > > > > > > > Feel free to add (and/or): > > > > Reported-by: Moritz Fischer > > Tested-by: Moritz Fischer > > > 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; > > > + } > > > + } > > > + > > If you go with memblock, it would be better to handle it separately from > the iomem? Do you mean having a separate helper from efi_mem_reserve_iomem()? Sure, can do. > > > > 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; > > It looks odd to free memblock when reqeust resource fails, they are not > relavant? I'm trying to keep the two trees in sync so that when the caller finds out that the reservation has failed, we're not in a half-baked state. But maybe it doesn't really matter, and if a reservation fails, we're already screwed. Ard, what do you think? M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Date: Thu, 13 May 2021 12:11:57 +0100 Message-ID: <87cztuopky.wl-maz@kernel.org> From: Marc Zyngier Subject: Re: [PATCH 1/2] firmware/efi: Tell memblock about EFI reservations In-Reply-To: <20210513031958.GD45898@dhcp-128-65.nay.redhat.com> References: <20210429133533.1750721-1-maz@kernel.org> <20210429133533.1750721-2-maz@kernel.org> <20210513031958.GD45898@dhcp-128-65.nay.redhat.com> MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kexec" Errors-To: kexec-bounces+dwmw2=infradead.org@lists.infradead.org To: Dave Young Cc: Moritz Fischer , kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Catalin Marinas , Will Deacon , Ard Biesheuvel , Mark Rutland , James Morse , Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , Eric Biederman , AKASHI Takahiro , kernel-team@android.com On Thu, 13 May 2021 04:20:21 +0100, Dave Young wrote: > > On 05/03/21 at 11:56am, Moritz Fischer wrote: > > Marc, > > > > On Thu, Apr 29, 2021 at 02:35:32PM +0100, Marc Zyngier wrote: > > > 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. > > > > > > > Feel free to add (and/or): > > > > Reported-by: Moritz Fischer > > Tested-by: Moritz Fischer > > > 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; > > > + } > > > + } > > > + > > If you go with memblock, it would be better to handle it separately from > the iomem? Do you mean having a separate helper from efi_mem_reserve_iomem()? Sure, can do. > > > > 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; > > It looks odd to free memblock when reqeust resource fails, they are not > relavant? I'm trying to keep the two trees in sync so that when the caller finds out that the reservation has failed, we're not in a half-baked state. But maybe it doesn't really matter, and if a reservation fails, we're already screwed. Ard, what do you think? M. -- Without deviation from the norm, progress is not possible. _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec