Received: by 10.213.65.68 with SMTP id h4csp47222imn; Mon, 19 Mar 2018 19:05:55 -0700 (PDT) X-Google-Smtp-Source: AG47ELtlo3H8V5DGHS3meZp5eFEgCPXXT5y1D5iPYr8Euslm2Ss8YpqMmzZG6Yt8WCl4ka+9OQ/j X-Received: by 10.101.97.139 with SMTP id c11mr10723488pgv.443.1521511555616; Mon, 19 Mar 2018 19:05:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521511555; cv=none; d=google.com; s=arc-20160816; b=MC4Zr3zNSimPH62DrH+8tSPaM7A89DHWCMDH/GgxrMRkMKoP3Nmb5LfySbQPbw0Dyd 6oYt9lSAhdO14hywm4Fs4K2xuZQUZCTby+RvcVhqaRxVOBPWICzmw8P7ydlxlmwAS0PF mC0IAX8if5fcYZLNq3C9vNb0ZmUFmL0XTmtpiC7huet1Kc3XdANJtpwHjaLgCQzf8mYt NThKUSW9eu71pPP1MvpBBieQxnT+f8LCb8/oPSY1kc4F+GM91Bvqt+UgiryOWkzQfhR3 5usNmvxhtWUT//7MNDBHNij0XZgHUdLIY5PwCTkwpNNAL5w1u8xN8bEzMlJ1BrKBiivG hudA== 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:message-id:subject:cc :to:from:date:arc-authentication-results; bh=+tLNpjbKmKbdzkpxOiV3ohFhiFX3TgyTMtV9R7Z3W8o=; b=nKWr3cRWtAuqkrRNQxb2pD6/YWXNsbiEbAIivSc3MC6qnZLMVMm2iObRJUiINlpNQ8 0zhK2gsMoI72AXgDtyLyz+Rr95nRGaG5/63xl+XXOWoMA0Ep307O9R8soNQhtNc/kXvG RpHC3NKddP/HG4wH1sc0oae8aU320JO31gLUcCB+A3IoaCAR86V2Jz7KdpsOhzlqAQf0 Ks9rN4hwdFGTnSdknL3ZKMDOFUsOT1WKY4emnIwqMiZymsjeRtY03cF3AqTe5v5/r8oy cAeD+FU6TpwUEoDEtfePQNgmhhOUUPCq/qiSgSSHgkZwsWD58dfE3cdHc5UyZ2f1LHV0 WkLA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 135si425724pfx.318.2018.03.19.19.05.41; Mon, 19 Mar 2018 19:05:55 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751706AbeCTBn3 (ORCPT + 99 others); Mon, 19 Mar 2018 21:43:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45294 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751650AbeCTBnX (ORCPT ); Mon, 19 Mar 2018 21:43:23 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 84B178D6FB; Tue, 20 Mar 2018 01:43:22 +0000 (UTC) Received: from localhost (ovpn-8-16.pek2.redhat.com [10.72.8.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0B8B7202322C; Tue, 20 Mar 2018 01:43:20 +0000 (UTC) Date: Tue, 20 Mar 2018 09:43:18 +0800 From: Baoquan He To: AKASHI Takahiro , Dave Young Cc: herbert@gondor.apana.org.au, ard.biesheuvel@linaro.org, catalin.marinas@arm.com, julien.thierry@arm.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, dhowells@redhat.com, arnd@arndb.de, linux-arm-kernel@lists.infradead.org, mpe@ellerman.id.au, bauerman@linux.vnet.ibm.com, akpm@linux-foundation.org, Linus Torvalds , davem@davemloft.net, vgoyal@redhat.com Subject: Re: [PATCH v8 01/13] resource: add walk_system_ram_res_rev() Message-ID: <20180320014318.GA2514@localhost.localdomain> References: <20180222111732.23051-1-takahiro.akashi@linaro.org> <20180222111732.23051-2-takahiro.akashi@linaro.org> <20180223083619.GA4433@dhcp-128-65.nay.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180223083619.GA4433@dhcp-128-65.nay.redhat.com> User-Agent: Mutt/1.9.1 (2017-09-22) X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 20 Mar 2018 01:43:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 20 Mar 2018 01:43:22 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'bhe@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/23/18 at 04:36pm, Dave Young wrote: > Hi AKASHI, > > On 02/22/18 at 08:17pm, AKASHI Takahiro wrote: > > This function, being a variant of walk_system_ram_res() introduced in > > commit 8c86e70acead ("resource: provide new functions to walk through > > resources"), walks through a list of all the resources of System RAM > > in reversed order, i.e., from higher to lower. > > > > It will be used in kexec_file implementation on arm64. > > I remember there was an old discussion about this, it should be added > in patch log why this is needed. It's used to load kernel/initrd at the top of system RAM, and this is consistent with user space kexec behaviour. In x86 64, Vivek didn't do like this since there's no reverse iomem resource iterating function, he just chose a match RAM region bottom up, then put kernel/initrd top down in the found RAM region. This is different than kexec_tools utility. I am considering to change resource sibling as double list, seems AKASHI's way is easier to be accepted by people. So I will use this one to change x86 64 code. Hi AKASHI, About arm64 kexec_file patches, will you post recently? Or any other plan? Thanks Baoquan > > > > > Signed-off-by: AKASHI Takahiro > > Cc: Vivek Goyal > > Cc: Andrew Morton > > Cc: Linus Torvalds > > --- > > include/linux/ioport.h | 3 +++ > > kernel/resource.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ > > 2 files changed, 60 insertions(+) > > > > diff --git a/include/linux/ioport.h b/include/linux/ioport.h > > index da0ebaec25f0..f12d95fe038b 100644 > > --- a/include/linux/ioport.h > > +++ b/include/linux/ioport.h > > @@ -277,6 +277,9 @@ extern int > > walk_system_ram_res(u64 start, u64 end, void *arg, > > int (*func)(struct resource *, void *)); > > extern int > > +walk_system_ram_res_rev(u64 start, u64 end, void *arg, > > + int (*func)(struct resource *, void *)); > > +extern int > > walk_iomem_res_desc(unsigned long desc, unsigned long flags, u64 start, u64 end, > > void *arg, int (*func)(struct resource *, void *)); > > > > diff --git a/kernel/resource.c b/kernel/resource.c > > index e270b5048988..bdaa93407f4c 100644 > > --- a/kernel/resource.c > > +++ b/kernel/resource.c > > @@ -23,6 +23,8 @@ > > #include > > #include > > #include > > +#include > > +#include > > #include > > > > > > @@ -486,6 +488,61 @@ int walk_mem_res(u64 start, u64 end, void *arg, > > arg, func); > > } > > > > +int walk_system_ram_res_rev(u64 start, u64 end, void *arg, > > + int (*func)(struct resource *, void *)) > > +{ > > + struct resource res, *rams; > > + int rams_size = 16, i; > > + int ret = -1; > > + > > + /* create a list */ > > + rams = vmalloc(sizeof(struct resource) * rams_size); > > + if (!rams) > > + return ret; > > + > > + res.start = start; > > + res.end = end; > > + res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; > > + i = 0; > > + while ((res.start < res.end) && > > + (!find_next_iomem_res(&res, IORES_DESC_NONE, true))) { > > + if (i >= rams_size) { > > + /* re-alloc */ > > + struct resource *rams_new; > > + int rams_new_size; > > + > > + rams_new_size = rams_size + 16; > > + rams_new = vmalloc(sizeof(struct resource) > > + * rams_new_size); > > + if (!rams_new) > > + goto out; > > + > > + memcpy(rams_new, rams, > > + sizeof(struct resource) * rams_size); > > + vfree(rams); > > + rams = rams_new; > > + rams_size = rams_new_size; > > + } > > + > > + rams[i].start = res.start; > > + rams[i++].end = res.end; > > + > > + res.start = res.end + 1; > > + res.end = end; > > + } > > + > > + /* go reverse */ > > + for (i--; i >= 0; i--) { > > + ret = (*func)(&rams[i], arg); > > + if (ret) > > + break; > > + } > > + > > +out: > > + vfree(rams); > > + return ret; > > +} > > + > > #if !defined(CONFIG_ARCH_HAS_WALK_MEMORY) > > > > /* > > -- > > 2.16.2 > > > > Thanks > Dave > > _______________________________________________ > kexec mailing list > kexec@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/kexec