public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Kent Overstreet <kent.overstreet@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	John Ogness <john.ogness@linutronix.de>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Ingo Molnar <mingo@redhat.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Michal Hocko <mhocko@suse.com>,
	Bjorn Helgaas <helgaas@kernel.org>,
	Christoph Hellwig <hch@infradead.org>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Al Viro <viro@zeniv.linux.org.uk>
Subject: Re: [PATCH v5 00/32] Printbufs
Date: Fri, 23 Sep 2022 09:10:44 +0200	[thread overview]
Message-ID: <Yy1b9KzPycxTa8OW@alley> (raw)
In-Reply-To: <20220808024128.3219082-1-willy@infradead.org>

On Mon 2022-08-08 03:40:56, Matthew Wilcox (Oracle) wrote:
> [all this code is from Kent, I'm helping him out because he's having
> trouble with git send-email and OAUTH]
> 
> This should (hopefully) be the final iteration of this patch series.
> 
> Previous discussion:
> https://lore.kernel.org/linux-mm/20220620004233.3805-1-kent.overstreet@gmail.com/
> 
> Changes since v4:
> 
>  - %pf(%p) format extension has been dropped for now, since it turned out to be
>    a bit controversial. I think we're going to want it, but I'm leaving it for a
>    future patch series.
>  - There was a small off by one error in the patch converting
>    trace_events_synth. The original code using seq_buf had to calculate the size
>    of the string to allocate; since printbufs have native support for heap
>    allocating strings, the version of the patch in this series just uses that
>    for a nice cleanup.
> 
> What are printbufs, and why?
> ============================
> 
> Printbufs are like the existing seq_buf, with some differences and new features:
> 
>  - Heap allocation (optional)
>    
>    Currently, we have no standard mechanism for printing to a heap-allocated
>    string: code that needs to do this must calculate the size of the buffer to
>    allocate, which is tedious and error prone. IOW, this is a major ergonomic
>    improvement.
> 
>  - Indent level
> 
>    Any time we're printing structured multi-line data, proper indenting makes
>    the output considerably more readable. Printbufs have state for the current
>    indent level, controlled by printbuf_indent_add() and printbuf_indent_sub()
>    and obeyed by prt_newline().
> 
>    In the future this may work with just \n, pending work to do this without
>    performance regressions.
> 
>  - Tab stops
> 
>    Printing reports with nicely aligned columns is something we do a _lot_, and
>    printbufs make this a lot easier. After setting tabstops (byte offsets from
>    start of line), prt_tab() will output spaces up to the next tabstop, and
>    pr_tab_rjust() will right justify output since the previous output against
>    the next tabstap. 
> 
>    In the future this may work with just \t, pending work to do this without
>    performance regressions.

The more I think about this patchset the more doubts I have.

My first reaction was rather positive because

1. __prt_char(out, c)

	looks more safe and sane than repeating the following code
	pattern in vsprintf code

    if (buf < end)
	*buf = '0';
    ++buf;


2. printk("%pf", meaningful_function_name(ptr))

     is more user friendly, extendable. With a type check,
     it might be even more safe than

   printk("%pxyz", ptr);


3. pretty print API would allow to avoid some tricky use of
   temporary buffers in vsprintf code, for example, see
   https://lore.kernel.org/r/20220808024128.3219082-15-willy@infradead.org


What are the concerns?

It seems that the motivation for the pretty print is to allow
printing more pretty/fancy multi-line debug messages. The API
should be usable inside vsprintf.c and also outside.

1. vsprintf() is very important core API. It is used (not only for)
   when kernel wants to provide a human readable feedback, for
   example, via printk(), trace_printk(), procfs, sysfs, debugfs.

   If a bug in vsprintf() blocks printk()/trace_printk() then
   crash_dump might be the only way to debug the kernel.


2. My experience with printk() is that external APIs are big source of
   problems. Some of them are even solved by hacks, for example:

     + Console drivers have to check oops_in_progress before taking
       port->lock to prevent a deadlock.

     + printk_deferred() or printk_once() have to be used by code that
       might be called by printk().

    This patchset adds another external API.

    The %pf feature allows writing crazy callbacks called inside
    vsprintf()/printk() without any proper review and self-tests.

    People would want to extend the pretty print API for a
    profs/sysfs/debugfs use-case. They would take it easily.
    There is a lower risk in this case because only a particular
    file is affected, the API is called in a well defined context.
    But it looks like a call for problems if we allow to call
    the same complicated code also from vsprintf() or printk()
    in any context.


3. Features usually complicate the code immediately or later.

   For example, the record based ring buffer complicated the printk()
   code a lot. It introduced many regressions. Development of the
   lockless variant was a real challenge. And it did not solve
   everything. Peple still complain that pr_cont() is not reliable.
   Multi-line output might be mixed, ...

   The pretty print API is actually designed for multi-line output.
   But it will not help when used with printk() that uses 1k buffers
   internally. And adding support for "unlimited" printk() messages
   would be another challenge. It would bring new problems,
   for example, one printk() caller might block others for too long, ...


Any opinion is really appreciated.

Best Regards,
Petr


PS: I am sorry that I did not react on this patchset for months. I was
    overloaded, sick twice, and had vacation.

    A more detailed review of the patchset would help me to have
    stronger opinion about it. I am not clever and experienced enough
    to see all the consequences on the first look.

  parent reply	other threads:[~2022-09-23  7:11 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-08  2:40 [PATCH v5 00/32] Printbufs Matthew Wilcox (Oracle)
2022-08-08  2:40 ` [PATCH v5 01/32] lib/printbuf: New data structure for printing strings Matthew Wilcox (Oracle)
2022-08-08  2:40 ` [PATCH v5 02/32] lib/string_helpers: Convert string_escape_mem() to printbuf Matthew Wilcox (Oracle)
2022-08-08 12:03   ` Andy Shevchenko
2022-08-08 14:58     ` Kent Overstreet
2022-08-08  2:40 ` [PATCH v5 03/32] vsprintf: Convert " Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 04/32] lib/hexdump: " Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 05/32] lib/string_helpers: string_get_size() now returns characters wrote Matthew Wilcox (Oracle)
2022-08-08 13:08   ` Andy Shevchenko
2022-08-08  2:41 ` [PATCH v5 06/32] lib/printbuf: Heap allocation Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 07/32] lib/printbuf: Tabstops, indenting Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 08/32] lib/printbuf: Unit specifiers Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 09/32] vsprintf: Improve number() Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 10/32] vsprintf: prt_u64_minwidth(), prt_u64() Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 11/32] test_printf: Drop requirement that sprintf not write past nul Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 12/32] vsprintf: Start consolidating printf_spec handling Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 13/32] vsprintf: Refactor resource_string() Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 14/32] vsprintf: Refactor fourcc_string() Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 15/32] vsprintf: Refactor ip_addr_string() Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 16/32] vsprintf: Refactor mac_address_string() Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 17/32] vsprintf: time_and_date() no longer takes printf_spec Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 18/32] vsprintf: flags_string() " Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 19/32] vsprintf: Refactor device_node_string, fwnode_string Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 20/32] vsprintf: Refactor hex_string, bitmap_string_list, bitmap_string Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 21/32] Input/joystick/analog: Convert from seq_buf -> printbuf Matthew Wilcox (Oracle)
2022-08-11  1:37   ` Dmitry Torokhov
2022-08-08  2:41 ` [PATCH v5 22/32] mm/memcontrol.c: Convert to printbuf Matthew Wilcox (Oracle)
2022-08-08  9:48   ` Michal Hocko
2022-08-08 12:48     ` Michal Hocko
2022-08-08  2:41 ` [PATCH v5 23/32] clk: tegra: bpmp: " Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 24/32] tools/testing/nvdimm: " Matthew Wilcox (Oracle)
2022-08-08 18:30   ` Dan Williams
2022-08-08 18:33     ` Kent Overstreet
2022-08-08  2:41 ` [PATCH v5 25/32] powerpc: " Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 26/32] x86/resctrl: " Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 27/32] PCI/P2PDMA: " Matthew Wilcox (Oracle)
2022-08-08 17:51   ` Bjorn Helgaas
2022-08-08 18:42     ` Kent Overstreet
2022-08-09  2:07       ` Bjorn Helgaas
2022-08-09  8:00         ` Christoph Hellwig
2022-08-08  2:41 ` [PATCH v5 28/32] tracing: trace_events_synth: " Matthew Wilcox (Oracle)
2022-08-08  2:41 ` [PATCH v5 29/32] d_path: prt_path() Matthew Wilcox (Oracle)
2022-08-08  4:17   ` Al Viro
2022-08-08  4:27     ` Kent Overstreet
2022-08-08  2:41 ` [PATCH v5 30/32] ACPI/APEI: Add missing include Matthew Wilcox (Oracle)
2022-08-08 14:09   ` Rafael J. Wysocki
2022-08-08  2:41 ` [PATCH v5 31/32] tracing: Convert to printbuf Matthew Wilcox (Oracle)
2022-08-08  2:51   ` Steven Rostedt
2022-08-08  3:32     ` Kent Overstreet
2022-08-08 13:37       ` Steven Rostedt
2022-08-08 15:15         ` Kent Overstreet
2022-08-08 15:25           ` Steven Rostedt
2022-08-08  2:41 ` [PATCH v5 32/32] Delete seq_buf Matthew Wilcox (Oracle)
2022-09-23  7:10 ` Petr Mladek [this message]
2022-09-24  1:39   ` [PATCH v5 00/32] Printbufs Kent Overstreet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yy1b9KzPycxTa8OW@alley \
    --to=pmladek@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=hch@infradead.org \
    --cc=helgaas@kernel.org \
    --cc=john.ogness@linutronix.de \
    --cc=kent.overstreet@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mhocko@suse.com \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox