From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04390C77B73 for ; Wed, 19 Apr 2023 11:47:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232976AbjDSLrS (ORCPT ); Wed, 19 Apr 2023 07:47:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231215AbjDSLrR (ORCPT ); Wed, 19 Apr 2023 07:47:17 -0400 Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [IPv6:2607:f8b0:4864:20::f2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C7B54C22; Wed, 19 Apr 2023 04:47:15 -0700 (PDT) Received: by mail-qv1-xf2a.google.com with SMTP id dd8so19810868qvb.13; Wed, 19 Apr 2023 04:47:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681904834; x=1684496834; 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=nyDadJE1NbgjC8wC5oHDlohplbMrXbFJOr8OYm4fr0g=; b=RzsTjKIWM6yKFuZODaI9MT7527b8MzXaBq+WUh30FXCvOUVRowFcFr90uQ+y0SB5Ha Nbs44J8KP09W+ZINagNZPy7o7Wp+Bybwo6jXkNE+8esZ6aq01Lt2/wNs1PNPptjooC0F 6LNfgb+yv9sSw3vdkTTHRBVvhOt0+PRPRrPSA5C5Q5e4vGu432K3UgFP2PFFrfakG2pi d/tSEjGL/Bq33rdcWVK9vOo0wD7B8JCfXSdijc/6guL11ssJFTWUxMd648Ee3ejvixQS Xh2TzVTxSdZZQn78hRPTmuxx3GZEhU38U6bO0liS+d+BMX1hd/y2l4UwN8+cvtqS+lZY zD5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681904834; x=1684496834; 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=nyDadJE1NbgjC8wC5oHDlohplbMrXbFJOr8OYm4fr0g=; b=Dpo/tFKDVCx2y2Aj2NTJhMs+QQm4Xf4gJEh0rNdz9UYErL0J/XuMIAepKhyDPcRVT3 fbajH0uAFsLn2W6Vk/M2bGrayUNZS59nVvpwTzjUbHW31mI5/6SXXBvcQWJdO93KSjp5 HqfPP5pSeG5vPotieWzFZuym9AXZ0PdMFWXsGiXCKrI5aSJk9AWlOGzuqM38h4Dlhwxn bL/biawgdpDIGPOgiYAoTH7IZjEXiaaLM2HDC8df1DsuTAQFrb2LoqJpaAjRqkIo+bcO hc5uCvYXymZd6CJT/P33J92m1f9jbtn6UW6bCKYoh87Y45mmLBYDkqc3hF7/ldWUpJXz D+vA== X-Gm-Message-State: AAQBX9dO+JQ7j0FAn9LNbny1jwquAEWHDj1A+eLrjLppR2RqChC7NZqf Deaeiij7mcDEdk9GryhQy+UZYxGNWFv0hXM5q9o= X-Google-Smtp-Source: AKy350alDLnATEjliOOTmkIQ3+3cIHSnEkNtmVKehwKlEUoOwVP1HXCWzUwHYwRbame9IrQOAbt6wQ543n2m2VHD8z0= X-Received: by 2002:a05:6214:2348:b0:5f1:6892:7437 with SMTP id hu8-20020a056214234800b005f168927437mr4619986qvb.26.1681904834432; Wed, 19 Apr 2023 04:47:14 -0700 (PDT) MIME-Version: 1.0 References: <20230417154737.12740-1-laoar.shao@gmail.com> <20230417154737.12740-6-laoar.shao@gmail.com> <20230417201457.c43xfcukjzm4u6vx@dhcp-172-26-102-232.dhcp.thefacebook.com> In-Reply-To: From: Yafang Shao Date: Wed, 19 Apr 2023 19:46:38 +0800 Message-ID: Subject: Re: [PATCH bpf-next 5/6] bpf: Improve tracing recursion prevention mechanism To: Alexei Starovoitov Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Steven Rostedt , Masami Hiramatsu , bpf , linux-trace-kernel@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org On Tue, Apr 18, 2023 at 11:38=E2=80=AFPM Alexei Starovoitov wrote: > > On Mon, Apr 17, 2023 at 6:49=E2=80=AFPM Yafang Shao wrote: > > > > On Tue, Apr 18, 2023 at 4:15=E2=80=AFAM Alexei Starovoitov > > wrote: > > > > > > On Mon, Apr 17, 2023 at 03:47:36PM +0000, Yafang Shao wrote: > > > > diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c > > > > index f61d513..3df39a5 100644 > > > > --- a/kernel/bpf/trampoline.c > > > > +++ b/kernel/bpf/trampoline.c > > > > @@ -842,15 +842,21 @@ static __always_inline u64 notrace bpf_prog_s= tart_time(void) > > > > static u64 notrace __bpf_prog_enter_recur(struct bpf_prog *prog, s= truct bpf_tramp_run_ctx *run_ctx) > > > > __acquires(RCU) > > > > { > > > > - rcu_read_lock(); > > > > - migrate_disable(); > > > > - > > > > - run_ctx->saved_run_ctx =3D bpf_set_run_ctx(&run_ctx->run_ctx)= ; > > > > + int bit; > > > > > > > > - if (unlikely(this_cpu_inc_return(*(prog->active)) !=3D 1)) { > > > > + rcu_read_lock(); > > > > + bit =3D test_recursion_try_acquire(_THIS_IP_, _RET_IP_); > > > > > > and bpf will prevent ftrace to run and vice versa. > > > Not a good idea. > > > > > > One bpf prog will prevent different bpf prog to run since they share = current task. > > > Not a good idea either. > > > > That shouldn't happen. test_recursion_try_acquire() uses a > > per-task_struct value. One single task_struct can't run in parallel, > > right? > > Note that the bpf program running in softirq or irq context won't be > > prevented by it. > > IIUC, the bpf program should run in serial in one single task, right? > > That said, one bpf program can only run after another bpf program > > finished in the same task? > > bpf progs can nest in the same task. Do you mean the tail_call ? --=20 Regards Yafang