From nobody Mon Apr 6 04:57:29 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 B6297ECAAD3 for ; Sat, 10 Sep 2022 22:29:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230466AbiIJW3B (ORCPT ); Sat, 10 Sep 2022 18:29:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230137AbiIJW2Q (ORCPT ); Sat, 10 Sep 2022 18:28:16 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43D5D43E7F for ; Sat, 10 Sep 2022 15:27:59 -0700 (PDT) Message-ID: <20220910222301.310153421@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1662848877; 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=Q4EKtLdKBpGBLYI/18LY67PpRmzH0E6rK3cfFzsdadQ=; b=NG4Uzw1YXjlcA334ks/2vKNcR5dhcaFrdgFDuMepIGsO38GRgb8G0ZXrWBYjwXCcjq+peY drotznovja8BcO1DvycSzG+KBNEtF6ujE7MBUvq/7skG1NViJI8dlg57khxTkL+WMfgqko unwT+nsTl5P8kiujhofC3s+MYjCSwmH8FYrN2DiIGmUFNwIt0KQcl1cFSXnEmilc2nvqxt vnzAEG6ht4EmSyDhdxWQ59/bkY/EUrspUoVX8dWxpZR4zWg3v/zLADAiVVR2C3LEOqZoqv 4zZfHQElfb+W2d2QcPC0cej6bKvQBHbYVeHw7J85zjGuxKEU376d8K9BL2ul+A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1662848877; 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=Q4EKtLdKBpGBLYI/18LY67PpRmzH0E6rK3cfFzsdadQ=; b=K43vbXpQMewswxlD0ROcI9fs5ZnsPtTRbWvgs3WG1ThyCcVXiwlvDDmwInsrUeMWv+YZWQ WRbG5KgbLTjtsxCg== 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 16/29] printk: Use struct cons_text_buf References: <20220910221947.171557773@linutronix.de> MIME-Version: 1.0 Date: Sun, 11 Sep 2022 00:27:56 +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" Replace the seperately allocated output buffers with a single instance of struct cons_text_buf. Signed-off-by: Thomas Gleixner --- kernel/printk/printk.c | 50 ++++++++++++++++++++------------------------= ----- 1 file changed, 21 insertions(+), 29 deletions(-) --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -666,11 +666,9 @@ struct devkmsg_user { atomic64_t seq; struct ratelimit_state rs; struct mutex lock; - char buf[CONSOLE_EXT_LOG_MAX]; - struct printk_info info; - char text_buf[CONSOLE_EXT_LOG_MAX]; struct printk_record record; + struct cons_text_buf txtbuf; }; =20 static __printf(3, 4) __cold @@ -753,6 +751,8 @@ static ssize_t devkmsg_read(struct file { struct devkmsg_user *user =3D file->private_data; struct printk_record *r =3D &user->record; + char *outbuf =3D user->txtbuf.ext_text; + const int maxlen =3D sizeof(user->txtbuf.ext_text); size_t len; ssize_t ret; =20 @@ -793,8 +793,8 @@ static ssize_t devkmsg_read(struct file goto out; } =20 - len =3D info_print_ext_header(user->buf, sizeof(user->buf), r->info); - len +=3D msg_print_ext_body(user->buf + len, sizeof(user->buf) - len, + len =3D info_print_ext_header(outbuf, maxlen, r->info); + len +=3D msg_print_ext_body(outbuf + len, maxlen - len, &r->text_buf[0], r->info->text_len, &r->info->dev_info); =20 @@ -805,7 +805,7 @@ static ssize_t devkmsg_read(struct file goto out; } =20 - if (copy_to_user(buf, user->buf, len)) { + if (copy_to_user(buf, outbuf, len)) { ret =3D -EFAULT; goto out; } @@ -904,7 +904,8 @@ static int devkmsg_open(struct inode *in mutex_init(&user->lock); =20 prb_rec_init_rd(&user->record, &user->info, - &user->text_buf[0], sizeof(user->text_buf)); + user->txtbuf.text, + sizeof(user->txtbuf.text)); =20 atomic64_set(&user->seq, prb_first_valid_seq(prb)); =20 @@ -2704,8 +2705,8 @@ static void __console_unlock(void) * * Requires the console_lock. */ -static bool console_emit_next_record(struct console *con, char *text, char= *ext_text, - char *dropped_text, bool *handover) +static bool console_emit_next_record(struct console *con, struct cons_text= _buf *txtbuf, + bool *handover, bool extmsg) { static int panic_console_dropped; struct printk_info info; @@ -2714,7 +2715,7 @@ static bool console_emit_next_record(str char *write_text; size_t len; =20 - prb_rec_init_rd(&r, &info, text, CONSOLE_LOG_MAX); + prb_rec_init_rd(&r, &info, txtbuf->text, CONSOLE_LOG_MAX); =20 *handover =3D false; =20 @@ -2736,13 +2737,13 @@ static bool console_emit_next_record(str goto skip; } =20 - if (ext_text) { - write_text =3D ext_text; - len =3D info_print_ext_header(ext_text, CONSOLE_EXT_LOG_MAX, r.info); - len +=3D msg_print_ext_body(ext_text + len, CONSOLE_EXT_LOG_MAX - len, + if (extmsg) { + write_text =3D txtbuf->ext_text; + len =3D info_print_ext_header(write_text, CONSOLE_EXT_LOG_MAX, r.info); + len +=3D msg_print_ext_body(write_text + len, CONSOLE_EXT_LOG_MAX - len, &r.text_buf[0], r.info->text_len, &r.info->dev_info); } else { - write_text =3D text; + write_text =3D txtbuf->text; len =3D record_print_text(&r, console_msg_format & MSG_FORMAT_SYSLOG, pr= intk_time); } =20 @@ -2760,7 +2761,7 @@ static bool console_emit_next_record(str console_lock_spinning_enable(); =20 stop_critical_timings(); /* don't trace print latency */ - call_console_driver(con, write_text, len, dropped_text); + call_console_driver(con, write_text, len, extmsg ? NULL : txtbuf->dropped= _text); start_critical_timings(); =20 con->seq++; @@ -2796,9 +2797,7 @@ static bool console_emit_next_record(str */ static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *h= andover) { - static char dropped_text[DROPPED_TEXT_MAX]; - static char ext_text[CONSOLE_EXT_LOG_MAX]; - static char text[CONSOLE_LOG_MAX]; + static struct cons_text_buf txtbuf; bool any_usable =3D false; struct console *con; bool any_progress; @@ -2816,16 +2815,9 @@ static bool console_flush_all(bool do_co continue; any_usable =3D true; =20 - if (con->flags & CON_EXTENDED) { - /* Extended consoles do not print "dropped messages". */ - progress =3D console_emit_next_record(con, &text[0], - &ext_text[0], NULL, - handover); - } else { - progress =3D console_emit_next_record(con, &text[0], - NULL, &dropped_text[0], - handover); - } + progress =3D console_emit_next_record(con, &txtbuf, handover, + con->flags & CON_EXTENDED); + if (*handover) return false;