Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp155361rdb; Sun, 21 Jan 2024 22:52:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IFSf8tVyW3aF1nC8+8yw1I70Qgs2H39j/xKG51AlO0WGG/wrgUOeF1b3phZJX+1g6eL4CzW X-Received: by 2002:a17:903:2603:b0:1d4:b4b8:93da with SMTP id jd3-20020a170903260300b001d4b4b893damr3606745plb.114.1705906328823; Sun, 21 Jan 2024 22:52:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705906328; cv=pass; d=google.com; s=arc-20160816; b=uRPqKoPAwKUhk8296jffOTpsE9sSAKe0YwmmM0pkGFUMMzCfwzNuKFvkOOYt2Ew7Qt bFyecxJMe62AwmN6Azi5hir6MYAnGVR2QWr3ORZF+fNP08EgH/ykPXxVGpIm9EcWCbjH anxLEt9zGk7zmnO0EDstEdo97vVOtf3cZj/rCe8aHF4e7JMgWMFVCBOV2zE9eOX3yur/ OzGngWHXRYOpRowMdQl6WRQ0h2XFByutRzHbRul2hkjvu7oJr816nSQA1f9I3N5xlYHE rj26rInwKr7e0rBUd6q1+YHdDRFl0bgYfYXdt86LPzD3BuKbPC5yGrH3lFtKdoSUtHva ySAw== 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=rgcXrf6x3g0AFfGNeTRNVD9JonbOcksFUg50spIVZ1E=; fh=VIymyPrEIcOR2cPH0mk/MrNg9+tGfyCUCcB8BhJM1vo=; b=mC0tPgZUvIhkKItAYbMJJDtAGL/z78vCg3551mTFkIm60f0aFTmEh5MTz3jYbFTTeB UZH+OGeJvFhZKdcPvuzyh7LVqOI8wGXwNkYjtccWjTlUDoewONMzvUJkKelcDhCfVTGb 2Ra9TNW6S81SqGvyQtQBaSwEseOv2qWQg031a+lOnYgabzeB+gHYYlFuS2m8uwQ8Qmwp +i0l+H9hkASimaUPjP0Zxpe4/q7xVkyScg6h4h3twu9IDygzOGo7I1qtR6dosdOse5Ml n4IESm9LUeliZxLg0Ytcw5CHaC00ICwSzxDuXVo9JpTZPgGOn8kh+t4Msq9YatSDHj9y +cXw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=GaKCRbBm; arc=pass (i=1 spf=pass spfdomain=kylehuey.com dkim=pass dkdomain=kylehuey.com); spf=pass (google.com: domain of linux-kernel+bounces-32382-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32382-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id k7-20020a170902c40700b001d720012ba0si5776313plk.128.2024.01.21.22.52.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jan 2024 22:52:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32382-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=GaKCRbBm; arc=pass (i=1 spf=pass spfdomain=kylehuey.com dkim=pass dkdomain=kylehuey.com); spf=pass (google.com: domain of linux-kernel+bounces-32382-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32382-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C5B7FB2527F for ; Mon, 22 Jan 2024 06:25:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 187176ADE; Mon, 22 Jan 2024 06:25:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kylehuey.com header.i=@kylehuey.com header.b="GaKCRbBm" Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 CC79C610D for ; Mon, 22 Jan 2024 06:25:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705904746; cv=none; b=j7mFddg6XfnnPogf0Rokf5oVZ/79I8T7xiz2hkU+3ntxhz3IJDi5vfN3FiEVvpI8CqNQ81+0V9RXuws7qDXKiDnLIgmz3buGo8O9G66z/2naoU+Qr+ctWj8ou3QmWLCpaU7OTWqN7wVgvvlq9kJo7kZIj90cXR9kEJLLFKRXel4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705904746; c=relaxed/simple; bh=rgcXrf6x3g0AFfGNeTRNVD9JonbOcksFUg50spIVZ1E=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=ms4qxHA/X7iaNbombp1LZsfng3mk+j981onGmBrglA6XHlcuJRHrsItBBkf8ZS4KXxUKglrKMh/jLwhcjCxcd4+4rNIUQAGe8y0CiMLDded3lW3mVPN7qNNaxZrVS/A50leAQJTg4yyNDnIQJnVFJvR7rJ7BY9lNaRwPU5bNbVw= 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=GaKCRbBm; arc=none smtp.client-ip=209.85.214.181 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-f181.google.com with SMTP id d9443c01a7336-1d711d7a940so23454705ad.1 for ; Sun, 21 Jan 2024 22:25:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kylehuey.com; s=google; t=1705904744; x=1706509544; 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=rgcXrf6x3g0AFfGNeTRNVD9JonbOcksFUg50spIVZ1E=; b=GaKCRbBmdWASrYHXtHLCoCpAwzCarsvomL64rWU76mmnCJ12npJBMU6BuiD23yhtwj 7/rJVsGDsxFjgiMHuMDkpQ8g+R4YY0CKLwxZ8O2t/m6aDwBeOiKicusclDLhumopNYhk PkmCp2nJUeQ5Mdr5aa20OMdwyKwfWJOUPtMNoEv4gXKi08e7ZYogXyLs4vxZb+Qfjtqb /KvpjnBHUgS+ia8N6wYwCRzFKYppyckhofU6LZ9Q9vio3oS1grJeFG98TbjYFlqkJhug d1OOBvGFrdt6u9iIadBlWyVuBPqyFH2JmjgxsBWkgBKmiL2nYB6huNL7FcfjSgAYk9Vs JP2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705904744; x=1706509544; 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=rgcXrf6x3g0AFfGNeTRNVD9JonbOcksFUg50spIVZ1E=; b=hu1XAbh2DWGB3Gf2d1aqkXOc0y2DrotE9wo9DSVlrRGhuWo8lPilzILBsMSROCo97T zlOlco4fCWU4/uIH3/fw2b9z0PY00BfNRj50QkH7v1H4nmq++Tytj8Q7zgxJDRMsv8dC t4feEi3ZMFSuVm0jM68+CIgvPrMNKkhKsh+EgHVRmqEbIBZB41bCPMqyKsUgmDzZELif EksW4625a9BRntFb7wI/mzAVlMJD3J0NJ6FPrO+SaypX1VYpopiQug/SggRYuceBsiKF tyze7Cr95MAvQ8J97BrxPn4KggZTsbnkIZIYRtYLS0r7gcR0/JVGpVK45ovLzzW/Rumr T2gA== X-Gm-Message-State: AOJu0YwGTYv4J2HokeH2w/O2jDOhCd8dmBYgch5j32n+XX2VpwlygH8Y R0KdMdwY1xSWZM102Rf8Xs1DJE1gJ+oNj2eox1WDYABxhkgmcNOgK3eBSWJSHA== X-Received: by 2002:a17:902:b088:b0:1d0:c7f:8eed with SMTP id p8-20020a170902b08800b001d00c7f8eedmr3966816plr.58.1705904744001; Sun, 21 Jan 2024 22:25:44 -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 u5-20020a17090282c500b001d7248fdc26sm4317771plz.69.2024.01.21.22.25.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jan 2024 22:25:43 -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 Cc: Robert O'Callahan , bpf@vger.kernel.org Subject: [PATCH v5 0/4] Combine perf and bpf for fast eval of hw breakpoint conditions Date: Sun, 21 Jan 2024 22:25:31 -0800 Message-Id: <20240122062535.8265-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/20240119001352.9396-1-khuey@kylehuey.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@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.