Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2619364ybp; Thu, 10 Oct 2019 10:00:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqyDXO4XWNHWBTZnHEP39Ntu91oYlEyNTSRzZvokTxZ5Y8yg3/9ZHxYKD3IJIqLHKj+TS9F+ X-Received: by 2002:a17:906:48cf:: with SMTP id d15mr9300658ejt.59.1570726802927; Thu, 10 Oct 2019 10:00:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570726802; cv=none; d=google.com; s=arc-20160816; b=0KCNZevJRbXyPynn7j/6npvCOCPJRFSSj+j/iF45s4UU5twCUyvQKNJ1va+0xmx8Ax 0lyvtLSYHCPWvSLQf1BoZuW88pGAtm3m/Ym9IsYj/A0ds1QANP2q1X/L/VTfQvsD0oEl VQ0uCZKxD61JCQrem5XicD8gaB/3scdxE0pHy+f/rD6nPzFPPmJWUX0HsmDajrmUDBM9 t2az1FLl4ingSFei12xL7j2V3ogRnjoZk3XfFl3GRLiHyvISG3apqmILxwmPyiXPp60r WFnFjpHTQn/MXR4jldMlYLlT5kfL2rWQ7Ag5LtPtsS5BG3Qr0/wzBNBAxROwNEOjaMWw YyEw== 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=ugJevpmlDNdDWvRJpDhyfN+SP8Ah613cjkPKstwFBKQ=; b=VzB8pjCCtcYTXXuYLAu7oqknvox0ZXngeSFStfP07qFxVJge8L67P65p12nUMM2r97 GQVDHi+yUaM5GP24DvYMjfQNJ0vLQjK9iZJz3Rm79as7RH3gaH4lthUjcL6/GvMVTPU9 DGsloo9WKDZ40w3e2/ZfvM44Ozx3o+90BJCmgUycke+EtiNfxHLM+6ks+MpmEuER0c4h LuzxypUcPZKFI1a7zrmxyUE8/aRAz0W+Ak6XSmtlyDhui3wZuVnEzdvyndOXicFdKWco sOIBhRUFB7kLiz4T7p4GB4JM9BbVmxH0gyhRPgmr9C5dLAqeVDaVabCPQ4XmYzjm/bmt YGVg== 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 o2si3443818ejm.367.2019.10.10.09.59.34; Thu, 10 Oct 2019 10:00:02 -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 S1726479AbfJJQ7S (ORCPT + 99 others); Thu, 10 Oct 2019 12:59:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:35980 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726038AbfJJQ7S (ORCPT ); Thu, 10 Oct 2019 12:59:18 -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 7B402214E0; Thu, 10 Oct 2019 16:59:17 +0000 (UTC) Date: Thu, 10 Oct 2019 12:59:15 -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: <20191010125915.34a2cfdf@gandalf.local.home> In-Reply-To: <20191010105515.5eba7f31@gandalf.local.home> 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> 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 10:55:15 -0400 Steven Rostedt wrote: I'll try to add more detail (mapping to functions) > > 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 Just need to know that the above will now have all loaded modules have their functions being traced. That is ftrace_startup > 0. > modprobe foo > enable foo functions to be traced > (foo function records not disabled) In your code, we have here: load_module() foo->state == UNFORMED ftrace_module_init() ftrace_process_locs() mutex_lock(ftrace_lock); __ftrace_replace_code(rec, 1) /* Enabling foo's functions */ mutex_unlock(ftrace_lock); > echo nop > current_tracer > > disable all functions being > traced including foo functions ftrace_shutdown() ftrace_run_update_code() ftrace_arch_code_modify_prepare() [ on arm and nds32 ] > > 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 complete_formation() module_enable_ro() > > tries to disable foo's functions > foo's text is read-only arch_ftrace_update_code() ftrace_modify_all_code() [ Includes foo's functions ] > > BUG trying to write to ro text!!! Hope that makes more sense. -- Steve > > > 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.