Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2647313ybp; Thu, 10 Oct 2019 10:23:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwrZQ3PK2eHGaqc8icLSrsZmQMMkajbWIMWlYUKn4LSzjUhxcR5Ovq/d4cCxIJCB0CysD/Q X-Received: by 2002:a17:906:48c6:: with SMTP id d6mr9291636ejt.291.1570728201402; Thu, 10 Oct 2019 10:23:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570728201; cv=none; d=google.com; s=arc-20160816; b=RmNo4KRmx57uuPpqs2Nw1GVo7bOdSqwQm878m27FiQLOEPiSzUoNhOA6QqA+9+fgHo Ili0Ud5W9TnEbBCJS8jS19gM6Jo0rqPc6IwAzsrWOmP1OkaZ5LsfcCaelRpD1arIs+Kc 2/OcxuhYO2l7xiqxnLtb6PqX1545JUEkSFfvoqWuSvZgpRdcq/moV86/SNZul3IUUawv lqr9sYeJ9PFP7eLQje1vmDTp4Z4JEBXoD9jlzHwz6Xtnu8Pn9mvVuOQWYx2rIiVNVhnF gJoIN5l9iiT640DpEwKYal0kniSengPq85vxb25RfV2hIvZgR07M8t6aSD4l0FOML0LA ytPQ== 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=A+z9qqJtvnBK6e+pq9DYJcvKn4N05/MNXgFwMhJeo4s=; b=tvDgrFCGvmVsx3+arPOhIURv7BOHgwsQgQMNoOJA+Fn3fM50npX0qgRPJp7xThsL8g Cn1hvHUaN7BW/ZsZ83gnEYMW2DY5KzlX0iTnMEhyOXf0Son47k/Sxuda88iar3M9R0lA PqBUu7LDGAdA2YcYdQvGQrvHSk/j+4B9kbRZVh98oC13hZ+j+0v4UesceRk9lg7Wx9R0 sWogNeeR8Qp/+RastfJWcui1aumJsaDRXsVpnuv3OK4/GM88Nn6hbJWDFubIozVruJG+ 0WB9bkAKM4tvf3POgoLLFMexwHRUM/dl2yB+pp1YE/y8LXAIAB2KcptY2XyqhCfbWsYY 895g== 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 d25si3459686edq.65.2019.10.10.10.22.57; Thu, 10 Oct 2019 10:23:21 -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 S1726753AbfJJRUR (ORCPT + 99 others); Thu, 10 Oct 2019 13:20:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:39830 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726131AbfJJRUR (ORCPT ); Thu, 10 Oct 2019 13:20:17 -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 9413A20659; Thu, 10 Oct 2019 17:20:15 +0000 (UTC) Date: Thu, 10 Oct 2019 13:20:13 -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: <20191010132013.7f3388bc@gandalf.local.home> In-Reply-To: <20191010170111.GQ2328@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> <20191010122909.GK2359@hirez.programming.kicks-ass.net> <20191010105515.5eba7f31@gandalf.local.home> <20191010170111.GQ2328@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 19:01:11 +0200 Peter Zijlstra wrote: > On Thu, Oct 10, 2019 at 10:55:15AM -0400, Steven Rostedt wrote: > > > OK, so basically this moves the enabling of function tracing from > > within the ftrace_module_enable() code without releasing the > > ftrace_lock mutex. > > > > But we have an issue with the state of the module here, as it is still > > set as MODULE_STATE_UNFORMED. Let's look at what happens if we have: > > > > > > CPU0 CPU1 > > ---- ---- > > echo function > current_tracer > > modprobe foo > > enable foo functions to be traced > > (foo function records not disabled) > > echo nop > current_tracer > > > > disable all functions being > > traced including foo functions > > > > arch calls set_all_modules_text_rw() > > [skips UNFORMED modules, which foo still is ] > > > > set foo's text to read-only > > foo's state to COMING > > > > tries to disable foo's functions > > foo's text is read-only > > > > BUG trying to write to ro text!!! > > > > > > Like I said, this is very subtle. It may no longer be a bug on x86 > > with your patches, but it will bug on ARM or anything else that still > > uses set_all_modules_text_rw() in the ftrace prepare code. > > I can't immediately follow, but I think we really should go there. > > For now, something like this might work: Hmm, I'm lost at what the below is trying to do with respect to the above. -- Steve > > --- a/arch/x86/kernel/ftrace.c > +++ b/arch/x86/kernel/ftrace.c > @@ -34,6 +34,8 @@ > > #ifdef CONFIG_DYNAMIC_FTRACE > > +static int ftrace_poke_late = 0; > + > int ftrace_arch_code_modify_prepare(void) > __acquires(&text_mutex) > { > @@ -43,12 +45,15 @@ int ftrace_arch_code_modify_prepare(void > * ftrace has it set to "read/write". > */ > mutex_lock(&text_mutex); > + ftrace_poke_late = 1; > return 0; > } > > int ftrace_arch_code_modify_post_process(void) > __releases(&text_mutex) > { > + text_poke_finish(); > + ftrace_poke_late = 0; > mutex_unlock(&text_mutex); > return 0; > } > @@ -116,7 +121,10 @@ ftrace_modify_code_direct(unsigned long > return ret; > > /* replace the text with the new text */ > - text_poke_early((void *)ip, new_code, MCOUNT_INSN_SIZE); > + if (ftrace_poke_late) > + text_poke_queue((void *)ip, new_code, MCOUNT_INSN_SIZE, NULL); > + else > + text_poke_early((void *)ip, new_code, MCOUNT_INSN_SIZE); > return 0; > } >