Received: by 10.192.165.156 with SMTP id m28csp61342imm; Wed, 18 Apr 2018 17:20:48 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/VVPwslac21aw+n3iFRNuIVfv2+rJsNalUebza2eUDewU62Xzxh6jMp1vNEnP5atKXR+BZ X-Received: by 10.99.111.130 with SMTP id k124mr3206937pgc.301.1524097247953; Wed, 18 Apr 2018 17:20:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524097247; cv=none; d=google.com; s=arc-20160816; b=Zn7IPR0r5dHPRkEikpaaNzDhKwoQn6lSyBehkLZoD7wQG2e4VpJO0014hAMy7t+XTo 34xAZV5Qx1cs57B4kgM7QJSb7cbV3z6JRBiigmVvT6YZpiyHp1Szz5rJNoHd5SIKT1x+ Ivyk5hyrt3fV6A5dC1i7dpHkU6D3sNdckSLr0BHWPKOet+hASsVre8fuinO2c/4hg/fl KOAKYxc3eATEF+xbyvPzr6QGZbO3mu7Q+yQWXgjXEbM7FNsimLO9vwlhalL4Eb7Uzoi0 Sr9eZAxALZ6SEg3xJABQiDiKKk0K53Nsq1uul3RY1WuQwc9Ly8+HRnSDRXEjDO7lIzw2 9IGQ== 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=Y+TLduKY16zEj53TsrZ+tzRlEbMYicoSaHzZfLDRy5g=; b=bk65BYGMb37AFlLk6zyVseBIleTPJDnwAZXic5nLCn+rK5An9v8QkjgTscFO+O64fR trFtW0h2xW3UC8U1IYP86Pr/SNuKYUulTMfhhGoEXxC+6lI2wNHTqTsofITCamBQrtNM lZJpIg0MBXUZMG48r5viq4cmiWn2FINCxt4EGWGHTKrFyebj+SthUA2U0mVvlaL3kDyY e4AKixg8Lb8roIWwxxonK9+wlxvx6FDdv/plVz1j9m5pRm1c4gNXkYF9dUpMNNARh7pw /NVk2SnrmElh5O36wda5wZxyyreKOsPBKZJK+4DdZVZOpEiLqMVXcagTtm5VzUe/XJ3Q Truw== 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 h9si1888786pgq.464.2018.04.18.17.20.34; Wed, 18 Apr 2018 17:20:47 -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 S1753187AbeDSATX (ORCPT + 99 others); Wed, 18 Apr 2018 20:19:23 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37228 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753065AbeDSATW (ORCPT ); Wed, 18 Apr 2018 20:19:22 -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 9C9028163AD3; Thu, 19 Apr 2018 00:19:21 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-8-16.pek2.redhat.com [10.72.8.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9EE82024CA1; Thu, 19 Apr 2018 00:19:16 +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 Cc: Baoquan He , Thomas Gleixner , Brijesh Singh , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Borislav Petkov , Tom Lendacky , Wei Yang Subject: [PATCH v3 2/3] resource: add walk_system_ram_res_rev() Date: Thu, 19 Apr 2018 08:18:47 +0800 Message-Id: <20180419001848.3041-3-bhe@redhat.com> In-Reply-To: <20180419001848.3041-1-bhe@redhat.com> References: <20180419001848.3041-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.8]); Thu, 19 Apr 2018 00:19:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 19 Apr 2018 00:19:21 +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 225d13d3500a..5f2cfb460a14 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -278,6 +278,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 4f560991c130..6c519b06e3d6 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include @@ -475,6 +477,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