]> www.infradead.org Git - users/jedix/linux-maple.git/log
users/jedix/linux-maple.git
9 years agodtrace: remove pre-alpha features for release
Kris Van Hees [Wed, 24 Jul 2013 07:31:51 +0000 (03:31 -0400)]
dtrace: remove pre-alpha features for release

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
9 years agodtrace: CONFIG_UPROBES is needed by CONFIG_DT_FASTTRAP, not CONFIG_DTRACE
Nick Alcock [Wed, 31 Jul 2013 13:42:07 +0000 (14:42 +0100)]
dtrace: CONFIG_UPROBES is needed by CONFIG_DT_FASTTRAP, not CONFIG_DTRACE

So move it.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
9 years agodtrace: CONFIG_DTRACE should depend on CONFIG_UPROBES
Nick Alcock [Mon, 29 Jul 2013 14:36:54 +0000 (15:36 +0100)]
dtrace: CONFIG_DTRACE should depend on CONFIG_UPROBES

Since DTrace uses uprobes, it needs to select it, or we end up with most of
uprobes not being compiled in.  In this situation, you can still *try* to
register a uprobe, but it will always fail.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
9 years agowait: fix loss of error code from waitid() when info is provided
Nick Alcock [Mon, 22 Jul 2013 18:16:07 +0000 (19:16 +0100)]
wait: fix loss of error code from waitid() when info is provided

One of the review comments on the original waitid patches suggested using the
pattern

ret = __put_user(...);
ret |= __put_user(...);
...

rather than

if (!ret)
ret = __put_user(...);
if (!ret)
ret |= __put_user(...);

This turns out to be a bad idea if ret is used for anything else first, e.g. if
it is used to store errnos from waitid(), since it overwrites any nonzero error
with the return value of __put_user(), even if that is zero.

The solution is to use a temporary error variable instead, and not assign it to
the actual return value if the temporary error variable is still zero after
doing all the __put_user()s (as is the common case).

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
9 years agowaitfd selftest: dike out some dead code.
Nick Alcock [Tue, 18 Jun 2013 19:03:33 +0000 (20:03 +0100)]
waitfd selftest: dike out some dead code.

Trivial cleanup.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
9 years agoepoll, wait: introduce poll_wait_fixed(), and use it in waitfds
Nick Alcock [Tue, 18 Jun 2013 19:03:08 +0000 (20:03 +0100)]
epoll, wait: introduce poll_wait_fixed(), and use it in waitfds

The poll() machinery expects to be used with files, or things enough like files
that the wake_up key contains an indication as to whether this wakeup
corresponds to a POLLIN / POLLOUT / POLLERR event on this fd.  You can override
this in your poll_queue_proc, but the poll() and epoll() queue procs both have
this interpretation.

Unfortunately, it is not true for waitfds, wihch wait on the the wait_chldexit
waitqueue, whose key is a pointer to the task_struct of the task being killed.
We can't do anything with this key, but we certainly don't want the poll
machinery treating it as a bitmask and checking it against poll events!

So we introduce a new poll_wait() analogue, poll_wait_fixed().  This is used for
poll_wait() calls which know they must wait on waitqueues whose keys are not
a typecast representation of poll events, and passes in an extra argument to
the poll_queue_proc, which if nonzero is the event which a wakeup on this
waitqueue should be considered as equivalent to.  The poll_queue_proc can then
skip adding entirely if that fixed event is not included in the set to be
caught by this poll().

We also add a new poll_table_entry.fixed_key.  The poll_queue_proc can record
the fixed key it is passed in here, and reuse it at wakeup time to track that
a nonzero fixed key was passed in to poll_wait_fixed() and that the key should
be ignored in preference to fixed_key.

With this in place, you can say, e.g. (as waitfd now does)

poll_wait_fixed(file, &current->signal->wait_chldexit, wait,
POLLIN);

and the key passed to wakeups on the wait_chldexit waitqueue will be ignored:
the fd will always be treated as having raised POLLIN, waking up poll()s and
epoll()s that have specified that event.  (Obviously, a poll function that
calls this should return the same value from the poll function as was passed
to poll_wait_fixed(), or, as usual, zero if this was a spurious wakeup.)

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: no longer reference 'ctf.ko.unsigned' in CTF debuginfo stripping machinery
Nick Alcock [Thu, 6 Jun 2013 16:56:18 +0000 (17:56 +0100)]
ctf: no longer reference 'ctf.ko.unsigned' in CTF debuginfo stripping machinery

We used to generate .ko.unsigned modules, which were renamed to .ko after
signing: so when stripping the debugging information out of ctf.ko, we had to
consider the possibility that we might have to strip it out of ctf.ko.unsigned
instead.  With the new signing machinery, this is no longer the case, and that
hack can be removed.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agowait: add waitfd(), and a testcase for it
Nick Alcock [Tue, 4 Jun 2013 15:52:46 +0000 (16:52 +0100)]
wait: add waitfd(), and a testcase for it

This syscall, of prototype

    int waitfd(int which, pid_t upid, int options, int flags);

yields a pollable file descriptor which yields a 'struct siginfo_t' whenever
waitid() or waitpid() would return (when child processes die or ptrace()d
tracees undergo an appropriate state change).

The which, upid and options arguments are as to waitid(); the flags argument is
fd flags as to open() or fcntl(F_SETFL), to which O_RDWR is automatically added.
WNOHANG in the options is automatically translated into O_NONBLOCK in the flags,
and vice versa.

No compat wrappers are in place for this syscall: 32-bit calls with a 64-bit
kernel will return a 64-bit version of 'struct siginfo'.

Current bugs:
  - select/poll/epoll is not waking up the process yet, even when it should.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agodtrace: ensure that arg6 through arg9 get retrieved correctly for USDT probes
Kris Van Hees [Fri, 31 May 2013 06:48:37 +0000 (02:48 -0400)]
dtrace: ensure that arg6 through arg9 get retrieved correctly for USDT probes

A bug in the implementation of retrieving arguments from the stack caused
bogus values to be returned for arg6 through arg9 on x86_64.  This has been
resolved.

This commit also removes various debugging output that is no longer needed.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: finish the implementation of is-enabled USDT probes
Kris Van Hees [Thu, 23 May 2013 14:52:00 +0000 (10:52 -0400)]
dtrace: finish the implementation of is-enabled USDT probes

This commit completes the implementation of is-enabled USDT probes, i.e. probes
that when fired cause an execution flow change.  This makes it possible (when
using USDT) to encode more complex code sections that are only executed if a
specific USDT probe has been enabled, i.e. when a consumer is listening for
s specific USDT probe.  This is most commonly used for cases where a USDT probe
might require additional computation for one or more of its arguments, and so
it would be too expensive to always do that computation, whether the probe is
enabled or not.  With is-enabled probes, the overhead when DTrace is not used
is negligible (2 NOPs), and when DTrace is in use but the guarded probe is not
enabled, the cost is a single probe firing (without calling dtrace_probe()).

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: fixes for tracepoint cleanup
Kris Van Hees [Wed, 22 May 2013 23:25:48 +0000 (19:25 -0400)]
dtrace: fixes for tracepoint cleanup

Various fixes to handle tracepoint cleanup.  It is important to note that it is
most common that USDT providers will be cleaned up (asynchronously) when the
process/task they relate to is already gone.  We therefore cannot use a (pid,
addr) pair to identify the tracepoint for removal.  The new implementation
stores the (inode, offset) pair calculated right before registering the uprobe,
so that we can use that same pair again when unregistering.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: update syscall tracing in view of Linux 3.8 changes
Kris Van Hees [Tue, 21 May 2013 06:48:39 +0000 (02:48 -0400)]
dtrace: update syscall tracing in view of Linux 3.8 changes

The handling of various stub-based syscalls in Linux 3.8 changed to no longer
use the saved registers directly.  This change is now also reflected in the
DTrace overrides for those system calls.

Also reset the compilatio debug settings to all-off (they should only be
turned on in local compilations - never in the repo.)

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: USDT implementation (phase 2)
Kris Van Hees [Mon, 20 May 2013 20:37:33 +0000 (16:37 -0400)]
dtrace: USDT implementation (phase 2)

This commit contains the 2nd phase of the USDT implementation for DTrace for
Linux.  It provides the mechanics of fasttrap probes (enabling, firing, and
disabling).  It also contains various debugging statements that will be cleaned
up in a future commit.  They exist right now, because this commit represents a
work in progress that is known to contain various bugs and loose ends.  The
commit for this code is provided as a "sharing of the pain" , and to ensure
that others can start playing with this code and test the interaction with
userspace.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: revamp and split up DTrace headers; add ioctl() debugging machinery
Nick Alcock [Mon, 29 Apr 2013 12:57:15 +0000 (13:57 +0100)]
dtrace: revamp and split up DTrace headers; add ioctl() debugging machinery

It has always been annoying that we have a duplicate set of DTrace headers
in userspace, and further annoying that the DTrace header we have is such a
monolithic monster.

This fixes both of these, at the cost of a (very) little extra complexity when
maintaining the headers.  It also adds automated machinery to verify that each
of the new headers is 'standalone enough'.

What does 'standalone enough' mean?  This is the problem that has stopped us
sharing DTrace headers between userspace and kernelspace for a long time: they
depend on types that come from different places and have different definitions
in the kernel and in userspace, and can never be made to come from the same
place.

So we fix this by dictating that the headers are standalone *given* that certain
headers are included first.  For userspace, this set is <sys/types.h>,
<ctf/types.h>, and <unistd.h>; for kernelspace, the set is <linux/types.h> and a
newly-introduced header included as <dtrace/types.h>.  We avoid exposing this
requirement to header users by arranging for the header included as "dtrace.h"
in kernelspace and as <sys/dtrace.h> in userspace to include the prerequisite
headers, and enough other headers that the users of those headers can keep
using them exactly as they did before.  (There is a single exception for
dtrace/ioctl.h: see below.)

Where have the headers gone?  They have been split in two directions (and the
Kbuild machinery has been adjusted to have its include paths point at the
appropriate places).

All DTrace headers, even <linux/dtrace_cpu.h> in the global kernel tree, have
had 'defines headers' split out of them, named ${header}_defines.h.  These
headers contain all typedefs, enums and #defines which do not depend on
visibility into structure definitions declared in the main non-defines header,
and opaque forwardings for all structure definitions declared in that header.
This means that users can include the defines header if they only want opaque
use of structures and relevant constants.  (This has necessitated some
mechanical changes to the DTrace headers to convert uses of foo_t typedefs into
'struct foo' where necessary.  Not all uses have been converted: only those that
need to be).  A _defines header is always accompanied by a corresponding non
_defines header (even if it is just one #include), but the reverse is not true.

In addition to this split, the core dtrace.h header has been split into three
pieces:

 - dtrace/include/uapi/linux/dtrace/*.h contains the majority of the headers,
   split into _defines and further by section roughly corresponding with the
   comment-delimited sections in the original file.  The include paths have been
   set up so that these can be used via

   #include <linux/dtrace/blah.h>

   in both userspace and kernelspace.

   #include <linux/include/dtrace.h> includes all the headers in the same order
   as they were originally.

   These headers are installed in userspace and used by dtrace-util.  They
   should always contain a CDDL license header, and should not use any
   kernel-specific types (modulo those that userspace normally uses, such as
   those related to kernel-specific functionality such as ioctl()).  If you use
   a new kernel-specific type, please add a definition of it to
   uts/common/sys/dtrace_types.h in userspace too.

   The old dtrace_ioctl.h has been renamed to <linux/dtrace/ioctl.h> and
   moved in here too.  It has gained some extra machinery to help debug
   ioctl() type size conflicts.  If you call dtrace_ioctl_sizes(), then
   dtrace_size_dbg_print() (not defined here) is repeatedly called with
   two parameters, the name of each ioctl() type and the size of that type.
   Please keep this list up to date, it is useful!

   There is one unfortunate exception to the userspace-types rule here:
   ioctl.h needs types from <linux/dtrace_cpu_defines.h>, which is not
   even a userspace-installed header.  So userspace must provide a copy of
   this header with appropriate typedefs as well.  (This should probably
   be fixed in due course.)

   <linux/dtrace/universal.h> defines constants and types used by virtually
   everything in any way related to dtrace.

 - dtrace/include/dtrace/*.h contains headers that are not shared with
   userspace, included as <dtrace/blah.h>:

   - <dtrace/types.h>: this contains the kernel-side definitions of types
     used in the shared headers.  (It has not been 'gardened' in any way,
     so probably contains a lot of other types as well).  This header is
     installed into the same place as the shared userspace headers.  This
     header needs a bit of care maintaining, as not everything kernel-
     side is allowable in it: see below.

   - <dtrace/provider.h>: The provider API, and its corresponding
     <dtrace/provider_defines.h> defines header.  This includes <dtrace/types.h>
     itself, so should be standalone -- however, this has not been in any way
     tested yet, unlike for the userspace headers.  This header is also
     installed into the same place as the shared userspace headers.

   - <dtrace/dtrace_impl.h> and <dtrace/dtrace_impl_defines.h>.

     These headers contain definitions used only by the DTrace core, and are
     not installed anywhere.

Note that because of the rules regarding kernel-specific types in the UAPI
DTrace headers, a number of uses of CONFIG_64BIT and CONFIG_BIG_ENDIAN have been
reverted to their Solaris-era-and-userspace _LP64 and _LITTLE_ENDIAN forms;
<dtrace/types.h> translates between the two.  (We have also fixed up a
couple of places in core DTrace where the nonexistent _BIG_ENDIAN was used.)

There are several things called dtrace.h now, which might get confusing:

- dtrace.h at the top level is for the DTrace core and included providers
  alone.  Anything goes in here.  It is never installed anywhere, and not even
  standalone providers can see it.

- dtrace/include/uapi/linux/dtrace/dtrace.h is shared with userspace and with
  standalone providers, and needs to follow the same rules as all such shared
  headers.

We have two new packages, dtrace-modules-$kver-headers and
dtrace-modules-$kver-provider-headers; to make it easy for people to Require
them, they provide features named 'dtrace-modules-headers' and
'dtrace-modules-provider-headers' using the same incrementing API version number
as 'dtrace-kernel-interface' (both currently 1).  dtrace-modules-headers serves
much the same purpose as dtrace-kernel-interface, tracking changes in the
userspace/kernelspace API: the dtrace-modules-provider-headers version number
tracks changes in the DTrace core/provider API.

The top-level Makefile has acquired two new rules, headers_install and
headers_check.  The former is a simple emulation of the top-level
headers_install rule, and is used by the RPM build system.  The latter checks to
be sure that the userspace-side headers can be #included on their own
(modulo only <unistd.h> et al, as above), and that dtrace/ioctl.h has all its
types in scope with appropriate sizes, since if they aren't everything will
appear to work until userspace tries to invoke the ioctl() and gets an -ENOTTY
error.

The latter is particularly difficult, since the size-checking machinery only
works for kernelspace builds, and the headers_check build is userspace.  So that
machinery hacks up a sort of halfway-house to the kernel environment, enough to
do the ioctl() size checks but not enough to #include arbitrary kernel
headers (among other things, there are no CONFIG constants here).  This means
that changes to those kernel-side headers which are included by this
machinery (in particular dtrace/types.h, dtrace_os.h) need to include a
headers_check run to make sure that machinery hasn't broken.  In general,
surrounding suspect definitions with an #ifndef HEADERS_CHECK should suffice:
nearly all of dtrace_os.h is so surrounded (and if we ever move dtrace_id_t out
into the shared headers, as perhaps we should, this problem will become less
serious).  (Feel free to make the headers_check dtrace/ioctl.h compilation
environment more like that used for the real kernel.)

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: blacklist certain structure members entirely
Nick Alcock [Mon, 25 Mar 2013 16:49:10 +0000 (16:49 +0000)]
ctf: blacklist certain structure members entirely

The problem of structures with identical names but conflicting members has
bitten dwarf2ctf before.  We defined a deduplication blacklist which prevents
specific modules from participating in deduplication, because they define a
structure with the same name as one in the shared type repository but with
different members.  This is, it turns out, not always enough.

Some kernel modules have begun to define structures with conflicting members in
different translation units within the same module.  There is no trick we can
use to help dwarf2ctf deal with this: each module gets one CTF file, covering
all that module's translation units, and if types have conflicting definitions
within that one module, there's nothing we can do: we must skip them entirely.
But we can limit the damage somewhat.

This commit adds a new blacklist, the 'member blacklist', stored in
scripts/dwarf2ctf/member.blacklist, which blacklists structure or union members
by name.  There are some limitations: only members of named structures and
unions can be blacklisted (not members of typedeffed, unnamed structures or
unions); and you can only blacklist types in the kernel tree, not types in
external modules.  Both of these restrictions can be lifted if it ever becomes
necessary, the latter quite easily.

The blacklist is of the form

filename:structure name.member name

The filenames are absolutized and compared with the filenames in the DWARF for
each structure member, both at emission time and when recursing to mark shared
types.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: repair faulty indentation
Nick Alcock [Mon, 25 Mar 2013 16:47:33 +0000 (16:47 +0000)]
ctf: repair faulty indentation

Part of assemble_ctf_su_member() got misidented.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: split the absolute-file-name caching machinery out of type_id()
Nick Alcock [Mon, 25 Mar 2013 16:45:52 +0000 (16:45 +0000)]
ctf: split the absolute-file-name caching machinery out of type_id()

We will be needing similar caching elsewhere in a forthcoming commit.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: sentinelize str_appendn()
Nick Alcock [Mon, 25 Mar 2013 16:43:49 +0000 (16:43 +0000)]
ctf: sentinelize str_appendn()

str_appendn() takes a variable argument list of items to append, terminated by a
NULL.  Every single time I have used it, I have forgotten the NULL.

Add a sentinel attribute to make it harder to forget in future.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoptrace: Add PTRACE_GETMAPFD.
Nick Alcock [Thu, 17 Jan 2013 14:25:40 +0000 (14:25 +0000)]
ptrace: Add PTRACE_GETMAPFD.

This request returns (in 'data') the file descriptor backing the mapping that
covers a given 'addr'.  This works even if the mapped file is unlinked and not
open anywhere besides this mapping.

New errors:

 -BADFD if the address is an anonymous mapping
 -EFAULT if the address is not mapped at all
 -PERM if the LSM does not permit the receipt of this file descriptor

Note that because the original fd is returned, you can access portions of it
outside the range of the original mapping (the use case for this, involving
acquiring ELF headers for executables and shared libraries that were unlinked
after mapping, relies on this).

This does not introduce a security hole because in order for the ptraced process
to mmap any file in the first place it must have had an fd to it, and the
ptracee could have accessed the outside-original-mapping portions at that point,
or simply forced the ptraced process to send it the fd via a Unix-domain socket
and held on to it.  There is no danger that an execute-only process can be read
by this mechanism either, since you cannot PTRACE_ATTACH to such a
process.  (Shared libraries cannot be execute-only at all.)

PTRACE_GETMAPFD is provisionally of value 0x42A5, in the architecture-
independent addition range, out-of-the-way so as not to collide with other
additions.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agodtrace: update execve() syscall probe support
Kris Van Hees [Thu, 7 Feb 2013 21:36:26 +0000 (16:36 -0500)]
dtrace: update execve() syscall probe support

The execve syscall stub and entry syscall function changed from 3.6 to 3.7 to
no longer pass a pointer to the registers from the stub to the entry syscall
function.  Instead, the entry syscall function now retrieves the registers
using current_pt_regs(), and passes it to the do_execve() function.  The DTrace
stub and override function have been updated to use the same mechanism.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: add support for an SDT probe getting called from multiple functions
Kris Van Hees [Thu, 7 Feb 2013 21:35:42 +0000 (16:35 -0500)]
dtrace: add support for an SDT probe getting called from multiple functions

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: move SDT call location for surrender probe
Kris Van Hees [Thu, 7 Feb 2013 21:35:09 +0000 (16:35 -0500)]
dtrace: move SDT call location for surrender probe

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: USDT implementation (Phase 1)
Kris Van Hees [Wed, 23 Jan 2013 09:53:14 +0000 (04:53 -0500)]
dtrace: USDT implementation (Phase 1)

This rather large patch provides the implementation for USDT support at the
DTrace kernel core level, and the fasttrap provider level.  It ensures that
executables can register their embedded providers (with USDT probes), that
the probes are visible to the dtrace userspace utility, and that probes are
properly removed upon executable completion, execve() invocation, or any
unexpected executable termination.

The following parts are provided by this patch:
- meta-provider support (dtrace_ptofapi)
- helper ioctl interface (dtrace_dev)
- DIF validation for helper objects (dtrace_dif)
- DOF processing for helpers for provider and probe definitions (dtrace_dof)
- fasttrap meta-provider for USDT only (fasttrap*)

The dtrace_helper.c file was removed because this code belongs in dtrace_dof.c
instead.

Minimal changes were made to the core kernel in exec.c, sched.h, exit.c, and
fork.c to add support for process-specific helpers (and those encapsulate
providers and probes).

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: remove incorrect FBT support code
Kris Van Hees [Wed, 23 Jan 2013 09:50:06 +0000 (04:50 -0500)]
dtrace: remove incorrect FBT support code

Code that was supporting an early implementation of FBT was still left hanging
in the source code tree.  This patch removes it in preparation for a more
generic and above all, correct (and stable) implementation.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: move psinfo to its own header file
Kris Van Hees [Wed, 23 Jan 2013 09:47:21 +0000 (04:47 -0500)]
dtrace: move psinfo to its own header file

The psinfo structure definition and related function prototypes have been moved
to their own header file to avoiding including dtrace_os.h in sched.h.  This is
also one step closer to providing the psinfo as a more generic piece of info,
rather than it being dtrace specific.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: update copyright statements
Kris Van Hees [Wed, 23 Jan 2013 09:37:30 +0000 (04:37 -0500)]
dtrace: update copyright statements

Various updates were made to files in the past months, and copyright statements
were never updated to reflect that.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agoctf: update the shared CTF file right after initialization
Nick Alcock [Thu, 22 Nov 2012 09:34:41 +0000 (09:34 +0000)]
ctf: update the shared CTF file right after initialization

If we don't do this, the void and function pointer types are not available for
lookup until something else gets added to the shared type repository and
triggers an update, so insertions of types depending on such types into the
shared type repository will fail until that happens.  Since function pointers
are seen a lot in structures in the Linux kernel, such a failure for a member of
a structure means that all later members of the structure are skipped, and since
a major cause of insertion into the shared type repository is recursive
insertion from structure members in headers, this has the effect of losing track
of quite a lot of types first seen in translation units mentioned early on the
dwarf2ctf command line.  Fortunately, since they haven't been successfully
inserted, insertion is retried later and succeeds.  So this bugfix fixes a
latent bug only.

We would have seen this long ago as a bunch of error output were it not for a
bug in libdtrace-ctf leading to bad ID errors in CTF lookups that recurse to
parents not being emitted anywhere we were looking for them.  Fixing that bug
requires us to fix this one, lest we get bombed with error messages
henceforward.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: Improve debugging and indentation fixes
Nick Alcock [Thu, 22 Nov 2012 09:30:11 +0000 (09:30 +0000)]
ctf: Improve debugging and indentation fixes

Reporting the type ID helps us determine when types used later on are
introduced.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: dwarf2ctf doc revisions
Nick Alcock [Wed, 10 Oct 2012 13:23:31 +0000 (14:23 +0100)]
ctf: dwarf2ctf doc revisions

Mostly small rewordings and reshufflings for clarity, and the introduction of a
program-wide flow graph, and a flow graph in each section.  (One hopes they
don't get out of date too fast.)

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agodtrace: internal performance measurement support code
Kris Van Hees [Fri, 19 Oct 2012 08:37:53 +0000 (04:37 -0400)]
dtrace: internal performance measurement support code

The dt_perf provider implements a few probes that are used in performance
(or more accurately put, overhead) measurements.  It uses an ioctl()
interface to trigger N-count interations of invoking probes through
various mechanisms, and a probe to post the results back to userspace.
This code also adds an SDT probe in the DTrace kernel support code, just
to measure overhead for triggering trap based SDT probes.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agokvm / dtrace: disable KVM steal-time accounting when DTrace is in use
Nick Alcock [Thu, 18 Oct 2012 16:11:25 +0000 (17:11 +0100)]
kvm / dtrace: disable KVM steal-time accounting when DTrace is in use

This feature does clocksource work in interrupt context, which interoperates
badly with the DTrace probes there.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: cosmetic improvements to CTF linking
Nick Alcock [Thu, 18 Oct 2012 16:01:57 +0000 (17:01 +0100)]
ctf: cosmetic improvements to CTF linking

DWARF2CTF is too long a tag: CTF aligns better.

We should also not carry around the CONFIG_MODULE_SIG ctf module-name-setting
code while module signing is not present in this kernel.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agodtrace: remove a few obsolete probes
Kris Van Hees [Thu, 18 Oct 2012 15:57:47 +0000 (16:57 +0100)]
dtrace: remove a few obsolete probes

The handle_sysrq, init_module and delete_module probes were for testing purposes
only.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: cater for changes in the way the kernel is linked
Kris Van Hees [Thu, 18 Oct 2012 15:56:46 +0000 (16:56 +0100)]
dtrace: cater for changes in the way the kernel is linked

3.6 started linking using a shell script, scripts/linux-vmlinux.sh, rather than
the old hair in the top-level Makefile. The SDT stub creation has to move in
there too.

Also, skip debugging sections explicitly when hunting for SDT probes in objdump
output.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: miscellaneous 3.6 porting work
Kris Van Hees [Thu, 18 Oct 2012 15:53:56 +0000 (16:53 +0100)]
dtrace: miscellaneous 3.6 porting work

Missing headers, catering for header movement, the occasional missing
prototype, and changes in the way the syscall table is built.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: fix up rq.dtrace_cpu_info member
Kris Van Hees [Thu, 18 Oct 2012 15:50:21 +0000 (16:50 +0100)]
dtrace: fix up rq.dtrace_cpu_info member

This moved into sched.h in 3.6, so the member must move there too.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agogitignore: Ignore objects.builtin and dwarf2ctf.
Nick Alcock [Thu, 18 Oct 2012 15:44:43 +0000 (16:44 +0100)]
gitignore: Ignore objects.builtin and dwarf2ctf.

These are generated files.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agodtrace: fix outright typos in the 3.6 forward-port.
Nick Alcock [Thu, 18 Oct 2012 15:43:30 +0000 (16:43 +0100)]
dtrace: fix outright typos in the 3.6 forward-port.

The mass cherry-pick of 3.6 support introduced some build-breaking typos.  This
fixes them (fixing here rather than where introduced for simplicity's sake and
because we don't really expect past history to be compilable against 3.6 without
changes).

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agodtrace: remove obsolete static probe documentation
Kris Van Hees [Thu, 18 Oct 2012 15:41:28 +0000 (16:41 +0100)]
dtrace: remove obsolete static probe documentation

This is outdated and useless.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agoctf: DTrace-independent CTF
Nick Alcock [Wed, 10 Oct 2012 18:37:49 +0000 (19:37 +0100)]
ctf: DTrace-independent CTF

These largely cosmetic changes remove mention of DTrace from the CTF code,
making it clear that it is freely usable by non-DTrace consumers.

The changes are:

 - dtrace_ctf.ko is now named ctf.ko, and is stored in kernel/ctf rather than
   kernel/dtrace, controlled by a new CONFIG_CTF Kconfig option select'ed by
   CONFIG_DTRACE.  (CONFIG_DT_DISABLE_CTF, being largely a DTrace debugging
   option, remains under DTrace configure control).  The function used to
   trigger loading of ctf.ko has changed name similarly, from
   dtrace_ctf_forceload() to ctf_forceload().

 - The CTF section names have changed, from .dtrace_ctf.* to .ctf.* (which as a
   bonus is more obviously related to the .ctf directory long used to store the
   CTF data during the build process).

 - The shared CTF repository is now stored in .ctf.shared_ctf instead of
   .dtrace_ctf.dtrace_ctf, making its intended use somewhat clearer.

These changes depend on a suitably changed libdtrace-ctf: a suitably changed
userspace is needed to take advantage of them.  The dtrace-kernel-interface is
bumped accordingly.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: do not build in CTF data for no-longer-built-in modules
Nick Alcock [Wed, 10 Oct 2012 18:30:42 +0000 (19:30 +0100)]
ctf: do not build in CTF data for no-longer-built-in modules

The module-ctf-flags code in Makefile.modpost uses $(wildcard) to include CTF
for all built-in modules (named *.builtin.ctf) inside dtrace_ctf.ko without
needing to know what its name is.  Unfortunately, if the .config is changed to
make a built-in module modular, or to not build it at all, a stale .builtin.ctf
file persists, and is built in to dtrace_ctf.ko despite the absence of any
module corresponding to it.

Since all .builtin.ctf files are regenerated (named .builtin.ctf.new) on every
dwarf2ctf run, the solution is to delete .builtin.ctf files without corresponding
.new files on every dwarf2ctf run.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: document dwarf2ctf
Nick Alcock [Wed, 3 Oct 2012 18:37:16 +0000 (19:37 +0100)]
ctf: document dwarf2ctf

dwarf2ctf is complex enough and has enough tricky corners that it really, really
needs some documentation.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: Extend the deduplication blacklist
Nick Alcock [Wed, 3 Oct 2012 18:36:10 +0000 (19:36 +0100)]
ctf: Extend the deduplication blacklist

A quick audit of the kernel suggests two more modules that need blacklisting
from deduplication due to #inclusion of translation units also used in other
modules while using #defines to change the definitions of structures defined in
those translation units.  Neither module is built by default by OEL, and both
are ancient ISA sound cards so are unlikely to be encountered by anyone else
either.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: Improve error message on internal deduplication error
Nick Alcock [Wed, 3 Oct 2012 18:32:09 +0000 (19:32 +0100)]
ctf: Improve error message on internal deduplication error

We should at least emit the name of the variable we are looking up (if possible)
as well as the name of the variable we are working over.  (Often this will be
unknown, but not always.)

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: Note a future enhancement
Nick Alcock [Wed, 3 Oct 2012 18:31:10 +0000 (19:31 +0100)]
ctf: Note a future enhancement

In -DDEBUG mode, we should not assume that identically-named structures with
different numbers of members are declarations of the same structure with a
shared prefix, but should validate it.  (The compiler cannot always verify this,
e.g. if the same structure is defined in multiple translation units.)

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: document parameters to die_to_ctf()
Nick Alcock [Wed, 3 Oct 2012 18:29:23 +0000 (19:29 +0100)]
ctf: document parameters to die_to_ctf()

This function has enough parameters that systematically describing them is
necessary if one is not to become frequently confused.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: do not construct objects.builtin if CTF is not being built
Nick Alcock [Mon, 24 Sep 2012 11:05:09 +0000 (12:05 +0100)]
ctf: do not construct objects.builtin if CTF is not being built

This file is used only for the dwarf2ctf run inside Makefile.modpost.  That run
is conditionalized on CONFIG_DT_DISABLE_CTF, so objects.builtin should be
conditionalized on that too.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: do not build dwarf2ctf nor attempt to use it if !CONFIG_DTRACE
Nick Alcock [Thu, 13 Sep 2012 18:18:10 +0000 (19:18 +0100)]
ctf: do not build dwarf2ctf nor attempt to use it if !CONFIG_DTRACE

We were already not using it for the CONFIG_DT_DISABLE_CTF case, but not
suppressing its build nor noting the !CONFIG_DTRACE case properly.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agodtrace: additional action support (and bug fixes)
Kris Van Hees [Sun, 9 Sep 2012 21:34:48 +0000 (17:34 -0400)]
dtrace: additional action support (and bug fixes)

Removed ASSIST_* definitions because they are no longer necessary (though they
may come back in the future).

Changed the behaviour of DTrace in interrupt context to base it on in_irq()
rather than in_interrupt().

On Linux it is always safe to dereference current, so there is no need to do
special casing on various process-based DIF functions.  There is no need to
fake values coming from the 0-pid process.

Added curcpu variables.

Added d_path() function.  This takes a struct path and turns it into a string.

Renumbered the register IDs to match the xlator support at userspace, and to
also match the on-stack order of registers.

Have dtrace_getreg() operate on the task rather than just a set of registers,
because (in 64-bit mode) segment registers have their value stored in fields
in the process-specific task info.

Implemented the raise() action.

Changed the deadman interal to 10s, and timeout/user to 120s.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: add psinfo/cpuinfo OS level support
Kris Van Hees [Sun, 9 Sep 2012 21:27:14 +0000 (17:27 -0400)]
dtrace: add psinfo/cpuinfo OS level support

Added a member to the task structure, to hold DTrace specific process info.  It
stores (up to) the first 79 characters of the command line (with arguments),
as required for the pr_psargs elements in psinfo_t.  It also stores the number
of initial arguments (pr_argc), and the initial argument (pr_argv) and
environment variable (pr_envp) vectors.

This process information is pre-populated when an execve takes place in the
current task.  Note that if a process alters the arguments, this altertation
will be visible when pr_argv is consulted, and thus returned argument strings
may not match the originally provided values.

Enforce that invop handlers return a uint8 value, to be used in the future for
knowing what instruction to emulate upon return from an invop trap.

Added per-cpu CPU information that is used to provide cpuinfo_t data.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: change the DTrace startup handling (at boot time) for SDT
Kris Van Hees [Sun, 9 Sep 2012 21:18:42 +0000 (17:18 -0400)]
dtrace: change the DTrace startup handling (at boot time) for SDT

The DTrace OS level handling was initialized at DTrace module load, which
caused major indigestion on the side of the scheduler when SDT probe points at
crucial locations in the scheduler were being patched by one CPU while another
was trying to get some real work done.  Even a nice stop_machine() based
approach turned out not to be possible, because that *cough* depends on the
scheduler also.

Instead, the DTrace OS support is initialized from the Linux boot sequence,
before SMP is enabled, which removes the complications altogether (and it is a
lot cleaner and faster).  We also call CPU-specific initialization for DTrace
during the boot sequence, albeit *after* the CPUs have been identified for SMP,
to ensure that we get accurate information.

Renamed sdt_register.c to be dtrace_sdt.c (for consistency).  And implemented
a better patching of SDT probe points.

Added a 'nosdt' kernel command line option to allow system wide diabling of
SDT probe points (at the kernel level).  This can be used when the patching of
SDT probe points somehow causes a problem.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: cleanup (and adding) of SDT probe points
Kris Van Hees [Sun, 9 Sep 2012 20:56:15 +0000 (16:56 -0400)]
dtrace: cleanup (and adding) of SDT probe points

Changed io SDT probe points to be located at the buffer_head level rather than
the bio level.  This may need to be revisted depending on further analysis,
but doing it this way provides consistent semantics that were not guaranteed by
the previous bio-based placement.

Changed the sched STD probes to not pass irrelevant arguments, and to pass
specific runqueue CPU information.  The CPU information is not available from
the task structure, so it needs to be passed explicily.

Added proc SDT probes start and lwp-start.

Added proc SDT probes for signal-discard and signal-clear.

Corrected the argument to the exit proc SDT probe, which should indicate the
reason for the process termination (exit, killed, core dumped) rather than the
return code of the process.

Provided argument information for all the new (and changed) SDT probe points.
This depends on working xlator support in userspace.

Enabling of SDT probes now uses a generic dtrace_invop_(enable|disable) rather
than SDT-specific functions.

SDT probes are not destroyed correctly, to ensure that subsequent uses will not
result in unpleasant events.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agoctf: write the CTF files for standalone modules to a subdir of the module dir
Nick Alcock [Fri, 7 Sep 2012 19:26:17 +0000 (20:26 +0100)]
ctf: write the CTF files for standalone modules to a subdir of the module dir

Writing all ctf to the .ctf subdirectory of the kernel directory is problematic
when building standalone modules, when the kernel directory may be unwritable.
So write it to the .ctf subdirectory of the module directory in this case
as well.  (The old .ctf relative path was hardwired into dwarf2ctf, so this
too is changed to accept the path to write the CTF files to as the first
parameter, in both non-standalone and standalone mode.)

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: unnamed structure/union support
Nick Alcock [Wed, 29 Aug 2012 13:18:57 +0000 (14:18 +0100)]
ctf: unnamed structure/union support

Since neither CTF nor DTrace userspace have support for unnamed structure/union
members, we have to cheat a bit.  We can model an unnamed structure member as
being precisely equivalent to simply naming the structure members in the
enclosing structure, with their offsets biased by the offset of the unnamed
member in its enclosing structure.  An unnamed union is the same, excepting the
overlapping offsets, which we don't need to pay any attention to since we
already get all our offset information directly from the debugging information
anyway.

So we handle this by detecting an anonymous member after offset computation,
skipping to its type DIE's first child (if any), and calling die_to_ctf()
directly with that child, so that die_to_ctf() works over the anonymous member's
members as if they were members of the enclosing structure, skipping all the
usual addition of that structure as a CTF entity in its own right.  We handle
the offset biasing by adding a parent_bias to die_to_ctf() and all CTF
construction functions, and adding that bias to all structure member offsets.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: recurse_ctf() -> die_to_ctf()
Nick Alcock [Wed, 29 Aug 2012 11:27:06 +0000 (12:27 +0100)]
ctf: recurse_ctf() -> die_to_ctf()

This function is badly named: sure, it's recursive, but so are half a dozen
other functions in dwarf2ctf.  Its callers do not care that it is recursive:
they care that its function is to translate a DWARF DIE to CTF.

So rename it accordingly.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: fix the signed-modules case
Nick Alcock [Fri, 10 Aug 2012 22:52:19 +0000 (23:52 +0100)]
ctf: fix the signed-modules case

The code in Makefile.modpost's module-ctf-flags variable which computes the name
of the CTF file, given the name of the kernel module being linked, was torpedoed
by the name of the unsigned module that is linked when module signing is in use.
So introduce a new ctf-module-name variable that substitutes the name
appropriately given the state of module signing.

Also, fix up some related places where I used spaces instead of tabs by mistake.

(3.6: most signed-modules code omitted, but a bit of supporting code remains
 in readiness for signed modules in 3.7.)

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: correctly propagate IDs for array types
Nick Alcock [Thu, 9 Aug 2012 23:54:55 +0000 (00:54 +0100)]
ctf: correctly propagate IDs for array types

We were constructing things of array type wrongly, for a rather interesting
reason.

DWARF describes an array by putting its base type in the parent DIE, then
describing its bounds in the child DIE.  Unfortunately, this puts us in an
unfortunate position: we always visit the parent before its children (so we can
build things like structures before filling their members in) -- but you can't
build a CTF array without knowing what its bounds are ('flexible' is not the
same as 'we don't know yet') -- and we *do* need the base type to be constructed
anyway.  So we constructed the base type when working over the parent DIE, then
wrapped an array around it when we visited the children where the dimensions
were described (possibly more than one for a multidimensional array: though GCC
happens not to emit those for C, it is permitted to, and handling it is easy, so
we do).  Unfortunately, recurse_ctf() throws away the type ID returned from
child DIEs, so the CTF ID that gets stashed for assignment to things of that
array type (when they are looked up via lookup_ctf_type()) turns out not to be
an array type at all, but the base type!

So we add an optional override parameter to recurse_ctf() and to all the
construction functions: it is passed only by recursive recurse_ctf() calls (when
processing child DIEs): it is set nonzero by construction functions that wrap
and replace the ID from their parent DIE, and when it is set, the type ID
returned by the construction function replaces the type ID that recurse_ctf()
passes back to its parent.  Now assemble_ctf_array_dimension() just needs to
set this override parameter, and all is well.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: fix off-by-one in emitted array bounds
Nick Alcock [Thu, 9 Aug 2012 23:33:14 +0000 (00:33 +0100)]
ctf: fix off-by-one in emitted array bounds

We were treating arrays described by DW_AT_count and DW_AT_upper_bound
identically, but in a language like C with zero-based arrays they are not:
DW_AT_upper_bound does not give the number of members unless you add one
to it.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agodtrace: fix tiny comment typo
Nick Alcock [Tue, 7 Aug 2012 08:47:09 +0000 (09:47 +0100)]
dtrace: fix tiny comment typo

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: blacklist certain modules from deduplication
Nick Alcock [Tue, 7 Aug 2012 08:46:38 +0000 (09:46 +0100)]
ctf: blacklist certain modules from deduplication

sound/pci/ens1371.c #includes another file, ens1370.c, with a #define
that changes the definition, but not name, of a single structure.

While this grotesquerie is permitted in C, there's no way that translation units
that engage in it can be permitted to share types with other translation units.
More specifically, types defined in such TUs must not be permitted to transform
a non-shared type to shared by virtue of their being detected in such TUs.

I'd like to detect the redefined structures themselves, but since the
preprocessor trickery leaves no mark in the DWARF another pass would be
necessary just to detect this. It's easier -- and faster -- to introduce a
blacklist of modules that do things like this and simply turn deduplication
scanning off for these modules. (Because they are still allowed to reuse
duplicates found in other modules, this does not increase their size
appreciably.)

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: include enumeration types inside functions
Nick Alcock [Mon, 6 Aug 2012 18:06:38 +0000 (19:06 +0100)]
ctf: include enumeration types inside functions

Like structures and unions, enumerations are a named type in their own
namespace: like structures and unions, arrays and other types based on such
types are represented by a DWARF DIE outside all functions. So the duplicate
detector must treat them like structures and unions, and include them even
if they are inside functions.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agodtrace: new IO and sched provider probes
Kris Van Hees [Mon, 6 Aug 2012 09:01:08 +0000 (05:01 -0400)]
dtrace: new IO and sched provider probes

New IO provider probes: start, done, wait-start, wait-done

New sched provider probes: enqueue, dequeue, wakeup, preempt, remain-cpu,
change-pri, surrender

(Note that the preempt probe currently passes a debugging argument that
will be removed in the future to match the argument-less version in the
documentation.)

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: fix to handle multiple SDT-based probes in a single function
Kris Van Hees [Wed, 1 Aug 2012 14:05:30 +0000 (10:05 -0400)]
dtrace: fix to handle multiple SDT-based probes in a single function

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: require assembler symbol stripping and debug info
Nick Alcock [Tue, 31 Jul 2012 17:35:57 +0000 (18:35 +0100)]
dtrace: require assembler symbol stripping and debug info

The former is needed because dt_module.c doesn't know how to ignore assembler
labels when reading module symbol data: the latter because dwarf2ctf reads the
types out of debug info.

Use select rather than require because both of these requirements are distinctly
non-obvious and we don't want to force people to hunt about for them.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: fix array dimensions
Nick Alcock [Tue, 31 Jul 2012 17:33:58 +0000 (18:33 +0100)]
ctf: fix array dimensions

Due to a premature optimization (in, admittedly, speed-critical code) and
mistakenly forgetting that dwarf_formudata() does not return its result like
dwarf_whatform(), all arrays were considered to be flexible arrays of unknown
dimension.

Also, the type ID representation for arrays was uniquely ugly in that it lacked
a trailing space after the close ].

(Both fixed.)

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: change the name of the CTF section in kernel modules
Nick Alcock [Mon, 30 Jul 2012 21:33:44 +0000 (22:33 +0100)]
ctf: change the name of the CTF section in kernel modules

Since we have broken backward-compatibility with Solaris libctf and changed the
magic number in CTF files, we should change the name of the section they are
written to. .dtrace_ctf seems like a good idea (which means that shared types
will now be found in the .dtrace_ctf.dtrace_ctf section, rather than, as
before, .SUNW_ctf.dtrace_ctf).

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agodtrace: fix a bug in the SDT probe location generator
Kris Van Hees [Mon, 30 Jul 2012 19:03:45 +0000 (15:03 -0400)]
dtrace: fix a bug in the SDT probe location generator

The generator could accidentally add the address of a non-function
identifier to the SDT list (e.g. watchdog occurs both in the
uninitialised data section (BSS) and the text section).

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agoctf: major duplicate detection fixes
Nick Alcock [Mon, 30 Jul 2012 18:21:15 +0000 (19:21 +0100)]
ctf: major duplicate detection fixes

The duplicate detector had numerous faults.  Among the situations it couldn't
handle:

 - a shared structure 'struct foo' visible in both opaque and non-opaque form,
   with an identically-sized array, pointer, or other entity referring to that
   type in both modules where the type was visible only as an opaque type and
   types where it was visible non-opaquely.

 - any situation in which a member of a shared structure points to a structure
   which would not be shared but for that (and so on, for as many repeated
   points-tos as one wishes)

 - situations in which structures had anonymous structures contained within
   themselves that were used as types for members within the outermost
   structure, whether or not either was shared, e.g.

   struct foo {
       struct {
           int womble;
       } *baz;
   };

   In this situation, the innermost struct would not be noted by the duplicate
   detector, which would lead to a failure to assemble the type later on, as CTF
   assembly can't tell what CTF file it belongs in.

A large-scale rewrite was needed for this, transforming the duplicate detector
from a three-pass scheme with one sharer-of-all-obviously-duplicated-types
running first and last and one detector of transparent/opaque struct/union
aliasing running in the middle, into a scheme where the sharer-of-all runs once,
then the alias detector runs repeatedly, sharing opaque types for which the
corresponding transparent types are already shared, and recursively sharing
transparent types for which the opaque ones are already shared: in the latter
case, it triggers another rerun of the alias detector, in case that recursive
sharing run marks more structures as shared (opaque or transparent).

Worse yet, when we mark a type 'struct foo' as shared, this may not be enough --
there may be types which use that type as a base type which should also be
shared. So the alias detector now runs over not just all structures and unions
but all types which have structures and unions as an ultimate base type,
checking at each level of descent towards the structure whether sharing is
required, and recursively sharing everything from that level down if such is
needed.  (This is done with a type_id() callback, like everything that
involves descending DWARF type use/def chains.)

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: optimize type_id() and fix array dimension lookup
Nick Alcock [Mon, 30 Jul 2012 18:08:49 +0000 (19:08 +0100)]
ctf: optimize type_id() and fix array dimension lookup

type_id() is the single hottest hot spot in dwarf2ctf, and had a number of
more or less severe performance problems:

 - we were calling str_append() where str_appendn() would do, incurring more
   realloc()s and strlen()s than necessary.

 - when calling type_id() for types such as structure members that have the same
   type-id representation as their reffed type, we were calling the hook
   function even though it's already been called with that ID by our recursive
   call on the reffed type.  Some hook functions are quite expensive, so this
   is probably a bad idea.

 - we were calling realpath() once per call, although a very limited number of
   input arguments are expected (one per translation unit) and the mapping from
   input to output never changes.  This is a perfect candidate for caching.

The latter in particular has a vast impact on dwarf2ctf performance, reducing it
by around 80% in my tests.

str_append() and str_appendn() themselves were suboptimal, taking the length of
their arguments more times than necessary and calling realloc() more often than
required (once per argument after the first in the case of str_appendn().)
Now that we are using str_appendn() more heavily, this becomes a significant
contributor to runtime, so this is fixed too.

Further, array dimension lookup (both in type_id() and in
assemble_ctf_array_dimension()) was broken due to looping past the first array
dimension without looking at it.  This tended to cause false sharing of
actually-distinct types (all one-dimensional arrays were treated as the same
type regardless of dimension, and since C only has one-dimensional arrays...)

We also add some comments noting that the format of type_id() and the
by-hand-constructed type IDs in the alias fixup code must be kept aligned, since
the breakage when this is not so is quite obscure and hard to figure out.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agodtrace: changed the logic for determining SDT probe point locations
Kris Van Hees [Sun, 29 Jul 2012 08:30:18 +0000 (04:30 -0400)]
dtrace: changed the logic for determining SDT probe point locations

The previous version did not account for probes that might be placed in
non-.text segments.  New code also avoids extra passes that were not necessary.

Added on-cpu and off-cpu sched probes.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agoctf: store away the types and names of non-static global variables
Nick Alcock [Sat, 28 Jul 2012 11:50:44 +0000 (12:50 +0100)]
ctf: store away the types and names of non-static global variables

The critical part of this change is assemble_ctf_variable(), which calls the new
ctf_add_variable() function to add a variable and its type information to the
appropriate CTF file (as determined by the deduplication pass).

Because we scan all scopes to detect non-opaque definitions of structures,
unions and enums used opaquely at global scope, and the functions called for
each DIE we understand tend to be quite expensive, we also introduce an
additional filtration mechanism (the 'assembly filter') to prevent DWARF tree
walks from calling an assembly function for DIEs we are not interested in.

We don't provide as much information to the assembly filter as to the assembly
function itself -- just the DIE and its parent DIE -- but that is enough to
prevent the assembly function from being called not only for variables but also
for base types, arrays, crv-qualified types, and pointer types at non-global
scope -- none of which we are interested in, since we care only about named
structures/unions/enums at non-global scope, and e.g.

typedef struct foo {
 ...
} *bar;

is represented as *three* DWARF nodes at the same level, one for 'struct foo',
one for a pointer to it, and one for a typedef of that.  So there is no danger
that avoiding processing for such types will miss the structures we are
interested in.

For variables, we filter out all 'uninteresting' types using a new filter
function which rules out not only 'variables' with no name, static variables,
and variables at non-global scope, but also a large number of specifically-
named global variables introduced by macros to cover facilities as diverse as
tracepoints and the kernel symbol table.  There is no chance that DTrace users
would want to look at these variables, so we don't need to store them in the
CTF.  (We don't need to consider points-to relationships for variables, unlike
types, so that consideration does not apply.)

DTrace userspace contains a similar list to avoid reading in uninteresting lines
from /proc/kallmodsyms, but the two need not be synchronized: CTF for variables
that DTrace is filtering out will simply never be consulted, and variables that
DTrace does not filter out but that have been filtered out by dwarf2ctf will
have no CTF and will simply be rejected at parsing time.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: set the name of the parent of child modules to "dtrace_ctf"
Nick Alcock [Wed, 25 Jul 2012 20:07:21 +0000 (21:07 +0100)]
ctf: set the name of the parent of child modules to "dtrace_ctf"

This is possible now that libdtrace-ctf has grown the ctf_parent_name_set()
function.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: clarify comments, improve a type name
Nick Alcock [Wed, 25 Jul 2012 20:06:28 +0000 (21:06 +0100)]
ctf: clarify comments, improve a type name

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: force dtrace_ctf.ko to be loaded whenever dtrace.ko is
Nick Alcock [Fri, 20 Jul 2012 22:00:07 +0000 (23:00 +0100)]
ctf: force dtrace_ctf.ko to be loaded whenever dtrace.ko is

DTrace userspace makes the simplifying assumption that dtrace_ctf.ko (containing
the CTF for the kernel, for built-in modules, and for shared types, but no code)
is always loaded whenever DTrace is usable.  (The CTF itself is in a non-loaded
section, but having dtrace_ctf.ko in the list of loaded modules means that we
can eliminate an annoying set of dtrace_ctf-related special case.)

We do this by introducing a dummy function dtrace_ctf_forceload() into the
dtrace_ctf module, which DTrace then calls: depmod will then arrange for
dtrace_ctf to be loaded when we need it.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: generate CTF information for the kernel
Nick Alcock [Fri, 11 May 2012 15:59:13 +0000 (16:59 +0100)]
ctf: generate CTF information for the kernel

This introdues a new tool, dwarf2ctf, which runs at modpost time whenever any
module or any part of the core kernel is changed, extracting the debugging
information from the kernel build tree, deduplicating it, and emitting it in
Sun's Compact Type Format into gzipped files in a new .ctf directory.  These
files are then linked into the kernel modules as new sections named .SUNW_ctf.

One file is emitted per kernel module, whether builtin or no, as well as one
file for types that are used by no modules, and one file for types shared
between more than one of the other files.  As the built-in modules and shared
types have no module of their own to go into, they are placed in a new
dtrace_ctf.ko module (which serves no other purpose: loading it is useless).
DTrace userspace will no longer start if this module is not present.

Due to the extensive sharing of types, dwarf2ctf must run whenever any object
files at all are changed, and may trigger relinks of modules that you would not
otherwise think had changed.

Standalone modules also have CTF generated for them, but never share types with
any other modules.

Because dwarf2ctf is slow enough to be annoying when running frequent kernel
builds to debug some unrelated problem, a new CONFIG_DT_DISABLE_CTF debugging
configuraton option is added, which suppresses CTF generation entirely.

This commit introduces new kernel build-time dependencies on elfutils and the
new libdtrace-ctf package (shared with dtrace userspace).  No new runtime
dependencies are introduced.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agokallsyms: provide symbol sizes in /proc/kallmodsyms
Nick Alcock [Fri, 29 Jun 2012 20:06:28 +0000 (21:06 +0100)]
kallsyms: provide symbol sizes in /proc/kallmodsyms

For modules, we can simply extract these sizes from the module symtab; for core
kernel symbols, we must do subtraction as get_symbol_pos() did: this is now
abstracted into a new get_symbol_size().

Because /proc/kallmodsyms contains *all* symbols, where get_symbol_pos() was
normally only called for a small subset of symbols, this exercises this code
like never before, and has revealed a bug: the size of __per_cpu_end was being
returned as a ludicrously vast value, because the next symbol after
__per_cpu_end is far up the address space, in the kernel proper. Fixing this by
forcing a size of zero for __per_cpu_end is easy enough.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agoctf: add a dummy dtrace_ctf.ko module
Nick Alcock [Wed, 20 Jun 2012 18:43:22 +0000 (19:43 +0100)]
ctf: add a dummy dtrace_ctf.ko module

Without this, the latest dtrace userspace will not start.
(This will soon be filled with cross-module and core-kernel CTF data.)

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agokallsyms: fix /proc/kallmodsyms population bugs
Nick Alcock [Mon, 18 Jun 2012 15:57:59 +0000 (16:57 +0100)]
kallsyms: fix /proc/kallmodsyms population bugs

scripts/kallsyms was failing to identify variables local to modules as being in
those modules, which is unfortunate because a large number of DTrace module
references are to data symbols.

This is easily enough fixed by recording variable references as well as function
references, which was all we were tracking before this. Alas, this breaks our
heuristic that symbols whose names are seen more than once must be outside all
modules, because external variable references can be seen multiple times inside
a single module even when the thing they are a reference to is also inside that
module.  The fix to this is to differentiate between 'names seen in this module'
and 'names seen in prior modules', recording newly-seen names in the former list
and moving them en masse to the latter when we switch from scanning one module
to scanning another.  We can then define a symbol as being 'not in any module'
iff it is seen while present in the names-seen-in-prior-modules list: a symbol
that is seen repeatedly but only inside a single module's object file is still
considered to be part of that module under this scheme.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agokallsyms: work in a clean tree, and a non-modular tree.
Nick Alcock [Mon, 14 May 2012 10:24:44 +0000 (11:24 +0100)]
kallsyms: work in a clean tree, and a non-modular tree.

kallsyms nowadays relies upon modules.builtin, so we must make sure that
modules.builtin is there before kallsyms runs.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agokallsyms: work with older glibc.
Nick Alcock [Mon, 14 May 2012 10:22:32 +0000 (11:22 +0100)]
kallsyms: work with older glibc.

Before glibc 2.10, getline() was under _GNU_SOURCE.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agokallsyms: add /proc/kallmodsyms
Nick Alcock [Fri, 11 May 2012 20:21:33 +0000 (21:21 +0100)]
kallsyms: add /proc/kallmodsyms

This procfile (controlled by CONFIG_KALLSYMS), introduces a new
/proc/kallmodsyms whose contents are the same as /proc/kallsyms, except that the
module name is provided even for built-in modules, as long as they could
potentially have been built as separate kernel modules.  DTrace will use it in
future to allow users to use the same module names in their D scripts regardless
of whether the modules are built-in or not in the kernel they happen to be
running.

This is done by scanning the object files named in the builtin.modules file
using libelf, extracting their function symbols, pruning out any symbols which
appear in more than one builtin module (since these are probably out-of-line
copies of inline functions in common kernel header files), then emitting the
names of all the modules in a new kallsyms_modules symbol and pointing at the
appropriate modules in a kallsyms_symbol_modules symbol which maps 1:1 to the
contents of kallsyms_addresses (thus, one kallsyms_symbol entry per kernel
symbol in /proc/kallsyms).  Always-built-in functions have a corresponding
kallsyms_symbol_modules index of zero.

This is not terribly space-efficient: the kallsyms_symbol_modules symbol is
quite large (~250K, mostly zeroes, four bytes per kernel symbol), but reducing
this requires some other way to signal that a symbol is not present in a module.
It is much smaller than even the compressed representation of the symbol names.

Possible future enhancements, low priority:
 - use a home-cooked hashtable rather than glib (pointless unless dwarf2ctf is
   similarly rejigged)
 - use nm rather than elfutils (liable to be quite a lot slower)
 - find a more robust way of detecting inlined functions, not fooled by
   out-of-line copies of inlined functions which happen to be used by
   only one module
 - shrink the kernel symbol space consumption, perhaps by using shorts rather
   than longs for the module offsets (65536Kb of module names should be enough
   for anybody)

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agodtrace: add sched-tick SDT probe and FBT probe point discovery/creation
Kris Van Hees [Thu, 19 Apr 2012 21:19:40 +0000 (17:19 -0400)]
dtrace: add sched-tick SDT probe and FBT probe point discovery/creation

Move code around for the kernel pseudo-module handling since it gets used
by both the SDT code and the FBT code.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: use new mutex_owned(), not mutex_is_locked()
Kris Van Hees [Tue, 7 Feb 2012 09:31:48 +0000 (04:31 -0500)]
dtrace: use new mutex_owned(), not mutex_is_locked()

This is used in our implementation of the Solaris MUTEX_HELD() macro.
The former was merely testing whether the mutex was locked, whereas
the real test needed here is whether the mutex is held by the current thread.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: fix signed division and modulo operations in DIF
Kris Van Hees [Tue, 17 Jan 2012 20:03:17 +0000 (15:03 -0500)]
dtrace: fix signed division and modulo operations in DIF

Ensure that SDT probe points are patched with a NOP sequence at boot time.

Remove debugging output during SDT registration.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: initialize the insn length in the right branch of the die notifier
Nick Alcock [Tue, 17 Jan 2012 13:46:02 +0000 (13:46 +0000)]
dtrace: initialize the insn length in the right branch of the die notifier

Absent this fix, dtrace will crash on any platform *except* for a buggy Xen.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agodtrace: ensure that the trap handler is regisstered only once
Kris Van Hees [Thu, 12 Jan 2012 14:25:35 +0000 (09:25 -0500)]
dtrace: ensure that the trap handler is regisstered only once

Register with first use.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: install the die notifier hook whenever DTrace is enabled
Kris Van Hees [Wed, 11 Jan 2012 06:18:41 +0000 (01:18 -0500)]
dtrace: install the die notifier hook whenever DTrace is enabled

Page fault and general protection fault handling depends on it, and that
is needed for safe memory access support in DTrace.

Work around an apparent bug in Xen where an invalid opcode fault is delivered
as a general protection failure instead.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: support for page fault and general protection fault detection
Kris Van Hees [Wed, 14 Dec 2011 05:09:14 +0000 (00:09 -0500)]
dtrace: support for page fault and general protection fault detection

This ensures that DTrace memory access faults are non-fatal.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: fix incorrect probe point name
Kris Van Hees [Tue, 13 Dec 2011 22:08:10 +0000 (17:08 -0500)]
dtrace: fix incorrect probe point name

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: add lwp-exit and lwp-create SDT probe points
Kris Van Hees [Tue, 13 Dec 2011 21:58:43 +0000 (16:58 -0500)]
dtrace: add lwp-exit and lwp-create SDT probe points

Change the DRELOC tag in make output to DT-SDT.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: SDT implementation
Kris Van Hees [Mon, 5 Dec 2011 20:01:27 +0000 (15:01 -0500)]
dtrace: SDT implementation

This adds core kernel support for providing a list of static probe
points for the kernel pseudo-module, dtrace SDT meta-provider support, ...
Also a new script (dtrace_sdt.sh) to extract locations of SDT probe points in
the core kernel.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: process the SDT probe point info early in boot
Kris Van Hees [Mon, 14 Nov 2011 15:17:45 +0000 (10:17 -0500)]
dtrace: process the SDT probe point info early in boot

If DTrace SDT support has been enabled (built-in or as module),
process the SDT probe point info early at boot time (before SMP is actually
enabled).  For now, provide some verbose info on the probe points getting
resolved.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: fix resolving addresses of relocation records for SDT probe points
Kris Van Hees [Fri, 11 Nov 2011 07:34:04 +0000 (02:34 -0500)]
dtrace: fix resolving addresses of relocation records for SDT probe points

The addresses were being calculated based on the wrong starting point (_stext
whereas it ought to be _text), and the base was not taken into account.
Fixed the writing of NOPs in the location of the probe point calls, since
the existing case was causing kernel paging faults.  Made the add_nops()
function in alternative.c non-static so it can be used in sdt_register.
Use add_nops() to select the most appropriate NOP sequence for replacing the
probe point call, and write the NOPs using text_poke().

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: fix cyclic allocation
Kris Van Hees [Thu, 3 Nov 2011 17:59:00 +0000 (13:59 -0400)]
dtrace: fix cyclic allocation

Fixed the allocation of cyclics that was the cause of some obscure crashes
during the testsuite execution.  Problem was that cyclics were being allocated
in chunks, with a new array being allocated as (prev-size + chink-size), and
then the old entries being copied over.  However, because the hrtimer struct is
embedded in the cyclic struct, this meant that hrtimer structs were being moved
outside the hrtimer code.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: stub-based syscall tracing
Kris Van Hees [Thu, 27 Oct 2011 14:39:19 +0000 (10:39 -0400)]
dtrace: stub-based syscall tracing

Due to the need for specialized code handling (mainly passing in a pt_regs
structure as one of the arguments), some syscalls are called through a stub
in assembly code.

We duplicate the stub cdode in dtrace_stubs_x86_64.S, but instead of calling
the actual syscall implementation code call our own syscall-specific handler,
which ensures that entry and return probes are called as enabled, and then
call the underlying implementation directly for handling the syscall.

Also removed debugging output that is no longer relevant (code cleanup).

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: migrate stacktrace dumping and move headers about: fix reloc overrun
Kris Van Hees [Fri, 14 Oct 2011 02:42:27 +0000 (22:42 -0400)]
dtrace: migrate stacktrace dumping and move headers about: fix reloc overrun

Stacktrace dumping has been moved to the GPL-licensed dtrace_os.c because it
depends on a symbol that is exported as GPL-only.  Functionality in dtrace_isa
that requires stacktrace dumping can now use dtrace_stacktrace().

The GPL-licensed dtrace_os.h C header file is now made available through the
/include/linux hierarchy, and it is included in dtrace.h.

Fixed a bug in dtrace_relocs.c where section names where copied into a memory
area that was 1 byte short, causing various unpleasant forms of behaviour.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
10 years agodtrace: move cyclic.h into include/linux
Nick Alcock [Tue, 4 Oct 2011 11:58:17 +0000 (12:58 +0100)]
dtrace: move cyclic.h into include/linux

This is so that things in dtrace/ can pick it up.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agodtrace: finish GPL/CDDL splitting work
Nick Alcock [Mon, 3 Oct 2011 16:20:15 +0000 (17:20 +0100)]
dtrace: finish GPL/CDDL splitting work

kernel/dtrace and all that it #includes is now GPLv2, with the aid of a new
systrace_os.h header containing the subset of systrace.h needed by the GPL shim.
Conversely, dtrace/ is entirely CDDL.

dtrace_ioctl.h is now an exported, header in include/linux/, to ease future
sharing by the userspace side. It is probably not copyrightable (as is essential
for interoperability and contains no creative elements), but if it has any license
at all it is GPLv2 like the other headers in that directory (many of which are
include them.)

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agodtrace: fix GPL and CDDL copyright notices
Nick Alcock [Fri, 30 Sep 2011 18:29:33 +0000 (19:29 +0100)]
dtrace: fix GPL and CDDL copyright notices

The stuff in kernel/dtrace gets just a (C) line: dual-licensed parts will need
further adjustment.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
10 years agodtrace: Migrate to a standalone module, situated at the top level of the tree
Nick Alcock [Fri, 30 Sep 2011 17:55:09 +0000 (18:55 +0100)]
dtrace: Migrate to a standalone module, situated at the top level of the tree

Built via a simple 'make' if you're already running this kernel, or via 'make
KERNELDIR=/path/to/kernel/top/level' otherwise. Installed via 'make install'.

A specfile creating a standalone source rpm (which depends on the kernel source
RPM) will be added soon.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>