From patchwork Mon Aug 3 05:02:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11697187 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6515D138A for ; Mon, 3 Aug 2020 05:19:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 32A24206D7 for ; Mon, 3 Aug 2020 05:19:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 32A24206D7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id ECC3F8D00DA; Mon, 3 Aug 2020 01:19:13 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E79A38D00AA; Mon, 3 Aug 2020 01:19:13 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1B738D00DA; Mon, 3 Aug 2020 01:19:13 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0038.hostedemail.com [216.40.44.38]) by kanga.kvack.org (Postfix) with ESMTP id B989E8D00AA for ; Mon, 3 Aug 2020 01:19:13 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 7CC131EE6 for ; Mon, 3 Aug 2020 05:19:13 +0000 (UTC) X-FDA: 77108103786.18.grass47_23119b326f9b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 585C4100ED0DB for ; Mon, 3 Aug 2020 05:19:13 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,dan.j.williams@intel.com,,RULES_HIT:30054:30064:30079,0,RBL:192.55.52.151:@intel.com:.lbl8.mailshell.net-62.18.0.100 64.95.201.95;04yguubouya7iwauydfkhoszepqzhocnx4idhtwymbyezwtzhqcdwexyjnhuain.twkgkrc1f1zgznfaw5a86jpkohmytxibmx9kqj4jdyudr5xoaqzwoc5oewac1b6.y-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: grass47_23119b326f9b X-Filterd-Recvd-Size: 3943 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Mon, 3 Aug 2020 05:19:12 +0000 (UTC) IronPort-SDR: OhxB3BZihn3ak7CcvhNCWwqUKi3tX6hEo6F+BhXfzQk/1Rz3kOUdXDS/Wc+P8VN68Nta6bu+1R OPXL4WFS5iFg== X-IronPort-AV: E=McAfee;i="6000,8403,9701"; a="132105557" X-IronPort-AV: E=Sophos;i="5.75,429,1589266800"; d="scan'208";a="132105557" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Aug 2020 22:19:10 -0700 IronPort-SDR: 8ZbSyWkuiQpaoznBPn1FxKc+srq2l6P5lOudvhAUNkNIJsl+a3nncXA0wCho+X3KpHCpnstaPs RdjCl47Fzn1A== X-IronPort-AV: E=Sophos;i="5.75,429,1589266800"; d="scan'208";a="314537621" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Aug 2020 22:19:10 -0700 Subject: [PATCH v4 05/23] resource: Report parent to walk_iomem_res_desc() callback From: Dan Williams To: akpm@linux-foundation.org Cc: Jason Gunthorpe , Dave Hansen , Wei Yang , Tom Lendacky , peterz@infradead.org, vishal.l.verma@intel.com, ard.biesheuvel@linaro.org, vishal.l.verma@intel.com, linux-mm@kvack.org, linux-nvdimm@lists.01.org, joao.m.martins@oracle.com, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, dri-devel@lists.freedesktop.org Date: Sun, 02 Aug 2020 22:02:51 -0700 Message-ID: <159643097166.4062302.11875688887228572793.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <159643094279.4062302.17779410714418721328.stgit@dwillia2-desk3.amr.corp.intel.com> References: <159643094279.4062302.17779410714418721328.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 X-Rspamd-Queue-Id: 585C4100ED0DB X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In support of detecting whether a resource might have been been claimed, report the parent to the walk_iomem_res_desc() callback. For example, the ACPI HMAT parser publishes "hmem" platform devices per target range. However, if the HMAT is disabled / missing a fallback driver can attach devices to the raw memory ranges as a fallback if it sees unclaimed / orphan "Soft Reserved" resources in the resource tree. Otherwise, find_next_iomem_res() returns a resource with garbage data from the stack allocation in __walk_iomem_res_desc() for the res->parent field. There are currently no users that expect ->child and ->sibling to be valid, and the resource_lock would be needed to traverse them. Use a compound literal to implicitly zero initialize the fields that are not being returned in addition to setting ->parent. Cc: Jason Gunthorpe Cc: Dave Hansen Cc: Wei Yang Cc: Tom Lendacky Signed-off-by: Dan Williams --- kernel/resource.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kernel/resource.c b/kernel/resource.c index 841737bbda9e..f1175ce93a1d 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -382,10 +382,13 @@ static int find_next_iomem_res(resource_size_t start, resource_size_t end, if (p) { /* copy data */ - res->start = max(start, p->start); - res->end = min(end, p->end); - res->flags = p->flags; - res->desc = p->desc; + *res = (struct resource) { + .start = max(start, p->start), + .end = min(end, p->end), + .flags = p->flags, + .desc = p->desc, + .parent = p->parent, + }; } read_unlock(&resource_lock);