Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp685707rdb; Thu, 18 Jan 2024 16:14:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGVfzDgRGGRTEuw1Agcj10s83e47+d+U+4kptpYXD/BRw2BTTAXSy84sM10+2eS4tiv0ekm X-Received: by 2002:ac8:7f86:0:b0:42a:17a7:36e4 with SMTP id z6-20020ac87f86000000b0042a17a736e4mr1832377qtj.17.1705623260518; Thu, 18 Jan 2024 16:14:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705623260; cv=pass; d=google.com; s=arc-20160816; b=zOBuhBF2/1MEKX0Rhcue+JzUhA/+0EqZ9tYXhxq4W56kAkwHzOq1mwnjZKMrbsnDPL y0Yoab7CiBeLvLdxxe+pqkNCjXVX1FZGJnhVXGN5OQaDb2ulUYcIYkyxPioWgUBGqslV R5M03GIObZc9BfTSGbdJvwWqN1BJ6Y8B2rCiuvA6RJxvjRqkGPcmc4jxjgM2Ua3GqUfF 0XpcLebaAoVeeiZBoTrQFA6J4Otw2RsNVlcs0sHp3Xbhr+jisUcDkZJ2dhdrjx7vQcRc DEZoEpyGCQKsNaxFmiaj+aF4pIKIJcOwcD7a+uTbCWJb75VXSiDOXZAc5SZcgFtXajep qGww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=vylMAwKjOKQHziaAu87Qiy3rOLrs3/9n8l6rCdO/DPQ=; fh=1r5ICvYfPWH8rB8myZId85/cda7oA7Xt/PEe2eT1tOg=; b=OddTqfEDFkvl0G4YMBsrsno6stKZ03+SESsXeNNoSg7Qw1fcODZByibgCavqpzrNJC F9YoOtmGBoW5XgHlYT5+m9JEq1PV2oI+3hlOO7vfDOKoZ/TkMm+f0g+cE4jCe6bShXEx wgegUZsBhhtfBEFh6+srckXY/7vXh13ZkRgWoXS7POYjSZWHPXeCVR3MA92/A/o4kK7K 0EbXqiTWnI9D63Dy7s9Pt/f/lkQRa7DoSqux+ffPO67D6U3sIBU5dYDrCVH/lRWy+cX3 KCnjVkpTqNfc63vopVNmnCKIqYmdwGLXuODc9XiV0GQ0V719e5czTm0eR/YKbSXBI9rv L2Xg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b="h1YdhG/u"; arc=pass (i=1 spf=pass spfdomain=kylehuey.com dkim=pass dkdomain=kylehuey.com); spf=pass (google.com: domain of linux-kernel+bounces-30649-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30649-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id bk12-20020a05620a1a0c00b007837aa4968asi3195449qkb.709.2024.01.18.16.14.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 16:14:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30649-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b="h1YdhG/u"; arc=pass (i=1 spf=pass spfdomain=kylehuey.com dkim=pass dkdomain=kylehuey.com); spf=pass (google.com: domain of linux-kernel+bounces-30649-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30649-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 327641C22871 for ; Fri, 19 Jan 2024 00:14:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 83394A59; Fri, 19 Jan 2024 00:14:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kylehuey.com header.i=@kylehuey.com header.b="h1YdhG/u" Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 639927EF for ; Fri, 19 Jan 2024 00:14:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705623252; cv=none; b=CmsA6hRNU4fLwspeLkMp59kFu5B7dgFcSDY5Nv2Qvf5epHpc/1WeQdLV5vJTgQJ5jJDJnIi4+BI/Qy2UJpkmvprorY7oRw07wJI3bgkk0HQgxP0/hB+J+F1VZp5Vrnp7R3txz03rd2NvwqdG7Y8qixqLxB9eAixmZP3z88x9Jhs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705623252; c=relaxed/simple; bh=vylMAwKjOKQHziaAu87Qiy3rOLrs3/9n8l6rCdO/DPQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=fxALXxL/O1tGrA2HlY40vfSfuAJdkSbYwCbe0VtkaOh2Al1ufxrf6eKfosbY/dPQAfr3fu3nZnJhMMEqoopeNeQJMioATRaptd7ad1BUFRJfooeDpa8rPr7YHQ3rw2f8mWmpTL32ThXtzXnZxRuNhM+EA3dsiSAo5zFKS8cC78s= 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=h1YdhG/u; arc=none smtp.client-ip=209.85.214.178 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-pl1-f178.google.com with SMTP id d9443c01a7336-1d41bb4da91so1733545ad.0 for ; Thu, 18 Jan 2024 16:14:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kylehuey.com; s=google; t=1705623251; x=1706228051; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=vylMAwKjOKQHziaAu87Qiy3rOLrs3/9n8l6rCdO/DPQ=; b=h1YdhG/uV4V/7dPA2x3YbN229M0X7P6v2zSSe+uXUiHIMdatP0XlCzFYCbUuJ1G46x dahGIt5fNpfWQIDjHYneNEpnnDm8eNnOe3NLKmg7eXk1dy0GT7cHDXLi5hvnTQ8ZOxpl fr9O02KY9+W7dkAHDBXid5Q0VTLlPXsvyNXiwW1lPKBrDoEPlZ2TzItOOLl7vh/Bvpog AwNHnWikEHg7/lg0QpQDYjhSq2fghMAb2tq1WyWT9tRY14EmXUMq34II00IqZezZGca8 OGiGlP9Z+LehY/t/sQcTBKvS9Han7yzEx6ruH93EJa735+PgjJqodlwIYEuitepwwQP6 bLDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705623251; x=1706228051; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vylMAwKjOKQHziaAu87Qiy3rOLrs3/9n8l6rCdO/DPQ=; b=pVgVjl2n3Y52qd5VK36Mp1q/Pn+OgC96wKNcOjW+zVDuDyoq2E3g5FgXuA8+Y7yJX8 kxrgkwZQcPkOkvAY8TeljB3/mcVOE9cOM2n6vvGCXkryplaAjp1VMliDG8Z02RRPtPWO 3PvfVoQlbyruAdoCenRjlIkhsYnqSFs67I2mZyzXoUaEAtDZT0EKxr/HtCul+sPa0Oti OdTgrMNSCjzquHn32BkQGhKXmnyWwSyllfCRm5bna9yPx4KVdCJE4tiNYyLAZWyhBH+e nYqvTs6XFaDpoWkPa03WVq/tE+nAJLxrdjIGWAjqJucYPql2kavbZDuaYKw6DPhu6RTq HniQ== X-Gm-Message-State: AOJu0YwTpg7B/NBnhu1jBYBPqtmSEx73IKf/xPVF7n29u8Cav+HBVOVr 2NL9HHn0ed3yYyTxUBGEbwIOh2NVXSXq/7BJsqvMr24uUWvJws8Yy7xqeFZWVA== X-Received: by 2002:a17:902:f68b:b0:1d4:4482:83c7 with SMTP id l11-20020a170902f68b00b001d4448283c7mr1774551plg.117.1705623250639; Thu, 18 Jan 2024 16:14:10 -0800 (PST) Received: from zhadum.home.kylehuey.com (c-76-126-33-191.hsd1.ca.comcast.net. [76.126.33.191]) by smtp.gmail.com with ESMTPSA id mj7-20020a1709032b8700b001d1d1ef8be6sm1921238plb.267.2024.01.18.16.14.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 16:14:10 -0800 (PST) From: Kyle Huey X-Google-Original-From: Kyle Huey To: Kyle Huey , linux-kernel@vger.kernel.org, Andrii Nakryiko , Jiri Olsa , Namhyung Kim , Marco Elver , Yonghong Song , Song Liu Cc: Robert O'Callahan , bpf@vger.kernel.org Subject: [PATCH v4 0/4] Combine perf and bpf for fast eval of hw breakpoint conditions Date: Thu, 18 Jan 2024 16:13:47 -0800 Message-Id: <20240119001352.9396-1-khuey@kylehuey.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit rr, a userspace record and replay debugger[0], replays asynchronous events such as signals and context switches by essentially[1] setting a breakpoint at the address where the asynchronous event was delivered during recording with a condition that the program state matches the state when the event 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 SIGTRAP. 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 machinery, passes the return code of the BPF program back to __perf_overflow_handler() 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 effects 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/20231211045543.31741-1-khuey@kylehuey.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 multiline comment formatting. v2 of this patchset can be found at https://lore.kernel.org/linux-kernel/20231207163458.5554-1-khuey@kylehuey.com/ Changes since v2: Patches 1 and 2 were added from a suggestion by Namhyung Kim to refactor this code to implement this feature in a cleaner way. Patch 2 is separated for the benefit of the ARM arch maintainers. Patch 3 conceptually supercedes v2's patches 1 and 2, now with a cleaner implementation thanks to the earlier refactoring. Patch 4 is v2's patch 3, and addresses review comments about C++ style comments, getting a TRAP_PERF definition into the test, and unnecessary NULL checks. [0] https://rr-project.org/ [1] Various optimizations exist to skip as much as execution as possible before setting a breakpoint, and to determine a set of program state that is practical to check and verify.