Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp596522lqo; Thu, 16 May 2024 16:02:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW1QUTWkrHcfBHOfMleJBx9Br2EhMRdoNw1/iROTi5j/7EymmSo/QXh7QUP1ee00/8MjZb+/YIouz0fSMYaaVYLRutVIOchalWDGbgLQQ== X-Google-Smtp-Source: AGHT+IE/Zjj23/eXIxcWDre/w2XPeM23ovZLoWU/qIaC5f2fAg9zuY0I+UjQ8Fe4zx4lH5T7fj1x X-Received: by 2002:a17:902:e80d:b0:1e3:d4a2:3882 with SMTP id d9443c01a7336-1ef43d0ad97mr268165575ad.2.1715900551724; Thu, 16 May 2024 16:02:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715900551; cv=pass; d=google.com; s=arc-20160816; b=uKw0Xh65pc4hIh3UTTYY1s4PrZw6UrUeIRjN/peeSfvoa7SI2IIGuBM5kK5j1uK8FU xw6fmwXSbjTUd4czJVjw+DYva5qiUT2H9ffCHqeixoALlTtoXrL30Mo5PizMmxI2aTC1 +371Ij/ahTVjtgoHuqVlAtsUXz9NmdTymVseSgEMuWv/Il3Td4K1h57HSiEkwSB2VC/q B5zQ2erzicKioJY1lqqYvTaHZP9Fpof1m0osCs2enARZSsYBEo72Z9+Ng+aBrhbeNVCn a37AxmJ/hVR2EhRVbcgCZYIzFz/OIfTG6DY7tv6+uqlz3UCQFybY71AGuqy6ea5VPf9l BhyA== 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=YiZm6RAtjJv5sclEXV9/7nXZIdJO10j8272UKQobI70=; fh=yq+Ko9clF5UAYI8GmthOJiStA11CnBmYu7J0V0GpMDI=; b=ARcyJ8czxw52T0ID6of5R1BzOmQbqnpVDlsbiaL27Gvfn7O/ZHgnK/GBAuKAvOEaLC YShCQ3UAp37dRJVnSLDR2qFDNtEMGbc4kggu6n6VPVBF/x9LR9IYir5SGI9SjPIXj5YG 5udo9Vc9Fn7CQ0cPQZOj5GVTWy5dK+jg6Q98zdXhS40l6+g1sK0Nn3PFx029tmt1JQfO BBXYISbiwHcCUxqPB7v0+EWhRciuZLBoCPVyHjgthawdMS4vr5Oe179WP6CKk0zuCiQO l+upMIBYAGMsmYw5ptx+e4ajejP0eyohXEEuXi82vwRng45xa5G8YX9f7ZG/s3oGchZ5 O+Kg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=WNuUlF+W; 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-181622-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181622-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0bf31408si165757705ad.318.2024.05.16.16.02.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 16:02:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181622-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=WNuUlF+W; 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-181622-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181622-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 6A418B221A6 for ; Thu, 16 May 2024 23:01:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8AED55473A; Thu, 16 May 2024 22:59:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="WNuUlF+W" 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 1F57038FA6; Thu, 16 May 2024 22:59:46 +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=1715900388; cv=none; b=hIEGiYbPKdT+1QpM0Y/9A0o9BV5nUni0WSagd13IB++XFYIMeodJvNh+jrlee+9Y+wJJAnearxqrQY43heFD3Hork7WSvtNPCdSBQs1HpN8WPC+mZ0dFlvkfRHFaA4GDeJvpBzPAibP5Kpexd+gIv4s7gW7FX4RQ+Q6sBxdEN0Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715900388; c=relaxed/simple; bh=PuP3rCcFrb95od+jXOlfqySFSEORz+MzdKmq2DrM7Io=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=Xo4edmLuZx1SZNEehoiyp+pZy6fF9MxxE0f4BdBf7ew/jqYz2xJc4EQO0ggqbAK5XKpO1Zxg8Jzm9ZApQX5/Rx1fUChqULn1VZqC0Bt4ak3wyyjEypFhma2vhCnAMaPWiR6UOqwzDyeKAaxHTUWAgsdLbM7ZL6Tf8xN3fejPFrU= 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=WNuUlF+W; 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 (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44GKMrO7008455; 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=YiZm6RAtjJv5sclEXV9/7nXZIdJO10j8272UKQobI70 =; b=WNuUlF+WAnFYata1I/47Zbh6B0ajZnWCnH0+XUyeJ6t7wfOWUmOoSKJKXG1 Y/lSDIDYj0Y/DxV50PsvSzL01O7B+qtqyhWiwityvEx3vCEGvm9Jh84R6K9eZJEX hrHjFw0pcWzqxVBIoFlMCw75ZLlE3IhqOXpK9mYKw+ZnZTma1qcSDgBqXD6DhoTr 8gnqe0UksRWvs/MSWZEDKQfLJix6sdeEsyLFAssqwrwwcixKi0IoDmld7wHKYdh0 czciwE8Ugd2M22WODwcrPE7qFWi8FWW4s5Ht/k8hZfyh191SbB0OGh+7KpQ+w+OO JxmZ5KYI13wQWSxTj5Oua5YwOKw== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3y51tuk6bp-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 44GMx6K2012432 (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:21 -0700 Subject: [PATCH 3/7] hwspinlock: Introduce hwspin_lock_bust() 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-3-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=5549; i=quic_clew@quicinc.com; s=20240508; h=from:subject:message-id; bh=r6T0Zp/81nd5V0dz4Vr79ona63c6Utz764HgHxRPvAQ=; b=DQOtMMsB6YfYb6ieVLpXbaK2ARStqPqBFkQrwerJT6Lfh3XX31xuKJzmMZiSp4MU0f6WNzkn1 hsG2FvAsAFSBO+6e2sWhnAfe317k6ogWTt4++PFNZ2Ri7ZNdO7qIMsk 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-ORIG-GUID: uz2yE_2PP5De56H-hTxKgdHjDlyI5iEE X-Proofpoint-GUID: uz2yE_2PP5De56H-hTxKgdHjDlyI5iEE 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 adultscore=0 phishscore=0 spamscore=0 impostorscore=0 bulkscore=0 suspectscore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 mlxlogscore=999 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405010000 definitions=main-2405160168 From: Richard Maina When a remoteproc crashes or goes down unexpectedly this can result in a state where locks held by the remoteproc will remain locked possibly resulting in deadlock. This new API hwspin_lock_bust() allows hwspinlock implementers to define a bust operation for freeing previously acquired hwspinlocks after verifying ownership of the acquired lock. Signed-off-by: Richard Maina Signed-off-by: Chris Lew --- Documentation/locking/hwspinlock.rst | 11 +++++++++++ drivers/hwspinlock/hwspinlock_core.c | 30 +++++++++++++++++++++++++++++- drivers/hwspinlock/hwspinlock_internal.h | 3 +++ include/linux/hwspinlock.h | 6 ++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/Documentation/locking/hwspinlock.rst b/Documentation/locking/hwspinlock.rst index c1c2c827b575..6ee94cc6d3b7 100644 --- a/Documentation/locking/hwspinlock.rst +++ b/Documentation/locking/hwspinlock.rst @@ -85,6 +85,17 @@ is already free). Should be called from a process context (might sleep). +:: + + int hwspin_lock_bust(struct hwspinlock *hwlock, unsigned int id); + +After verifying the owner of the hwspinlock, release a previously acquired +hwspinlock; returns 0 on success, or an appropriate error code on failure +(e.g. -EOPNOTSUPP if the bust operation is not defined for the specific +hwspinlock). + +Should be called from a process context (might sleep). + :: int hwspin_lock_timeout(struct hwspinlock *hwlock, unsigned int timeout); diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c index 73a6dff5cbac..a7851262f36f 100644 --- a/drivers/hwspinlock/hwspinlock_core.c +++ b/drivers/hwspinlock/hwspinlock_core.c @@ -305,6 +305,34 @@ void __hwspin_unlock(struct hwspinlock *hwlock, int mode, unsigned long *flags) } EXPORT_SYMBOL_GPL(__hwspin_unlock); +/** + * hwspin_lock_bust() - bust a specific hwspinlock + * @hwlock: a previously-acquired hwspinlock which we want to bust + * @id: identifier of the remote lock holder, if applicable + * + * This function will bust a hwspinlock that was previously acquired as + * long as the current owner of the lock matches the id given by the caller. + * + * Should be called from a process context (might sleep). + * + * Returns: 0 on success, or -EINVAL if the hwspinlock does not exist, or + * the bust operation fails, and -EOPNOTSUPP if the bust operation is not + * defined for the hwspinlock. + */ +int hwspin_lock_bust(struct hwspinlock *hwlock, unsigned int id) +{ + if (WARN_ON(!hwlock)) + return -EINVAL; + + if (!hwlock->bank->ops->bust) { + pr_err("bust operation not defined\n"); + return -EOPNOTSUPP; + } + + return hwlock->bank->ops->bust(hwlock, id); +} +EXPORT_SYMBOL_GPL(hwspin_lock_bust); + /** * of_hwspin_lock_simple_xlate - translate hwlock_spec to return a lock id * @hwlock_spec: hwlock specifier as found in the device tree @@ -610,7 +638,7 @@ EXPORT_SYMBOL_GPL(devm_hwspin_lock_unregister); * This function should be called from the underlying platform-specific * implementation, to register a new hwspinlock device instance. * - * Should be called from a process context (might sleep) + * Context: Process context. GFP_KERNEL allocation. * * Returns: %0 on success, or an appropriate error code on failure */ diff --git a/drivers/hwspinlock/hwspinlock_internal.h b/drivers/hwspinlock/hwspinlock_internal.h index 12f230b40693..2202f2c9a62e 100644 --- a/drivers/hwspinlock/hwspinlock_internal.h +++ b/drivers/hwspinlock/hwspinlock_internal.h @@ -21,6 +21,8 @@ struct hwspinlock_device; * @trylock: make a single attempt to take the lock. returns 0 on * failure and true on success. may _not_ sleep. * @unlock: release the lock. always succeed. may _not_ sleep. + * @bust: optional, platform-specific bust handler, called by hwspinlock + * core to bust a specific lock. * @relax: optional, platform-specific relax handler, called by hwspinlock * core while spinning on a lock, between two successive * invocations of @trylock. may _not_ sleep. @@ -28,6 +30,7 @@ struct hwspinlock_device; struct hwspinlock_ops { int (*trylock)(struct hwspinlock *lock); void (*unlock)(struct hwspinlock *lock); + int (*bust)(struct hwspinlock *lock, unsigned int id); void (*relax)(struct hwspinlock *lock); }; diff --git a/include/linux/hwspinlock.h b/include/linux/hwspinlock.h index bfe7c1f1ac6d..f0231dbc4777 100644 --- a/include/linux/hwspinlock.h +++ b/include/linux/hwspinlock.h @@ -68,6 +68,7 @@ int __hwspin_lock_timeout(struct hwspinlock *, unsigned int, int, int __hwspin_trylock(struct hwspinlock *, int, unsigned long *); void __hwspin_unlock(struct hwspinlock *, int, unsigned long *); int of_hwspin_lock_get_id_byname(struct device_node *np, const char *name); +int hwspin_lock_bust(struct hwspinlock *hwlock, unsigned int id); int devm_hwspin_lock_free(struct device *dev, struct hwspinlock *hwlock); struct hwspinlock *devm_hwspin_lock_request(struct device *dev); struct hwspinlock *devm_hwspin_lock_request_specific(struct device *dev, @@ -127,6 +128,11 @@ void __hwspin_unlock(struct hwspinlock *hwlock, int mode, unsigned long *flags) { } +static inline int hwspin_lock_bust(struct hwspinlock *hwlock, unsigned int id) +{ + return 0; +} + static inline int of_hwspin_lock_get_id(struct device_node *np, int index) { return 0; -- 2.25.1