From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: From: Marc Zyngier Subject: [PATCH v2 5/5] arm64: kexec_image: Restore full kexec functionnality Date: Mon, 31 May 2021 10:57:20 +0100 Message-Id: <20210531095720.77469-6-maz@kernel.org> In-Reply-To: <20210531095720.77469-1-maz@kernel.org> References: <20210531095720.77469-1-maz@kernel.org> MIME-Version: 1.0 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: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Catalin Marinas , Will Deacon , Ard Biesheuvel , Mark Rutland , James Morse , Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , Eric Biederman , Bhupesh SHARMA , AKASHI Takahiro , Dave Young , Andrew Morton , Moritz Fischer , kernel-team@android.com Provide an arm64-specific implementation for arch_kexec_locate_mem_hole(), using the resource tree instead of memblock, and respecting the reservations added by EFI. This ensures that kexec_file is finally reliable. Reported-by: Moritz Fischer Acked-by: Catalin Marinas Reviewed-by: Ard Biesheuvel Signed-off-by: Marc Zyngier --- arch/arm64/kernel/kexec_image.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index acf9cd251307..2a51a2ebd2b7 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -156,12 +156,31 @@ const struct kexec_file_ops kexec_image_ops = { */ int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf) { + int ret; + + /* Arch knows where to place */ + if (kbuf->mem != KEXEC_BUF_MEM_UNKNOWN) + return 0; + /* - * For the time being, kexec_file_load isn't reliable except - * for crash kernel. Say sorry to the user. + * Crash kernels land in a well known place that has been + * reserved upfront. + * + * Normal kexec kernels can however land anywhere in memory. + * We have to be extra careful not to step over critical + * memory ranges that have been marked as reserved in the + * iomem resource tree (LPI and ACPI tables, among others), + * hence the use of the child-excluding iterator. This + * matches what the userspace version of kexec does. */ - if (kbuf->image->type != KEXEC_TYPE_CRASH) - return -EADDRNOTAVAIL; - - return kexec_locate_mem_hole(kbuf); + if (kbuf->image->type == KEXEC_TYPE_CRASH) + ret = walk_iomem_res_desc(crashk_res.desc, + IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY, + crashk_res.start, crashk_res.end, + kbuf, kexec_locate_mem_hole_callback); + else + ret = walk_system_ram_excluding_child_res(0, ULONG_MAX, kbuf, + kexec_locate_mem_hole_callback); + + return ret == 1 ? 0 : -EADDRNOTAVAIL; } -- 2.30.2 _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec 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.4 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 87679C47080 for ; Mon, 31 May 2021 10:01:11 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 5463861220 for ; Mon, 31 May 2021 10:01:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5463861220 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=bombadil.20210309; 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=eStUxGyzLS5bRL8xkwV+Th5Upyg+bhnST5tsU0szQ08=; b=qdbPr20wlKUYqW lBkZxPchWq3GHmgEf7NML1TARoDiA1RcrVF+XUaq/JmwGty+JWyCD4yUJpEyATejyDpMX8Ajzw8AN +LkwFQzrp9O1GfRnE9fR1sY8fn6sYiiFPjdLZ/T0ZznzIi+0oMzsgGWrUtbm8OrT2tmso2Jvwr4qI Zwo0wvJ3URZoywkbuIqCxmB3+PGju8o8oO1SYN6sIeGEUWLlXK+YmGrBJhS08o15c0U/Q10b3rD8u lvgpW1eP2FBzksSJuSURKiZQbhRXf4oRjY+ngeF16IvdVnhvVJYjFNpzm6NeO1EDY3HkR4407qJUz AHm3iRn6Ie1GdLvGBAEQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lnehb-00Bkvd-Kw; Mon, 31 May 2021 09:59:20 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lnegP-00BkS5-97; Mon, 31 May 2021 09:58:06 +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 0376861249; Mon, 31 May 2021 09:58:05 +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.2) (envelope-from ) id 1lnegM-004Z7v-UL; Mon, 31 May 2021 10:58:03 +0100 From: Marc Zyngier To: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Catalin Marinas , Will Deacon , Ard Biesheuvel , Mark Rutland , James Morse , Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , Eric Biederman , Bhupesh SHARMA , AKASHI Takahiro , Dave Young , Andrew Morton , Moritz Fischer , kernel-team@android.com Subject: [PATCH v2 5/5] arm64: kexec_image: Restore full kexec functionnality Date: Mon, 31 May 2021 10:57:20 +0100 Message-Id: <20210531095720.77469-6-maz@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210531095720.77469-1-maz@kernel.org> References: <20210531095720.77469-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, linux-kernel@vger.kernel.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, bhupesh.sharma@linaro.org, takahiro.akashi@linaro.org, dyoung@redhat.com, akpm@linux-foundation.org, mdf@kernel.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-20210531_025805_386612_48C23141 X-CRM114-Status: GOOD ( 18.69 ) 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 Provide an arm64-specific implementation for arch_kexec_locate_mem_hole(), using the resource tree instead of memblock, and respecting the reservations added by EFI. This ensures that kexec_file is finally reliable. Reported-by: Moritz Fischer Acked-by: Catalin Marinas Reviewed-by: Ard Biesheuvel Signed-off-by: Marc Zyngier --- arch/arm64/kernel/kexec_image.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index acf9cd251307..2a51a2ebd2b7 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -156,12 +156,31 @@ const struct kexec_file_ops kexec_image_ops = { */ int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf) { + int ret; + + /* Arch knows where to place */ + if (kbuf->mem != KEXEC_BUF_MEM_UNKNOWN) + return 0; + /* - * For the time being, kexec_file_load isn't reliable except - * for crash kernel. Say sorry to the user. + * Crash kernels land in a well known place that has been + * reserved upfront. + * + * Normal kexec kernels can however land anywhere in memory. + * We have to be extra careful not to step over critical + * memory ranges that have been marked as reserved in the + * iomem resource tree (LPI and ACPI tables, among others), + * hence the use of the child-excluding iterator. This + * matches what the userspace version of kexec does. */ - if (kbuf->image->type != KEXEC_TYPE_CRASH) - return -EADDRNOTAVAIL; - - return kexec_locate_mem_hole(kbuf); + if (kbuf->image->type == KEXEC_TYPE_CRASH) + ret = walk_iomem_res_desc(crashk_res.desc, + IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY, + crashk_res.start, crashk_res.end, + kbuf, kexec_locate_mem_hole_callback); + else + ret = walk_system_ram_excluding_child_res(0, ULONG_MAX, kbuf, + kexec_locate_mem_hole_callback); + + return ret == 1 ? 0 : -EADDRNOTAVAIL; } -- 2.30.2 _______________________________________________ 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: 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.0 required=3.0 tests=BAYES_00,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 2B0DCC4708F for ; Mon, 31 May 2021 09:58:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0868F611EE for ; Mon, 31 May 2021 09:58:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231418AbhEaKAf (ORCPT ); Mon, 31 May 2021 06:00:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:58066 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231407AbhEaJ7o (ORCPT ); Mon, 31 May 2021 05:59:44 -0400 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 0376861249; Mon, 31 May 2021 09:58:05 +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.2) (envelope-from ) id 1lnegM-004Z7v-UL; Mon, 31 May 2021 10:58:03 +0100 From: Marc Zyngier To: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Catalin Marinas , Will Deacon , Ard Biesheuvel , Mark Rutland , James Morse , Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , Eric Biederman , Bhupesh SHARMA , AKASHI Takahiro , Dave Young , Andrew Morton , Moritz Fischer , kernel-team@android.com Subject: [PATCH v2 5/5] arm64: kexec_image: Restore full kexec functionnality Date: Mon, 31 May 2021 10:57:20 +0100 Message-Id: <20210531095720.77469-6-maz@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210531095720.77469-1-maz@kernel.org> References: <20210531095720.77469-1-maz@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.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, bhupesh.sharma@linaro.org, takahiro.akashi@linaro.org, dyoung@redhat.com, akpm@linux-foundation.org, mdf@kernel.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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Provide an arm64-specific implementation for arch_kexec_locate_mem_hole(), using the resource tree instead of memblock, and respecting the reservations added by EFI. This ensures that kexec_file is finally reliable. Reported-by: Moritz Fischer Acked-by: Catalin Marinas Reviewed-by: Ard Biesheuvel Signed-off-by: Marc Zyngier --- arch/arm64/kernel/kexec_image.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/kexec_image.c b/arch/arm64/kernel/kexec_image.c index acf9cd251307..2a51a2ebd2b7 100644 --- a/arch/arm64/kernel/kexec_image.c +++ b/arch/arm64/kernel/kexec_image.c @@ -156,12 +156,31 @@ const struct kexec_file_ops kexec_image_ops = { */ int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf) { + int ret; + + /* Arch knows where to place */ + if (kbuf->mem != KEXEC_BUF_MEM_UNKNOWN) + return 0; + /* - * For the time being, kexec_file_load isn't reliable except - * for crash kernel. Say sorry to the user. + * Crash kernels land in a well known place that has been + * reserved upfront. + * + * Normal kexec kernels can however land anywhere in memory. + * We have to be extra careful not to step over critical + * memory ranges that have been marked as reserved in the + * iomem resource tree (LPI and ACPI tables, among others), + * hence the use of the child-excluding iterator. This + * matches what the userspace version of kexec does. */ - if (kbuf->image->type != KEXEC_TYPE_CRASH) - return -EADDRNOTAVAIL; - - return kexec_locate_mem_hole(kbuf); + if (kbuf->image->type == KEXEC_TYPE_CRASH) + ret = walk_iomem_res_desc(crashk_res.desc, + IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY, + crashk_res.start, crashk_res.end, + kbuf, kexec_locate_mem_hole_callback); + else + ret = walk_system_ram_excluding_child_res(0, ULONG_MAX, kbuf, + kexec_locate_mem_hole_callback); + + return ret == 1 ? 0 : -EADDRNOTAVAIL; } -- 2.30.2