Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp595871lqo; Thu, 16 May 2024 16:01:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVY6erJCNlN6zDWnkY8VvIxdTgZFumUERN1vQHb7KdBIFLoAKHTZfcsHDiCb7/HzW7mi8eEhE/3EXztD7YuA+ZBXuQgrKzLBPSMOyFDtQ== X-Google-Smtp-Source: AGHT+IGeAU5TQ7zX8YnkMFqzXexyR4qoaDVgEGY66ji7Erl8nXgGGMZz5uWaNJDeAzjBwR023KTS X-Received: by 2002:a05:620a:29ce:b0:792:ea76:2e63 with SMTP id af79cd13be357-792ea762eb2mr1274976485a.12.1715900484105; Thu, 16 May 2024 16:01:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715900484; cv=pass; d=google.com; s=arc-20160816; b=BPdz/J2VD2Gzn7NJN2xrrQZ7EQolsVnI7Wppjdvl/ywwG8qnUEf3WQuteN6OKQgg15 ZbmSekAWgq6qhtsaK+WB88FjmmrIEHuMMYPqTLTiqZp47R++vve58PcOwkLFAAvA7jFt Paf3fpIrUt+YZsdioQMU1gHMRXsojJlKm+6bnBY3QnRnyEohCCb2Zdf10k0n725OEq6/ a/H3gPOfAapuGYSZyyyqcTr7ae7JWoMpm3pJyr9K6LGKd2tHLMdkqmDtybSEjKtd1bE6 CjAndqTzJqmGHptJNbUFHagkyVfaqEETteQvYVC7VeL+wrwpeG5Wfa23zfLkOWhj7qQd uAvg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=xXHsiv91PwjlPs1MvcU7cM3/qVstxKwE0iOAL5DZUek=; fh=yq+Ko9clF5UAYI8GmthOJiStA11CnBmYu7J0V0GpMDI=; b=Oxe5vorhpqIRycSehEBOloJI4JUuaovmfDD0oquBomuL1wpTXR98xzMA0mquBHk8Mq mdroIxZZZHaN75VKBTN6KDNdNs4pPCZeVtYnYvbs192/TWIfxVu82rqJNlm2X1OMSvP9 0FcWHMCIiL3xASYs3byyyPoK33Eu11Zcf4sIWDsvVvIfthvr/S0pzadBT6NiI9cjie1J E30g4ymtl+6vmpzXt50WWSjJfmyZYB5Djn6KWJQOIFAGondcBVd9LgfSQu40QFX0RS3V AqKckkfQ6KJavcLVHXAwzBcCWkmmuR+7akI1c+8QuU99BuZJeT+YNtfOTwPjAys56mz8 ELLg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=AOQtd1TE; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-181620-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181620-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-792bf360a22si1894495185a.541.2024.05.16.16.01.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 16:01:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181620-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=AOQtd1TE; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-181620-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181620-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B5B281C20DB0 for ; Thu, 16 May 2024 23:01:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A5134F1E4; Thu, 16 May 2024 22:59:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="AOQtd1TE" 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 0AB702CCC2; Thu, 16 May 2024 22:59:45 +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=1715900387; cv=none; b=H4ZIWSZxdlMhjI+moQ1cDyHfZ4GT/57qb+cU0G8gcSnTbaQUFISIp5BmXNzNdR+VipqQ5MnHLPw2gUdRPiJwg2wZy7DW9utzoA/9/KyV2yqaxmv/q+/SKSAlQ+7/ItrtXtqot2n8vi7qlQg73ebusi/RDfOj7c8cc23Hg28ZOtM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715900387; c=relaxed/simple; bh=ZPDmk7U3xa9ciGMMpt439g4ATxp4CcHH9SRjaxdv558=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=MGQSuUNnhwolx/1NppVqRR14M5q9qDRMfatzdq8Iu1fA2YptYxJfCECeHNeD7M7BAVZQuQQhkRI0RxI70rJ1McDkU3VV8ewHQ3UbiHJCFH9OA+V4WEIK9qhFHnNc753cAhAWvCR4VaQBLKF3D/eeoM8rpo5TYA4bzbpw9/MTSs0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=AOQtd1TE; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44GKN4lX017831; Thu, 16 May 2024 22:59:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:date:subject:mime-version:content-type :content-transfer-encoding:message-id:references:in-reply-to:to :cc; s=qcppdkim1; bh=xXHsiv91PwjlPs1MvcU7cM3/qVstxKwE0iOAL5DZUek =; b=AOQtd1TEoccPpx3pzv3CNzvdR0U4M5myJRc3hLbi2J5bdkXwmoZiXGMqQOP SqiDXHdpljQYmrcaCrC3WFqidrNnGLBnpaCwiQa6/UiCjTKrguKG0t0eI2FbN0Yn 4zC8XFr+cQuyveGG4dbfyL1LCDMWPXDIFCgkTDC/xYmKDKpAyGYwTu2uJWxDzyJu 5G4O77CRvc2hBG9j4ATkxPWpGsgxBd4swEgTTzsEhg7IqBFbM3zcfWhkqYQX7igu JMGCVk4XULdTU0/DZbdHReZSkHSu4aSVaE/6pvUp34lgFnzlXDYv8ztp1cpwzD8u imxle0LPmXFFcU8fw5TEZywlmKw== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3y5c05t5dj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 May 2024 22:59:09 +0000 (GMT) Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 44GMx6K0012432 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 May 2024 22:59:06 GMT Received: from hu-clew-lv.qualcomm.com (10.49.16.6) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Thu, 16 May 2024 15:59:05 -0700 From: Chris Lew Date: Thu, 16 May 2024 15:58:19 -0700 Subject: [PATCH 1/7] hwspinlock: Introduce refcount 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: <20240516-hwspinlock-bust-v1-1-47a90a859238@quicinc.com> References: <20240516-hwspinlock-bust-v1-0-47a90a859238@quicinc.com> In-Reply-To: <20240516-hwspinlock-bust-v1-0-47a90a859238@quicinc.com> To: Bjorn Andersson , Baolin Wang , Peter Zijlstra , "Ingo Molnar" , Will Deacon , Waiman Long , Boqun Feng , Jonathan Corbet , Mathieu Poirier , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Manivannan Sadhasivam , Konrad Dybcio CC: , , , , , Chris Lew , "Richard Maina" X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715900345; l=2718; i=quic_clew@quicinc.com; s=20240508; h=from:subject:message-id; bh=hLiGXwK6/eMJFtwZ/h8OJhnWXPSq0ajjAK8+KrHxcRc=; b=XUGEroFrF2iuYIvReZr/iR+0SeLZ7IJdNaNVHw3QAwF6yauJa3LcNrBP+WETJgxZQTOm4UhxO 4SuRikBC0ZlDOWqM1zW7mA2HtY038BudSe5ERhOTdvfgbCnfbRr2/Xy X-Developer-Key: i=quic_clew@quicinc.com; a=ed25519; pk=lEYKFaL1H5dMC33BEeOULLcHAwjKyHkTLdLZQRDTKV4= X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: 6WbZUnFuNARMRCh1Ki0bUX_R5fX01YI6 X-Proofpoint-ORIG-GUID: 6WbZUnFuNARMRCh1Ki0bUX_R5fX01YI6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-16_07,2024-05-15_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 bulkscore=0 phishscore=0 priorityscore=1501 clxscore=1011 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405010000 definitions=main-2405160168 From: Richard Maina Currently each device receives a dedicated hwspinlock that is not accesible to other device drivers. In order to allow multiple consumers access to the same hwspinlock, introduce a refcount to hwspinlock struct and implement refcounting infrastructure. Signed-off-by: Richard Maina Signed-off-by: Chris Lew --- drivers/hwspinlock/hwspinlock_core.c | 14 +++++++++----- drivers/hwspinlock/hwspinlock_internal.h | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c index 0c0a932c00f3..29b33072ff57 100644 --- a/drivers/hwspinlock/hwspinlock_core.c +++ b/drivers/hwspinlock/hwspinlock_core.c @@ -428,6 +428,7 @@ static int hwspin_lock_register_single(struct hwspinlock *hwlock, int id) int ret; mutex_lock(&hwspinlock_tree_lock); + hwlock->refcnt = 0; ret = radix_tree_insert(&hwspinlock_tree, id, hwlock); if (ret) { @@ -671,6 +672,8 @@ static int __hwspin_lock_request(struct hwspinlock *hwlock) ret = 0; + hwlock->refcnt++; + /* mark hwspinlock as used, should not fail */ tmp = radix_tree_tag_clear(&hwspinlock_tree, hwlock_to_id(hwlock), HWSPINLOCK_UNUSED); @@ -829,12 +832,13 @@ int hwspin_lock_free(struct hwspinlock *hwlock) /* notify the underlying device that power is not needed */ pm_runtime_put(dev); - /* mark this hwspinlock as available */ - tmp = radix_tree_tag_set(&hwspinlock_tree, hwlock_to_id(hwlock), - HWSPINLOCK_UNUSED); + if (--hwlock->refcnt == 0) { + /* mark this hwspinlock as available */ + tmp = radix_tree_tag_set(&hwspinlock_tree, hwlock_to_id(hwlock), HWSPINLOCK_UNUSED); - /* sanity check (this shouldn't happen) */ - WARN_ON(tmp != hwlock); + /* sanity check (this shouldn't happen) */ + WARN_ON(tmp != hwlock); + } module_put(dev->driver->owner); diff --git a/drivers/hwspinlock/hwspinlock_internal.h b/drivers/hwspinlock/hwspinlock_internal.h index 29892767bb7a..12f230b40693 100644 --- a/drivers/hwspinlock/hwspinlock_internal.h +++ b/drivers/hwspinlock/hwspinlock_internal.h @@ -35,11 +35,13 @@ struct hwspinlock_ops { * struct hwspinlock - this struct represents a single hwspinlock instance * @bank: the hwspinlock_device structure which owns this lock * @lock: initialized and used by hwspinlock core + * @refcnt: counter for the number of existing references to the hwspinlock * @priv: private data, owned by the underlying platform-specific hwspinlock drv */ struct hwspinlock { struct hwspinlock_device *bank; spinlock_t lock; + unsigned int refcnt; void *priv; }; -- 2.25.1