Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp359109imm; Tue, 3 Jul 2018 21:14:06 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe28onL6PcuAf+EnZbxVuXUszh/1vlbEH7ltj5DtwciPmUJi2kyiKsQEfITBOL+6hwNut2g X-Received: by 2002:a17:902:1007:: with SMTP id b7-v6mr450930pla.277.1530677646240; Tue, 03 Jul 2018 21:14:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530677646; cv=none; d=google.com; s=arc-20160816; b=UeiyfL0ZI+niW7aSz+9GKEshH5sPZp1p9RFOTVupuPP4qqB1wSX9WzqkXsdxTHiq5S 46wEYCuw+SsokP5I5st0DL4Q+ztuVCujZb7rWQt2u5I8hNTykSEpdB57Y0N2dBBeZ1Ta 0K78MANU62w7aPfGtS+hjnHBobWi8BnBHAzcIFNqaQTrCTo7PpCe+9wPenVTqAVMsACh CFktNCNpzuh3xHQuk3MXRpdwaHaE03yL4Vtrhj1HhRaEzeOkOvPRtglxZ4ePDA/Ot5z9 ndKedcCc23TcdyM+Nfq4/MyVqUGwzfDHDsmt/IiMcR43Pi4xLqyO/+SlDC2yQxCcpoNs F9Kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Y9cPM5z05Jcsu6gXaxgeNPOBls4s5HVlFjw7zmFdj/A=; b=BT9MqVabzNNosTPtVKK2swwPzzXHaAIMuh6MFkAIL4Ki9fQYo4kLsOjus0lsYenlx/ Wiqy9mBunFPei1yrXWmO3ZJaiCXFKD/BiMQfBMPp64edzn/Xx3XnzSNbnJ/lF3BeJI1V 7EAAqV/n7JoIrpa3FeGAa5sLwxpOTKJeg4y4YO2ZBzdtT01T2XpDNMEvkXOfPKuzsYY2 hmIBDQzy7jSK1ZPLdr5y4pzQTC6CUBHPZ1Io46rLeiPVQp5Fs044TkOO951KsF8M81Tb M1PLJxWuGMI4wAVgaX6qIbM12caeL+uXgHCIW9/jm0c+w+/fVhwxZ7MW0mqaMNGjad40 31Bg== 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 m12-v6si2519925plt.276.2018.07.03.21.13.52; Tue, 03 Jul 2018 21:14:06 -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 S932746AbeGDEMH (ORCPT + 99 others); Wed, 4 Jul 2018 00:12:07 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51486 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932188AbeGDEME (ORCPT ); Wed, 4 Jul 2018 00:12:04 -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 102FFB798; Wed, 4 Jul 2018 04:12:03 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-8-16.pek2.redhat.com [10.72.8.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 83CD02026D76; Wed, 4 Jul 2018 04:11:42 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, robh+dt@kernel.org, dan.j.williams@intel.com, nicolas.pitre@linaro.org, josh@joshtriplett.org, fengguang.wu@intel.com, bp@suse.de, andy.shevchenko@gmail.com Cc: patrik.r.jakobsson@gmail.com, airlied@linux.ie, kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, dmitry.torokhov@gmail.com, frowand.list@gmail.com, keith.busch@intel.com, jonathan.derrick@intel.com, lorenzo.pieralisi@arm.com, bhelgaas@google.com, tglx@linutronix.de, brijesh.singh@amd.com, jglisse@redhat.com, thomas.lendacky@amd.com, gregkh@linuxfoundation.org, baiyaowei@cmss.chinamobile.com, richard.weiyang@gmail.com, devel@linuxdriverproject.org, linux-input@vger.kernel.org, linux-nvdimm@lists.01.org, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, ebiederm@xmission.com, vgoyal@redhat.com, dyoung@redhat.com, yinghai@kernel.org, kexec@lists.infradead.org, monstr@monstr.eu, davem@davemloft.net, chris@zankel.net, jcmvbkbc@gmail.com, gustavo@padovan.org, maarten.lankhorst@linux.intel.com, seanpaul@chromium.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Baoquan He Subject: [PATCH v6 3/4] resource: add walk_system_ram_res_rev() Date: Wed, 4 Jul 2018 12:10:37 +0800 Message-Id: <20180704041038.8190-4-bhe@redhat.com> In-Reply-To: <20180704041038.8190-1-bhe@redhat.com> References: <20180704041038.8190-1-bhe@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.1]); Wed, 04 Jul 2018 04:12:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 04 Jul 2018 04:12:03 +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 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: Baoquan He Cc: Andrew Morton Cc: Thomas Gleixner Cc: Brijesh Singh Cc: "Jérôme Glisse" Cc: Borislav Petkov Cc: Tom Lendacky Cc: Wei Yang --- include/linux/ioport.h | 3 +++ kernel/resource.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/include/linux/ioport.h b/include/linux/ioport.h index b7456ae889dd..066cc263e2cc 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -279,6 +279,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 6d647a3824b1..4c5fbef4ea24 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include @@ -443,6 +445,44 @@ 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 *)) +{ + unsigned long flags; + struct resource *res; + int ret = -1; + + flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; + + read_lock(&resource_lock); + list_for_each_entry_reverse(res, &iomem_resource.child, sibling) { + if (start >= end) + break; + if ((res->flags & flags) != flags) + continue; + if (res->desc != IORES_DESC_NONE) + continue; + if (res->end < start) + break; + + if ((res->end >= start) && (res->start < end)) { + ret = (*func)(res, arg); + if (ret) + break; + } + end = res->start - 1; + + } + read_unlock(&resource_lock); + 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