Received: by 10.223.185.116 with SMTP id b49csp424381wrg; Fri, 23 Feb 2018 00:38:43 -0800 (PST) X-Google-Smtp-Source: AH8x226Z1kWGUeDE9sdTBbNjbe1S+ws0/c3QMmvCe2TmExIlU3YSi6TgaNGVehIkJMP0zgSq5jL1 X-Received: by 2002:a17:902:5a5:: with SMTP id f34-v6mr1037406plf.134.1519375123302; Fri, 23 Feb 2018 00:38:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519375123; cv=none; d=google.com; s=arc-20160816; b=Y9Mwq/zw/g5EtfbqsE9Qw99d8z5SU10qIhez8VTkY/yWDLpilM95BRK/RqWToUnFyJ eY2Hq0oFhF5X0h5cZ7kOHxqAMDZF2FoqISfCMiU/Bp7JQMyzBZ/XyDHDV7ZeBghXCK50 251J68RQRVmg2OvURbkvQCo0MjMLRFhs+ph1srS9Y8sf5ek/vaFUR+ZHOxX58awS64+B ABWJbwIUDFK5H8vJUeUoAxP+x5MSpJG3dNaDWMmr4q6XKZTxtzbVOfcB9RbyFM0nLemg lfHMQu1pEnO8EbeYmOlrGJ8FyChl9LEcQTE25kX5Hfo/KMZ5JnTwrCJKnOP1ShRne+tp QGhQ== 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=a6XM+OhU26/pNbxKVBhYYAbfJm+l4UDPBLuBIyNtRAM=; b=V0t9og+C8YESMtQE1ZV8n/axk43yZfuEXTDGpCg++RHVulDWQHFWym06KSNWP//oO5 lg8OaMTv9X+dHiOC/34+0JmAlOAwS9Po8x0QIa15q9fLFIUQFd0i0zXY4oIvljRAVMVh GEhIXf4Y3inH1UYsg97b8SRXwBNgrprf5UICtkkDHHvofpvUiaWgLGwBZ3lzd3f6c61+ 29oAmSTBLA0RjXaT4ywGv4SAHg936U/J8kOMgzzZW2YH1iuB25Z5bAjbhQ1Twf/JI9UF YvlZs7QajWGTKnD3nAB9/OrP0z1YK2LL2m9yRokj4ZwlMZM7I+VuKcExSnizFt9vpbQ+ b96A== 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 p15si1216788pgq.51.2018.02.23.00.38.28; Fri, 23 Feb 2018 00:38:43 -0800 (PST) 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 S1751662AbeBWIgc (ORCPT + 99 others); Fri, 23 Feb 2018 03:36:32 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60828 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751273AbeBWIgb (ORCPT ); Fri, 23 Feb 2018 03:36:31 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B3B1D407519B; Fri, 23 Feb 2018 08:36:30 +0000 (UTC) Received: from dhcp-128-65.nay.redhat.com (ovpn-12-55.pek2.redhat.com [10.72.12.55]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2BB67213AEE4; Fri, 23 Feb 2018 08:36:22 +0000 (UTC) Date: Fri, 23 Feb 2018 16:36:19 +0800 From: Dave Young To: AKASHI Takahiro Cc: catalin.marinas@arm.com, will.deacon@arm.com, bauerman@linux.vnet.ibm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, mpe@ellerman.id.au, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org, julien.thierry@arm.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Torvalds Subject: Re: [PATCH v8 01/13] resource: add walk_system_ram_res_rev() Message-ID: <20180223083619.GA4433@dhcp-128-65.nay.redhat.com> References: <20180222111732.23051-1-takahiro.akashi@linaro.org> <20180222111732.23051-2-takahiro.akashi@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180222111732.23051-2-takahiro.akashi@linaro.org> User-Agent: Mutt/1.9.1 (2017-09-22) X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 23 Feb 2018 08:36:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 23 Feb 2018 08:36:30 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dyoung@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > 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