Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1804765pxa; Sun, 2 Aug 2020 22:20:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLyKQFqffnkBYNSpKka78mpdLPBqRZLae8IikNNx4QewrjIsb3NQj6fN/zYJNbtMOvV4pW X-Received: by 2002:a50:baea:: with SMTP id x97mr14261354ede.337.1596432013245; Sun, 02 Aug 2020 22:20:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596432013; cv=none; d=google.com; s=arc-20160816; b=B/GKqiycuYfXHmksbmBvNuIzFnGlzqQcUNJs5GUnxkMwCI78olg/Wb8ksPSUnX0Mg/ zHsKzD/XWoYW8D4+SYH+h9FvGNKy/tCNp1fjEc3Da8gk+yorWYVbasUPvJk4EMjuxpsX c0oqSozyzU4V0h1a+AKzJZYgTMmQipPeYzeVHGqSWFRd4Q2a64sMfCbkg7L4ioxBnrwa byo02ZMl8MVbtG/gxwsNUbhXTMTRUvW1wdJoFDmnI/eKXtTk8x0CANpXs5cBVkS2a25c kzMO1xOz3o5Nl7mpVNUBZl1FqCXX0y9UivNLOSC4d7IQ9Ln8nAzhrX8wDhFjbwJ6MyOS lneQ== 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=gp3SPewvoBnA4kXIfXncCaHdJmyecsm6su/nKAuEVdWTJOcOj+/KgJdwdMeV6vjCV/ RmNRaMS5uRPiZqZ9urlB+8W2CagFlyUEu+U4fRPVYDhPX5Lj1RVHzd2G2y/K4eP4tzI9 ctGMbnV1fl7dqHdpWNK82HJTyAAG6aThpjeacHAaJXvmakc7IdKueb80l2ngRkwF5FyI MCzt9toB/ST5UPfr7CwES5srIVw4kg3xb30XW/20YoElUxoPRkCxU+dR+BsFWa8dA3En GX6yQpiHG+ttkwsPS4XYeDLR8DTybzZY+W/NtsaZ+K4ZmrF9N/lP5+hmQfwhLt+0Vvw5 w2FA== 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 f12si9271762eja.367.2020.08.02.22.19.51; Sun, 02 Aug 2020 22:20:13 -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 S1728076AbgHCFTM (ORCPT + 99 others); Mon, 3 Aug 2020 01:19:12 -0400 Received: from mga03.intel.com ([134.134.136.65]:21020 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728008AbgHCFTM (ORCPT ); Mon, 3 Aug 2020 01:19:12 -0400 IronPort-SDR: 7yPK2cc2FD8w/NFAlPX1Pi2i8YdPzy9XtS6HmO12SjR4IJEMltgwe47Cwe/6ucTJ17/msmMNiK Zv4OY9vZLJ4w== X-IronPort-AV: E=McAfee;i="6000,8403,9701"; a="152015629" X-IronPort-AV: E=Sophos;i="5.75,429,1589266800"; d="scan'208";a="152015629" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Aug 2020 22:19:11 -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 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);