• Marco Elver's avatar
    perf: Add support for SIGTRAP on perf events · 97ba62b2
    Marco Elver authored
    Adds bit perf_event_attr::sigtrap, which can be set to cause events to
    send SIGTRAP (with si_code TRAP_PERF) to the task where the event
    occurred. The primary motivation is to support synchronous signals on
    perf events in the task where an event (such as breakpoints) triggered.
    
    To distinguish perf events based on the event type, the type is set in
    si_errno. For events that are associated with an address, si_addr is
    copied from perf_sample_data.
    
    The new field perf_event_attr::sig_data is copied to si_perf, which
    allows user space to disambiguate which event (of the same type)
    triggered the signal. For example, user space could encode the relevant
    information it cares about in sig_data.
    
    We note that the choice of an opaque u64 provides the simplest and most
    flexible option. Alternatives where a reference to some user space data
    is passed back suffer from the problem that modification of referenced
    data (be it the event fd, or the perf_event_attr) can race with the
    signal being delivered (of course, the same caveat applies if user space
    decides to store a pointer in sig_data, but the ABI explicitly avoids
    prescribing such a design).
    Suggested-by: default avatarPeter Zijlstra <peterz@infradead.org>
    Signed-off-by: default avatarMarco Elver <elver@google.com>
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Acked-by: default avatarDmitry Vyukov <dvyukov@google.com>
    Link: https://lore.kernel.org/lkml/YBv3rAT566k+6zjg@hirez.programming.kicks-ass.net/
    97ba62b2
core.c 319 KB