Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp89476imm; Mon, 14 May 2018 21:36:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZprPJ3aB6WSwmGsfyW89Cu4sgdAXcs/xbwOBTNgKoUlCc2eEwxTc9qX24vXVNl6kCJib70f X-Received: by 2002:a17:902:3303:: with SMTP id a3-v6mr12713471plc.209.1526358973519; Mon, 14 May 2018 21:36:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526358973; cv=none; d=google.com; s=arc-20160816; b=Ow69i4hvpIv7JEKDzNUnJn7NzDZFVH+U36YmRs0QNNzgB5FKaTzczQ9eI8WZLyih4f kWyhSIH7YoSeEkrMoHpFAQaZSOjfaPSyX/Kxp698pm9l3g6uKtX+j8BfuLblWGsrqqqc RKtr4e6Kw2acSiC43xcagRTTe5FHIFIBljRP70yIRBv2VGe2FXQJEyoUYNDjDvfiKNsd SeRPQTOkhib25WMacidwxb8wYchrRCkh8Vvd1TqamRzevmwy2Jgu224UgYPdcW8Szk4G irjDlEE+CHmMs+84aoGSroJEcdVoLekzQg107zmdiGJRVQeFamlvWL8Ayn3dFg/Axo85 eVRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :message-id:subject:to:from:date:dkim-signature :arc-authentication-results; bh=NskRR2F0QurXRwof1nd25ga2MLSp9T09OZAkDnZsLJU=; b=PkZdYcQxvD+3LHZf+xKB8tvVAKyhIcAupqhuHba3hbWmoA9SZeUEwAeltoBKtN+Diw 4t7gXlpKzi/L+Eh2Y/beZ7aoHjXK0aJt9wmWRhXf8HFe7qkOclfAuzFpOTwNd0WL79hI 9csDvhQtpYMrLA/+9WryyIKPM76+V3V910l9ADgD+S7JOuj5K4RiJ3gduFzIipky7E7J j9gYvUU8nHAyp5fZFGI27w3scrkb4JvIiqtQiPjPV+WRFv7xsPxx2kNLsWhVnXZbQApZ 0RAa0lD3EyTW2qzVwEXWDpMzVhxSI5fJpID+pcefb8Bh5FrQW5tnuW1M5UDX/yRNlR2L dzaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UergnZM9; 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 y5-v6si10645043pfe.134.2018.05.14.21.35.59; Mon, 14 May 2018 21:36:13 -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=UergnZM9; 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 S1752139AbeEOEft (ORCPT + 99 others); Tue, 15 May 2018 00:35:49 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:33653 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750952AbeEOEfr (ORCPT ); Tue, 15 May 2018 00:35:47 -0400 Received: by mail-pg0-f65.google.com with SMTP id v7-v6so3638902pgs.0 for ; Mon, 14 May 2018 21:35:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=NskRR2F0QurXRwof1nd25ga2MLSp9T09OZAkDnZsLJU=; b=UergnZM9lGdPzX7WsulT0ti3ONZpUndHmyFs2m1j8wji6hXJBprFu64ky6UH44YjLa 9wrFAicLC5maDjnsXzyNqwWgrxYunhuakjGmFpya4gdE9nZ5IkTPUZvKAP0oyM7ZZKlK AX8JM0zhvvqRrQTC1s6jh/C+YIzlzDA5jiEOs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=NskRR2F0QurXRwof1nd25ga2MLSp9T09OZAkDnZsLJU=; b=j13yMb6s2y2kAecF5qovgopXOm2ERUjfxGl8TKVP+MT0jYy/HxrvW2UxasYkbb+AAB 5BHJO0C7j+FSiP2A4FrCz/GguyOr8qBGmiCiLkzTeHBaiQNVOcVCzzWMzpUdPDLG21zl 4A40MuGkWcMLMJDOGSLGYZ49IEppuLpRT6QeBrpiKda0f1IM7faeA2OoerS1HYY5hQbt ssLKawNNWtsZ04IjLxaFrx4j215UJ2EJ31iWZ2/ai9D7ch3RNQIy1h7WzVWPheClADJZ p8ibOM9FvR1cdyhg+yTb7g/ep781fPj4qxFNbuUG6f2tdC9/pMhFwhQ9Xin84HFLlZn5 sV1g== X-Gm-Message-State: ALKqPwe4fu4P6Kwu0PqSZXhy5WlYx+TBZR7qYB07SWUW9NnEgWC0eOd8 6/95Avp2/029ITLtgO4XG8tAdvDUOdU= X-Received: by 2002:a65:648a:: with SMTP id e10-v6mr10816093pgv.34.1526358947216; Mon, 14 May 2018 21:35:47 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id f29-v6sm21651550pff.169.2018.05.14.21.35.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 May 2018 21:35:46 -0700 (PDT) Date: Tue, 15 May 2018 13:35:40 +0900 From: AKASHI Takahiro To: James Morse , 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 Subject: Re: [PATCH v9 04/11] arm64: kexec_file: allocate memory walking through memblock list Message-ID: <20180515043538.GB2737@linaro.org> Mail-Followup-To: AKASHI Takahiro , James Morse , 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> <648656ef-1f1e-b0ac-581c-aba1e62f4eee@arm.com> <20180507055906.GE11326@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180507055906.GE11326@linaro.org> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org James, On Mon, May 07, 2018 at 02:59:07PM +0900, AKASHI Takahiro wrote: > James, > > On Tue, May 01, 2018 at 06:46:09PM +0100, James Morse wrote: > > 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... > > I know what you mean. > /proc/iomem or system resource is, in my opinion, not the best place to > describe memory usage of kernel but rather to describe *physical* hardware > layout. As we are still discussing about "reserved" memory, I don't want > to depend on it. > Along with memblock list, we will have more accurate control over memory > usage. If you don't have further objection, I will take memblock approach (with factoring out powerpc's arch_kexec_walk_mem()). Thanks, -Takahiro AKASHI > > > > > 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? > > Will remove this comment from this patch. > Obviously, this comment is for the rest of the code which will be > added to succeeding patches (patch #5 and #7). > > > > > > > + */ > > > + > > > +#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. > > OK. I used to use my own limited list of reserved memory instead of > memblock.reserved here to exclude verbose ranges. > > > > > + if (!memblock_is_map_memory(start)) > > > + continue; > > > > Passing MEMBLOCK_NONE means this walk will never find MEMBLOCK_NOMAP memory. > > Sure, I confirmed it. > > > > > > + 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()? > > OK. > > > > + 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. I've forgot ppc. > > -Takahiro AKASHI > > > > > > Thanks, > > > > James