From nobody Tue Oct 7 07:06:12 2025 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 B4CABA2D for ; Sun, 13 Jul 2025 05:09:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752383373; cv=none; b=imtxVbzoGYK2kqF/CvSB30eTxIwH3un+Cu40XSbNXCddi4ARFh6Ppg1L8VhtcX0mAZl662X+SC5go6o8gKLjoSj3tbOri3GdkUBw8ALTADiGz8DsAcZoDfhO5TydL7rim6m8/z2lauXqHwQRhL3MEqKJO44tFZzXYUjrqHNbUyQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752383373; c=relaxed/simple; bh=eHQxt3OQgRDSDL+/Kzb0bRPmuzSVSZ5fvf2mWGLEL6g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=g1E+gfDKIln1HnUuPzZNQpzvb25tD8E1+qqDah/4JYw6NnplN6eQscimINLUu14yEqErF9RjEUfcS0t96756F0+U9XuKEJutOCNTGUrWG3MEh4ib22q//r6iBUS0rWX3WrzPqiYN3YtaN8Clnxg5VzkARSfzyDY1PsxnHd5Ghzk= 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=VFCs5qf8; arc=none smtp.client-ip=209.85.221.48 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="VFCs5qf8" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-3a528243636so1783581f8f.3 for ; Sat, 12 Jul 2025 22:09:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1752383368; x=1752988168; 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=SJ5nFRIqwgqlbPEHr8CpnUbj2DPgbxersP6LBScpX6s=; b=VFCs5qf8PjB0Z9Eu6XlZnHqM8535qbkIOS3aUXzxXbPOfooldKWRh6En4YMBAGrSIx uzf741iOJvi1CFbL6eilVIOM4GoGYFWYVkVtcyFomS8lWW0eqsc7p1+Q6D4a7Tmla4iX 27tlvq815SwZdRBxxRK8LERzVNpwjye24Gm4/5jtBL33dO7Gkfko9Gu2+pXIr/iXfgYb Q2KAOMWhHp7+LilW+zHOeJB9IePpI0QOXD4adMa3xr3cemHsQ5Zo5VFEj6bloEpf0HwH EylCHLI4h6lRqO4oZElmw/IdW6XKsyGJ9ygk7gXEhcQFV0h+W2592yAw2H/De5Lii1pe Y49g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752383368; x=1752988168; 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=SJ5nFRIqwgqlbPEHr8CpnUbj2DPgbxersP6LBScpX6s=; b=VsrXX+EmZjG5fqAwytpanImXbG2eCR4+7OG5oP9b8haeYZssf32MCQayN5qaXqb9mH 44xC2pWRGlyOQAKPNTuoKzu3PgG6vnxi5qxqBLvlgL8y4wkWB/VgSB7uujDJ2Ckf7nEI wWh5WcbbrH2fP6klrAK890yEnXyIZjJhFru4W62WWdp7pcTbUiTmz2kN2lXdyGyUHros x6xKDQdcGzqN3f6LnXdfNkfwnX5lyPDXrWBvMRbCsDwBV64FsOixJ5Z3NnmFoz3fnx4C An7BIPqaESd1XccWUwBbfp4i9763Lsf7HVQoQeqaUOSi3zQfxQ/Z8PCAR5R0xayxdXZm OXiA== X-Gm-Message-State: AOJu0Ywrbohfvot2njl7mzONGHsTbcpns54gA1rAELcstMOv7tnBQPxA rmNYj1mHZWummqKrdN6RcWbkxjZikHhK4D7Z1ZOU2q+EnJmnnrYSi3Sr/MgS66pB4xk= X-Gm-Gg: ASbGncs6X9Ll/0v7L6+pzZU9fv7pRypueRScoFv5aCA3zRZ1CuClB9P5UYFGfR6xtXS YhGNI44z95jzkpt4sLrzocexjxVZ/mt5qbkagcQssY8x4zrhEg1E1klxMPCihoFYiDvAC/QdYXJ QZRaImYIgMD7s7wed3F/kEGk8jQH/8NItgrrHSAAZ8cTdUgC+dZBf5EX8EtEWpBZ/Q/8NssdRmC Il1l/WVsNu5bz24h5abqG6nNr6lhAL4yEeEp9KcUHlgOY2avhM6Sn58wZ2BRQwzGWCH2K3AzZ1v M5bdLZg6fFZb9tePm3vyonwOe7IY9EQHIguTkKNEVYXc8X4/LgItZ5vlNfYGDAKJtFj7WgHWYjk zklW/vI/zOzf0v84y7P4= X-Google-Smtp-Source: AGHT+IGWIGicBdiZCJidY8N92VCt38Kw2K2NUnXkamozSH7OAMCwpffBE8C4REiahA57ea3QhMxLrQ== X-Received: by 2002:a05:6000:2c08:b0:3a4:dc2a:924e with SMTP id ffacd0b85a97d-3b5f187b273mr7374858f8f.6.1752383368010; Sat, 12 Jul 2025 22:09:28 -0700 (PDT) Received: from [127.0.0.1] ([2804:5078:828:f400:58f2:fc97:371f:2]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74eb9f210f1sm8125879b3a.88.2025.07.12.22.09.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Jul 2025 22:09:27 -0700 (PDT) From: Marcos Paulo de Souza Date: Sun, 13 Jul 2025 02:09:18 -0300 Subject: [PATCH 1/2] printk: nbcon: Export console_is_usage and other nbcon symbols 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: <20250713-nbcon-kgdboc-v1-1-51eccd9247a8@suse.com> References: <20250713-nbcon-kgdboc-v1-0-51eccd9247a8@suse.com> In-Reply-To: <20250713-nbcon-kgdboc-v1-0-51eccd9247a8@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=1752383361; l=6088; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=eHQxt3OQgRDSDL+/Kzb0bRPmuzSVSZ5fvf2mWGLEL6g=; b=HagkgsWmd9lg8ADrLcdrGSFoCgjFq3ZjERaj0qqCBFg4CHI0gH+fIHzF6LZWnxaPSO7QK4z2J pLQdoDG92ZwBhYeio27lYLvuSOH1/34TV/sWJ3DPE6qUNMCZyU92vSL X-Developer-Key: i=mpdesouza@suse.com; a=ed25519; pk=/Ni/TsKkr69EOmdZXkp1Q/BlzDonbOBRsfPa18ySIwU= Function nbcon_context_try_acquire, nbcon_context_relase and console_is_usable are going to be used in the next patch. Signed-off-by: Marcos Paulo de Souza --- include/linux/console.h | 48 ++++++++++++++++++++++++++++++++++++++++++++= ++++ kernel/printk/internal.h | 41 ----------------------------------------- kernel/printk/nbcon.c | 4 ++-- 3 files changed, 50 insertions(+), 43 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index 8f10d0a85bb4536e4b0dda4e8ccbdf87978bbb4a..d5398b4be4f7ce8d1642b919952= 710431b53a8ad 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -599,19 +599,67 @@ static inline bool console_is_registered(const struct= console *con) hlist_for_each_entry(con, &console_list, node) =20 #ifdef CONFIG_PRINTK +extern bool nbcon_context_try_acquire(struct nbcon_context *ctxt); +extern void nbcon_context_release(struct nbcon_context *ctxt); extern void nbcon_cpu_emergency_enter(void); extern void nbcon_cpu_emergency_exit(void); extern bool nbcon_can_proceed(struct nbcon_write_context *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 bool nbcon_context_try_acquire(struct nbcon_context *ctxt) {= } +static inline void nbcon_context_release(struct nbcon_context *ctxt) { } static inline void nbcon_cpu_emergency_enter(void) { } static inline void nbcon_cpu_emergency_exit(void) { } static inline bool nbcon_can_proceed(struct nbcon_write_context *wctxt) { = return false; } 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 48a24e7b309db20fdd7419f7aeda68ea7c79fd80..4ad51a98690b43fd2383a0c6e70= ac4da68c34da3 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 diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index fd12efcc4aeda8883773d9807bc215f6e5cdf71a..b95030018472493b1019932c3d1= d92c1abd044ee 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -568,7 +568,7 @@ static struct printk_buffers panic_nbcon_pbufs; * in an unsafe state. Otherwise, on success the caller may assume * the console is not in an unsafe state. */ -static bool nbcon_context_try_acquire(struct nbcon_context *ctxt) +bool nbcon_context_try_acquire(struct nbcon_context *ctxt) { unsigned int cpu =3D smp_processor_id(); struct console *con =3D ctxt->console; @@ -648,7 +648,7 @@ static bool nbcon_owner_matches(struct nbcon_state *cur= , int expected_cpu, * nbcon_context_release - Release the console * @ctxt: The nbcon context from nbcon_context_try_acquire() */ -static void nbcon_context_release(struct nbcon_context *ctxt) +void nbcon_context_release(struct nbcon_context *ctxt) { unsigned int cpu =3D smp_processor_id(); struct console *con =3D ctxt->console; --=20 2.50.0 From nobody Tue Oct 7 07:06:12 2025 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 44DC419C558 for ; Sun, 13 Jul 2025 05:09:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752383375; cv=none; b=LwrsO3AX6ixAjguN/dlfke46217U3t/uHtHyIyR3U6vVdMVznXS3mEhEekpHvQ9vrUtLuU4bDP1IhlglzhTWx64wZt8wyErqHoKXsNWCcXFNbOGdOIClKw8AYFW+MoxYpt6CrGCdE373440zM1K/EjtlJ6caTzcqfZ4POhhXpas= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752383375; c=relaxed/simple; bh=BhkQT2VjxlBBB44KZbEDSDCxnibcvsDE0D7c+VlqDfo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Vs0r9K1V98kMz5oxu1Xl0X7DnJOkl4bZLnxGzpEk2tpb56Qm2Ow7zCmSWzu19ALbIBuMTwDAyjxCILgpCL+CveQoZuzZgsSHTutjNpQsKpoYYyMzO+dMj3ewdqDq/VOzosUKYCSDJ2a2Q6LpIc3Pnlcn14Ij0ReoPvfctHAZtk4= 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=NFxRV6s2; arc=none smtp.client-ip=209.85.221.44 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="NFxRV6s2" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-3a6cd1a6fecso3261513f8f.3 for ; Sat, 12 Jul 2025 22:09:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1752383371; x=1752988171; 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=rplS/4F9HQSrBRuj60001ScYo39oY8hZsZRvEzwk1RM=; b=NFxRV6s2Rz5wygWFwVWlXsakR454K3TwSgAHm/wSN+ZHdXz8MbwGZ99wY9H7+WY6Py DstI6H4dJZd2nA9Aeb+SWBSMgH51lyIAaXtLgC3klobhONLaeB/wPnw93Y2861FceQX6 1DDDzhIztzFiLzEskdjh393aXqofv5z4vTDmb2gjmXLP8UaJzy51WBAge/b3aAsizf7Y QQTjtN5TqxUnCoJOQsZv4ccWN0NZMBblcmAN7gsIyPvz/493vgd/ROodfBMdv+sL4DTQ yFXr74m2Tu0/vCJlWB/0RfPW2g2UaLXN85u7kYiN08d7Z7iWdmQO2/zS7GYJvOG7NPve wTcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752383371; x=1752988171; 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=rplS/4F9HQSrBRuj60001ScYo39oY8hZsZRvEzwk1RM=; b=ACev6pnsZTzhRSnOkAgmgYycVjMC9zBFyAX7SKO3de+kmErEan6YpFg9Iffw9X3dzK 24j6Wmr4prqrOEb8GRylhhZKgrsSAAAovDguogbggpC0Io0IFzkkdGwqsniRn1kP4Syn iYgD+0+wkrdvY2o1xZQ3TVo9Zx2rDhLlsR0EE7z+phUTo6GWSuuZGUwoCOHiPk/J4pOJ vzMweTrMeVPpKKZAdhJh8ZSpwWGlwI/l4Ol8Dh4CgYPne9mwQ9kOYGcGx8vJ9/hrJiq9 cVZRDR+jnUT8OwW5K5SmPAFhW3mRq1bXWQloK+gcRvDS5kclfDxQLKJV5+iz5tacDMhP sbRw== X-Gm-Message-State: AOJu0YwX5ZpZZXE/UpPDjQPce4LdHEggf7shy7iQXA9iMpq4gSJ3/89O pH70RJx4mFuipHQXD3ZYWYyBoWRJJ+nqm1mHHQaA5n2lPdM/Sdi16o3OiYsPL8ApKJw= X-Gm-Gg: ASbGncs/t3USaZLuIoRALD8HP/JFLSM+9TShf2K4UcKZcde8JZMiizNoxKFg9fv8cCO EeMdJWmsFT58a1yj05kPzrvYngKGGA8vCAE2WQBV34V9m+Xeo2UOS6kldejRQjCOFlr8jq86pyN hzDVT3zAn/c2y/xGsREQB+gRowvxS9n9zvp9WHqQuZj8EkeZQKCMKEjHqrI3+iHeDVrQnVC0z8d Wzvp1aTTkRMsd3GTbfM9vNGPuTyREZuotVcSbXns62R/ocmQwfikYwKJhNrt1CVd3HevBTHXXbP 53jsVXpUjSwu9ZRsZMAc1Fiv7VQgzIbhX4Hv8eV103JP2Bf4dPmRmwNOdr/9GuI0OyWgLK0BWMX zoiE9xDR6voFF6AVDdpE= X-Google-Smtp-Source: AGHT+IH/lG0/wtwwi45kibg7irhMga7P+QoBrHuyvg1RpJroQXZkYkGelqR1QnmMJ8MsjRb/KbFTZQ== X-Received: by 2002:adf:b60b:0:b0:3a8:6260:ea91 with SMTP id ffacd0b85a97d-3b5f1895c8cmr7180948f8f.40.1752383371510; Sat, 12 Jul 2025 22:09:31 -0700 (PDT) Received: from [127.0.0.1] ([2804:5078:828:f400:58f2:fc97:371f:2]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74eb9f210f1sm8125879b3a.88.2025.07.12.22.09.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Jul 2025 22:09:31 -0700 (PDT) From: Marcos Paulo de Souza Date: Sun, 13 Jul 2025 02:09:19 -0300 Subject: [PATCH 2/2] 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: <20250713-nbcon-kgdboc-v1-2-51eccd9247a8@suse.com> References: <20250713-nbcon-kgdboc-v1-0-51eccd9247a8@suse.com> In-Reply-To: <20250713-nbcon-kgdboc-v1-0-51eccd9247a8@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=1752383361; l=2988; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=BhkQT2VjxlBBB44KZbEDSDCxnibcvsDE0D7c+VlqDfo=; b=mD048M7lF++L74S6TaHtkYIT8KOYYfLt+kZ+fMDfjPU1S7ibbneYLVe0x3wybOOfDdr0n/f3E 5V1w79YtGJDAAIJtOsboa8A8L6LsStIOs9wdNyuj1QFRndJ4GBHdZdB X-Developer-Key: i=mpdesouza@suse.com; a=ed25519; pk=/Ni/TsKkr69EOmdZXkp1Q/BlzDonbOBRsfPa18ySIwU= Function kdb_msg_write was calling con->write for the 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. 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. Suggested-by: Petr Mladek Signed-off-by: Marcos Paulo de Souza --- kernel/debug/kdb/kdb_io.c | 46 ++++++++++++++++++++++++++++++++++++++++++-= --- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 9b11b10b120cf07e451a7a4d92ce50f9a6c066b2..3b7365c11d06b01d487767fd89f= 1081da10dd2ed 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -558,6 +558,25 @@ static int kdb_search_string(char *searched, char *sea= rchfor) return 0; } =20 +static struct nbcon_context *nbcon_acquire_ctxt(struct console *con, + struct nbcon_write_context *wctxt, + char *msg, int msg_len) +{ + struct nbcon_context *ctxt =3D &ACCESS_PRIVATE(wctxt, ctxt); + + ctxt->console =3D con; + ctxt->spinwait_max_us =3D 0; + ctxt->prio =3D NBCON_PRIO_EMERGENCY; + ctxt->allow_unsafe_takeover =3D false; + wctxt->outbuf =3D msg; + wctxt->len =3D msg_len; + + if (!nbcon_context_try_acquire(ctxt)) + return NULL; + + return ctxt; +} + static void kdb_msg_write(const char *msg, int msg_len) { struct console *c; @@ -589,12 +608,26 @@ 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 { }; + struct nbcon_context *ctxt; + 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; + + /* + * Do not continue if the console is NBCON and the context + * can't be acquired. + */ + if (flags & CON_NBCON) { + ctxt =3D nbcon_acquire_ctxt(c, &wctxt, (char *)msg, + msg_len); + if (!ctxt) + continue; + } + /* * Set oops_in_progress to encourage the console drivers to * disregard their internal spin locks: in the current calling @@ -605,7 +638,12 @@ static void kdb_msg_write(const char *msg, int msg_len) * for this calling context. */ ++oops_in_progress; - c->write(c, msg, msg_len); + if (flags & CON_NBCON) { + c->write_atomic(c, &wctxt); + nbcon_context_release(ctxt); + } else { + c->write(c, msg, msg_len); + } --oops_in_progress; touch_nmi_watchdog(); } --=20 2.50.0