Received: by 10.213.65.68 with SMTP id h4csp335767imn; Wed, 21 Mar 2018 20:39:02 -0700 (PDT) X-Google-Smtp-Source: AG47ELvS5s4s148Bc3JV6YSltSwK76XhOpFJ1Qow1sncFzyzX3fmuYFgN8jaC2+7n/h2cnSMfuNv X-Received: by 10.167.129.152 with SMTP id g24mr350697pfi.117.1521689942598; Wed, 21 Mar 2018 20:39:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521689942; cv=none; d=google.com; s=arc-20160816; b=hzV5+1OOrDFn0niIRUZzw4DrOLILRU5ZBRl6WXKsVHeST2CbP+JY/7rV4Ox1v24732 Y4JpbbOLy4zJ4/afM+qpWqeAjnK5IfqFTMuChYuDcf1i+89o2IKNQ8SDZ5n0AbC3Zjn2 lI2GL7hwPLC6KIT6ASsD3X/0C8lUoa5QSyhI9pUinaD02t3O9SUTbb1SV3cf6z4Eaby7 xcRsODb4tQZ7MeTNyBag8ZRQ2bRfdX+sMpIeXJi7mCj0c8jK/KRabEnxNMTb8u9iV6+/ V0SUOVLrPsnBpYYZCf7PtRCElq1LRSHX8OUA60wiOBktCtkcZLJ39/mYikflmAUvXlT1 /hwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Qe+cgi1aCF78qsSYOOWRM9nc4XT/CyhKrJBab/2+t/E=; b=msy1vcaUYT6Ybq+LDnAsL3SkmxR2CMvPAMHtsDxmHgSpremP3sViuMWYKYjetx7Lc2 xkLyvHsY7mUP/A3CPesTmCuGDDywC0q/wOJ9o3ZqQZ4EsXi+ST4VIKajGODJi2PrLbGn +pFhzDmBKi7ogdCNi5wqOaqFXHJahDk9MgxgVGPO2R52oY0IVhcZfQszrteKESQ7UO1r hNZNz+3SXookBtZQ/pyMaFM1W2zTOi+p8yZrLstdrjsAew2iLbENYtwAb58ia3uBiN36 tJfuPo+k0IWT/MYOHnC5sKZvfcwU+/gl2zpxgjpZ3Fu8WTDkK/ZaDZ65wRpu5ZLts2S/ M4gQ== 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 q15si3823735pgc.367.2018.03.21.20.38.48; Wed, 21 Mar 2018 20:39:02 -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 S1752097AbeCVDhq (ORCPT + 99 others); Wed, 21 Mar 2018 23:37:46 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39792 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751728AbeCVDhm (ORCPT ); Wed, 21 Mar 2018 23:37:42 -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 28B6A8160F99; Thu, 22 Mar 2018 03:37:42 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-8-26.pek2.redhat.com [10.72.8.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E7D1202322F; Thu, 22 Mar 2018 03:37:37 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: kexec@lists.infradead.org, akpm@linux-foundation.org, takahiro.akashi@linaro.org, ebiederm@xmission.com, vgoyal@redhat.com, dyoung@redhat.com, prudo@linux.vnet.ibm.com, Baoquan He Subject: [PATCH 1/2] resource: add walk_system_ram_res_rev() Date: Thu, 22 Mar 2018 11:37:21 +0800 Message-Id: <20180322033722.9279-2-bhe@redhat.com> In-Reply-To: <20180322033722.9279-1-bhe@redhat.com> References: <20180322033722.9279-1-bhe@redhat.com> 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.8]); Thu, 22 Mar 2018 03:37:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 22 Mar 2018 03:37:42 +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 From: AKASHI Takahiro 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 code. Signed-off-by: AKASHI Takahiro Signed-off-by: Baoquan He --- include/linux/ioport.h | 3 +++ kernel/resource.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 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..f456fc95f1b2 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include @@ -470,6 +472,67 @@ int walk_system_ram_res(u64 start, u64 end, void *arg, } /* + * This function, being a variant of walk_system_ram_res(), calls the @func + * callback against all memory ranges of type System RAM which are marked as + * IORESOURCE_SYSTEM_RAM and IORESOUCE_BUSY in reversed order, i.e., from + * higher to lower. + */ +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; +} + +/* * This function calls the @func callback against all memory ranges, which * are ranges marked as IORESOURCE_MEM and IORESOUCE_BUSY. */ -- 2.13.6