From nobody Sun Oct 5 00:12:25 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 59E852D7805 for ; Mon, 11 Aug 2025 13:33:36 +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=1754919218; cv=none; b=FBst5zxvoFHuUFh8jocYF+vzwhCcqvKjCQff1VFMa6XDrs0Rw8/ZraRYOl9WisShpdz6y03g4OSes27Yp5K9PI0mYxSfd7uJfU2BVjSnTfTIIpRp5LeVXNrmU/qieaOqkqM4c7cBSe2/MbrysKTphrM/0rZxkPK9ZJhz58PMrBI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754919218; c=relaxed/simple; bh=BHf0HTOHyGX4EITGM2Q1C51Falk64PM/uaZX63oRSyY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=H4E6livzg/PC8dHuOV4K+lmr2WDgT/O+cmxYc/kbzFr3nAL7x3Z5PIavf9zcczj0R99qNyDSop+LES5xo1T4PlSg51ecF790kGiZc/2TYhI1BV3xchOf0Vg0sbRQ4+kUBDECiEB5TQhSAjLSNH/xOR3nT/8Lowj+PGNFU9nLp1A= 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=L48A0qmO; 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="L48A0qmO" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-3b78294a233so3790149f8f.3 for ; Mon, 11 Aug 2025 06:33:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1754919214; x=1755524014; 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=bL/NquOlpF5TigMCebJLLc4bp+Hhqn9zNRjpj1kl/wY=; b=L48A0qmOi+0r1GWUvE4nRD033qDssh4hpvmIJ2p9dujoCUIeJrjDFLwRAbtoF9PXIb CDFOuWUiSEFkEIl45I5yns54Vz/Ek/APJq9TDov2rr3QY82l9xRd3tKFRTAqL0nw5q1N ipvjVAltaYlVXYzSOI0qHpNMVRp/00J7cTPuWYi57YrhWww7+4+9yKWKw9DHQ6fSJ9v4 QLVJgEL3AsDE2neFsHdcRK5kxLL79g/Ko0MrR32VevKOhT355oFjBznR1Hw6Y3JKDBJp IjBMCb3h7eZLfnlfYLa6ral3nbWucvA41ZhJhwUyJdrZYURG8lk3kzITXC6JlbFAwEEC bZeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754919214; x=1755524014; 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=bL/NquOlpF5TigMCebJLLc4bp+Hhqn9zNRjpj1kl/wY=; b=TFJO8IaO2QDmBJlHzc6qDlcHXzLFEXfZnzZmV3BGpzN+fX3dUpPt/+/415pjN0KrWj hcL2QeFqkcOlo5EPu8xPbGA1Ytt6dh33A/ChEzZwN9c1NqzCEVv8v8g6lO25cjp/Obfu MZY+RsyK98BFtJMnRQZEUpjuGrnXlBAK0bp2cF0zxSkCIUSjoEga19rmO28JfnatvPcM KPLOySzmcQ/DQgciOXCsl4Mvtj3TwbOrWlFbyw2eQXqZ7bGVjLyXQw937QxG/+KTDAfo 9fJ+DI/1vxJRF6Zzj8AYodm7T5V5ClINiWAx3krVravTzhLJElgVkr9veL1FfTjCyVGZ QthA== X-Gm-Message-State: AOJu0YwFT5DVB7ouVK93dpl+voQCpmrs0w0SSX/fVmw32hxQwmoA4kAJ J4kaM8HCEolq6OR/dy53iXEETPs3tws7oNQJznFqVOADQU8rfZ7Jc6NcbsLKswyzFdQ= X-Gm-Gg: ASbGncsIhoNeMF9utEVHa95cxPcS7Z/tu2WwpeNHD0y7cjAkoO01T7n8oo19ar0LONB Mt1DBaf8et44CU87EwxkZITg7qJ4+vAmJnPJ/xR9hnjjy2V2fgn0Eht+I7syJ5Qwqo9hHH00ImC 5vZFDwqhAZT0LrMzxqaMNHJlKyHGnNf1ELxCmhLnommPWL9eKC58KaQNfQukUiss4D7WslH58u+ dW8vL1NVcrZKfKUDTyFe4y3C5+yIvdhNR5dmOSsfWgvpQwFtm49V+yjZt168Dnybzq+rKh5oTzQ GeQ6OHYHqFijlFMVoX8E6QYjWKzNIHB6iLRwko5YSiRYEVzJdgWzozr4YvfiITac8g+rz3dIngP 9Fd/9+Hp8qPY/MhQ9bqmLAxfXbvtIGVFFyi5pK5xoaEQLSA== X-Google-Smtp-Source: AGHT+IHTuzaawVjBb6/L16J74AehOLxcbzZ1Rzz8jZVDxQY+drVz7VrKSxKZHRfLOt/fn9cWY6uuPg== X-Received: by 2002:a05:6000:2003:b0:3b8:d082:41e with SMTP id ffacd0b85a97d-3b900b80484mr9566864f8f.57.1754919214456; Mon, 11 Aug 2025 06:33:34 -0700 (PDT) Received: from [127.0.0.1] (71.36.160.45.gramnet.com.br. [45.160.36.71]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-76bccfd18c9sm26667449b3a.91.2025.08.11.06.33.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Aug 2025 06:33:33 -0700 (PDT) From: Marcos Paulo de Souza Date: Mon, 11 Aug 2025 10:32:45 -0300 Subject: [PATCH v2 1/3] 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: <20250811-nbcon-kgdboc-v2-1-c7c72bcdeaf6@suse.com> References: <20250811-nbcon-kgdboc-v2-0-c7c72bcdeaf6@suse.com> In-Reply-To: <20250811-nbcon-kgdboc-v2-0-c7c72bcdeaf6@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=1754919199; l=4427; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=BHf0HTOHyGX4EITGM2Q1C51Falk64PM/uaZX63oRSyY=; b=KDWxdcdW9zWcFr4T5qRdeM9cpZSTgwcJ8oVIShWifFHUS/LIMS0tEnhvf70f2aq+eoFmLRlt9 hqx1Mk6TuP2DdR5qxdnNMfF69uX4T+WdhjZSW2UhmHYNlsloP101s4M 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 --- include/linux/console.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ kernel/printk/internal.h | 41 ----------------------------------------- 2 files changed, 44 insertions(+), 41 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..077927ed56c5f7ae22f76be4635= a4b4614387de8 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 --=20 2.50.0 From nobody Sun Oct 5 00:12:25 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 12EBE2DAFA0 for ; Mon, 11 Aug 2025 13:33:43 +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=1754919227; cv=none; b=uThmMGr27nPgreKd4/NGgsRG75jdAWWFCoQUonU8FEQgfaBBpykD6BsFfCfBZFJJMRb2WkRLdYDkYuy2Fe4yHdELQifE9+g1A4j9FBYsQ+eRlhy+QcGV0UGQIwXc8tLOxTh+kZcWt8RJ+Y0ilkQRR5Qs04Arfr6GGigoQczmXxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754919227; c=relaxed/simple; bh=ufvmR164HIDVErbGEUZkCxgBjPQguwJct+qr4ByygZI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TARUW4HOfb3F4CkbhGdBdG8aZWx0PkTMBo4NcbXl33bF57uzRnnXdKUBCxJI3sMTQO6QWiVNp7yFw2QpASkQuuySNnfHLeKQ/8mDAdRVS7g651KFzXlPwv+saX9926JTfu70Z04erE3vI4FPVAgCLWBjM61yf0X6xlYnVpP/Wx4= 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=B81o32Cu; 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="B81o32Cu" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-3b7823559a5so2000913f8f.0 for ; Mon, 11 Aug 2025 06:33:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1754919222; x=1755524022; 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=cbLmjZ7mpSHXmCBoNACkr+Z3uGmrZkDtS8F4oX6bjhs=; b=B81o32CuwezYTMxTxF9TH7I6CCwA5iSZ8D/W2m1QNk971l6ehCAofaYC+aP/DRkW/w 9+eCQiQFJAFyDNOuo0EA7XhNJhv7pS3Hlo83Tb6fMPgFiu7HC3hfiCDZrX3+MpW9oXLo WMrsK69vbcRYf5n8+oteQ5vVFdBG32JRA3C6F55kSmNUSJ0r42V7FDa+pEBTDpAPrTiI s9fO4nr6r4wRUPUo3ZLJKQ5GUPKBj9bZlrY8rHhW5fJIRddOrZQLusjzrP3pg5R/oI76 v3HoIfqAKByZlrp/Cr50chploRCyNVHS6o1D+iE7XkPA7oG+6X6f6cVSC6c1YI++H6yA 7/ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754919222; x=1755524022; 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=cbLmjZ7mpSHXmCBoNACkr+Z3uGmrZkDtS8F4oX6bjhs=; b=DAuEly2CkEW6iLWmuLZzXkaYJexCeh1EsE4YR/+Wusf9JBwme7813d9VDtFlp9NlmC xIKqR3D42XOi5pNp08WjjosUa9hJt1Ka5uXuBrG3E35QoIHLYUPwHemGM+/Z3f3cCJyG Z6/wPASL/2b9bfyDCgWa29g+d3iwnJwm0wVQQ4SnPjiKkgQxQ+WWEzmFImQ2pEtzJRMn 56xO3HdFLgd2jFU6ytKfrbPy9yji9pg+v5afhvmVMXU9qGn8SOT/QkCBKHUkOk3H2X+3 7eoOWd6d9MTBbZGKfveTABHaSGlsmS/5x/WHuhUlFAQ0sJXKqbFDzSVwpmAeAW0Ly7JL TuUw== X-Gm-Message-State: AOJu0Yzg/Ix5eR50CboL8QRb5kY8pd4FDEQI5UU98IVOHyy/s7cD2mxI 5BceozDU3xIPj9zJzmw2PGs25uGIkNXEVN6KXPZmjwqzpvKns6igQsHLnLMHNMbLIpg= X-Gm-Gg: ASbGncvW2jnj5OJyzNig5tinQJXJ1ZZ7R/gjGckm0pT7ErrP1rkfQqlJqpDtzT4bqM0 AUD9hJg/DNZs9SdojNwAmopjQpHZBiyoxUalzNxpnOutZoT0jrZF6hucYHaDbYYHETyizGdR20h imIoheY9q3ARir4kbGyIZmo+Mshrkb3w6eGK9b/Q3hxV8F6BFOlplem7qlu9cozobZBNEhttO3H uXSkXz0nIkKKRBtSPReWk4upYsC27zmzJzUYhsWRnopNi8IXsblsGcG69CgAM87J7Hm/3aeq4Lq dRb50mhD0X6q6NPKtZw8v9wjbBnleEewLqrzp5i2JQIxfKlen6ik0PgsI1qoY9jxciyqKwupQdC WGlD2NliTvbDGmmPp7955MuGjo3tK3RL438i+TI7LR81dwg== X-Google-Smtp-Source: AGHT+IGK59D88yKPWNRUvP+ILW4Vpaah51IRVhPO6OEWpPPAqEFM3jLI+j3e4vsddNCEhMgpbbmK1A== X-Received: by 2002:a5d:5f8d:0:b0:3b8:d893:5230 with SMTP id ffacd0b85a97d-3b900b510dcmr10619010f8f.47.1754919222247; Mon, 11 Aug 2025 06:33:42 -0700 (PDT) Received: from [127.0.0.1] (71.36.160.45.gramnet.com.br. [45.160.36.71]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-76bccfd18c9sm26667449b3a.91.2025.08.11.06.33.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Aug 2025 06:33:41 -0700 (PDT) From: Marcos Paulo de Souza Date: Mon, 11 Aug 2025 10:32:46 -0300 Subject: [PATCH v2 2/3] 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: <20250811-nbcon-kgdboc-v2-2-c7c72bcdeaf6@suse.com> References: <20250811-nbcon-kgdboc-v2-0-c7c72bcdeaf6@suse.com> In-Reply-To: <20250811-nbcon-kgdboc-v2-0-c7c72bcdeaf6@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=1754919199; l=3028; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=ufvmR164HIDVErbGEUZkCxgBjPQguwJct+qr4ByygZI=; b=0z+ZxHNmXiP62d7RqMOp8U/qBmtiS8QwaHpae3RV/4o5+s7NEPv1b+j/TXHxNSxHwk7pebdRu UUXdMjY3XxnAJpBlLuBJEIWrZwYzFWgwSp94O2nWTyO6RKQytI7ZRFN 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, differently from nbcon_device_release, we don't need to flush the console, since all CPUs are stopped when KDB is active. Signed-off-by: Marcos Paulo de Souza --- include/linux/console.h | 6 ++++++ kernel/printk/nbcon.c | 26 ++++++++++++++++++++++++++ 2 files changed, 32 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..79d8c7437806119ad9787ddc483= 82dc2c86c23c3 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -1855,3 +1855,29 @@ void nbcon_device_release(struct console *con) console_srcu_read_unlock(cookie); } EXPORT_SYMBOL_GPL(nbcon_device_release); + +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; +} + +void nbcon_kdb_release(struct nbcon_write_context *wctxt) +{ + struct nbcon_context *ctxt =3D &ACCESS_PRIVATE(wctxt, ctxt); + + nbcon_context_exit_unsafe(ctxt); + nbcon_context_release(ctxt); +} --=20 2.50.0 From nobody Sun Oct 5 00:12:25 2025 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 EEE962DC33B for ; Mon, 11 Aug 2025 13:33:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754919234; cv=none; b=QFiARM+e8vDWgID4rdgH8WfzOCbCk4awY7rFd73YrGXY5A5ZsxtpQAUlLfKvwTZUa6jwfVWkYWhZbh/mHgGTISKo2pJa5dvcJGHfvKsSr29JIzXmIz1TONBvla+m8h4m9PpdO4uPBnIo4sEWKDQFMEiZse1p/uFOAA+OYh8WzhE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754919234; c=relaxed/simple; bh=wHJt9KADeg3vlovyFmoply0rzf3HIHb2hJqagqqEV+w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pVn2CWC+My9LWIxcR34BwRtlNzRV5HvRj/yeG3ux1oTeaF0pkxfHz5Ufh7DniYj/uRJvZ846cJ2ImcMETQICoz+jYOq8If3FCYbDE2RzdgH0NFYURt5F6FyUNvOq/9p9rbJPRRwhjqqspDDXKKgOS9rKV1KXs/iXdWU81vl0QH8= 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=BUiG8ukl; arc=none smtp.client-ip=209.85.221.46 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="BUiG8ukl" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-3b792b0b829so4231622f8f.3 for ; Mon, 11 Aug 2025 06:33:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1754919230; x=1755524030; 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=npbwFYYz8zd+MoHg005SoEvDbAHHK2F2wVdN9XZoFi0=; b=BUiG8ukl4bnqoa5GRpl60zIyjFHG4n2xINKzRTPXT5rToZvWyMM2hCcLVpkYXj+Ikh U9LvzGD6Q5uth/wuw0yPiJZnzCK0ZO57aNFzfilrliBYjSsdnOyk7VTSLMg01Zqe2lMw gX54BKZotvDqet4fv25qf+wnEs8xvS4cXL3oNUfrw8yrdstmi6jeJxitJdRKac7MDDNW P1dKOlDAESut5B/Jih5VGsWQ+TmaUgwQRn6yJ5Q4x6z+pjrKNoARQtfPUwf83XpfBuEQ nNHE2mLpqMzjuwTrMkc8eGUNALBpuwpNhlODXuRG+gJi4HmnJbUufMWO8vxixo+CA7+0 lgBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754919230; x=1755524030; 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=npbwFYYz8zd+MoHg005SoEvDbAHHK2F2wVdN9XZoFi0=; b=rYuyLvs3a8ihAetyiAQ5g0XzYp69zjzUus5FKWMQyKtDJ+1JZZCbnx2sUDKJuQutR8 T9538tm+SNaTi8aL4Htw584Ce0aNyn80dwScdgaqcEGKwxKPwIW+ffG+S81X9T+0KP7l HJKd5isoYgNDbSLJtlYT+JED48QggsOcDwaDRKAPAHUWFOID+tA63a+p49fArjzuTM3d xjSIPeZ0BnUPIFQwTC7yNEbXjiqKLoWr/ygF8vVErXFp4/8V8cTp3O+adHwy2fmyx8xa NE8s/a9SwH+/D2BqcMelefq+fAS1nYS2mPOtxAKsAXyryqBEK6A7xZhGx71TDoAywOhW QHwQ== X-Gm-Message-State: AOJu0YzvREV7y6KE1A6V8Uq/PWE1KtZWvGHG8Kz2iJrS6RsYYc/wB/9V Mut7fHrhBbmtmAnDoq7sSBIutpsUNHdCl1a4mQX67Ixayy3sdpETEwSPMJOF73nxLpk= X-Gm-Gg: ASbGncuHWvRTP5Euv+FU3j9X4IW3CnnScqABA89i9fKMUE6ZZsv0A7hB1qr74y41T+F 1BFJ1D9TgnHwhgL9b5IaR8yN87T2HRVxTcL7UkOwarM6DUd9+k3rDU3CDMhxDyf/4X7c+lMr8oE YHCjFySRX+L14Sn+RLTB0auvXKVpIRXwUVqXggr18asDTbxP2vx80Z3Hk11kNi6SooqkGLjJWS6 DFZH1Pl80A0PADNSE06GE/LERuYY5JbPQPtxIxqLwIXyd0w53wxPDxXIfkYDjqslml8dg7pFQOz iq9U3qbhtnU6QCoY/6j3BxW3jpTZNu51jjq934FEqs19abjes6vISMnAm3jCCUezWfv/jpw+93Q fR9t8X4lRd+EVI46BQ3QjJzqYRL7ZmX+B33CQWpBvQeG9wg== X-Google-Smtp-Source: AGHT+IFxFD2OXnDy2a0RgFmC/y+CVZzaev2ere71b0IMZGKVsU0l/pbGXasgy8IKu9OXnU5Vt+tAHg== X-Received: by 2002:a05:6000:178f:b0:3b7:8dd7:55ad with SMTP id ffacd0b85a97d-3b900b7aeafmr10984761f8f.39.1754919230049; Mon, 11 Aug 2025 06:33:50 -0700 (PDT) Received: from [127.0.0.1] (71.36.160.45.gramnet.com.br. [45.160.36.71]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-76bccfd18c9sm26667449b3a.91.2025.08.11.06.33.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Aug 2025 06:33:49 -0700 (PDT) From: Marcos Paulo de Souza Date: Mon, 11 Aug 2025 10:32:47 -0300 Subject: [PATCH v2 3/3] 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: <20250811-nbcon-kgdboc-v2-3-c7c72bcdeaf6@suse.com> References: <20250811-nbcon-kgdboc-v2-0-c7c72bcdeaf6@suse.com> In-Reply-To: <20250811-nbcon-kgdboc-v2-0-c7c72bcdeaf6@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=1754919199; l=2309; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=wHJt9KADeg3vlovyFmoply0rzf3HIHb2hJqagqqEV+w=; b=a5sAiSr27faPRI3JEgJIJnvCPiyXuqBHilT/H7/wQTH7y8AvHd1onEGwUehVWIzpdBfmoTXj1 4JZv+miDm9oDWSNn8rFpmilYyhCt/JzEP1cILI6+h9NUo74JB81TMTz 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. 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. Suggested-by: Petr Mladek Signed-off-by: Marcos Paulo de Souza --- kernel/debug/kdb/kdb_io.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 9b11b10b120cf07e451a7a4d92ce50f9a6c066b2..74f6d4316bdc9d3c4f6d4252bf4= 25e33cce65a87 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -589,12 +589,23 @@ 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; + + /* + * Do not continue if the console is NBCON and the context + * can't be acquired. + */ + if (flags & CON_NBCON) { + if (!nbcon_kdb_try_acquire(c, &wctxt)) + continue; + } + /* * Set oops_in_progress to encourage the console drivers to * disregard their internal spin locks: in the current calling @@ -605,7 +616,14 @@ 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) { + wctxt.outbuf =3D (char *)msg; + wctxt.len =3D msg_len; + c->write_atomic(c, &wctxt); + nbcon_kdb_release(&wctxt); + } else { + c->write(c, msg, msg_len); + } --oops_in_progress; touch_nmi_watchdog(); } --=20 2.50.0