From patchwork Fri Jan 19 00:13:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Huey X-Patchwork-Id: 19163 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp703087dyb; Thu, 18 Jan 2024 16:14:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IGIQ0ZqIHoHZXUO7W24hps3KuUle2YJhNQ7QW9p19E5fsn6xn/h0mgIZKxu2qpTDSbuppg/ X-Received: by 2002:a17:906:3498:b0:a2d:49ba:71ee with SMTP id g24-20020a170906349800b00a2d49ba71eemr890454ejb.101.1705623269103; Thu, 18 Jan 2024 16:14:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705623269; cv=pass; d=google.com; s=arc-20160816; b=D6ecbjTpPjz11RswFNqOVWCDcPFUK6iWYJt31Hyn/a+J4lqGKBqSQpujxWF6i6ky/o 9QOQA+wcRl82X/OtFQnNL8HBxhPI/Jr8TnWQjzPNUQ3YCoYInMVIgnC/GdLr0IibBCDG MAbmf/o+Tlgp/kkT3koJG4mQ6dtidk9SwUJnY7SBnQ+/ondWWbu5UwWmHrF2D3ueSCfV 3hL6Io3U48bZUi5R8DtFBKnH4xBetRT6rEb/s3Oxd6yQk9o9YeIFwu1cG+H1s5LBnYDu cNCQnUeTdSjZm3/IAv+KpkLawjGD06HX6mrh7DDWNVAFop4TrUd2F4442IIbne1w+qyz L5hQ== 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30649-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id h8-20020a170906260800b00a2ec61046b1si1936786ejc.178.2024.01.18.16.14.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 16:14:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30649-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30649-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id B31AB1F2355D for ; Fri, 19 Jan 2024 00:14:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7BC79138F; Fri, 19 Jan 2024 00:14:15 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788475625128695295 X-GMAIL-MSGID: 1788475625128695295 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. Acked-by: Jiri Olsa