From nobody Mon Apr 6 04:44:18 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DBA2ECAAD3 for ; Sat, 10 Sep 2022 22:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230409AbiIJW2l (ORCPT ); Sat, 10 Sep 2022 18:28:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230090AbiIJW1x (ORCPT ); Sat, 10 Sep 2022 18:27:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 569C243311 for ; Sat, 10 Sep 2022 15:27:49 -0700 (PDT) Message-ID: <20220910222300.966724916@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1662848867; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=dUt7YWFMhjrMP4Qpw0W8vZndSNzlNorKm2KfwhLmlGk=; b=ZpGAMzk+By9q2iPr47fY+/daL7Pha5lvv2nOYLh97IzQ9DzVrzYq3Lq+QdyQokBlPs3Yvd ImRl/mHBqiLHGEPYTId7/dj6oxqq7qpGD1g0uIUo6lTUhkAKPUjAHaHFfloPIskY07i7XW e3KAXvvfKkYpYyGQmhByzFg1TqejB2pOe+NrM88nR+xNoxxxVis9T2plynwWfrjpeP0BEy 4BSI6p4oKx4yjtUwnwj+EfONM1qq1v+pL899ch6yuTeEx51yiOFLIP1xGYl2F4lDBwtZyi YAFEiVdncj9YK5OAzqqZkJK2q41kU+mDey6Rk5Aky5dXzifGt4HfBx6mAVljaQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1662848867; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=dUt7YWFMhjrMP4Qpw0W8vZndSNzlNorKm2KfwhLmlGk=; b=JHvCvb5+eSydfHBwY6ELO4EIf6T3okWVuaIDiFOwC4ey9m1xP4iBb2VHfDiiKy6CEoOHN2 IdDp66ONAbAPoBAA== From: Thomas Gleixner To: LKML Cc: John Ogness , Petr Mladek , Sergey Senozhatsky , Steven Rostedt , Linus Torvalds , Peter Zijlstra , "Paul E. McKenney" , Daniel Vetter , Greg Kroah-Hartman , Helge Deller , Jason Wessel , Daniel Thompson Subject: [patch RFC 10/29] kgbd: Pretend that console list walk is safe References: <20220910221947.171557773@linutronix.de> MIME-Version: 1.0 Date: Sun, 11 Sep 2022 00:27:47 +0200 (CEST) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Provide a special list iterator macro for KGDB to allow unprotected list walks and add a few comments to explain the hope based approach. Preperatory change for changing the console list to hlist and adding lockdep asserts to regular list walks. Signed-off-by: Thomas Gleixner Reviewed-by: Sergey Senozhatsky --- drivers/tty/serial/kgdboc.c | 5 ++++- include/linux/console.h | 12 +++++++++++- kernel/debug/kdb/kdb_io.c | 7 ++++++- 3 files changed, 21 insertions(+), 3 deletions(-) --- a/drivers/tty/serial/kgdboc.c +++ b/drivers/tty/serial/kgdboc.c @@ -462,10 +462,13 @@ static void kgdboc_earlycon_pre_exp_hand * we have no other choice so we keep using it. Since not all * serial drivers might be OK with this, print a warning once per * boot if we detect this case. + * + * Pretend that walking the console list is safe... */ - for_each_console(con) + for_each_console_kgdb(con) { if (con =3D=3D kgdboc_earlycon_io_ops.cons) return; + } =20 already_warned =3D true; pr_warn("kgdboc_earlycon is still using bootconsole\n"); --- a/include/linux/console.h +++ b/include/linux/console.h @@ -184,7 +184,17 @@ extern void console_list_unlock(void); * Requires console_lock to be held which guarantees that the * list is immutable. */ -#define for_each_console(con) \ +#define for_each_console(con) \ + for (con =3D console_drivers; con !=3D NULL; con =3D con->next) + +/** + * for_each_console_kgdb() - Iterator over registered consoles for KGDB + * @con: struct console pointer used as loop cursor + * + * Has no serialization requirements and KGDB pretends that this is safe. + * Don't use outside of the KGDB fairy tale land! + */ +#define for_each_console_kgdb(con) \ for (con =3D console_drivers; con !=3D NULL; con =3D con->next) =20 extern int console_set_on_cmdline; --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -558,7 +558,12 @@ static void kdb_msg_write(const char *ms cp++; } =20 - for_each_console(c) { + /* + * This is a completely unprotected list walk designed by the + * wishful thinking departement. See the oops_inprogress comment + * below - especially the encourage section... + */ + for_each_console_kgdb(c) { if (!(c->flags & CON_ENABLED)) continue; if (c =3D=3D dbg_io_ops->cons)