Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3488524pxy; Mon, 26 Apr 2021 03:02:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzplPKX8KagmINPp3Mvwhyqfj6WNL4AdyroQ7cQ+a2s6sR8ViyBLgowIQenocPSdwSRbLo X-Received: by 2002:a17:906:4e93:: with SMTP id v19mr17513185eju.215.1619431375185; Mon, 26 Apr 2021 03:02:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619431375; cv=none; d=google.com; s=arc-20160816; b=Ll7EjiA5sLC3a2fmpOLDfAiVJNdUG566B5QTlnB8KHG7qsRacOlgObJRTwSrgRXKDg nyXCXsC2Uv+kqjn+hTGJ/nbOSyEOwQfFz/4W1U+ZHx20vAVllDb/30EX1rfoINXVlNLd uobFy/GjAvDwC0dw1bK9gi/oamWKHwRb08x8koSmsO1gFLPxIXGW/K7IMuaCOEbUtm2G 9Fx/jKIac5h0rIHrt4kU2fU92XtqmG26zvbnlLwwcKEVn4NJbGP9hIEq0aEQOesfQ+kJ hpwomuX5Zg/c+VWt2nF6MR8IHXpXwreDmm+aF/o1NVosszn4xvmaklBgTZQv5xhlmtq2 pHBA== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=236Xh/UNn0S/8u+6zQznzVUUtl8jlR4aS6Ek+3iM9ag=; b=YxiKs+ia61GEpzmR7L2zNInf9H+eaJHTK7I7cEbntyMeBIAPP2VxVNkaDz6t3m+EgL /d1uLYRJ/xVNf01xedDTeDcxaD5Yjg/PGe0R+ynqKnwaF/6n30cQgEwM7/ZakUIUai9W xZmGoRLS9IpIjKRTqMzaQg8GEglIXkSFuNcwHlzkwz7BI37Uaiwd/5tz+PIQDhjDS7Ev q9uDBR0UHYYI9ILNvk65I/71kZgrI/WpGMR2Bz/kJT44yDU3TKNOqmzMkCDVURxbB5/i tvsEawOKADa4YkvVZOZ4TMMaEIXhRIDrP1jTC1PI3iYLP+1jJD9eqFdbppxzohCQuNIz DXmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=e3noeTC2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w5si13034377edr.110.2021.04.26.03.02.30; Mon, 26 Apr 2021 03:02:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=e3noeTC2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232496AbhDZKBU (ORCPT + 99 others); Mon, 26 Apr 2021 06:01:20 -0400 Received: from mx2.suse.de ([195.135.220.15]:38364 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232328AbhDZKBU (ORCPT ); Mon, 26 Apr 2021 06:01:20 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1619431238; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=236Xh/UNn0S/8u+6zQznzVUUtl8jlR4aS6Ek+3iM9ag=; b=e3noeTC28z/Xri6GrVAsLQbb+19/ZXKcwiXykttGpO3/LQwVaTNdxg12/fw2LRPC+6t9IA HcPkCQPLrE/HN8gkXcHFzww+HzN2AvJoWL+Y2kwYFA5bE5sc6iWvSNPVySXFy2EecsWSxC 0I4I24RVxxYVhLylKutG0yct0a6ntQA= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id EBD40AFE2; Mon, 26 Apr 2021 10:00:37 +0000 (UTC) Date: Mon, 26 Apr 2021 12:00:35 +0200 From: Petr Mladek To: Samo =?utf-8?B?UG9nYcSNbmlr?= Cc: Tetsuo Handa , Jiri Slaby , Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , linux-kernel@vger.kernel.org, syzkaller-bugs Subject: Re: [PATCH] ttyprintk: Add TTY hangup callback. Message-ID: References: <095d5393-b212-c4d8-5d6d-666bd505cc3d@i-love.sakura.ne.jp> <31a4dec3d36ed131402244693cae180816ebd4d7.camel@t-2.net> <17e0652d-89b7-c8c0-fb53-e7566ac9add4@i-love.sakura.ne.jp> <8043d41d48a0f4f13bd891b4c3e9ad28c76b430e.camel@t-2.net> <699d0312-ee68-8f05-db2d-07511eaad576@kernel.org> <33461bad-ef57-9036-135d-95a60a8c88d5@i-love.sakura.ne.jp> <07c3c9015491ca9b42362098d5e90ca7480cf5ed.camel@t-2.net> <9e8805a98d6c0d0f20e563c8e4db98b595826c13.camel@t-2.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <9e8805a98d6c0d0f20e563c8e4db98b595826c13.camel@t-2.net> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat 2021-04-24 11:57:47, Samo Pogačnik wrote: > Dne 24.04.2021 (sob) ob 10:16 +0900 je Tetsuo Handa napisal(a): > > On 2021/04/24 4:47, Samo Pogačnik wrote: > > > At any point the tpk_buffer is potentially multiplexed/interleaved by parts > > > of > > > required output of any concurrent user, as buffs are being delivered by the > > > scheduled writes. > > > > As long as one line is printed by one printk() call, CONFIG_PRINTK_CALLER=y is > > helpful enough to distinguish multilplexed/interleaved messages. I consider > > that > > ttyprintk offers additional advantage over printk() for allow buffering one > > line > > of message from userspace. It does not matter how much buffering games you play. As long as you use printk() to store single lines into the kernel logbuffer they alway could be interleaved with lines from other processes/CPUs. > > > > > > As per user buffers look promising with output formatting, the FDs passing > > > between tasks lead to the same single buffer (Greg already mentioned that). > > > > Those programs which use FD passing know what they are doing. If they still > > want > > one line of message printed via ttyprintk interface, they must do their > > buffering > > before trying to write() to ttyprintk's file descriptor. Lines might get interleaved when using printk(). What is special about messages passed via ttyprintk()? How many processes are using it? Do they print many lines? Is it really worth any added complexity? > > Use of per "struct file" buffer gives those programs which does not use > > FD passing a guarantee that one line of message from those programs won't be > > multilplexed/interleaved (with the aid of CONFIG_PRINTK_CALLER=y). How huge bugffer would be needed? IMHO, even a 80-bytes big per-task buffer is not acceptable. And even such a buffer would hold only 1-3 lines. > I think i understand, what would you like to achieve, however implementation > wise there seems to be no reference point available in tty write operation that > would relate to its tty open/close operations (i.e. open() and close() provide > filp while write() does not - probably for a reason) or is there such a relation > available? < > On the other hand, my main concern is how to provide a reliable system wide > collection of all console output via ttyprintk console redirection, while normal > operation of system console is preserved (except its output being detoured via > printk and as such logged together with kernel output). Such logging is > particularly useful for after-the-fact inspection of system operation. I am not sure if I understand the problem. But why does ttyprintk need any buffer at all. AFAIK, the use-case is to pass any written data into the kernel logbuffer via printk()? Why tpk_write() does not call printk() directly? If you call printk() directly, the caller_id would be from the process that really wrote the data/message. > That being said i am thinking about how to permanently enable this redirection > as early as possible (i.e. via kernel command line option). I had a working > prototype for that some time ago (never posted). Would anybody like to see such > functionality? Please, do not add any complex code if it does not cause real life problems. There seems to be only few commits that suggest that anyone is using this driver and the latest is 7 year old. + (2014) acef6660d3aaf18813143 ("ttyprintk: make the printk log level configurable") + (2014) b24313a82cf24e9017067 ("ttyprintk: Allow built as a module") + (2014) 7d1c2858c49095ab748f5 ("ttyprintk: Fix wrong tty_unregister_driver() call in the error path") + (2014) db50d2f65b7c2bcdfb931 ("drivers/char: don't use module_init in non-modular ttyprintk.c") + (2013) b5325a02aa84c794cf520 ("ttyprintk: Fix NULL pointer deref by setting tty_port ops after initializing port") + (2012) ee8b593affdf893012e57 ("TTY: ttyprintk, don't touch behind tty->write_buf") + (2012) f06fb543c1d0cbd721250 ("TTY: ttyprintk, unregister tty driver on failure") + (2012) 2f16669d322e05171c9e1 ("TTY: remove re-assignments to tty_driver members") + (2010) 24b4b67d17c308aaa956b ("add ttyprintk driver") Best Regards, Petr