Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934112AbbLPO2Z (ORCPT ); Wed, 16 Dec 2015 09:28:25 -0500 Received: from cdptpa-outbound-snat.email.rr.com ([107.14.166.231]:16103 "EHLO cdptpa-oedge-vip.email.rr.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753728AbbLPO2X (ORCPT ); Wed, 16 Dec 2015 09:28:23 -0500 Date: Wed, 16 Dec 2015 09:28:12 -0500 From: Steven Rostedt To: "Zhang, Yanmin" Cc: "Qiu, PeiyangX" , linux-kernel@vger.kernel.org, mingo@redhat.com, Rusty Russell Subject: Re: [PATCH] ftrace: fix race between ftrace and insmod Message-ID: <20151216092812.34711e3b@grimm.local.home> In-Reply-To: <56713CD3.80006@linux.intel.com> References: <566E3076.5080708@intel.com> <566E3482.1090008@intel.com> <20151214105128.780b8bac@gandalf.local.home> <566F675C.9000904@linux.intel.com> <566F8871.7070408@linux.intel.com> <20151215123719.183879fc@gandalf.local.home> <56713CD3.80006@linux.intel.com> X-Mailer: Claws Mail 3.13.0 (GTK+ 2.24.28; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-RR-Connecting-IP: 107.14.168.142:25 X-Cloudmark-Score: 0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2145 Lines: 59 On Wed, 16 Dec 2015 18:28:35 +0800 "Zhang, Yanmin" wrote: > > + /* > > + * If the tracing is enabled, go ahead and enable the record. > > + * > > + * The reason not to enable the record immediatelly is the > > + * inherent check of ftrace_make_nop/ftrace_make_call for > > + * correct previous instructions. Making first the NOP > > + * conversion puts the module to the correct state, thus > > + * passing the ftrace_make_call check. > > + * > > + * We also delay this to after the module code already set the > > + * text to read-only, as we now need to set it back to read-write > > + * so that we can modify the text. > > + */ > > + if (ftrace_start_up) > > + ftrace_arch_code_modify_prepare(); > > + > > + do_for_each_ftrace_rec(pg, rec) { > > + int cnt; > > + /* > > + * do_for_each_ftrace_rec() is a double loop. > > + * module text shares the pg. If a record is > > + * not part of this module, then skip this pg, > > + * which the "break" will do. > > + */ > > + if (!within_module_core(rec->ip, mod)) > > + break; > > + > > + cnt = 0; > > + > > + /* > > + * When adding a module, we need to check if tracers are > > + * currently enabled and if they are, and can trace this record, > > + * we need to enable the module functions as well as update the > > + * reference counts for those function records. > > + */ > > + if (ftrace_start_up) > > + cnt += referenced_filters(rec); > > + > > + /* This clears FTRACE_FL_DISABLED */ > > + rec->flags = cnt; > > + > > + if (ftrace_start_up && cnt) { > > + int failed = __ftrace_replace_code(rec, 1); > > If we choose to call ftrace_module_enable when receiving module notification > MODULE_STATE_COMING, TEXT section of the module is already changed to RO. And that's why we call ftrace_arch_code_modify_prepare(). That should change all text to RW. -- Steve -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/