Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp689672rdb; Thu, 18 Jan 2024 16:25:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGH2jIMm6aSCs+czP/74AbYPcY+X9ujrvCSEzSfDIPJLEMb0c8LaqHJXu4vcEytwHCMyAMN X-Received: by 2002:a17:903:2805:b0:1d6:f59f:f2b5 with SMTP id kp5-20020a170903280500b001d6f59ff2b5mr1602747plb.112.1705623918900; Thu, 18 Jan 2024 16:25:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705623918; cv=pass; d=google.com; s=arc-20160816; b=AvxJXMqoOjaFFnUlk78byCGJjTQ1gg53gqwWRTG4wCezLxFv5gAnk/M0Bi4WOHvH73 guGwUcg3NqpU/Zm2Jx0Ns63VKJlrF/8h5bKp2BEVi3IEuzLcZ5zJP0iE53IwQGY6JlW4 lD6Xz8cQiRKeY1kIq+Jp2ISpaQ8VGcj/QmJyKqShNlg5gGgvsIu+TwnlVwBSSwMfKr0S 6EKxpysa62x9QkyAATVq8y2V+tqnf+aPVcD8OTctcoL9CrrtAVwqzPpRy+75KWaN2Iw6 9j/Wr3/LAQbaKWRK1Dxae+hPbCpdiBAanaS7v4NfRQspCVoitxvF5E6P99i6D2kImNUK 8lRw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=/hEmM3vmtzdKl0VwvFdVPj5xDGeYkLg3iqjbEyKv8xM=; fh=vyLuMFPX7a5RxtKqZusW0ny9V2SiUBkKFuhqxl/vIvk=; b=A/GmaNPG/iwsSdb7woXfQLdlMLI24HU7I7b+VJBoOy9yPC9fRhT5gjGRDIZyaqYYW3 j3yse0sdSwilP6LFWb+qXEdMnFL5swZtXiarKHoYacaoY31vbSih8ehZao52WjwVr0/+ o7jA0MTzOsSYyFVXfdPheZZnkKxH1eITfMcjN+LbTxf9St02nXOQnHS/UjcB4ExT4Tqf A+HZVWL+pDCFeHUxdHPpLaPkqpAw8RTS1aLsq28DMa0NxU56K7XjQ4onkf8oYCfLx6rG bWrPEqg0/38XtNWQU+jF/y5MvpyzO56oG8+xVn8fdisGEWM4oK45QJUEF4YQUlnJHEMT xpzQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=EAHGi4sB; arc=pass (i=1 spf=pass spfdomain=kylehuey.com dkim=pass dkdomain=kylehuey.com); spf=pass (google.com: domain of linux-kernel+bounces-30652-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30652-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 d11-20020a170903230b00b001d55aed1d8bsi2387164plh.213.2024.01.18.16.25.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 16:25:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30652-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=EAHGi4sB; arc=pass (i=1 spf=pass spfdomain=kylehuey.com dkim=pass dkdomain=kylehuey.com); spf=pass (google.com: domain of linux-kernel+bounces-30652-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30652-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 0502DB236CA for ; Fri, 19 Jan 2024 00:15:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7AA713D60; Fri, 19 Jan 2024 00:14:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kylehuey.com header.i=@kylehuey.com header.b="EAHGi4sB" Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 703A62F35 for ; Fri, 19 Jan 2024 00:14:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705623260; cv=none; b=gIxK9g7BHGs02Y9aSLOaMrL7Bs9HtF0gvYngsqACt/v7s/eSIfqfKuwEBTJvbXwh1cCYnVPI0KmIab9ctquppRrIbv24I0zd+4dY22qkoUQVa8F2bF8+oLrxVKVGOJGxwNZbFLTH3nbHmma3WFK9yLC6ZF7l70C4VpRK2MXD850= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705623260; c=relaxed/simple; bh=3622UZiYTMAps9fbTXA59oDeFjLFPk6fc41GnG+9ElA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZCcvT150BGDNrhYgk5MF2nIJV8MxLJqFfsnr4sFZpTApVJWCJDzVcNLyFSXpfINhePdNZB9qNyIezOM7B0pqeKY6H70kAaeaXyh6H/IZHd0otLGtLjx0voolTwRiU6JXG+T1G+aeRNslKB6sRAAxMl+5MQSkk+gs8cbNpHJK26E= 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=EAHGi4sB; arc=none smtp.client-ip=209.85.214.182 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-f182.google.com with SMTP id d9443c01a7336-1d70c150632so1737255ad.0 for ; Thu, 18 Jan 2024 16:14:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kylehuey.com; s=google; t=1705623259; x=1706228059; 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=/hEmM3vmtzdKl0VwvFdVPj5xDGeYkLg3iqjbEyKv8xM=; b=EAHGi4sBFq4E70+oyXfcJgh8JejvoQfg6y70LujDnGNW/nQOK9LEZJMPMZcZYCYo1F 2ncaGimK3K2P/N05NrVZXPV4ips16A8D5lj31KH8UHVEAplH0q4u4wgoO4zN2uZdDxU0 SokB2JECL0+E2SY+ppU5oUWAJU+YvZ/QnM2xulqWen/U98PUR/EiplgxGSafz0xBUWa2 XU3TKx0QjHgl14oL5yg7K56xQUt2WjL8eQVZWBGKuicvbXvqCGET6lHctm35vbiskLTX nQz+dpMWZx2icGdjq5nrRfeDxyj/hDqnrddGgrjvqxxPFEaqnid6C1+SgQDpIj8JGHdJ 3YmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705623259; x=1706228059; 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=/hEmM3vmtzdKl0VwvFdVPj5xDGeYkLg3iqjbEyKv8xM=; b=JsREBLJMkgvZIKTBcAQEycIMgIS1v9gvY8lKwuG/WDDZp4K5uqZtvd+9F0qs3Cn8zb a8QHgwC2HQkYS+IIpm3nFYT4jE2ukhXlG2u8qXR8a0iM73Xjk3DK8lcESdGDMwsBCykI ZX9XzvQ2TWUDMN9o3I4bZg5qKDJFEKINK5RztcINEA6uu1BcdnbFXI3a21I7gYXDNL5H e9vEszjHgb2Qcp4LAtQoCYgzF77/aklGb3iV9/LquSH7vgjDPKVREKpL+ruQI34I6dXa HUZNaUP+CFWgRoSJpDWWsxFmkWCegVPZQJ9V3z3sBjfW3H6efNLOyt9qB5Rj6gqH7s6A wNbg== X-Gm-Message-State: AOJu0YxJcthArW5lQ7+VRyDguRU3Zw4nwrYhCREuCi7aMec9sbGfR273 R16+n/Ku14uOMN5FLZ5KjEP5fcth9Fo2NwJ2dvA1tmBbS5Dy+cKOFW92IVdCGw== X-Received: by 2002:a17:903:26c4:b0:1d4:f29f:e13b with SMTP id jg4-20020a17090326c400b001d4f29fe13bmr1639156plb.40.1705623258923; Thu, 18 Jan 2024 16:14:18 -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 mj7-20020a1709032b8700b001d1d1ef8be6sm1921238plb.267.2024.01.18.16.14.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 16:14:18 -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 , Song Liu 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 v4 3/4] perf/bpf: Allow a bpf program to suppress all sample side effects Date: Thu, 18 Jan 2024 16:13:50 -0800 Message-Id: <20240119001352.9396-4-khuey@kylehuey.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240119001352.9396-1-khuey@kylehuey.com> References: <20240119001352.9396-1-khuey@kylehuey.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Acked-by: Song Liu --- 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 24a718e7eb98..a329bec42c4d 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -9574,6 +9574,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 @@ -9623,10 +9628,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