From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382196; b=zHkr8R3gkuVca1kz/1J0Fufj9KREMLeCTowuw0OfcW6lEeKevS8udkYmgw0dFG+EJ1Q3 0d6nrryxovIp6wzWhFrrtdhzjYQODjA4FPiqNX3tnpc+Fb/Fck4TZvlLcC6l0vHeIuPrr nNJ/PdZNWqR+8F4CeLRIVZID9hHSnj+mbkvpy1LPvQi60u1CPBw9rpt6qgW5aUblHgw65 bncuyQgE9zXaOizsaDpzCP5LvZAaJDQezgWgxFspoo+XQkSTLxMZbsQKx0igb973/8kvc xfJi2krpfazqRB3nOzIm2TLeAKFtvvSe2uTT/12EAqF63tTtKfMgolF7ZxpEHUKdTfw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382196; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=9c1W+RSML4nHVS+yR0QFOKzW0PeksFHDZAY5A4f6cuE=; b=24VW91vb+FK15t/HCd3Zw/keQ9q+1Zr80hG26d4o5GNH82LZsIGkF0CeBDHOcDYN5r4X cTmEyDSWR1ukzel0Q3zJBH8aIjC/azHoOBqnVa8sXTueDTE4ick1sAHljddGXcH8OOkim jXqEpJ0HTReYKl3FWPq7DIcSMmg7aN3QHKK2/ZWcSLFPAyecwplXx6UYZ5KUNx/VtWe1s 5obgpsXZYZpGTq1qmYqpiDPpQLFNuCmuez60XqsBYAQedr/UyqGtsronSxZRScusdlt4U 4gj4Epk8NVLvIoSdMaUPikmNBekmhHv1oBO6jZVs2Qr6wJWBVkuWm9BJiUyL/7QzgkA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=0EStMJyc; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5CD7606A322; Fri, 4 Dec 2026 11:03:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=0EStMJyc Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6752A1F000C2; Fri, 4 Dec 2026 11:03:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382195; bh=9c1W+RSML4nHVS+yR0QFOKzW0PeksFHDZAY5A4f6cuE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=0EStMJyczuvhHgGYYM67KzMAAocFwxy2T3k/wGKy8nXM5dxMsWCDUXe/mP/JFy1Dj PqeAhW4EqvWG4KCibJituOOVd/SailV15BzGq4qLWh87nj20X6mX6fHx75f3xbyo56 xk+ymYzGf1FuORBUmdz2bH3bgJxGLV6oLLB8hGwg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Thomas Zimmermann , Zack Rusin , Louis Chauvet , Javier Martinez Canillas , David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , dri-devel@lists.freedesktop.org Subject: [PATCH 6.18 349/703] drm/vblank: timer: Do not block within critical section Date: Fri, 4 Dec 2026 19:04:08 +0900 Message-ID: <20261204100637.076058539@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Zimmermann commit f02d1f70d361c42d09569e51612d6be5ffceb7d6 upstream. Remove try-to-cancel loop from drm_crtc_vblank_start_timer() to avoid a possible livelock while spinning within the loop. Hold interval_lock when starting and forwarding the vblank timer's hrtimer to avoid forwarding an already queued timer. The vblank helper drm_vblank_disable_and_save() and the vblank IRQ handler hold the spin lock vblank_time_lock at some point. This can result in a deadlock if the vblank timer's disable code in drm_crtc_vblank_cancel_timer() calls hrtimer_cancel() directly: the helper waits for the timer function to complete and the timer function waits for the helper to release vblank_time_lock. drm_crtc_vblank_cancel_timer() works around this problem by calling hrtimer_try_to_cancel() instead. For re-enabling the vblank timer, drm_crtc_vblank_start_timer() currently waits for the vblank timer to stop. It runs into the same locking problem while waiting for the timer function to complete. Resolve the locking problem by removing hrtimer_try_to_cancel() from drm_crtc_vblank_start_timer(). Hold interval_lock while starting or forwarding the hrtimer. Without holding interval_lock, drm_crtc_vblank_start_timer() could set an interval and start the hrtimer; while a concurrent timer function forwards the timer with the old interval. This can corrupt the ordering of the hrtimer's internal queue. Holding the lock prevents this from happening. When starting the vblank timer, it is still possible that an already running timer sends out a vblank event at the previous vblank interval. This is merely an inconsistency and not critical. Closes: https://lore.kernel.org/dri-devel/20260914111129.300691F00898@smtp.kernel.org/ Suggested-by: Ville Syrjälä Signed-off-by: Thomas Zimmermann Reviewed-by: Zack Rusin Fixes: 74afeb812850 ("drm/vblank: Add vblank timer") Cc: Louis Chauvet Cc: Javier Martinez Canillas Cc: David Airlie Cc: Simona Vetter Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: dri-devel@lists.freedesktop.org Cc: # v6.19+ Link: https://patch.msgid.link/20261110084710.503870-2-tzimmermann@suse.de Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/drm_vblank.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) --- a/drivers/gpu/drm/drm_vblank.c +++ b/drivers/gpu/drm/drm_vblank.c @@ -2185,19 +2185,18 @@ static enum hrtimer_restart drm_vblank_t struct drm_crtc *crtc = vtimer->crtc; const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; struct drm_device *dev = crtc->dev; - unsigned long flags; - ktime_t interval; - u64 ret_overrun; + u64 ret_overrun = 1; bool succ; - spin_lock_irqsave(&vtimer->interval_lock, flags); - interval = vtimer->interval; - spin_unlock_irqrestore(&vtimer->interval_lock, flags); + scoped_guard(spinlock_irqsave, &vtimer->interval_lock) { + ktime_t interval = vtimer->interval; - if (!interval) - return HRTIMER_NORESTART; + if (!interval || hrtimer_is_queued(timer)) + return HRTIMER_NORESTART; + + ret_overrun = hrtimer_forward_now(timer, interval); + } - ret_overrun = hrtimer_forward_now(&vtimer->timer, interval); if (ret_overrun != 1) drm_dbg_vbl(dev, "vblank timer overrun\n"); @@ -2226,7 +2225,6 @@ int drm_crtc_vblank_start_timer(struct d { struct drm_vblank_crtc *vblank = drm_crtc_vblank_crtc(crtc); struct drm_vblank_crtc_timer *vtimer = &vblank->vblank_timer; - unsigned long flags; if (!vtimer->crtc) { /* @@ -2236,22 +2234,14 @@ int drm_crtc_vblank_start_timer(struct d spin_lock_init(&vtimer->interval_lock); hrtimer_setup(&vtimer->timer, drm_vblank_timer_function, CLOCK_MONOTONIC, HRTIMER_MODE_REL); - } else { - /* - * Timer should not be active. If it is, wait for the - * previous cancel operations to finish. - */ - while (hrtimer_active(&vtimer->timer)) - hrtimer_try_to_cancel(&vtimer->timer); } drm_calc_timestamping_constants(crtc, &crtc->mode); - spin_lock_irqsave(&vtimer->interval_lock, flags); - vtimer->interval = ns_to_ktime(vblank->framedur_ns); - spin_unlock_irqrestore(&vtimer->interval_lock, flags); - - hrtimer_start(&vtimer->timer, vtimer->interval, HRTIMER_MODE_REL); + scoped_guard(spinlock_irqsave, &vtimer->interval_lock) { + vtimer->interval = ns_to_ktime(vblank->framedur_ns); + hrtimer_start(&vtimer->timer, vtimer->interval, HRTIMER_MODE_REL); + } return 0; }