From patchwork Sat Aug 1 03:25:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 11695735 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 55E4C13B6 for ; Sat, 1 Aug 2020 03:41:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2B3152245C for ; Sat, 1 Aug 2020 03:41:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2B3152245C 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 19B8C8D006C; Fri, 31 Jul 2020 23:41:49 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 173AD8D0068; Fri, 31 Jul 2020 23:41:49 -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 088D68D006C; Fri, 31 Jul 2020 23:41:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0040.hostedemail.com [216.40.44.40]) by kanga.kvack.org (Postfix) with ESMTP id E67A58D0068 for ; Fri, 31 Jul 2020 23:41:48 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id AC7A1180AD80F for ; Sat, 1 Aug 2020 03:41:48 +0000 (UTC) X-FDA: 77100600696.08.bike51_4c0c39726f89 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 852DF1819E785 for ; Sat, 1 Aug 2020 03:41:48 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,dan.j.williams@intel.com,,RULES_HIT:30054:30064:30079,0,RBL:134.134.136.31:@intel.com:.lbl8.mailshell.net-64.95.201.95 62.18.0.100;04y87k8nzmp5xj79iow3c3sgqja7yocnx4idhtwymbyezwtzhqcdwexyjnhuain.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:23,LUA_SUMMARY:none X-HE-Tag: bike51_4c0c39726f89 X-Filterd-Recvd-Size: 3942 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Sat, 1 Aug 2020 03:41:47 +0000 (UTC) IronPort-SDR: +NXRHN9baz4+qI4DOTGMrf2fgjl6ROaqptE///9EHoxAyuPFSTNAKZgesXuwYTAnqJEBfVWvDf qsIVUmEd8VAg== X-IronPort-AV: E=McAfee;i="6000,8403,9699"; a="213438736" X-IronPort-AV: E=Sophos;i="5.75,420,1589266800"; d="scan'208";a="213438736" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jul 2020 20:41:47 -0700 IronPort-SDR: e3n7QjNdU9Y2kvg/YuTFVsHi/u3CvHT/O+EWhzOCkRhj3ddVnVfce6sMGJY08fskipYBVKlcP+ 3mllkaRHMBNQ== X-IronPort-AV: E=Sophos;i="5.75,420,1589266800"; d="scan'208";a="321647307" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jul 2020 20:41:47 -0700 Subject: [PATCH v3 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: Fri, 31 Jul 2020 20:25:29 -0700 Message-ID: <159625232903.3040297.3259451012924415121.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <159625229779.3040297.11363509688097221416.stgit@dwillia2-desk3.amr.corp.intel.com> References: <159625229779.3040297.11363509688097221416.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 X-Rspamd-Queue-Id: 852DF1819E785 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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);