From nobody Fri Oct 3 08:49:10 2025 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5F79345723 for ; Tue, 2 Sep 2025 18:34:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756838054; cv=none; b=ekLY7+XwPa3s81h1tPiYNIU+OR4UNWbgIS5RF0V3rlV0+QeZf3IZ1Pj2ims+Te1fBzUMfxb5RsxcMICBTLex0K2pjooPriL2ml6TqinCt9JS4OOrLs1Y02OaAeurYInojilrKYOesW4pOhFme5LK/lMEOWLGxvQoXSrTJ/K8rIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756838054; c=relaxed/simple; bh=r5zUwQ6GxG1jCUU829+hFTuxN+HS8Xhr4zObCZLsark=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HkkWsdwZapenT38J8R6UJqPwCtVsfr4KOF3yWyGCs2XsUAWmUW7CBZtotryXBAypiX8rqu8juHDmrHyRqD3sAEo36m/wFpaXAhj5Ggx7Pxg6b3pvJsE2hBehJ6dIxAAUPJWF9ZZ5YlqWOo7ZHWJfXKVlk7qo4JbZ3eqits+uMAE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=B6hVTgtg; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="B6hVTgtg" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-45b8b25296fso18668135e9.2 for ; Tue, 02 Sep 2025 11:34:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1756838050; x=1757442850; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ttbC3r1SK6GKufIVtofaDKxaTS0OI5TigCweNxXtNk4=; b=B6hVTgtg4rayLqB+bJKHZhhKL680Oc6bM2JmC+XI5Obm0sQw73cFWc48N3bmiZBI9y oI7fYzBzho/4qWSQvnrhwgTjSiOqaQmnIgKy6QJ/yWhdJL+japW5nj6j45lGk+9197eE 5VPpAg2TtF1J2UzRYKi0qqktPjbIT2mfjx5HM6pWIgWa1Cbv9342P+y3Fwmv5rx7Bmkf ITZC6OuSBEwZGy8clRw6I8HlFSCCIZwLDQJ24drd2J3iwGc1Sm+WDh4txqEM8kQgLsYr XffRVmcp2OxS186TEU6oBpnlh1wJ2KAxyT8E50WW5FWIahBKOIRd6O1T+g2MTak5kKXr EXWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756838050; x=1757442850; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ttbC3r1SK6GKufIVtofaDKxaTS0OI5TigCweNxXtNk4=; b=vmJEYa4KAHrlZg/3eF81YSOEztSeHwnczsLByD9BJNyxxOoAjDVCsiczzrYh+iVumL kOW6NR8aa+4KeAQLwCspdqds0/MUp/OSDNN2OuGeq5zjanTYUz/Gwj2aYuBDvjnnAZih gk/5wFCFupGW/bZGbnQFCdChGwc3/C3vgFzERi3xKxshbzdk4TUdi3BgBq2MFo/umiJK /pvfDBJ/LaT1MDq8DUSs76t2ZqaZ47H836i2gcxArb7TNc1JfRdxrse6Zf3wTg4Fyc+W SLTFY0u1QPwtFsOZ8ZuuLC1HQsXmKZKdM1Z8O0Eo2vujcQtBHSf3ao0lo8bqScNiBQji yShQ== X-Gm-Message-State: AOJu0Yxwyn83tXSqATqGTdVZnT4hnPqqq6oKm+iag/Z/+/4nJddL55fh FiMP6XXiPA3W1X40NSOSnPS3GFdQW/ZCbZ9lKcsuPhkbIXvPk6+YfuEKSwF70oO9/os= X-Gm-Gg: ASbGnctig/3X4BmosrTCv0TGhKbQV73e0HSmN5tuxSGRfhH3DwOhvSe591RbjD+Sh+K 047TsVWXAIla0aRuwIS/niSl1T2wVdySjIzn1ILyh9h64w3955Ic49UFlkU/iwZ30a3HVAQVnY5 mOEmY9eW/nol4FSK7USQmYiJ/NgjgmA8IuO3xkfjP1MGqIIMZIJ2n08HfCsE0btujwrvfwkyJDA fHbIMT/VLTmappvm3+Ow1ykNyX1cxdxxv/Tf9edSG59VYebEM1OcYWcsuvbZTEOlDU/OBBDs0zK emLIyZbUZT6iAq6vLX0sB71Lxtfk6M5KPKqLYt7IdgQlHrQrRgFyO4iEpLm1R0V63OpL9DnsmPH QpwBCY5/Nmxnysh6O9dq6IgN3XH1vew== X-Google-Smtp-Source: AGHT+IGCzUSqvHnAnst5yqD69KVC/ia6+vzcWIQx+WNo5yIeMhcitFEhgO7XQVRUak+laB8Ki2ODiA== X-Received: by 2002:a05:6000:26ca:b0:3c9:f4a3:f145 with SMTP id ffacd0b85a97d-3d1de89c4efmr10176812f8f.27.1756838050020; Tue, 02 Sep 2025 11:34:10 -0700 (PDT) Received: from [127.0.0.1] ([2804:5078:9a0:f000:58f2:fc97:371f:2]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7722a4e1d4fsm14028477b3a.73.2025.09.02.11.34.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Sep 2025 11:34:09 -0700 (PDT) From: Marcos Paulo de Souza Date: Tue, 02 Sep 2025 15:33:52 -0300 Subject: [PATCH v3 1/4] printk: nbcon: Export console_is_usable 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: quoted-printable Message-Id: <20250902-nbcon-kgdboc-v3-1-cd30a8106f1c@suse.com> References: <20250902-nbcon-kgdboc-v3-0-cd30a8106f1c@suse.com> In-Reply-To: <20250902-nbcon-kgdboc-v3-0-cd30a8106f1c@suse.com> To: Greg Kroah-Hartman , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky , Jason Wessel , Daniel Thompson , Douglas Anderson Cc: linux-kernel@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net, Marcos Paulo de Souza X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1756838042; l=4838; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=r5zUwQ6GxG1jCUU829+hFTuxN+HS8Xhr4zObCZLsark=; b=thmhh708ziRAZ1AKoaAMXXM2K8RvBcpU7YNTWqO/pGIUEwoabt4quMFBc7EJl0TqEQcxgSUes /8JEUpU3m7gDUyx8npud/FeN8pzBdfLlKR2VuPhcg/Ns+3PV5utwkVK X-Developer-Key: i=mpdesouza@suse.com; a=ed25519; pk=/Ni/TsKkr69EOmdZXkp1Q/BlzDonbOBRsfPa18ySIwU= The helper will be used on KDB code in the next commits. Signed-off-by: Marcos Paulo de Souza Reviewed-by: Petr Mladek --- include/linux/console.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ kernel/printk/internal.h | 44 -------------------------------------------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index 8f10d0a85bb4536e4b0dda4e8ccbdf87978bbb4a..67af483574727c00eea1d5a1eac= c994755c92607 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -605,6 +605,48 @@ extern bool nbcon_can_proceed(struct nbcon_write_conte= xt *wctxt); extern bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt); extern bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt); extern void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt); + +/* + * Check if the given console is currently capable and allowed to print + * records. Note that this function does not consider the current context, + * which can also play a role in deciding if @con can be used to print + * records. + */ +static inline bool console_is_usable(struct console *con, short flags, boo= l use_atomic) +{ + if (!(flags & CON_ENABLED)) + return false; + + if ((flags & CON_SUSPENDED)) + return false; + + if (flags & CON_NBCON) { + /* The write_atomic() callback is optional. */ + if (use_atomic && !con->write_atomic) + return false; + + /* + * For the !use_atomic case, @printk_kthreads_running is not + * checked because the write_thread() callback is also used + * via the legacy loop when the printer threads are not + * available. + */ + } else { + if (!con->write) + return false; + } + + /* + * Console drivers may assume that per-cpu resources have been + * allocated. So unless they're explicitly marked as being able to + * cope (CON_ANYTIME) don't call them until this CPU is officially up. + */ + if (!cpu_online(raw_smp_processor_id()) && !(flags & CON_ANYTIME)) + return false; + + return true; +} + #else static inline void nbcon_cpu_emergency_enter(void) { } static inline void nbcon_cpu_emergency_exit(void) { } @@ -612,6 +654,8 @@ static inline bool nbcon_can_proceed(struct nbcon_write= _context *wctxt) { return static inline bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt) {= return false; } static inline bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt) { = return false; } static inline void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt= ) { } +static inline bool console_is_usable(struct console *con, short flags, + bool use_atomic) { return false; } #endif =20 extern int console_set_on_cmdline; diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index ef282001f200fdbbacae3171932bf9f049037a85..bef97f2d11793191280bfb46f7f= 8b13bf2560351 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -112,47 +112,6 @@ bool nbcon_kthread_create(struct console *con); void nbcon_kthread_stop(struct console *con); void nbcon_kthreads_wake(void); =20 -/* - * Check if the given console is currently capable and allowed to print - * records. Note that this function does not consider the current context, - * which can also play a role in deciding if @con can be used to print - * records. - */ -static inline bool console_is_usable(struct console *con, short flags, boo= l use_atomic) -{ - if (!(flags & CON_ENABLED)) - return false; - - if ((flags & CON_SUSPENDED)) - return false; - - if (flags & CON_NBCON) { - /* The write_atomic() callback is optional. */ - if (use_atomic && !con->write_atomic) - return false; - - /* - * For the !use_atomic case, @printk_kthreads_running is not - * checked because the write_thread() callback is also used - * via the legacy loop when the printer threads are not - * available. - */ - } else { - if (!con->write) - return false; - } - - /* - * Console drivers may assume that per-cpu resources have been - * allocated. So unless they're explicitly marked as being able to - * cope (CON_ANYTIME) don't call them until this CPU is officially up. - */ - if (!cpu_online(raw_smp_processor_id()) && !(flags & CON_ANYTIME)) - return false; - - return true; -} - /** * nbcon_kthread_wake - Wake up a console printing thread * @con: Console to operate on @@ -204,9 +163,6 @@ static inline bool nbcon_legacy_emit_next_record(struct= console *con, bool *hand static inline void nbcon_kthread_wake(struct console *con) { } static inline void nbcon_kthreads_wake(void) { } =20 -static inline bool console_is_usable(struct console *con, short flags, - bool use_atomic) { return false; } - #endif /* CONFIG_PRINTK */ =20 extern bool have_boot_console; --=20 2.50.0 From nobody Fri Oct 3 08:49:10 2025 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6359B34DCEF for ; Tue, 2 Sep 2025 18:34:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756838057; cv=none; b=dHrHO3n1C3rSQPGxvZ27v8kLdfLhk/M3e3d5krIm3mPZXPSARdeMLyOK2lhH25Px1He9dvJPrGWwNUAezvlYwBnS6FOaqoKwRMkSIbbKyN1rvdSAVPuJvx+6ZBvae+fk8N7ZXBQJqEkckGp0K1eMT7Ai/wuqdw2HH59OGQc6c4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756838057; c=relaxed/simple; bh=/pJm51k0Rdgg7h4U6y2MCvfn06HwAtBOQoQcGVJQThM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MuGvzafZKRDxXaCzQBfnWFPvgYJ1cR8jbBX35lEJzbSNDmeBDQDR6kbMo7z4jzExC3pKTlHk8d0gt6Q3p0zhvC14z1OllNWsyK99S8MmlOmjFdTZyyBpVrFuC6KQwiqza5nWlYrL/p2EyDRvhh1sKmczpm1H6/reNFgdJeJHhJU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=CPXj3lm7; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="CPXj3lm7" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-45b7c01a708so20277625e9.3 for ; Tue, 02 Sep 2025 11:34:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1756838054; x=1757442854; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Ozr279Qr3C7/dftyUFUfvHvaGGNWVlgEMFeuHaNz1sQ=; b=CPXj3lm7h4ZMcoqqe8J+Qb1lSof3aRHjZ9ZyXjARXTQIlK/cA/rig9x7dB+GiAFE4l HOIuy/D6c/qaeymAQUudgk4c5wXsXTV8JyORUI5DHrALy4oyB9C3DyoJU38L0RGqJYut w/szsR8Yy3bCZmZKLcjw3n/6lhmbvA6rthmDpHx9h4c+NDQhXZOw9EPAEKr55PhrZfKS qGjs654GAOz7roX3q5kkm8ifYxawVoCNoxY8eBsvoWGdL9oeJg+kn5XL4mDdX8ZR3Ala mqZFFB4ZYCX/OFAs4UrWH9vqjnoA2EuSWx52q0CX2cSe06XVgnUwezJxqZbIphaeV9a5 uV7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756838054; x=1757442854; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ozr279Qr3C7/dftyUFUfvHvaGGNWVlgEMFeuHaNz1sQ=; b=giBtcVZ2H+XTlsMy8f1BXAz5inVcE7/TrxmZQb7ckN47FZGqtTEBFd3xUsuQ61XNxE 9qPbFH8EhTDPwWV/f5tY1UkemDVsnCOiT+6Cst0r7bA+duZz90KpT8k1DEf7SdUfSpYo bn8En/iQDNrk2aDd+sVYhht7lxpLvL6rQvdWCtdfBREdWgtfPpK1NboH1Xk2owGTaqfP iJ9mv1s+/3KewREF9zjDhXmb2mk4eyntRLXRIZSMpLJtEkAhmaAwoD/qqG41/ZPCH7Uc JXgzzDt1bcXavUNQ2AhNPrWnDssXOgFruTL2YClTp0YNiHq8PiKWoC3UKLCGm6B+SA7l TcXQ== X-Gm-Message-State: AOJu0Yw44G9Oy5jSdE2M9wLQaq2K5jsQdlUUx0ul3RgXTgp0GEGX5wDG TEKh0Uo0mevEdxFgtZm0jXdx4j2hXBA6hAZR4P/isESdGuGqndEAv9Z3jMk6nhGIa9c= X-Gm-Gg: ASbGncs6iN2JqUPsPwePr1TXc28nzbn15BvE+wsyUz07BFH6VjnNiH7vss0ZpkeMVSk wTYSVpuOdQ8ay+xu9oj6UpgkCYzt8N28f1ONLrjFyP7Y2yq3VZku5eWnzREKz+D5fElwCc0CM3T uy43IDJusWaFSQaPfG5/Jljx62plXWdegcvCb/oLTMHmhZfyZYGA2cO13gQ7OEC3SwKw7N/I2JU cqax1HKrrkCQg9z8RRX91sLr4x4bh5OVxvxhAisa4sd6tjPkLfZLDK3yw7FRKgoiTXhyzoUoh19 o0bjHkzokhFShOf4zgRpqO0pFstr6U0v0qPBJpe82ziLDMi821PTFmZJtMcIfvahnpD1hxvLIrb 1VqsND1+zrEbO/LQ7OXQV4CWkQerFFg== X-Google-Smtp-Source: AGHT+IFyoewyQkFD3NG61mGAIXizgMS8veX/EjIkv5VWOA4VeD/40JNT3aeC/9VsEcdOKAPv/TumTA== X-Received: by 2002:a05:6000:26cb:b0:3ca:99ad:519e with SMTP id ffacd0b85a97d-3d1dca7bed7mr8080271f8f.4.1756838053592; Tue, 02 Sep 2025 11:34:13 -0700 (PDT) Received: from [127.0.0.1] ([2804:5078:9a0:f000:58f2:fc97:371f:2]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7722a4e1d4fsm14028477b3a.73.2025.09.02.11.34.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Sep 2025 11:34:13 -0700 (PDT) From: Marcos Paulo de Souza Date: Tue, 02 Sep 2025 15:33:53 -0300 Subject: [PATCH v3 2/4] printk: nbcon: Introduce KDB helpers 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: quoted-printable Message-Id: <20250902-nbcon-kgdboc-v3-2-cd30a8106f1c@suse.com> References: <20250902-nbcon-kgdboc-v3-0-cd30a8106f1c@suse.com> In-Reply-To: <20250902-nbcon-kgdboc-v3-0-cd30a8106f1c@suse.com> To: Greg Kroah-Hartman , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky , Jason Wessel , Daniel Thompson , Douglas Anderson Cc: linux-kernel@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net, Marcos Paulo de Souza X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1756838042; l=4736; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=/pJm51k0Rdgg7h4U6y2MCvfn06HwAtBOQoQcGVJQThM=; b=OwV7zxr7qtBpl4tFe1W2+lxYPvdoZ/xhEiJjaExvY1Sh/xGKLCnnELpOYrDD0V7OjQdDn8eVs 6rOYDz5TTAYBwwQQlG+wwAIcSTorufLSVyyFwf2tTcE+uxJkjFiMRnv X-Developer-Key: i=mpdesouza@suse.com; a=ed25519; pk=/Ni/TsKkr69EOmdZXkp1Q/BlzDonbOBRsfPa18ySIwU= These helpers will be used when calling console->write_atomic on KDB code in the next patch. It's basically the same implementaion as nbcon_device_try_acquire, but using NBCON_PORIO_EMERGENCY when acquiring the context. For release we need to flush the console, since some messages could be added before the context was acquired, as KDB emits the messages using con->{write,write_atomic} instead of storing them on the ring buffer. Signed-off-by: Marcos Paulo de Souza --- include/linux/console.h | 6 +++++ kernel/printk/nbcon.c | 66 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 72 insertions(+) diff --git a/include/linux/console.h b/include/linux/console.h index 67af483574727c00eea1d5a1eacc994755c92607..b34c5a0b86303e2fb4583fa467d= 8be43761cf756 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -605,6 +605,9 @@ extern bool nbcon_can_proceed(struct nbcon_write_contex= t *wctxt); extern bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt); extern bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt); extern void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt); +extern bool nbcon_kdb_try_acquire(struct console *con, + struct nbcon_write_context *wctxt); +extern void nbcon_kdb_release(struct nbcon_write_context *wctxt); =20 /* * Check if the given console is currently capable and allowed to print @@ -654,6 +657,9 @@ static inline bool nbcon_can_proceed(struct nbcon_write= _context *wctxt) { return static inline bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt) {= return false; } static inline bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt) { = return false; } static inline void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt= ) { } +static inline bool nbcon_kdb_try_acquire(struct console *con, + struct nbcon_write_context *wctxt) { return false; } +static inline void nbcon_kdb_release(struct console *con) { } static inline bool console_is_usable(struct console *con, short flags, bool use_atomic) { return false; } #endif diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 646801813415f0abe40cabf2f28ca9e30664f028..ff218e95a505fd10521c2c4dfb0= 0ad5ec5773953 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -1855,3 +1855,69 @@ void nbcon_device_release(struct console *con) console_srcu_read_unlock(cookie); } EXPORT_SYMBOL_GPL(nbcon_device_release); + +/** + * nbcon_kdb_try_acquire - Try to acquire nbcon console, enter unsafe + * section, and initialized nbcon write context + * @con: The nbcon console to acquire + * @wctxt: The nbcon write context to be used on success + * + * Context: Under console_srcu_read_lock() for emiting a single kdb message + * using the given con->write_atomic() callback. Can be called + * only when the console is usable at the moment. + * + * Return: True if the console was acquired. False otherwise. + * + * kdb emits messages on consoles registered for printk() without + * storing them into the ring buffer. It has to acquire the console + * ownerhip so that it could call con->write_atomic() callback a safe way. + * + * This function acquires the nbcon console using priority NBCON_PRIO_EMER= GENCY + * and marks it unsafe for handover/takeover. + */ +bool nbcon_kdb_try_acquire(struct console *con, + struct nbcon_write_context *wctxt) +{ + struct nbcon_context *ctxt =3D &ACCESS_PRIVATE(wctxt, ctxt); + + memset(ctxt, 0, sizeof(*ctxt)); + ctxt->console =3D con; + ctxt->prio =3D NBCON_PRIO_EMERGENCY; + + if (!nbcon_context_try_acquire(ctxt, false)) + return false; + + if (!nbcon_context_enter_unsafe(ctxt)) + return false; + + return true; +} + +/** + * nbcon_kdb_release - Exit unsafe section and release the nbcon console + * + * @wctxt: The nbcon write context initialized by a successful + * nbcon_kdb_try_acquire() + * + * Context: Under console_srcu_read_lock() for emiting a single kdb message + * using the given con->write_atomic() callback. Can be called + * only when the console is usable at the moment. + */ +void nbcon_kdb_release(struct nbcon_write_context *wctxt) +{ + struct nbcon_context *ctxt =3D &ACCESS_PRIVATE(wctxt, ctxt); + + if (!nbcon_context_exit_unsafe(ctxt)) + return; + + nbcon_context_release(ctxt); + + /* + * Flush any new printk() messages added when the console was blocked. + * Only the console used by the given write context was blocked. + * The console was locked only when the write_atomic() callback + * was usable. + */ + __nbcon_atomic_flush_pending_con(ctxt->console, + prb_next_reserve_seq(prb), false); +} --=20 2.50.0 From nobody Fri Oct 3 08:49:10 2025 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05CC6350823 for ; Tue, 2 Sep 2025 18:34:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756838061; cv=none; b=T6HaQYP1ZtT7Yu+CE19Q7IhcCB9mHys+1bky1wdu/g/OvI81jM6vy+vOHLp8mNtpdG/M2ChONvlaw28oHYgStLfRyLVECfo45UOPyvBW7U64nyCZfXhri21P9BkDEt0ht9ka+msBB7dJPh4nAnd3Re4iFjQHWZ36iThHeQ81Y8s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756838061; c=relaxed/simple; bh=r5/WzNLFvBizJNQfa0Ilg++26fG8AY3qSmOM5PSpOPE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cDeEvg7Lp0kXf2q+0BY55Am0wSWfl91ZF5FNZlr1kLTtkjdG2KZQ9yk8TXp+loyiTLknawMbizsHzXC4PHyDE8Q6ZIMo31nljfgLPfakfde/ri6uwCGYjtjBrBWsFqf+xp41WV6v6HBamhv2j7XMCKUAQ6zfHeVGb2Ag/cKkW/U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=gcNLQJU7; arc=none smtp.client-ip=209.85.221.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="gcNLQJU7" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-3d17f24d42fso2464280f8f.1 for ; Tue, 02 Sep 2025 11:34:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1756838057; x=1757442857; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=WnHal8GQDAKujAP+BdXrilvKsGown9cJN4bGYLKXHLw=; b=gcNLQJU7p3P1/fyT8VDWAkCfqJgC31c+pgJqVjTrgnFIrWMrV8+O0C/BH62NptKKwo 2cne7ndHuJ2JkFtTUHBe771WobZ2doHifgdMpVttSTxz4PA95DRUiEHN64Xbvnm/OwHb yxfHyIIJ5XIXNodWXCJ9cb7ERm8mIKMh8t1fNjpfppEa+AuX1BWgOxBT2bSygUbE/GKz 598eJY7WHNPk9FExhdiCQQpH6EJpk0IBuUnq9OiLq3jGSBr8rOKgXtiHUfmA2wg4Guke z3nGxnlBHY7GPNBni4Z45CTZP7yeiwaVm9QxFWUW+D6HnMmwSIKTwxB5Zt7iKZZjfUiO FgMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756838057; x=1757442857; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WnHal8GQDAKujAP+BdXrilvKsGown9cJN4bGYLKXHLw=; b=dVKD3AYoOY+IWyvoGnxCCpYv+oko1k2Ml5zmLtwe1stXuOyLYnf4U020r8snMvtinv vhM4FnonmzcXfsT2A7HqPUaLiLdMVTNg6tUcasgj0E3FNYPso75FDJ5cOb/ja0R8ljVF cexvwVhZ5ktZEA36jVvRBOWw9Y+n0H1vuTZ4Hov6tM8r7DcVccc76Yu+zegh9xLHQrhV +lXHMWFQTirNCbwrIqv1OB8Knf0GTJYPPyHc4iYbRtMzpJhJi+gPiN8CmMCefpAoeeZD BtzxA5Ie+LZVNTC/J2AuAp2Ec8kHCZp3YBj2z6WnVwQ7LsRNCPbTjPTBGKCSg+xMIvwK qmHw== X-Gm-Message-State: AOJu0Yz+oxxOff1+RBwm96h+0jeVWNghS8dzUF8541XqvLl9kNq42yBb /cSjT9qB2Otc7qpahHG7MINTWPbsqi0TxUujSIH7iveGQWF5mg/69wJYaYJYPKYPjYPpe0n4szT HgU/A11I= X-Gm-Gg: ASbGncubU3G8XbUNVGFUWSVWhv8Q8W8J2zs+C9Q2UcHhKhn7QWhQBDTLIjc+XoXGXGX m/H2aG+8A7RUt28jZ4YLThZ1yiP42sr6eOCD83bT7i1tcrAab4VWU2Fv+BIrdmI2noTJJmKUk0P QwqQehG4n9F6uYJN+EY1GlfwlN5d0ZeIeNsRvQjMXBaI5rGq88c+qKuL2xK6u6OPYPJmGFJyK5c avOpOqTjJWT4dYYHtOmLzYOeQltzAj+voMIAr3C16f1DnvqriqQdovllY3tx8sISgl7EYk5l4En 4GPgS3mvtZAY6VDam1D7dy6PyjpIjy51gzad1CQ8v1EALG39fuhMj3fU4K6M3C/izl9Pe0XcYEZ yD6AOOLT8qaLhbKWKX6E= X-Google-Smtp-Source: AGHT+IFBPkGpH7OCUHfHFF8d+acmdhzJ29lI4BjvBzLTfWRbfPTbQPxmr3Hnz/k/wLvWCf/I5Td6iQ== X-Received: by 2002:a05:6000:2893:b0:3d3:8711:d951 with SMTP id ffacd0b85a97d-3d38711dd3emr9891835f8f.45.1756838057231; Tue, 02 Sep 2025 11:34:17 -0700 (PDT) Received: from [127.0.0.1] ([2804:5078:9a0:f000:58f2:fc97:371f:2]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7722a4e1d4fsm14028477b3a.73.2025.09.02.11.34.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Sep 2025 11:34:16 -0700 (PDT) From: Marcos Paulo de Souza Date: Tue, 02 Sep 2025 15:33:54 -0300 Subject: [PATCH v3 3/4] printk: nbcon: Allow KDB to acquire the NBCON context 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: quoted-printable Message-Id: <20250902-nbcon-kgdboc-v3-3-cd30a8106f1c@suse.com> References: <20250902-nbcon-kgdboc-v3-0-cd30a8106f1c@suse.com> In-Reply-To: <20250902-nbcon-kgdboc-v3-0-cd30a8106f1c@suse.com> To: Greg Kroah-Hartman , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky , Jason Wessel , Daniel Thompson , Douglas Anderson Cc: linux-kernel@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net, Marcos Paulo de Souza X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1756838042; l=1914; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=r5/WzNLFvBizJNQfa0Ilg++26fG8AY3qSmOM5PSpOPE=; b=W+qjsg4lnlTEWWbLzvCQWRhvM5FtpC60RWrOTzt57hm8vTwi/RkTlKIRi1iUPtvsE27C2RkYu r8Lc+i/hR5WC9g+1cDvixfxUaqC8+aWCE/HBdWdc/k+JE3Xklx1gUQz X-Developer-Key: i=mpdesouza@suse.com; a=ed25519; pk=/Ni/TsKkr69EOmdZXkp1Q/BlzDonbOBRsfPa18ySIwU= KDB can interrupt any console to execute the "mirrored printing" at any time, so add an exception to nbcon_context_try_acquire_direct to allow to get the context if the current CPU is the same as kdb_printf_cpu. This change will be necessary for the next patch, which fixes kdb_msg_write to work with NBCON consoles by calling ->write_atomic on such consoles. But to print it first needs to acquire the ownership of the console, so nbcon_context_try_acquire_direct is fixed here. Signed-off-by: Marcos Paulo de Souza --- kernel/printk/nbcon.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index ff218e95a505fd10521c2c4dfb00ad5ec5773953..352235a0eb4a484caccf86d3a57= d1a149218ecec 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -247,6 +248,8 @@ static int nbcon_context_try_acquire_direct(struct nbco= n_context *ctxt, * Panic does not imply that the console is owned. However, * since all non-panic CPUs are stopped during panic(), it * is safer to have them avoid gaining console ownership. + * The only exception is if kdb is active, which may print + * from multiple CPUs during a panic. * * If this acquire is a reacquire (and an unsafe takeover * has not previously occurred) then it is allowed to attempt @@ -255,6 +258,7 @@ static int nbcon_context_try_acquire_direct(struct nbco= n_context *ctxt, * interrupted by the panic CPU while printing. */ if (other_cpu_in_panic() && + READ_ONCE(kdb_printf_cpu) !=3D raw_smp_processor_id() && (!is_reacquire || cur->unsafe_takeover)) { return -EPERM; } --=20 2.50.0 From nobody Fri Oct 3 08:49:10 2025 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85AAC350857 for ; Tue, 2 Sep 2025 18:34:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756838065; cv=none; b=iWubGCBhKZe3UFyppi2NGLKAVtOkRryFZOLHHP+heoywMob+eNa1bUKoJnZvYgEWBykrOEVLmE6ZFetkzeiLVW1pvYcunov94XHKkG/Jm6gXJRbQu9/QQCxilG1FbEhAJO0WLKUnAU6GRdCMUDNTF6iX85jYvG09a30GYrEMzN8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756838065; c=relaxed/simple; bh=+UwyHLjdFrZY6eKJLE4ZxlJyjFoWSa4EScBE6ysnaVI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rxnmekfgPGPzfNKP3t3q7crekLspxHBeojzyJE5sIUoX8a2fMcRQkFM14URKRW0I5oUNORovhzd6anLv80QOMgl8bgehw3vfVomuZU41qw7vmKURq2AIEDEkpXGyynNe0ikW2ftjA/9rV5WqqZ/gQFC5VYNTDVnnMf3PzBIjXC0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=fYEzzByO; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="fYEzzByO" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-45b79ec2fbeso38846965e9.3 for ; Tue, 02 Sep 2025 11:34:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1756838061; x=1757442861; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Xcq4igIAw5t5SC0KyrVI7uzqX4joQRvngrbWP1St/kY=; b=fYEzzByO4ryzG6guf31cGmYrw/yOkfuksZ+9pwAIsKl9syvI9HW+KzVaxCCWZNR0qO zFjV/rtfsK6VAaG3WjRz8BRG8vgEbjJt6q6eToscIO6TKbGj7dBnc9el3oreq7vPQ0YH fctnBda4B0AouyrGt01oXLJQSyfOy/vr7k2amRhfmWmpJnUarOsBSGLf147Aq+fljbel NKJ+elTezGzRqoPiJ/9VzgJ6IJU0wrjNp9zWSgAPXU6a2zxH7al8K+mXxpJ4sBT6bKyD lH5h54QbVNLGb+QdWiRBwBbtiR6sv62Xmu00cIUV3luc4NBKMx3G98sT+TzSWENlF3eA CR6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756838061; x=1757442861; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Xcq4igIAw5t5SC0KyrVI7uzqX4joQRvngrbWP1St/kY=; b=qlcwn9+B8VvUna4z3mTD78NsQkGnuMuyA0SkxeGlQmuIFoN54FMzGHF+ugCDHnEOTL QyconXSXWh2fe6JHDZVEbf4zl9m9/Cv2wEF7U6FdhlO4tPcVOc4DHo8QsUi4fz2O2DUp zxPzpspy46gkc3xU1SgkJocTA0SUhguoKpMm9rxFG6NC3qYH8DhGPOpwChs0oxx8oqOI 7ilcieMx8C+znvEcWcnf1ikhdu/UmSw4JirfwFSjF66NAlqAuVRoKSAxSdY0R8AN0jkl MHM4UMTDKt63i96IDHCSQOxj0WivMiFJXUf2LzTIHq7DKHTfAq5Lpa801+ShWv3kIsRn i2gg== X-Gm-Message-State: AOJu0YzKhcXT/s5q+F8SuxqmhaP73aJZ3WmsB2jS31FWHLzuc/5twk3Y RYuOfwZfM8gaDvOuFyIXdGfKmDqHh1cvY5DecgzNCvAlcGbaQammBByKlX9rOdmd1c0= X-Gm-Gg: ASbGncs21Mj3RRclzUU9ydiLY5JwP6cs1m7mGN5eYFmaZ4jUS4Ps7qLZqZr3pYWBK5j AGxt/uhTi4G1Tt0jeZqxuKQdu0k/CgjZwIjVA5AL+j4DftT47d3vb9YgVGcSFTCqsT3cdM+ynwH HGJ4Gc9vKwwKHt7M4wRkVaIReM1fGj/7eoYFTQJR49jvtHae5mR9gHK1F7Qx5Z+KYJKb+gll56p eTFB0655YxGYmsJVv9J+RNU3FtWDGexXFglZWQG2KL+o9tKRUXD0KsWaUUYAJawWq6C26ah5JwQ jr0XaUhsfaG+98mx8ZMrrJ9VM/oTwo0dhvGewDK0HhdVKwag8iq5NE/l9K9uZcfPxj+IBBDCns3 MhWHH/HdeROA0bkkZcaJxmLvrz93Klg== X-Google-Smtp-Source: AGHT+IHWvfa1MfnXxCv92+LKAfoxq9DlDGk2apmD5Gzp1xX7ZsE3yezBngl0biLHukmFmhP6HVgmWA== X-Received: by 2002:a05:6000:1888:b0:3ce:a06e:f24e with SMTP id ffacd0b85a97d-3d1e05b6b69mr7933860f8f.52.1756838060800; Tue, 02 Sep 2025 11:34:20 -0700 (PDT) Received: from [127.0.0.1] ([2804:5078:9a0:f000:58f2:fc97:371f:2]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7722a4e1d4fsm14028477b3a.73.2025.09.02.11.34.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Sep 2025 11:34:20 -0700 (PDT) From: Marcos Paulo de Souza Date: Tue, 02 Sep 2025 15:33:55 -0300 Subject: [PATCH v3 4/4] kdb: Adapt kdb_msg_write to work with NBCON consoles 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: quoted-printable Message-Id: <20250902-nbcon-kgdboc-v3-4-cd30a8106f1c@suse.com> References: <20250902-nbcon-kgdboc-v3-0-cd30a8106f1c@suse.com> In-Reply-To: <20250902-nbcon-kgdboc-v3-0-cd30a8106f1c@suse.com> To: Greg Kroah-Hartman , Petr Mladek , Steven Rostedt , John Ogness , Sergey Senozhatsky , Jason Wessel , Daniel Thompson , Douglas Anderson Cc: linux-kernel@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net, Marcos Paulo de Souza X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1756838042; l=3211; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=+UwyHLjdFrZY6eKJLE4ZxlJyjFoWSa4EScBE6ysnaVI=; b=lzYUMPYu2PLlg3gPvl+ogk+PEjpIYL3DTt0nd9nwcAKyg8F5UiKDXV5FZhydCLA1LLurdiii+ qJiBTPCmsZICSMPLq2lXvZ6UqfFRvqPjmtLz9muRoX0jMUIqyOGY28T X-Developer-Key: i=mpdesouza@suse.com; a=ed25519; pk=/Ni/TsKkr69EOmdZXkp1Q/BlzDonbOBRsfPa18ySIwU= Function kdb_msg_write was calling con->write for any found console, but it won't work on NBCON ones. In this case we should acquire the ownership of the console using NBCON_PRIO_EMERGENCY, since printing kdb messages should only be interrupted by a panic in the case it was triggered by sysrq debug option. This is done by the nbcon_kdb_{acquire,release} functions. At this point, the console is required to use the atomic callback. The console is skipped if the write_atomic callback is not set or if the context could not be acquired. The validation of NBCON is done by the console_is_usable helper. The context is released right after write_atomic finishes. The oops_in_progress handling is only needed in the legacy consoles, so it was moved around the con->write callback. Suggested-by: Petr Mladek Signed-off-by: Marcos Paulo de Souza --- kernel/debug/kdb/kdb_io.c | 46 +++++++++++++++++++++++++++++++------------= --- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 9b11b10b120cf07e451a7a4d92ce50f9a6c066b2..47bc31cc71bc84750db5d9304ed= 75a113cd382bf 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -589,24 +589,40 @@ static void kdb_msg_write(const char *msg, int msg_le= n) */ cookie =3D console_srcu_read_lock(); for_each_console_srcu(c) { - if (!(console_srcu_read_flags(c) & CON_ENABLED)) + struct nbcon_write_context wctxt =3D { }; + short flags =3D console_srcu_read_flags(c); + + if (!console_is_usable(c, flags, true)) continue; if (c =3D=3D dbg_io_ops->cons) continue; - if (!c->write) - continue; - /* - * Set oops_in_progress to encourage the console drivers to - * disregard their internal spin locks: in the current calling - * context the risk of deadlock is a bigger problem than risks - * due to re-entering the console driver. We operate directly on - * oops_in_progress rather than using bust_spinlocks() because - * the calls bust_spinlocks() makes on exit are not appropriate - * for this calling context. - */ - ++oops_in_progress; - c->write(c, msg, msg_len); - --oops_in_progress; + + if (flags & CON_NBCON) { + /* + * Do not continue if the console is NBCON and the context + * can't be acquired. + */ + if (!nbcon_kdb_try_acquire(c, &wctxt)) + continue; + + wctxt.outbuf =3D (char *)msg; + wctxt.len =3D msg_len; + c->write_atomic(c, &wctxt); + nbcon_kdb_release(&wctxt); + } else { + /* + * Set oops_in_progress to encourage the console drivers to + * disregard their internal spin locks: in the current calling + * context the risk of deadlock is a bigger problem than risks + * due to re-entering the console driver. We operate directly on + * oops_in_progress rather than using bust_spinlocks() because + * the calls bust_spinlocks() makes on exit are not appropriate + * for this calling context. + */ + ++oops_in_progress; + c->write(c, msg, msg_len); + --oops_in_progress; + } touch_nmi_watchdog(); } console_srcu_read_unlock(cookie); --=20 2.50.0