Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3540324pxb; Mon, 4 Apr 2022 20:31:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrm16WNXaBNHb6aKAkrH68L8o2BI5zZkU/x5LBkjkwQ46qqILVmEgINpYaEPNHV+6IJVpL X-Received: by 2002:a17:902:d4c8:b0:154:2416:218b with SMTP id o8-20020a170902d4c800b001542416218bmr1444438plg.139.1649129461435; Mon, 04 Apr 2022 20:31:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649129461; cv=none; d=google.com; s=arc-20160816; b=SCge23pPLyZipXjKSwHEuoaJNUXibcivw55eS333YJeTP/WKimLluPHZ5sBw+vb8LV foFuZ04PYzIXDS5sYRfw6IEcEY+hyN3QjJS4I6BHrmdClsgZ4zGBcxv3QKV59xXwKhdM Dla7iGKooOQyeMkN/TUDfmkWx+6TrlqEfhqOFSvNU7YfH3+lGS/VL9yJkT29ajyauixY 8fyFp3gTuN2YzKqn5R9T7xyF5PuwLYw7lR14p5eqd3PtzqW6SU/gZcVdWSQATG9+l5ld SA5gaz0Ec5M9wJFWSlFXqCmbCFM7MCH2efIt7YjBvAJpLiwP9XqbfayK5QeahUZw/cnV F7Dg== 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; bh=nYvQ/9sOxTrqd5FO05k5YTA5C/LjNCLjagWPfQG2994=; b=xllIzVMerClrjQ5YLpNumbf1pGrIqOwQSvVven6z/Q9liGQtJYTkg1jSU38J03JElx JgwCrj17mNKfF5ce9+tghbb+ORApZJuGHXp8WNJ7ju9GzmVO4F/KiNHDquKE+xDL3sSc 4nPT6jVXY7X29VHCEFCu0YdPriQLkFdV4+yWnSh/U6s83JVciny7+F1r35LbD7UruhJf vyC8c5l0LwGnCFaA8FfX47JU+lBH56NUxCQjuaP9KzMZNxW4jGRHRdIwNDglpp0EAbwB ZIWeLZujFE1g00hL6bct5v+zdaDEhE5xwz/V7tgx9yF3IMVHZMvlzR5lyM4x8WYPrlQg ARVw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j9-20020a170903024900b00153b2d164bdsi12931998plh.197.2022.04.04.20.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 20:31:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 09EF335A508; Mon, 4 Apr 2022 18:30:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350784AbiDDLqI (ORCPT + 99 others); Mon, 4 Apr 2022 07:46:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348762AbiDDLqE (ORCPT ); Mon, 4 Apr 2022 07:46:04 -0400 Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B9CB1B7A7; Mon, 4 Apr 2022 04:44:08 -0700 (PDT) Received: by mail-qv1-f49.google.com with SMTP id cs16so1456035qvb.8; Mon, 04 Apr 2022 04:44:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nYvQ/9sOxTrqd5FO05k5YTA5C/LjNCLjagWPfQG2994=; b=TBjThrjyTVGV54MpL6ZIexcyW0rJu6yhTulv5b07N1fqiwyVK4VfBz8lIB1/nwLR+m zvsbVMjV88OurfMyzYhQpmLw44taIJYnnZI9mAf7t4fno50TQAXD5grCHNSJE2eyZE2N oAwOmgIGYwG1c1OZzWJ2d7BLjQoBhla4/XO8/0Y6FSfPhe2P7x0CTXxmYTv8xp8cKomQ ePmQeKr37Ks5CZmW7nAustErX5QbB51D0nx7cbcBmN9SlqBdI9g+/G7KHEiNPJPQsvEn /kZy46eQ9JMH5B5x1/zezm8lUCt8yvhol/ZxoQF7RJvNLGqmqwhD/AbDpKIvpoItuP7v m4ww== X-Gm-Message-State: AOAM532HMyNGTYI+vJNPRtQdsUkbBwt8AzfqTydAMjhQvoYEMDS59aiM 7LOX1SShTI/v7GZAQrts/BTSdHCZuqoxfA== X-Received: by 2002:a05:6214:c44:b0:443:c09c:b15c with SMTP id r4-20020a0562140c4400b00443c09cb15cmr7518017qvj.30.1649072646773; Mon, 04 Apr 2022 04:44:06 -0700 (PDT) Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com. [209.85.128.174]) by smtp.gmail.com with ESMTPSA id e20-20020ac84e54000000b002e06753cf70sm9416199qtw.6.2022.04.04.04.44.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Apr 2022 04:44:06 -0700 (PDT) Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-2e5e9025c20so95510687b3.7; Mon, 04 Apr 2022 04:44:05 -0700 (PDT) X-Received: by 2002:a81:618b:0:b0:2db:d952:8a39 with SMTP id v133-20020a81618b000000b002dbd9528a39mr22035506ywb.132.1649072645615; Mon, 04 Apr 2022 04:44:05 -0700 (PDT) MIME-Version: 1.0 References: <20220404111204.935357-1-elver@google.com> In-Reply-To: <20220404111204.935357-1-elver@google.com> From: Geert Uytterhoeven Date: Mon, 4 Apr 2022 13:43:54 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] signal: Deliver SIGTRAP on perf event asynchronously if blocked To: Marco Elver Cc: Peter Zijlstra , "Eric W. Biederman" , Thomas Gleixner , Ingo Molnar , "the arch/x86 maintainers" , Linux ARM , linux-m68k , sparclinux , Linux-Arch , linux-perf-users@vger.kernel.org, kasan-dev , Linux Kernel Mailing List , Dmitry Vyukov Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 4, 2022 at 1:30 PM Marco Elver wrote: > With SIGTRAP on perf events, we have encountered termination of > processes due to user space attempting to block delivery of SIGTRAP. > Consider this case: > > > ... > sigset_t s; > sigemptyset(&s); > sigaddset(&s, SIGTRAP | ); > sigprocmask(SIG_BLOCK, &s, ...); > ... > > > When the perf event triggers, while SIGTRAP is blocked, force_sig_perf() > will force the signal, but revert back to the default handler, thus > terminating the task. > > This makes sense for error conditions, but not so much for explicitly > requested monitoring. However, the expectation is still that signals > generated by perf events are synchronous, which will no longer be the > case if the signal is blocked and delivered later. > > To give user space the ability to clearly distinguish synchronous from > asynchronous signals, introduce siginfo_t::si_perf_flags and > TRAP_PERF_FLAG_ASYNC (opted for flags in case more binary information is > required in future). > > The resolution to the problem is then to (a) no longer force the signal > (avoiding the terminations), but (b) tell user space via si_perf_flags > if the signal was synchronous or not, so that such signals can be > handled differently (e.g. let user space decide to ignore or consider > the data imprecise). > > The alternative of making the kernel ignore SIGTRAP on perf events if > the signal is blocked may work for some usecases, but likely causes > issues in others that then have to revert back to interception of > sigprocmask() (which we want to avoid). [ A concrete example: when using > breakpoint perf events to track data-flow, in a region of code where > signals are blocked, data-flow can no longer be tracked accurately. > When a relevant asynchronous signal is received after unblocking the > signal, the data-flow tracking logic needs to know its state is > imprecise. ] > > Link: https://lore.kernel.org/all/Yjmn%2FkVblV3TdoAq@elver.google.com/ > Fixes: 97ba62b27867 ("perf: Add support for SIGTRAP on perf events") > Reported-by: Dmitry Vyukov > Signed-off-by: Marco Elver > arch/m68k/kernel/signal.c | 1 + Acked-by: Geert Uytterhoeven Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds