Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp395346ybh; Sun, 12 Jul 2020 09:45:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx923r/y77/uXsZVJ6Mq1RJzUstdX6DlihQyV8LKxJZBQg1tWtule4aUU7Kqb3/eh1otM2Z X-Received: by 2002:a17:906:57da:: with SMTP id u26mr72173796ejr.157.1594572345758; Sun, 12 Jul 2020 09:45:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594572345; cv=none; d=google.com; s=arc-20160816; b=xt+QUWXpoc5SZh7E0W/nZJaZiD9MB1LaOKC3ktMxHFRpAqnIxbamB3ryMqtto8GDLj Z8Rlv44PkBNz9mmMoefum/UvK6+Jt31TJQqxr/4BUcu4RkS5+z8iDes60Li9mZOleszR 3Rw1qrFCnRQdgKvhRMlxPJFQa068T6KG0eFGxFuEtoLkMyz1uPUvArDeUXz5B4UAmoaq Z6T7lrKDD92hcrmc3nRUJ32vSSaYkUocil8iS0gJhO7BKnfN8XMyp/TU64gDwrQAOPwP w9EasuD1YoF50XqAYwsHzbpArGHtJ44cXupskTXLgc1wpZNXEtJYHm1OXEJLHnIeKXCb qzMw== 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 :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:ironport-sdr:ironport-sdr; bh=wkmcZcOcrJYrEfxhoWGjpDsSPLKT+Jxt3szhiESUlDY=; b=ZeABn+Bgdvf88eiwkO0gihqPK886zLM/ezqGLRyDVydehAxTu7QpmTyrkxseUsRe/X 1NYu6tyAy/yJtuikFvA4iR+8ZLNjFzC0qdWONvZGeb2RlzC3v5v5BBgvvoFAqG6C9CWK Y7JI7JeuDqDVoOb9BOjbo8MZsxURTd8aBwBJ10gsgUK1amJmWFG5hRcw12h3i5nKJuOk WkAFiDFZBCqEnH2W5k202qmcFYpYRcB7KftzESt5eIWHdJRk3svY3r0B8IG+HOff+Ws9 57LhTDAjklAm3EV4Prhlni6J6PihaPEyvEDMuR4w7JgFhl3/nIHuk9PGKOMB6twH2xpt k2Zg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w24si7079178ejk.712.2020.07.12.09.45.23; Sun, 12 Jul 2020 09:45:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729185AbgGLQmz (ORCPT + 99 others); Sun, 12 Jul 2020 12:42:55 -0400 Received: from mga04.intel.com ([192.55.52.120]:7743 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729169AbgGLQmu (ORCPT ); Sun, 12 Jul 2020 12:42:50 -0400 IronPort-SDR: kPZ84riN4sw6qDrvJg1dprPiVTLjU8pRGZja2Z/Gv1yk2Wl12Kbny57WECLWet+8YLP0hc5kus 9/Ytsp+wx1ew== X-IronPort-AV: E=McAfee;i="6000,8403,9680"; a="145998859" X-IronPort-AV: E=Sophos;i="5.75,344,1589266800"; d="scan'208";a="145998859" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2020 09:42:49 -0700 IronPort-SDR: ZzOMBq0ET8igwu4TZFb4M2OdcM55gg/QlESleodkOsbeBEKm9gKJZLYMr9qCqV6UMIu2eGNtXI gaVJXoQw7NRA== X-IronPort-AV: E=Sophos;i="5.75,344,1589266800"; d="scan'208";a="458998362" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2020 09:42:48 -0700 Subject: [PATCH v2 05/22] resource: Report parent to walk_iomem_res_desc() callback From: Dan Williams To: linux-nvdimm@lists.01.org Cc: Jason Gunthorpe , Dave Hansen , Wei Yang , Tom Lendacky , peterz@infradead.org, vishal.l.verma@intel.com, ard.biesheuvel@linaro.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, hch@lst.de, joao.m.martins@oracle.com Date: Sun, 12 Jul 2020 09:26:33 -0700 Message-ID: <159457119303.754248.2238364198589067082.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <159457116473.754248.7879464730875147365.stgit@dwillia2-desk3.amr.corp.intel.com> References: <159457116473.754248.7879464730875147365.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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);