From patchwork Sat Jul 25 02:38:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 6863941 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 48DF89F1D4 for ; Sat, 25 Jul 2015 02:46:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 626E7205E6 for ; Sat, 25 Jul 2015 02:46:46 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7A707205DC for ; Sat, 25 Jul 2015 02:46:45 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZIpSD-0000im-W2; Sat, 25 Jul 2015 02:44:50 +0000 Received: from mga01.intel.com ([192.55.52.88]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZIpRn-0000R8-J9 for linux-arm-kernel@lists.infradead.org; Sat, 25 Jul 2015 02:44:24 +0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 24 Jul 2015 19:44:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,542,1432623600"; d="scan'208";a="769352046" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.11]) by fmsmga002.fm.intel.com with ESMTP; 24 Jul 2015 19:44:03 -0700 Subject: [PATCH v2 04/25] mm: enhance region_is_ram() to distinguish 'unknown' vs 'mixed' From: Dan Williams To: tglx@linutronix.de, mingo@kernel.org, hpa@zytor.com Date: Fri, 24 Jul 2015 22:38:21 -0400 Message-ID: <20150725023821.8664.81275.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <20150725023649.8664.59145.stgit@dwillia2-desk3.amr.corp.intel.com> References: <20150725023649.8664.59145.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-8-g92dd MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150724_194423_652646_402159BD X-CRM114-Status: GOOD ( 18.00 ) X-Spam-Score: -8.1 (--------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, toshi.kani@hp.com, linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org, rmk+kernel@arm.linux.org.uk, hch@lst.de, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP region_is_ram() is used to prevent the establishment of aliased mappings to physical "System RAM" with incompatible cache settings. However, it uses "-1" to indicate both "unknown" memory ranges (ranges not described by platform firmware) and "mixed" ranges (where the parameters describe a range that partially overlaps "System RAM"). Fix this up by explicitly tracking the "unknown" vs "mixed" resource cases. In addition to clarifying that "-1" means the requested spanned RAM and non-RAM resource, this re-write also adds support for detecting when the requested range completely covers all of a resource. Finally, the implementation treats overlaps between "unknown" and RAM as RAM. Cc: Toshi Kani Signed-off-by: Dan Williams Reviewed-by: Toshi Kani --- kernel/resource.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/kernel/resource.c b/kernel/resource.c index fed052a1bc9f..119b282985f9 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -493,39 +493,42 @@ int __weak page_is_ram(unsigned long pfn) EXPORT_SYMBOL_GPL(page_is_ram); /* - * Search for a resouce entry that fully contains the specified region. - * If found, return 1 if it is RAM, 0 if not. - * If not found, or region is not fully contained, return -1 + * Check if the specified region partially overlaps or fully eclipses "System + * RAM". Return '0' if the region does not overlap RAM, return '-1' if the + * region overlaps RAM and another resource, and return '1' if the region + * overlaps RAM and no other defined resource. Note, that '1' is also returned + * in the case when the specified region overlaps RAM and undefined memory + * holes. * * Used by the ioremap functions to ensure the user is not remapping RAM and is * a vast speed up over walking through the resource table page by page. */ int region_is_ram(resource_size_t start, unsigned long size) { - struct resource *p; - resource_size_t end = start + size - 1; unsigned long flags = IORESOURCE_MEM | IORESOURCE_BUSY; + resource_size_t end = start + size - 1; const char *name = "System RAM"; - int ret = -1; + int ram = 0; int other = 0; + struct resource *p; read_lock(&resource_lock); for (p = iomem_resource.child; p ; p = p->sibling) { - if (p->end < start) - continue; - - if (p->start <= start && end <= p->end) { - /* resource fully contains region */ - if ((p->flags != flags) || strcmp(p->name, name)) - ret = 0; - else - ret = 1; - break; - } - if (end < p->start) - break; /* not found */ + bool is_ram = strcmp(p->name, name) == 0 && p->flags == flags; + + if (start >= p->start && start <= p->end) + is_ram ? ram++ : other++; + if (end >= p->start && end <= p->end) + is_ram ? ram++ : other++; + if (p->start >= start && p->end <= end) + is_ram ? ram++ : other++; } read_unlock(&resource_lock); - return ret; + + if (other == 0) + return !!ram; + if (ram) + return -1; + return 0; } void __weak arch_remove_reservations(struct resource *avail)