From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (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 7236C3AC0D8 for ; Wed, 29 Jul 2026 06:22:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785306178; cv=pass; b=YVSq+OZqFqyQ2VsKui5FukbNVUIJNOiK3teXWdgOEkjQSh3SLe9EE52bqPHBu2rGffINvonylTAfvKWz7gde0/ZuJ5KuyW2YSfkIgd965rHv7MMK6BNaELfXLzfSQUBUUoTJ618dUQGAdPniZ/5Kas1RsNpwRAIxRgKrXyJiywA= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785306178; c=relaxed/simple; bh=tCCYWrfGRTP7VR5Rl1I8tJRCOfWmkpj8y9AqOvYCE3M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WI8XzBYfLkXdWtQzGNQBeS5jVHn5IcLnjdmmp3BO2upPnSSXWfM8dRhRXPuxR0wOgAwYE0I52a9Mgr2jKp3gdLxDXdKMEG4JUtxdKssCIOQpZb179ttkC7uYNvWaft+h/ryC8mzoK6P7xmu5/GLJkcZMz2xB50d1pLuyI6oTA14= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b=B3QU/YLD; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b="B3QU/YLD" ARC-Seal: i=1; a=rsa-sha256; t=1785306016; cv=none; d=zohomail.com; s=zohoarc; b=WXYb/2I64GQPJquB2wSbI3VDKibY7uUvb+RBiO7SBGCIGlmboHyxjSYT4PSut3H3ddSK/ZdtnXF+0QjX3syav40kZV5pqYOEK969pw4eIm4/Ej/xRbsN1lkGLNVIUZvi4Omt1xrwXPNh3kvtx4XPb14T1k3WRnQdMN4jrvVm6RM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1785306016; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=A/S77ywcJNEWNYibuHZlunu83Y1+7/T5c7HCPO1HImM=; b=HArlFG22J0QAWm54fR56EsOBd2Pr0zqSm3IxN0Hn17ugdnf4X3tgQa3A8Ijyf5FM34NKEEydhWiXQ2UqF3/TdRe/KzA5HQy9+uwSmv5gQ6R3YLDQiLGWF7t7gW+x5TQ5zvJe6mNVqdyFcQxV/7idfbPxiRl7CNurXouk5UpZDGA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=nicolas.frattaroli@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1785306016; s=zohomail; d=collabora.com; i=nicolas.frattaroli@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=A/S77ywcJNEWNYibuHZlunu83Y1+7/T5c7HCPO1HImM=; b=B3QU/YLDsWtynt68Z5gWKAyrV/8Co6Z8JXYdcIqj7jQWbgMwdHv2SCDw7OROD/TX p1btkTLsDBMLj2L+Ss7moaAlmEDE5jdBjlEAQU7KQmmgRRZjfCp4NuFLq22hxA2tDVz NkKKzXmdSzSx5UK/YoKYGBqG1VJM24vd2ys5n2yc= Received: by mx.zohomail.com with SMTPS id 1785306014417121.58010653555687; Tue, 28 Jul 2026 23:20:14 -0700 (PDT) From: Nicolas Frattaroli Date: Wed, 29 Jul 2026 08:19:49 +0200 Subject: [PATCH 1/3] wait: Introduce non-irq variants of wait_event_lock_timeout 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: <20260729-panthor-cache-flush-fix-v1-1-205921ed3c81@collabora.com> References: <20260729-panthor-cache-flush-fix-v1-0-205921ed3c81@collabora.com> In-Reply-To: <20260729-panthor-cache-flush-fix-v1-0-205921ed3c81@collabora.com> To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Boris Brezillon , Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Grant Likely , Heiko Stuebner Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, kernel@collabora.com, Nicolas Frattaroli X-Mailer: b4 0.15.2 For locks that are never acquired in an interrupt context, the non-irq variants for spin_lock()/spin_unlock() are more efficient. However, so far, wait.h only provided wait_event_lock_irq_timeout and wait_event_interruptible_lock_irq_timeout, both of which use spin_lock_irq()/spin_unlock_irq(). Rectify this by adding new non-irq variants of these two macros. Signed-off-by: Nicolas Frattaroli --- include/linux/wait.h | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/include/linux/wait.h b/include/linux/wait.h index dce055e6add3..cd9b989c120e 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h @@ -1174,6 +1174,13 @@ do { \ __ret = schedule_timeout(__ret); \ spin_lock_irq(&lock)); +#define __wait_event_lock_timeout(wq_head, condition, lock, timeout, state) \ + ___wait_event(wq_head, ___wait_cond_timeout(condition), \ + state, 0, timeout, \ + spin_unlock(&lock); \ + __ret = schedule_timeout(__ret); \ + spin_lock(&lock)) + /** * wait_event_interruptible_lock_irq_timeout - sleep until a condition gets * true or a timeout elapses. The condition is checked under @@ -1219,6 +1226,83 @@ do { \ __ret; \ }) +/** + * wait_event_interruptible_lock_timeout - sleep until a condition gets + * true or a timeout elapses. The condition is checked under + * the lock with IRQs enabled. This is expected to be called + * with the lock taken. + * @wq_head: the waitqueue to wait on + * @condition: a C expression for the event to wait for + * @lock: a spinlock_t that has been locked with spin_lock(), which will be + * released before schedule() and reacquired afterwards. + * @timeout: timeout, in jiffies + * + * The process is put to sleep (TASK_INTERRUPTIBLE) until the + * @condition evaluates to true or signal is received. The @condition is + * checked each time the waitqueue @wq_head is woken up. + * + * wake_up() has to be called after changing any variable that could + * change the result of the wait condition. + * + * This is supposed to be called while holding the lock. The lock is + * dropped before going to sleep using spin_unlock() and is reacquired + * using spin_lock() afterwards, but without globally disabling IRQs. + * This is in contrast to wait_event_interruptible_lock_irq_timeout(), + * which uses the spin_lock_irq() and spin_unlock_irq() functions instead. + * + * The function returns 0 if the @timeout elapsed, -ERESTARTSYS if it + * was interrupted by a signal, and the remaining jiffies otherwise + * if the condition evaluated to true before the timeout elapsed. + */ +#define wait_event_interruptible_lock_timeout(wq_head, condition, lock, \ + timeout) \ +({ \ + long __ret = timeout; \ + if (!___wait_cond_timeout(condition)) \ + __ret = __wait_event_lock_timeout( \ + wq_head, condition, lock, timeout, \ + TASK_INTERRUPTIBLE); \ + __ret; \ +}) + +/** + * wait_event_lock_timeout - sleep until a condition gets true or a timeout + * elapses. The condition is checked under the lock with IRQs + * enabled. This is expected to be called with the lock taken. + * @wq_head: the waitqueue to wait on + * @condition: a C expression for the event to wait for + * @lock: a spinlock_t that has been locked with spin_lock(), which will be + * released before schedule() and reacquired afterwards. + * @timeout: timeout, in jiffies + * + * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the + * @condition evaluates to true or signal is received. The @condition is + * checked each time the waitqueue @wq_head is woken up. + * + * wake_up() has to be called after changing any variable that could + * change the result of the wait condition. + * + * This is supposed to be called while holding the lock. The lock is + * dropped before going to sleep using spin_unlock() and is reacquired + * using spin_lock() afterwards, but without globally disabling IRQs. + * This is in contrast to wait_event_lock_irq_timeout(), which uses the + * spin_lock_irq() and spin_unlock_irq() functions instead. Compared to + * wait_event_interruptible_lock_timeout(), it uses the %TASK_UNINTERRUPTIBLE + * instead of allowing the task to be interrupted. + * + * The function returns 0 if the @timeout elapsed, or the remaining jiffies + * otherwise if the condition evaluated to true before the timeout elapsed. + */ +#define wait_event_lock_timeout(wq_head, condition, lock, timeout) \ +({ \ + long __ret = timeout; \ + if (!___wait_cond_timeout(condition)) \ + __ret = __wait_event_lock_timeout( \ + wq_head, condition, lock, timeout, \ + TASK_UNINTERRUPTIBLE); \ + __ret; \ +}) + /* * Waitqueues which are removed from the waitqueue_head at wakeup time */ -- 2.55.0