All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v5 00/28] dynamic debug diet plan
@ 2021-05-11 18:50 Jim Cromie
  2021-05-11 18:50 ` [RFC PATCH v5 01/28] dyndbg: avoid calling dyndbg_emit_prefix when it has no work Jim Cromie
                   ` (28 more replies)
  0 siblings, 29 replies; 37+ messages in thread
From: Jim Cromie @ 2021-05-11 18:50 UTC (permalink / raw)
  Cc: linux-mm, Jim Cromie

DYNAMIC_DEBUG has extra weight/memory in its data table/section; its
(module,filename,function) columns have ordered, repeating data
(90%,55%,45%), and is highly compressible (~110/300) with simple RLE.

On my i7 laptop, the compressible chunk is ~70kb, This patchset
prepares for compression, but doesn't try it; RFC.  Using that RLE
compression estimate, we could save ~45kb; Id hope for better with ZSTD.

Series Overview:

1st, split the struct _ddebug & __dyndbg elf section into 2, moving
compressible fields into their own section/array/block.  A temporary
site pointer connects the 2 halves of the composite callsite, it will
be obsoleted later, after we verify our replacement against it, we can
drop the .site pointer.

table change:
 from:	[ key,mod,func,filenm,fmt,ln,flg ]
 into:	[ key,fmt,ln,flg,site-> ]	[ mod,func,filenm ]

2nd, make the 'site' data optional.  The "module:function:line"
log-message prefix is fundamentally an optional decoration, if we can
do without it, we simplify codepath, and we could drop the storage in
those cases, possibly reducing memory footprint.

 into:	[ key,fmt,ln,flg,site->? ]  0
 
Then things get more interesting:

3rd, make kernel/module handle "__dyndbg_sites" ELF section (which was
added in 1) as is already done for "__dyndbg".

Hide/replace ->site with site_get/_put api
this will let us retrieve site info from compressed storage.

Add _index.
gives us the fixed offset from __dyndbg[N] to __dyndbg[0].

 into:	[ key,fmt,ln,flg,_index,site->? ]  0

Add table/header record-pair.
These 2 records are created into ".gnu.linkonce.dyndbg*" sections.
The linker script places these 2 sections in front of their respective
"__dyndbg*" sections.
So this header-pair becomes __dyndbg[0], __dyndbg_sites[0].
we can use __dyndbg[0]->site[N] to get the site info.

module.lds.h - insert ".gnu.linkonce.dyndbg*" sections into "__dyndbg*".
Without this, headers arent part of the sections that kernel/module loads.

validate ddebug_site_get() invariants.
prove that our indirection to ->site[N] is correct.
BUG_ON uses survived 0-day tests.
they go away with !SITE_CHK

 into:
    0: 	[ ...,_index,site-> ]		--->  0:[ ... ]
    	  	^
  ..N:  [ key,fmt,ln,flg,_index ]	      N:[ ... ]

specialize header from _ddebug, keep header.site, drop _ddebug.site
RFC: needs refinement, better type choices?


Status:
  recent revs passed 0day compile grind, including BUG_ONs
  I got one KASAN report, quick reproduction failed, none more recently
  memory footprint is same as master.

Whats Next ? Compression: RFC !!!

POC: could compress during __init, decompress on-demand.  Doing this
would give something to decompress, to build out that code.

ISTM Compression during build is best, but targets are unclear:
initrd, initramfs, cpio, FW-blob all seem suitable at some level, but
so does (ro) zram & zswap.  How should I think about this ?

Also, I understand that support exists for compressed elf sections, I
dunno if/how kernel uses it currently, which would considerably ease
this.  Builtin __dyndbg_site data is in .data, probably needs to be
moved to a separate elf section to get generic tool support for
compressed sections.

It would be nice if a compressed "__dyndbg_sites" elf section could be
loaded by unchanged kernel/module.c.  A magic number in the attached
memory block could distinguish it from the current elf block.  There
is room in the 2 header records for new private data; we could store
decompression contexts there while iterating thru a block.

Decompression - a few use-cases:

= for builtins, each loadable module:
1- stream, for `cat control` etc.
   these are 1 visit and forget
2- `module foo +mfp > control` - enable contiguous blocks w decorations
3- pr_debug - semi-random access - by (ptr - _index)
   [0-5k] for builtin pr-debugs, [0-20] for most loadable modules
   _index is 16 bit currently

Simplest, minimum-memory strategy is late-fetch; to wait until a
pr_debug is actually called, then check flags before fetching the
site-rec, and save it to a hash on modname+_index (and delete on -p).
Without the save, it works for (1) too.

The only downside with late-fetch is that during pr_debug, a 1st fetch
of site-info maybe cant come from io/zswap without locking/latency
concerns.  A forced-prefetch ala (2) with a new flag '!' could work
around this, but might look like a wart.

So thats it. I hope its clear and concise.

Jim Cromie (28):

trivial cleanup:
  dyndbg: avoid calling dyndbg_emit_prefix when it has no work
  dyndbg: drop uninformative vpr_info

split to 2 vectors of callsite:
  dyndbg: split struct _ddebug's display fields to new _ddebug_site
  dyndbg: __init iterate over __dyndbg & __dyndbg_site in parallel

make site info optional:
  dyndbg: refactor part of ddebug_change to ddebug_match_site
  dyndbg: accept null site in ddebug_match_site
  dyndbg: hoist ->site out of ddebug_match_site
  dyndbg: accept null site in ddebug_change
  dyndbg: accept null site in dynamic_emit_prefix
  dyndbg: accept null site in ddebug_proc_show
  dyndbg: refactor ddebug_alter_site out of ddebug_change
  dyndbg: allow deleting site info via control interface

interesting: 
  dyndbg+module: expose ddebug_sites to modules
  dyndbg: add ddebug_site(_get|_put) abstraction
  dyndbg: ddebug_add_module avoid adding empty modules
  dyndbg: add _index to struct _ddebug
  dyndbg: prevent build bugs via -DNO_DYNAMIC_DEBUG_TABLE
  dyndbg: RFC - DEFINE_DYNAMIC_DEBUG_TABLE
  dyndbg: RFC handle __dyndbg* sections in module.lds.h
  dyndbg: ddebug_add_module() handle headers.
  dyndbg: validate ddebug_site_get invariants
  dyndbg: fix NULL deref after deleting sites
  dyndbg: dont show header records in control
  dyndbg: make site pointer and checks on it optional (not quite)
  dyndbg: swap WARN_ON for BUG_ON see what 0-day says
  dyndbg: fixup protect header when deleting site
  dyndbg: unionize _ddebug*_headers with struct _ddebug*
  dyndbg: drop _ddebug.site pointer

 arch/arm/boot/compressed/Makefile     |   2 +
 arch/sparc/vdso/Makefile              |   2 +
 arch/x86/boot/compressed/Makefile     |   1 +
 arch/x86/entry/vdso/Makefile          |   3 +
 arch/x86/purgatory/Makefile           |   1 +
 drivers/firmware/efi/libstub/Makefile |   3 +-
 include/asm-generic/module.lds.h      |  12 +-
 include/asm-generic/vmlinux.lds.h     |  24 +-
 include/linux/dynamic_debug.h         | 135 ++++++++--
 kernel/module-internal.h              |   1 +
 kernel/module.c                       |   9 +-
 lib/dynamic_debug.c                   | 363 +++++++++++++++++++-------
 12 files changed, 437 insertions(+), 119 deletions(-)

-- 
2.31.1



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

end of thread, other threads:[~2021-05-12 22:25 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-11 18:50 [RFC PATCH v5 00/28] dynamic debug diet plan Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 01/28] dyndbg: avoid calling dyndbg_emit_prefix when it has no work Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 02/28] dyndbg: drop uninformative vpr_info Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 03/28] dyndbg: split struct _ddebug's display fields to new _ddebug_site Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 04/28] dyndbg: __init iterate over __dyndbg & __dyndbg_site in parallel Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 05/28] dyndbg: refactor part of ddebug_change to ddebug_match_site Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 06/28] dyndbg: accept null site in ddebug_match_site Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 07/28] dyndbg: hoist ->site out of ddebug_match_site Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 08/28] dyndbg: accept null site in ddebug_change Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 09/28] dyndbg: accept null site in dynamic_emit_prefix Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 10/28] dyndbg: accept null site in ddebug_proc_show Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 11/28] dyndbg: refactor ddebug_alter_site out of ddebug_change Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 12/28] dyndbg: allow deleting site info via control interface Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 13/28] dyndbg+module: expose ddebug_sites to modules Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 14/28] dyndbg: add ddebug_site(_get|_put) abstraction Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 15/28] dyndbg: ddebug_add_module avoid adding empty modules Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 16/28] dyndbg: add _index to struct _ddebug Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 17/28] dyndbg: prevent build bugs via -DNO_DYNAMIC_DEBUG_TABLE Jim Cromie
2021-05-11 18:50   ` Jim Cromie
2021-05-12 14:55   ` Ard Biesheuvel
2021-05-12 14:55     ` Ard Biesheuvel
2021-05-12 14:55     ` Ard Biesheuvel
2021-05-12 18:03     ` jim.cromie
2021-05-12 18:03       ` jim.cromie
2021-05-12 18:03       ` jim.cromie
2021-05-11 18:50 ` [RFC PATCH v5 18/28] dyndbg: RFC - DEFINE_DYNAMIC_DEBUG_TABLE Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 19/28] dyndbg: RFC handle __dyndbg* sections in module.lds.h Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 20/28] dyndbg: ddebug_add_module() handle headers Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 21/28] dyndbg: validate ddebug_site_get invariants Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 22/28] dyndbg: fix NULL deref after deleting sites Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 23/28] dyndbg: dont show header records in control Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 24/28] dyndbg: make site pointer and checks on it optional (not quite) Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 25/28] dyndbg: swap WARN_ON for BUG_ON see what 0-day says Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 26/28] dyndbg: fixup protect header when deleting site Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 27/28] dyndbg: unionize _ddebug*_headers with struct _ddebug* Jim Cromie
2021-05-11 18:50 ` [RFC PATCH v5 28/28] dyndbg: RFC drop _ddebug.site pointer Jim Cromie
2021-05-12 22:08 ` Fwd: [RFC PATCH v5 00/28] dynamic debug diet plan jim.cromie

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.