Received: by 10.192.165.148 with SMTP id m20csp5209461imm; Tue, 1 May 2018 10:51:43 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo1wRmsL4T6LjCGqk3zgCgMwdXIBYMwjyTunOEtAT98neJrJBCcH1OGPCCnrKa75FJGEtwp X-Received: by 10.98.20.195 with SMTP id 186mr16504617pfu.92.1525197103292; Tue, 01 May 2018 10:51:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525197103; cv=none; d=google.com; s=arc-20160816; b=BVDKqXFx6kiXuvetRqVU92o784rBb+qLdPU1MdvbKbGRk9oCJY5QX65jMjoVpd8+Hz AG4Gb2/b2sLrBwX2DJzvPSTwvFjYsI3V/4BuLsV+UBVE/g/rnMXEl6qlqJ+UwrayriWA N+ZqS9r0ghIAKKsYoW5JO+dNTo9zkldKyHm7qgjs7zyDYTaV5xSUZgwJqSmxPHa4vALE Gy+lepvnvzqtY/1+U2bdM2W7D2t85b8CviU3GNbltVRKz/FQ+ojZwR/INEGY4fxVQxTz uSKMFCITNHFDz6FCVyS6fVtGBmvuf9g1E77L77GGnn2eGsla3NR4Dohs30aHgG+0qM0W mBTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=/4/2wnhHtuuP42Mz+SwT2bpsnfBfbPPpiKYysUSUjoo=; b=N1QBLb+9TXc9qjZqwsMLIZ8cmA4CRnXqz3eo8YtZefSXJOlaZdFKVvArYG9UbehVnw 89fjXOUZFbpnGeSJW5mQCK3xK0VjB8YXd8ql7JvS4T9kAfHv27t7oVTmgdjcLo4pC//u KMvEUIVoQb3aB4sMKj7FBWGSud4DUVTe3PPGYJjUI8JBpc9TwGgsv6YKJGOScevSCSbo y/GPt4r3cO/npHnS6YmdjSfsNMKwjzUkNVkjPoLlzRnXKSi8eZHSmG6acogEWphG+YLs VLEq/JUek+I55h6gpgLb3RFt9L90dvaTc1MJnwswn9VudroTQ6iQq7hHYawAUYg4MYPT c+vQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n11-v6si4302834pgt.679.2018.05.01.10.51.29; Tue, 01 May 2018 10:51:43 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932107AbeEARtl (ORCPT + 99 others); Tue, 1 May 2018 13:49:41 -0400 Received: from foss.arm.com ([217.140.101.70]:49912 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756300AbeEARtJ (ORCPT ); Tue, 1 May 2018 13:49:09 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C6D5015AD; Tue, 1 May 2018 10:49:08 -0700 (PDT) Received: from [10.1.207.55] (melchizedek.cambridge.arm.com [10.1.207.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3CA743F25D; Tue, 1 May 2018 10:49:05 -0700 (PDT) Subject: Re: [PATCH v9 04/11] arm64: kexec_file: allocate memory walking through memblock list To: AKASHI Takahiro Cc: 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, ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20180425062629.29404-1-takahiro.akashi@linaro.org> <20180425062629.29404-5-takahiro.akashi@linaro.org> From: James Morse Message-ID: <648656ef-1f1e-b0ac-581c-aba1e62f4eee@arm.com> Date: Tue, 1 May 2018 18:46:09 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180425062629.29404-5-takahiro.akashi@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Akashi, On 25/04/18 07:26, AKASHI Takahiro wrote: > 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. Didn't we try to fix the system-resource-tree in order to fix regular-kexec to be safe in the EFI-memory-map/ACPI-tables case? It would be good to avoid having two ways of doing this, and I would like to avoid having extra arch code... > 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 How does kexec-tools walk memblock? > + */ > + > +#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) { for_each_free_mem_range_reverse() is a more readable version of this helper. > + if (!memblock_is_map_memory(start)) > + continue; Passing MEMBLOCK_NONE means this walk will never find MEMBLOCK_NOMAP memory. > + 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) { for_each_free_mem_range()? > + if (!memblock_is_map_memory(start)) > + continue; > + > + res.start = start; > + res.end = end; > + ret = func(&res, kbuf); > + if (ret) > + break; > + } > + > + return ret; > +} > With these changes, what we have is almost: arch/powerpc/kernel/machine_kexec_file_64.c::arch_kexec_walk_mem() ! (the difference being powerpc doesn't yet support crash-kernels here) If the argument is walking memblock gives a better answer than the stringy walk_system_ram_res() thing, is there any mileage in moving this code into kexec_file.c, and using it if !IS_ENABLED(CONFIG_ARCH_DISCARD_MEMBLOCK)? This would save arm64/powerpc having near-identical implementations. 32bit arm keeps memblock if it has kexec, so it may be useful there too if kexec_file_load() support is added. Thanks, James