From patchwork Fri Jan 19 00:13:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Huey X-Patchwork-Id: 189368 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp707040dyb; Thu, 18 Jan 2024 16:25:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IERQuL1aJsWCOLhpZh1OqArAU7OgHD5AQEuD6QbRF3J0qnpIjuJtqDTLgnqa+Fm+4TcpEUd X-Received: by 2002:a05:6830:3b0c:b0:6dd:ddd8:51e5 with SMTP id dk12-20020a0568303b0c00b006ddddd851e5mr1633818otb.43.1705623908750; Thu, 18 Jan 2024 16:25:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705623908; cv=pass; d=google.com; s=arc-20160816; b=1D4PXYmaeLaLauCVMYQYIDXZStxWbvOMvfst1fSJfjma5GtINb/TEd7Pskq5WxfZF7 BrCTsa8OrJeV/Gux5MdZcRWuTtmWxVECgbRmja4nnLihfHwwEyGyO9D+hzCEdQuFISZe OuAUOMdvPKbK7jEJo4bF96F9Ck9Kt6Yf78Km24paxahebyL5DjlfqyRLspgDGVwOhklD C1GQXdREeqrRX9ynWZ1XPqkPakUjXtwWYiVRh+x5JCK85Z67EPuXeTCJarNQYwASu4le qf+tatjOYE6L209btIzgAa36kkQIdUqfhxs6hpAcPp3hoJrqilnag75nm/lkqwtMt4J2 EVWg== 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30652-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u2-20020a05620a0c4200b0078366089f14si8033237qki.168.2024.01.18.16.25.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 16:25:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30652-ouuuleilei=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=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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30652-ouuuleilei=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 24BDF1C229E7 for ; Fri, 19 Jan 2024 00:15:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 569824A08; Fri, 19 Jan 2024 00:14:23 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788476295819022698 X-GMAIL-MSGID: 1788476295819022698 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 Acked-by: Namhyung Kim --- 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;