From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21821361DB5 for ; Mon, 23 Feb 2026 10:06:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771841210; cv=none; b=ZkPWkqC9hNt1ST0JcZZx6CyC8ikPKXQAEem1Ouw4tSBj2gVB+IRX5HpmUGsjEHZymgxtH0QsUi3FV5bMlFyDyfb1YOhZXB9mztG550nue1JMpg646wM8ddND79LkbY8ePK0O8WfQ3i4GfWbfsHSe/n5LAjmOMCgMs+wjio0Bg50= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771841210; c=relaxed/simple; bh=XIaVIFGyKxRFAVNTCoC6mtQQ9fiI4L7RdNBVhpzo77c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=R5Wb62J9Ffz2jqN9o6gznsP4nb9Gmq33ARaaKGZasUuaLi32larWqRloywM5X+StdIOsztghqviDag9PY0HXNBzn4Xf5RRt8wwtfyMC71ZTcaun1n82dy931/+UQ18npxZahrQRwxl/f/hk/fYo5rCvvZ2QfTAtFJRcNSEzLMEs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=ZMa7iH1S; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=aWmj2GVm; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="ZMa7iH1S"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="aWmj2GVm" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 61N8xHmr2320254 for ; Mon, 23 Feb 2026 10:06:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= MCKmBMM6OnSuHzXoHkqHCseMHs6O0rCeUxE/L5JsgZ0=; b=ZMa7iH1SIuVMec3d Gq3qCDaH7/FxAVSzhx41j97PBvFuEu+A1bSQT4KfjyjbwilqI9hJMKmN/41wAhhX E+sYhZoYQcHP1wcpodhJivbo0nu7S6+AoroL/wZnETAWdqvztEbueYU+Q3s8Vmne CZ9MO0pwfaVQn/bUgTMZ/ColEigvKkKsNuTfm3OEZiGmsUk4kJ0D2uelvlTN3H8g B0L8gstPpoRomABfmQov843auKk0ZQWTYFDMEk1Ls3NyQjFCF7x6b6Ev5ZrjOd0N +ZARGMtAx/6gQsYHVL/YjZv1nWWY9Glk630ZsjXjBwkONmuTwS6beGQr9HxQgRLC Uta6/Q== Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4cf5vj47nt-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 23 Feb 2026 10:06:47 +0000 (GMT) Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-8c71500f274so464239085a.1 for ; Mon, 23 Feb 2026 02:06:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1771841207; x=1772446007; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=MCKmBMM6OnSuHzXoHkqHCseMHs6O0rCeUxE/L5JsgZ0=; b=aWmj2GVmgoMTam7hPMex73wAaB3vQA34AwVk821vvf0lizvXqs8rFPpKXHUYx7Zw+C W616OCL7T5mfUumKSdS+KRprU72tgJp8UfDAgsoFgfY9DgTeKuoNG40WVOw9xpVQwyhF 6PRb5FDZrksfyZVC2awELg6ZAeK0EJpUcHHj/OkSixZhPk9OqdcMZwCCEAqw7V+dm972 RpYjbH4jI0KJbA+hczIXGuia4noQxHELbgzhJfW1J25vsF7v42zRS9EkrtpoLMZ3nRGB Lq+6udqFjgdDwinzx1I/nUKKgRQVqzzRIUMOHLH5NA6rpCTtiabUxYs+5G4eD0H14Jka dunA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771841207; x=1772446007; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=MCKmBMM6OnSuHzXoHkqHCseMHs6O0rCeUxE/L5JsgZ0=; b=GjPJWn8LwF0F0oDND+ffy4WcUvEKivdbRwoQZ4Zr3WZafNZ8gGfC9BS/CWjsbeH2V6 SLMKvNx+rX/8+YMi1p0EjfpeJx4JdLv+w5hej4GAXjhwME0c0dzBXwRkpGkDGdhQeQ6B qzTtnkYri+A1ii89WDlVGqUgaP7v6FoFuKdzcEoNoBuQalVrVfYDgvjyKm+nUibIskrq DqlvXlu8wxEk50JiZN2lyOln2lF9l+mU3TKWRYZPiKcBDvUeDnz/6LXiZmaWxPa6jPwE +7Va3YPjdh6MmU6b7XZMYVE+/OU49mfx1kakLiyo2Dk56m68Cuqd+q6id2b3FtB6u3Op NkbA== X-Gm-Message-State: AOJu0YzUwiJu/n2eF7w1xpS29dMEdw4pT4ABvVbCkjqDEXizUVUpIpSX 9f6A2ezHB3hpwSpXTiHkyzSUyogOoWycSDZZNZFv3QNrqhNitvfM28SX4MnLkKReuFQFnHiBBek 7/ppkJ5n8nPxjLuf9md0xTqjOLG8da+d1ZjQxl4RLNMhjPAt1ua/xyQ4chn6/V01h5jA= X-Gm-Gg: AZuq6aI9BRMdpBs2jdSEFLHyeobx++TxGriDBhNeBegBUdS0xbyOOJMkOil3ZU+Jfl4 mgQRhzJUTW/py+hwzxvAH01pXeg4ZjO2n7ITXfMwOWk3XX+FbtnqpIgvPHMyXKKIf8oOFM7KXt6 qr8dpOoF1kQE1/ugwRLQoO9tMvGREi8bX8DBjeCnnDnLV98geW3ycoHt2246RwyvKGLvj6eUrpI 0snnxGpQXWEyW2soL3BzXUDsxAUUlcBl9N3bNFSb/cDahHfSn752wIF9Mj4N22TOTi7esO3SyGu AhcfUdOzGDfXIGeiz231dMOa/t5/RDkloekqlNJg9o42JwbbHpdod76ha4GjRG3A0TAyXdE/U04 LBxpcwm59n6w9ju+qTcgMBOMJg++bgEKiIh0knnmlzHum2etszNV6 X-Received: by 2002:a05:620a:4491:b0:8cb:4ba9:cce6 with SMTP id af79cd13be357-8cb8ca83450mr1008628185a.66.1771841207308; Mon, 23 Feb 2026 02:06:47 -0800 (PST) X-Received: by 2002:a05:620a:4491:b0:8cb:4ba9:cce6 with SMTP id af79cd13be357-8cb8ca83450mr1008624985a.66.1771841206762; Mon, 23 Feb 2026 02:06:46 -0800 (PST) Received: from brgl-qcom.local ([2a01:cb1d:dc:7e00:bd71:422c:5e83:8b37]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43970d54760sm18288885f8f.35.2026.02.23.02.06.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Feb 2026 02:06:46 -0800 (PST) From: Bartosz Golaszewski Date: Mon, 23 Feb 2026 11:06:22 +0100 Subject: [PATCH v2 09/14] reset: protect struct reset_controller_dev with its own mutex Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260223-reset-core-refactor-v2-9-5e5a7289190c@oss.qualcomm.com> References: <20260223-reset-core-refactor-v2-0-5e5a7289190c@oss.qualcomm.com> In-Reply-To: <20260223-reset-core-refactor-v2-0-5e5a7289190c@oss.qualcomm.com> To: Krzysztof Kozlowski , Philipp Zabel Cc: linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4635; i=bartosz.golaszewski@oss.qualcomm.com; h=from:subject:message-id; bh=XIaVIFGyKxRFAVNTCoC6mtQQ9fiI4L7RdNBVhpzo77c=; b=owEBbQKS/ZANAwAKAQWdLsv/NoTDAcsmYgBpnCaohGyBCuO5ufMCfJpv/H6sQTR+qZKMUgq02 jWEgVJR1GqJAjMEAAEKAB0WIQSR5RMt5bVGHXuiZfwFnS7L/zaEwwUCaZwmqAAKCRAFnS7L/zaE wyGUD/kB8IqpNC2SAEfXA09Y5xTU+6fF449xNcfbSsinqRrN5f8kXGRPlPOV0ZGUMdGaoPCPu82 Kn9OroAaUa69LxGdwc+IrgwIYO/RYqDgW5gtaNeDWLGqKksxXfHg+YZYmBy3G9ckl7vsMxFZr1+ VB3gQ7dH4KM5PulAEFs/TWpke47fF0J+Bmt38EAOeeTVB8i+L/aQDxSr/SsQ7fvZ5d79yZR4Q8z ygfAKXRO3SdYjKmeOr96P03LNPby5FMHFBoyVuFjMVLACtXS0FOymBWcnqcpBg3T1ld9rIoLvH5 5Wif9aA/+Oi2lXlUpzaCcvCeSw37dUYx7elho7MR7ddJw7AOfwuprt1a6pVhA5GJKi/KBIyOLdZ BySOjt/lrV3YqhwwWaVc8bZPa+JlREFFjJ7cEjn6vRvU7Y7yGfxSsL8wMpCDkDLfLWVQpyPiE/X 7TwWbntI5j9EFjAhzN/dbh/jTjOvCj24JEsNWNpbvZcFWzFFXwkUpGrbKNRuqANko6oNiZEHZLo eO52rQavFLrxPQDPSFkIsCrfFldQj1c0EIR53NiPTYdkkqEtc5JCXpi52NJcSxATXnMH+cZ/K3q YSv7E1B4LMRV/Q4e8LQzz8PVj+o4JmLwnL5A6REXsAzKkEk59F5KF8UCxSgmhig6tXAYQpo+DCx WjLLjqe99/dy7iw== X-Developer-Key: i=bartosz.golaszewski@oss.qualcomm.com; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMjIzMDA4NiBTYWx0ZWRfX7uhdCIMqfEtP ld+Z79Ax7TErUm3yTFNeP3HWbd8IuaDiKFwzCqdQDXgOf0+GtynmNPzwJkV60/bdM+SGaBUlHYN loe45yuTnlAbV5hMwCJsZcxuUubJRLx5yJIKNgfewnaWDrHUgxeYiorXVhjmTSGavfoV+xsD0za EUUmiMC0mC7ikpUDEqxcYeCytlt585a1zgBv2LNrGZOUP38SXqFsxm0iF1glB9U8SJ0TR7X13UB 3CJhf2jmdyubBoWopkcmPGlQoJv4WtEjwBma0JcbSUrocUSTlav9+sUaW4nxXzbbyzKq+APQcoQ 1XbzflB0Jwia+G1/YG3IPepy0RdB9ot2BjNYGOja+59nr+ik+BJ7l4sTdNogpBgLKPtKapTxAbh vF4IUDNLzUBlE5m5vBEZV3JPg7VQ25AYSr/O832Tfu8BGVp9na7h1DXR0gpZjP1L5B/Q/4B+tvR LMNp335OZkks68mx6Sg== X-Authority-Analysis: v=2.4 cv=T5KBjvKQ c=1 sm=1 tr=0 ts=699c26b8 cx=c_pps a=HLyN3IcIa5EE8TELMZ618Q==:117 a=xqWC_Br6kY4A:10 a=IkcTkHD0fZMA:10 a=HzLeVaNsDn8A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22 a=EUspDBNiAAAA:8 a=nQ7P6-40-II7rw7jOZoA:9 a=QEXdDO2ut3YA:10 a=bTQJ7kPSJx9SKPbeHEYW:22 X-Proofpoint-GUID: BXINIbumMj93IFrguGR5VwuGnzOtBLkd X-Proofpoint-ORIG-GUID: BXINIbumMj93IFrguGR5VwuGnzOtBLkd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-02-23_02,2026-02-20_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 malwarescore=0 priorityscore=1501 clxscore=1015 phishscore=0 lowpriorityscore=0 adultscore=0 impostorscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2602130000 definitions=main-2602230086 Currently we use a single, global mutex - misleadingly names reset_list_mutex - to protect the global list of reset devices, per-controller list of reset control handles and also internal fields of struct reset_control. Locking can be made a lot more fine-grained if we use a separate mutex for serializing operations on the list AND accessing the reset controller device. Signed-off-by: Bartosz Golaszewski --- drivers/reset/core.c | 44 ++++++++++++++++++++++++---------------- include/linux/reset-controller.h | 3 +++ 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/drivers/reset/core.c b/drivers/reset/core.c index 96199e7b0dd7c89c5a11e2e2c3e5eb7fd5d49355..d4813c712abf3df7993b0c2be1fe292b89241d11 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -131,6 +131,7 @@ int reset_controller_register(struct reset_controller_dev *rcdev) } INIT_LIST_HEAD(&rcdev->reset_control_head); + mutex_init(&rcdev->lock); guard(mutex)(&reset_list_mutex); @@ -143,6 +144,8 @@ EXPORT_SYMBOL_GPL(reset_controller_register); static void reset_controller_remove(struct reset_controller_dev *rcdev, struct reset_control *rstc) { + lockdep_assert_held(&rcdev->lock); + list_del(&rstc->list); module_put(rcdev->owner); put_device(rcdev->dev); @@ -156,19 +159,22 @@ void reset_controller_unregister(struct reset_controller_dev *rcdev) { struct reset_control *rstc, *pos; - guard(mutex)(&reset_list_mutex); - - list_del(&rcdev->list); + scoped_guard(mutex, &reset_list_mutex) + list_del(&rcdev->list); - /* - * Numb but don't free the remaining reset control handles that are - * still held by consumers. - */ - list_for_each_entry_safe(rstc, pos, &rcdev->reset_control_head, list) { - rcu_assign_pointer(rstc->rcdev, NULL); - synchronize_srcu(&rstc->srcu); - reset_controller_remove(rcdev, rstc); + scoped_guard(mutex, &rcdev->lock) { + /* + * Numb but don't free the remaining reset control handles that are + * still held by consumers. + */ + list_for_each_entry_safe(rstc, pos, &rcdev->reset_control_head, list) { + rcu_assign_pointer(rstc->rcdev, NULL); + synchronize_srcu(&rstc->srcu); + reset_controller_remove(rcdev, rstc); + } } + + mutex_destroy(&rcdev->lock); } EXPORT_SYMBOL_GPL(reset_controller_unregister); @@ -712,10 +718,12 @@ int reset_control_acquire(struct reset_control *rstc) if (!rcdev) return -ENODEV; - list_for_each_entry(rc, &rcdev->reset_control_head, list) { - if (rstc != rc && rstc->id == rc->id) { - if (rc->acquired) - return -EBUSY; + scoped_guard(mutex, &rcdev->lock) { + list_for_each_entry(rc, &rcdev->reset_control_head, list) { + if (rstc != rc && rstc->id == rc->id) { + if (rc->acquired) + return -EBUSY; + } } } @@ -806,7 +814,7 @@ __reset_control_get_internal(struct reset_controller_dev *rcdev, struct reset_control *rstc; int ret; - lockdep_assert_held(&reset_list_mutex); + lockdep_assert_held(&rcdev->lock); /* Expect callers to filter out OPTIONAL and DEASSERTED bits */ if (WARN_ON(flags & ~(RESET_CONTROL_FLAGS_BIT_SHARED | @@ -868,8 +876,10 @@ static void __reset_control_release(struct kref *kref) scoped_guard(srcu, &rstc->srcu) { rcdev = rcu_replace_pointer(rstc->rcdev, NULL, true); - if (rcdev) + if (rcdev) { + guard(mutex)(&rcdev->lock); reset_controller_remove(rcdev, rstc); + } } synchronize_srcu(&rstc->srcu); diff --git a/include/linux/reset-controller.h b/include/linux/reset-controller.h index aa95b460fdf86f10002a465e285cd0119da6eeaf..2fecb4edeba1a2b1f5f5db2b34c867362c5f9c18 100644 --- a/include/linux/reset-controller.h +++ b/include/linux/reset-controller.h @@ -3,6 +3,7 @@ #define _LINUX_RESET_CONTROLLER_H_ #include +#include struct reset_controller_dev; @@ -40,6 +41,7 @@ struct of_phandle_args; * device tree to id as given to the reset control ops, defaults * to :c:func:`of_reset_simple_xlate`. * @nr_resets: number of reset controls in this reset controller device + * @lock: synchronizes concurrent access to the structure's fields */ struct reset_controller_dev { const struct reset_control_ops *ops; @@ -52,6 +54,7 @@ struct reset_controller_dev { int (*of_xlate)(struct reset_controller_dev *rcdev, const struct of_phandle_args *reset_spec); unsigned int nr_resets; + struct mutex lock; }; #if IS_ENABLED(CONFIG_RESET_CONTROLLER) -- 2.47.3