Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3756837rdb; Sun, 10 Dec 2023 20:56:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IESpWFV/io5oTG/9mxPipFTRLwARuIH0qa/bHpKhIfhXTNpaNx8urK/4NRqNG98FVZoY7rt X-Received: by 2002:a05:6358:88c:b0:16d:fb29:d78 with SMTP id m12-20020a056358088c00b0016dfb290d78mr5200596rwj.2.1702270595408; Sun, 10 Dec 2023 20:56:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702270595; cv=none; d=google.com; s=arc-20160816; b=Xh0+zHPdXTX17Rwhh2yTBi7Fx3cC9R1hxwFJSspriyApai58opTbWhFOxiJ9QbHBPT ftAkZSLWaPg2jXMrbvbUX4PHNLx4SZRRaHIYbA7Ds4RXdf70mEHXUhcqFQ/dY6opTb0W nDM844SS7y6Xhw+rzzHVwGsVQbWjXvxTyNdlLrQ5QSmNqolmwB1spwCRrs7QBm9XKMaV t9E6vPoKyn8LW8/skWXjVzfG9J/Z0KfbvWZ7/sHA82dxZy1yXi7ty6AyA3B7x1Rcb8DI VicLX2fGZ7/dfrrM0YUQttMsm1T3Buqy9/k76KWCA1ALHxestQDVqOEhzMjeT4ysD/xl 5QvA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BoADJIsaU4bvjYI7gdqH4FQT1qltoRFf88+tkPG8tZk=; fh=TgNdCu0nkwWF6I0gv1FaAZU9nxNhZAbxhuG8wY4k0B8=; b=ojM0WIcnG7LjkbFiXnseJ/ip2TlAQ28uQACvKoQapn14OAaS/2KaBcxxcoZg+XkhX7 EyolC19E1pHDUr9+crTElWMCuHDuLerduK41O8dMSvGmjsc7bCbDIDwujTK+4zDeer0/ u3uJXtsIlSWfTI1gh+ZabQkI0iYrHLXfBLU0ifnv8SXJzsk/pzcKvz9naNQQqxspL5nz k0UYyObtdVO0itzhYkY4BTfthA4GTI5uWxvQ694eLWS7OZnV//ldtbn2OxKaEh5BJSdx ZmsirmzUUVOJcHbB/NHmKT9bwaP9z2ZW4Roi+i7bTLiufEPszg4Ra05/GAJNNQo1f6Fj f5AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=TKGWwN1B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id t1-20020a63eb01000000b005c6bdab9e4dsi5397562pgh.746.2023.12.10.20.56.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 20:56:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=TKGWwN1B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 E75B68062292; Sun, 10 Dec 2023 20:56:31 -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 S233080AbjLKEz6 (ORCPT + 99 others); Sun, 10 Dec 2023 23:55:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232996AbjLKEzw (ORCPT ); Sun, 10 Dec 2023 23:55:52 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6D82F3 for ; Sun, 10 Dec 2023 20:55:58 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1cfb30ce241so35598025ad.0 for ; Sun, 10 Dec 2023 20:55:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kylehuey.com; s=google; t=1702270558; x=1702875358; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BoADJIsaU4bvjYI7gdqH4FQT1qltoRFf88+tkPG8tZk=; b=TKGWwN1BMSfkcarzFN58mcceccPtTKo8f+lsaSmGESfSjcWXVzeVturjsETQBsbmFx KoFzR0qSE93M3dMBH8rwryOSXnsHsy/ktAVjRiH8ZWThdUmvvFdSo6m+o39XW1tLokql TZZCzt2UKeWBkgUg15enpKP+v+8vlN4oR/uaWp52O7LdaqWQJXf99XOf2xc90YSpbfX/ aPRFQdKIKvUP+O25NwGvrJ6cywElGOKbvQQ81ttlMgK29w2zSm3KQ3o7B7Xo9Vlw2xSC 9INEfPcO6VTPC4wEaYbnmjqIO922djMFHBBlTQ/kUX5QYXtleLSNqrGZzCy3toqswhN1 an9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702270558; x=1702875358; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BoADJIsaU4bvjYI7gdqH4FQT1qltoRFf88+tkPG8tZk=; b=Xam5YCf9yzFyc1bsPZwqv895/VrZOOC/xUqFVJBZ3MRMiZugydjTPZFkQwfrIRp2Nm QLauyPQXMxVowvxNFDX9q/OIYOV8dYFByhNiDTWRImggzjp+jiuGDL7mZJTrZLeqh91C GqAmHqZ901Ml5QiTdE3OsHNrdqxKmIZbp6i0dHJ0tq+peDNLaBYTcPZY1TBY+woEODNh hMQLxx22LPXyKetQs8W6/CQwNBJ1WDBcor2kM8tAfLI0ccQVp1gujd2DipkNUEuckxbO gbHg3xWo08jGCCxwrCCsryk5U3M8PR9H5T6KhfGgPZjzCYXwYOHyr9s0lfyM1Ejja+Q4 B/AQ== X-Gm-Message-State: AOJu0YzJmpBkOxZIfkB07cyYaMqU+JV0yk+464800a8hqrykQ0lye/wv ldYgxqaL6YKtTY6LGOpZ+TbvbQ== X-Received: by 2002:a17:902:bc84:b0:1d2:e976:bd21 with SMTP id bb4-20020a170902bc8400b001d2e976bd21mr3501188plb.94.1702270558222; Sun, 10 Dec 2023 20:55:58 -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 e11-20020a170902b78b00b001d2ffeac9d3sm3300623pls.186.2023.12.10.20.55.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 20:55:57 -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 , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH v3 3/4] perf/bpf: Allow a bpf program to suppress all sample side effects Date: Sun, 10 Dec 2023 20:55:42 -0800 Message-Id: <20231211045543.31741-4-khuey@kylehuey.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231211045543.31741-1-khuey@kylehuey.com> References: <20231211045543.31741-1-khuey@kylehuey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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]); Sun, 10 Dec 2023 20:56:32 -0800 (PST) Returning zero from a bpf program attached to a perf event already suppresses any data output. Return early from __perf_event_overflow() in this case so it will also suppress event_limit accounting, SIGTRAP generation, and F_ASYNC signalling. Signed-off-by: Kyle Huey --- kernel/events/core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 54f6372d2634..d6093fe893c8 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -9541,6 +9541,11 @@ static int __perf_event_overflow(struct perf_event *event, ret = __perf_event_account_interrupt(event, throttle); +#ifdef CONFIG_BPF_SYSCALL + if (event->prog && !bpf_overflow_handler(event, data, regs)) + return ret; +#endif + /* * XXX event_limit might not quite work as expected on inherited * events @@ -9590,10 +9595,7 @@ static int __perf_event_overflow(struct perf_event *event, irq_work_queue(&event->pending_irq); } -#ifdef CONFIG_BPF_SYSCALL - if (!(event->prog && !bpf_overflow_handler(event, data, regs))) -#endif - READ_ONCE(event->overflow_handler)(event, data, regs); + READ_ONCE(event->overflow_handler)(event, data, regs); if (*perf_event_fasync(event) && event->pending_kill) { event->pending_wakeup = 1; -- 2.34.1