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: 134235 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp472244lji; Tue, 24 Apr 2018 23:28:57 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/IY+2Wea3aRObzrEM47PL0DaQ1lw0fHkckVL2t+wtH8tOyQ8qdP22OdBCNc3ItJempYu1R X-Received: by 10.101.66.139 with SMTP id j11mr22577047pgp.370.1524637737102; Tue, 24 Apr 2018 23:28:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524637737; cv=none; d=google.com; s=arc-20160816; b=xoBaICqi9//kO47XzRieRR0wETUvdXB+T2h9QIqBukQ3AzPBgRKcx9ss5tzY6oSFtG +J0JuH3I5DfPiIvF5yOfa0tyllCpSJwWs8djp4rKvd/UhuR52gNiAcpjL5cwzEGPbk/C RVL7OouNg8jtZyE7It/pfaIDanXsSvWLCORRLsOF9Ti1dE5KU5PgeAzqsuiSi3O0C0qm C0Qbf0O+hwym8/cHeg9xDwZ4B3M7Mn45J79CUMgsL4itVzJ6Cx6ENTfkFCoCroJtN2Cc wpBWw4UBsbs8RRTKh22hYaE6iTq6/zAmXKD3D/8+rra8kkQrx9BhPHlCtalT/nuKE2Da v5vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=BGy/B2xlXyJiO0NTOmJQQedzIhM7vraX1PekUsLXCUk=; b=yvqgUWmaOt5j35GsEHvyun0X7Nw4xAxvDzjzOy7XJgNm+xSuW1sW9U9Kr2TSLjEjfg MjyYwxn/6wbdNIY1vW5tL7LucLaPIcvV542VYfyn8vNIefA9ARcfYEThy9t3TpuQCfYo KZJAopEoaeMrbmDX6e3qJPF4qsZMdg/wyK7hN9SjGRSoIQhdUFai2oQBU7/O2vDszIg/ iUMwlwCmsgF3W/3/J05Q14EjNS0uIHKrmpZSIUJ68j6r+ME6/aYOCivF1akYRCc3o9X3 XAmVFtxsmKwxJ47ZXqFFpUIGd53qteKv2tiRAafOMz6zKA1rpV9UYxTKVrvlrCq6wGz5 yaTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OimhlRjX; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r1si15899498pff.24.2018.04.24.23.28.56; Tue, 24 Apr 2018 23:28:57 -0700 (PDT) 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=@linaro.org header.s=google header.b=OimhlRjX; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751936AbeDYG2y (ORCPT + 29 others); Wed, 25 Apr 2018 02:28:54 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:35826 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750929AbeDYG1I (ORCPT ); Wed, 25 Apr 2018 02:27:08 -0400 Received: by mail-pg0-f66.google.com with SMTP id j11so12600882pgf.2 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=BGkEPpqcmNUykvc14RgCx9O3hTm8yknHZ8SAGYcw+CoAPrf4styBfSMNXVzfj7psvQ +cmbbO1xMHxOZfc+5gxMV5iEXzMSyAD2c+a+he3hhRaAnRO+f3iGwErAF5c381z5Fioq 9lvPH6u5GJNqGMKqkmrwstG71mSwsDJUKAbZCMDmJ9uBrE1HWBioOAtsYMp4VmuKrkng ZXJXBEu5iYLxo0iuQ1kAOZKHhplYiqnC1R5wrFTzmMYaqXGoJ2N9swnPGZoJkOdsuT+W bJQxAQe1u3IpZhG6KYofm6q2uNBUIQ250SpWccViJkE0aPNpWZcOAn/EbjScj1IyC/L8 CGmg== X-Gm-Message-State: ALQs6tAe6xWMK3tmBfUhG5o0PM4rWrZTvEXeu3vxHp9OIH6VpI73E440 YKHCsLNqqPmkQ9fHumNWv6DJdA== 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 Cc: ard.biesheuvel@linaro.org, james.morse@arm.com, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, AKASHI Takahiro 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 -- 2.17.0 Reviewed-by: James Morse 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; +}