From nobody Fri Nov 29 00:39:17 2024 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (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 EC9871D5AAD for ; Thu, 26 Sep 2024 02:31:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727317873; cv=none; b=uA9ClHg+IuBZ5jKoHB/iaKA5QoX9UYiHRREajhY3trDE3tkZuM4S+RjrRuWJ+3s+ZU6PoBYJRv3bXif/pJKS3TxTkem0z4lGSKE4keH3rkQFcYvO/jIp23+8f84aNixtZ7HLuuIKM5P48U5aaqzCP4y9UnQV/woM4VC1wU9Bqhs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727317873; c=relaxed/simple; bh=wqUeunnH24DSyREqkvENGRSHzRul/RYRg2ZsoZVBA34=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=OCAQfdV8+ewK4eH6QE3b/O0VBnQxrd2YK5dwZ8X770jf9H7wHynYMI3SeNhed9XnKa3LJIYXKIxDpV5FbQxNerlaCnX21x2BTfnMpVLfASzkfCrhul3721D9qaC3qsS376Pk/mtamRCiG+jHnP4+YHHuZU4zH5/Yp7kR50AkJHo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=QpKYEtHz; arc=none smtp.client-ip=91.218.175.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="QpKYEtHz" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1727317867; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=+Jq6VURV88x+fuCfGXXrbTg7EOL5oxox8+EDOJdVkd4=; b=QpKYEtHzkaDuB2RiwWq6RturpoEhOGJWMbxSS6vwKSgE6tPkkO2mHa5N5mN5+ua6VGC0Kn YFsDinx4EdwcaRNwFqIRlkBOm5Get2EAA0a0RYU8+VCogkd8b4mU76EGJ0p6Yb1r//PPnh dfjR0YgWQhMfMK3JgEdd7qDHoPa84M4= From: Wen Yang To: Bjorn Andersson Cc: Wen Yang , Baolin Wang , Dave Young , linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] hwspinlock: fix some comments about 'will never sleep' Date: Thu, 26 Sep 2024 10:30:28 +0800 Message-Id: <20240926023028.774580-1-wen.yang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Both __hwspin_trylock and __hwspin_unlock use hwlock->lock, with a special annotation: function will never sleep. However, this requirement is not fulfilled on PREEMPT_RT. Bjorn said: : "will never sleep" comment expresses that the function can be called : in atomic or irq context, not necessarily that it must not sleep. This patch fixes these comments. Suggested-by: Bjorn Andersson Signed-off-by: Wen Yang Cc: Bjorn Andersson Cc: Baolin Wang Cc: Dave Young Cc: linux-remoteproc@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- Documentation/locking/hwspinlock.rst | 64 ++++++++++++++-------------- drivers/hwspinlock/hwspinlock_core.c | 25 +++++------ 2 files changed, 46 insertions(+), 43 deletions(-) diff --git a/Documentation/locking/hwspinlock.rst b/Documentation/locking/h= wspinlock.rst index 2ffaa3cbd63f..9d20823a21e7 100644 --- a/Documentation/locking/hwspinlock.rst +++ b/Documentation/locking/hwspinlock.rst @@ -103,14 +103,14 @@ Should be called from a process context (might sleep). Lock a previously-assigned hwspinlock with a timeout limit (specified in msecs). If the hwspinlock is already taken, the function will busy loop waiting for it to be released, but give up when the timeout elapses. -Upon a successful return from this function, preemption is disabled so -the caller must not sleep, and is advised to release the hwspinlock as -soon as possible, in order to minimize remote cores polling on the -hardware interconnect. +Upon a successful return from this function, preemption is disabled on +non-PREEMPT_RT kernels, so the caller must not sleep, and is advised to +release the hwspinlock as soon as possible, in order to minimize remote +cores polling on the hardware interconnect. =20 Returns 0 when successful and an appropriate error code otherwise (most notably -ETIMEDOUT if the hwspinlock is still busy after timeout msecs). -The function will never sleep. +The function will never sleep on a non-PREEMPT_RT kernel. =20 :: =20 @@ -120,12 +120,12 @@ Lock a previously-assigned hwspinlock with a timeout = limit (specified in msecs). If the hwspinlock is already taken, the function will busy loop waiting for it to be released, but give up when the timeout elapses. Upon a successful return from this function, preemption and the local -interrupts are disabled, so the caller must not sleep, and is advised to -release the hwspinlock as soon as possible. +interrupts are disabled on non-PREEMPT_RT kernels, so the caller must not +sleep, and is advised to release the hwspinlock as soon as possible. =20 Returns 0 when successful and an appropriate error code otherwise (most notably -ETIMEDOUT if the hwspinlock is still busy after timeout msecs). -The function will never sleep. +The function will never sleep on a non-PREEMPT_RT kernel. =20 :: =20 @@ -137,13 +137,13 @@ msecs). If the hwspinlock is already taken, the funct= ion will busy loop waiting for it to be released, but give up when the timeout elapses. Upon a successful return from this function, preemption is disabled, local interrupts are disabled and their previous state is saved at the -given flags placeholder. The caller must not sleep, and is advised to -release the hwspinlock as soon as possible. +given flags placeholder on non-PREEMPT_RT kernels. The caller must not sle= ep, +and is advised to release the hwspinlock as soon as possible. =20 Returns 0 when successful and an appropriate error code otherwise (most notably -ETIMEDOUT if the hwspinlock is still busy after timeout msecs). =20 -The function will never sleep. +The function will never sleep on a non-PREEMPT_RT kernel. =20 :: =20 @@ -160,7 +160,7 @@ or sleepable operations under the hardware lock. Returns 0 when successful and an appropriate error code otherwise (most notably -ETIMEDOUT if the hwspinlock is still busy after timeout msecs). =20 -The function will never sleep. +The function will never sleep on a non-PREEMPT_RT kernel. =20 :: =20 @@ -176,7 +176,7 @@ value shall not exceed a few msecs. Returns 0 when successful and an appropriate error code otherwise (most notably -ETIMEDOUT if the hwspinlock is still busy after timeout msecs). =20 -The function will never sleep. +The function will never sleep on a non-PREEMPT_RT kernel. =20 :: =20 @@ -186,14 +186,14 @@ The function will never sleep. Attempt to lock a previously-assigned hwspinlock, but immediately fail if it is already taken. =20 -Upon a successful return from this function, preemption is disabled so -caller must not sleep, and is advised to release the hwspinlock as soon as -possible, in order to minimize remote cores polling on the hardware -interconnect. +Upon a successful return from this function, preemption is disabled on +non-PREEMPT_RT kernels so caller must not sleep and is advised to release +the hwspinlock as soon as possible, in order to minimize remote cores poll= ing +on the hardware interconnect. =20 Returns 0 on success and an appropriate error code otherwise (most notably -EBUSY if the hwspinlock was already taken). -The function will never sleep. +The function will never sleep on a non-PREEMPT_RT kernel. =20 :: =20 @@ -204,13 +204,13 @@ Attempt to lock a previously-assigned hwspinlock, but= immediately fail if it is already taken. =20 Upon a successful return from this function, preemption and the local -interrupts are disabled so caller must not sleep, and is advised to -release the hwspinlock as soon as possible. +interrupts are disabled on non-PREEMPT_RT kernels so caller must not sleep, +and is advised to release the hwspinlock as soon as possible. =20 Returns 0 on success and an appropriate error code otherwise (most notably -EBUSY if the hwspinlock was already taken). =20 -The function will never sleep. +The function will never sleep on a non-PREEMPT_RT kernel. =20 :: =20 @@ -221,12 +221,12 @@ it is already taken. =20 Upon a successful return from this function, preemption is disabled, the local interrupts are disabled and their previous state is saved -at the given flags placeholder. The caller must not sleep, and is advised -to release the hwspinlock as soon as possible. +at the given flags placeholder on non-PREEMPT_RT kernels. The caller must +not sleep, and is advised to release the hwspinlock as soon as possible. =20 Returns 0 on success and an appropriate error code otherwise (most notably -EBUSY if the hwspinlock was already taken). -The function will never sleep. +The function will never sleep on a non-PREEMPT_RT kernel. =20 :: =20 @@ -241,7 +241,7 @@ or sleepable operations under the hardware lock. =20 Returns 0 on success and an appropriate error code otherwise (most notably -EBUSY if the hwspinlock was already taken). -The function will never sleep. +The function will never sleep on a non-PREEMPT_RT kernel. =20 :: =20 @@ -254,14 +254,14 @@ This function shall be called only from an atomic con= text. =20 Returns 0 on success and an appropriate error code otherwise (most notably -EBUSY if the hwspinlock was already taken). -The function will never sleep. +The function will never sleep on a non-PREEMPT_RT kernel. =20 :: =20 void hwspin_unlock(struct hwspinlock *hwlock); =20 Unlock a previously-locked hwspinlock. Always succeed, and can be called -from any context (the function never sleeps). +from any context (the function never sleeps on a non-PREEMPT_RT kernel). =20 .. note:: =20 @@ -277,7 +277,8 @@ The caller should **never** unlock an hwspinlock which = is already unlocked. =20 Doing so is considered a bug (there is no protection against this). Upon a successful return from this function, preemption and local -interrupts are enabled. This function will never sleep. +interrupts are enabled on non-PREEMPT_RT kernels. +This function will never sleep on a non-PREEMPT_RT kernel. =20 :: =20 @@ -290,7 +291,8 @@ The caller should **never** unlock an hwspinlock which = is already unlocked. Doing so is considered a bug (there is no protection against this). Upon a successful return from this function, preemption is reenabled, and the state of the local interrupts is restored to the state saved at -the given flags. This function will never sleep. +the given flags on non-PREEMPT_RT kernels. +This function will never sleep on a non-PREEMPT_RT kernel. =20 :: =20 @@ -300,7 +302,7 @@ Unlock a previously-locked hwspinlock. =20 The caller should **never** unlock an hwspinlock which is already unlocked. Doing so is considered a bug (there is no protection against this). -This function will never sleep. +This function will never sleep on a non-PREEMPT_RT kernel. =20 :: =20 @@ -310,7 +312,7 @@ Unlock a previously-locked hwspinlock. =20 The caller should **never** unlock an hwspinlock which is already unlocked. Doing so is considered a bug (there is no protection against this). -This function will never sleep. +This function will never sleep on a non-PREEMPT_RT kernel. =20 :: =20 diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwsp= inlock_core.c index 6505261e6068..b602d6cf5e1b 100644 --- a/drivers/hwspinlock/hwspinlock_core.c +++ b/drivers/hwspinlock/hwspinlock_core.c @@ -73,10 +73,10 @@ static DEFINE_MUTEX(hwspinlock_tree_lock); * lock, they need one sleepable lock (like mutex) to protect the operatio= ns. * * If the mode is neither HWLOCK_IN_ATOMIC nor HWLOCK_RAW, upon a successf= ul - * return from this function, preemption (and possibly interrupts) is disa= bled, - * so the caller must not sleep, and is advised to release the hwspinlock = as - * soon as possible. This is required in order to minimize remote cores po= lling - * on the hardware interconnect. + * return from this function, preemption (and possibly interrupts) is disa= bled + * on non-PREEMPT_RT kernels, so the caller must not sleep, and is advised= to + * release the hwspinlock as soon as possible. This is required in order to + * minimize remote cores polling on the hardware interconnect. * * The user decides whether local interrupts are disabled or not, and if y= es, * whether he wants their previous state to be saved. It is up to the user @@ -87,7 +87,7 @@ static DEFINE_MUTEX(hwspinlock_tree_lock); * Returns: %0 if we successfully locked the hwspinlock or -EBUSY if * the hwspinlock was already taken. * - * This function will never sleep. + * This function will never sleep on a non-PREEMPT_RT kernel. */ int __hwspin_trylock(struct hwspinlock *hwlock, int mode, unsigned long *f= lags) { @@ -190,10 +190,10 @@ EXPORT_SYMBOL_GPL(__hwspin_trylock); * is handled with busy-waiting delays, hence shall not exceed few msecs. * * If the mode is neither HWLOCK_IN_ATOMIC nor HWLOCK_RAW, upon a successf= ul - * return from this function, preemption (and possibly interrupts) is disa= bled, - * so the caller must not sleep, and is advised to release the hwspinlock = as - * soon as possible. This is required in order to minimize remote cores po= lling - * on the hardware interconnect. + * return from this function, preemption (and possibly interrupts) is disa= bled + * on non-PREEMPT_RT kernels, so the caller must not sleep, and is advised= to + * release the hwspinlock as soon as possible. This is required in order to + * minimize remote cores polling on the hardware interconnect. * * The user decides whether local interrupts are disabled or not, and if y= es, * whether he wants their previous state to be saved. It is up to the user @@ -204,7 +204,7 @@ EXPORT_SYMBOL_GPL(__hwspin_trylock); * error code otherwise (most notably -ETIMEDOUT if the @hwlock is still * busy after @timeout msecs). * - * The function will never sleep. + * The function will never sleep on a non-PREEMPT_RT kernel. */ int __hwspin_lock_timeout(struct hwspinlock *hwlock, unsigned int to, int mode, unsigned long *flags) @@ -253,7 +253,8 @@ EXPORT_SYMBOL_GPL(__hwspin_lock_timeout); * @flags: previous caller's interrupt state to restore (if requested) * * This function will unlock a specific hwspinlock, enable preemption and - * (possibly) enable interrupts or restore their previous state. + * (possibly) enable interrupts or restore their previous state on + * non-PREEMPT_RT kernels. * @hwlock must be already locked before calling this function: it is a bug * to call unlock on a @hwlock that is already unlocked. * @@ -263,7 +264,7 @@ EXPORT_SYMBOL_GPL(__hwspin_lock_timeout); * same way users decide between spin_unlock, spin_unlock_irq and * spin_unlock_irqrestore. * - * The function will never sleep. + * The function will never sleep on a non-PREEMPT_RT kernel. */ void __hwspin_unlock(struct hwspinlock *hwlock, int mode, unsigned long *f= lags) { --=20 2.25.1