Received: by 10.213.65.68 with SMTP id h4csp1162467imn; Sat, 7 Apr 2018 19:52:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+FwUIgYdQL3ijHt9MVqp8SAlqIt64mD6yWa5216aW7m46zMP7BiMMNtGmF/zo7tUOyRFIG X-Received: by 2002:a17:902:7292:: with SMTP id d18-v6mr32607184pll.289.1523155926322; Sat, 07 Apr 2018 19:52:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523155926; cv=none; d=google.com; s=arc-20160816; b=yLPAJ1r9qi800gS97Rp1Tw/ZXh+GlKgxIvFhnAsf07pJm60wE5fATcVoJ0QfMP5IuC zN1Znq5MuPKQPCF/8/4xmatjgHD+JbQoTsZlqnzlLdnDKsqRj473tE+2a42BXG/iEmws +qfwRzhUX0AaAihR234iNv69p+GNiRo2jczW5WbUIVX/I3jVm8wJUM02h1EkQH9lRxCI yWBsoLJ4lgioQaXOKwElX1gliovyrNNl5c5IWWxa8T9n0BcR6xDH9NundVA0Ox0hEGj9 qzRxJ47h6osgdIqbXHmE+sw0nBEtzyune+v9p4sZlJrKnU3SmKcC9GVuz5kFCTB0v23F SdBw== 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=lhnOw+TOrXuxEzT7gX/OEFeAVipwIq11IyWzea44LX4=; b=EnnzjPSpbPuj9QjAzNo37WYAhZrJdSZb68eRMdeHbkoPENJD2wWdk7XuInmaQy9z06 eV5+JzrmalmRAtoeOgNtPFJUHz/njxJwOkFs3PfM1bCoWuZKc6Pkp0ivX5ktyPdtPTvq llo9ktvz3E7NYzvZxCM10JFWAIh3iWXJ3t7TBkI71N35i/eoMinOg+yJDKo6BKq5fyyd yccIVNG/vCJXbPiH/ZaCpLAx/K6YM9ED7d9vuctlpZjviujmPzp2uRDLvG5iKNcgbV+x FN25bNbGzbLqtLnqwJsVx+XqrmpwPGG79oLXKUyfQP9tSRKKgvjFZNzMPbLPEeAWSBZp nKwA== 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 w2-v6si11492119plz.206.2018.04.07.19.51.29; Sat, 07 Apr 2018 19:52: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 S1752688AbeDHCry (ORCPT + 99 others); Sat, 7 Apr 2018 22:47:54 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58528 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752572AbeDHCru (ORCPT ); Sat, 7 Apr 2018 22:47:50 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 15BB6EAEBB; Sun, 8 Apr 2018 02:47:50 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-8-18.pek2.redhat.com [10.72.8.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6268A1102E23; Sun, 8 Apr 2018 02:47:46 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: Baoquan He , Andrew Morton , Thomas Gleixner , Brijesh Singh , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Borislav Petkov , Tom Lendacky , Wei Yang Subject: [PATCH v2 2/3] resource: add walk_system_ram_res_rev() Date: Sun, 8 Apr 2018 10:47:23 +0800 Message-Id: <20180408024724.16812-3-bhe@redhat.com> In-Reply-To: <20180408024724.16812-1-bhe@redhat.com> References: <20180408024724.16812-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.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sun, 08 Apr 2018 02:47:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sun, 08 Apr 2018 02:47:50 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 745f2acc3674..ae2c409a0634 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 05b1efa595c2..332a27403c33 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include @@ -487,6 +489,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