Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp756938ybp; Fri, 11 Oct 2019 04:01:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqyI/SoZ1HX2B174zxBTXV9OEXmBNhOX/HNiLbNmLz5SA86TaIu1OwT3TZInBBcfMzi26pZ6 X-Received: by 2002:a17:907:10d3:: with SMTP id rv19mr12678747ejb.301.1570791666514; Fri, 11 Oct 2019 04:01:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570791666; cv=none; d=google.com; s=arc-20160816; b=0YpiiM9OVKYS5EJCBS6PGqyu3jMLJtBq8izHWunBbdTJIPEAN0XqRhy1W309Et5E08 AemZ6/wQ9MVrQgmdTzUg9/2VqAO+wI8fwJ5vVievIsQFe5k/y27J7KRrlXpO2Z3AzGGi G/fnEHh3t3hYvoByWXjhek4ONdGO3e3WgBvC5GOWjUQWhj2aW1pVksQxq+dQ1jl/SEh6 OxfPlx9fBSYK1Xt2PHtY7MuLgfYA8lttykL99r5XhPNNBddJOw6oOSwomBKjtOekeDjC URKnnMk+18+kSbEm++mcfqiglXNrdiY9i2Gffdgv9e02f9sE9kdBT2LWzVjP9RR+k0kB gWyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=OCP5lhDCSBpeO5Vh7HhxpRJB7tB8MYPetbw1XJik9JM=; b=b4SgZ5HMD4buJaPzRMw4vHSpC8BV+4vQcGKb0hHPoWA+wps48hX0zHIYvNMcCPxN4J zCmXQ7SAV0raK4ooSZZ4PEuF1poJ+wuP0x+/RkZYlyQQLh+UZdxmjk+ZcOzKjet+0AIt TIaEa8pHLQorNR0AKKZy0eDhiBKqZ+4zjvYsYrzrJgqYo6Yh/n87zrGx6cdfuWPJP/9R TlmDP3Ue60GAsFxgec6jDW626okzDBfGtuQgfraiHJG7Z0o6aV5LwSTuRXyFzuM0H1/h +nCGvyBpzCevdDD5As4mMw+Lx+UA4mcJDjfE3miQbmXfA1vsqCJDw4i8oNuWyJ+aIlMC k0LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ut4+Z8nv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l45si5837924edc.185.2019.10.11.04.00.42; Fri, 11 Oct 2019 04:01:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ut4+Z8nv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727785AbfJKK54 (ORCPT + 99 others); Fri, 11 Oct 2019 06:57:56 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:35084 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726885AbfJKK54 (ORCPT ); Fri, 11 Oct 2019 06:57:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=OCP5lhDCSBpeO5Vh7HhxpRJB7tB8MYPetbw1XJik9JM=; b=ut4+Z8nvRj2QKkHDgyZb8vChp gGHdGnQ37YSZiaiaxadpetd4H/F+V6rDUn4vSWi+FKGOjMDDEdyXYBKr7+yuZqb5btAvQZs4j4z5i GN3FC/HwoX4uW6vhLkY8HZIaL6TojrTJHHmnekJH90EYM/OjVH3GqPdvsCy34DOqBVMm9E6iHk+YV znRagxExipiPbhfYriXkN+eLzkIqJ1+w6lMufS/B2NdSkMI6sGmRPXkuoT1RPRiDX96otpv1zD8iP Ps8P1Ih9i1l1JVIggEbYxvX2phGcO4mt3xZ1C0qU1yVwE76TfYHmE5Vn5TTblLYAWD857LYNt2G+r jh16CNeyA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIscE-00051A-PV; Fri, 11 Oct 2019 10:57:46 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 4855B305BD3; Fri, 11 Oct 2019 12:56:52 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id DCD5520230368; Fri, 11 Oct 2019 12:57:44 +0200 (CEST) Date: Fri, 11 Oct 2019 12:57:44 +0200 From: Peter Zijlstra To: Daniel Bristot de Oliveira Cc: Steven Rostedt , linux-kernel@vger.kernel.org, x86@kernel.org, Nadav Amit , Andy Lutomirski , Dave Hansen , Song Liu , Masami Hiramatsu Subject: Re: [PATCH 3/3] x86/ftrace: Use text_poke() Message-ID: <20191011105744.GW2311@hirez.programming.kicks-ass.net> References: <20190827180622.159326993@infradead.org> <20190827181147.166658077@infradead.org> <20191002182106.GC4643@worktop.programming.kicks-ass.net> <20191003181045.7fb1a5b3@gandalf.local.home> <7b4196a4-b6e1-7e55-c3e1-a02d97c262c7@redhat.com> <20191011070126.GU2328@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 11, 2019 at 09:37:10AM +0200, Daniel Bristot de Oliveira wrote: > On 11/10/2019 09:01, Peter Zijlstra wrote: > > On Fri, Oct 04, 2019 at 10:10:47AM +0200, Daniel Bristot de Oliveira wrote: > >> Currently, ftrace_rec entries are ordered inside the group of functions, but > >> "groups of function" are not ordered. So, the current int3 handler does a (*): > > We can insert a sort() of the vector right before doing > > text_poke_bp_batch() of course... > > I agree! > > What I tried to do earlier this week was to order the ftrace_pages in the > insertion [1], and so, while sequentially reading the pages with > do_for_each_ftrace_rec() we would already see the "ip"s in order. > > As ftrace_pages are inserted only at boot and during a load of a module, this > would push the ordering for a very very slow path. > > It works! But under the assumption that the address of functions in a module > does not intersect with the address of other modules/kernel, e.g.: > > kernel: module A: module B: > [ 1, 2, 3, 4 ] [ 7, 8, 9 ] [ 15, 16, 19 ] > > But this does not happen in practice, as I saw things like: > > kernel: module A: module B: > [ 1, 2, 3, 4 ] [ 7, 8, 18 ] [ 15, 16, 19 ] > ^^ <--- greater than the first of the next > > Is this expected? Expected is I think a big word. That is, I would certainly not expect that, but I think I can see how it can happen. Suppose that init sections are placed at the end (didn't verify, but makes sense), then suppose that A's 18 is in an init section, which gets freed once the module load is completed. We then proceed to load B, which then overlaps with what used to be A's init. If this were the case, then while we could retain the pach location for A's 18, we would never actually modify it, because it's gotten marked freed or something (that's how jump_labels work, I didn't check what ftrace actually does here). So while the above contains some assumptions, it is a semi plausable explanation for what you've described.