mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: stable-review@kernel.org, torvalds@linux-foundation.org,
	akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
	Steven Rostedt <rostedt@goodmis.org>
Subject: [36/38] ftrace: Fix regression where ftrace breaks when modules are loaded
Date: Tue, 11 Oct 2011 10:55:46 -0600	[thread overview]
Message-ID: <20111011165713.842995901@pistachio.kroah.org> (raw)
In-Reply-To: <20111011165903.GA30976@kroah.com>

3.0-stable review patch.  If anyone has any objections, please let us know.

------------------

From: Steven Rostedt <srostedt@redhat.com>

commit f7bc8b61f65726ff98f52e286b28e294499d7a08 upstream.

Enabling function tracer to trace all functions, then load a module and
then disable function tracing will cause ftrace to fail.

This can also happen by enabling function tracing on the command line:

  ftrace=function

and during boot up, modules are loaded, then you disable function tracing
with 'echo nop > current_tracer' you will trigger a bug in ftrace that
will shut itself down.

The reason is, the new ftrace code keeps ref counts of all ftrace_ops that
are registered for tracing. When one or more ftrace_ops are registered,
all the records that represent the functions that the ftrace_ops will
trace have a ref count incremented. If this ref count is not zero,
when the code modification runs, that function will be enabled for tracing.
If the ref count is zero, that function will be disabled from tracing.

To make sure the accounting was working, FTRACE_WARN_ON()s were added
to updating of the ref counts.

If the ref count hits its max (> 2^30 ftrace_ops added), or if
the ref count goes below zero, a FTRACE_WARN_ON() is triggered which
disables all modification of code.

Since it is common for ftrace_ops to trace all functions in the kernel,
instead of creating > 20,000 hash items for the ftrace_ops, the hash
count is just set to zero, and it represents that the ftrace_ops is
to trace all functions. This is where the issues arrise.

If you enable function tracing to trace all functions, and then add
a module, the modules function records do not get the ref count updated.
When the function tracer is disabled, all function records ref counts
are subtracted. Since the modules never had their ref counts incremented,
they go below zero and the FTRACE_WARN_ON() is triggered.

The solution to this is rather simple. When modules are loaded, and
their functions are added to the the ftrace pool, look to see if any
ftrace_ops are registered that trace all functions. And for those,
update the ref count for the module function records.

Reported-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

---
 kernel/trace/ftrace.c |   30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -1744,10 +1744,36 @@ static cycle_t		ftrace_update_time;
 static unsigned long	ftrace_update_cnt;
 unsigned long		ftrace_update_tot_cnt;
 
+static int ops_traces_mod(struct ftrace_ops *ops)
+{
+	struct ftrace_hash *hash;
+
+	hash = ops->filter_hash;
+	return !!(!hash || !hash->count);
+}
+
 static int ftrace_update_code(struct module *mod)
 {
 	struct dyn_ftrace *p;
 	cycle_t start, stop;
+	unsigned long ref = 0;
+
+	/*
+	 * When adding a module, we need to check if tracers are
+	 * currently enabled and if they are set to trace all functions.
+	 * If they are, we need to enable the module functions as well
+	 * as update the reference counts for those function records.
+	 */
+	if (mod) {
+		struct ftrace_ops *ops;
+
+		for (ops = ftrace_ops_list;
+		     ops != &ftrace_list_end; ops = ops->next) {
+			if (ops->flags & FTRACE_OPS_FL_ENABLED &&
+			    ops_traces_mod(ops))
+				ref++;
+		}
+	}
 
 	start = ftrace_now(raw_smp_processor_id());
 	ftrace_update_cnt = 0;
@@ -1760,7 +1786,7 @@ static int ftrace_update_code(struct mod
 
 		p = ftrace_new_addrs;
 		ftrace_new_addrs = p->newlist;
-		p->flags = 0L;
+		p->flags = ref;
 
 		/*
 		 * Do the initial record conversion from mcount jump
@@ -1783,7 +1809,7 @@ static int ftrace_update_code(struct mod
 		 * conversion puts the module to the correct state, thus
 		 * passing the ftrace_make_call check.
 		 */
-		if (ftrace_start_up) {
+		if (ftrace_start_up && ref) {
 			int failed = __ftrace_replace_code(p, 1);
 			if (failed) {
 				ftrace_bug(failed, p->ip);



  parent reply	other threads:[~2011-10-11 17:07 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-11 16:59 [00/38] 3.0.7-stable review Greg KH
2011-10-11 16:55 ` [01/38] PCI: Set PCI-E Max Payload Size on fabric Greg KH
2011-10-11 17:20   ` Benjamin LaHaise
2011-10-11 18:14     ` Bjorn Helgaas
2011-10-11 19:24       ` Greg KH
2011-10-11 19:47         ` Bjorn Helgaas
2011-10-11 19:56           ` Greg KH
2011-10-11 20:03             ` Benjamin LaHaise
2011-10-11 21:31               ` Greg KH
2011-10-11 20:22             ` Bjorn Helgaas
2011-10-11 21:32               ` Greg KH
2011-10-11 16:55 ` [02/38] PCI: export pcie_bus_configure_settings symbol Greg KH
2011-10-11 16:55 ` [03/38] PCI: Remove MRRS modification from MPS setting code Greg KH
2011-10-11 16:55 ` [04/38] pci: Dont crash when reading mpss from root complex Greg KH
2011-10-11 16:55 ` [05/38] Fix pointer dereference before call to pcie_bus_configure_settings Greg KH
2011-10-11 16:55 ` [06/38] PCI: Disable MPS configuration by default Greg KH
2011-10-11 16:55 ` [07/38] sparc64: Force the execute bit in OpenFirmwares translation entries Greg KH
2011-10-11 16:55 ` [08/38] sched/rt: Migrate equal priority tasks to available CPUs Greg KH
2011-10-11 16:55 ` [09/38] sched: Fix up wchan borkage Greg KH
2011-10-11 16:55 ` [10/38] ide-disk: Fix request requeuing Greg KH
2011-10-11 16:55 ` [11/38] posix-cpu-timers: Cure SMP wobbles Greg KH
2011-10-11 16:55 ` [12/38] lis3: fix regression of HP DriveGuard with 8bit chip Greg KH
2011-10-11 16:55 ` [13/38] ASoC: use a valid device for dev_err() in Zylonite Greg KH
2011-10-11 16:55 ` [14/38] ASoC: Fix setting update bits for WM8753_LADC and WM8753_RADC Greg KH
2011-10-11 16:55 ` [15/38] drm/radeon: Update AVIVO cursor coordinate origin before x/yorigin calculation Greg KH
2011-10-11 16:55 ` [16/38] drm/radeon/kms: Fix logic error in DP HPD handler Greg KH
2011-10-11 16:55 ` [17/38] drm/radeon/kms: fix regression in DP aux defer handling Greg KH
2011-10-11 16:55 ` [18/38] drm/radeon/kms: add retry limits for native DP aux defer Greg KH
2011-10-11 16:55 ` [19/38] drm/radeon/kms: fix channel_remap setup (v2) Greg KH
2011-10-11 16:55 ` [20/38] ptp: fix L2 event message recognition Greg KH
2011-10-11 16:55 ` [21/38] rt2x00: Serialize TX operations on a queue Greg KH
2011-10-11 16:55 ` [22/38] x86/PCI: use host bridge _CRS info on ASUS M2V-MX SE Greg KH
2011-10-11 16:55 ` [23/38] [SCSI] qla2xxx: Fix crash in qla2x00_abort_all_cmds() on unload Greg KH
2011-10-11 16:55 ` [24/38] [SCSI] libsas: fix panic when single phy is disabled on a wide port Greg KH
2011-10-11 16:55 ` [25/38] md: Avoid waking up a thread after it has been freed Greg KH
2011-10-11 16:55 ` [26/38] dm table: avoid crash if integrity profile changes Greg KH
2011-10-11 16:55 ` [27/38] mmc: mxs-mmc: fix clock rate setting Greg KH
2011-10-11 16:55 ` [28/38] exec: do not call request_module() twice from search_binary_handler() Greg KH
2011-10-11 16:55 ` [29/38] ARM: mach-ux500: enable fix for ARM errata 754322 Greg KH
2011-10-11 16:55 ` [30/38] drm/radeon/kms: retry aux transactions if there are status flags Greg KH
2011-10-11 16:55 ` [31/38] drm/radeon/kms: use hardcoded dig encoder to transmitter mapping for DCE4.1 Greg KH
2011-10-11 16:55 ` [32/38] ipv6: fix NULL dereference in udp6_ufo_fragment() Greg KH
2011-10-11 16:55 ` [33/38] ahci: Enable SB600 64bit DMA on Asus M3A Greg KH
2011-10-11 16:55 ` [34/38] MIPS: PM: Use struct syscore_ops instead of sysdevs for PM (v2) Greg KH
2011-10-11 16:55 ` [35/38] ftrace: Fix regression of :mod:module function enabling Greg KH
2011-10-11 16:55 ` Greg KH [this message]
2011-10-11 16:55 ` [37/38] ftrace: Fix warning when CONFIG_FUNCTION_TRACER is not defined Greg KH
2011-10-11 16:55 ` [38/38] e1000e: workaround for packet drop on 82579 at 100Mbps Greg KH
2011-10-11 17:00 ` [00/38] 3.0.7-stable review Greg KH
2011-10-17 15:05   ` Conny Seidel
2011-10-17 15:21     ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111011165713.842995901@pistachio.kroah.org \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=stable-review@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®