public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Steven Rostedt <rostedt@goodmis.org>
Subject: [ 040/104] tracing: Remove most or all of stack tracer stack size from stack_max_size
Date: Mon,  6 May 2013 16:11:59 -0700	[thread overview]
Message-ID: <20130506230047.734956546@linuxfoundation.org> (raw)
In-Reply-To: <20130506230043.526528358@linuxfoundation.org>

3.8-stable review patch.  If anyone has any objections, please let me know.

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

From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>

commit 4df297129f622bdc18935c856f42b9ddd18f9f28 upstream.

Currently, the depth reported in the stack tracer stack_trace file
does not match the stack_max_size file. This is because the stack_max_size
includes the overhead of stack tracer itself while the depth does not.

The first time a max is triggered, a calculation is not performed that
figures out the overhead of the stack tracer and subtracts it from
the stack_max_size variable. The overhead is stored and is subtracted
from the reported stack size for comparing for a new max.

Now the stack_max_size corresponds to the reported depth:

 # cat stack_max_size
4640

 # cat stack_trace
        Depth    Size   Location    (48 entries)
        -----    ----   --------
  0)     4640      32   _raw_spin_lock+0x18/0x24
  1)     4608     112   ____cache_alloc+0xb7/0x22d
  2)     4496      80   kmem_cache_alloc+0x63/0x12f
  3)     4416      16   mempool_alloc_slab+0x15/0x17
[...]

While testing against and older gcc on x86 that uses mcount instead
of fentry, I found that pasing in ip + MCOUNT_INSN_SIZE let the
stack trace show one more function deep which was missing before.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 kernel/trace/trace_stack.c |   75 ++++++++++++++++++++++++++++++++-------------
 1 file changed, 54 insertions(+), 21 deletions(-)

--- a/kernel/trace/trace_stack.c
+++ b/kernel/trace/trace_stack.c
@@ -20,27 +20,24 @@
 
 #define STACK_TRACE_ENTRIES 500
 
-/*
- * If fentry is used, then the function being traced will
- * jump to fentry directly before it sets up its stack frame.
- * We need to ignore that one and record the parent. Since
- * the stack frame for the traced function wasn't set up yet,
- * the stack_trace wont see the parent. That needs to be added
- * manually to stack_dump_trace[] as the first element.
- */
 #ifdef CC_USING_FENTRY
-# define add_func	1
+# define fentry		1
 #else
-# define add_func	0
+# define fentry		0
 #endif
 
 static unsigned long stack_dump_trace[STACK_TRACE_ENTRIES+1] =
 	 { [0 ... (STACK_TRACE_ENTRIES)] = ULONG_MAX };
 static unsigned stack_dump_index[STACK_TRACE_ENTRIES];
 
+/*
+ * Reserve one entry for the passed in ip. This will allow
+ * us to remove most or all of the stack size overhead
+ * added by the stack tracer itself.
+ */
 static struct stack_trace max_stack_trace = {
-	.max_entries		= STACK_TRACE_ENTRIES - add_func,
-	.entries		= &stack_dump_trace[add_func],
+	.max_entries		= STACK_TRACE_ENTRIES - 1,
+	.entries		= &stack_dump_trace[1],
 };
 
 static unsigned long max_stack_size;
@@ -58,10 +55,14 @@ check_stack(unsigned long ip, unsigned l
 {
 	unsigned long this_size, flags;
 	unsigned long *p, *top, *start;
+	static int tracer_frame;
+	int frame_size = ACCESS_ONCE(tracer_frame);
 	int i;
 
 	this_size = ((unsigned long)stack) & (THREAD_SIZE-1);
 	this_size = THREAD_SIZE - this_size;
+	/* Remove the frame of the tracer */
+	this_size -= frame_size;
 
 	if (this_size <= max_stack_size)
 		return;
@@ -73,6 +74,10 @@ check_stack(unsigned long ip, unsigned l
 	local_irq_save(flags);
 	arch_spin_lock(&max_stack_lock);
 
+	/* In case another CPU set the tracer_frame on us */
+	if (unlikely(!frame_size))
+		this_size -= tracer_frame;
+
 	/* a race could have already updated it */
 	if (this_size <= max_stack_size)
 		goto out;
@@ -85,15 +90,12 @@ check_stack(unsigned long ip, unsigned l
 	save_stack_trace(&max_stack_trace);
 
 	/*
-	 * When fentry is used, the traced function does not get
-	 * its stack frame set up, and we lose the parent.
-	 * Add that one in manally. We set up save_stack_trace()
-	 * to not touch the first element in this case.
+	 * Add the passed in ip from the function tracer.
+	 * Searching for this on the stack will skip over
+	 * most of the overhead from the stack tracer itself.
 	 */
-	if (add_func) {
-		stack_dump_trace[0] = ip;
-		max_stack_trace.nr_entries++;
-	}
+	stack_dump_trace[0] = ip;
+	max_stack_trace.nr_entries++;
 
 	/*
 	 * Now find where in the stack these are.
@@ -123,6 +125,18 @@ check_stack(unsigned long ip, unsigned l
 				found = 1;
 				/* Start the search from here */
 				start = p + 1;
+				/*
+				 * We do not want to show the overhead
+				 * of the stack tracer stack in the
+				 * max stack. If we haven't figured
+				 * out what that is, then figure it out
+				 * now.
+				 */
+				if (unlikely(!tracer_frame) && i == 1) {
+					tracer_frame = (p - stack) *
+						sizeof(unsigned long);
+					max_stack_size -= tracer_frame;
+				}
 			}
 		}
 
@@ -149,7 +163,26 @@ stack_trace_call(unsigned long ip, unsig
 	if (per_cpu(trace_active, cpu)++ != 0)
 		goto out;
 
-	check_stack(parent_ip, &stack);
+	/*
+	 * When fentry is used, the traced function does not get
+	 * its stack frame set up, and we lose the parent.
+	 * The ip is pretty useless because the function tracer
+	 * was called before that function set up its stack frame.
+	 * In this case, we use the parent ip.
+	 *
+	 * By adding the return address of either the parent ip
+	 * or the current ip we can disregard most of the stack usage
+	 * caused by the stack tracer itself.
+	 *
+	 * The function tracer always reports the address of where the
+	 * mcount call was, but the stack will hold the return address.
+	 */
+	if (fentry)
+		ip = parent_ip;
+	else
+		ip += MCOUNT_INSN_SIZE;
+
+	check_stack(ip, &stack);
 
  out:
 	per_cpu(trace_active, cpu)--;



  parent reply	other threads:[~2013-05-06 23:11 UTC|newest]

Thread overview: 106+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-06 23:11 [ 000/104] 3.8.12-stable review Greg Kroah-Hartman
2013-05-06 23:11 ` [ 001/104] USB: serial: option: Added support Olivetti Olicard 145 Greg Kroah-Hartman
2013-05-06 23:11 ` [ 002/104] USB: option: add a D-Link DWM-156 variant Greg Kroah-Hartman
2013-05-06 23:11 ` [ 003/104] staging: zsmalloc: Fix link error on ARM Greg Kroah-Hartman
2013-05-06 23:11 ` [ 004/104] ARM: omap3: cpuidle: enable time keeping Greg Kroah-Hartman
2013-05-06 23:11 ` [ 005/104] ARM: u300: fix ages old copy/paste bug Greg Kroah-Hartman
2013-05-06 23:11 ` [ 006/104] ARM: at91/at91sam9260.dtsi: fix u(s)art pinctrl encoding Greg Kroah-Hartman
2013-05-06 23:11 ` [ 007/104] ARM: at91: remove partial parameter in bootargs for at91sam9x5ek.dtsi Greg Kroah-Hartman
2013-05-06 23:11 ` [ 008/104] ARM: at91: Fix typo in restart code panic message Greg Kroah-Hartman
2013-05-06 23:11 ` [ 009/104] ARM: at91/trivial: fix model name for SAM9G15-EK Greg Kroah-Hartman
2013-05-06 23:11 ` [ 010/104] ARM: at91/trivial: typos in compatible property Greg Kroah-Hartman
2013-05-06 23:11 ` [ 011/104] powerpc: Add isync to copy_and_flush Greg Kroah-Hartman
2013-05-06 23:11 ` [ 012/104] powerpc: Fix hardware IRQs with MMU on exceptions when HV=0 Greg Kroah-Hartman
2013-05-06 23:11 ` [ 013/104] powerpc/power8: Fix secondary CPUs hanging on boot for HV=0 Greg Kroah-Hartman
2013-05-06 23:11 ` [ 014/104] powerpc/spufs: Initialise inode->i_ino in spufs_new_inode() Greg Kroah-Hartman
2013-05-06 23:11 ` [ 015/104] iwlwifi: fix freeing uninitialized pointer Greg Kroah-Hartman
2013-05-06 23:11 ` [ 016/104] iwlwifi: dvm: dont send zeroed LQ cmd Greg Kroah-Hartman
2013-05-06 23:11 ` [ 017/104] mwifiex: Use pci_release_region() instead of a pci_release_regions() Greg Kroah-Hartman
2013-05-06 23:11 ` [ 018/104] mwifiex: Call pci_release_region after calling pci_disable_device Greg Kroah-Hartman
2013-05-06 23:11 ` [ 019/104] mac80211: fix station entry leak/warning while suspending Greg Kroah-Hartman
2013-05-06 23:11 ` [ 020/104] usb/misc/appledisplay: Add 24" LED Cinema display Greg Kroah-Hartman
2013-05-06 23:11 ` [ 021/104] USB: add ftdi_sio USB ID for GDM Boost V1.x Greg Kroah-Hartman
2013-05-06 23:11 ` [ 022/104] USB: ftdi_sio: correct ST Micro Connect Lite PIDs Greg Kroah-Hartman
2013-05-06 23:11 ` [ 023/104] USB: ftdi_sio: enable two UART ports on ST Microconnect Lite Greg Kroah-Hartman
2013-05-06 23:11 ` [ 024/104] usbfs: Always allow ctrl requests with USB_RECIP_ENDPOINT on the ctrl ep Greg Kroah-Hartman
2013-05-06 23:11 ` [ 025/104] usb: chipidea: udc: fix memory access of shared memory on armv5 machines Greg Kroah-Hartman
2013-05-06 23:11 ` [ 026/104] usb: chipidea: udc: fix memory leak in _ep_nuke Greg Kroah-Hartman
2013-05-06 23:11 ` [ 027/104] usb: remove redundant tdi_reset Greg Kroah-Hartman
2013-05-06 23:11 ` [ 028/104] usb-storage: CY7C68300A chips do not support Cypress ATACB Greg Kroah-Hartman
2013-05-06 23:11 ` [ 029/104] s390/memory hotplug: prevent offline of active memory increments Greg Kroah-Hartman
2013-05-06 23:11 ` [ 030/104] xen/time: Fix kasprintf splat when allocating timer%d IRQ line Greg Kroah-Hartman
2013-05-06 23:11 ` [ 031/104] xen/smp: Fix leakage of timer interrupt line for every CPU online/offline Greg Kroah-Hartman
2013-05-06 23:11 ` [ 032/104] xen/smp/spinlock: Fix leakage of the spinlock " Greg Kroah-Hartman
2013-05-06 23:11 ` [ 033/104] serial_core.c: add put_device() after device_find_child() Greg Kroah-Hartman
2013-05-06 23:11 ` [ 034/104] arm: set the page table freeing ceiling to TASK_SIZE Greg Kroah-Hartman
2013-05-06 23:11 ` [ 035/104] gianfar: do not advertise any alarm capability Greg Kroah-Hartman
2013-05-06 23:11 ` [ 036/104] tty: fix up atime/mtime mess, take three Greg Kroah-Hartman
2013-05-06 23:11 ` [ 037/104] fbcon: when font is freed, clear also vc_font.data Greg Kroah-Hartman
2013-05-06 23:11 ` [ 038/104] tracing: Use stack of calling function for stack tracer Greg Kroah-Hartman
2013-05-06 23:11 ` [ 039/104] tracing: Fix stack tracer with fentry use Greg Kroah-Hartman
2013-05-06 23:11 ` Greg Kroah-Hartman [this message]
2013-05-06 23:12 ` [ 041/104] tracing: Fix off-by-one on allocating stat->pages Greg Kroah-Hartman
2013-05-06 23:12 ` [ 042/104] tracing: Check return value of tracing_init_dentry() Greg Kroah-Hartman
2013-05-06 23:12 ` [ 043/104] tracing: Reset ftrace_graph_filter_enabled if count is zero Greg Kroah-Hartman
2013-05-06 23:12 ` [ 044/104] i2c: xiic: must always write 16-bit words to TX_FIFO Greg Kroah-Hartman
2013-05-06 23:12 ` [ 045/104] crypto: crc32-pclmul - Use gas macro for pclmulqdq Greg Kroah-Hartman
2013-05-06 23:12 ` [ 046/104] sysfs: fix use after free in case of concurrent read/write and readdir Greg Kroah-Hartman
2013-05-06 23:12 ` [ 047/104] Fix initialization of CMCI/CMCP interrupts Greg Kroah-Hartman
2013-05-06 23:12 ` [ 048/104] PCI / ACPI: Dont query OSC support with all possible controls Greg Kroah-Hartman
2013-05-06 23:12 ` [ 049/104] PCI/PM: Fix fallback to PCI_D0 in pci_platform_power_transition() Greg Kroah-Hartman
2013-05-06 23:12 ` [ 050/104] rt2x00: Fix transmit power troubles on some Ralink RT30xx cards Greg Kroah-Hartman
2013-05-06 23:12 ` [ 051/104] Wrong asm register contraints in the futex implementation Greg Kroah-Hartman
2013-05-06 23:12 ` [ 052/104] Wrong asm register contraints in the kvm implementation Greg Kroah-Hartman
2013-05-06 23:12 ` [ 053/104] fs/fscache/stats.c: fix memory leak Greg Kroah-Hartman
2013-05-06 23:12 ` [ 054/104] mm: allow arch code to control the user page table ceiling Greg Kroah-Hartman
2013-05-06 23:12 ` [ 055/104] TPM: Retry SaveState command in suspend path Greg Kroah-Hartman
2013-05-06 23:12 ` [ 056/104] ALSA: emu10k1: Fix dock firmware loading Greg Kroah-Hartman
2013-05-06 23:12 ` [ 057/104] ALSA: snd-usb: try harder to find USB_DT_CS_ENDPOINT Greg Kroah-Hartman
2013-05-06 23:12 ` [ 058/104] ALSA: usb: Add quirk for 192KHz recording on E-Mu devices Greg Kroah-Hartman
2013-05-06 23:12 ` [ 059/104] ALSA: usb-audio: disable autopm for MIDI devices Greg Kroah-Hartman
2013-05-06 23:12 ` [ 060/104] ALSA: usb-audio: Fix autopm error during probing Greg Kroah-Hartman
2013-05-06 23:12 ` [ 061/104] ALSA: USB: adjust for changed 3.8 USB API Greg Kroah-Hartman
2013-05-06 23:12 ` [ 062/104] ALSA: hda - Add the support for ALC286 codec Greg Kroah-Hartman
2013-05-06 23:12 ` [ 063/104] ARM: 7702/1: Set the page table freeing ceiling to TASK_SIZE Greg Kroah-Hartman
2013-05-06 23:12 ` [ 064/104] ASoC: max98088: Fix logging of hardware revision Greg Kroah-Hartman
2013-05-06 23:12 ` [ 065/104] hrtimer: Fix ktime_add_ns() overflow on 32bit architectures Greg Kroah-Hartman
2013-05-06 23:12 ` [ 066/104] hrtimer: Add expiry time overflow check in hrtimer_interrupt Greg Kroah-Hartman
2013-05-06 23:12 ` [ 067/104] swap: redirty page if page write fails on swap file Greg Kroah-Hartman
2013-05-06 23:12 ` [ 068/104] mm: swap: mark swap pages writeback before queueing for direct IO Greg Kroah-Hartman
2013-05-06 23:12 ` [ 069/104] drivers/rtc/rtc-cmos.c: dont disable hpet emulation on suspend Greg Kroah-Hartman
2013-05-06 23:12 ` [ 070/104] libata: acpi: make ata_ap_acpi_handle not block Greg Kroah-Hartman
2013-05-06 23:12 ` [ 071/104] ACPI: Fix wrong parameter passed to memblock_reserve Greg Kroah-Hartman
2013-05-06 23:12 ` [ 072/104] ACPI / thermal: do not always return THERMAL_TREND_RAISING for active trip points Greg Kroah-Hartman
2013-05-06 23:12 ` [ 073/104] cgroup: fix an off-by-one bug which may trigger BUG_ON() Greg Kroah-Hartman
2013-05-06 23:12 ` [ 074/104] cgroup: fix broken file xattrs Greg Kroah-Hartman
2013-05-06 23:12 ` [ 075/104] localmodconfig: Process source kconfig files as they are found Greg Kroah-Hartman
2013-05-06 23:12 ` [ 076/104] clockevents: Set dummy handler on CPU_DEAD shutdown Greg Kroah-Hartman
2013-05-06 23:12 ` [ 077/104] sata_highbank: Rename proc_name to the module name Greg Kroah-Hartman
2013-05-06 23:12 ` [ 078/104] inotify: invalid mask should return a error number but not set it Greg Kroah-Hartman
2013-05-06 23:12 ` [ 079/104] fs/dcache.c: add cond_resched() to shrink_dcache_parent() Greg Kroah-Hartman
2013-05-06 23:12 ` [ 080/104] exec: do not abuse ->cred_guard_mutex in threadgroup_lock() Greg Kroah-Hartman
2013-05-06 23:12 ` [ 081/104] LOCKD: Ensure that nlmclnt_block resets block->b_status after a server reboot Greg Kroah-Hartman
2013-05-06 23:12 ` [ 082/104] md: bad block list should default to disabled Greg Kroah-Hartman
2013-05-06 23:12 ` [ 083/104] MD: ignore discard request for hard disks of hybid raid1/raid10 array Greg Kroah-Hartman
2013-05-06 23:12 ` [ 084/104] NFSv4: Handle NFS4ERR_DELAY and NFS4ERR_GRACE in nfs4_open_delegation_recall Greg Kroah-Hartman
2013-05-06 23:12 ` [ 085/104] nfsd4: dont close read-write opens too soon Greg Kroah-Hartman
2013-05-06 23:12 ` [ 086/104] nfsd: dont run get_file if nfs4_preprocess_stateid_op return error Greg Kroah-Hartman
2013-05-06 23:12 ` [ 087/104] nfsd: Decode and send 64bit time values Greg Kroah-Hartman
2013-05-06 23:12 ` [ 088/104] wireless: regulatory: fix channel disabling race condition Greg Kroah-Hartman
2013-05-06 23:12 ` [ 089/104] ipc: sysv shared memory limited to 8TiB Greg Kroah-Hartman
2013-05-06 23:12 ` [ 090/104] ixgbe: fix EICR write in ixgbe_msix_other Greg Kroah-Hartman
2013-05-06 23:12 ` [ 091/104] ext4/jbd2: dont wait (forever) for stale tid caused by wraparound Greg Kroah-Hartman
2013-05-06 23:12 ` [ 092/104] jbd2: fix race between jbd2_journal_remove_checkpoint and ->j_commit_callback Greg Kroah-Hartman
2013-05-06 23:12 ` [ 093/104] ext4: fix journal callback list traversal Greg Kroah-Hartman
2013-05-06 23:12 ` [ 094/104] ext4: fix big-endian bug in metadata checksum calculations Greg Kroah-Hartman
2013-05-06 23:12 ` [ 095/104] ext4: fix online resizing for ext3-compat file systems Greg Kroah-Hartman
2013-05-06 23:12 ` [ 096/104] ext4: fix Kconfig documentation for CONFIG_EXT4_DEBUG Greg Kroah-Hartman
2013-05-06 23:12 ` [ 097/104] mmc: at91/avr32/atmel-mci: fix DMA-channel leak on module unload Greg Kroah-Hartman
2013-05-06 23:12 ` [ 098/104] Give the OID registry file module info to avoid kernel tainting Greg Kroah-Hartman
2013-05-06 23:12 ` [ 099/104] KVM: X86 emulator: fix source operand decoding for 8bit mov[zs]x instructions Greg Kroah-Hartman
2013-05-06 23:12 ` [ 100/104] x86: Eliminate irq_mis_count counted in arch_irq_stat Greg Kroah-Hartman
2013-05-06 23:13 ` [ 101/104] mmc: core: Fix bit width test failing on old eMMC cards Greg Kroah-Hartman
2013-05-06 23:13 ` [ 102/104] mmc: atmel-mci: pio hang on block errors Greg Kroah-Hartman
2013-05-06 23:13 ` [ 103/104] rcutrace: single_open() leaks Greg Kroah-Hartman
2013-05-06 23:13 ` [ 104/104] mfd: adp5520: Restore mode bits on resume Greg Kroah-Hartman
     [not found] ` <CAKocOOPJ=hsX6zY=2tgE=VBNLruqg7Asmym2ia0ye4FZiS5fSw@mail.gmail.com>
2013-05-07 19:16   ` [ 000/104] 3.8.12-stable review Shuah Khan

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=20130506230047.734956546@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=stable@vger.kernel.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