All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/28] Printbufs (now with more printbufs!)
@ 2022-05-19 17:23 Kent Overstreet
  2022-05-19 17:23 ` [PATCH v2 01/28] lib/printbuf: New data structure for printing strings Kent Overstreet
                   ` (28 more replies)
  0 siblings, 29 replies; 63+ messages in thread
From: Kent Overstreet @ 2022-05-19 17:23 UTC (permalink / raw)
  To: linux-kernel, linux-mm, pmladek, rostedt, senozhatsky
  Cc: Kent Overstreet, andriy.shevchenko, willy

So there's a lot of new stuff since the first posting:

 - Printbufs have been broken up into multiple patches that each add distinct
   functionality - this is intended to make it easier to review and to see
   what's used for what

 - Printbufs now support both auto-heap allocated buffers, and external/static
   buffers: this was required for the vsprintf.c refactoring, and means they're
   (almost) a direct replacement for seq_buf

 - The big thing: a new %pf(%p) format string extension for calling pretty
   printers from printf (idea from Matthew Wilcox)

   This is intended to replace most of our other format string extensions: e.g.
   instead of writing
     printf("%pg", bdev);

   You'd now write
     printf("%pf(%p)", bdev_name, bdev);

   The advantage of this is that pretty printers no longer have to live in
   lib/vsprintf.c, and they're much more discoverable - you can cscope to the
   pretty printer!

   And my hope is that this will help induce people to write lots more pretty
   printers; since they can now live with the code they're printing and don't
   require touching code in vsprintf.c, there's less friction to creating new
   ones.

   We hope to standardize this extension as %(%p), but since gcc's printf format
   checking doesn't yet understand that we're going with %pf(%p) for now.

   Currently, we only support pointer arguments to pretty-printers. I think we
   can improve this in the future to support at least integer arguments as well,
   i.e. "%(%u)" will eventually work. This will require using libffi to do it
   correctly, but it looks like libffi is nearly suitable for in kernel use (it
   supports all linux architectures, and configured with the features we want it
   compiles down to practically nothing).

 - Massive vsprintf.c refactoring

   printbufs are now the core data structure used by vsprintf.c - we're not
   passing around a bunch of raw char pointers anymore! yay!

   This gets us a sane standard calling convention for pretty printers - i.e.,
   we need this for %pf(%p).

   Couple notes on the refactoring:

   - printf_spec has become a dumping ground of state, passed everywhere and
     used inconsistently. The refactoring attempts to improve this, and
     centralize printf_spec handling as much as possible near/in the top level
     code that handles format strings. Some %p extensions use
     field/width/precision in nonstandard ways; the refactoring patches make it
     clearer where this is going on.

   - a _lot_ of pretty printers were allocating secondary buffers on the stack,
     mainly to avoid ever writing past the terminating null in the output
     buffer. There was a test that checked for this, but it had no documentation
     where the requirement came from nor does that requirement make any sense,
     so I deleted it (if anyone knows anything about it, speak up!). The code
     now takes the approach of just writing to the output buffer and then
     truncating afterwards if required by the precision argument.

     Yay, less stack usage!

   - format string parsing is still a mess: I'd like to consolidate that to only
     happen in one place, but that's going to be a much more involved
     refactoring - and if we just switch to new-style calling pretty printers
     directly, we'll be able to just delete all that code.

 - More seq_buf conversions

   Using printbufs to clean up vsprintf.c meant adding a second, non
   heap-allocated mode, so printbufs now do almost everything seq_buf does -
   seq_buf has a read_pos member for some reason (tracing?) that I didn't get
   into.

   So now seq_buf is just used by the tracing code, and that can also probably
   be converted to printbuf, but seq_buf is Steven's thing so I'll let him take
   a look before getting into that.

Kent Overstreet (28):
  lib/printbuf: New data structure for printing strings
  vsprintf: Convert to printbuf
  vsprintf: %pf(%p)
  lib/string_helpers: string_get_size() now returns characters wrote
  lib/printbuf: Heap allocation
  lib/printbuf: Tabstops, indenting
  lib/printbuf: Unit specifiers
  lib/pretty-printers: pr_string_option(), pr_bitflags()
  vsprintf: Improve number()
  vsprintf: pr_u64_minwidth(), pr_u64()
  vsprintf: Lift pr_hex_bytes() out from hex_string()
  test_printf: Drop requirement that sprintf not write past nul
  vsprintf: Start consolidating printf_spec handling
  vsprintf: Refactor resource_string()
  vsprintf: Refactor fourcc_string()
  vsprintf: Refactor ip_addr_string()
  vsprintf: Refactor mac_address_string()
  vsprintf: time_and_date() no longer takes printf_spec
  vsprintf: flags_string() no longer takes printf_spec
  vsprintf: Refactor device_node_string, fwnode_string
  vsprintf: Refactor hex_string, bitmap_string_list, bitmap_string
  Input/joystick/analog: Convert from seq_buf -> printbuf
  mm/memcontrol.c: Convert to printbuf
  clk: tegra: bpmp: Convert to printbuf
  tools/testing/nvdimm: Convert to printbuf
  powerpc: Convert to printbuf
  x86/resctrl: Convert to printbuf
  PCI/P2PDMA: Convert to printbuf

 Documentation/core-api/printk-formats.rst |   19 +
 arch/powerpc/kernel/process.c             |   16 +-
 arch/powerpc/kernel/security.c            |   75 +-
 arch/powerpc/platforms/pseries/papr_scm.c |   34 +-
 arch/x86/kernel/cpu/resctrl/rdtgroup.c    |   16 +-
 drivers/clk/tegra/clk-bpmp.c              |   21 +-
 drivers/input/joystick/analog.c           |   37 +-
 drivers/pci/p2pdma.c                      |   17 +-
 include/linux/kernel.h                    |    4 +
 include/linux/pretty-printers.h           |   11 +
 include/linux/printbuf.h                  |  225 +++
 include/linux/string_helpers.h            |    8 +-
 lib/Makefile                              |    2 +-
 lib/pretty-printers.c                     |   81 ++
 lib/printbuf.c                            |  252 ++++
 lib/string_helpers.c                      |   18 +-
 lib/test_printf.c                         |   23 +-
 lib/vsprintf.c                            | 1612 ++++++++++-----------
 mm/memcontrol.c                           |   68 +-
 tools/testing/nvdimm/test/ndtest.c        |   22 +-
 20 files changed, 1527 insertions(+), 1034 deletions(-)
 create mode 100644 include/linux/pretty-printers.h
 create mode 100644 include/linux/printbuf.h
 create mode 100644 lib/pretty-printers.c
 create mode 100644 lib/printbuf.c

-- 
2.36.0


^ permalink raw reply	[flat|nested] 63+ messages in thread

end of thread, other threads:[~2022-05-31 22:03 UTC | newest]

Thread overview: 63+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-19 17:23 [PATCH v2 00/28] Printbufs (now with more printbufs!) Kent Overstreet
2022-05-19 17:23 ` [PATCH v2 01/28] lib/printbuf: New data structure for printing strings Kent Overstreet
2022-05-19 18:21   ` Matthew Wilcox
2022-05-20  4:44     ` Kent Overstreet
2022-05-26 15:06   ` Petr Mladek
2022-05-26 15:21     ` Kent Overstreet
2022-05-26 15:36       ` Joe Perches
2022-05-27 10:29       ` Petr Mladek
2022-05-29 18:15         ` Kent Overstreet
2022-05-31 22:03         ` Kent Overstreet
2022-05-19 17:23 ` [PATCH v2 02/28] vsprintf: Convert to printbuf Kent Overstreet
2022-05-19 17:23 ` [PATCH v2 03/28] vsprintf: %pf(%p) Kent Overstreet
2022-05-19 18:33   ` Matthew Wilcox
2022-05-20  4:43     ` Kent Overstreet
2022-05-19 21:06   ` David Laight
2022-05-19 21:15     ` Matthew Wilcox
2022-05-20  8:03       ` David Laight
2022-05-20 13:08         ` Matthew Wilcox
2022-05-20  4:49     ` Kent Overstreet
2022-05-20 14:17       ` andriy.shevchenko
2022-05-19 21:20   ` Matthew Wilcox
2022-05-20  7:40   ` Michal Hocko
2022-05-20 15:01     ` Kent Overstreet
2022-05-20 17:56     ` Kent Overstreet
2022-05-19 17:23 ` [PATCH v2 04/28] lib/string_helpers: string_get_size() now returns characters wrote Kent Overstreet
2022-05-19 17:23 ` [PATCH v2 05/28] lib/printbuf: Heap allocation Kent Overstreet
2022-05-19 17:23 ` [PATCH v2 06/28] lib/printbuf: Tabstops, indenting Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 07/28] lib/printbuf: Unit specifiers Kent Overstreet
2022-05-19 20:21   ` Andy Shevchenko
2022-05-19 20:26     ` Kent Overstreet
2022-05-19 21:11       ` Matthew Wilcox
2022-05-20  4:40         ` Kent Overstreet
2022-05-19 21:16       ` Andy Shevchenko
2022-05-19 21:22         ` Matthew Wilcox
2022-05-20  4:36         ` Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 08/28] lib/pretty-printers: pr_string_option(), pr_bitflags() Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 09/28] vsprintf: Improve number() Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 10/28] vsprintf: pr_u64_minwidth(), pr_u64() Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 11/28] vsprintf: Lift pr_hex_bytes() out from hex_string() Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 12/28] test_printf: Drop requirement that sprintf not write past nul Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 13/28] vsprintf: Start consolidating printf_spec handling Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 14/28] vsprintf: Refactor resource_string() Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 15/28] vsprintf: Refactor fourcc_string() Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 16/28] vsprintf: Refactor ip_addr_string() Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 17/28] vsprintf: Refactor mac_address_string() Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 18/28] vsprintf: time_and_date() no longer takes printf_spec Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 19/28] vsprintf: flags_string() " Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 20/28] vsprintf: Refactor device_node_string, fwnode_string Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 21/28] vsprintf: Refactor hex_string, bitmap_string_list, bitmap_string Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 22/28] Input/joystick/analog: Convert from seq_buf -> printbuf Kent Overstreet
2022-05-19 20:04   ` Andy Shevchenko
2022-05-19 20:19     ` Kent Overstreet
2022-05-19 21:09       ` Andy Shevchenko
2022-05-19 17:24 ` [PATCH v2 23/28] mm/memcontrol.c: Convert to printbuf Kent Overstreet
2022-05-20  7:59   ` Michal Hocko
2022-05-19 17:24 ` [PATCH v2 24/28] clk: tegra: bpmp: " Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 25/28] tools/testing/nvdimm: " Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 26/28] powerpc: " Kent Overstreet
2022-05-19 17:24   ` Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 27/28] x86/resctrl: " Kent Overstreet
2022-05-19 17:24 ` [PATCH v2 28/28] PCI/P2PDMA: " Kent Overstreet
2022-05-26 14:44 ` [PATCH v2 00/28] Printbufs (now with more printbufs!) Petr Mladek
2022-05-26 15:11   ` Kent Overstreet

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.