From patchwork Thu Dec 7 16:34:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Huey X-Patchwork-Id: 17701 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4907159vqy; Thu, 7 Dec 2023 08:36:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFgavwcSMCWNA7NnmSFAZhZt5lJk5cWDOE7Xq99zRi6IqHuxUmND9sWQIhtINQjiWk6wpgk X-Received: by 2002:a17:902:f681:b0:1d0:7d9e:e727 with SMTP id l1-20020a170902f68100b001d07d9ee727mr3069166plg.14.1701966996578; Thu, 07 Dec 2023 08:36:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701966996; cv=none; d=google.com; s=arc-20160816; b=NJqIOn8BdZYvNXdYx6Q90NZWqcPiIsNIKmKUpHzrNBenwpHONsNbL192ZyIJ0VUVUF AGu6aozI23mhHhQdVyiM5JpaYeTSzehWv4CRwsPDUAqxm9lrLUmLG8g9e24DMqabl+9T DSrHhV33g2xPB33y37icxETb5yGpn3ECxP3tAr71MmkAQ9YW4hqZpv0pVWUVGuP6hd8+ x2SxJsyw+C5AxUFrM8PLtLuHkBJaMOjkk2CKbHKm4UXMDf9FsgI9uT/ay4v/jWVrVWDX bHdNj5Yqvmd2q9pflFEgCO3CD1rZOIxjGf2bjAETd1ezU2lKi8TuU1tEp1rjYthXXw/c IS6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=xogDwySrHiRFAfCXEnCaVWOOT+dvRIT71JwIoqFZVtE=; fh=VIymyPrEIcOR2cPH0mk/MrNg9+tGfyCUCcB8BhJM1vo=; b=Lql00bsqscbB0aKoja3vz4Cj3iCNOER9Ywd5BnQsAulR5ye8FkEMY7EAXmMC2A2hAO LZG2T6RzD+2skTg5jCKa2ZcM3m0/NdYhZVWjSCYvy4A2eXzDGoDb6OJT2IGoH91L0oOo KDpQVFKn7GbbEdTsv0dD2sq+//UW4PCfy7hCFnzzAc3fzfW6GHjaazDvEPspXBBTNpHD KEhmLDG/08djSJ7ZYCSh23PxB9Xd6dm4NzGOzyHZjj1PPEjDdkduuQ21lQhjkAbTi5RC FQae2mnEVlzYSEPvN48NHmuVAFCVW2BoG7H8ZzMQIMAjN0paXgvIyaWEwr4eokrHXjo7 WUKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=EvNyROlM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id bv186-20020a632ec3000000b005b8ef498e2fsi1403863pgb.181.2023.12.07.08.36.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 08:36:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=EvNyROlM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id CE0728085F82; Thu, 7 Dec 2023 08:35:17 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229949AbjLGQfI (ORCPT + 99 others); Thu, 7 Dec 2023 11:35:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232666AbjLGQfG (ORCPT ); Thu, 7 Dec 2023 11:35:06 -0500 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E42A8D5B for ; Thu, 7 Dec 2023 08:35:10 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1d048c171d6so9640385ad.1 for ; Thu, 07 Dec 2023 08:35:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kylehuey.com; s=google; t=1701966910; x=1702571710; 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=xogDwySrHiRFAfCXEnCaVWOOT+dvRIT71JwIoqFZVtE=; b=EvNyROlMdIw6MNUH1GZ8AGOS2+s0uTw1QVqATc5+52zV4QJbOMhAvINSslxxGT+dWX ERKSagQJmdK27Ss4Xjf+iALF3GVnFnOjXO7CP4x+mQjZWiVcfm8X2+d8FnT7Tr4i2JLQ WiGlx5TrDJTYq6oa/ERU1wbHrkRnSHtAzI9Jqx3Z/3OFkrbg33Xs0/+xFIs85Je+3tw5 hrkDgd5d8R4rvmxblbs0G5TBoUXbdsdkx7XwiKhVEYSETsIlZYDWKSaQMS8UQ3ZolQ8H b436MQZM8hJVNAqvAR0KphhM/mtRxzbfRSDp6KSrGgRcX9vVnWaPtoShI8PtEXol2n3/ HyVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701966910; x=1702571710; 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=xogDwySrHiRFAfCXEnCaVWOOT+dvRIT71JwIoqFZVtE=; b=lLQJm3rlVJEx4j4Jt0WjcpXzq1aCZFxt3j69SXFBw6hHph7wvZNKqVkcstMWNAN8eB D+KISbcpjw/4ku4yB/LYbAoW5GwHwSK8qC1PJoad1gi4Wk0gK/bliz3Ir1q+90/CpRcx KShUWB6UkJk2Uj953aHFmdH4+4j9EByFhtT9CfefpBoDm05cU0qOQQbj0SapwgbAlGbI 71d7l1ss7sw35/RqA94aLlL6tklJXWF8EmDfQfWWAojIZDy/bn0MUkQ2F13yWnyJSOyf 29Zh6v5yt/ZmyFxAIhWLSxdrQrXTRjpeOBKBAPGNQBDD0s9gWf4MP15vYLhjTId0HYsA 3P0g== X-Gm-Message-State: AOJu0YzKfO48pferhDwK+zBnd5V7fE8Pg/cWwqXmWArleTfCtvD96wi4 DHq8rzRUgm0THhVbo7eulMP5Lg== X-Received: by 2002:a17:902:a711:b0:1d0:6ffd:9e2e with SMTP id w17-20020a170902a71100b001d06ffd9e2emr2493195plq.128.1701966910194; Thu, 07 Dec 2023 08:35: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 iw15-20020a170903044f00b001d1cd7e4acfsm6143plb.201.2023.12.07.08.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 08:35:09 -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 v2 0/3] Combine perf and bpf for fast eval of hw breakpoint conditions Date: Thu, 7 Dec 2023 08:34:55 -0800 Message-Id: <20231207163458.5554-1-khuey@kylehuey.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 07 Dec 2023 08:35:18 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784641745736806280 X-GMAIL-MSGID: 1784641745736806280 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. This appears to be a simple oversight in the code. This patch set reorders the overflow handler callback and the side effects of perf event overflow to allow an overflow handler to suppress all side effects, changes bpf_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/20231204201406.341074-1-khuey@kylehuey.com/ Changes since v1: Patch 1 was added so that a sample suppressed by this mechanism will also not generate SIGTRAPs nor count against the event limit. Patch 2 is v1's patch 1. Patch 3 is v1's patch 2, and addresses a number of review comments about the self test and adds testing for the behavior introduced by patch 1. [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.