From patchwork Thu Mar 22 03:37:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 132248 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp334515ljb; Wed, 21 Mar 2018 20:37:49 -0700 (PDT) X-Google-Smtp-Source: AG47ELvVrOqdFfzT2xTAAd2+bsL0j/VGRCCiMp0NDsZqFl336a3jPRV7nM4llKTtdVMgMnuHer0O X-Received: by 2002:a17:902:a5c5:: with SMTP id t5-v6mr23570072plq.244.1521689869271; Wed, 21 Mar 2018 20:37:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521689869; cv=none; d=google.com; s=arc-20160816; b=c3/KlgMrKJ1+Ea6FZ1CvAgFSzBkA+9Mm1KPTu1KMbpTLSq8GY+/ayXODVHQ1YRmwC+ TPV/KCqFXrNpsy45ieS00xh4DRfP8EHikhPryXiXF/Meclv0LTroso95NU4DvIx/h++X N8Xu7jsnJMlkHoO1DXB9+qDvktMwrb+vSEL3aDebjrYtIt8464EGyaj6er7EreKUFIjs VnZB7nHypLyMad8MgbAy3ghsFbgueBe20SzMQ4rwJv9+B3Yb8+g6G1Fgd8vAL1TuQbEN UuefgpQSu5ZiOn56g9+jzCKl1v97Ar/MXZQ03zInEJYpv7duco7Q1R+sU5f6EGJSLVgl B4Xg== 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 v22si1393055pfe.124.2018.03.21.20.37.49; Wed, 21 Mar 2018 20:37:49 -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 S1752113AbeCVDhq (ORCPT + 28 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(+) -- 2.13.6 Signed-off-by: Wei Yang 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. */