]> sourceware.org Git - systemtap.git/log
systemtap.git
3 years agoPR27031 stapbpf fix 'missing conversion specifier' in println()
Serhei Makarov [Wed, 3 Mar 2021 18:03:15 +0000 (13:03 -0500)]
PR27031 stapbpf fix 'missing conversion specifier' in println()

The synthesized format string was using '%lld' for integers
which is not actually handled by staptree.cxx print_format::string_to_components.

3 years agohtml-docs: switch to htlatex from latex2html
Frank Ch. Eigler [Tue, 2 Mar 2021 02:07:47 +0000 (21:07 -0500)]
html-docs: switch to htlatex from latex2html

latex2html has been supplanted by htlatex, a more native latex->html
renderer.  Switch the update-htmldocs file etc. to use it to generate
html for the langref and tutorial documents.

3 years agoPR27392: tweak uconversions.stp markup for html extraction
Frank Ch. Eigler [Tue, 2 Mar 2021 00:56:31 +0000 (19:56 -0500)]
PR27392: tweak uconversions.stp markup for html extraction

Just needed to move the runtime-conditional before the structured docs.

Reported-by: Dan Streetman <ddstreet@canonical.com>
3 years agoman error::pass5: document lockdown escapes
Frank Ch. Eigler [Tue, 2 Mar 2021 00:50:02 +0000 (19:50 -0500)]
man error::pass5: document lockdown escapes

Give some alternative advice for secureboot/lockdown machines about
how to turn off those security measures, based on bpftrace's
INSTALL.md.

3 years agoFix misspellings in stap manpage.
Stan Cox [Thu, 25 Feb 2021 21:56:07 +0000 (16:56 -0500)]
Fix misspellings in stap manpage.

3 years agostapbpf PR25177/27032 review tweax: redundant variables, whitespace
Serhei Makarov [Thu, 25 Feb 2021 20:15:52 +0000 (15:15 -0500)]
stapbpf PR25177/27032 review tweax: redundant variables, whitespace

1. Merge stapbpf.cxx log_level with verbose.
2. Alias stapbpf.cxx module_name to __name__ (module_name is better).
3. Put back double-space in usage messages.

3 years agostapbpf PR25177/27032: handle process exit (SIGCHLD)
Serhei Makarov [Thu, 25 Feb 2021 16:54:00 +0000 (11:54 -0500)]
stapbpf PR25177/27032: handle process exit (SIGCHLD)

* stapbpf.cxx (target_pid_failed_p): New variable.
(sigchld): New function, handle child process exit and signal bpf program.
(main): Set up and disable SIGCHLD handler and propagate failure exit.

3 years agostapbpf PR25177/27032: link start_cmd() into stapbpf, launch the process
Serhei Makarov [Wed, 24 Feb 2021 19:48:41 +0000 (14:48 -0500)]
stapbpf PR25177/27032: link start_cmd() into stapbpf, launch the process

This patch takes care of launching the process, next patch must take care
of listening for the process to finish running.

TODO some redundant declarations in stapbpf.cxx should be merged.

TODO in general staprun uses much nicer print functions,
should stapbpf borrow them too?

* buildrun.cxx (make_bpf_run_command): pass s.cmd to the stapbpf command.

* stapbpf/stapbpf.cxx (verbose): TODO redundant decl for start_cmd.c.
(read_stdin): TODO unused decl for start_cmd.c.
(__name__): TODO redundant decl for start_cmd.c.
(target_pid): now shared with C code in start_cmd.c.
(target_cmd): now shared with C code in start_cmd.c.
(eprintf): decl for start_cmd.c.
(start_cmd): decl for start_cmd.c.
(resume_cmd): decl for start_cmd.c.
(load_bpf_file): populate TODO redundant __name__ decl.
(usage): add '-c' option.
(main): add '-c' option, use start_cmd()/resume_cmd() to launch the process.
* stapbpf/bpfinterp.h (target_pid): now shared with C code in start_cmd.c.

* stapbpf/Makefile.{am,in}: add ../staprun/start_cmd.c to sources.

3 years agoPR25177/27032 staprun: factor out start_cmd() for stapbpf usage
Serhei Makarov [Tue, 23 Feb 2021 21:12:47 +0000 (16:12 -0500)]
PR25177/27032 staprun: factor out start_cmd() for stapbpf usage

Most/all of the start_cmd() code in stap run should apply
to stapbpf '-c' support as well. Factor it out into an object
file that can be linked by both staprun and stapbpf.

* staprun/start_cmd.c: New file to be linked into both staprun and stapbpf.
* staprun/staprun.h: Declare functions in start_cmd.c.
* common.c (closefrom): Moved to start_cmd.c.
(OPEN_MAX): Moved to start_cmd.c.
* mainloop.c (signal_usr1): Moved to start_cmd.c.
(start_cmd): Moved to start_cmd.c.
(stp_main_loop): Move signal code to resume_cmd() in start_cmd.c.

* staprun/Makefile.{am,in}: add start_cmd.c.

3 years agosystemtap.spec: for testsuite, tweak 32-bit glibc recommendation
Frank Ch. Eigler [Tue, 23 Feb 2021 15:05:22 +0000 (10:05 -0500)]
systemtap.spec: for testsuite, tweak 32-bit glibc recommendation

For testing 32-bit cross-arch probing, we need a 32-bit glibc devel
environment.  Use a more modern way of asking for it.

Suggested-by: Florian Weimer <fweimer@redhat.com>
3 years agostapbpf PR27030 WIP: user_long() test with compiled program
Serhei Makarov [Mon, 22 Feb 2021 16:53:24 +0000 (11:53 -0500)]
stapbpf PR27030 WIP: user_long() test with compiled program

3 years agousage message: explain [man FOO] notation right there
Frank Ch. Eigler [Sat, 20 Feb 2021 00:37:30 +0000 (19:37 -0500)]
usage message: explain [man FOO] notation right there

Maybe hinting right during the naked stap startup will work!

% stap
A script must be specified.
Try '-i' for building a script interactively.
Try '--help' for more information. [man stap]
A message like [man foo] means for more info, run % man foo

3 years agosystemtap.spec: bump minimum elfutils to 0.179
Frank Ch. Eigler [Fri, 19 Feb 2021 23:27:48 +0000 (18:27 -0500)]
systemtap.spec: bump minimum elfutils to 0.179

We haven't tested with a pre-debuginfod version in some time.

3 years agoRHBZ1930973 part: .spec: add elfutils-devel dependency
Frank Ch. Eigler [Fri, 19 Feb 2021 23:22:53 +0000 (18:22 -0500)]
RHBZ1930973 part: .spec: add elfutils-devel dependency

Since TLS-related work, building modules for the dyninst backend
requires elfutils headers.  Add them to the .spec for the -devel
subpackage.

Reported-By: Jan Pokorný <fedora@t.poki.me>
3 years agoCorrect the with_debuginfod macro in systemtap.spec.
William Cohen [Wed, 17 Feb 2021 17:53:17 +0000 (12:53 -0500)]
Correct the with_debuginfod macro in systemtap.spec.

3 years agosystemtap.spec: buildrequire elfutils debuginfod client library
Frank Ch. Eigler [Wed, 10 Feb 2021 20:42:53 +0000 (15:42 -0500)]
systemtap.spec: buildrequire elfutils debuginfod client library

... but now with the appropriate conditional and %configure clause,
so as to reject misconfiguration.

3 years agosystemtap.spec: buildrequire elfutils debuginfod client library
Frank Ch. Eigler [Wed, 10 Feb 2021 20:42:53 +0000 (15:42 -0500)]
systemtap.spec: buildrequire elfutils debuginfod client library

... after all, this is needed for buildid based probing.

3 years agoNEWS: Mention enumerators
Stan Cox [Mon, 8 Feb 2021 16:59:02 +0000 (11:59 -0500)]
NEWS: Mention enumerators

stapref.1: Mention @var("varname","module")

3 years agoPR27361: make --dump-functions work again
Frank Ch. Eigler [Sun, 7 Feb 2021 13:38:35 +0000 (08:38 -0500)]
PR27361: make --dump-functions work again

Part of the work in commit 88db3a197 (version 4.3)
caused a regression with --dump-functions, wherein
optimizers would eliminate uncalled functions, even
in dump mode.  We now suppress this again and extend
the test case to look for a few more functions.

3 years agoPR27361 part 1: enable typequery result memoization & operation on linux 5.11
Frank Ch. Eigler [Sun, 7 Feb 2021 02:09:24 +0000 (21:09 -0500)]
PR27361 part 1: enable typequery result memoization & operation on linux 5.11

Linux 5.11 rejects previous kmod_typequery .c files because they don't
have a MODULE_LICENSE bit.  Here, stap tries and tries and tries
building kmod_typequery files, up to thousands (!).  We solve the
first by adding the MODULE_LICENSE.  We solve the second by memoizing
typequery build results (whether they succeed or fail) in the
systemtap_session object.

3 years agodyninst runtime: adapt to stp_rwlock_t change
Frank Ch. Eigler [Sat, 6 Feb 2021 14:28:16 +0000 (09:28 -0500)]
dyninst runtime: adapt to stp_rwlock_t change

commit 6d6795f490 introduced stp_rwlock_t for stap script globals.
The dyninst runtime needs the same (an alias to pthread_rwlock_t).

3 years agostp_utrace: fix widespread utrace struct use-after-free issues
Sultan Alsawaf [Sat, 6 Feb 2021 04:36:01 +0000 (20:36 -0800)]
stp_utrace: fix widespread utrace struct use-after-free issues

The utrace structs suffer from a number of use-after-free scenarios,
which cause panics and other mayhem. They can be used in queued-up task
workers after being freed, fetched from task_utrace_struct() and quickly
freed after while still in use, or fetched from task_utrace_struct()
after having already been freed. And utrace->task can be used after the
task struct it points to is freed.

A number of changes are made to remedy the widespread use-after-free
issues. Firstly, utrace structs now have a reference counter to protect
them from being abruptly freed while in use. This guarantees that a
utrace struct will only be freed after everything using it, including
task workers, is finished.

The task struct assigned to each utrace struct is now pinned as well,
making all utrace->task usage safe while the utrace struct is alive.

When utrace exits, all of the possible utrace workers are now canceled
instead of only some of them. Although this mass cancel isn't necessary
now, it's good to do so to speed up utrace exit so that exiting doesn't
require waiting for all of the in-flight workers to finish running. We
are also guaranteed that utrace->task will be valid if the utrace struct
has a positive reference count since the task struct is pinned.

To accommodate for the reference counting, rename get_utrace_bucket() to
find_utrace_bucket() since it doesn't grab any references, and rename
task_utrace_struct() to get_utrace_struct() to indicate that it grabs a
reference on the returned utrace struct.

The utrace_flags member of the utrace struct is reduced from a long to
an int to make room for an atomic reference counter without increasing
the size of the utrace struct. This is fine since there aren't enough
utrace flags to require the use of a long.

3 years agostp_utrace: always assume in_atomic() in utrace_report_death()
Sultan Alsawaf [Fri, 5 Feb 2021 22:07:17 +0000 (14:07 -0800)]
stp_utrace: always assume in_atomic() in utrace_report_death()

As we've established in the past, in_atomic() only works when PREEMPT is
enabled. On non-PREEMPT kernels, in_atomic() will return false even when
used inside a spin-locked critical section. Therefore, in order to make
utrace_report_death() safe on all configurations, always use a task
worker to perform the report work.

3 years agostp_utrace: remove useless RCU read locks
Sultan Alsawaf [Fri, 5 Feb 2021 21:22:16 +0000 (13:22 -0800)]
stp_utrace: remove useless RCU read locks

These RCU read locks don't actually protect anything. The task struct
pointer is not actually dereferenced in get_utrace_lock(), and the RCU
read lock in utrace_reset() serves no purpose at all.

3 years agostp_utrace: remove outdated utrace_cleanup_lock comment
Sultan Alsawaf [Fri, 5 Feb 2021 21:09:16 +0000 (13:09 -0800)]
stp_utrace: remove outdated utrace_cleanup_lock comment

This lock doesn't exist anymore.

3 years agoAdd support for accessing enumerators
Stan Cox [Fri, 5 Feb 2021 21:20:22 +0000 (16:20 -0500)]
Add support for accessing enumerators

Adds dwarf_get_enum, similar to dwarf_getscopevar, except search for a matching
DW_TAG_enumerator.  If a scoped variable then use the enumerator die
and attributes; translate_location  will convert to a constant.  If a
struct member then translate_components will fold the component locations then
use translate_location.

3 years agoruntime: make probe locks rt-safe
Sultan Alsawaf [Thu, 4 Feb 2021 22:09:30 +0000 (14:09 -0800)]
runtime: make probe locks rt-safe

The only safe alternative to rw locks on PREEMPT_RT is a raw spin lock.

Extend the stp lock helper API to provide rt-safe rw locks for probe
lock use.

3 years agoalloc: use rt-safe spin lock for DEBUG_MEM
Sultan Alsawaf [Thu, 4 Feb 2021 22:07:29 +0000 (14:07 -0800)]
alloc: use rt-safe spin lock for DEBUG_MEM

Use the stp_spin_lock macros to use the correct lock primitive when
PREEMPT_RT is in use.

3 years agostapbpf PR27030 WIP :: new bpf/uconversions.stp tapset
Serhei Makarov [Wed, 3 Feb 2021 15:36:33 +0000 (10:36 -0500)]
stapbpf PR27030 WIP :: new bpf/uconversions.stp tapset

Tentative version of user_long_error() for bpf, needs more testing.
NEXT, the __bpf_probe_read_user_error() helper can be used to implement
the other user_{char,short,int} tapset functions.

This patch starts a new practice for tapset layout for tapset functions
that have a lkm/dyninst implementation and a separate bpf implementation:

- The lkm/dyninst implementation is placed in the toplevel tapset/
  directory, surrounded by %( runtime != "bpf" %? ... %).

- The bpf implementation is placed in the tapset/bpf/ directory.

Once applied to the rest of the tapsets, this practice should work to
eliminate the current proliferation of two-way
%( runtime != "bpf" %? implementation1 %: implementation2 %)
conditionals in the runtime code, and allow bpf versions of numerous
remaining tapset functions to be implemented and cleanly placed
into separate files under bpf/.

3 years agotapset/bpf fixups, esp. signed comparison
Serhei Makarov [Tue, 2 Feb 2021 23:59:06 +0000 (18:59 -0500)]
tapset/bpf fixups, esp. signed comparison

The substantive bugfix is to use signed opcodes for $rc<0 type comparisons.
Threw in some other tweaks/notes in the process.

3 years agoBug: delete_module() syscall might get interrupted under load.
Yichun Zhang (agentzh) [Tue, 2 Feb 2021 22:05:00 +0000 (14:05 -0800)]
Bug: delete_module() syscall might get interrupted under load.

staprun might fail to delete modules and leave ko in the system:

  $ sudo lsmod|grep stap
  stap_2eb3039808b647e990825b99fb1f9b6_18830   221184  0
  stap_eee9b566240fbeb1194347a571ccd68_17219   208896  0

Now we try up to 5 times for the delete_module() syscall in staprun with
a growing sleep interval between successive attempts upon the EINTR
error.

3 years agoTapset: aarc64: register()/u_register(): support w* registers
Yichun Zhang (agentzh) [Mon, 1 Feb 2021 22:51:22 +0000 (14:51 -0800)]
Tapset: aarc64: register()/u_register(): support  w* registers

3 years agobuildrun: stop adding our own -Wframe-larger-than=XYZ CFLAGS
Frank Ch. Eigler [Mon, 1 Feb 2021 19:49:32 +0000 (14:49 -0500)]
buildrun: stop adding our own -Wframe-larger-than=XYZ CFLAGS

linux kbuild has included a CONFIG_FRAME_WARN option for some time,
which adds a -Wframe-larger-than=$(...) CFLAGS.  Until this patch,
systemtap used to add one of its own, on the theory that our generated
code really should not have large stack frames.  This is partly
assured by use of preallocated per-cpu "struct context" structures, so
our warning was a belt-and-suspenders protection.  However, this lower
limit is not sufficient any more.

On rawhide (linux 5.11, gcc 11), KASAN etc. makes the stack-frame of
the unwind_frame() function about 700 bytes, which is easily within
the CONFIG_FRAME_WARN but larger than 512.  We now just defer to
kbuild's wisdom.

3 years agostapbpf assembler bugfix :: stol in parse_imm should parse all bases
Serhei Makarov [Mon, 1 Feb 2021 19:08:54 +0000 (14:08 -0500)]
stapbpf assembler bugfix :: stol in parse_imm should parse all bases

Other places in the assembler pass base=0 to allow octal/hex bases.
This one didn't which led to hex immediate arguments being zeroed out.

3 years agostap.bpf optional debugging aid :: show location of bpfasm-embeddedcode
Serhei Makarov [Mon, 1 Feb 2021 18:06:05 +0000 (13:06 -0500)]
stap.bpf optional debugging aid :: show location of bpfasm-embeddedcode

3 years agoAdd CONFIG_COMPAT 32-bit support for aarch64 and powerpc
William Cohen [Mon, 1 Feb 2021 03:16:49 +0000 (22:16 -0500)]
Add CONFIG_COMPAT 32-bit support for aarch64 and powerpc

The aarch64 and powerpc kernels may be built with support for 32-bit
user-space applications.  On Fedora 33 the aarch64 kernel is
configured with CONFIG_COMPAT enabled.  Needed to provide some support
in _stp_is_compat_task2 for the aarch64.  The Fedora 33 ppc64le
kernels by default do not have CONFIG_COMPAT enabled, but included
similar check in there for powerpc in case locally built kernels
enable it.

3 years agoPR27273: port to linux 5.11, kretprobes - unwinding
Frank Ch. Eigler [Fri, 29 Jan 2021 20:54:42 +0000 (20:54 +0000)]
PR27273: port to linux 5.11, kretprobes - unwinding

Missed one.

3 years agoscripts/spin-rawhide: allow multiple spins in a day
Frank Ch. Eigler [Fri, 29 Jan 2021 20:57:53 +0000 (15:57 -0500)]
scripts/spin-rawhide: allow multiple spins in a day

Extend the rawhide rpm Release: header to include HHMM,
not just YYYYmmdd.

3 years agoPR27273: port to linux 5.11, kretprobes
Frank Ch. Eigler [Fri, 29 Jan 2021 20:54:42 +0000 (20:54 +0000)]
PR27273: port to linux 5.11, kretprobes

Linux commit d741bf41d7c changed how kretprobe_instances can
find their kretprobes.  Adapt with an autoconf and wrapper
function.

3 years agoPR27273: port to linux 5.11
Frank Ch. Eigler [Fri, 29 Jan 2021 03:12:48 +0000 (22:12 -0500)]
PR27273: port to linux 5.11

Main change is removal/movement of TIF_IA32 in linux commit ff170cd05953
and nearby.  Now using single a central wrapper _stp_is_compat_task() and
_stp_is_compat_task2() functions, instead of sprinkling
test_tsk_thread_flag(...) around the code base.

Also, suppressing CONFIG_DEBUG_INFO_BTF_MODULES generation for stap
modules, for diagnostic noise reduction.

3 years agoPR27251: support buildid probing on --x--x--x perm binaries
Frank Ch. Eigler [Tue, 26 Jan 2021 16:09:53 +0000 (11:09 -0500)]
PR27251: support buildid probing on --x--x--x perm binaries

We need to delegate to executable searches to debuginfod for binaries
that exist on the local system, but are unreadable.  Correcting
util.cxx access(3) checks from X_OK -> R_OK to avoid relying on
unreadable links/binaries, which results in stap being unable to probe
them at all.  This can come up for probing some setuid programs.

3 years agoman/stap.1: add example about composing macros & embedded-c expressions
Craig Ringer [Mon, 25 Jan 2021 22:55:59 +0000 (17:55 -0500)]
man/stap.1: add example about composing macros & embedded-c expressions

3 years agobpf-translate.cxx WIP bugfix for PR27030: delay adjusted_toks deallocation
Serhei Makarov [Mon, 25 Jan 2021 18:29:58 +0000 (13:29 -0500)]
bpf-translate.cxx WIP bugfix for PR27030: delay adjusted_toks deallocation

Identified more diagnostic data (adjusted BPF assembler tokens)
that the BPF translator was deallocating prematurely on exception throw.
For now, fix the problem by keeping deallocation disabled
entirely. Only other solution I can think of is to catch and re-throw
any semantic error, copying the adjusted token at that point to
keep it from being deallocated.

3 years agoPR27067: set procfs traceNN files' uid/gid too
Frank Ch. Eigler [Sun, 24 Jan 2021 19:45:54 +0000 (14:45 -0500)]
PR27067: set procfs traceNN files' uid/gid too

commit e3d03db828 neglected to include the proper calls to set the
procfs traceNN files to the correct uid/gid ownership.  With those
files left as uid/gid=0/0, stapio running with a user with
stapusr/stapdev privileges couldn't fopenat() those files.  Now they
can again.  This problem became obvious after commit 4706ab3ca5c0,
which makes STAP_TRANS_PROCFS the default.

3 years agobugfix: unwinder: expr: DW_OP_push*: we forgot to push the result to the dwarf stack.
Yichun Zhang (agentzh) [Fri, 22 Jan 2021 05:29:32 +0000 (21:29 -0800)]
bugfix: unwinder: expr: DW_OP_push*: we forgot to push the result to the dwarf stack.

Most of the assembly routines in OpenSSL's libcrypto would produce unwinder failures
and the warning "WARNING: DWARF expression stack underflow in CFI" due to this bug.

3 years agoruntime: utilize relay subbufs as much as possible
Sultan Alsawaf [Fri, 22 Jan 2021 23:19:33 +0000 (15:19 -0800)]
runtime: utilize relay subbufs as much as possible

The relay subbufs used for printing are used very inefficiently, causing
print messages to be frequently dropped. The cause for this inefficiency
is that every time a print flush occurs, the current subbuf is switched
out even if it isn't filled. We can't wait for a subbuf to fill up
before switching it out either, or messages will be delayed.

To remedy this, we instead check to see if there's any data in any
subbuf and use that as an indicator to staprun to tell if there's data
available to read. Then when staprun attempts to read the data out, we
can switch out the current subbuf if it has data in it. This lets us
squeeze out every bit of storage from the subbufs.

Any print drops experienced after this patch should be fixed by
increasing the subbuf count (_stp_nsubbufs).

3 years agoruntime: default to using procfs for the transport
Sultan Alsawaf [Fri, 22 Jan 2021 18:46:22 +0000 (10:46 -0800)]
runtime: default to using procfs for the transport

Using debugfs for the transport results in a multitude of bugs when
running stap modules in parallel. The bugs include debugfs outright
failing, warnings hit in fs/inode.c, and kernel panics. Since procfs has
been more stable over the years, default to using it for the transport
instead of debugfs. Using procfs resolves the issues faced with debugfs.

3 years agostp_utrace: remove unneeded RCU-freed field from struct utrace
Sultan Alsawaf [Wed, 20 Jan 2021 20:55:40 +0000 (12:55 -0800)]
stp_utrace: remove unneeded RCU-freed field from struct utrace

We're only using RCU on struct utrace in order to allow non-blocking
iteration through the hashlists. RCU is not used to manage the lifetime
of utrace structs; once a utrace struct is ready to be freed, nothing
will try to grab it anymore, so we can remove the unneeded utrace->freed
check.

3 years agostp_utrace: remove kmem cache usage
Sultan Alsawaf [Wed, 20 Jan 2021 20:51:19 +0000 (12:51 -0800)]
stp_utrace: remove kmem cache usage

Some kernels appear to have trouble registering the same kmem_cache in
parallel, resulting in the following error as well as some other mayhem,
such as staprun hangs and kernel freezes:
sysfs: cannot create duplicate filename '/kernel/slab/:0000144'

This occurs when stap modules are registered in parallel with one
another.

The justification for using kmem caches in utrace is that the utrace
struct sizes are not powers of 2, and a lot of them can be allocated, so
leaving them to the kernel's default kmem caches can waste quite a bit
of memory. However, this is only a problem for the utrace struct, and
not really the utrace_engine struct, as the utrace_engine struct is 56
bytes on 64-bit, and can be allocated by the kernel's internal 64-byte
kmem cache with only 8 bytes wasted per allocation.

The same cannot be said for the utrace struct, since it's 144 bytes. It
would therefore be allocated from the 256-byte kmem cache, resulting in
112 bytes wasted per allocation. We can remedy this by reusing existing
memory in the struct for the 16-byte RCU callback head, bringing the
overall struct size down to 128 bytes and thus eliminating the need for
a kmem cache. This is safe because the reused struct members are no
longer used once the struct is ready to be freed.

This also eliminates a pesky rcu_barrier() we no longer required.

3 years agosystemtap-service onboot: Skip updating the bootloader
Martin Cermak [Wed, 20 Jan 2021 21:09:49 +0000 (22:09 +0100)]
systemtap-service onboot: Skip updating the bootloader

It shows up that just modifying the default initrd is good enough,
no need to call kernel-install or new-kernel-pkg.  This speeds up
the systemtap-service onboot operation.

3 years agoRevert "stp_utrace: remove kmem cache usage"
Sultan Alsawaf [Tue, 19 Jan 2021 23:39:14 +0000 (15:39 -0800)]
Revert "stp_utrace: remove kmem cache usage"

This reverts commit 23ef716aa40abe6473497f7d198003d0f199df58.

This was pushed on accident. :(

3 years agostp_utrace: add missing rcu_read_unlock() in get_utrace_lock() error path
Sultan Alsawaf [Tue, 19 Jan 2021 23:36:24 +0000 (15:36 -0800)]
stp_utrace: add missing rcu_read_unlock() in get_utrace_lock() error path

This bug was introduced in 619f6940d ("PR26697: fix NULL pointer deref
in get_utrace_lock()), which was my first stap commit, and subsequently
where this project started going downhill as a result.

3 years agostp_utrace: remove kmem cache usage
Sultan Alsawaf [Tue, 19 Jan 2021 23:00:50 +0000 (15:00 -0800)]
stp_utrace: remove kmem cache usage

Some kernels appear to have trouble registering the same kmem_cache in
parallel, resulting in the following error as well as some other mayhem,
such as staprun hangs and kernel freezes:
sysfs: cannot create duplicate filename '/kernel/slab/:0000144'

This occurs when stap modules are registered in parallel with one
another.

The justification for using kmem caches in utrace is that the utrace
struct sizes are not powers of 2, and a lot of them can be allocated, so
leaving them to the kernel's default kmem caches can waste quite a bit
of memory. However, this is only a problem for the utrace struct, and
not really the utrace_engine struct, as the utrace_engine struct is 56
bytes on 64-bit, and can be allocated by the kernel's internal 64-byte
kmem cache with only 8 bytes wasted per allocation.

The same cannot be said for the utrace struct, since it's 144 bytes. It
would therefore be allocated from the 256-byte kmem cache, resulting in
112 bytes wasted per allocation. We can remedy this by reusing existing
memory in the struct for the 16-byte RCU callback head, bringing the
overall struct size down to 128 bytes and thus eliminating the need for
a kmem cache. This is safe because the reused struct members are no
longer used once the struct is ready to be freed.

This also eliminates a pesky rcu_barrier() we no longer required.

3 years agoIgnore link map entries with no name.
Stan Cox [Mon, 18 Jan 2021 18:53:09 +0000 (13:53 -0500)]
Ignore link map entries with no name.

Do not attempt to add entries to tls_link_map_name if there is no name
for the entry in the link map.

3 years agoPR27185: conversions.exp test enhancements
Craig Ringer [Sat, 16 Jan 2021 00:08:55 +0000 (19:08 -0500)]
PR27185: conversions.exp test enhancements

I've adjusted the stress tests referenced in
systemtap.stress/conversions.exp to make them more concise and allow
all the test definitions to be shared across each variant.

3 years agotransport: procfs: fix transposed procfs removal ordering
Sultan Alsawaf [Fri, 15 Jan 2021 02:43:48 +0000 (18:43 -0800)]
transport: procfs: fix transposed procfs removal ordering

In order to avoid a use-after-free bug, we must remove the pde before
doing the path_put(), even though this contradicts what one would
naturally think the ordering should be.

This fixes the following KASAN splat:
BUG: KASAN: use-after-free in proc_remove+0x7b/0x80
Read of size 8 at addr ffff8882dc3b00b8 by task staprun-d/6732
CPU: 7 PID: 6732 Comm: staprun-d Tainted: G           OE    --------- -  - 4.18.0-259.el8.x86_64+debug #1
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-2.fc32 04/01/2014
Call Trace:
 dump_stack+0x8e/0xd0
 print_address_description.constprop.3+0x1f/0x300
 __kasan_report.cold.7+0x76/0xbf
 ? proc_remove+0x7b/0x80
 kasan_report+0xe/0x20
 proc_remove+0x7b/0x80
 __stp_procfs_relay_remove_buf_file_callback+0x254/0x346 [orxray_libc_usleep_XX_6587]
 ? __stp_procfs_relay_remove_buf_file_callback+0x346/0x346 [orxray_libc_usleep_XX_6587]
 ? __stp_relay_remove_buf_file_callback+0x28/0x29 [orxray_libc_usleep_XX_6587]
 ? relay_close_buf+0xe0/0x130
 ? relay_close+0x14f/0x470
 ? _stp_transport_data_fs_close+0x1b/0x27 [orxray_libc_usleep_XX_6587]
 ? _stp_procfs_transport_fs_close+0xa/0xb [orxray_libc_usleep_XX_6587]
 ? _stp_transport_fs_close+0x24/0x26 [orxray_libc_usleep_XX_6587]
 ? _stp_transport_close+0x1e/0x24 [orxray_libc_usleep_XX_6587]
 ? cleanup_module+0xa/0xb [orxray_libc_usleep_XX_6587]
 ? __x64_sys_delete_module+0x2cc/0x4a0
 ? __ia32_sys_delete_module+0x4a0/0x4a0
 ? lockdep_hardirqs_on_prepare+0x343/0x4f0
 ? do_syscall_64+0x22/0x420
 ? do_syscall_64+0xa5/0x420
 ? entry_SYSCALL_64_after_hwframe+0x6a/0xdf
Allocated by task 6587:
 save_stack+0x19/0x80
 __kasan_kmalloc.constprop.10+0xc1/0xd0
 kmem_cache_alloc+0xfe/0x350
 __proc_create+0x1f6/0x740
 proc_create_reg+0x61/0x100
 proc_create_data+0x79/0xf0
 __stp_procfs_relay_create_buf_file_callback+0xcb/0x43e [orxray_libc_usleep_XX_6587]
Freed by task 6732:
 save_stack+0x19/0x80
 __kasan_slab_free+0x125/0x170
 kmem_cache_free+0xcd/0x360
 proc_evict_inode+0x73/0x100
 evict+0x29e/0x590
 __dentry_kill+0x326/0x5a0
 dentry_kill+0x94/0x410
 dput+0x3b0/0x4a0
 path_put+0x2d/0x60
 __stp_procfs_relay_remove_buf_file_callback+0x24c/0x346 [orxray_libc_usleep_XX_6587]
The buggy address belongs to the object at ffff8882dc3b0000
                            which belongs to the cache proc_dir_entry of size 512
The buggy address is located 184 bytes inside of
                            512-byte region [ffff8882dc3b0000ffff8882dc3b0200)
The buggy address belongs to the page:
page:ffffea000b70ec00 refcount:1 mapcount:0 mapping:ffff8881061d4f00 index:0x0 compound_mapcount: 0
flags: 0x17ffffc0008100(slab|head)
raw: 0017ffffc0008100 dead000000000100 dead000000000200 ffff8881061d4f00
raw: 0000000000000000 0000000080190019 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
 ffff8882dc3aff80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff8882dc3b0000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff8882dc3b0080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                        ^
 ffff8882dc3b0100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8882dc3b0180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb

3 years agodiagnostics: amplify .return $context var warning
Frank Ch. Eigler [Thu, 14 Jan 2021 21:45:58 +0000 (16:45 -0500)]
diagnostics: amplify .return $context var warning

Suggested-by: Craig Ringer <craig@2ndquadrant.com>
3 years agostapbpf (for PR27030): bugfix the b71d20af bugfix
Serhei Makarov [Wed, 13 Jan 2021 19:28:20 +0000 (14:28 -0500)]
stapbpf (for PR27030): bugfix the b71d20af bugfix

stap commit b71d20af819 fixed error messages in bpf assembly
(being broken by implicit deallocation of stack vars on exception throw)
but neglected the fact that visit_embeddedcode can recurse
(via emit_functioncall) such that a single bpf_unparser field for
storing asm_stmts will get overwritten by the recursive call.

Alloc/free a separate statement list per visit_embeddedcode call instead.

3 years agoNEWS: correct arch names for recent tls code
Frank Ch. Eigler [Wed, 13 Jan 2021 18:31:03 +0000 (13:31 -0500)]
NEWS: correct arch names for recent tls code

Clarify that it's the 64-bit cpus that have tls var enablement.

3 years agoUpdate test for bpf raw tracepoints to work with Linux 5.7 kernels
William Cohen [Mon, 11 Jan 2021 03:36:21 +0000 (22:36 -0500)]
Update test for bpf raw tracepoints to work with Linux 5.7 kernels

The kernel commit 70ed506c3bbcfa846d4636b23051ca79fa4781f7 in Linux
5.7 and newer replaced the bpf_raw_tracepoint_release function with
bpf_raw_tp_link_release.  This change in function names would cause
SystemTap's test for BPF raw tracepoint support to fail.  Updated the
check to look for the newer alternative function name.

3 years agoRemove non-posix == operators from configure.ac
Sven Wegener [Sat, 9 Jan 2021 21:40:02 +0000 (16:40 -0500)]
Remove non-posix == operators from configure.ac

The configure.ac script contains test commands with the == operator,
which is supported by most shells, but fails if /bin/sh has a test
built-in which is strictly posix-compliant.

3 years agoAdd BuildRequires: make
Tom Stellard [Sat, 9 Jan 2021 21:38:50 +0000 (16:38 -0500)]
Add BuildRequires: make

https://fedoraproject.org/wiki/Changes/Remove_make_from_BuildRoot

3 years agoDon't warn about freeing a NULL pointer for functions that tolerate it
Sultan Alsawaf [Fri, 8 Jan 2021 21:09:34 +0000 (13:09 -0800)]
Don't warn about freeing a NULL pointer for functions that tolerate it

Passing a NULL pointer to kfree(), vfree(), and free_percpu() is fine
and supported behavior; these functions will just return early when
given a NULL pointer. However, DEBUG_MEM doesn't know about this, and
warns about it even though it isn't a problem. This mutes the warning
from _stp_mem_debug_free() when these functions receive a NULL pointer.

Signed-off-by: Sultan Alsawaf <sultan@openresty.com>
3 years agoAdd stapdyn VMA-tracking.
Stan Cox [Fri, 8 Jan 2021 20:38:42 +0000 (15:38 -0500)]
Add stapdyn VMA-tracking.

To handle VMA-tracking in stapdyn: 1) do not emit pragma:vma so the
kernel VMA-tracker is not enabled 2) add a stapdyn version of
_stp_umodule_relocate which 3) uses dwfl_linux_proc_report to find the
appropriate module start 4) relocate the offset.  This makes tls
possible so it is enabled for stapdyn.

3 years agoConditionally define ASYNC_SIZE in stack-s390.c
Martin Cermak [Thu, 7 Jan 2021 21:59:52 +0000 (22:59 +0100)]
Conditionally define ASYNC_SIZE in stack-s390.c

Upstream commit ce3dc44749 removed ASYNC_SIZE.

3 years agotask_finder2: fix task worker race on module unload
Sultan Alsawaf [Wed, 30 Dec 2020 23:47:58 +0000 (15:47 -0800)]
task_finder2: fix task worker race on module unload

Unfortunately, __stp_tf_cancel_all_task_work() does not guarantee that
all of the task finder's task workers will be finished executing when it
returns. In this case, we rely on the stp_task_work API to prevent the
module from being unloaded while there are task workers in-flight, which
works, but the stp_task_work API is notified of a task worker finishing
before it actually finishes. Inside __stp_tf_task_worker_fn(), the
call to the task worker's function (tf_work->func) is where the final
refcount in the stp_task_work API could be put, but there will still be
instructions left in the task worker that will be executing for a short
time after that. In that short time, there can be a race where the
module is unloaded before the task worker finishes executing all of its
instructions, especially if the task worker gets preempted during this
time on a PREEMPT kernel.

To remedy this, we must ensure that the last instruction in
__stp_tf_task_worker_fn() is where the stp_task_work API is notified of
a task worker finishing.

3 years agotask_finder2: fix list corruption in __stp_tf_cancel_all_task_work()
Sultan Alsawaf [Wed, 30 Dec 2020 23:42:11 +0000 (15:42 -0800)]
task_finder2: fix list corruption in __stp_tf_cancel_all_task_work()

The previous commit (b26b4e2c2 "task_finder2: fix panics due to broken
task work cancellation") made it possible for the next node in the task
work list to be free, which would made list_for_each_entry_safe() not so
safe anymore. Using list_for_each_entry_safe() is still the fastest
approach here, so when the next node in the list happens to be freed, we
should just restart iteration on the list.

3 years agotask_finder2: fix panics due to broken task work cancellation
Sultan Alsawaf [Wed, 30 Dec 2020 22:21:42 +0000 (14:21 -0800)]
task_finder2: fix panics due to broken task work cancellation

The task_work_cancel() API uses function pointers to uniquely identify
task work structs, so there's no guarantee that a specific task work
struct we want to cancel is the one that will actually get canceled.
This issue would cause task work structs to be freed while they were
still queued up on the task's task-worker list.

This is an example of one such panic, where the DEBUG_MEM feature
reported that a __stp_tf_task_work struct (56 bytes) wasn't freed,
because that specific task worker got canceled and instead an active
task worker got freed!

orxray_resty_mem_X_35062: ERROR: Memory ffff8809ed388620 len=56 allocation type: kmalloc. Not freed.
BUG: unable to handle kernel paging request at ffffffffa0570877
IP: [<ffffffffa0570877>] 0xffffffffa0570876
PGD 1abd067 PUD 1abe063 PMD 1028286067 PTE 0
Oops: 0010 [#1] SMP
CPU: 3 PID: 1338 Comm: nginx Tainted: G           OE  ------------   3.10.0-514.10.2.el7.x86_64.debug #1
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-2.fc32 04/01/2014
task: ffff880eae2d0000 ti: ffff880eaf2e4000 task.ti: ffff880eaf2e4000
RIP: 0010:[<ffffffffa0570877>]  [<ffffffffa0570877>] 0xffffffffa0570876
RSP: 0018:ffff880eaf2e7d78  EFLAGS: 00010282
RAX: 0000000000000001 RBX: 0000000000000000 RCX: 0000000000000000
RDX: ffff8809ed388640 RSI: 0000000000000000 RDI: ffff8809ed388640
RBP: ffff880eaf2e7da0 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000001 R11: ffffffffff90001c R12: ffffffff8248b1c0
R13: ffff880eae2d0818 R14: ffff880eae2d0000 R15: 00007eff3d2490b0
FS:  00007eff3dcd2740(0000) GS:ffff881037c00000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffffffffa0570877 CR3: 0000000ebce67000 CR4: 00000000003406e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
Stack:
 ffffffff810c6544 ffff880eaf2e7f58 ffff880eaf2e7e70 ffff880eae2d0000
 00007eff3dcb3338 ffff880eaf2e7e38 ffffffff810b31ba ffff880eaf2e7dc0
 ffffffff8106c279 ffff880eaf2e7e50 ffff880ef8a792c0 ffff880eaf2e7df8
Call Trace:
 [<ffffffff810c6544>] ? task_work_run+0xb4/0xe0
 [<ffffffff810b31ba>] get_signal_to_deliver+0x85a/0x960
 [<ffffffff8106c279>] ? kvm_sched_clock_read+0x9/0x20
 [<ffffffff810e7b4d>] ? sched_clock_local+0x1d/0x80
 [<ffffffff810e7dd8>] ? sched_clock_cpu+0xb8/0xe0
 [<ffffffff810324a7>] do_signal+0x57/0x6e0
 [<ffffffff8176dba6>] ? int_very_careful+0x5/0xd
 [<ffffffff81032b8f>] do_notify_resume+0x5f/0xb0
 [<ffffffff8176dbfd>] int_signal+0x12/0x17
Code:  Bad RIP value.
RIP  [<ffffffffa0570877>] 0xffffffffa0570876
 RSP <ffff880eaf2e7d78>
CR2: ffffffffa0570877
---[ end trace 1cdf8e5b522b246e ]---

3 years agoWork around kernel claims of a function("input_event").inline probe point
William Cohen [Wed, 23 Dec 2020 21:33:03 +0000 (16:33 -0500)]
Work around kernel claims of a function("input_event").inline probe point

Newer Fedora Linux kernels (F32/F33) are claiming a
function("input_event").inline probe point exists and has no
arguments.  The build of the stapgames block and eater fail because
the needed arguments are not found.  Examined where the claimed inline
input_events functions are with:

  stap -v -L 'kernel.function("input_event").*'

There appears to be a bogus one listed inside the callable input_event
function itself.  Worked around this by setting the game.input tapset
probe to function("input_event").call to exclude the bogus inline
version.  It was verified that the games got input from the keyboard
with this patch.

3 years agoAdjust enospc.stp example to work with Linux 5.9 kernels
William Cohen [Wed, 23 Dec 2020 20:19:42 +0000 (15:19 -0500)]
Adjust enospc.stp example to work with Linux 5.9 kernels

The Linux 5.9 kernels changed the type of the inode agument passed
into the btrfs_check_data_free_space function.  Need to check to see
if it is the new struct btrfs_inode being used or the old struct inode
and use a different field to get the s_dev value if required.

3 years agoAllow ioblock.request to work Linux 5.9 and newer kernels
William Cohen [Tue, 22 Dec 2020 21:17:02 +0000 (16:17 -0500)]
Allow ioblock.request to work Linux 5.9 and newer kernels

In the Linux 5.9 kernel the generic_make_request function was renamed
to submit_bio_noacct by commit ed00aabd5e.  Adjust the ioblock
ioblock.request to use the new name if it is available.

3 years agoRevert "PR26844: remove trailing space from printed backtraces"
Sultan Alsawaf [Wed, 16 Dec 2020 23:17:24 +0000 (15:17 -0800)]
Revert "PR26844: remove trailing space from printed backtraces"

This reverts commit 3d888f650fd13c6051b16573d0f84243689bf999.

Bad toast. This is a hack.

3 years agoPR26844: remove trailing space from printed backtraces
Sultan Alsawaf [Wed, 16 Dec 2020 22:46:36 +0000 (14:46 -0800)]
PR26844: remove trailing space from printed backtraces

When _STP_SYM_POST_SPACE is used, a trailing space is left over in the
log buffer which is then copied to the output for the backtrace print.
This issue was exposed by commit fd93cf71d.

3 years agotestsuite regrediag: new test for diagnostic duplication
Frank Ch. Eigler [Wed, 16 Dec 2020 21:46:29 +0000 (16:46 -0500)]
testsuite regrediag: new test for diagnostic duplication

Little test case confirms the correct number of semantic error
lines from the test case for commit 405f69a11a6.

3 years agosession.cxx: fix print error dupe-elimination for chained errors
Sultan Alsawaf [Wed, 16 Dec 2020 21:03:47 +0000 (13:03 -0800)]
session.cxx: fix print error dupe-elimination for chained errors

Commit 0e1d5b7eb397 introduced an issue where error messages would be
duplicated, like so:
Before:
--------------------8<--------------------
semantic error: type mismatch (long): identifier 'a' at test.stp:8:5
        source:     a = 32;
                    ^

semantic error: type was first inferred here (string): identifier 'a' at :4:5
        source:     a = "stringcheese";
                    ^

Pass 2: analysis failed.  [man error::pass2]
-------------------->8--------------------

After:
--------------------8<--------------------
semantic error: type mismatch (long): identifier 'a' at test.stp:8:5
        source:     a = 32;
                    ^

semantic error: type mismatch (long): identifier 'a' at :8:5
        source:     a = 32;
                    ^

semantic error: type was first inferred here (string): identifier 'a' at :4:5
        source:     a = "stringcheese";
                    ^

Pass 2: analysis failed.  [man error::pass2]
-------------------->8--------------------

The first message would be duplicated because the wrong seen_errors is
checked inside the loop, after that first message would be printed
outside the loop. This fixes the issue by using the same error counter
throughout.

3 years agostapbpf (for PR27030) tentative regalloc fix: zero unused regs
Serhei Makarov [Tue, 15 Dec 2020 20:42:23 +0000 (15:42 -0500)]
stapbpf (for PR27030) tentative regalloc fix: zero unused regs

It can happen with some programs that the register allocator
restores a register whose spill slot was never written.

Tentatively, zero the stack to avoid a verifier error in this case.

3 years agostaprun: use the correct out_fd when bulkmode and fsize_max aren't used
Sultan Alsawaf [Mon, 14 Dec 2020 21:20:34 +0000 (13:20 -0800)]
staprun: use the correct out_fd when bulkmode and fsize_max aren't used

When bulkmode and fsize_max aren't used, there is only one output fd and
it is stored at out_fd[avail_cpus[0]].

3 years agostapbpf (for PR27030): bugfix error messages in bpf assembly
Serhei Makarov [Mon, 14 Dec 2020 17:39:51 +0000 (12:39 -0500)]
stapbpf (for PR27030): bugfix error messages in bpf assembly

Need to retain the asm_stmts vector so that bpf assembly tokens
are not deallocated on exception throw.

Otherwise, printing semantic errors from bpf assembly causes segfault.

* bpf-translate.cxx (struct bpf_unparser): retain asm_stmts vector.
(bpf_unparser::visit_embeddedcode): reuse retained asm_stmts vector.

3 years agoPR27067 <<< corrected bug# for previous commit
Frank Ch. Eigler [Mon, 14 Dec 2020 02:19:15 +0000 (21:19 -0500)]
PR27067 <<< corrected bug# for previous commit

3 years agoPR23512: fix staprun/stapio operation via less-than-root privileges
Frank Ch. Eigler [Mon, 14 Dec 2020 02:05:23 +0000 (21:05 -0500)]
PR23512: fix staprun/stapio operation via less-than-root privileges

Commit 7615cae790c899bc8a82841c75c8ea9c6fa54df3 for PR26665 introduced
a regression in handling stapusr/stapdev/stapsys gid invocation of
staprun/stapio.  This patch simplifies the relevant code in
staprun/ctl.c, init_ctl_channel(), to rely on openat/etc. to populate
and use the relay_basedir_fd as much as possible.  Also, we now avoid
unnecessary use of access(), which was checking against the wrong
(real rather than effective) uid/gid.

3 years agostaprun: handle more and fewer cpus better
Frank Ch. Eigler [Fri, 11 Dec 2020 23:06:36 +0000 (18:06 -0500)]
staprun: handle more and fewer cpus better

NR_CPUS was a hard-coded minimum and maximum on the number of CPUs
worth of trace$N files staprun/stapio would open at startup.  While a
constant is useful for array sizing (and so might as well be really
large), the actual iteration should be informed by get_nprocs_conf(3).

This patch replaces NR_CPUS with MAX_NR_CPUS (now 1024, why not), and
limits open/thread iterations to the actual number of processors.  It
even prints an error if a behemoth >1K-core machine comes into being.

3 years agobugfix: runtime: transport: handle more error cases in module init
Cosmin Tanislav [Thu, 10 Dec 2020 21:48:54 +0000 (16:48 -0500)]
bugfix: runtime: transport: handle more error cases in module init

Signed-off-by: Sultan Alsawaf <sultan@openresty.com>
3 years agorelay transport: comment on STP_BULK message
Frank Ch. Eigler [Fri, 11 Dec 2020 20:39:29 +0000 (15:39 -0500)]
relay transport: comment on STP_BULK message

While we've eliminated any STP_BULKMODE effects from the way relayfs
files are used ("always bulkmode"), staprun/stapio still need to know
whether the user intended "stap -b" or not, so they can save files
stpd_cpu* files separately.

3 years agotransport: set is_global to zero even when bulkmode is disabled
Sultan Alsawaf [Fri, 11 Dec 2020 20:31:25 +0000 (12:31 -0800)]
transport: set is_global to zero even when bulkmode is disabled

This is needed now that we always want per-cpu logger threads. When
is_global is set to a non-zero value, relay won't create per-cpu log
files.

3 years agoSupport pointer_arg in dyninst mode
Stan Cox [Fri, 11 Dec 2020 16:52:50 +0000 (11:52 -0500)]
Support pointer_arg in dyninst mode

Obey STAPCONF_X86_UNIREGS in _stp_arg2 since dyninst uses the standard
ptrace.h which defines, e.g. rax instead of ax

3 years agoRevert "REVERTME: tapset-timers: work around on-the-fly deadlocks caused by mutex_try...
Sultan Alsawaf [Thu, 10 Dec 2020 01:22:27 +0000 (17:22 -0800)]
Revert "REVERTME: tapset-timers: work around on-the-fly deadlocks caused by mutex_trylock"

This reverts commit 6a27888b118b7a94650a68aae028957cdd5fb5f5.

No longer needed. As promised, we're reverting this.

3 years agoalways use per-cpu bulkmode relayfs files to communicate with userspace
Sultan Alsawaf [Thu, 10 Dec 2020 01:22:20 +0000 (17:22 -0800)]
always use per-cpu bulkmode relayfs files to communicate with userspace

Using a mutex_trylock() in __stp_print_flush() leads to a lot of havoc,
for numerous. Firstly, since __stp_print_flush() can be called from IRQ
context, holding the inode mutex from here would make the mutex owner
become nonsense, since mutex locks can only be held in contexts backed
by the scheduler. Secondly, the mutex_trylock implementation has a
spin_lock() inside of it that leads to two issues: IRQs aren't disabled
when acquiring this spin_lock(), so using it from IRQ context can lead
to a deadlock, and since spin locks can have tracepoints via
lock_acquire(), the spin_lock() can recurse on itself inside a stap
probe and deadlock, like so:

 #0 [ffff88017f6d7a08] kvm_wait at ffffffff81079f5a
 #1 [ffff88017f6d7a30] __pv_queued_spin_lock_slowpath at ffffffff8114f51e
 #2 [ffff88017f6d7a70] queued_spin_lock_slowpath at ffffffff810e842b
 #3 [ffff88017f6d7a80] mutex_trylock at ffffffff81882b1b
 #4 [ffff88017f6d7ab8] _stp_transport_trylock_relay_inode at ffffffffc0c599df [stap_47650d3377d05db0ab7cbbaa25765809__11657]
 #5 [ffff88017f6d7ad8] __stp_print_flush at ffffffffc09b6483 [stap_47650d3377d05db0ab7cbbaa25765809__11657]
 #6 [ffff88017f6d7b10] probe_7879 at ffffffffc0a98c85 [stap_47650d3377d05db0ab7cbbaa25765809__11657]
 #7 [ffff88017f6d7b38] enter_real_tracepoint_probe_1543 at ffffffffc0c3b757 [stap_47650d3377d05db0ab7cbbaa25765809__11657]
 #8 [ffff88017f6d7b70] enter_tracepoint_probe_1543 at ffffffffc09b117e [stap_47650d3377d05db0ab7cbbaa25765809__11657]
 #9 [ffff88017f6d7b80] lock_acquire at ffffffff811460ba

The reason the mutex_trylock() was needed in the first place was because
staprun doesn't properly use the relayfs API when reading buffers in
non-bulk mode. It tries to read all CPUs' buffers from a single thread,
when it should be reading each CPU's buffer from a thread running on
said CPU in order to utilize relayfs' synchronization guarantees, which
are made by disabling IRQs on the local CPU when a buffer is modified.

This change makes staprun always use per-CPU threads to read print
buffers so that we don't need the mutex_trylock() in the print flush
routine, which resolves a wide variety of serious bugs.

We also need to adjust the transport sub-buffer count to accommodate for
frequent print flushing. The sub-buffer size is now reduced to match the
log buffer size, which is 8192 by default, and the number of sub-buffers
is increased to 256. This uses exactly the same amount of memory as
before.

3 years agoPR27044: fix lock loop for conditional probes
Frank Ch. Eigler [Thu, 10 Dec 2020 03:29:43 +0000 (22:29 -0500)]
PR27044: fix lock loop for conditional probes

Emit a nested block carefully so that the "goto out;" from a failed
stp_lock_probe() call in that spot near the epilogue of a
probe-handler goes downward, not upward.

3 years agoPR26844: fix off-by-one error when copying printed backtraces
Sultan Alsawaf [Wed, 9 Dec 2020 20:55:10 +0000 (12:55 -0800)]
PR26844: fix off-by-one error when copying printed backtraces

Since log->buf isn't null-terminated, log->len represents the total
number of bytes present in the log buffer for copying. The use of
strlcpy() here with log->len as its size results in log->len - 1 bytes
being copied, with the log->len'nth byte of the output buffer being set
to zero to terminate the string. Use memcpy() instead to remedy this,
while ensuring that the output buffer has space for null termination,
since the output buffer needs to be terminated.

3 years agodyninst transport: add _stp_print_*lock_irq* stubs
Frank Ch. Eigler [Sat, 5 Dec 2020 02:33:21 +0000 (21:33 -0500)]
dyninst transport: add _stp_print_*lock_irq* stubs

Recent code on the transport/linux side needs a few new (stub)
functions and type decls.

3 years agoconfigury noise: regenerate using fedora-33 auto*
Frank Ch. Eigler [Sat, 5 Dec 2020 00:47:25 +0000 (19:47 -0500)]
configury noise: regenerate using fedora-33 auto*

autoreconf here and there, nothing of consequence

3 years agotestsuite pr14536.stp: toughen
Frank Ch. Eigler [Sat, 5 Dec 2020 00:33:22 +0000 (19:33 -0500)]
testsuite pr14536.stp: toughen

This test case stresses nesting of heavy duty processing (backtrace
printing) within kernel interrupt processing paths.  It seems to
sometimes trigger problems - so let's make the test harder to make
latent problems show up more likely.  Instead of quitting after the
first irq_* function hit, stick around for 10 seconds.

3 years agoPR27001: fix runtime/transport/transport.c lockdown build problem
Guillaume Morin [Fri, 4 Dec 2020 17:18:44 +0000 (12:18 -0500)]
PR27001: fix runtime/transport/transport.c lockdown build problem

On some kernel/configs, CONFIG_SECURITY_LOCKDOWN_LSM !=
STAPCONF_LOCKDOWN_DEBUGFS, which broke the runtime build.
Using the matching macro as detected by autoconf to fix.

3 years agoruntime: fix print races in IRQ context and during print cleanup
Sultan Alsawaf [Thu, 3 Dec 2020 20:57:34 +0000 (12:57 -0800)]
runtime: fix print races in IRQ context and during print cleanup

Prints can race when there's a print called from IRQ context or a print
called while print cleanup takes place, which can lead to garbled print
messages, out-of-bounds memory accesses, and memory use-after-free. This
is one example of racy modification of the print buffer len in IRQ
context which caused a panic due to an out-of-bounds memory access:

BUG: unable to handle kernel paging request at ffffe8ffff621000
IP: [<ffffffffc05da0f3>] _stp_vsprint_memory+0x83/0x950 [stap_2c44636dfda18135ca3012a752599da6_13_533]
PGD 174b90067 PUD 174b8f067 PMD 174b93067 PTE 0
Oops: 0002 [#1] SMP
CPU: 12 PID: 3468 Comm: cat Kdump: loaded Tainted: G           OE  ------------   3.10.0-1127.19.1.el7.x86_64.debug #1
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ?-20180531_142017-buildhw-08.phx2.fedoraproject.org-1.fc28 04/01/2014
task: ffff88001f4f0000 ti: ffff88004ea5c000 task.ti: ffff88004ea5c000
RIP: 0010:[<ffffffffc05da0f3>]  [<ffffffffc05da0f3>] _stp_vsprint_memory+0x83/0x950 [stap_2c44636dfda18135ca3012a752599da6_13_533]
RSP: 0018:ffff88004ea5f9a8  EFLAGS: 00010082
RAX: ffffe8ffff621001 RBX: ffffe8ffff620ff2 RCX: fffffffffffffffe
RDX: 000000000000006e RSI: ffffffffffffffff RDI: ffffc90002c23730
RBP: ffff88004ea5fa28 R08: 00000000ffffffff R09: 0000000000000073
R10: ffffc90002c243d7 R11: 0000000000000001 R12: ffffc90002c2373f
R13: ffffe8ffff621004 R14: 0000000000000012 R15: 00000000fffffffe
FS:  00007f8a9b1d4740(0000) GS:ffff880179e00000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffffe8ffff621000 CR3: 00000000b3e3c000 CR4: 0000000000360fe0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 [<ffffffff8103eb89>] ? sched_clock+0x9/0x10
 [<ffffffff8114036f>] ? lock_release_holdtime.part.30+0xf/0x1a0
 [<ffffffffc05dcb80>] function___global_trace__overload_0+0x5b0/0x1220 [stap_2c44636dfda18135ca3012a752599da6_13_533]
 [<ffffffffc05d8993>] ? stp_lock_probe+0x53/0xe0 [stap_2c44636dfda18135ca3012a752599da6_13_533]
 [<ffffffff8188d879>] ? kretprobe_trampoline_holder+0x9/0x9
 [<ffffffffc05e0662>] probe_7118+0x82/0xe0 [stap_2c44636dfda18135ca3012a752599da6_13_533]
 [<ffffffffc05de866>] enter_kretprobe_common+0x256/0x490 [stap_2c44636dfda18135ca3012a752599da6_13_533]
 [<ffffffff813489f1>] ? proc_sys_open+0x51/0x60
 [<ffffffffc05dead0>] enter_kretprobe_probe+0x10/0x20 [stap_2c44636dfda18135ca3012a752599da6_13_533]
 [<ffffffff8188e1d8>] trampoline_handler+0x148/0x220
 [<ffffffff813489f1>] ? proc_sys_open+0x51/0x60
 [<ffffffff8188d89e>] kretprobe_trampoline+0x25/0x57
 [<ffffffff813489f1>] ? proc_sys_open+0x51/0x60
 [<ffffffff8188d879>] kretprobe_trampoline_holder+0x9/0x9
 [<ffffffff81384702>] ? security_inode_permission+0x22/0x30
 [<ffffffff813489a0>] ? sysctl_head_finish+0x50/0x50
 [<ffffffff812ac11d>] vfs_open+0x5d/0xb0
 [<ffffffff812bb74a>] ? may_open+0x5a/0x120
 [<ffffffff812c0af5>] do_last+0x285/0x15b0
 [<ffffffff812bf18e>] ? link_path_walk+0x27e/0x8c0
 [<ffffffff812c1ef0>] path_openat+0xd0/0x5d0
 [<ffffffff8107a7f3>] ? kvm_clock_read+0x33/0x40
 [<ffffffff812c38ad>] do_filp_open+0x4d/0xb0
 [<ffffffff81889497>] ? _raw_spin_unlock+0x27/0x40
 [<ffffffff812d5a9b>] ? __alloc_fd+0xfb/0x270
 [<ffffffff812ad784>] do_sys_open+0x124/0x220
 [<ffffffff812ad89e>] SyS_open+0x1e/0x20
 [<ffffffff8188d879>] kretprobe_trampoline_holder+0x9/0x9

This patch resolves the IRQ print races by disabling IRQs on the local
CPU when accessing said CPU's print buffer, and resolves the cleanup
races with a lock. We also protect against data corruption and panics
from prints inside NMIs now by checking if the current CPU was accessing
the log buffer when an NMI fired; in this case, the NMI's prints will be
dropped, as there is no way to safely service them without creating a
dedicated log buffer for them. This is achieved by forbidding reentrancy
with respect to _stp_print_trylock_irqsave() when the runtime context
isn't held. Reentrancy is otherwise allowed when the runtime context is
held because the runtime context provides reentrancy protection.

3 years agopost-release prep: bump version number to 4.5
Frank Ch. Eigler [Thu, 3 Dec 2020 20:24:20 +0000 (15:24 -0500)]
post-release prep: bump version number to 4.5

3 years agoMerge branch 'master' of ssh://sourceware.org/git/systemtap into concious_language
Alice Zhang [Thu, 3 Dec 2020 16:55:43 +0000 (11:55 -0500)]
Merge branch 'master' of ssh://sourceware.org/git/systemtap into concious_language

3 years agoREVERTME: tapset-timers: work around on-the-fly deadlocks caused by mutex_trylock
Sultan Alsawaf [Thu, 3 Dec 2020 02:09:17 +0000 (18:09 -0800)]
REVERTME: tapset-timers: work around on-the-fly deadlocks caused by mutex_trylock

The following deadlock exists due to tracepoints existing inside a lock
that is used both inside probe context and outside probe context:
 #0 [ffff88017f6d7a08] kvm_wait at ffffffff81079f5a
 #1 [ffff88017f6d7a30] __pv_queued_spin_lock_slowpath at ffffffff8114f51e
 #2 [ffff88017f6d7a70] queued_spin_lock_slowpath at ffffffff810e842b
 #3 [ffff88017f6d7a80] mutex_trylock at ffffffff81882b1b
 #4 [ffff88017f6d7ab8] _stp_transport_trylock_relay_inode at ffffffffc0c599df [stap_47650d3377d05db0ab7cbbaa25765809__11657]
 #5 [ffff88017f6d7ad8] __stp_print_flush at ffffffffc09b6483 [stap_47650d3377d05db0ab7cbbaa25765809__11657]
 #6 [ffff88017f6d7b10] probe_7879 at ffffffffc0a98c85 [stap_47650d3377d05db0ab7cbbaa25765809__11657]
 #7 [ffff88017f6d7b38] enter_real_tracepoint_probe_1543 at ffffffffc0c3b757 [stap_47650d3377d05db0ab7cbbaa25765809__11657]
 #8 [ffff88017f6d7b70] enter_tracepoint_probe_1543 at ffffffffc09b117e [stap_47650d3377d05db0ab7cbbaa25765809__11657]
 #9 [ffff88017f6d7b80] lock_acquire at ffffffff811460ba
#10 [ffff88017f6d7be8] mutex_trylock at ffffffff81882a27
#11 [ffff88017f6d7c20] _stp_transport_trylock_relay_inode at ffffffffc0c599df [stap_47650d3377d05db0ab7cbbaa25765809__11657]
#12 [ffff88017f6d7c40] __stp_print_flush at ffffffffc09b6483 [stap_47650d3377d05db0ab7cbbaa25765809__11657]
#13 [ffff88017f6d7c78] _stp_vlog at ffffffffc09b8d32 [stap_47650d3377d05db0ab7cbbaa25765809__11657]
#14 [ffff88017f6d7cd8] _stp_dbug at ffffffffc09ba43b [stap_47650d3377d05db0ab7cbbaa25765809__11657]
#15 [ffff88017f6d7d38] systemtap_module_refresh at ffffffffc09ba51d [stap_47650d3377d05db0ab7cbbaa25765809__11657]
#16 [ffff88017f6d7d50] module_refresher at ffffffffc09ba53e [stap_47650d3377d05db0ab7cbbaa25765809__11657]
#17 [ffff88017f6d7d60] process_one_work at ffffffff810da9cc
#18 [ffff88017f6d7de8] worker_thread at ffffffff810dafe6
#19 [ffff88017f6d7e48] kthread at ffffffff810e44cf
#20 [ffff88017f6d7f50] ret_from_fork_nospec_begin at ffffffff818958dd

Note the deadlock due to _stp_transport_trylock_relay_inode recursing
onto itself via mutex_trylock.

This is a temporary fix for the issue until a proper patch is made to
remove the mutex_trylock from __stp_print_flush. This should be reverted
when that patch lands (it will have something to do with bulkmode).

3 years agotask_finder_vma: add kfree_rcu() compat for old kernels
Sultan Alsawaf [Wed, 2 Dec 2020 19:27:47 +0000 (11:27 -0800)]
task_finder_vma: add kfree_rcu() compat for old kernels

Newer RHEL 6 kernels have kfree_rcu(), but older ones do not. Using
kfree_rcu() is beneficial because it lets the RCU subsystem know that
the queued RCU callback is low-priority, and can be deferred, hence why
we don't replace kfree_rcu() with call_rcu() outright. Luckily,
kfree_rcu() is a macro so we can just #ifdef with it.

3 years agoruntime_context: disable preempt while holding the context
Sultan Alsawaf [Wed, 2 Dec 2020 19:07:11 +0000 (11:07 -0800)]
runtime_context: disable preempt while holding the context

After the context lock was converted to an atomic in the previous
commit, the preempt disable logic disappeared. Add it back.

3 years agoConscious language initiatives: replaced whitelist->passlist, blacklist->blocklist...
Alice Zhang [Fri, 27 Nov 2020 18:45:41 +0000 (13:45 -0500)]
Conscious language initiatives: replaced whitelist->passlist, blacklist->blocklist, master->main/primary. Some occurences of master and slave may not be able to be replaced at this point, eg. name of a terminology or usage of other programs interface.

This page took 0.088435 seconds and 5 git commands to generate.