Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp734196rdh; Wed, 14 Feb 2024 09:42:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUQl19EznFHsIt5ypIgihvW+6HEBTp5vBMI6Rg9d7eekhWwTbGMqwHa2lHhEyafKWJ4ekfUmW9oxl5l0Dn5dGj1fAMCpXLv3C4fEdiZOg== X-Google-Smtp-Source: AGHT+IEFAyddjMUXPdC64nOq5reHKuj4U0hNf8rtJwL36rfhVGkgANMZk4sW3B8u4T+D7Fr1Cz2i X-Received: by 2002:a05:6214:d49:b0:68c:c3f7:618e with SMTP id 9-20020a0562140d4900b0068cc3f7618emr4274113qvr.19.1707932538739; Wed, 14 Feb 2024 09:42:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707932538; cv=pass; d=google.com; s=arc-20160816; b=YllmCxOmBFKX61NkR9X5OaYCoR14K1cpqbrcnK7c6orD0RAqoxti1sUjj3z5GME84m jrtQWHUVeSMHlh0lYM0e6WmM+Y6ehVDtfC53Lui6U+/AZG0jOUE6rDFEQxriYwJzNxqR 0vZNiVQ0DhzLsFAOlqUYFeQOXRN18PQTTzRYFoTgimLeiAxAHj91zXyMZhz7y8VJQdrM c18wAJP9e56AD6v/R7D6SW8kF0UWBR95LmzXGzC8vp+3vjIdOlm6q1QWqjC/D49L4b1/ pOoD4yXdZpC07jRBFPPuFjIhaCSzyJgHz/cZElKDB03xBTNccVGexcKaOcj3gAYpcPSg FoGA== 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=jgy2rEJspdN//Zbn+lFhBu2O/NSR+ai7CwG74xi36l8=; fh=TSmZ5RH6XUxdznPkJWrswAeUf/Krq0v0o4A21rXSgl0=; b=ytzpBINz8A0ARvPPolxBI7ycOQ0KK9HRMbSnacMIlXnzRn1fHCHjzBX4zelNvHdCTU wxMEaSIZ6OqaQoRCOAls6hQ/gF0CMEoDqcR2nd0V12FT9UZ5hYAGBbRzR+FxaOoUmEhR GYWS5Fm6ohn1M2D3uSkAAZxcueBQdLe4Q8PJCwvn2VKdkXfvnUVVCC6BMw1svTXXXcx7 bJJeOO0O+iEJGt87Mn1Px3LB3WVPJ362/ZWePuqZRJhmIBxOQU6xVqsgc7oeVo9jUtw3 ziNWUvGeCBG48oCYcvbVbYa0eRYFI/idP571MLsnnfCAVU+c0wyiSxL4UiG/uVQIECZ9 8LXw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=cshEGeq4; arc=pass (i=1 spf=pass spfdomain=kylehuey.com dkim=pass dkdomain=kylehuey.com); spf=pass (google.com: domain of linux-kernel+bounces-65696-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65696-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCU42aulDdF0QayBY7EWG8GsYQoSblw2xqx6kQ9JBCZXtI6CHYKBf7xLCcN62AXGovKeV8v02ZRFAkZQUqLF5MqpdjaIHP9HIixJtaiXdw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 4-20020ad45ba4000000b0068cd5aa1600si5803007qvq.499.2024.02.14.09.42.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 09:42:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65696-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=cshEGeq4; arc=pass (i=1 spf=pass spfdomain=kylehuey.com dkim=pass dkdomain=kylehuey.com); spf=pass (google.com: domain of linux-kernel+bounces-65696-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65696-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 89B5F1C2975C for ; Wed, 14 Feb 2024 17:40:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4BAA684FDD; Wed, 14 Feb 2024 17:40:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kylehuey.com header.i=@kylehuey.com header.b="cshEGeq4" Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 B352A84A42 for ; Wed, 14 Feb 2024 17:40:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707932443; cv=none; b=f2D9RfkD7H6fwWGSrUcKxDdkMhQFL14BrhsHrS9cMyO/7YkLLGShqUFrKa3UZpZ66O5Bva2pjuX9/M+N7lJdvZK+NCbAuyMCgD4rGHm6vuc/dCiSWlM8g1QRzaI3vfZpE/t2SoYXNC21nYbAsVbc+bUIfT3FquIJkLmye5wUPM4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707932443; c=relaxed/simple; bh=jgy2rEJspdN//Zbn+lFhBu2O/NSR+ai7CwG74xi36l8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=kT8Mo0tPOA7EZJfbbmsi3e+ddIOWm5bYl3nUEVnn5UVnO0gv97E2hERv3wmY0SxiRceiRRiYqnjnvne4+748ET08ZRKi/nfCHB+juIOt89/8FOQ3K0bA+m95PQKyZs5t0Zyw3c7JQFIVoQb5aGIGxViMlsyPb/Jymq1tGJ+JaOs= 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=cshEGeq4; arc=none smtp.client-ip=209.85.210.175 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-pf1-f175.google.com with SMTP id d2e1a72fcca58-6e0a37751cbso33221b3a.2 for ; Wed, 14 Feb 2024 09:40:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kylehuey.com; s=google; t=1707932441; x=1708537241; 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=jgy2rEJspdN//Zbn+lFhBu2O/NSR+ai7CwG74xi36l8=; b=cshEGeq4uL3Qs8a2xF9v32Aot1qFpjiU9PYHrMy484V67zH5QG5Eag1ZAhKCqlxoDS qRnHvxx0ziqIVJuh/uyh44DjrnuyfaJSqrVrCe6/7x+aVqtYa2VspoA+F7MCGb4RZiI8 DkysExi3m8K1YFshThivrZQ0Br8ITpfIexp8uDqTQ+N6s995m1J2TcuyzlLaFcdKTzp8 3/HiUnPbbqK9a/pOUoj3Cnl1Kf1YLAXAu8jSuoxa/MzW50SlDRE0KvVwWRsQz4Lz1+Tb 9q5ayMsViQrLEKcFBwLF3HhhmX+6mpLk2jLeKdIV4VbrtvIjXAp/p4oRtO9ATMf7xTyJ gHWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707932441; x=1708537241; 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=jgy2rEJspdN//Zbn+lFhBu2O/NSR+ai7CwG74xi36l8=; b=gmqAVqXBVTUQT5bM9e53Yg1hFa+zQYz/9Hpbyw5B5ucYDTHfcIvK0l/b3dY4uHYNjb X11UE0uCJS1Qc82v535BW5kvbDT6W59Ac7Y/5nRUP9OVIlKQgiIDB1aIfJKsBdyyozCz ZnF0k80SEMpQ4YjMsJY6ipCAbeOhb0QymM9t/+fugoz8WJkx0pyblKhog/rJcT24epsw ajDlbz8vlPAGeOqcR6cnNuc/JLjtLOAYMpPQ4qmJVfvSvUghn5WTo76Gc6Rfrr7p6OZu o6oUfVDrf0LXK5cYOLnt254XJDjM7XOUPYy+Jp7dhp0cg7rt3Sr2XTSLY/zs+LaXlrL+ 7xYA== X-Forwarded-Encrypted: i=1; AJvYcCV5Zu3A3sWUYnUd2swNniIXomkocnYohy7H7yFaTlZhLs83aRdOs1UNSDTTlrh9GalABf6H0AArV8ir/SAfgZ5IPl9PlWR61VbjidXg X-Gm-Message-State: AOJu0YymDpfKhtahAyR5E0UFu5FS4PKiy2+2kHZl1ut+CLf3mRqLm/eY 4aGPfxZ0cjsxhJQFliqfZCEhV/dT/ZB6UuQqCSEztWF8Xfkx6d/2vcovkz19Pw== X-Received: by 2002:a05:6a00:b43:b0:6e0:6a38:6ded with SMTP id p3-20020a056a000b4300b006e06a386dedmr4004544pfo.12.1707932440840; Wed, 14 Feb 2024 09:40:40 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUVN3G485IyQtiWXChm4rxS62IFSFeMyx8XXwhMpaCfud4q7qWXuJidif8vl1V9Hs124NvPiZTxGaMlqZdMI5dhmc6KCHLjhSRlciye6v9GYdyS3CfDMwTmdiSIGHWsT0iPK9DMkNdaR0TtPT+TYjKyKb4q3LKMtlqsb1m3QOxbDumQiKXoRwOhI2QQQaVIM9wNJQmSnkbC9/30hWyl88D6rucTDX875kd7bHH7yYYbM+S11ltDJwOsOH/TbIFvQb6XqleXVArQSfCRpEOScN7GxrRpVSrVr5LHB6Rxl4TX/OOWuHV7gIzsSu2t5HGBISID86SAKQKniTHV9/g+7Af+R3UjliQNVg== 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 p5-20020aa78605000000b006e0874cbaefsm9567604pfn.27.2024.02.14.09.40.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 09:40:40 -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 , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo Cc: Robert O'Callahan , bpf@vger.kernel.org Subject: [RESEND PATCH v5 0/4] Combine perf and bpf for fast eval of hw breakpoint conditions] Date: Wed, 14 Feb 2024 09:39:31 -0800 Message-Id: <20240214173950.18570-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 Peter, Ingo, could you take a look at this? ---- 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.