Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1062714pxb; Sat, 16 Oct 2021 00:22:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwehdN1JbYxW++JV8dS3gJ4IXL3paqvjg/zj5fvCsGjEzN273q0s4toOlxPqkuSfKU7kvQu X-Received: by 2002:a05:6402:50cd:: with SMTP id h13mr24432078edb.245.1634368974066; Sat, 16 Oct 2021 00:22:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634368974; cv=none; d=google.com; s=arc-20160816; b=JCWKUud9ENbELISgJbEVzevc0d4eI25cZYine3+klJplFWitW+0/UbMU47g90gWgco OMzPPxV2pHRzFPlGBvjwOiIihgPtlGcoDKuuGBjaC/m0cn08Cc7UXnAS0N9yArK4EsuN FdvApN1vsl7Zib9Q7zyDMja6mhLmH+YOQq2W8ZsJ/PFZjOhSsqZQCOrRHDms/a5Kcn5q oaeLXkotO0shlH9ixKq+vlktafGZeY63ZxWCBAYytcgBDsjY2KNY+C934Q8sFuUuKzdV bleoMWv1YWl+C16gacS55kKxU3pQgDld+g4SbKYBsgLBbDcIgMDmV/HhBWd/Rm6UlGs+ dNmQ== 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=P0gQls/orO5bW3MP+G2rOnIAflZaRjolbH+lpHJDEro=; b=LZnoTfGvtsrBiYSAOcR0tWWarOQnBp8lbfJ7PpEENbQg6WkTbCZ5UN9PJ/NX0mhkRa N2qN0+3HV52zb9OjpFyQ0Xsgb41tm9hQ0rc3vlb442AAGqjB5+xPuObNpt2y34HXq6Kp H3j3eZ8uqfMUJGCyGBbbEYFsYq/uNTBPTKMgWcQ7cc5OWMwRtQyu6cDETpeDYwM1ks5x Acj0cLrCjtsl4ERC3KkZ0PVAPZfInAGJP62uOiinap2FNiDpbwz7fYQjHJTWFUoInqI9 xiAFLkNtiyv5cr/jPaDWw0BDteGWyTf7WCN8+LuJ4zEFqB+yu3m38cVlHSQ+azLSNkzF ZqFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e8si7988061edz.147.2021.10.16.00.22.19; Sat, 16 Oct 2021 00:22:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234697AbhJONhz convert rfc822-to-8bit (ORCPT + 99 others); Fri, 15 Oct 2021 09:37:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:45774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236973AbhJONhx (ORCPT ); Fri, 15 Oct 2021 09:37:53 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 667A761151; Fri, 15 Oct 2021 13:35:44 +0000 (UTC) Date: Fri, 15 Oct 2021 09:35:42 -0400 From: Steven Rostedt To: =?UTF-8?B?546L6LSH?= Cc: Petr Mladek , Guo Ren , Ingo Molnar , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Paul Walmsley , Palmer Dabbelt , Albert Ou , Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Joe Lawrence , Colin Ian King , Masami Hiramatsu , "Peter Zijlstra (Intel)" , Nicholas Piggin , Jisheng Zhang , linux-csky@vger.kernel.org, linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, live-patching@vger.kernel.org Subject: Re: [PATCH v3 1/2] ftrace: disable preemption between ftrace_test_recursion_trylock/unlock() Message-ID: <20211015093542.7d9a9671@gandalf.local.home> In-Reply-To: <3c87e825-e907-cba0-e95f-28878356fc71@linux.alibaba.com> References: <609b565a-ed6e-a1da-f025-166691b5d994@linux.alibaba.com> <7e4738b5-21d4-c4d0-3136-a096bbb5cd2c@linux.alibaba.com> <5e907ed3-806b-b0e5-518d-d2f3b265377f@linux.alibaba.com> <3c87e825-e907-cba0-e95f-28878356fc71@linux.alibaba.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 15 Oct 2021 17:12:26 +0800 王贇 wrote: > Maybe take some example would be easier to understand... > > Currently there are two way of using ftrace_test_recursion_trylock(), > one with TRACE_FTRACE_XXX we mark as A, one with TRACE_LIST_XXX we mark > as B, then: > > A followed by B on same context got bit > 0 > B followed by A on any context got bit 0 > A followed by A on same context got bit > 0 > A followed by A followed by A on same context got bit -1 > B followed by B on same context got bit > 0 > B followed by B followed by B on same context got bit -1 > > If we get rid of the TRACE_TRANSITION_BIT which allowed recursion for > onetime, then it would be: We can't get rid of the transition bit. It's there to fix a bug. Or at least until we finish the "noinst" issue which may be true now? I have to go revisit it. The reason for the transition bit, is because we were dropping function traces, that people relied on being there. The problem is that the recursion protection allows for nested context. That is, it will not detect recursion if we an interrupt triggers during a trace (while the recursion lock is held) and then that interrupt does a trace. It is allowed to call the ftrace_test_recursion_trylock() again. But, what happens if the trace occurs after the interrupt triggers, but before the preempt_count states that we are now in interrupt context? As preempt_count is used by this code to determine what context we are in, if a trace happens in this "transition" state, without the transition bit, a recursion is detected (false positive) and the event is dropped. People are then confused on how an interrupt happened, but the entry of the interrupt never triggered (according to the trace). The transition bit allows one level of recursion to handle this case. The "noinst" work may also remove all locations that can be traced before the context is updated. I need to see if that is now the case, and if it is, we can remove the transition bit. This is not the design issue I mentioned earlier. I'm still working on that one. -- Steve > > A followed by B on same context got bit > 0 > B followed by A on any context got bit 0 > A followed by A on same context got bit -1 > B followed by B on same context got bit -1 > > So as long as no continuously AAA it's safe?