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=1796327798; b=4QnjVOdSCJdorsjj5otmwM4Fy5QudKyMak8JIirZWn4VXQtSGHRT7rk3JWY/cLzvYbR7 TJs6Aix40dqKOtZSOCZCZ9Rfhp2Jx0h28FlimO8Wex/FU7yQXHDgTlgPNHOgycZOC78XI +JP9EA4FvGzubv49R571zrpDys6pnx+g1IbnHln0ZgeWXvG6jpiBZN6/CU6O+N61w34He Eh3QHAyreKs60QYwguLPV/UhsF5Et8x4jVFEURMiWaX+Vv3EcqmSrGCFnZDjNFvqINRAV gzSmLc5EwHbeqKKxaKam+v4MTnhu7kssQY9Uk+1C3W72ovTnKGcr8bqlh0iH/mfO4rA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796327798; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=zDzCdR49hrCS2OGewXT05veVggr9OsWEPbS5sAa9MVI=; b=YEeplZ5m3iuUrOE4c12dVzMm7wktl+CqTPSMJITzLTnX61ZTz9GEZa+KlaUqNf8fZJwv rcTwzkbJxE0VIimfazAWFWGnqSqfrtuyoWEIRDLB243WqFBFEZCs3CMW47tkDSOueYu2F m9x3mpv+JNFcGVE4wCf1o4wL7ISSiSRVzfumGSNFsdzO2dJLpFn8WBCHjV3FQdgpW2PMp bD8NGqUXFL0VtcWrUx32jY6qHGkNAFUFU8UwSMov4ygDeuwVPFjy5aFYoJPHUEOuALjcy W6jXvQAY02/CgRLNs4Zxc6lFpGUNq1K/a8gcd1KvT1pqwxnrSRlqUrU7PWWH8LjHSvA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cqaAm6TX; 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 BC73B606A334 for ; Thu, 3 Dec 2026 19:56:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cqaAm6TX Received: by smtp.kernel.org (Postfix) with ESMTPSA id 027DA1F00934; Thu, 3 Dec 2026 19:56:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796327798; bh=zDzCdR49hrCS2OGewXT05veVggr9OsWEPbS5sAa9MVI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cqaAm6TX0mNaZp75hoHW6CcU5q0svsfp4WzdwVJXnQ5J2doTtOgGltNEfeNQZHXSs 0Gbg1dMHIpvKIL9F8r3u0AB2Rb2qxsK3k17/R9vIETMfS/tXx0ke0SfBSlqo1YbLVX fqk8SKph5Uyhoh4o6VTEuQtmN8St3Uqluq+DgXAsnw0Jx5EnB7YuatIpiArXUnWSQi n+D2iSOTdEhwOJbjdBqd1bHZTZlVQL/Xlaa7YYeZEOGw8Gn+Jfx2xaDedG59xXiI46 KMdLIO3t6D9EHHkOAIeep08wAKGEpQLVITE8Iyy1AfNH5K/P9HubJJxp+//SMAgyRZ QqrOzuBGiF1tw== From: Sasha Levin To: stable@vger.kernel.org Cc: Yao Yiqi , Helge Deller , Sasha Levin Subject: [PATCH 6.1.y] fbcon: Avoid cancel_delayed_work_sync() in atomic context Date: Thu, 3 Dec 2026 14:56:36 -0500 Message-ID: <20261203195602.731798-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120259-publisher-willed-5e68@gregkh> References: <2026120259-publisher-willed-5e68@gregkh> 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-Transfer-Encoding: 8bit From: Yao Yiqi [ Upstream commit b3a3f241dace3d4a775e1401b53a3f6d304534f0 ] fbcon_cursor() can be reached from the console printing path, which runs in atomic context. When the VT software cursor is enabled (vc_cursor_type & CUR_SW), it calls fbcon_del_cursor_work(), which uses cancel_delayed_work_sync() and therefore may sleep. With CONFIG_DEBUG_ATOMIC_SLEEP enabled, the following is reported: BUG: sleeping function called from invalid context at kernel/workqueue.c:4722 in_atomic(): 1, irqs_disabled(): 1, non_block: 0 ... __cancel_work_sync fbcon_del_cursor_work fbcon_cursor hide_cursor vt_console_print console_unlock ... Make the default helper safe: fbcon_del_cursor_work() only stops blinking, using cancel_delayed_work(), which is allowed in any context. Every "stop blinking" call site keeps using it, including fbcon_cursor(). Only fbcon_release(), which is about to free @par and must ensure that no callback is still using it, calls the separate fbcon_del_cursor_work_sync(). New call sites therefore get the safe variant by default. cancel_delayed_work() does not wait for a callback that is already running. Since fb_flashcursor() re-arms itself, a callback that has already been dequeued by process_one_work() can queue the work again after fbcon_del_cursor_work() returns. Add a cursor_blink_on flag to struct fbcon_par: fbcon_add_cursor_work() sets it, fbcon_del_cursor_work() clears it, and fb_flashcursor() checks it after taking console_lock and returns without drawing or re-arming once blinking has been stopped. Keep the requeue inside the console_lock section so that the flag check and the requeue are not split by a concurrent stop. Fixes: 3b0fb6ab25dd ("fbcon: Use delayed work for cursor") Cc: stable@vger.kernel.org Assisted-by: Opencode:deepseek-v4.1-flash Signed-off-by: Yao Yiqi Signed-off-by: Helge Deller [ sashal: adapted fbcon_cursor_noblink and cursor ops to the older tree: inverted flag check, par->cursor() with get_color() instead of par->bitops->cursor() with fg/bg helpers, and shifted fbcon.h context. ] Signed-off-by: Sasha Levin --- drivers/video/fbdev/core/fbcon.c | 41 +++++++++++++++++++++++++++----- drivers/video/fbdev/core/fbcon.h | 1 + 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c index 2b891dd6330f9..5c28457cf12bf 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -372,7 +372,8 @@ static void fb_flashcursor(struct work_struct *work) if (par->currcon != -1) vc = vc_cons[par->currcon].d; - if (!vc || !con_is_visible(vc) || + if (!par->cursor_blink_on || + !vc || !con_is_visible(vc) || fbcon_info_from_console(vc->vc_num) != info || vc->vc_deccm != 1) { console_unlock(); @@ -384,25 +385,53 @@ static void fb_flashcursor(struct work_struct *work) CM_ERASE : CM_DRAW; par->cursor(vc, info, mode, get_color(vc, info, c, 1), get_color(vc, info, c, 0)); - console_unlock(); + /* + * Re-arm under console_lock so that a concurrent + * fbcon_del_cursor_work() cannot race with this requeue. + */ queue_delayed_work(system_power_efficient_wq, &par->cursor_work, par->cur_blink_jiffies); + console_unlock(); } static void fbcon_add_cursor_work(struct fb_info *info) { struct fbcon_par *par = info->fbcon_par; - if (!fbcon_cursor_noblink) - queue_delayed_work(system_power_efficient_wq, &par->cursor_work, - par->cur_blink_jiffies); + if (fbcon_cursor_noblink) + return; + + par->cursor_blink_on = true; + queue_delayed_work(system_power_efficient_wq, &par->cursor_work, + par->cur_blink_jiffies); } +/* + * Stop the cursor blink. + * + * Does not wait for a callback that is already running, so it is safe to + * call from any context. + * + * console_lock serializes this with the requeue in fb_flashcursor(); + * otherwise a running callback could re-arm the work. + */ static void fbcon_del_cursor_work(struct fb_info *info) { struct fbcon_par *par = info->fbcon_par; + par->cursor_blink_on = false; + cancel_delayed_work(&par->cursor_work); +} + +/* + * Stop the cursor blink and wait for a running callback to finish before + * @par is freed. May sleep, only for teardown paths. + */ +static void fbcon_del_cursor_work_sync(struct fb_info *info) +{ + struct fbcon_par *par = info->fbcon_par; + cancel_delayed_work_sync(&par->cursor_work); } @@ -705,7 +734,7 @@ static void fbcon_release(struct fb_info *info) if (info->fbcon_par) { struct fbcon_par *par = info->fbcon_par; - fbcon_del_cursor_work(info); + fbcon_del_cursor_work_sync(info); kfree(par->cursor_state.mask); kfree(par->cursor_data); kfree(par->cursor_src); diff --git a/drivers/video/fbdev/core/fbcon.h b/drivers/video/fbdev/core/fbcon.h index 95d2399fe8fc5..834a6ced12a93 100644 --- a/drivers/video/fbdev/core/fbcon.h +++ b/drivers/video/fbdev/core/fbcon.h @@ -77,6 +77,7 @@ struct fbcon_par { int graphics; int save_graphics; /* for debug enter/leave */ bool initialized; + bool cursor_blink_on; int rotate; int cur_rotate; char *cursor_data; -- 2.53.0