Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp170768lqn; Thu, 11 Apr 2024 18:50:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWYjjKS4GLvSVxLkY8zDpo/LRwmmyG4zJlZqa3KLpsnTIQkd/+oYkmEEh9+LQD1HoD+8KBexWA8s7C+njdXZ2+rshosr7L6pnMJzugZxw== X-Google-Smtp-Source: AGHT+IERlQqjx2LvABBvbGLjjHWeUWPVSQe4a1HnoML5JjzUuSa5pBGn23uZ0tufPej+HNsKvKao X-Received: by 2002:a50:d4cb:0:b0:56e:2e41:3c39 with SMTP id e11-20020a50d4cb000000b0056e2e413c39mr888638edj.19.1712886650127; Thu, 11 Apr 2024 18:50:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712886650; cv=pass; d=google.com; s=arc-20160816; b=lxKUwYtoEeCbZfyAaFXDnue8wMhMtVI654SLU98iZZW7Xx0zMoa963lC5VjvSFcIni rPTc0h5P4ZrKvDCfe8eQPTs3GfBvrZdWPph0dvXrappYoHgfnYX72X3j2wJAfISOtLYZ 9z8Aue0eD0V/yayGQHXyP3USaUvjXe75lvRkCm8CXSkyTBPQPxXEcN1zAZh13PNa1ADx iUP8+fPFTUGjZkpwTEb9EFQhAr8r75sCstGaGMrqbM82g6NPDLTqSj86FZELcy2mXgoc CJLEJe3UJK3bAYzQTfZcLH3LpN738+SRC5dp2W5hwMhtgHrID7AGGrFitjmI/EIqTbDe KyQQ== 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=RKfWMjr5Qx55FeibUP0Tdl8Z8rvHwRWMq761t6ZocyU=; fh=ZtXVA7GvatSa00SVwIkiCHmipMTTBbCidVr/9RbTxQA=; b=ju3utRYQ/PH0Hz8d8Z8V72kmdm04pcRygq+Y0mPpVjLLfG/wAlGCEFMik1wywtGPzS fIkz7G+A7WGMwwY0ZeOqedqY0NdudBVxqcmQwhAtVlW2D8PINGV/j5i4pZXf10BKx7oe 7Y9mK/wyRdnuAZv2oAXSnNUB/qByhvgHAgvQaA3GGjVPuNYqGToK5frnJtWD9j3U3PGn NC1Bxuwwlkiiispuuha6+vVkfFWkVVxisFIVzQF94uQuousA/cZrjqs2y4/lNkbABH1O DzgA18d2klmEewT8UIBtDAtKKlyMOw8KOR+ZHz1ZYqJ9s6j4vNxOQm7FOrPahbcXC8OP 7+qg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=h78Qsxjb; arc=pass (i=1 spf=pass spfdomain=kylehuey.com dkim=pass dkdomain=kylehuey.com); spf=pass (google.com: domain of linux-kernel+bounces-141780-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141780-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id h7-20020a056402280700b0056ba01693afsi1260143ede.510.2024.04.11.18.50.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 18:50:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141780-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=h78Qsxjb; arc=pass (i=1 spf=pass spfdomain=kylehuey.com dkim=pass dkdomain=kylehuey.com); spf=pass (google.com: domain of linux-kernel+bounces-141780-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141780-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 am.mirrors.kernel.org (Postfix) with ESMTPS id B14C21F22F9C for ; Fri, 12 Apr 2024 01:50:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2822ED27A; Fri, 12 Apr 2024 01:50:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kylehuey.com header.i=@kylehuey.com header.b="h78Qsxjb" Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (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 D81414C92 for ; Fri, 12 Apr 2024 01:50:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712886642; cv=none; b=gcnWXR237iaqQfT8N+JuEyPNg5liZyUrllksc1UAH7yxdD7HDWX6KS/AM7qQjuLvxAXzPFVzp3mfOOutcqljlq2MYF4cKqwRLHBCXv5M4YzL/QXE4JoFP8Y/tvIQlsf0Swnq2GZAsR7gxLxYLtxDJbEB6/kgxvYKiGpn2bmyk6I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712886642; c=relaxed/simple; bh=RKfWMjr5Qx55FeibUP0Tdl8Z8rvHwRWMq761t6ZocyU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=QhoD2J4anXn2wQy1qOF6yz5AyReaQe2tfRYpqbPlR6oTtwGUFvtQnV5AJ/9Z1NlUttZEOzhCHVa5bapMp21QY4B45ABG0js/X6Iod82PZvVum3WMGqyXgGJFIa3glcccZ7XsywnUpIgST8O/45RDssAKkaiWUp39w6weIPIoWZg= 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=h78Qsxjb; arc=none smtp.client-ip=209.85.222.180 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-qk1-f180.google.com with SMTP id af79cd13be357-78d5e80bc42so34443985a.0 for ; Thu, 11 Apr 2024 18:50:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kylehuey.com; s=google; t=1712886640; x=1713491440; 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=RKfWMjr5Qx55FeibUP0Tdl8Z8rvHwRWMq761t6ZocyU=; b=h78QsxjbzPkO/ItaWrTyIkFan3/dyp94gMjCEpJH+Zvh1erJ2w5qSgko4G9vzet6Jh yOe6LZmESQn50cwnYr0S9ENNQFSzKePUIY7yTirD8CyOmZmun11yd1oiCS2Ynklmybcp v/wCgavYj02iCwJ6IlUSE0OHvXDnATLZEKExoJRkb5ilhtaDrIefqnyMFgGKuMMYbU+i X00WeKDOBlL50XwfXR1c+yebDg1QJtEvrVPwKmO/ShtGqOzBmeDGKp5yM2sNFh6LO77a OWptLaKGcVsRBi88GP0vB7u9+yjyQNBMx0JNpPh5FkMvisSNKrBhs/zimRkYxRaZ9SxT qQog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712886640; x=1713491440; 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=RKfWMjr5Qx55FeibUP0Tdl8Z8rvHwRWMq761t6ZocyU=; b=J66o2U13Z2AgXmUeXFgj2MaBrPib4n/TOHpVWm0HjHDJqjDxPopiAuNdwdQUG7nFwy 5ZvryS7ISL73AC0l15uJMBhgBYDzW+UaYeS9Mm1u4LjAFGly7pwc0MNqrFjKOq3/pHr9 +brH2VoZ2QUld8XR8YLwBPZ+VCOEfw+dW4vOtbhUHYzypEPBoSSrnvjd8Auj3dYM9xSA vkx4YPwqLxhSlQPQD/CORYLgYklDO9rjqQLgH7wlH7gN/jSYvgGlJ5c63kMD5po3Xc0D Qtc4nNNbgpyaJ95CWJK13d836PPibivfohcK1X/SuG8hF8Z36ybztGxTvsWfQ7TMBbbJ tZZA== X-Forwarded-Encrypted: i=1; AJvYcCXwL7zE6zbjbzoyw6ROj99HXAwqfgnJOxy+uqRYsqtt3hnaM73ellBT51OGA3OTSbV6FTtDumKQ+b5UZXsxCaL5B7dbjMQeZ0WXYuPQ X-Gm-Message-State: AOJu0Yy2ljbPbJTHSnxw5EaPxJ58wB0AQ8OeZqFlVfrTNC3SO4hr1vfx XmBeO48vJ1LiF1vaUyB3IKywJigPHyBfptN8ayE+s+fO9tzl0zaVzGgBqqEtuQ== X-Received: by 2002:a05:620a:14a1:b0:78d:5700:2ce0 with SMTP id x1-20020a05620a14a100b0078d57002ce0mr1227193qkj.68.1712886639804; Thu, 11 Apr 2024 18:50:39 -0700 (PDT) Received: from ip-172-31-44-15.us-east-2.compute.internal (ec2-52-15-100-147.us-east-2.compute.amazonaws.com. [52.15.100.147]) by smtp.googlemail.com with ESMTPSA id f10-20020a05620a15aa00b0078d76c1178esm1756677qkk.119.2024.04.11.18.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 18:50:39 -0700 (PDT) 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 , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo Cc: Robert O'Callahan , bpf@vger.kernel.org Subject: [PATCH v6 0/7] Combine perf and bpf for fast eval of hw breakpoint conditions Date: Thu, 11 Apr 2024 18:50:12 -0700 Message-Id: <20240412015019.7060-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/20240214173950.18570-1-khuey@kylehuey.com/ Changes since v5: Patches 1, 2, and 3 are added to address Ingo's review comments. Patches 4 through 7 are the previous patches 1 through 4. Patches 4 through 7 add Andrii's Acked-by. Patch 5 fixes Ingo's comments about punctuation and newlines. v4 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 subset of program state that is practical to check and verify.