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=1796380871; b=pQRTp6TqVRqA0SL+ZZCRK8cwKDz34A9Gx+dmPHOci3lUVjVr4jvY3pdozSZEYt3Ggzox yOjO2bj5P/C9gafrnyDQmX9+PlGyOjsOTYioiwu8Pl1d6Rqf4o3c5ZYqyJJawo/5ehyKO 5BaHrVi34A9zXSyBkpjzRRBZu32EADGI7CjSFyaS+ENntpn3BO6f9eciU7zs4UCWdbpP/ yEz/qh/fMoxIKZBKjZxYt09EFP06eHEYGf6Z2BO+30Uzv/TzJxq0Je/JC1uapSj7McCug tL8wt8BcZWDZTzQQc7YhY3uQWCPY0gIk6UpgU7qyzvv/R1+kbZgCk5gwnbKOk0rMcpA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380871; 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-Transfer-Encoding; bh=VXcbSTyISKHwDKqVrXiqkmVZNXQVfqpbJCAuiBovScM=; b=HiTi7WsQAZj+u2XFsqO8Cw3mrKCa7Dzgy8bn8wRb5H/1pimZDTgPdz3/Xlv9LjP/6ZC7 dF93+iHzme9zFA1FV79ThQDPexY6WCk/Oj00rLx+t5PIOF3GIXvljZ93MHttsSBOMto18 voY6OLEdI3lYxpHmwJ0mqUieN/dPPrjHiDyrg21Uos6XagLXqIl6iVA5OVJA+YVaGiROj llfqhni8ucKR2Sixa11yLzL+bmkZFlU+6mztLhO3+Bx7yijLl1doigWJZ0yCtQS5/DW/0 OYDGJaY8u/bZcuzMoAHDCO4II1SSMWNTvWewX6txkD3OAolyAlKn6PWNE1r51kFRx8A== 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=j1ohglMp; 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 B9239606A332; Fri, 4 Dec 2026 10:41:11 +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=j1ohglMp Received: by smtp.kernel.org (Postfix) with ESMTPSA id 318681F000CE; Fri, 4 Dec 2026 10:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380871; bh=VXcbSTyISKHwDKqVrXiqkmVZNXQVfqpbJCAuiBovScM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=j1ohglMpNb7/5dhDSFTBIMnJwR1Lqo59jOv5uFFOeLWU97w3W0faa4peb8TWgG2FS 7FwOYvnYuq//kDkwPb2nzMDRvFzvjOpAcdFkDd7CmN3cSs2sLfruC/EXdVDInzDucV 5jGYRW6OnomVmPt0Q8ju+nn+QRmgirw0Cx8mAgsI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yao Yiqi , Helge Deller Subject: [PATCH 7.3 460/742] fbcon: Avoid cancel_delayed_work_sync() in atomic context Date: Fri, 4 Dec 2026 19:05:24 +0900 Message-ID: <20261204100647.383052900@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yao Yiqi commit b3a3f241dace3d4a775e1401b53a3f6d304534f0 upstream. 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 Signed-off-by: Greg Kroah-Hartman --- drivers/video/fbdev/core/fbcon.c | 41 +++++++++++++++++++++++++++++++++------ drivers/video/fbdev/core/fbcon.h | 1 2 files changed, 36 insertions(+), 6 deletions(-) --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -411,7 +411,8 @@ static void fb_flashcursor(struct work_s 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(); @@ -423,25 +424,53 @@ static void fb_flashcursor(struct work_s par->bitops->cursor(vc, info, enable, get_fg_color(vc, info, c), get_bg_color(vc, info, c)); - 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_blink) - queue_delayed_work(system_power_efficient_wq, &par->cursor_work, - par->cur_blink_jiffies); + if (!fbcon_cursor_blink) + 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); } @@ -789,7 +818,7 @@ static void fbcon_release(struct fb_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); --- a/drivers/video/fbdev/core/fbcon.h +++ b/drivers/video/fbdev/core/fbcon.h @@ -97,6 +97,7 @@ struct fbcon_par { int blank_state; int graphics; bool initialized; + bool cursor_blink_on; int rotate; char *cursor_data; #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION