From nobody Thu Apr 9 17:58:39 2026 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.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 A91A5425CEE for ; Fri, 6 Mar 2026 17:23:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772817813; cv=none; b=AMpmvUEAy7H6oY8BNG4ABLmbm16Z5B1CCBQwBsAoubvEgwvoX9gfdL6GfnyPQ/fY8sJ6yYLbWF2QkdBFueijJrhnAkSwaK2y9KDM+fNls4HLptuIBhU/aeb7rv1dOUaac8DppqwpgJTgxIabAegV5Gi/vH9pIIyJwR29+6wWAD0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772817813; c=relaxed/simple; bh=cFVRek2ApJRDsXIzvIHRimHH12mRJMFB9qA0OR3X75s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lpwsMZZH4eXEm0yq1j9XF0Hzuy17c4oasgj2X9jACqWX87pJdHlzCNtwcPWfZS431Xn1Lujs8UXEonSmWfRV4D/cQ6OMAxCt++LpbbjKZbOmetqy+Ia8Q869bQAAdBRwDYpqk9SshdBWWd5EqRxZWghn9eDdDgi4XlprLuG/21o= 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=XuDEZbTB; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=eBgLCJle; arc=none smtp.client-ip=205.220.168.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="XuDEZbTB"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="eBgLCJle" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 626H2PCe742675 for ; Fri, 6 Mar 2026 17:23:31 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= Mvf/fMp10klr3lNcw5FhLLQnphhOnIvjXrPlO1YIOoA=; b=XuDEZbTBDUms0QL3 pFHun+6dMmZl22RgOFv5W6Ag0v5s4encCtJ3efLqQzC2Zx6Yu2ch3aiLDcB8NDdZ PDGuL53/ZPNMq6Z4HCsAk++Je84zgNgzN+NAf0R5HWfM678CLKCLe6krhHFnOEM6 pGUHt2Y8oCXy2ZEO4CqpX/zFck0ItQwBQc7nAFhA/Rk/BtSK4pMJ1aA7jrV7QYve hdmD08c13KFofXIGntrQEvKwQs8ENpa5GHbCXlp20mLR2kypV/FPfTOBWLpNaenj /2RtjtpNF7wo9ORVcFayT+dwWp3D5zZikxHEzqEOfFM0fw/NfnAZf+iNa9m2MWAq MpFJOg== Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4cqpxdtqbe-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 06 Mar 2026 17:23:30 +0000 (GMT) Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-8cb3ff05c73so4808261985a.0 for ; Fri, 06 Mar 2026 09:23:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1772817810; x=1773422610; 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=Mvf/fMp10klr3lNcw5FhLLQnphhOnIvjXrPlO1YIOoA=; b=eBgLCJleTEdO0QfhkCsSl5R5t2P0hJP88DDTqb3Zhw/z2anYp7PhuLbEEM2Rs3b4t2 CRUptjSHK6UJb3Vz2vmpYvrwSNK78MvRTLTynzSpOIUbdcoYoqaIe3ba/Y5TC7KqRisW eWf/67bqJjYVgFAzLxeRemwMBIzWCqc/v379Z0eY+9eSHaon0iJ++QI1kaD9hxi49avy 8ZRdDI1OvJqNDzMlrAYyZSSbkVKHTPGwqRFkpVoZsio0ysRoBDmotBv9juABvU7iFsQS fwrBkggOIHg47NAwur8Axoomo1dkycEhxS7iJmmlpKBstEfCh8azICzD45HUjVOcTddD erRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772817810; x=1773422610; 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=Mvf/fMp10klr3lNcw5FhLLQnphhOnIvjXrPlO1YIOoA=; b=YOFwpZQAO0SI48AulGDfPg7KZ/Tkq6B1l9QUCU60ufgCKut02hf4wJdZAnCeI/NGZr 0M33rrXZOedF2BM9VvsnQvHkDP8qe3+YU4q3NGu/o8Z6UTyyplWh+tvdsMVWnAipyP2i YR1y5AHd/XWA+vRwRPISE59HcRjTT16WmtmBmTZLFxt5wZJB0FKlHyrL1HKxtsn2WBeP qBFpccgCcUVSBo12FDtoliMlLamVxb8JyPopMlbPP2IJyRzm4V18Yicy+x/coeFD2zRR uDq9XQip2qxlAvzlj1D8jO6gthN1QIEjcqEiCuVXooA1h6nj0N7KzHWJPDn6RfLkJ+nE SVNg== X-Gm-Message-State: AOJu0YxXX/zODaZNOKc1/54uZpgCqBb0fEqkkrD6OW5WDrgpwQTnYlwv 9iNt8mFy3TBlTcMyyI6pUNL9jDa9pn4RhPZZPDumza0cLooemStlronvXB0Xj1tw3KjtewscQSp 1z6uyVYhdNJLe+Te90hAFGZUUt4AXO3MzUUY1+GdL9Q11RrUxCxSrVxM+fACd8kPrN2Au44jrXT 4= X-Gm-Gg: ATEYQzwBWPrm/6qCSIctUJtsz/sz1gxDKYrahaQ0Lc4kcatMXQir8vj/o9H8De5VAOn faJ1P8gj3fZsTgltRxFP2HFUYlAJt3ZEAO1NzWByr2A2FJcWLMrExUvv6PjsMb7fbOMsVzDM03H Ia2/k/JUm/w3mT4ZXqgjwAsDbSTCrULm/HiwWH0iBcRC5mChTfhLGqp4NroHp/8lEWx3RyR01fn x4waS+50NxWrXM34lPrYIA7m45aFOMp/8h82/Wniy4rbxtgO668xfIOUs4broEn+oC1OWZYRK/R r1ksBFpaZDM6zscwn9YarxVOaXK2cmJ03nv8YBU25W3lDR7EuOpU+s51NKqN2NBoA6gCv4wXGzj cf3bgTnJ9oHuvZ3qnqT6+WrUr1HAC0MFnrDe09/SdE0RREI2m5dTw X-Received: by 2002:a05:620a:4048:b0:8a9:ef98:6835 with SMTP id af79cd13be357-8cd6d427f8cmr362535885a.33.1772817809752; Fri, 06 Mar 2026 09:23:29 -0800 (PST) X-Received: by 2002:a05:620a:4048:b0:8a9:ef98:6835 with SMTP id af79cd13be357-8cd6d427f8cmr362530285a.33.1772817809266; Fri, 06 Mar 2026 09:23:29 -0800 (PST) Received: from brgl-qcom.local ([2a01:cb1d:dc:7e00:28b1:4950:7702:bb20]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48527686fa9sm61488475e9.8.2026.03.06.09.23.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2026 09:23:28 -0800 (PST) From: Bartosz Golaszewski Date: Fri, 06 Mar 2026 18:22:54 +0100 Subject: [PATCH v3 10/14] reset: protect struct reset_control 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: quoted-printable Message-Id: <20260306-reset-core-refactor-v3-10-599349522876@oss.qualcomm.com> References: <20260306-reset-core-refactor-v3-0-599349522876@oss.qualcomm.com> In-Reply-To: <20260306-reset-core-refactor-v3-0-599349522876@oss.qualcomm.com> To: Krzysztof Kozlowski , Philipp Zabel , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, brgl@kernel.org, linux-doc@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5788; i=bartosz.golaszewski@oss.qualcomm.com; h=from:subject:message-id; bh=cFVRek2ApJRDsXIzvIHRimHH12mRJMFB9qA0OR3X75s=; b=owEBbAKT/ZANAwAKAQWdLsv/NoTDAcsmYgBpqw17iaFtggQHPnqQeoX6wV2u7jiA/Zt0AhKg5 G4sX5hoQcCJAjIEAAEKAB0WIQSR5RMt5bVGHXuiZfwFnS7L/zaEwwUCaasNewAKCRAFnS7L/zaE w7M3D/iEPA6rpq1rm36ayc2LrKWizgL8xoiQf8aOOk4cvBH3DBgINVNvndeijAGsro1UpJ9XKfO h9YaXg6YuQHWcuC1SzzPDWZ0wvUEKwzOXzSxktr+QvEHQ4O3Isyqz/MKdiEv5lp/0BB0GECg6/x DJD8ojCR6GpPvxFz9quWIRm+ARh9HO2DHwEl7mEz1LMEzwusI//JhaSUZGvRzrCl/38Q8wRn9E4 wtM0B4tkbBjpUqhTjHybXtu27ewTSZCIV5nRltIHpXFyAH+4+d9adfQUTBndjZaodNItzyqs64r ghTEP3NgvtcnppN7zG9FtI7lvi6osuB4jxV9T8wI9SioW2ELpkM8yvJWPeNVpBl8/gzGxWpH1V/ lH/gWnQ337c6qjwxcpjvoxC6cleT91+Ago3gx1MUvG+C57eI10rrpbv7XKg+XnEKgP9IypqIUM6 e/wL+LfmXIYBehAY4kLHc4uzgJ4X+wds7+Cc6PiSc28TOXmG/eafmDWGabM8lZJ2a8MDEPp4243 mIyBe8vDF4oxQ0Myn7Vf2IklMR56NQid0QZt/Y2h3bigR1+CoiyVR6ZKBYXx/+Go6kvOChepvYH 4jQn/iXc4fX8UqFpVl9EdaANlXRh9y2zXlrhX+SvvTU+6faHjPoJ/l30JYtLP1YidqQ9IXdamv5 NUJz02liJG2Td X-Developer-Key: i=bartosz.golaszewski@oss.qualcomm.com; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 X-Proofpoint-ORIG-GUID: yG_VoYaIbfmpWHGaGmxwZeaUp6GRf8V5 X-Authority-Analysis: v=2.4 cv=E83AZKdl c=1 sm=1 tr=0 ts=69ab0d92 cx=c_pps a=hnmNkyzTK/kJ09Xio7VxxA==:117 a=xqWC_Br6kY4A:10 a=IkcTkHD0fZMA:10 a=Yq5XynenixoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yOCtJkima9RkubShWh1s:22 a=EUspDBNiAAAA:8 a=BqEP8_E81RGvC7HVDgcA:9 a=QEXdDO2ut3YA:10 a=PEH46H7Ffwr30OY-TuGO:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzA2MDE2NCBTYWx0ZWRfXxGrYryHPIdTY 7idKU3X2CbAOkVx3xISremaFPy0hWha/y9iUPcJt1q4pc/EXkvnKonr05yoh03qugCUkdMLzwtS rMLHaD9p6qE6fnsioctqZjQj/bck12aE9Ysi4TRfdd4NYAXzCz0aJnp1KC+Fi5mypuEVKOq6Imv yzC6KDcg9etpoxGNdpDsNSx5COT4v5WqcG8f2K01jZ9Lj2V8C9MQOY1klcb7i0fSh69H3cBqUkU tJy+0LYxOrL+AuhDkhmCfWdIW0T2aoI/NBpd8IsrJFFjxaIj2ndBlyCcJp4ZUwpHUw7+mXY49CV C2EodVmq8CJ5SHB2bPznhBw8nG7JOclfVf0oth/hjG6IR31bAhFIdPfvBUvmiz08ENOKQdcvwbU CYpfP1QnOrNJxLnofwrXCCqxPzqS/MY9L0Z1FJJ/tXniaH/4Q/SGXXRs9QQSyFPCWhONxvy10/t rEau1PTQTRbAW/FI5xw== X-Proofpoint-GUID: yG_VoYaIbfmpWHGaGmxwZeaUp6GRf8V5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-06_05,2026-03-06_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 bulkscore=0 phishscore=0 impostorscore=0 adultscore=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2602130000 definitions=main-2603060164 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 control handle. Signed-off-by: Bartosz Golaszewski Reviewed-by: Philipp Zabel --- drivers/reset/core.c | 68 +++++++++++++++++++++++++++---------------------= ---- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/drivers/reset/core.c b/drivers/reset/core.c index d4813c712abf3df7993b0c2be1fe292b89241d11..34b11a68f28cd32e7b0ac852503= 193b0d9514915 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -49,6 +49,7 @@ static DEFINE_IDA(reset_gpio_ida); * @triggered_count: Number of times this reset line has been reset. Curre= ntly * only used for shared resets, which means that the val= ue * will be either 0 or 1. + * @lock: serializes the internals of reset_control_acquire() */ struct reset_control { struct reset_controller_dev __rcu *rcdev; @@ -61,6 +62,7 @@ struct reset_control { bool array; atomic_t deassert_count; atomic_t triggered_count; + struct mutex lock; }; =20 /** @@ -707,7 +709,7 @@ int reset_control_acquire(struct reset_control *rstc) if (reset_control_is_array(rstc)) return reset_control_array_acquire(rstc_to_array(rstc)); =20 - guard(mutex)(&reset_list_mutex); + guard(mutex)(&rstc->lock); =20 if (rstc->acquired) return 0; @@ -859,6 +861,7 @@ __reset_control_get_internal(struct reset_controller_de= v *rcdev, list_add(&rstc->list, &rcdev->reset_control_head); rstc->id =3D index; kref_init(&rstc->refcnt); + mutex_init(&rstc->lock); rstc->acquired =3D acquired; rstc->shared =3D shared; get_device(rcdev->dev); @@ -872,29 +875,40 @@ static void __reset_control_release(struct kref *kref) refcnt); struct reset_controller_dev *rcdev; =20 - lockdep_assert_held(&reset_list_mutex); + lockdep_assert_held(&rstc->srcu); =20 - scoped_guard(srcu, &rstc->srcu) { - rcdev =3D rcu_replace_pointer(rstc->rcdev, NULL, true); - if (rcdev) { - guard(mutex)(&rcdev->lock); - reset_controller_remove(rcdev, rstc); - } + rcdev =3D rcu_replace_pointer(rstc->rcdev, NULL, true); + if (rcdev) { + lockdep_assert_held(&rcdev->lock); + reset_controller_remove(rcdev, rstc); } =20 - synchronize_srcu(&rstc->srcu); - cleanup_srcu_struct(&rstc->srcu); - kfree(rstc); + mutex_destroy(&rstc->lock); } =20 -static void __reset_control_put_internal(struct reset_control *rstc) +static void reset_control_put_internal(struct reset_control *rstc) { - lockdep_assert_held(&reset_list_mutex); + struct reset_controller_dev *rcdev; + int ret =3D 0; =20 if (IS_ERR_OR_NULL(rstc)) return; =20 - kref_put(&rstc->refcnt, __reset_control_release); + scoped_guard(srcu, &rstc->srcu) { + rcdev =3D srcu_dereference(rstc->rcdev, &rstc->srcu); + if (!rcdev) + /* Already released. */ + return; + + guard(mutex)(&rcdev->lock); + ret =3D kref_put(&rstc->refcnt, __reset_control_release); + } + + if (ret) { + synchronize_srcu(&rstc->srcu); + cleanup_srcu_struct(&rstc->srcu); + kfree(rstc); + } } =20 static void reset_gpio_aux_device_release(struct device *dev) @@ -1104,7 +1118,7 @@ __of_reset_control_get(struct device_node *node, cons= t char *id, int index, { bool optional =3D flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL; bool gpio_fallback =3D false; - struct reset_control *rstc; + struct reset_control *rstc =3D ERR_PTR(-EINVAL); struct reset_controller_dev *rcdev; struct of_phandle_args args; int rstc_id; @@ -1169,8 +1183,8 @@ __of_reset_control_get(struct device_node *node, cons= t char *id, int index, =20 flags &=3D ~RESET_CONTROL_FLAGS_BIT_OPTIONAL; =20 - /* reset_list_mutex also protects the rcdev's reset_control list */ - rstc =3D __reset_control_get_internal(rcdev, rstc_id, flags); + scoped_guard(mutex, &rcdev->lock) + rstc =3D __reset_control_get_internal(rcdev, rstc_id, flags); =20 out_put: of_node_put(args.np); @@ -1213,10 +1227,8 @@ int __reset_control_bulk_get(struct device *dev, int= num_rstcs, return 0; =20 err: - guard(mutex)(&reset_list_mutex); - while (i--) - __reset_control_put_internal(rstcs[i].rstc); + reset_control_put_internal(rstcs[i].rstc); =20 return ret; } @@ -1226,10 +1238,8 @@ static void reset_control_array_put(struct reset_con= trol_array *resets) { int i; =20 - guard(mutex)(&reset_list_mutex); - for (i =3D 0; i < resets->num_rstcs; i++) - __reset_control_put_internal(resets->rstc[i]); + reset_control_put_internal(resets->rstc[i]); kfree(resets); } =20 @@ -1247,9 +1257,7 @@ void reset_control_put(struct reset_control *rstc) return; } =20 - guard(mutex)(&reset_list_mutex); - - __reset_control_put_internal(rstc); + reset_control_put_internal(rstc); } EXPORT_SYMBOL_GPL(reset_control_put); =20 @@ -1260,10 +1268,8 @@ EXPORT_SYMBOL_GPL(reset_control_put); */ void reset_control_bulk_put(int num_rstcs, struct reset_control_bulk_data = *rstcs) { - guard(mutex)(&reset_list_mutex); - while (num_rstcs--) - __reset_control_put_internal(rstcs[num_rstcs].rstc); + reset_control_put_internal(rstcs[num_rstcs].rstc); } EXPORT_SYMBOL_GPL(reset_control_bulk_put); =20 @@ -1482,10 +1488,8 @@ of_reset_control_array_get(struct device_node *np, e= num reset_control_flags flag return &resets->base; =20 err_rst: - guard(mutex)(&reset_list_mutex); - while (--i >=3D 0) - __reset_control_put_internal(resets->rstc[i]); + reset_control_put_internal(resets->rstc[i]); =20 kfree(resets); =20 --=20 2.47.3