• Alexander Shishkin's avatar
    perf/core: Fix exclusive events' grouping · 8a58ddae
    Alexander Shishkin authored
    So far, we tried to disallow grouping exclusive events for the fear of
    complications they would cause with moving between contexts. Specifically,
    moving a software group to a hardware context would violate the exclusivity
    rules if both groups contain matching exclusive events.
    
    This attempt was, however, unsuccessful: the check that we have in the
    perf_event_open() syscall is both wrong (looks at wrong PMU) and
    insufficient (group leader may still be exclusive), as can be illustrated
    by running:
    
      $ perf record -e '{intel_pt//,cycles}' uname
      $ perf record -e '{cycles,intel_pt//}' uname
    
    ultimately successfully.
    
    Furthermore, we are completely free to trigger the exclusivity violation
    by:
    
       perf -e '{cycles,intel_pt//}' -e '{intel_pt//,instructions}'
    
    even though the helpful perf record will not allow that, the ABI will.
    
    The warning later in the perf_event_open() path will also not trigger, because
    it's also wrong.
    
    Fix all this by validating the original group before moving, getting rid
    of broken safeguards and placing a useful one to perf_install_in_context().
    Signed-off-by: default avatarAlexander Shishkin <alexander.shishkin@linux.intel.com>
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Cc: <stable@vger.kernel.org>
    Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Jiri Olsa <jolsa@redhat.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Stephane Eranian <eranian@google.com>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Vince Weaver <vincent.weaver@maine.edu>
    Cc: mathieu.poirier@linaro.org
    Cc: will.deacon@arm.com
    Fixes: bed5b25a ("perf: Add a pmu capability for "exclusive" events")
    Link: https://lkml.kernel.org/r/20190701110755.24646-1-alexander.shishkin@linux.intel.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
    8a58ddae
core.c 289 KB