Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2323334ybp; Thu, 10 Oct 2019 05:53:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqzDNa92iRwB6V5KKrRuIPOIICdFMM/oeIX8krde6DJjaFEffLeK948/++HCdY8qKZb8zUxv X-Received: by 2002:a17:906:6a4f:: with SMTP id n15mr7949119ejs.19.1570711990029; Thu, 10 Oct 2019 05:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570711990; cv=none; d=google.com; s=arc-20160816; b=kVumNpyBOIbnFwUFXYG4UdMEXcIk09q85LduaQ33fBo3MhXYHQmR8eom3NTccBPul9 DzJTE3KQp2o5yITTMqwmRZ+TZOtdQsMf7Ihyu7f7t/MZ+lzCeqr6mTWAPAUt/KuZtrNB Yn0Jy2zGIy/zgqXUb/qjCkO29aBXk28r46yyF9d6Yi3cQGBYBB/1yPznUhD3MxO6Xe9Q UT5xolG8LUi33AcyDfWjgf1bUmkwvtmNbJHIDFEQgpEyTPF312Wp/d0kjG1YghvNXLDM NKi2MBxRnR58UeBQc6FGZ2Or41SdY0gCUH1Wi8v09UF9oh3zikD2d9vIxCEfgaskKJF9 wAVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=vH8tvAEHLYYf/SgfomzlmCrFD7g0kmHFWtxDRZqlqbg=; b=jAT8cZoy5UY0dvGXcBTlHua/kuSwGnIzEy+XSTsc0+pO0meFpsIfw9OyhnCTbtKMJO lwswLqkCPjP67L0pd9EAjx/JuQcI/D17rFkJ0pAvU6Yz/SLJV/ou53/7AB+HBwJcZ7Ml rXq/I2fB1yzQWAewtfKDnxeSU9cM97iuigt5BLGKbmQoG2TuWNv5RuOpSLtyGooapSbE l2jfFe4V4y4Vh8KtsCW/WdqpcUPLooK3eP+664a1kjlZfLe0JVYVjVuGIV7YIcRzVONZ VlXGUpojisSwG78M1LJ8p1HgSRhmPDEHcToXJSDoCfFq/RrOaKZeyZ0/WzgrhDMRRL00 Yn2Q== ARC-Authentication-Results: i=1; mx.google.com; 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 f14si3724151edf.102.2019.10.10.05.52.45; Thu, 10 Oct 2019 05:53:10 -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; 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 S2387457AbfJJMuO (ORCPT + 99 others); Thu, 10 Oct 2019 08:50:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:50738 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733171AbfJJMuO (ORCPT ); Thu, 10 Oct 2019 08:50:14 -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 767012067B; Thu, 10 Oct 2019 12:50:13 +0000 (UTC) Date: Thu, 10 Oct 2019 08:50:11 -0400 From: Steven Rostedt To: Peter Zijlstra Cc: LKML , Jessica Yu , Ingo Molnar Subject: Re: [PATCH] ftrace/module: Allow ftrace to make only loaded module text read-write Message-ID: <20191010085011.3734d87b@gandalf.local.home> In-Reply-To: <20191010093650.GJ2359@hirez.programming.kicks-ass.net> References: <20191009223638.60b78727@oasis.local.home> <20191010073121.GN2311@hirez.programming.kicks-ass.net> <20191010093329.GI2359@hirez.programming.kicks-ass.net> <20191010093650.GJ2359@hirez.programming.kicks-ass.net> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 10 Oct 2019 11:36:50 +0200 Peter Zijlstra wrote: > > > > The reason is that ftrace_module_enable() is called after the module > > > > has set its text to read-only. There's subtle reasons that this needs > > > > to be called afterward, and we need to continue to do so. > > > > > > Please explain. I knew you were going to say that ;-) I was too tired last night to go back and see all the issues. > > > > I don't see any reason what so ever.. > > > > load_module() > > ... > > complete_formation() > > mutex_lock(&module_mutex); > > ... > > module_enable_ro(); > > module_enable_nx(); > > module_enable_x(); > > > > mod->state = MODULE_STATE_COMING; > > mutex_unlock(&module_mutex); > > > > prepare_coming_module() > > ftrace_module_enable(); > > ... > > > > IOW, we're doing ftrace_module_enable() immediately after we flip it > > RO+X. There is nothing in between that we can possibly rely on. One reason for the above is the module_mutex. The lock order is that module_mutex may be called inside the ftrace_lock, but not vice-versa. The ftrace_module_init() was called due to the setting of all modules rw when registering a ftrace function while a module was being loaded. We may have eliminated this issue on x86 but other archs still call set_all_modules_text_rw/ro() when enabling function tracing. Thus, the race will still exist there. See commit a949ae560a511 for the description of it. After implementing that commit, I found it a bit cleaner to handle modules in general by breaking it up into setting nops first, and then determining if we need to trace that module. > > > > I was going to put: > > > > blocking_notifier_call_chain(&module_notify_list, > > MODULE_STATE_UNFORMED, mod); > > > > right before module_enable_ro(), in complete_formation(), for jump_label > > and static_call. It looks like ftrace (and possibly klp) want that too. > > Also, you already have ftrace_module_init() right before that. The only > thing inbetween ftrace_module_init() and ftrace_module_enable() is > verify_exported_symbols() and module_bug_finalize(). Yep, see commit a949ae560a511 about that too. > > Do you really need that for patching stuff? Because arm and nds32 still use the set_all_modules_text_rw(), this patch would at least remove that for all archs, and only modify the text of a module that isn't running yet. Which I thought was a plus. Just need to be careful about other archs, or we need to at least make sure they change too. -- Steve