Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2829404rdb; Mon, 12 Feb 2024 19:58:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+kbljJXM3URyPLh1frzcqBasZQ58k2EeXEZ9HXrQ3Q3FTczRZG+6wyHeC6RQv7XFi0Dgp X-Received: by 2002:a9d:6b19:0:b0:6e2:e3b0:7659 with SMTP id g25-20020a9d6b19000000b006e2e3b07659mr4158682otp.12.1707796687307; Mon, 12 Feb 2024 19:58:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707796687; cv=pass; d=google.com; s=arc-20160816; b=urkGj64l+/U7b++IiWaG2e39AeDfp0G2fiosHX2tlh2nUM4LoF6NJYVcjfzIhcbAAU mv3ohrOnWFgdQO1swhdSyqYYN4Nrzs8SDXL1HeFy2qVFFfcnRCJWcPh/y6ubRLBYRF32 hjbY12BuyopcTOaIqIbM4Ua8DjNRnSk3ODBgR76yHNuWoUiDjPJGMICUDrLx9kRg31FE EWQV0NENLu9yKnySwjz5wm0PO9rS813jWgw+1eld2q2oJV/crGhEpccFrC7NtBQaGxVr J8GhSe6UQgjLYLiePupqcu4WfAG6kI41n4GdRDh+xmZiggaMGBD8kXowN+FjuvgZegvi e1+g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=HGDUec+ltrfJRSqU4fW2OgD37xMy9JdASW7ExQePVdQ=; fh=zwSE7X29lgb67kLAez4pu6Oi7EnFy5Yt4NW7O4KSERo=; b=u7Lee6JthqLwkYORqdzvm+RpFq0ycYJXM+zr1AJoHcxDBCMFOgcDWIDq8/TeUWQWCT 3guZYMaWBoBWoQgt2Pl2f2YKIUmxUPICXxrd3TCm72UX9IyYPErEUYZTb1GwEz8Hhl+T L+5n5urxwoB3JH2pns7VMjNFDYNPnFZUrbXBSpdCVkcb2gxOVlJ+VleoRnRUVf2qNImZ BVn8f0t3r2kmrndXra6db2nV5yYIs/ms3mEdmKIOGJZOYxUS71efdYKO2WWp+3E7+c8z pJmMZ+74woUGy7MNqu8AbmOAYzXrUrtKVVcp1VACQb+mCj2tB1nQlFutnapfiPFomi28 q6Hw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=bfXONbeI; arc=pass (i=1 spf=pass spfdomain=kylehuey.com dkim=pass dkdomain=kylehuey.com); spf=pass (google.com: domain of linux-kernel+bounces-62923-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62923-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCVEy01L0g7bT4PjVONrG+mj8QEiyji7Pejn02YjOo39w/wUmyqYk4nZPMlRP4661Awpd28faKMPoYAJJMME4u34JwKWKkkF6mrimJHi3A== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id bq16-20020a056a02045000b005dc4c1f8c52si1291165pgb.523.2024.02.12.19.58.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 19:58:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62923-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=bfXONbeI; arc=pass (i=1 spf=pass spfdomain=kylehuey.com dkim=pass dkdomain=kylehuey.com); spf=pass (google.com: domain of linux-kernel+bounces-62923-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62923-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E9788284BB5 for ; Tue, 13 Feb 2024 03:58:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9E8F3AD24; Tue, 13 Feb 2024 03:57:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kylehuey.com header.i=@kylehuey.com header.b="bfXONbeI" Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D72EB28F3 for ; Tue, 13 Feb 2024 03:57:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707796676; cv=none; b=K+BAhXXCNwpKN5pDLNYjkwD7hxktDzeA2+mrt0uij422ZU6mNKrBHwCSVm8Jq6iMmNXbVCWJXfWU7rwIzm/QtoWZlK5l723lkRIyeVT3i0a9L8SBY/7Pu+YoL6uj9ooOr/nfoAp2wBQ5qnbFrOgbMmf2z85Yfb4GHwiKLvhZBYw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707796676; c=relaxed/simple; bh=bN6dK6aD4FKyqegpnhvZEjDICtz9+BSGPPA7uv6RYgw=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=ai0C4ZEibTdiO8j27GSLWwpJGDNAiGdqlyCgNVbu94FQOUXa6oAvkBJH8uJyjhJcsMhdN5QTY66t/I221OF0SXHP5RaSoH0j8cpUsaybp9k2OWVIZdHE21N9JVP4m66YouBb+3Q9DgBys6YmlDu0J+gHaOfvG6q1IZQT0fVT7ak= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylehuey.com; spf=pass smtp.mailfrom=kylehuey.com; dkim=pass (2048-bit key) header.d=kylehuey.com header.i=@kylehuey.com header.b=bfXONbeI; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylehuey.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylehuey.com Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-51147d0abd1so4401009e87.1 for ; Mon, 12 Feb 2024 19:57:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kylehuey.com; s=google; t=1707796673; x=1708401473; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=HGDUec+ltrfJRSqU4fW2OgD37xMy9JdASW7ExQePVdQ=; b=bfXONbeIwgulPmbNIGSf3ZL3eerOXb59wypn7JW2Io7Rp8kOgFTW3N+UWfs1IfPQBx cc/20zR2N/3OOt5j46uwtp1wSbw62eS2iUvpRHkEXYA2+JfYSfSjItBG+MrhDIFdEB8e 9lfhIvyZT61V2Qv62C5AflXNlSQ24Dy4J75SKq+1xw++gBkrBovZUgj66WGJ3kEnSAKL GNOf/iFlguMLqybAXhYJgPsQgepHOmxNHK8lrb1Htz0/9rpObut8bUiN+zL9pMbGidll kgiGPotOEZaK55/n/ir5NSIBadEmltbCRGBxOqDYThNcqX6Vb/X6LAzJMqUtNkCELp+w aMAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707796673; x=1708401473; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HGDUec+ltrfJRSqU4fW2OgD37xMy9JdASW7ExQePVdQ=; b=K7Oq4NrDxvBPvtxZ8zFmOpacWipl2lmo07dMjqKYGgAVCeDfoWm2PVXnJ/J6mhae9G 4l6ptKqhGSUDtpyj/q6oNPI+7dfnehvRYNAfU3yiULfdg3IBAKEGfsnX9liWEkAp/yUg vHKuA4qQkCbj0yAVMVy+UajOrmaFq7W0x/1n1s3Kiy95fOTyuaRl5+2q38pyqegyj5ya vdAcuO7mNheDxM/1KLbE1OBviqCN1oTkd2w/mbpYVZcLaeP4ZLosMSdc2wbGpjqUz2yc 4n19hy7eaqSsJaaf5NI4zt4t8KEBHs1LyGiPv4iNE4eYP0QYKjxtttSXTgOVy8WtqVct trfA== X-Gm-Message-State: AOJu0Yxwdkyy6Skmyo6gTA7OCSicpDxR1T/WLHUixUKi7De9itLW94sY R4othCCwIjEaHO+55CZfuzlwWM0zAEFvtVCrXcrvBIV6Mx9Sxoa+BRuUgJ8LU5XHe1ixlJZ18CZ Wltgb70M/s0oN95Z6DIG72A2S2QtELuYFUggV X-Received: by 2002:a05:6512:2e9:b0:511:2e97:add2 with SMTP id m9-20020a05651202e900b005112e97add2mr5394630lfq.66.1707796672701; Mon, 12 Feb 2024 19:57:52 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240122062535.8265-1-khuey@kylehuey.com> In-Reply-To: From: Kyle Huey Date: Mon, 12 Feb 2024 19:57:39 -0800 Message-ID: Subject: Re: [PATCH v5 0/4] Combine perf and bpf for fast eval of hw breakpoint conditions To: Alexei Starovoitov Cc: Kyle Huey , LKML , Andrii Nakryiko , Jiri Olsa , Namhyung Kim , Marco Elver , Yonghong Song , "Robert O'Callahan" , bpf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Feb 12, 2024 at 6:42=E2=80=AFPM Alexei Starovoitov wrote: > > On Mon, Feb 12, 2024 at 8:37=E2=80=AFAM Kyle Huey wrote= : > > > > On Sun, Jan 21, 2024 at 10:25=E2=80=AFPM Kyle Huey wr= ote: > > > > > > rr, a userspace record and replay debugger[0], replays asynchronous e= vents > > > such as signals and context switches by essentially[1] setting a brea= kpoint > > > at the address where the asynchronous event was delivered during reco= rding > > > with a condition that the program state matches the state when the ev= ent > > > was delivered. > > > > > > Currently, rr uses software breakpoints that trap (via ptrace) to the > > > supervisor, and evaluates the condition from the supervisor. If the > > > asynchronous event is delivered in a tight loop (thus requiring the > > > breakpoint condition to be repeatedly evaluated) the overhead can be > > > immense. A patch to rr that uses hardware breakpoints via perf events= with > > > an attached BPF program to reject breakpoint hits where the condition= is > > > not satisfied reduces rr's replay overhead by 94% on a pathological (= but a > > > real customer-provided, not contrived) rr trace. > > > > > > The only obstacle to this approach is that while the kernel allows a = BPF > > > program to suppress sample output when a perf event overflows it does= not > > > suppress signalling the perf event fd or sending the perf event's SIG= TRAP. > > > This patch set redesigns __perf_overflow_handler() and > > > bpf_overflow_handler() so that the former invokes the latter directly= when > > > appropriate rather than through the generic overflow handler machiner= y, > > > passes the return code of the BPF program back to __perf_overflow_han= dler() > > > to allow it to decide whether to execute the regular overflow handler= , > > > reorders bpf_overflow_handler() and the side effects of perf event > > > overflow, changes __perf_overflow_handler() to suppress those side ef= fects > > > if the BPF program returns zero, and adds a selftest. > > > > > > The previous version of this patchset can be found at > > > https://lore.kernel.org/linux-kernel/20240119001352.9396-1-khuey@kyle= huey.com/ > > > > > > Changes since v4: > > > > > > Patches 1, 2, 3, 4 added various Acked-by. > > > > > > Patch 4 addresses additional nits from Song. > > > > > > v3 of this patchset can be found at > > > https://lore.kernel.org/linux-kernel/20231211045543.31741-1-khuey@kyl= ehuey.com/ > > > > > > Changes since v3: > > > > > > Patches 1, 2, 3 added various Acked-by. > > > > > > Patch 4 addresses Song's review comments by dropping signals_expected= and the > > > corresponding ASSERT_OKs, handling errors from signal(), and fixing m= ultiline > > > comment formatting. > > > > > > v2 of this patchset can be found at > > > https://lore.kernel.org/linux-kernel/20231207163458.5554-1-khuey@kyle= huey.com/ > > > > > > Changes since v2: > > > > > > Patches 1 and 2 were added from a suggestion by Namhyung Kim to refac= tor > > > this code to implement this feature in a cleaner way. Patch 2 is sepa= rated > > > for the benefit of the ARM arch maintainers. > > > > > > Patch 3 conceptually supercedes v2's patches 1 and 2, now with a clea= ner > > > implementation thanks to the earlier refactoring. > > > > > > Patch 4 is v2's patch 3, and addresses review comments about C++ styl= e > > > comments, getting a TRAP_PERF definition into the test, and unnecessa= ry > > > NULL checks. > > > > > > [0] https://rr-project.org/ > > > [1] Various optimizations exist to skip as much as execution as possi= ble > > > before setting a breakpoint, and to determine a set of program state = that > > > is practical to check and verify. > > > > Since everyone seems to be satisfied with this now, can we get it into > > bpf-next (or wherever) for 6.9? > > The changes look fine, but since they change perf side we need > perf maintainer's ack-s before we can land the patches. > And none of them were cc-ed. > So please resend the whole set and cc > PERFORMANCE EVENTS SUBSYSTEM > M: Peter Zijlstra > M: Ingo Molnar > M: Arnaldo Carvalho de Melo > M: Namhyung Kim They're all CCd to the three non-test patches in this set, Namhyung Kim is CCd to all of them and this cover email, and he both suggested the first patch and acked the third. - Kyle