From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.8 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796431356; b=oQmYPHi3gR+hEkh2uEOk8UFpUMHcORpHAj9HW61a/nz5pVO78OeITMCHpG2zsCzdXYsn zz+mV7seBpps290oHpypLTUXCin1CG4aeNbQDDC3bpXdQupEt7L2AgCHmKwsbibe5LpSl wXlMwoaI4J2HpHDy8zaYoSIQa4SOb4hzwuD4DIV03cGEe+natTmwRlSC3xd+aq0e6IINU GJcoDOip8avxRX2HmrKytTTbDcW1LBWR3rufmjn2VNJ48c4eSZDE7m/YUjULu47GfZ78T IECr3h5r0p5R2AAwu9Ipp+bNAiZpJnX5Qg6Iq38uOofuMSB01lZxor/ClgXWoXq4gFg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796431356; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=lUwilEyetG9Pq4P2PV4gaMsPJW3hxRGti8YHb6TEk4A=; b=wPTDSh7rTzpKUTnHmn/jUM55EQVtTtGxxOevN06+MU/LdF0a6te3rtzO3+oeOwI8SbZa Y6q5AyauIEQfQeo7e6x+UDKh7lpb4esv+AqGxVNzepU8gu/ExUm6NrtPn/gSBEcfMVVT0 StHCM0okeqja6msFUxEQi5cl0YcRD5ZtIQbDQvUoUKCdldLzjKfKKHpc6rWTACOQ27IiV fG84Waxt1C1ZJxAsKI7ccakWv3gJqAmtaHDvja67O0NXASDKHSI/0d4b/fdPo8YJe6WRZ g3R9xTNonam0q2mvLsNk160r1IU5vL01a6MjHG5X7RwOVsjKwqvRonhmy9mrsa3jqXw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=bVJLJ+5m; arc=none smtp.remote-ip=192.198.163.8 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DAFB606A322 for ; Sat, 5 Dec 2026 00:42:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2DAFB606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=bVJLJ+5m DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796431356; x=1827967356; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lUwilEyetG9Pq4P2PV4gaMsPJW3hxRGti8YHb6TEk4A=; b=bVJLJ+5mYonjCZqY52SeP39CvLcVBpT4IzNcwLZmvBYIOnM+WJOGDstF j42n12hYWqDeX2zvpRUlfg22BzqqxRkbV1jAOF7crrE44oJB5NSQgsGbv lLbklJkiyzHZiNP6qokAz+BMtzWIy6Nwk5LyR6WOF/pESxlDEliWIrM5y pd1qm3OuVF9CN2xKTZBGKsc8StFPTFRw1wEe+lEqSvU7hFHWgN4sBb8TB gQZ6FwEh9L2JQ8p0GHpKVZZ5EH3PCvSZ1I7D/OJocRsHTpVD7oFXi7KnO 9UabHi99HWccecyqxtw8pplLnBwBNtBzds0ffiKFX8TYHLee50l/d2cHw g==; X-CSE-ConnectionGUID: PkjwegWYQteEr9bGKmrLCQ== X-CSE-MsgGUID: +KdvaSNRTFyPPQK+gPgrZQ== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5308101" X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="5308101" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 16:42:35 -0800 X-CSE-ConnectionGUID: FVEAKhEETROvzyftwGf5Mg== X-CSE-MsgGUID: 1GEbVoMuRVm1zGFREXd4/A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="14412269" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.245.47]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 16:42:28 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Matthew Brost , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , =?UTF-8?q?Micha=C5=82=20Winiarski?= , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , David Airlie , Simona Vetter , dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, Anthony Pighin , linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v2 11/16] resource: Make resource_lock and resource tree traversal available Date: Sat, 5 Dec 2026 02:39:46 +0200 Message-ID: <20261205003957.3304-12-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261205003957.3304-1-ilpo.jarvinen@linux.intel.com> References: <20261205003957.3304-1-ilpo.jarvinen@linux.intel.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Code that needs to look at the resource tree to decide whether it can release a resource together with the resources underneath it has to traverse the tree, and both the check and the release must be done under resource_lock so that no resource gets added in between. Make resource_lock and resource_tree_next() available through ioport.h and move resource_tree_for_each() there. As resource_tree_next() is now public, assert that resource_lock is held. Signed-off-by: Ilpo Järvinen --- include/linux/ioport.h | 21 +++++++++++++++++++++ kernel/resource.c | 21 +++++++-------------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/include/linux/ioport.h b/include/linux/ioport.h index f38800fb957d..830d621907b7 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -14,6 +14,7 @@ #include #include #include +#include #include /* * Resources are tree-like, allowing @@ -241,6 +242,26 @@ extern struct resource ioport_resource; extern struct resource iomem_resource; extern struct resource soft_reserve_resource; +/* Protects all resource trees */ +extern rwlock_t resource_lock; + +struct resource *resource_tree_next(struct resource *p, bool skip_children, + struct resource *subtree_root); + +/* + * Traverse the resource subtree under @_root in pre-order, excluding + * @_root itself. With @_skip_children, only the children of @_root are + * traversed. + * + * Context: Caller must hold resource_lock. + * + * NOTE: '__p' is introduced to avoid shadowing '_p' outside of loop. + * And it is referenced to avoid unused variable warning. + */ +#define resource_tree_for_each(_root, _p, _skip_children) \ + for (typeof(_root) __root = (_root), __p = _p = __root->child; \ + __p && _p; _p = resource_tree_next(_p, _skip_children, __root)) + extern struct resource *request_resource_conflict(struct resource *root, struct resource *new); extern int request_resource(struct resource *root, struct resource *new); extern int release_resource(struct resource *new); diff --git a/kernel/resource.c b/kernel/resource.c index fff69b044a6d..5e3853610b58 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -58,17 +58,21 @@ struct resource soft_reserve_resource = { .flags = IORESOURCE_MEM, }; -static DEFINE_RWLOCK(resource_lock); +DEFINE_RWLOCK(resource_lock); /* * Return the next node of @p in pre-order tree traversal. If * @skip_children is true, skip the descendant nodes of @p in * traversal. If @p is a descendant of @subtree_root, only traverse * the subtree under @subtree_root. + * + * Context: Caller must hold resource_lock. */ -static struct resource *resource_tree_next(struct resource *p, bool skip_children, - struct resource *subtree_root) +struct resource *resource_tree_next(struct resource *p, bool skip_children, + struct resource *subtree_root) { + lockdep_assert_held(&resource_lock); + if (!skip_children && p->child) return p->child; while (!p->sibling && p->parent) { @@ -79,17 +83,6 @@ static struct resource *resource_tree_next(struct resource *p, bool skip_childre return p->sibling; } -/* - * Traverse the resource subtree under @_root in pre-order, excluding - * @_root itself. - * - * NOTE: '__p' is introduced to avoid shadowing '_p' outside of loop. - * And it is referenced to avoid unused variable warning. - */ -#define resource_tree_for_each(_root, _p, _skip_children) \ - for (typeof(_root) __root = (_root), __p = _p = __root->child; \ - __p && _p; _p = resource_tree_next(_p, _skip_children, __root)) - #ifdef CONFIG_PROC_FS enum { MAX_IORES_LEVEL = 8 }; -- 2.47.3