Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3374653rdh; Thu, 28 Sep 2023 09:45:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGEhPmWhaeFAWfmmjQ9VgphelwjzhAC/Y/0v8pF1xM23MoyS7eeUO15jT1HexCh9/anRCt7 X-Received: by 2002:a17:902:c651:b0:1be:f37f:a8d5 with SMTP id s17-20020a170902c65100b001bef37fa8d5mr2505114pls.10.1695919530347; Thu, 28 Sep 2023 09:45:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695919530; cv=none; d=google.com; s=arc-20160816; b=z2g3uA7L19TIr5/ajWsrd+hp0hlz5uYhUWhYJc1k4ANrAzXt1F8dMoINY+Hj9UKFom gy3ZJlWadrle/lIMpp6vXjtb+mmVf/hwaZrbHq5tZvgIN55kCUpZa9DbtR9Ey7sMw31w XfcSWx9oKArnGsf3MBv1oYe7jwKIzjc5MYBHql2/8uS+fs+DXDTD+huBg4TnrsKzGV8B IpmVfwggbZqzPr3fDhMNi864MiEiWvm1w2HzY57ZNnuSyDeS44zckaCKBW+XVt7+1T+S DUjZPtQeslSkAR7fCUclCvo7WTjpJubP35ZhkQY5gMNaCTVILvuoSpfmaZykuW3uBcGB /uRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=TiB3kOtOHfeUjOSXRAu2k520P1XEBseS6ilUrwqLVLI=; fh=yn4VAuaoCGioacY5vJ3Zhta6pOGtj8OcBSq4Rnrd9iI=; b=UbaJONIm34A1XyogKx9uKHNhu90gfij43e03XspzRKjVHVmY43xtCVMfAV2fhJ/yWy vOKzokXuInoCzooONtoxc6lTmJPvPfvaydgmZLszvnd/OYO6GKD+i1nlw9Hvsdp+eTtO DOlvuElTHXJ7+FUWrYamnEio8zAug1wA7mIwcYXDAfsu+ro799+y9+8CqSQVS9doXmkf u5UlAbpYmg7pAHSmCKaCoKIB+xxhvGXw2gTv+zogGVTNrNYuPIwMPy09qI3QGlk66ApU iaBWOTNg7QIx2K9HAV4gPq9JsVxqU8gWhrLocnF2i4j573jmEAzhlTBF7nvrmxSLQbnm hCjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xm1YqDrb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id km12-20020a17090327cc00b001c427a74e31si17422322plb.628.2023.09.28.09.45.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 09:45:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xm1YqDrb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 28187802F7CF; Wed, 27 Sep 2023 23:43:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230490AbjI1Gn3 (ORCPT + 99 others); Thu, 28 Sep 2023 02:43:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbjI1Gn1 (ORCPT ); Thu, 28 Sep 2023 02:43:27 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A57D9C; Wed, 27 Sep 2023 23:43:25 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55545C433C8; Thu, 28 Sep 2023 06:43:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1695883404; bh=DSvDae1aDnAGK6cZ1bq0OV0fku1272PZ2tdvrFmrup4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=xm1YqDrbd47/RaAXYtFbyDPcMfa81W/h3Bqbh5qK1av3hDzGKhVxeBgQbahJzJt3p Lc5jIl5zrlw64Ebf55Aez44e13cTU1VioTZXZXPpDq+IoHPMiaYb5/R06abeYxxGFf 3xopreGCGy0F88x4Lu3Bv4vxn4QlBBdcunhiZ3Xs= Date: Thu, 28 Sep 2023 08:43:22 +0200 From: Greg KH To: Yuanhe Shu Cc: jirislaby@kernel.org, keescook@chromium.org, tony.luck@intel.com, gpiccoli@igalia.com, shuah@kernel.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-hardening@vger.kernel.org, linux-kselftest@vger.kernel.org, Xingrui Yi Subject: Re: [PATCH 1/5] pstore: add tty frontend Message-ID: <2023092804-backslid-ninth-3afe@gregkh> References: <20230928024244.257687-1-xiangzao@linux.alibaba.com> <20230928024244.257687-2-xiangzao@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230928024244.257687-2-xiangzao@linux.alibaba.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 27 Sep 2023 23:43:50 -0700 (PDT) On Thu, Sep 28, 2023 at 10:42:40AM +0800, Yuanhe Shu wrote: > Provide a pstore frontend which can log all messages that are send > to tty drivers when there are some problems with drivers or there > is no access to serial ports. > > Using pmsg requires us to redirect the output of the user state. > When we need to globally view the serial output of various processes, > it is tedious to redirect the output of each process. We think pmsg is > more suitable for targeted viewing of certain processes' output, and > we also need a tool that can quickly do a global view so that we can > get user-state printed data if the tty driver is working abnormally or > if we don't have serial access. > > Furthermore, by enabling tty frontend and console/dmesg frontend in > dump capture kernel, one can collect kernel and user messages to > discover why kdump service works abnormal. > > Signed-off-by: Yuanhe Shu > Signed-off-by: Xingrui Yi > --- > drivers/tty/n_tty.c | 1 + > fs/pstore/Kconfig | 23 +++++++++++++++++ > fs/pstore/Makefile | 2 ++ > fs/pstore/blk.c | 10 ++++++++ > fs/pstore/internal.h | 8 ++++++ > fs/pstore/platform.c | 5 ++++ > fs/pstore/ram.c | 40 +++++++++++++++++++++++++++-- > fs/pstore/tty.c | 50 +++++++++++++++++++++++++++++++++++++ > fs/pstore/zone.c | 42 ++++++++++++++++++++++++++++++- > include/linux/pstore.h | 2 ++ > include/linux/pstore_blk.h | 3 +++ > include/linux/pstore_ram.h | 1 + > include/linux/pstore_zone.h | 2 ++ > include/linux/tty.h | 14 +++++++++++ > 14 files changed, 200 insertions(+), 3 deletions(-) > create mode 100644 fs/pstore/tty.c > > diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c > index 552e8a741562..55ca40605e4c 100644 > --- a/drivers/tty/n_tty.c > +++ b/drivers/tty/n_tty.c > @@ -582,6 +582,7 @@ static ssize_t process_output_block(struct tty_struct *tty, > } > } > break_out: > + tty_pstore_hook(buf, i); "hook"? That does not help explain what this is doing here at all. A better name would be best, but why is this part of n_tty at all? Why isn't it a console driver just for this, you are sitting in the middle of the fast-path of the tty layer sucking in data all the time, what is the performance impact of this extra jump? > --- a/fs/pstore/blk.c > +++ b/fs/pstore/blk.c > @@ -52,6 +52,14 @@ static long ftrace_size = -1; > module_param(ftrace_size, long, 0400); > MODULE_PARM_DESC(ftrace_size, "ftrace size in kbytes"); > > +#if IS_ENABLED(CONFIG_PSTORE_TTY) > +static long tty_size = CONFIG_PSTORE_BLK_TTY_SIZE; > +#else > +static long tty_size = -1; > +#endif > +module_param(tty_size, long, 0400); > +MODULE_PARM_DESC(tty_size, "tty_size size in kbytes"); Do we really need more module parameters that are undocumented? > diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c > index 2f625e1fa8d8..f59712bc51d3 100644 > --- a/fs/pstore/ram.c > +++ b/fs/pstore/ram.c > @@ -44,6 +44,10 @@ static ulong ramoops_pmsg_size = MIN_MEM_SIZE; > module_param_named(pmsg_size, ramoops_pmsg_size, ulong, 0400); > MODULE_PARM_DESC(pmsg_size, "size of user space message log"); > > +static ulong ramoops_tty_size = MIN_MEM_SIZE; > +module_param_named(tty_size, ramoops_tty_size, ulong, 0400); > +MODULE_PARM_DESC(tty_size, "size of tty message log"); Again, why a module parameter? > --- /dev/null > +++ b/fs/pstore/tty.c > @@ -0,0 +1,50 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Provide a pstore frontend which can log all messages that are send > + * to tty drivers when there are some problems with drivers or there > + * is no access to serial ports. > + */ No copyright line? Are you sure your company is ok with that? > + > +#include > +#include > +#include > +#include "internal.h" > + > +DEFINE_STATIC_KEY_FALSE(tty_key); > + > +#define TTY_NAME "tty" > +#undef pr_fmt > +#define pr_fmt(fmt) TTY_NAME ": " fmt > + > +static void do_write_ttymsg(const unsigned char *buf, int count, > + struct pstore_info *psinfo) Odd formatting :( > +{ > + struct pstore_record record, newline; > + > + pstore_record_init(&record, psinfo); > + record.type = PSTORE_TYPE_TTY; > + record.size = count; > + record.buf = (char *)buf; Why the casting? Why isn't the buffer a u8 * here? > + psinfo->write(&record); > + > + pstore_record_init(&newline, psinfo); > + newline.type = PSTORE_TYPE_TTY; > + newline.size = strlen("\n"); > + newline.buf = "\n"; > + psinfo->write(&newline); Why have 2 structures and not just one? And why the new line all the time, you are not guaranteed that your buffer must have a new line here, it could be in the middle of a hunk of data that is longer than the normal buffer size. Why not rely on the tty data to handle the new line stuff for you in the proper location? thanks, greg k-h