From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Alexander Lam <azl@google.com>,
Steven Rostedt <rostedt@goodmis.org>
Subject: [ 101/103] tracing: Get trace_array ref counts when accessing trace files
Date: Tue, 23 Jul 2013 15:26:52 -0700 [thread overview]
Message-ID: <20130723220433.507987675@linuxfoundation.org> (raw)
In-Reply-To: <20130723220418.532514378@linuxfoundation.org>
3.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>
commit 7b85af63034818e43aee6c1d7bf1c7c6796a9073 upstream.
When a trace file is opened that may access a trace array, it must
increment its ref count to prevent it from being deleted.
Reported-by: Alexander Lam <azl@google.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
kernel/trace/trace.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 112 insertions(+), 9 deletions(-)
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2902,6 +2902,43 @@ int tracing_open_generic(struct inode *i
return 0;
}
+/*
+ * Open and update trace_array ref count.
+ * Must have the current trace_array passed to it.
+ */
+int tracing_open_generic_tr(struct inode *inode, struct file *filp)
+{
+ struct trace_array *tr = inode->i_private;
+
+ if (tracing_disabled)
+ return -ENODEV;
+
+ if (trace_array_get(tr) < 0)
+ return -ENODEV;
+
+ filp->private_data = inode->i_private;
+
+ return 0;
+
+}
+
+int tracing_open_generic_tc(struct inode *inode, struct file *filp)
+{
+ struct trace_cpu *tc = inode->i_private;
+ struct trace_array *tr = tc->tr;
+
+ if (tracing_disabled)
+ return -ENODEV;
+
+ if (trace_array_get(tr) < 0)
+ return -ENODEV;
+
+ filp->private_data = inode->i_private;
+
+ return 0;
+
+}
+
static int tracing_release(struct inode *inode, struct file *file)
{
struct seq_file *m = file->private_data;
@@ -2945,6 +2982,32 @@ static int tracing_release(struct inode
return 0;
}
+static int tracing_release_generic_tr(struct inode *inode, struct file *file)
+{
+ struct trace_array *tr = inode->i_private;
+
+ trace_array_put(tr);
+ return 0;
+}
+
+static int tracing_release_generic_tc(struct inode *inode, struct file *file)
+{
+ struct trace_cpu *tc = inode->i_private;
+ struct trace_array *tr = tc->tr;
+
+ trace_array_put(tr);
+ return 0;
+}
+
+static int tracing_single_release_tr(struct inode *inode, struct file *file)
+{
+ struct trace_array *tr = inode->i_private;
+
+ trace_array_put(tr);
+
+ return single_release(inode, file);
+}
+
static int tracing_open(struct inode *inode, struct file *file)
{
struct trace_cpu *tc = inode->i_private;
@@ -3331,9 +3394,14 @@ tracing_trace_options_write(struct file
static int tracing_trace_options_open(struct inode *inode, struct file *file)
{
+ struct trace_array *tr = inode->i_private;
+
if (tracing_disabled)
return -ENODEV;
+ if (trace_array_get(tr) < 0)
+ return -ENODEV;
+
return single_open(file, tracing_trace_options_show, inode->i_private);
}
@@ -3341,7 +3409,7 @@ static const struct file_operations trac
.open = tracing_trace_options_open,
.read = seq_read,
.llseek = seq_lseek,
- .release = single_release,
+ .release = tracing_single_release_tr,
.write = tracing_trace_options_write,
};
@@ -3829,6 +3897,9 @@ static int tracing_open_pipe(struct inod
if (tracing_disabled)
return -ENODEV;
+ if (trace_array_get(tr) < 0)
+ return -ENODEV;
+
mutex_lock(&trace_types_lock);
/* create a buffer to store the information to pass to userspace */
@@ -3881,6 +3952,7 @@ out:
fail:
kfree(iter->trace);
kfree(iter);
+ __trace_array_put(tr);
mutex_unlock(&trace_types_lock);
return ret;
}
@@ -3888,6 +3960,8 @@ fail:
static int tracing_release_pipe(struct inode *inode, struct file *file)
{
struct trace_iterator *iter = file->private_data;
+ struct trace_cpu *tc = inode->i_private;
+ struct trace_array *tr = tc->tr;
mutex_lock(&trace_types_lock);
@@ -3901,6 +3975,8 @@ static int tracing_release_pipe(struct i
kfree(iter->trace);
kfree(iter);
+ trace_array_put(tr);
+
return 0;
}
@@ -4358,6 +4434,8 @@ tracing_free_buffer_release(struct inode
/* resize the ring buffer to 0 */
tracing_resize_ring_buffer(tr, 0, RING_BUFFER_ALL_CPUS);
+ trace_array_put(tr);
+
return 0;
}
@@ -4534,10 +4612,20 @@ static ssize_t tracing_clock_write(struc
static int tracing_clock_open(struct inode *inode, struct file *file)
{
+ struct trace_array *tr = inode->i_private;
+ int ret;
+
if (tracing_disabled)
return -ENODEV;
- return single_open(file, tracing_clock_show, inode->i_private);
+ if (trace_array_get(tr))
+ return -ENODEV;
+
+ ret = single_open(file, tracing_clock_show, inode->i_private);
+ if (ret < 0)
+ trace_array_put(tr);
+
+ return ret;
}
struct ftrace_buffer_info {
@@ -4733,34 +4821,38 @@ static const struct file_operations trac
};
static const struct file_operations tracing_entries_fops = {
- .open = tracing_open_generic,
+ .open = tracing_open_generic_tc,
.read = tracing_entries_read,
.write = tracing_entries_write,
.llseek = generic_file_llseek,
+ .release = tracing_release_generic_tc,
};
static const struct file_operations tracing_total_entries_fops = {
- .open = tracing_open_generic,
+ .open = tracing_open_generic_tr,
.read = tracing_total_entries_read,
.llseek = generic_file_llseek,
+ .release = tracing_release_generic_tr,
};
static const struct file_operations tracing_free_buffer_fops = {
+ .open = tracing_open_generic_tr,
.write = tracing_free_buffer_write,
.release = tracing_free_buffer_release,
};
static const struct file_operations tracing_mark_fops = {
- .open = tracing_open_generic,
+ .open = tracing_open_generic_tr,
.write = tracing_mark_write,
.llseek = generic_file_llseek,
+ .release = tracing_release_generic_tr,
};
static const struct file_operations trace_clock_fops = {
.open = tracing_clock_open,
.read = seq_read,
.llseek = seq_lseek,
- .release = single_release,
+ .release = tracing_single_release_tr,
.write = tracing_clock_write,
};
@@ -4788,13 +4880,19 @@ static int tracing_buffers_open(struct i
struct trace_cpu *tc = inode->i_private;
struct trace_array *tr = tc->tr;
struct ftrace_buffer_info *info;
+ int ret;
if (tracing_disabled)
return -ENODEV;
+ if (trace_array_get(tr) < 0)
+ return -ENODEV;
+
info = kzalloc(sizeof(*info), GFP_KERNEL);
- if (!info)
+ if (!info) {
+ trace_array_put(tr);
return -ENOMEM;
+ }
mutex_lock(&trace_types_lock);
@@ -4812,7 +4910,11 @@ static int tracing_buffers_open(struct i
mutex_unlock(&trace_types_lock);
- return nonseekable_open(inode, filp);
+ ret = nonseekable_open(inode, filp);
+ if (ret < 0)
+ trace_array_put(tr);
+
+ return ret;
}
static unsigned int
@@ -5707,9 +5809,10 @@ rb_simple_write(struct file *filp, const
}
static const struct file_operations rb_simple_fops = {
- .open = tracing_open_generic,
+ .open = tracing_open_generic_tr,
.read = rb_simple_read,
.write = rb_simple_write,
+ .release = tracing_release_generic_tr,
.llseek = default_llseek,
};
next prev parent reply other threads:[~2013-07-23 22:26 UTC|newest]
Thread overview: 119+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-23 22:25 [ 000/103] 3.10.3-stable review Greg Kroah-Hartman
2013-07-23 22:25 ` [ 001/103] powerpc/hw_brk: Fix setting of length for exact mode breakpoints Greg Kroah-Hartman
2013-07-23 22:25 ` [ 002/103] powerpc/hw_brk: Fix clearing of extraneous IRQ Greg Kroah-Hartman
2013-07-23 22:25 ` [ 003/103] powerpc/hw_brk: Fix off by one error when validating DAWR region end Greg Kroah-Hartman
2013-07-23 22:25 ` [ 004/103] powerpc/powernv: Fix iommu initialization again Greg Kroah-Hartman
2013-07-23 22:25 ` [ 005/103] powerpc/tm: Fix writing top half of MSR on 32 bit signals Greg Kroah-Hartman
2013-07-23 22:25 ` [ 006/103] powerpc/tm: Fix 32 bit non-rt signals Greg Kroah-Hartman
2013-07-23 22:25 ` [ 007/103] powerpc/tm: Fix restoration of MSR on 32bit signal return Greg Kroah-Hartman
2013-07-23 22:25 ` [ 008/103] powerpc/tm: Fix return of 32bit rt signals to active transactions Greg Kroah-Hartman
2013-07-23 22:25 ` [ 009/103] powerpc/tm: Fix return of active 64bit signals Greg Kroah-Hartman
2013-07-23 22:25 ` [ 010/103] powerpc: Remove unreachable relocation on exception handlers Greg Kroah-Hartman
2013-07-23 22:25 ` [ 011/103] powerpc: Remove KVMTEST from RELON " Greg Kroah-Hartman
2013-07-23 22:25 ` [ 012/103] powerpc: Rename and flesh out the facility unavailable exception handler Greg Kroah-Hartman
2013-07-23 22:25 ` [ 013/103] powerpc: Wire up the HV facility unavailable exception Greg Kroah-Hartman
2013-07-23 22:25 ` [ 014/103] powerpc/smp: Section mismatch from smp_release_cpus to __initdata spinning_secondaries Greg Kroah-Hartman
2013-07-23 22:25 ` [ 015/103] powerpc/numa: Do not update sysfs cpu registration from invalid context Greg Kroah-Hartman
2013-07-23 22:25 ` [ 016/103] powerpc/perf: Check that events only include valid bits on Power8 Greg Kroah-Hartman
2013-07-23 22:25 ` [ 017/103] powerpc/perf: Rework disable logic in pmu_disable() Greg Kroah-Hartman
2013-07-23 22:25 ` [ 018/103] powerpc/perf: Freeze PMC5/6 if were not using them Greg Kroah-Hartman
2013-07-23 22:25 ` [ 019/103] powerpc/perf: Use existing out label in power_pmu_enable() Greg Kroah-Hartman
2013-07-23 22:25 ` [ 020/103] powerpc/perf: Dont enable if we have zero events Greg Kroah-Hartman
2013-07-23 22:25 ` [ 021/103] cpufreq: Revert commit a66b2e to fix suspend/resume regression Greg Kroah-Hartman
2013-07-23 22:25 ` [ 022/103] cpufreq: Revert commit 2f7021a8 to fix CPU hotplug regression Greg Kroah-Hartman
2013-07-23 22:25 ` [ 023/103] arm64: mm: dont treat user cache maintenance faults as writes Greg Kroah-Hartman
2013-07-23 22:25 ` [ 024/103] iio: Fix iio_channel_has_info Greg Kroah-Hartman
2013-07-23 22:25 ` [ 025/103] iio: inkern: fix iio_convert_raw_to_processed_unlocked Greg Kroah-Hartman
2013-07-23 22:25 ` [ 026/103] ALSA: hda - Fix EAPD vmaster hook for AD1884 & co Greg Kroah-Hartman
2013-07-23 22:25 ` [ 027/103] ALSA: hda - Fix return value of snd_hda_check_power_state() Greg Kroah-Hartman
2013-07-23 22:25 ` [ 028/103] ALSA: hda - Cache the MUX selection for generic HDMI Greg Kroah-Hartman
2013-07-23 22:25 ` [ 029/103] ALSA: hda - Fix missing Mic Boost controls for VIA codecs Greg Kroah-Hartman
2013-07-23 22:25 ` [ 030/103] ALSA: hda - Fix the max length of control name in generic parser Greg Kroah-Hartman
2013-07-23 22:25 ` [ 031/103] ALSA: hda - Add new GPU codec ID to snd-hda Greg Kroah-Hartman
2013-07-23 22:25 ` [ 032/103] ALSA: seq-oss: Initialize MIDI clients asynchronously Greg Kroah-Hartman
2013-07-23 22:25 ` [ 033/103] ALSA: 6fire: Fix unlocked snd_pcm_stop() call Greg Kroah-Hartman
2013-07-23 22:25 ` [ 034/103] ALSA: ua101: " Greg Kroah-Hartman
2013-07-23 22:25 ` [ 035/103] ALSA: pxa2xx: " Greg Kroah-Hartman
2013-07-23 22:25 ` [ 036/103] ALSA: atiixp: " Greg Kroah-Hartman
2013-07-23 22:25 ` [ 037/103] ALSA: asihpi: " Greg Kroah-Hartman
2013-07-23 22:25 ` [ 038/103] ALSA: usx2y: " Greg Kroah-Hartman
2013-07-23 22:25 ` [ 039/103] hwmon: (nct6775) Fix temperature alarm attributes Greg Kroah-Hartman
2013-07-23 22:25 ` [ 040/103] hwmon: (nct6775) Drop unsupported fan alarm attributes for NCT6775 Greg Kroah-Hartman
2013-07-23 22:25 ` [ 041/103] libata-zpodd: must use ata_tf_init() Greg Kroah-Hartman
2013-07-23 22:25 ` [ 042/103] libata: skip SRST for all SIMG [34]7x port-multipliers Greg Kroah-Hartman
2013-07-23 22:25 ` [ 043/103] ata_piix: IDE-mode SATA patch for Intel Coleto Creek DeviceIDs Greg Kroah-Hartman
2013-07-23 22:25 ` [ 044/103] sata_highbank: increase retry count but shorten duration for Calxeda controller Greg Kroah-Hartman
2013-07-23 22:25 ` [ 045/103] i2c-piix4: Add AMD CZ SMBus device ID Greg Kroah-Hartman
2013-07-23 22:25 ` [ 046/103] ASoC: s6000: Fix unlocked snd_pcm_stop() call Greg Kroah-Hartman
2013-07-23 22:25 ` [ 047/103] ASoC: atmel: " Greg Kroah-Hartman
2013-07-23 22:25 ` [ 048/103] ASoC: sglt5000: Fix SGTL5000_PLL_FRAC_DIV_MASK Greg Kroah-Hartman
2013-07-23 22:26 ` [ 049/103] md/raid10: fix bug which causes all RAID10 reshapes to move no data Greg Kroah-Hartman
2013-07-23 22:26 ` [ 050/103] md/raid10: fix two bugs affecting RAID10 reshape Greg Kroah-Hartman
2013-07-23 22:26 ` [ 051/103] md/raid10: fix two problems with RAID10 resync Greg Kroah-Hartman
2013-07-23 22:26 ` [ 052/103] tick: Sanitize broadcast control logic Greg Kroah-Hartman
2013-07-23 22:26 ` [ 053/103] tick: Prevent uncontrolled switch to oneshot mode Greg Kroah-Hartman
2013-07-23 22:26 ` [ 054/103] clocksource: dw_apb: Fix error check Greg Kroah-Hartman
2013-07-23 22:26 ` [ 055/103] rt2x00: read 5GHz TX power values from the correct offset Greg Kroah-Hartman
2013-07-23 22:26 ` [ 056/103] rt2x00: rt2800lib: fix default TX power check for RT55xx Greg Kroah-Hartman
2013-07-23 22:26 ` [ 057/103] ath9k_hw: Assign default xlna config for AR9485 Greg Kroah-Hartman
2013-07-23 22:26 ` [ 058/103] ath9k: Fix noisefloor calibration Greg Kroah-Hartman
2013-07-23 22:26 ` [ 059/103] ath9k: Do not assign noise for NULL caldata Greg Kroah-Hartman
2013-07-23 22:26 ` [ 060/103] SCSI: sd: Update WRITE SAME heuristics Greg Kroah-Hartman
2013-07-23 22:26 ` [ 061/103] SCSI: aacraid: Fix for arrays are going offline in the system. System hangs Greg Kroah-Hartman
2013-07-23 22:26 ` [ 062/103] SCSI: zfcp: fix adapter (re)open recovery while link to SAN is down Greg Kroah-Hartman
2013-07-23 22:26 ` [ 063/103] SCSI: zfcp: block queue limits with data router Greg Kroah-Hartman
2013-07-23 22:26 ` [ 064/103] SCSI: zfcp: status read buffers on first adapter open with link down Greg Kroah-Hartman
2013-07-23 22:26 ` [ 065/103] SCSI: mpt2sas: fix firmware failure with wrong task attribute Greg Kroah-Hartman
2013-07-23 22:26 ` [ 066/103] SCSI: mpt2sas: Fix for issue Missing delay not getting set during system bootup Greg Kroah-Hartman
2013-07-23 22:26 ` [ 067/103] SUNRPC: fix races on PipeFS MOUNT notifications Greg Kroah-Hartman
2013-07-23 22:26 ` [ 068/103] SUNRPC: fix races on PipeFS UMOUNT notifications Greg Kroah-Hartman
2013-07-23 22:30 ` Myklebust, Trond
2013-07-23 22:50 ` Greg Kroah-Hartman
2013-07-23 22:26 ` [ 069/103] virtio_balloon: leak_balloon(): only tell host if we got pages deflated Greg Kroah-Hartman
2013-07-23 22:26 ` [ 070/103] b43: ensue that BCMA is "y" when B43 is "y" Greg Kroah-Hartman
2013-07-23 22:26 ` [ 071/103] mac80211: close AP_VLAN interfaces before unregistering all Greg Kroah-Hartman
2013-07-23 22:26 ` [ 072/103] printk: Fix rq->lock vs logbuf_lock unlock lock inversion Greg Kroah-Hartman
2013-07-23 22:26 ` [ 073/103] uprobes: Fix return value in error handling path Greg Kroah-Hartman
2013-07-23 22:26 ` [ 074/103] svcrpc: fix failures to handle -1 uids Greg Kroah-Hartman
2013-07-23 22:26 ` [ 075/103] svcrpc: fix handling of too-short rpcs Greg Kroah-Hartman
2013-07-23 22:26 ` [ 076/103] svcrpc: dont error out on small tcp fragment Greg Kroah-Hartman
2013-07-23 22:26 ` [ 077/103] of: Fix address decoding on Bimini and js2x machines Greg Kroah-Hartman
2013-07-23 22:26 ` [ 078/103] drm/i915: Fix up sdvo hpd pins for i965g/gm Greg Kroah-Hartman
2013-07-23 22:26 ` [ 079/103] drm/i915: Fix context sizes on HSW Greg Kroah-Hartman
2013-07-23 22:26 ` [ 080/103] drm/i915: Only clear write-domains after a successful wait-seqno Greg Kroah-Hartman
2013-07-23 22:26 ` [ 081/103] drm/gem: fix not to assign error value to gem name Greg Kroah-Hartman
2013-07-23 22:26 ` [ 082/103] drm/mgag200: Added resolution and bandwidth limits for various G200e products Greg Kroah-Hartman
2013-07-23 22:26 ` [ 083/103] drm/nouveau: use vmalloc for pgt allocation Greg Kroah-Hartman
2013-07-23 22:26 ` [ 084/103] drm/radeon: fix AVI infoframe generation Greg Kroah-Hartman
2013-07-23 22:26 ` [ 085/103] drm/radeon: add backlight quirk for hybrid mac Greg Kroah-Hartman
2013-07-23 22:26 ` [ 086/103] drm/nva3/disp: Fix HDMI audio regression Greg Kroah-Hartman
2013-07-23 22:26 ` [ 087/103] drm/nv50-/disp: Use output specific mask in interrupt Greg Kroah-Hartman
2013-07-23 22:26 ` [ 088/103] iommu/amd: Only unmap large pages from the first pte Greg Kroah-Hartman
2013-07-23 22:26 ` [ 089/103] xtensa: adjust boot parameters address when INITIALIZE_XTENSA_MMU_INSIDE_VMLINUX is selected Greg Kroah-Hartman
2013-07-23 22:26 ` [ 090/103] thermal: cpu_cooling: fix stub function Greg Kroah-Hartman
2013-07-23 22:26 ` [ 091/103] MIPS: Octeon: Dont clobber bootloader data structures Greg Kroah-Hartman
2013-07-23 22:26 ` [ 092/103] staging: line6: Fix unlocked snd_pcm_stop() call Greg Kroah-Hartman
2013-07-23 22:26 ` [ 093/103] perf: Clone child context from parent context pmu Greg Kroah-Hartman
2013-07-23 22:26 ` [ 094/103] perf: Remove WARN_ON_ONCE() check in __perf_event_enable() for valid scenario Greg Kroah-Hartman
2013-07-23 22:26 ` [ 095/103] perf: Fix perf_lock_task_context() vs RCU Greg Kroah-Hartman
2013-07-23 22:26 ` [ 096/103] tracing: Failed to create system directory Greg Kroah-Hartman
2013-07-23 22:26 ` [ 097/103] tracing: Fix irqs-off tag display in syscall tracing Greg Kroah-Hartman
2013-07-23 22:26 ` [ 098/103] tracing: Make trace_marker use the correct per-instance buffer Greg Kroah-Hartman
2013-07-23 22:26 ` [ 099/103] tracing: Protect ftrace_trace_arrays list in trace_events.c Greg Kroah-Hartman
2013-07-23 22:26 ` [ 100/103] tracing: Add trace_array_get/put() to handle instance refs better Greg Kroah-Hartman
2013-07-23 22:26 ` Greg Kroah-Hartman [this message]
2013-07-23 22:26 ` [ 102/103] tracing: Fix race between deleting buffer and setting events Greg Kroah-Hartman
2013-07-23 22:26 ` [ 103/103] tracing: Add trace_array_get/put() to event handling Greg Kroah-Hartman
[not found] ` <CAKocOOPO61YUj5kTL7k1HuEeDdB_x=sxWga007nBSiLD4Px5Mg@mail.gmail.com>
2013-07-24 13:40 ` [ 000/103] 3.10.3-stable review Shuah Khan
2013-07-24 14:55 ` gregkh@linuxfoundation.org >> "Kroah-Hartman, Greg"
2013-07-24 17:04 ` Linus Torvalds
2013-07-24 17:15 ` Willy Tarreau
2013-07-24 17:16 ` Steven Rostedt
2013-07-24 17:24 ` Linus Torvalds
2013-07-24 17:46 ` Steven Rostedt
2013-07-24 17:52 ` gregkh@linuxfoundation.org >> Kroah-Hartman, Greg
2013-07-24 18:05 ` Steven Rostedt
2013-07-25 9:52 ` Geert Uytterhoeven
2013-07-25 12:47 ` Steven Rostedt
2013-07-25 3:10 ` linux
2013-07-25 4:20 ` Greg Kroah-Hartman
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=20130723220433.507987675@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=azl@google.com \
--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;
as well as URLs for NNTP newsgroup(s).