From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.13 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796140885; b=YiEEV2XgI1RyjODD8ca06sw6nqaE2HOi9pIDP3NH7a3wssHAEKcYRsStlJNSJOEXPCaJ K0Etekpm4MAgNXUpAIM/0MdRfLgK8x6oeahmW50vxj6J87GogUHCjXPwy35ZiULaY8dsM DNwUVU1PNwIeyiCys6rvlJ2qVcSsOX2VarYL4cMA9PozEm1R6QZxHCVQWMyjLWVpwTqAM FZD9NhbN9L/YJvtMvdqgM7XT1NC168Mwq2x757Qx7mYz6gWRwRXF+5BaEpGG/NI86frsv mKglRtgKZ08nLBJIxP/+ShUQ6zgkxaoxLbwJElFVsX5ajuNjKmbcG20DR+wa6hMGyxQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796140885; 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=yIs+Duth0mEEI9zKKkqxWhkQbqxwL+a1UGKsCWufv28=; b=SI1FkqudewKuSZldaCI/bAA2hUyNubEPz/S41OoyQNAFrnCCLBG62+1JRP5G1bpnbtcC 1/fTfZqYhXBZPJedSa6J8kv252qLHEU7F3xl0Nf6I8wWeFbv1EQmuWQzFprHCL8oc+cYN 2xS9a4Nu0jBNQgaFEW9PKHABh4uHFXgRAFvRf/q7f5T+iA474vkv7lOBkn2qQV5PN+62s oPxHgpPPRYRzfsxxfX1bN/g6FR8FOQ0z9Ut6jv+x1m5PGekUfqDDBLg/JHgZj37dVQrZD AdBnwv7/V29Xs5XGvr2ouolZYGtM1s2v1598fAbpam3HuOA5SyZvLjeJsdxD6mEz9Gg== 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=ly4pVzu5; arc=none smtp.remote-ip=192.198.163.13 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 52C80606A31A for ; Tue, 1 Dec 2026 16:01:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 52C80606A31A 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=ly4pVzu5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796140886; x=1827676886; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yIs+Duth0mEEI9zKKkqxWhkQbqxwL+a1UGKsCWufv28=; b=ly4pVzu5346a0cNPjRsB8aYbxY8DWP8dJ5xyKG5DJB8OWG6PsRkD4cUb gj7W4Tu/yGTBnpid3zRWqGoofvZynn+gFnZC1GLMFPyhiaiuV8xiZyhJ6 AbEVTkZEC/06/vHdVdRLYe91kESfJw1/X022SOxQXMNvTQr3PfVzjGD04 ThMTC3y3iIx9hFQn/4ncDH0EnSdpVeXJmc/ReolBLJVqfGdAZS2s+FaUj WkHU7xRq8Bw4t97nxYhm4ZSwQ25AmBNlPribglguqmtoKo+GPX695KZ0T aV04S4jnA+qLIKprsUo3UxY9JVoqmEM90g3hd5y2u4nowgBwJRvG6dANO w==; X-CSE-ConnectionGUID: ssB6KIHuRkGwAvIpCi3q4A== X-CSE-MsgGUID: 5AVsQwk4TKu11pFpUKdfQw== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="4991363" X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="4991363" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 08:01:25 -0800 X-CSE-ConnectionGUID: QkdplbxfRdeZ1+YLhaBhzg== X-CSE-MsgGUID: zwWRnWszSAy6UOnvEhOCrw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="4730811" Received: from pgcooper-mobl3.ger.corp.intel.com (HELO localhost) ([10.245.245.21]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 08:01:17 -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, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH 11/15] resource: Make resource_lock and resource tree traversal available Date: Tue, 1 Dec 2026 17:58:35 +0200 Message-ID: <20261201155844.2278-12-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261201155844.2278-1-ilpo.jarvinen@linux.intel.com> References: <20261201155844.2278-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 8d6928c638ff..fbcbdae99887 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