Received: by 10.192.165.148 with SMTP id m20csp2711579imm; Sun, 6 May 2018 22:59:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqHOQvt5aFAlz9EaBQ9IBIGI17YZ0MKaVtqo8ylPXNNYDnsR/KsWF/jIKYNdDADX+SkQeEb X-Received: by 2002:a17:902:8602:: with SMTP id f2-v6mr10485386plo.5.1525672796907; Sun, 06 May 2018 22:59:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525672796; cv=none; d=google.com; s=arc-20160816; b=FJ9NLTRFq7ifjMLU2XGq8zlvTYb4Chv1OvFm0XOsInoxHMZp5AWc5ZG/jAKdLbeIk7 Q2nL2Vr5nkzkk+U40FreYpCRJStXUSDqEFhhGtH9yBf37s9vAKDu0vfpO3X7CDuM7TGu uOCPvkR+nSl8TL1EUfcsoLIlNhIPYoVGd2rJaAuu5uiurrV50tEYN88ZNV+8+i1G83qp CvMs9mP6HOYMnj1wHE4fC+51j9auRLJn44sITIHhkoFX+WLSiBrBxV39/9Q63mn8Swrh 4ik+kUgeCoq3cLBxKMv2kmzavEpdeTaiOjzhOmo9+H2w/FjxqOq+yvoG4XjLqa+5FnwG J0XQ== 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:cc:to:from:date:dkim-signature :arc-authentication-results; bh=ZsUzADEQfnJSm3O6JuL5eivvxYpxb4vyUPZOeXVGwFA=; b=Bxi7w1bzQsZ9ceRoiTpWSsnzcYoMvNauOSPSo2BJE8LV+1XQIIUsb/e5mwFLUcZQJW 6/tzY56IR4vN/58g0C6lHgT46BTkhFT73Mb5V0QqdnUJSRoDZi1NmtqRbfpCx3MHeV24 lUulEhHPYDbsPL131BQm7mthl8lyTT+XdXX8nkbvfQ7ASKmk4Al201iUOumMvXrIgW7u zPm+8xed5qfbXvui/viDrhU4L6qdVhAEfuQ2QCWD52CycWzpJji20ROOVIamjLOMt7xU Gk9s+mlGYO/Ngvxudr8FSPHGf39Ou9wwbC1/s2SoEqPwK9dpDpK4+Rdj1p+lv7rV2oSn C9vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZnsTlv7h; 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 i1-v6si12808816pgv.424.2018.05.06.22.59.42; Sun, 06 May 2018 22:59:56 -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=ZnsTlv7h; 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 S1751379AbeEGF6Z (ORCPT + 99 others); Mon, 7 May 2018 01:58:25 -0400 Received: from mail-io0-f195.google.com ([209.85.223.195]:40587 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750716AbeEGF6W (ORCPT ); Mon, 7 May 2018 01:58:22 -0400 Received: by mail-io0-f195.google.com with SMTP id g14-v6so28599325ioc.7 for ; Sun, 06 May 2018 22:58:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ZsUzADEQfnJSm3O6JuL5eivvxYpxb4vyUPZOeXVGwFA=; b=ZnsTlv7hfHNDO7i0jbwkdB2yNe37t8kBrZ57ir0ucJAI5blsrhahNTuUR719QyipWF O/FjVRbbFfBwoy6pSHh1yOy3ztKpq5NEWQwoXlzt0jPE89NeWsv4djKGtXPNCF6YuWzI 8BKwLDJrdlv5/quKyL9g2lg1MM+BPOewGr1Ds= 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:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=ZsUzADEQfnJSm3O6JuL5eivvxYpxb4vyUPZOeXVGwFA=; b=R/vRfFbq4maFZOq4q7NLx9ezk4fmQ/b66urjUP3aaZr0Cc0+F6USyw7SnxuTiLXVso sCQVxGZSguP326rnI5CM8f590b0MtNCzDPht8TaJ7xOXsjdTLGGGsCWT6bu3xIXIIm7j UIb9tc6bvPfLeaMXQFnU5obI+dt3yGENbdGBJTFE2KIcsShTlU+wkrTCB3saIxzx7Q0a gdb9sCSzFf+uqE3hw0PFNWJco1UilNupO/e1sQbIYcp1z3DNG1hpytaxpG38FwEi6cPC r0iv5jx/Un1GQm8TAWhdiUembpbcquLneHyc796qyH+Zmi+X0hrqz1Pvzzc8WLrapgdt z6Mw== X-Gm-Message-State: ALQs6tD1N9Ar6xNtf+bsnpjuDstnvWoNk0i4O7v8UT6uHsArtGdkPmtZ CQtkIEg0Z6Eirb33htqUWZqW3g== X-Received: by 2002:a6b:994d:: with SMTP id b74-v6mr40295591ioe.195.1525672701662; Sun, 06 May 2018 22:58:21 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id p16-v6sm3931825itp.3.2018.05.06.22.58.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 May 2018 22:58:21 -0700 (PDT) Date: Mon, 7 May 2018 14:59:07 +0900 From: AKASHI Takahiro To: James Morse 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 Subject: Re: [PATCH v9 04/11] arm64: kexec_file: allocate memory walking through memblock list Message-ID: <20180507055906.GE11326@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <648656ef-1f1e-b0ac-581c-aba1e62f4eee@arm.com> 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 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. > > > 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