Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp169770lqn; Thu, 11 Apr 2024 18:47:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXSu9oYmB5qVLdr3B5Iq9JWZrdK7cgu3nE4gOPsr2kZI+7RCev6afmPV/uGXuEa0c0iRCQIhPaSv+CQAaZwC48UM2jWgyWvQCZVIk9B5g== X-Google-Smtp-Source: AGHT+IFUcCHEILanVDiXzPaRIQwowosCE5HiKmsML13dPerxndd+ksayvAL4nwlIWnfz48DF2TfJ X-Received: by 2002:a17:90a:7146:b0:2a5:be1a:6831 with SMTP id g6-20020a17090a714600b002a5be1a6831mr6035823pjs.19.1712886451671; Thu, 11 Apr 2024 18:47:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712886451; cv=pass; d=google.com; s=arc-20160816; b=r8q5ESQlZ5Rpq7K7gkUIYY4bYy48rVFfxEH7IL7WwU4+KCzFINPkSM/B9D16+rlVzc YokpPf1hN8rKDwNEru/I2gwbDAaXtcEOEZdlpILHUM5VcdpYU/7scuSPtM3LgG5hvWIH 7roCBfMgt/2EbjrxEeM/nwsE0bRFXYdUdpeOO8vF1wkIofR8ZS1jga/rVgJ0PuqZOawc 0sXVkpfFwIwM9nhwUeBKVJU4A5vHQJI82lMjT1wgZwddnoJ8PG82NDZlcDW14cbv3J69 3JBJ2a/ozaIGuSykiw9mwZyH11w4NrIs+ARG6jAH23kWxkfxq2W8nAvV4ATOjuEXixpx 3bfA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=osjArfM964ZMCs2J7V2IvF4mEAZbgUY8xcLmh6ewJ6U=; fh=DgdR50Jb8Md89ncNBLL6jOepqccBHpDLShuBQHF76w4=; b=oBD9Ti+cbnQmU903f9RqIyGJIGqfvhoiyNBAYFN/4Ylr2cC8PAmziEohVK/23I1447 9MXD/MkETHBuUQlzLCxQVa/RGQDKgp8OEOg3m7Wmlp95eJcCk4w1cpCa4vT/Sg8Pkn4U JEHUFOlcGAfgecKzs99vuIMDAQyyD1TAbSbGtemWy168cHG0K6dvzcF9AJng+wKyZQkj vQCdJidOFUGvLsJ97HvvVhPAf3/7kvXMTGsho+kTUHJr/inAOJSawMlvluOOwXLySNEd ntDsUr1X2o6P1EEZEZVoO/h3dITdOndbhWVupWiTGTxBM7HZyuNf2+ZETAVkYe6f8u65 VvsA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=OwHBLEZs; arc=pass (i=1 spf=pass spfdomain=kylehuey.com dkim=pass dkdomain=kylehuey.com); spf=pass (google.com: domain of linux-kernel+bounces-141777-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141777-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id nv4-20020a17090b1b4400b0029ff777c440si4575245pjb.7.2024.04.11.18.47.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 18:47:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141777-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kylehuey.com header.s=google header.b=OwHBLEZs; arc=pass (i=1 spf=pass spfdomain=kylehuey.com dkim=pass dkdomain=kylehuey.com); spf=pass (google.com: domain of linux-kernel+bounces-141777-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141777-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B23AE285291 for ; Fri, 12 Apr 2024 01:47:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18EB5525D; Fri, 12 Apr 2024 01:47:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kylehuey.com header.i=@kylehuey.com header.b="OwHBLEZs" Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 5673FDDAA for ; Fri, 12 Apr 2024 01:47:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712886445; cv=none; b=TZ5eN8XiyRO3sMWFf8ZgE5Z72wPL4Ni5q4xjz4xgZOhe2blh9bpN6rOSHZ1vHtBNVfJxacosFBY9rIbh85wJwKzYbfk1ybuKPIIomkTTK/Z67QUVc5RcQPBhLujJ7G5bxgS8UZTdDizm+XbxtQgdA1JyZgM6RNc41IlcWstxDnQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712886445; c=relaxed/simple; bh=g9UjYOg9Kyh9GD+IongtakgGXRYTohWmsMgeLoWdgio=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=TrXkE3+365+fUGYklefeB40ni9qkvdoN1HjpHnok3S8WS6q9lgE+l5ArKru5aZCLA5u5uQm4xXAec85mT7CtG0oGXeA4EStTbboEAO+EJJ3jy0lC1W9kpqOM6oi06KLPWs7SKtnTHdNPUbf3TIAK6q8VwbCBbF9hRCsDPSpok2g= 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=OwHBLEZs; arc=none smtp.client-ip=209.85.208.49 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-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-56e48d0a632so617866a12.2 for ; Thu, 11 Apr 2024 18:47:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kylehuey.com; s=google; t=1712886441; x=1713491241; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=osjArfM964ZMCs2J7V2IvF4mEAZbgUY8xcLmh6ewJ6U=; b=OwHBLEZsAmCbf+jjjyfuW/6e4iXuFZyG4li8l/B93Yq0slqchDM/vf+CnRCbDoWTWQ Vt+bom7BBWloadEtUpWjOgb8spu8yNcbeIbnF62ALUEv+IQ6EBzIikE0cPttEvrN4K7c Vg29PDyaj3j4fDL55HXh2B6zDnr0wbQbd41e5iSloLO8t+Q0LUz5sCU8hagICFGTHeLb rfKVxQufPxtA3NYg8WElB39Cv+H3dOfxXiQGZpNEvWPM2quf20JihTiEhUiVQaVKBwNl cDKzA+i5NCwInXtoF6LYc+zBdhMZOXSwDW2a3q6PTuaeXLImiDAqk1IXe5CnTRYVPigR 5hUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712886441; x=1713491241; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=osjArfM964ZMCs2J7V2IvF4mEAZbgUY8xcLmh6ewJ6U=; b=qW3smtnc0Gx9loFrrAkJ2QJRR8TB/sAM5u3IJi/3u6RkU3tFPlL48cOQ7cGtB/g5lZ 1PdxHnJLniegAsDgJ9/j88PTrj8rHzTao8dy09UTUgHLTZQcQc2bWwx3hLHi7OA0bKgf N4ngZZ5xRuQq9gZXi7schN9DOzbJS+UDDGE4dR8GzZioVoTtL7YBKTByvfG1rhbuKsYE wNSf2ALWegNlt4fRufFBXYZCAhzV6FsfE7xRxrP+Fgb4TvlVMB2DxagAUG+92HhmhPnX ykxULaMtQ6YxVTmRCjZxYfpdMH2w/mj6wP3HPvl01fYa+Ttgz5OtdVths1kfQyOpyWsZ 6N5A== X-Gm-Message-State: AOJu0YykhAsjL1eafDC79KHXFSjElcoRRWf5PXNst0JgWJvIcU+zU3rG axtCQCpNcoDVwfxcjEgkjdURrWrk3ILTFfjvqnKOnPap41D0UXa7VTfIaVhRcndvMafcRVZXbGU 2oq2gm0eyV1CJpAPYT1D1VTzLhaFwKFBJTjXdsFtgAhTcYBQcog== X-Received: by 2002:a50:ab5a:0:b0:56e:3172:20dd with SMTP id t26-20020a50ab5a000000b0056e317220ddmr1096208edc.27.1712886441445; Thu, 11 Apr 2024 18:47:21 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240214173950.18570-1-khuey@kylehuey.com> <20240214173950.18570-2-khuey@kylehuey.com> In-Reply-To: From: Kyle Huey Date: Thu, 11 Apr 2024 21:47:09 -0400 Message-ID: Subject: Re: [RESEND PATCH v5 1/4] perf/bpf: Call bpf handler directly, not through overflow machinery To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, Andrii Nakryiko , Jiri Olsa , Namhyung Kim , Marco Elver , Yonghong Song , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , "Robert O'Callahan" , Song Liu , Mark Rutland , Alexander Shishkin , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Apr 11, 2024 at 8:11=E2=80=AFAM Kyle Huey wrote: > > On Wed, Apr 10, 2024 at 12:32=E2=80=AFAM Ingo Molnar w= rote: > > > > > > * Kyle Huey wrote: > > > > > To ultimately allow bpf programs attached to perf events to completel= y > > > suppress all of the effects of a perf event overflow (rather than jus= t the > > > sample output, as they do today), call bpf_overflow_handler() from > > > __perf_event_overflow() directly rather than modifying struct perf_ev= ent's > > > overflow_handler. Return the bpf program's return value from > > > bpf_overflow_handler() so that __perf_event_overflow() knows how to > > > proceed. Remove the now unnecessary orig_overflow_handler from struct > > > perf_event. > > > > > > This patch is solely a refactoring and results in no behavior change. > > > > > > Signed-off-by: Kyle Huey > > > Suggested-by: Namhyung Kim > > > Acked-by: Song Liu > > > Acked-by: Jiri Olsa > > > --- > > > include/linux/perf_event.h | 6 +----- > > > kernel/events/core.c | 28 +++++++++++++++------------- > > > 2 files changed, 16 insertions(+), 18 deletions(-) > > > > > > diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h > > > index d2a15c0c6f8a..c7f54fd74d89 100644 > > > --- a/include/linux/perf_event.h > > > +++ b/include/linux/perf_event.h > > > @@ -810,7 +810,6 @@ struct perf_event { > > > perf_overflow_handler_t overflow_handler; > > > void *overflow_handler_context; > > > #ifdef CONFIG_BPF_SYSCALL > > > - perf_overflow_handler_t orig_overflow_handler; > > > struct bpf_prog *prog; > > > u64 bpf_cookie; > > > #endif > > > > Could we reduce the #ifdeffery please? > > Not easily. > > > On distros CONFIG_BPF_SYSCALL is almost always enabled, so it's not lik= e > > this truly saves anything on real systems. > > > > I'd suggest making the perf_event::prog and perf_event::bpf_cookie fiel= ds > > unconditional. > > That's not sufficient. See below. > > > > +#ifdef CONFIG_BPF_SYSCALL > > > +static int bpf_overflow_handler(struct perf_event *event, > > > + struct perf_sample_data *data, > > > + struct pt_regs *regs); > > > +#endif > > > > If the function definitions are misordered then first do a patch that m= oves > > the function earlier in the file, instead of slapping a random prototyp= e > > into a random place. > > Ok. > > > > - READ_ONCE(event->overflow_handler)(event, data, regs); > > > +#ifdef CONFIG_BPF_SYSCALL > > > + if (!(event->prog && !bpf_overflow_handler(event, data, regs))) > > > +#endif > > > + READ_ONCE(event->overflow_handler)(event, data, regs); > > > > This #ifdef would go away too - on !CONFIG_BPF_SYSCALL event->prog shou= ld > > always be NULL. > > bpf_overflow_handler() is also #ifdef CONFIG_BPF_SYSCALL. It uses > bpf_prog_active, so that would need to be moved out of the ifdef, > which would require moving the DEFINE_PER_CPU out of bpf/syscall.c ... > or I'd have to add a !CONFIG_BPF_SYSCALL definition of > bpf_overflow_handler() that only returns 1 and never actually gets > called because the condition short-circuits on event->prog. Neither > seems like it makes my patch or the code simpler, especially since > this weird ifdef-that-applies-only-to-the-condition goes away in Part > 3 where I actually change the behavior. After fiddling with this I think the stub definition of bpf_overflow_handler() is fine. The other CONFIG_BPF_SYSCALL functions in this file already have similar stubs. I'll send a new patch set. - Kyle > It feels like the root of your objection is that CONFIG_BPF_SYSCALL > exists at all. I could remove it in a separate patch if there's > consensus about that. > > > > > > Please keep the #ifdeffery reduction and function-moving patches separa= te > > from these other changes. > > > > Thanks, > > > > Ingo > > - Kyle