Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2777510pxb; Tue, 23 Feb 2021 15:51:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbwoecdgU1e/MavW8PM8mBHdlQ1lq7sGMme3OrB4pcex3kguETIUPjnx5qPZtrMhpdOHtU X-Received: by 2002:a17:907:3e1b:: with SMTP id hp27mr27204346ejc.506.1614124319471; Tue, 23 Feb 2021 15:51:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614124319; cv=none; d=google.com; s=arc-20160816; b=Oh4H3zg15Fd8k+S2+Nel2qlHsPz0kX99nv6xbXUUoOt2j1B7OQIdGCaFa5DEH8Z7wm mKihK9ssqSf917H7v7/miXlzSplve4586rZl0/u4Pk5LXerpBE9/RzvF1mpZ+kgOrv1a tIZjndnAeI4qrxW0oJMKGXWefnNLBgdyp2sEwjtIv3VBKFhGp7Za0+eug4x1+8Byd1ZS S27mAGUTzIe3EXWZ+8DTbjwsVaDzvwkd7dtk7KKaoJj5ickuNP2kj65Kjw70oYIdE9i0 47Bpgc1bFiL1AMD959rQiHyFEWoRoNHX6Lr0komcNTPGx6pBV4yEzTofvVMLM1yFN2AN im+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=KDbWfjB7meY0E7XLsjIrc5m2e7z/Yrkuj6hZaVwwlGE=; b=qj4hdlW/Fogo/VaDE+LHjQ9+puSA1nJHSLe+CTtVglmoISZvmCqZsClak0k3udQ8/7 QDqf2WvRzSCJNWP8hzGvnqIWtsFyv3cdhf1o6wj/pBNGymt4L/TAVdH1XwoU1GNZN/E+ /sU3WE90C6l3crV5lkbA+6iQyHfhPoGlsU0rA9FcQYHy8PAUU3SWqQ/dN+/PA21+e3G/ pGHk6FGFKl/Niuo0k66vcjEcZgw+K3iIyDZQDi1AZVphKsFjMUj3ICPhjS0b6eNGCfal CK2Y+ZznMvH1ISovXmJG/Uqnypm1Iqsu6XihhXXhZHC00RDyyMGTfdzh1MwVsvl1xGFK ArZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uueyZEhC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h11si27845edb.576.2021.02.23.15.51.19; Tue, 23 Feb 2021 15:51:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uueyZEhC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232144AbhBWUFX (ORCPT + 99 others); Tue, 23 Feb 2021 15:05:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233040AbhBWUEh (ORCPT ); Tue, 23 Feb 2021 15:04:37 -0500 Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3B67C06178A for ; Tue, 23 Feb 2021 12:03:57 -0800 (PST) Received: by mail-ot1-x32d.google.com with SMTP id d9so2745972ote.12 for ; Tue, 23 Feb 2021 12:03:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KDbWfjB7meY0E7XLsjIrc5m2e7z/Yrkuj6hZaVwwlGE=; b=uueyZEhCJsJkc1//64Eechxof/hRtg3m1Kam7rXXOkGxioSseruAEXvRT1gwPL8vci FduZ0uQOv8+hJwNqH9PO99dchqYCcxQiJavaJVEq/x4E+GhQSZ1/+TJqGhdyxth/c9b0 uBrjxFkcXCrqELg63jTj2cOvhZihBwrbswwm24tvtYDcz3VfF4hdNH3wZ4J2dUZ+BkDt MufANT3JpO5VQjXitgDU8rg0FNLkZhigCEZj/mve/wdbPae6jymb4nI850CjV70cb/eu vERzojj1KOkEFfWGrh7Xvuh/pR7gscOH4+/AOHuoREQG0qNB8ht4uwrfaELflnr/vR/c +bjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KDbWfjB7meY0E7XLsjIrc5m2e7z/Yrkuj6hZaVwwlGE=; b=mhZjy+K+mI01/sCBaI4USw65IXjarRHBjYJydvpkdCqRokH2mhjawXo6tLbQHsKkcf QpL9GX38PCzSr+Gaj+VE6gTw51cObmHZ3FG046YnPq+SmjwqUoHRCJpKRDMxzYZQ0RG8 1IUK2zK6gNdbbZ9NAQCizc/DkNW3gisV6tmYd4lYDNs2DM44H6CzT/0UYwhoe46ylfZB 3Y5YAdzSF5Dm6PC0NkioGTcrx4Y72cS+iLDPXST249u3MHAqjhgU8Os1hdK5P746BttE WJ4/JJqLgMXebtodprfc8dMzdH5aR3AUELAEUIIvuzpM6xE2K+CRpLxt06OEMCcTEEZ0 HWuw== X-Gm-Message-State: AOAM5339YdsZk6xSDjLCLITN72psKE/06zbTNjWk2osC95Y8YFoRaGHI 6z8BwRQPdqcWp+pn1zN4c5HPs/EUYNhrvmfrUMxgBw== X-Received: by 2002:a05:6830:18e6:: with SMTP id d6mr22473227otf.251.1614110636519; Tue, 23 Feb 2021 12:03:56 -0800 (PST) MIME-Version: 1.0 References: <20210223143426.2412737-1-elver@google.com> In-Reply-To: <20210223143426.2412737-1-elver@google.com> From: Marco Elver Date: Tue, 23 Feb 2021 21:03:44 +0100 Message-ID: Subject: Re: [PATCH RFC 0/4] Add support for synchronous signals on perf events To: Marco Elver , Peter Zijlstra , Alexander Shishkin , Arnaldo Carvalho de Melo , Ingo Molnar , Jiri Olsa , Mark Rutland , Namhyung Kim , Thomas Gleixner Cc: Alexander Potapenko , Al Viro , Arnd Bergmann , Christian Brauner , Dmitry Vyukov , Jann Horn , Jens Axboe , Matt Morehouse , Peter Collingbourne , Ian Rogers , kasan-dev , linux-arch , linux-fsdevel , LKML , linux-m68k@lists.linux-m68k.org, "the arch/x86 maintainers" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 23 Feb 2021 at 15:34, Marco Elver wrote: > > The perf subsystem today unifies various tracing and monitoring > features, from both software and hardware. One benefit of the perf > subsystem is automatically inheriting events to child tasks, which > enables process-wide events monitoring with low overheads. By default > perf events are non-intrusive, not affecting behaviour of the tasks > being monitored. > > For certain use-cases, however, it makes sense to leverage the > generality of the perf events subsystem and optionally allow the tasks > being monitored to receive signals on events they are interested in. > This patch series adds the option to synchronously signal user space on > events. > > The discussion at [1] led to the changes proposed in this series. The > approach taken in patch 3/4 to use 'event_limit' to trigger the signal > was kindly suggested by Peter Zijlstra in [2]. > > [1] https://lore.kernel.org/lkml/CACT4Y+YPrXGw+AtESxAgPyZ84TYkNZdP0xpocX2jwVAbZD=-XQ@mail.gmail.com/ > [2] https://lore.kernel.org/lkml/YBv3rAT566k+6zjg@hirez.programming.kicks-ass.net/ > > Motivation and example uses: > > 1. Our immediate motivation is low-overhead sampling-based race > detection for user-space [3]. By using perf_event_open() at > process initialization, we can create hardware > breakpoint/watchpoint events that are propagated automatically > to all threads in a process. As far as we are aware, today no > existing kernel facility (such as ptrace) allows us to set up > process-wide watchpoints with minimal overheads (that are > comparable to mprotect() of whole pages). > > [3] https://llvm.org/devmtg/2020-09/slides/Morehouse-GWP-Tsan.pdf > > 2. Other low-overhead error detectors that rely on detecting > accesses to certain memory locations or code, process-wide and > also only in a specific set of subtasks or threads. > > Other example use-cases we found potentially interesting: > > 3. Code hot patching without full stop-the-world. Specifically, by > setting a code breakpoint to entry to the patched routine, then > send signals to threads and check that they are not in the > routine, but without stopping them further. If any of the > threads will enter the routine, it will receive SIGTRAP and > pause. > > 4. Safepoints without mprotect(). Some Java implementations use > "load from a known memory location" as a safepoint. When threads > need to be stopped, the page containing the location is > mprotect()ed and threads get a signal. This can be replaced with > a watchpoint, which does not require a whole page nor DTLB > shootdowns. > > 5. Tracking data flow globally. > > 6. Threads receiving signals on performance events to > throttle/unthrottle themselves. > > > Marco Elver (4): > perf/core: Apply PERF_EVENT_IOC_MODIFY_ATTRIBUTES to children > signal: Introduce TRAP_PERF si_code and si_perf to siginfo > perf/core: Add support for SIGTRAP on perf events > perf/core: Add breakpoint information to siginfo on SIGTRAP Note that we're currently pondering fork + exec, and suggestions would be appreciated. We think we'll need some restrictions, like Peter proposed here: here: https://lore.kernel.org/lkml/YBvj6eJR%2FDY2TsEB@hirez.programming.kicks-ass.net/ We think what we want is to inherit the events to children only if cloned with CLONE_SIGHAND. If there's space for a 'inherit_mask' in perf_event_attr, that'd be most flexible, but perhaps we do not have the space. Thanks, -- Marco > > arch/m68k/kernel/signal.c | 3 ++ > arch/x86/kernel/signal_compat.c | 5 ++- > fs/signalfd.c | 4 +++ > include/linux/compat.h | 2 ++ > include/linux/signal.h | 1 + > include/uapi/asm-generic/siginfo.h | 6 +++- > include/uapi/linux/perf_event.h | 3 +- > include/uapi/linux/signalfd.h | 4 ++- > kernel/events/core.c | 54 +++++++++++++++++++++++++++++- > kernel/signal.c | 11 ++++++ > 10 files changed, 88 insertions(+), 5 deletions(-) > > -- > 2.30.0.617.g56c4b15f3c-goog >