Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp593848rwr; Thu, 27 Apr 2023 05:54:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7oQ3sNsyfcCBs0CUsqm9JH8BERa+m6oBtjnNVDMAYJSHV8DWjLyJ6P7WucWQiTi8llqBVe X-Received: by 2002:a17:90a:1d3:b0:246:fa2b:91be with SMTP id 19-20020a17090a01d300b00246fa2b91bemr1543343pjd.3.1682600098696; Thu, 27 Apr 2023 05:54:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682600098; cv=none; d=google.com; s=arc-20160816; b=g24d1LOaauXZw7XmLz1ctVI8EjBgWG3krfyB3nRI/Ti0ZO5zcDoeXuBH7uaEsQUvbJ S+XUNnwFvLFRfHr1bZYcxzz0QoJD572zdG4ltrUe+djCdWzKcVbNyOu9kdVeb3USIfTy wQNqBVBl97WB8RxkzK+wXtstcm7uTnMveKKOJ7Prt4XKUi+Cs9McF6aMcpZkWBl0Hm5q NE+xsJTOpwyM9vbjqusy228lMFBVxA1srQ5z+dQ9fDUQ/gkGwkZe2Z0MsQpCTqHFu/I9 8/s656kG/r24aTxPUY9bwUqFYj+js8kfwkrT4CarhxYt3IlXss01QjMGYZEbUSQSkh7T 378w== 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=uamYaAPiGbEuD/CCuWzrQEEft21M2zokyUeiq+isD7s=; b=jR6Y1sVGIXnUZ5DR/2jUY6HM7GfOXqUqDUUfHNWZQeWCzMUd+9bhdlcOt+QK6ApiMZ qlPIlJVxGJUOSE4FdIyWZp+y/pJ151MnRW6y8bEvUV6W84SgZQJwOOFVh3iTPjBYZ3zZ G1q1k7TF0Nbf6uNyxqDUBVTHnl57+YzwXdShjMF9z9fBN20TlrF1BPauA5C9e/n61rav Xh709aqxfh9K6GI9d/VbxvnmLPagIRZzdkNFpGVomNvx+H2TfuXvpxC/IQZKpWQ8+6yx +40g/44ExSfqHL1EcBxCvZeRyzG3sFC0lQXiGjhU5zGFtOeJvmRzBjMtLlWot+lLNMJZ yjrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=BTlbPFOc; 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 r23-20020a63e517000000b004fbd7827010si18604335pgh.263.2023.04.27.05.54.45; Thu, 27 Apr 2023 05:54: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=BTlbPFOc; 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 S243418AbjD0MgY (ORCPT + 99 others); Thu, 27 Apr 2023 08:36:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229636AbjD0MgW (ORCPT ); Thu, 27 Apr 2023 08:36:22 -0400 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D989B3AAA; Thu, 27 Apr 2023 05:36:21 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id af79cd13be357-74de7635180so809485185a.3; Thu, 27 Apr 2023 05:36:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682598981; x=1685190981; 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=uamYaAPiGbEuD/CCuWzrQEEft21M2zokyUeiq+isD7s=; b=BTlbPFOcy9ohq/rnIcEzr3ktsmGoIkLS5TIak2p0WjRjIS7tVD1nIqK8H28Io6XqVb 9aLFzRITd38OHn++1iixe4l+zH9eVbZwDAfhDkBPWusPk/VSHTt3diuofZ1nXTms4rWa JJDnLuoNxKzEPHBsTTAesrqHvIflWeuCV+ypelKfuvD4O+TPSpqMCXAzeoegikWjB/Xn oB//Q9Oj0JVMjfEMXdE+932BDwJurikQ3prEJSDaerswpy8Wg2pAA2X1sKEPI4tHB6Go ZHMRvXK14JUWYrPAmxUScss3xazUqYC7wB2ZNdtCocebfo9MWUezS6nhOC52uXfScmbO Xkvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682598981; x=1685190981; 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=uamYaAPiGbEuD/CCuWzrQEEft21M2zokyUeiq+isD7s=; b=kbVIus5Zlt1nLD/D602IavKg+fKqXa8euUDk5wNeoKeKslEGCRlnf/+FguDfLS7nNr J6OS79tYntZJI5mU8S0NEMJtcagDbH23QkSrOQTJWkoaC/7KZbmAFJ9+aJ/EqObjj/Y3 VIpIh7k+9564H7g/f607IQDM+muou5KLm35tSuqVBKwA3ZWSyDUCZf6NWXsF9ztJEqZN XR+OHdg9S99O2R8wQuWrQdVUn9uXvDjenVOGaTr1ah+kcyRFgCTsbBT6N7BbxoHDkBMl U3PAvPdg5UG624P4gmPagdoy7DtOAxfHxAF2cW6HB6nTfR+GG2xwJ9N0XXgOPCTS1vNJ IiWg== X-Gm-Message-State: AC+VfDxH0DdzGYSmcdfON4HaNzKOiGX6g63VQOGlZ8rfJB4Iu66akujw aDTw+E6YwojY5QuMYT4n6TkG8IA+UJ1Met7kKKQ= X-Received: by 2002:ad4:5fca:0:b0:615:29ab:e4c6 with SMTP id jq10-20020ad45fca000000b0061529abe4c6mr2008193qvb.45.1682598981060; Thu, 27 Apr 2023 05:36:21 -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> <20230424174049.1c9e54dd@rorschach.local.home> In-Reply-To: From: Yafang Shao Date: Thu, 27 Apr 2023 20:35:45 +0800 Message-ID: Subject: Re: [PATCH bpf-next 5/6] bpf: Improve tracing recursion prevention mechanism To: Steven Rostedt , 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 , Masami Hiramatsu , bpf , linux-trace-kernel@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Thu, Apr 27, 2023 at 8:15=E2=80=AFPM Yafang Shao = wrote: > > On Thu, Apr 27, 2023 at 5:57=E2=80=AFPM Yafang Shao wrote: > > > > On Tue, Apr 25, 2023 at 5:40=E2=80=AFAM Steven Rostedt wrote: > > > > > > On Wed, 19 Apr 2023 15:46:34 -0700 > > > Alexei Starovoitov wrote: > > > > > > > No. Just one prog at entry into any of the kernel functions > > > > and another prog at entry of funcs that 1st bpf prog called indirec= tly. > > > > Like one prog is tracing networking events while another > > > > is focusing on mm. They should not conflict. > > > > > > You mean that you have: > > > > > > function start: > > > __bpf_prog_enter_recur() > > > bpf_program1() > > > __bpf_prog_enter_recur() > > > bpf_program2(); > > > __bpf_prog_exit_recur() > > > __bpf_prog_exit_recur() > > > > > > rest of function > > > > > > That is, a bpf program can be called within another bpf pogram betwee= n > > > the prog_enter and prog_exit(), that is in the same context (normal, > > > softirq, irq, etc)? > > > > > > > Right, that can happen per my verification. Below is a simple bpf > > program to verify it. > > > > struct { > > __uint(type, BPF_MAP_TYPE_LPM_TRIE); > > __type(key, __u64); > > __type(value, __u64); > > __uint(max_entries, 1024); > > __uint(map_flags, BPF_F_NO_PREALLOC); > > } write_map SEC(".maps"); > > > > __u64 key; > > > > SEC("fentry/kernel_clone") > > int program1() > > { > > __u64 value =3D 1; > > > > bpf_printk("before update"); > > // It will call trie_update_elem and thus trigger program2. > > bpf_map_update_elem(&write_map, &key, &value, BPF_ANY); > > __sync_fetch_and_add(&key, 1); > > bpf_printk("after update"); > > return 0; > > } > > > > SEC("fentry/trie_update_elem") > > int program2() > > { > > bpf_printk("trie_update_elem"); > > return 0; > > } > > > > The result as follows, > > > > kubelet-203203 [018] ....1 9579.862862: > > __bpf_prog_enter_recur: __bpf_prog_enter_recur > > kubelet-203203 [018] ...11 9579.862869: bpf_trace_printk: > > before update > > kubelet-203203 [018] ....2 9579.862869: > > __bpf_prog_enter_recur: __bpf_prog_enter_recur > > kubelet-203203 [018] ...12 9579.862870: bpf_trace_printk: > > trie_update_elem > > kubelet-203203 [018] ....2 9579.862870: > > __bpf_prog_exit_recur: __bpf_prog_exit_recur > > kubelet-203203 [018] ...11 9579.862870: bpf_trace_printk: > > after update > > kubelet-203203 [018] ....1 9579.862871: > > __bpf_prog_exit_recur: __bpf_prog_exit_recur > > > > Note that we can't trace __bpf_prog_enter_recur and > > __bpf_prog_exit_recur, so we have to modify the kernel to print them. > > > > ... However, surprisingly it still works even after this patchset is > applied, because the hardirq/softirq flag is set when the program2 is > running, see also the flags in the above trace_pipe output. Is that > expected ?! > I need some time to figure it out, but maybe you have a quick answer... Answer it by myself, that is because of the allowing-one-single-recursion rule. I misread the trace flags before. Sorry about the noise. --=20 Regards Yafang