Bug 5163 - tweak uprobes.ko build process
Summary: tweak uprobes.ko build process
Status: RESOLVED FIXED
Alias: None
Product: systemtap
Classification: Unclassified
Component: uprobes (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Josh Stone
URL:
Keywords:
Depends on:
Blocks: 7062
  Show dependency treegraph
 
Reported: 2007-10-11 15:09 UTC by Frank Ch. Eigler
Modified: 2014-05-28 19:45 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
implements cached uprobes (5.55 KB, patch)
2011-06-21 18:22 UTC, Josh Stone
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Frank Ch. Eigler 2007-10-11 15:09:37 UTC
We need to tweak some of the uprobes.ko build steps from bug #5079.
Several problems: /usr/share/systemtap/runtime/uprobes is the wrong place
to build an object file into; /usr could be read-only; the file may not be
easily accessible to staprun except in the local/immediate probing scenario;
uprobes.ko is kernel-version/arch. dependent, just like the systemtap probe
module.

Let's investigate building the uprobes.ko more similarly to probe modules.

It could be stored in the module cache directory ($SYSTEMTAP_DIR/uprobes/).
It could be given a name that encodes the version/architecture parameters
(so the cache directory itself can be shared between machines).  Instead
of passing just "-u" to staprun and have it find uprobes.ko someplace,
pass "UPROBEFILENAME.ko" itself in addition ot the "PROBEFILE.ko".
"stap -p4" could itself print out both needed modules.
Comment 1 Jim Keniston 2007-10-11 23:01:52 UTC
(In reply to comment #0)

These are valid concerns, but I think the solutions need further thought.  See
below.

One thing to keep in mind is that we don't expect uprobes.ko to be insmod-ed and
rmmod-ed every time somebody runs a stap script.  Rather, once uprobes is in the
kernel, it stays there.  (As mentioned in bugs #5079 and #5083, sometimes
uprobes has to hang around long after the last unregister.)  The typical
scenario is that when it's time to insmod a stap-generated module,  uprobes is
already in the kernel (which we can detect becauses the uprobes symbols show up
in /proc/kallsyms).

We can certainly handle somebody rmmod-ing uprobes (in which case we
automatically rebuild it and/or re-insmod it as necessary), but that's not the
typical situation.

The only times we try to build uprobes.ko are:
1. we're stopping after pass 4 (in case uprobes.ko is needed in the environment
where the script will eventually be run); or
2. we're proceeding to pass 5 and we don't see uprobes in the kernel...
... and the script needs uprobes, of course.

> We need to tweak some of the uprobes.ko build steps from bug #5079.
> Several problems: /usr/share/systemtap/runtime/uprobes is the wrong place
> to build an object file into; /usr could be read-only;

And a user from group stapdev doesn't have write access to the directory where
stap currently tries to build uprobes.ko.  You'd have to run stap as root for
the build to succeed.

> the file may not be
> easily accessible to staprun except in the local/immediate probing scenario;

Yes, if you move the stap-generated module to another system, you may need to
bring uprobes.ko with it.

> uprobes.ko is kernel-version/arch. dependent, just like the systemtap probe
> module.
> 
> Let's investigate building the uprobes.ko more similarly to probe modules.
> 
> It could be stored in the module cache directory ($SYSTEMTAP_DIR/uprobes/).

Since each stap user has his/her own cache directory (by default), this would
mean multiple copies of uprobes.ko (and possibly the uprobes source).

> It could be given a name that encodes the version/architecture parameters
> (so the cache directory itself can be shared between machines).  Instead
> of passing just "-u" to staprun and have it find uprobes.ko someplace,
> pass "UPROBEFILENAME.ko" itself in addition ot the "PROBEFILE.ko".
> "stap -p4" could itself print out both needed modules.

Jim
Comment 2 Jim Keniston 2007-11-28 00:31:13 UTC
Further thoughts:

a) How about moving the uprobes source from
$(DESTDIR)/$(pkgdatadir)/runtime/uprobes to $(DESTDIR)/var/systemtap/uprobes? 
That would insure that the uprobes home lives in a writable filesystem, so
uprobes.ko can be built there.  I guess the preferred way to refer to
$(DESTDIR)/var/systemtap in Makefile.am is as
$(DESTDIR)/$(localstatedir)/var/$(PACKAGE).

b) I think it's correct that only root can build the version of uprobes.ko that
staprun insmods.  We don't want non-root users -- even users in  group stapdev
-- to mess with the uprobes source.  This also gets around some rather messy
problems that can arise if root builds uprobes.ko and then a non-root member of
stapdev tries to build it.

c) staprun will modprobe or insmod uprobes.ko, if necessary, for anybody who
invokes staprun with -u and specifies a permitted stap-generated module.  I
think this is OK.
Comment 3 Jim Keniston 2007-11-28 01:05:11 UTC
(In reply to comment #2)
...
> 
> c) staprun will modprobe or insmod uprobes.ko, if necessary, for anybody who
> invokes staprun with -u and specifies a permitted stap-generated module.  I
> think this is OK.

Let me clarify the above, before anybody gets too worked up.  staprun runs
check_permissions() before trying to ensure that uprobes is available.  So if
you're not root, and not in stapdev or stapusr, no dice.  If you're not root and
not in stapdev, and the specified module isn't in /lib/modules/KVER/systemtap,
no dice.  (However, staprun doesn't currently verify that the module actually
uses uprobes.)
Comment 4 Mark Wielaard 2009-01-21 11:51:23 UTC
This does impact usability because of some oddities:
- A user in the stapdev group still has to sudo to get uprobes compiled and loaded.
  The error messages don't immediately make that clear. Especially confusing
after upgrading the kernel.
- When running a script that is cached no test is done to see if uprobes is loaded.
  Somewhat confusing after a reboot
Comment 5 David Smith 2009-01-21 19:18:03 UTC
(In reply to comment #4)
> This does impact usability because of some oddities:
...
> - When running a script that is cached no test is done to see if uprobes is
loaded.
>   Somewhat confusing after a reboot

That one is very annoying to me.  It makes cached modules of scripts that use
uprobes useless.
Comment 6 Josh Stone 2009-04-03 21:58:13 UTC
(In reply to comment #5)
> (In reply to comment #4)
> > This does impact usability because of some oddities:
> ...
> > - When running a script that is cached no test is done to see if uprobes is
> loaded.
> >   Somewhat confusing after a reboot
> 
> That one is very annoying to me.  It makes cached modules of scripts that use
> uprobes useless.

That particular nit should be improved now:

commit 8a03658eed54ff02494107f0ca55081f352df75b
Author: Josh Stone <jistone@redhat.com>
Date:   Fri Apr 3 14:50:18 2009 -0700

    PR5163: Assign need_uprobes during pass-2
    
    We were doing this in pass-3, which means it was never set for cached
    runs, and so staprun didn't get the -u flag.  Now need_probes is set as
    soon as a uprobe_derived_probe is saved into the session in pass-2.
Comment 7 Mark Wielaard 2009-04-16 19:14:43 UTC
Got another instance of this. With the recent update of uprobes I kept getting
failures loading stap modules. It turned out (in dmesg) because the new uprobes
defines two new symbols. But since the uprobes module is never unloaded the old
version without the new functions was still there. Only after a manual rmmod
uprobes did things start working again. That was a bit odd failure mode.
Comment 8 Frank Ch. Eigler 2009-04-16 19:21:19 UTC
The build process changes probably wouldn't fix mjw's problem.
However, one thing we could do easily would be similar to the logic
recently added to staprun to automatically clean up junk leftover
stap_XXXX modules at startup.  It could gently attempt to module_remove
any existing uprobes first, then load the new copy.
Comment 9 Jim Keniston 2009-04-17 18:12:09 UTC
(In reply to comment #8)
> The build process changes probably wouldn't fix mjw's problem.
> However, one thing we could do easily would be similar to the logic
> recently added to staprun to automatically clean up junk leftover
> stap_XXXX modules at startup.  It could gently attempt to module_remove
> any existing uprobes first, then load the new copy.

How about if "make install" unloads uprobes.ko?

For that matter, "make install" could attempt to build uprobes.ko, to help
prevent the situation where a stapdev or stapusr user can't run his script until
root builds uprobes.ko for him.  (It would have to be tolerant of the case where
there's already a kernel-built version of uprobes.)

Another thing we could do is add a script to /etc/init.d to (re)build
uprobes.ko, thus keeping it in sync with the running kernel.
Comment 10 Frank Ch. Eigler 2009-04-20 20:05:10 UTC
(In reply to comment #9)
> How about if "make install" unloads uprobes.ko?
> For that matter, "make install" could attempt to build uprobes.ko

Good ideas; should help systemtap developers.

> Another thing we could do is add a script to /etc/init.d to (re)build
> uprobes.ko, thus keeping it in sync with the running kernel.

Should help systemtap users, except for security concerns (running
kernel make etc. at root during init).  dkms ...
Comment 11 Josh Stone 2011-06-10 19:54:33 UTC
We're thinking about this bug again, especially now that we have cases that must be responsible for multiple distinct targets (--remote and --use-server both).  I'd like to try leaving the uprobes source where it is in SYSTEMTAP_RUNTIME, but build the output in our tmpdir and cache it like all the rest.

Earlier concerns about even stapdev providing uprobes.ko seem moot, given that such users could do whatever they want in guru-mode anyway.
Comment 12 Josh Stone 2011-06-21 18:22:36 UTC
Created attachment 5811 [details]
implements cached uprobes
Comment 13 Frank Ch. Eigler 2011-07-22 17:51:07 UTC
commit 7d26ee024
Comment 14 Jackie Rosen 2014-02-16 17:51:11 UTC Comment hidden (spam)