Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1886850rwd; Sun, 21 May 2023 08:13:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5VYOPc1XKknqLkkA7RF7Nar+ycYAf6RZivnlu4jivntM3omqpKBC6UpruvfOuLnv5k33n1 X-Received: by 2002:a17:902:e5ce:b0:1ad:e3a8:3bf with SMTP id u14-20020a170902e5ce00b001ade3a803bfmr9973160plf.21.1684682038276; Sun, 21 May 2023 08:13:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684682038; cv=none; d=google.com; s=arc-20160816; b=CS6Fk2c/mu5nleqMq7W8ezRjtygKqASa4W19r3WTCQOvCdejokx8+Wq1WeqKcXrVeA oOmO6CULuupCANnphopGhJPm0xnncyLbsurrhqRJpBbsaVkdU8blNj4GOxfFL/83WAWw b04o4WBpMX3FTtSXG1H0lQAB1q4Haf7CpIb4E7RcJX5FrRkj4jveNWOxONKXsfGOg7Th E2R8a6lmGAegVI9ScRvhhWwPOlRzs7B4AqZPmoiOfX1advjqhJ9bp8VuWRdHhZ/RVSda SuKSNYPVdmJWT+xoTLeJVgb5QW2/HOTdD86PVyo8Ug823z01JqOFuZcK1wqbXwZovvRZ AL3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=g7nc8IQP1+x6u9N7+EYfITX13eAIkcVj3K/FpgMBq4Y=; b=F1/6SC+7oBuuLQGbYNVzLQI6CSrw5ZyzYF5G2kTu8C8MMSI/ptuBO5wJA/PkU/lOpB gAt7h26i8h/RBrpPzFH8r1DTubdpUIYlZ5VCs1x+7XPjeil2UWxFCXUk1ymqFFvYahT7 oEu/02AnmOa6zzHBAOiNsKA/2a45YnXcGxR6wbgy2Q/cPuuNcZ8D7r4iRFW6WPdct92B c8Yy5MA5REPc+35QFskRULQMoS8jyhsqC9d3AGsemiK8P/7/GE+xm1taoQ4Ivh6wknjo VMOGBbMVOib9Ch9ORJpJ9+PFM8GBT371c8bca3JcXWzsqjT4fYooP6xwzcmiu8gqzmrq FosQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=hMI+YQvg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h1-20020a170902f54100b001aaccc51d45si3467944plf.398.2023.05.21.08.13.40; Sun, 21 May 2023 08:13:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=hMI+YQvg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229627AbjEUOUq (ORCPT + 99 others); Sun, 21 May 2023 10:20:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229940AbjEUOUj (ORCPT ); Sun, 21 May 2023 10:20:39 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16F49BE; Sun, 21 May 2023 07:19:48 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-510d8ead2f1so7163501a12.3; Sun, 21 May 2023 07:19:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684678786; x=1687270786; 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=g7nc8IQP1+x6u9N7+EYfITX13eAIkcVj3K/FpgMBq4Y=; b=hMI+YQvgIwZ0nFTrph18YPJAPJ/xqRvgbwDk0QNL7DpOR3z2xwQQZ09Y5ZB6aKwQ1N vAgB18wD4Uz/K3EB1WkMeoAAQj9DLgB56nJjPbLccvgfFoiQI74WddeHk+E7C8SRYSYL HrpQLEY5WuXmBoxwAPjftuOppi/LU8kC/KLqRKQJB6t4mwXSTDzGCa2Z9HHBVeihFInM +j+n2WojQy5OP7ATXwgbIfOAdr8sCKWQNah5J28W/WJwcBBQ+MvXxi6K+vUpN5+DCuKe CWg64ghMVjzIgCBe5FnaHQziqCCEr23LlqmF/i8RfrDYQrd5B/cL7jrk1CAmHsXdoFvc 681A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684678786; x=1687270786; 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=g7nc8IQP1+x6u9N7+EYfITX13eAIkcVj3K/FpgMBq4Y=; b=SFn5N4Zxm4F1FlfFFlNPK7n2xD4j56CUwEgjU5Yedq16qYyXoOyMqrpOdCQ6usMGcX q3SaCqkRbADGozd/zb34GjJnx0lU8mkr9v4GnFOOmEDh2gmFXlrcL4v1l35ZdCrlRViv rjRfXtrFtGD/kxnUgzXV0HXNl2+1o2S76TA1VwYwzcF09Q+br0mxmTk6t2R2vHfgBlS4 5FTuW+8rXYyLJ93+r3vThzycC9sQ4xOvoiffxg5icHWUuSvgKk2WSdB4UmkxeMJ31OaZ PKs696XuY4fwCtKeJVZ6nxS9lb6rE2wIAYBGOCZ/B4i4vM2s6WW4rexSc/qYwRijVnLe EsXg== X-Gm-Message-State: AC+VfDy+NxOJGF7mQ9HyZWIJOYKFT1fEaw0gOgfdEGvTed7FmLS67RxW rBQm2GQhCD1Y9GTDDWVHhxB18Pwy3w71aW37v1k= X-Received: by 2002:a05:6402:1217:b0:50b:faa1:e1d5 with SMTP id c23-20020a056402121700b0050bfaa1e1d5mr5627068edw.39.1684678786185; Sun, 21 May 2023 07:19:46 -0700 (PDT) MIME-Version: 1.0 References: <20220515203653.4039075-1-jolsa@kernel.org> <20230520094722.5393-1-zegao@tencent.com> <20230521190907.e4104a653583dfac785e379a@kernel.org> In-Reply-To: <20230521190907.e4104a653583dfac785e379a@kernel.org> From: Ze Gao Date: Sun, 21 May 2023 22:19:34 +0800 Message-ID: Subject: Re: To: Masami Hiramatsu Cc: Jiri Olsa , Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Hao Luo , John Fastabend , KP Singh , Martin KaFai Lau , Song Liu , Stanislav Fomichev , Steven Rostedt , Yonghong Song , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, kafai@fb.com, kpsingh@chromium.org, netdev@vger.kernel.org, paulmck@kernel.org, songliubraving@fb.com, Ze Gao Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 21, 2023 at 6:09=E2=80=AFPM Masami Hiramatsu wrote: > > On Sun, 21 May 2023 10:08:46 +0200 > Jiri Olsa wrote: > > > On Sat, May 20, 2023 at 05:47:24PM +0800, Ze Gao wrote: > > > > > > Hi Jiri, > > > > > > Would you like to consider to add rcu_is_watching check in > > > to solve this from the viewpoint of kprobe_multi_link_prog_run > > > > I think this was discussed in here: > > https://lore.kernel.org/bpf/20230321020103.13494-1-laoar.shao@gmail.c= om/ > > > > and was considered a bug, there's fix mentioned later in the thread > > > > there's also this recent patchset: > > https://lore.kernel.org/bpf/20230517034510.15639-3-zegao@tencent.com/ > > > > that solves related problems > > I think this rcu_is_watching() is a bit different issue. This rcu_is_watc= hing() > check is required if the kprobe_multi_link_prog_run() uses any RCU API. > E.g. rethook_try_get() is also checks rcu_is_watching() because it uses > call_rcu(). Yes, that's my point! Regards, Ze > > > > > > itself? And accounting of missed runs can be added as well > > > to imporve observability. > > > > right, we count fprobe->nmissed but it's not exposed, we should allow > > to get 'missed' stats from both fprobe and kprobe_multi later, which > > is missing now, will check > > > > thanks, > > jirka > > > > > > > > Regards, > > > Ze > > > > > > > > > ----------------- > > > From 29fd3cd713e65461325c2703cf5246a6fae5d4fe Mon Sep 17 00:00:00 200= 1 > > > From: Ze Gao > > > Date: Sat, 20 May 2023 17:32:05 +0800 > > > Subject: [PATCH] bpf: kprobe_multi runs bpf progs only when rcu_is_wa= tching > > > > > > From the perspective of kprobe_multi_link_prog_run, any traceable > > > functions can be attached while bpf progs need specical care and > > > ought to be under rcu protection. To solve the likely rcu lockdep > > > warns once for good, when (future) functions in idle path were > > > attached accidentally, we better paying some cost to check at least > > > in kernel-side, and return when rcu is not watching, which helps > > > to avoid any unpredictable results. > > > > > > Signed-off-by: Ze Gao > > > --- > > > kernel/trace/bpf_trace.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c > > > index 9a050e36dc6c..3e6ea7274765 100644 > > > --- a/kernel/trace/bpf_trace.c > > > +++ b/kernel/trace/bpf_trace.c > > > @@ -2622,7 +2622,7 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_mu= lti_link *link, > > > struct bpf_run_ctx *old_run_ctx; > > > int err; > > > > > > - if (unlikely(__this_cpu_inc_return(bpf_prog_active) !=3D 1)) { > > > + if (unlikely(__this_cpu_inc_return(bpf_prog_active) !=3D 1 || !rc= u_is_watching())) { > > > err =3D 0; > > > goto out; > > > } > > > -- > > > 2.40.1 > > > > > > -- > Masami Hiramatsu (Google)