From patchwork Wed Feb 14 17:39:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Huey X-Patchwork-Id: 201075 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1384021dyb; Wed, 14 Feb 2024 09:42:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUerlHNrRK7i8veLOycHJAEbN7CnDT/yydl/MRxZFMbdqLcIkdMnYCAVN+e6Cr8DdVSBc8P5iCdZx7ZgdI3xcEkX4JweA== X-Google-Smtp-Source: AGHT+IHIMb24F9yVxnaN0pNBq2mKBQE13VShsdpwT4dpms55kZPSjYpnaLVOoIYH/HxY1kwQWByg X-Received: by 2002:ac8:5cd4:0:b0:42c:5fce:e40d with SMTP id s20-20020ac85cd4000000b0042c5fcee40dmr3524386qta.49.1707932575768; Wed, 14 Feb 2024 09:42:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707932575; cv=pass; d=google.com; s=arc-20160816; b=XjWZj0BHLGIrnj6BPntysTVJH0W5tnNnmdYQnnUzcwGmE8hGqVh/2Xot3fW0MHOq9M dOprW4mm6a9OwecgbNKFaT3mSiTK6q921by3oEK9E0hjf7z0nHjsSf73hfv/ZTbZsW/0 lwL8zo2ChremszFgxf3duZsfH4vqRnEZ56sRwJycxHGJg6ZVKHqu2dO7EJu1SBKAaSB3 3IHhCzJMvwFBgD+nj3QG8NwfSQJasPgHNjzXdT3FZ3eFb4aXyLJbZZerJuLfApxNBGmj IrS+2pP2PWjCWmwnmDhm+nkUp7PzN3mWK6UTtKZ0I8p3D0RCodD6lUX3XN7zvR21AyBk NPaQ== 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=HG1Z9345f9l/NkzG8Y/mlPsfRpv6azyFKs0IWGP/jfI=; fh=UdResm5WKnA2mfpSuDeviQZ0r+iN49hM7HDfdXJ7dM4=; b=BjLvEhioCG24shBC7y1BXL84QoN1fsXHMGzfQu88QitayMP5I3pgFDyrIjQRQ2dxpf KUaxw90Luk/XhfxvDsW5Ua3XuBrNLazXgIITFvxQEu1DvOuR5fg/21oNY90dvCJlGBpj b+CHwDI3DZY/uD8DVRAPv09n+AX2sxg/QvZgHc6aTYWmFX8GmHslo+FJXnGEfHeq/v72 ugTIAB6NxH1gB4SK+n5O2C8NYv0vUpuHRJeTkVNmv0C6PKz/p/JU6nBcfkkiDBMKqpIz DoK8/r3PViOPZD/8U3torwXvRXcPwczmBd3vvXOENQsKH200aK4jZ2y3bWJp4CgVxNwk YDyw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=OPM2+jI5; arc=pass (i=1 spf=pass spfdomain=kylehuey.com dkim=pass dkdomain=kylehuey.com); spf=pass (google.com: domain of linux-kernel+bounces-65699-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65699-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCUhU4hNRBYMui/uqwg/Q0636/ePRu1vqHk1Ov1bxzkGdlEtnePcAFh7gPZ5yQItA/DYQo5R4g00x5pgst2jjRbrGhU3gQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id o14-20020ac85a4e000000b0042da980e578si5622711qta.88.2024.02.14.09.42.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 09:42:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65699-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=OPM2+jI5; arc=pass (i=1 spf=pass spfdomain=kylehuey.com dkim=pass dkdomain=kylehuey.com); spf=pass (google.com: domain of linux-kernel+bounces-65699-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65699-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 549EA1C29209 for ; Wed, 14 Feb 2024 17:42:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED4AF86626; Wed, 14 Feb 2024 17:40:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kylehuey.com header.i=@kylehuey.com header.b="OPM2+jI5" Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 A339185651 for ; Wed, 14 Feb 2024 17:40:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707932449; cv=none; b=uSfiFVxdV8OgnIB+5NPxFaJhGi/qf0TjFz6SBqhhIMIQ71ivNNvNZRAfH3Lyf+AruA5dkP6b9e6oE1m/Wk+yBO4zuWxnS+oP54K5vokpquuBQiu1ga39kihZ9l9AFO4EHHEGlIXyOSL2TlLW0oa/IsSKbzoAPFCe/ySUMUyGdNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707932449; c=relaxed/simple; bh=PX2QIRe/Ic85BaGVX4Y1MwT3KJ9EiLQ96IEJSBjyAmE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MnrFyiJ3MdIt7mACB0Q+2eRvMHab4QohJgby1NlEGCz++4PzZHqGFeAxThiJuKJgDLTfdyYUN58Yut6JxAN/VesI/WaYuyHIAirvGsXy10Rpjl2kNgdJZaBe08SNX83tiQ8ddPa05V05C1il61pJ7zT9Xs3yFk+SyDk33w7sX9A= 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=OPM2+jI5; arc=none smtp.client-ip=209.85.210.174 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-f174.google.com with SMTP id d2e1a72fcca58-6e0a37751cbso33305b3a.2 for ; Wed, 14 Feb 2024 09:40:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kylehuey.com; s=google; t=1707932447; x=1708537247; 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=HG1Z9345f9l/NkzG8Y/mlPsfRpv6azyFKs0IWGP/jfI=; b=OPM2+jI5a1lsGQN7mpklD9h+LInX4e/9Kti3Ophc6GHXLnrZIOULn5dEbwoQ+cnVSM /LsWpst9DYAO7/0u9Uz0o9wnwtFGILz9q0YRJvKVNfmG0Jl5aqKvirnRNa5OUWa8B1GP SR5yGTs9QKvKp5Js+L7mzTpFNSZ3eJxEAYSFdvIr+twcCP+Le1AT6LQx+UWbpQMZQAN8 SVPyITIlvaUcFzbyLV9AMY7dzZHIQCDVthQwfXelaRmMkwC95H+OG+sUTSbWpfiCu+ns CaITZlwXfkv6RMcdQ7UAgaKHQFCEHRhTs+xBtgga0XFo4XdmmTMdXRsIzUFjM1LfEOYj m/+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707932447; x=1708537247; 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=HG1Z9345f9l/NkzG8Y/mlPsfRpv6azyFKs0IWGP/jfI=; b=wCxja54g+TN//nsiIvjiKDIQmcFKovBDAN2WPmmw5mvVwLAK0FVdpNx4CNtfGmTCQ5 3gu4avKNhVC27K0GFsaik6VFMU5Vd/zLLzQLTo7zfwa0COWV8fODWGJW1pcgh40+TYXL n5iZ9N+uF8+4OSr+3QjApgzS3XQW1AzLY7Nn68mnj9V8HTE7xGoW7ClW+xk7RoN6RlMK KaIc2mh+Y0bovPV+FM7yZhRcDwo8GjhxRTw5vC0K6CuRnvSdozL8yGv1Whsy8WmpSaU4 9Boin65d58UwCqvfu1iDfF7FA65W6N/ttaFZ2bYzWdW9m79hTHlD6OgmGThia3lujWoI Ag5A== X-Forwarded-Encrypted: i=1; AJvYcCXuUk8gr0J9laWZLodOFxboDorEWXjSRXdJZloUXtfgfNn4eHy/IkGRlpk6c4GcwuuJJ7OxCaYxqKzPbPArOCyOSlVlR7ar+6bduqGY X-Gm-Message-State: AOJu0YyzzpPDdztnBf1WmnygLAIO9fOr+qSPZvJIY/FhHm/npsx9O63r 4ymYrZxSIKRsLrlhlMPyFc30naKNVXVORZFr7eDk2pithRDnh8el1YWnpY408w== X-Received: by 2002:a05:6a20:5a05:b0:19e:34ea:36ab with SMTP id jz5-20020a056a205a0500b0019e34ea36abmr2596022pzb.16.1707932446967; Wed, 14 Feb 2024 09:40:46 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXCVm9x2c70Y3aUaKd5dJ9CyzyMqThObPmrRdxYZr+tKeNMU1F1t+87B11jHOCr3NjPSIjrc8unAoIFwG9j0ZWYfOUjq8Y//B8Ho60+jtM9/uIvVF7wEczEsKXfEZdbu4k/Y9gDo56B4zs5WTz7e8HU/vqmCrH6Z6MWpoEhr0laUxGnMeEoblbsvak/hKw7m0PitxNEgtda/ZfHIx0dItrJ+KMd2YuYqP6+nIRaMrV0tkWBYd60QoHOrxAP1b91xYjlvSOiS+hrHyKD+87Vj1ixhRsn3cZeOHk/i5mZamezp2z0CE4R0OzfEWoHj2rf9Ebdhn1/cnVD7Y+EXw1jOIXyYLZaQiQ2HfJEXyp/cgEvJd9nuISq0xMvVvHjqsdlKV2SDcOmjp1mCfBjDHkRZLt2pQEMu/cQUcGGi9PpWFjBJ0N3u1KcM3kfAj3rOcfBr8ouBYBh3YG/6Dn+nmnZP3fQNVfkKmR6Ilx/c0SR4B7kSy7dcKwVlQwpXqUThPCp6ernnDjQJbXCLoZAo4D5a47aC5fgS7he5A8wX+LihWY1lh8= 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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 09:40:46 -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 , Song Liu , Mark Rutland , Alexander Shishkin , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, bpf@vger.kernel.org Subject: [RESEND PATCH v5 3/4] perf/bpf: Allow a bpf program to suppress all sample side effects Date: Wed, 14 Feb 2024 09:39:34 -0800 Message-Id: <20240214173950.18570-4-khuey@kylehuey.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240214173950.18570-1-khuey@kylehuey.com> References: <20240214173950.18570-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: 1790897108815805088 X-GMAIL-MSGID: 1790897108815805088 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: Jiri Olsa 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;