From patchwork Wed Apr 25 06:26:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 10361737 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DE645601D3 for ; Wed, 25 Apr 2018 06:31:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD36128DE8 for ; Wed, 25 Apr 2018 06:31:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C12E328ECE; Wed, 25 Apr 2018 06:31:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3187D28DE8 for ; Wed, 25 Apr 2018 06:31:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=bxNQTOPLH9cDpUi09KD6ECQYEn9jIeIh5jtGZL8ZUVo=; b=ZlPpwmEcsXqsWkHIn4P9R4PVCD CRzYlanE6dZP6/aSBvNrwji+iNiWz1ZxJYzRRu/Z9A6UE5pJg6G2mZyxvnvMOTeGRNfxgjXjk76Jb gRSfx8C330CqEEdELlyw1mnUVk6BYU58fqrHOOcSXvTYW+AzM1PVxbG76z3l/hWwyhxj7j366W31n 8pIZSEMt2qezgp2fChlTmzSu9+mtjlZmi2fk0m56Pe6jW69uv8qjB/lD+wfxuwSwCfmUbdOJj+kXz v5+hWjC5eqVhgwY4Y1pQ32vF/UumIteAHUkQO6x2Ugau4FhTuqqccKvMI/zTxmfk3RHa6/jsLEPT6 COTrbnRQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fBDxg-000134-MF; Wed, 25 Apr 2018 06:31:28 +0000 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fBDte-0006Mf-Qo for linux-arm-kernel@lists.infradead.org; Wed, 25 Apr 2018 06:27:21 +0000 Received: by mail-pg0-x243.google.com with SMTP id f132so12596251pgc.10 for ; Tue, 24 Apr 2018 23:27:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BGy/B2xlXyJiO0NTOmJQQedzIhM7vraX1PekUsLXCUk=; b=OimhlRjXJaVorW8wcmYBqSqFfwpgYs9cubMILUJkitObDkCi2NXpNZOtnjfbsl47Uc 8Q5EoUrZ44L8RcluE8prTfKaD6qtBkaJUVgd4+RpKnYumkknU83Y/Ik8eT3dAcnJ96cU 5SalaoZ6evwxdCr8igU7hyvyJ6fBXAWv/MQNw= 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:in-reply-to :references; bh=BGy/B2xlXyJiO0NTOmJQQedzIhM7vraX1PekUsLXCUk=; b=h0DK+1pR38Yk2q65mx6NNTQPd+oIswrvDa65x1OhlfFD/kfFTzrszIGX1KkeXnicY6 3slWdzTved8OwnUrK4pxglzSB9cSYwE5UkIdSN8xGMZIiQLlKF/66EuJ2GAmto+5WNfj /ijfLb3NOaYetOu28lkpl858EnTkSunJh7R7bJNuPzZxS9OEeSc1vpGwBlF8s4xhPK3P qCgizK2me/viY7HdirsT9VC/v8DLaqlh/1F5DjVC7XwcaTpjMBSDsr3jWzAxPtbkTgoW uesq2d3oBqFw3a17U1jjc0GzfEhWDONpEZ0f23ATlbJPKNyMBHBeocfGPI5h51MCQVst 1RMA== X-Gm-Message-State: ALQs6tCC0T8b7SESrWGCB1qD025pF5VHtjJ/B4O2N/a7aG7DkOwHecRT lGt5R3ED6KPzDfldKARhwjIriQ== X-Google-Smtp-Source: AIpwx49OX+AY0PZySovV+pQR9LgduoWw20+sBe2Tit+HuUgmwnlWy6nVqZzrWMlL0Fb+fpSEe74tdg== X-Received: by 10.98.237.17 with SMTP id u17mr26719524pfh.78.1524637627702; Tue, 24 Apr 2018 23:27:07 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id z16sm27906062pfn.101.2018.04.24.23.27.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 23:27:07 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de Subject: [PATCH v9 04/11] arm64: kexec_file: allocate memory walking through memblock list Date: Wed, 25 Apr 2018 15:26:22 +0900 Message-Id: <20180425062629.29404-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425062629.29404-1-takahiro.akashi@linaro.org> References: <20180425062629.29404-1-takahiro.akashi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180424_232718_919380_B3981F48 X-CRM114-Status: GOOD ( 15.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro , james.morse@arm.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We need to prevent firmware-reserved memory regions, particularly EFI memory map as well as ACPI tables, from being corrupted by loading kernel/initrd (or other kexec buffers). We also want to support memory allocation in top-down manner in addition to default bottom-up. So let's have arm64 specific arch_kexec_walk_mem() which will search for available memory ranges in usable memblock list, i.e. !NOMAP & !reserved, instead of system resource tree. Signed-off-by: AKASHI Takahiro Cc: Catalin Marinas Cc: Will Deacon Reviewed-by: James Morse --- arch/arm64/kernel/Makefile | 3 +- arch/arm64/kernel/machine_kexec_file.c | 57 ++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/machine_kexec_file.c diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index bf825f38d206..2f2b2757ae7a 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -48,8 +48,9 @@ arm64-obj-$(CONFIG_ARM64_ACPI_PARKING_PROTOCOL) += acpi_parking_protocol.o arm64-obj-$(CONFIG_PARAVIRT) += paravirt.o arm64-obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o arm64-obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o -arm64-obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o \ +arm64-obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ cpu-reset.o +arm64-obj-$(CONFIG_KEXEC_FILE) += machine_kexec_file.o arm64-obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o arm64-obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c new file mode 100644 index 000000000000..f9ebf54ca247 --- /dev/null +++ b/arch/arm64/kernel/machine_kexec_file.c @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * kexec_file for arm64 + * + * Copyright (C) 2018 Linaro Limited + * Author: AKASHI Takahiro + * + * Most code is derived from arm64 port of kexec-tools + */ + +#define pr_fmt(fmt) "kexec_file: " fmt + +#include +#include +#include +#include + +int arch_kexec_walk_mem(struct kexec_buf *kbuf, + int (*func)(struct resource *, void *)) +{ + phys_addr_t start, end; + struct resource res; + u64 i; + int ret = 0; + + if (kbuf->image->type == KEXEC_TYPE_CRASH) + return func(&crashk_res, kbuf); + + if (kbuf->top_down) + for_each_mem_range_rev(i, &memblock.memory, &memblock.reserved, + NUMA_NO_NODE, MEMBLOCK_NONE, + &start, &end, NULL) { + if (!memblock_is_map_memory(start)) + continue; + + res.start = start; + res.end = end; + ret = func(&res, kbuf); + if (ret) + break; + } + else + for_each_mem_range(i, &memblock.memory, &memblock.reserved, + NUMA_NO_NODE, MEMBLOCK_NONE, + &start, &end, NULL) { + if (!memblock_is_map_memory(start)) + continue; + + res.start = start; + res.end = end; + ret = func(&res, kbuf); + if (ret) + break; + } + + return ret; +}