Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp1083297rdb; Wed, 1 Nov 2023 10:46:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHXNe+aIvVRtxAztVPvecqk0J8HTjvXzSvyk5NZoFPJT38uTZLZMyvd0okp7T7fTuASoOiY X-Received: by 2002:a17:90a:199d:b0:280:c98f:2092 with SMTP id 29-20020a17090a199d00b00280c98f2092mr1536892pji.33.1698860783028; Wed, 01 Nov 2023 10:46:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698860783; cv=none; d=google.com; s=arc-20160816; b=VGPGdh5ENBdVGXIsbe1F2ws3U3e6qlIjqZLQxcV+G0AlTxLvoXyRcvuiKPsMmUVO3G A5ex/0J8KVlDxFRjvd/Fd2gBu0/hwt7G75LT07mMc99uzY1PxI6U1QQ+adu50Yy2j7O+ rZrVkGXspOyYYp8xm9/MMR7hwJi5vj7wCZkYBCM4SxNnuDZpwl2S0IykYIwwaprqtwME PCVyuESrXep6jc+Anpl2TcunygNC+Kw02LrS54agaZqaLhFk2Wkoq2eA9Oh616L8zozY c9Te/ys9PMtoYAdXAYG7a7LktWHe/S5lCa43x7eqclPycytg8vtxm/QrzIaKXRyS7DdR jH9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=4LdDWe+nHVSFRbVoP/efYQBsZcWql/n14ehINMw79JE=; fh=RLyvT+9znyh5NCLVcwcGg8/M/h1uR6tfDvAAbw7yZcs=; b=LJpXVT7tsbc/SjUlStRjhznUL+UIMuZBDxwlH3u9KU6XTsORo0Pu48IRAI6od4W1ZU VhwTfMYemMfZKkClgrxZZ1JwBawGDUrzXtjf/Y290quilXFCkMWr9eVJ3Wy6HjvnSdvA Xb2ifJ5lydiTfoDI8a8jWpwRA5J5c11nSET20cT8qfqlfIK4ss88Z+hrikX/uhcu25y4 8dZ03CynbBcDFZ/+onVRwBEmvJ5VTPOpiVQ+FX4W7QTs6uofSIhhEeb0qV1UZFl+Ub9y N6ETv469/qWBxuJ2ToLt6SA8CnCfdYAcGUWVThRQ3GLDuUzTR/RdaR+PWA/K+WlIIr1a pXyQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id e8-20020a17090ab38800b0026ceee6848asi1234905pjr.180.2023.11.01.10.46.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 10:46:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 97CDE8062909; Wed, 1 Nov 2023 10:46:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344649AbjKARqK (ORCPT + 99 others); Wed, 1 Nov 2023 13:46:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344760AbjKARqH (ORCPT ); Wed, 1 Nov 2023 13:46:07 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 260A912E for ; Wed, 1 Nov 2023 10:45:59 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2083DC433C8; Wed, 1 Nov 2023 17:45:58 +0000 (UTC) Date: Wed, 1 Nov 2023 13:45:56 -0400 From: Steven Rostedt To: Jiri Olsa Cc: "Masami Hiramatsu (Google)" , Florent Revest , linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [QUESTION] ftrace_test_recursion_trylock behaviour Message-ID: <20231101134556.5d4a46c3@gandalf.local.home> In-Reply-To: References: X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 01 Nov 2023 10:46:17 -0700 (PDT) On Wed, 1 Nov 2023 18:32:14 +0100 Jiri Olsa wrote: > hi, > I'm doing some testing on top of fprobes and noticed that the > ftrace_test_recursion_trylock allows caller from the same context > going through twice. > > The change below adds extra fprobe on stack_trace_print, which is > called within the sample_entry_handler and I can see it being executed > with following trace output: > > <...>-457 [003] ...1. 32.352554: sample_entry_handler: > Enter ip = 0xffffffff81177420 <...>-457 > [003] ...2. 32.352578: sample_entry_handler_extra: Enter > ip = 0xffffffff8127ae70 > > IOW nested ftrace_test_recursion_trylock call in the same context > succeeded. > > It seems the reason is the TRACE_CTX_TRANSITION bit logic. > > Just making sure it's intentional.. we have kprobe_multi code on top of > fprobe with another re-entry logic and that might behave differently based > on ftrace_test_recursion_trylock logic. Yes it's intentional, as it's a work around for an issue that may be cleared up now with Peter Zijlstra's noinstr updates. The use case for that TRACE_CTX_TRANSITION is when a function is traced just after an interrupt was triggered but before the preempt count was updated to let us know that we are in an interrupt context. Daniel Bristot reported a regression after the trylock was first introduced where the interrupt entry function was traced sometimes but not always. That's because if the interrupt happened normally, it would be traced, but if the interrupt happened when another event was being traced, the recursion logic would see that the trace of the interrupt was happening in the same context as the event it interrupted and drop the interrupt trace. But after the preempt count was updated, the other functions in the interrupt would be seen. This led to very confusing trace output. The solution to that was this workaround hack, where the trace recursion logic would allow a single recursion (the interrupt preempting another trace before it set preempt count). But with noinstr, there should be no more instances of this problem and we can drop that extra bit. But the last I checked, there were a few places that still could be traced without the preempt_count set. I'll have to re-investigate. -- Steve