License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2008-08-28 03:31:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Steven Rostedt <srostedt@redhat.com>
|
|
|
|
*
|
|
|
|
*/
|
2017-02-08 17:51:37 +00:00
|
|
|
#include <linux/sched/task_stack.h>
|
2008-08-28 03:31:01 +00:00
|
|
|
#include <linux/stacktrace.h>
|
2019-10-11 21:22:50 +00:00
|
|
|
#include <linux/security.h>
|
2008-08-28 03:31:01 +00:00
|
|
|
#include <linux/kallsyms.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <linux/ftrace.h>
|
|
|
|
#include <linux/module.h>
|
2008-12-17 04:06:40 +00:00
|
|
|
#include <linux/sysctl.h>
|
2008-08-28 03:31:01 +00:00
|
|
|
#include <linux/init.h>
|
2011-12-20 03:01:00 +00:00
|
|
|
|
|
|
|
#include <asm/setup.h>
|
|
|
|
|
2008-08-28 03:31:01 +00:00
|
|
|
#include "trace.h"
|
|
|
|
|
2019-04-25 09:44:54 +00:00
|
|
|
#define STACK_TRACE_ENTRIES 500
|
|
|
|
|
|
|
|
static unsigned long stack_dump_trace[STACK_TRACE_ENTRIES];
|
|
|
|
static unsigned stack_trace_index[STACK_TRACE_ENTRIES];
|
2008-08-29 20:51:43 +00:00
|
|
|
|
2019-04-25 09:45:17 +00:00
|
|
|
static unsigned int stack_trace_nr_entries;
|
2019-04-25 09:44:54 +00:00
|
|
|
static unsigned long stack_trace_max_size;
|
|
|
|
static arch_spinlock_t stack_trace_max_lock =
|
2009-12-03 11:38:57 +00:00
|
|
|
(arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED;
|
2008-08-28 03:31:01 +00:00
|
|
|
|
2017-04-06 19:47:32 +00:00
|
|
|
DEFINE_PER_CPU(int, disable_stack_tracer);
|
2008-12-17 04:06:40 +00:00
|
|
|
static DEFINE_MUTEX(stack_sysctl_mutex);
|
|
|
|
|
|
|
|
int stack_tracer_enabled;
|
2008-08-28 03:31:01 +00:00
|
|
|
|
2019-04-25 09:44:54 +00:00
|
|
|
static void print_max_stack(void)
|
2014-06-02 04:33:12 +00:00
|
|
|
{
|
|
|
|
long i;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
pr_emerg(" Depth Size Location (%d entries)\n"
|
|
|
|
" ----- ---- --------\n",
|
2019-04-25 09:45:17 +00:00
|
|
|
stack_trace_nr_entries);
|
2014-06-02 04:33:12 +00:00
|
|
|
|
2019-04-25 09:45:17 +00:00
|
|
|
for (i = 0; i < stack_trace_nr_entries; i++) {
|
|
|
|
if (i + 1 == stack_trace_nr_entries)
|
2015-10-30 05:25:39 +00:00
|
|
|
size = stack_trace_index[i];
|
2014-06-02 04:33:12 +00:00
|
|
|
else
|
2015-10-30 05:25:39 +00:00
|
|
|
size = stack_trace_index[i] - stack_trace_index[i+1];
|
2014-06-02 04:33:12 +00:00
|
|
|
|
2015-10-30 05:25:39 +00:00
|
|
|
pr_emerg("%3ld) %8d %5d %pS\n", i, stack_trace_index[i],
|
2014-06-02 04:33:12 +00:00
|
|
|
size, (void *)stack_dump_trace[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-07 16:27:30 +00:00
|
|
|
/*
|
|
|
|
* The stack tracer looks for a maximum stack at each call from a function. It
|
|
|
|
* registers a callback from ftrace, and in that callback it examines the stack
|
|
|
|
* size. It determines the stack size from the variable passed in, which is the
|
|
|
|
* address of a local variable in the stack_trace_call() callback function.
|
|
|
|
* The stack size is calculated by the address of the local variable to the top
|
|
|
|
* of the current stack. If that size is smaller than the currently saved max
|
|
|
|
* stack size, nothing more is done.
|
|
|
|
*
|
|
|
|
* If the size of the stack is greater than the maximum recorded size, then the
|
|
|
|
* following algorithm takes place.
|
|
|
|
*
|
|
|
|
* For architectures (like x86) that store the function's return address before
|
|
|
|
* saving the function's local variables, the stack will look something like
|
|
|
|
* this:
|
|
|
|
*
|
|
|
|
* [ top of stack ]
|
|
|
|
* 0: sys call entry frame
|
|
|
|
* 10: return addr to entry code
|
|
|
|
* 11: start of sys_foo frame
|
|
|
|
* 20: return addr to sys_foo
|
|
|
|
* 21: start of kernel_func_bar frame
|
|
|
|
* 30: return addr to kernel_func_bar
|
|
|
|
* 31: [ do trace stack here ]
|
|
|
|
*
|
|
|
|
* The save_stack_trace() is called returning all the functions it finds in the
|
|
|
|
* current stack. Which would be (from the bottom of the stack to the top):
|
|
|
|
*
|
|
|
|
* return addr to kernel_func_bar
|
|
|
|
* return addr to sys_foo
|
|
|
|
* return addr to entry code
|
|
|
|
*
|
|
|
|
* Now to figure out how much each of these functions' local variable size is,
|
|
|
|
* a search of the stack is made to find these values. When a match is made, it
|
|
|
|
* is added to the stack_dump_trace[] array. The offset into the stack is saved
|
|
|
|
* in the stack_trace_index[] array. The above example would show:
|
|
|
|
*
|
|
|
|
* stack_dump_trace[] | stack_trace_index[]
|
|
|
|
* ------------------ + -------------------
|
|
|
|
* return addr to kernel_func_bar | 30
|
|
|
|
* return addr to sys_foo | 20
|
|
|
|
* return addr to entry | 10
|
|
|
|
*
|
|
|
|
* The print_max_stack() function above, uses these values to print the size of
|
|
|
|
* each function's portion of the stack.
|
|
|
|
*
|
|
|
|
* for (i = 0; i < nr_entries; i++) {
|
|
|
|
* size = i == nr_entries - 1 ? stack_trace_index[i] :
|
|
|
|
* stack_trace_index[i] - stack_trace_index[i+1]
|
|
|
|
* print "%d %d %d %s\n", i, stack_trace_index[i], size, stack_dump_trace[i]);
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* The above shows
|
|
|
|
*
|
|
|
|
* depth size location
|
|
|
|
* ----- ---- --------
|
|
|
|
* 0 30 10 kernel_func_bar
|
|
|
|
* 1 20 10 sys_foo
|
|
|
|
* 2 10 10 entry code
|
|
|
|
*
|
|
|
|
* Now for architectures that might save the return address after the functions
|
|
|
|
* local variables (saving the link register before calling nested functions),
|
|
|
|
* this will cause the stack to look a little different:
|
|
|
|
*
|
|
|
|
* [ top of stack ]
|
|
|
|
* 0: sys call entry frame
|
|
|
|
* 10: start of sys_foo_frame
|
|
|
|
* 19: return addr to entry code << lr saved before calling kernel_func_bar
|
|
|
|
* 20: start of kernel_func_bar frame
|
|
|
|
* 29: return addr to sys_foo_frame << lr saved before calling next function
|
|
|
|
* 30: [ do trace stack here ]
|
|
|
|
*
|
|
|
|
* Although the functions returned by save_stack_trace() may be the same, the
|
|
|
|
* placement in the stack will be different. Using the same algorithm as above
|
|
|
|
* would yield:
|
|
|
|
*
|
|
|
|
* stack_dump_trace[] | stack_trace_index[]
|
|
|
|
* ------------------ + -------------------
|
|
|
|
* return addr to kernel_func_bar | 30
|
|
|
|
* return addr to sys_foo | 29
|
|
|
|
* return addr to entry | 19
|
|
|
|
*
|
|
|
|
* Where the mapping is off by one:
|
|
|
|
*
|
|
|
|
* kernel_func_bar stack frame size is 29 - 19 not 30 - 29!
|
|
|
|
*
|
|
|
|
* To fix this, if the architecture sets ARCH_RET_ADDR_AFTER_LOCAL_VARS the
|
|
|
|
* values in stack_trace_index[] are shifted by one to and the number of
|
|
|
|
* stack trace entries is decremented by one.
|
|
|
|
*
|
|
|
|
* stack_dump_trace[] | stack_trace_index[]
|
|
|
|
* ------------------ + -------------------
|
|
|
|
* return addr to kernel_func_bar | 29
|
|
|
|
* return addr to sys_foo | 19
|
|
|
|
*
|
|
|
|
* Although the entry function is not displayed, the first function (sys_foo)
|
|
|
|
* will still include the stack size of it.
|
|
|
|
*/
|
2019-04-25 09:44:54 +00:00
|
|
|
static void check_stack(unsigned long ip, unsigned long *stack)
|
2008-08-28 03:31:01 +00:00
|
|
|
{
|
2014-06-02 04:33:12 +00:00
|
|
|
unsigned long this_size, flags; unsigned long *p, *top, *start;
|
2013-03-14 03:34:22 +00:00
|
|
|
static int tracer_frame;
|
locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns to READ_ONCE()/WRITE_ONCE()
Please do not apply this to mainline directly, instead please re-run the
coccinelle script shown below and apply its output.
For several reasons, it is desirable to use {READ,WRITE}_ONCE() in
preference to ACCESS_ONCE(), and new code is expected to use one of the
former. So far, there's been no reason to change most existing uses of
ACCESS_ONCE(), as these aren't harmful, and changing them results in
churn.
However, for some features, the read/write distinction is critical to
correct operation. To distinguish these cases, separate read/write
accessors must be used. This patch migrates (most) remaining
ACCESS_ONCE() instances to {READ,WRITE}_ONCE(), using the following
coccinelle script:
----
// Convert trivial ACCESS_ONCE() uses to equivalent READ_ONCE() and
// WRITE_ONCE()
// $ make coccicheck COCCI=/home/mark/once.cocci SPFLAGS="--include-headers" MODE=patch
virtual patch
@ depends on patch @
expression E1, E2;
@@
- ACCESS_ONCE(E1) = E2
+ WRITE_ONCE(E1, E2)
@ depends on patch @
expression E;
@@
- ACCESS_ONCE(E)
+ READ_ONCE(E)
----
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: davem@davemloft.net
Cc: linux-arch@vger.kernel.org
Cc: mpe@ellerman.id.au
Cc: shuah@kernel.org
Cc: snitzer@redhat.com
Cc: thor.thayer@linux.intel.com
Cc: tj@kernel.org
Cc: viro@zeniv.linux.org.uk
Cc: will.deacon@arm.com
Link: http://lkml.kernel.org/r/1508792849-3115-19-git-send-email-paulmck@linux.vnet.ibm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-10-23 21:07:29 +00:00
|
|
|
int frame_size = READ_ONCE(tracer_frame);
|
2015-07-16 17:24:54 +00:00
|
|
|
int i, x;
|
2008-08-28 03:31:01 +00:00
|
|
|
|
2013-03-14 00:43:57 +00:00
|
|
|
this_size = ((unsigned long)stack) & (THREAD_SIZE-1);
|
2008-08-28 03:31:01 +00:00
|
|
|
this_size = THREAD_SIZE - this_size;
|
2013-03-14 03:34:22 +00:00
|
|
|
/* Remove the frame of the tracer */
|
|
|
|
this_size -= frame_size;
|
2008-08-28 03:31:01 +00:00
|
|
|
|
2015-10-30 05:25:39 +00:00
|
|
|
if (this_size <= stack_trace_max_size)
|
2008-08-28 03:31:01 +00:00
|
|
|
return;
|
|
|
|
|
2008-10-07 01:24:18 +00:00
|
|
|
/* we do not handle interrupt stacks yet */
|
2013-03-14 00:43:57 +00:00
|
|
|
if (!object_is_on_stack(stack))
|
2008-10-07 01:24:18 +00:00
|
|
|
return;
|
|
|
|
|
2015-10-21 01:48:02 +00:00
|
|
|
/* Can't do this from NMI context (can cause deadlocks) */
|
|
|
|
if (in_nmi())
|
|
|
|
return;
|
|
|
|
|
2008-12-02 20:34:05 +00:00
|
|
|
local_irq_save(flags);
|
2015-11-03 19:50:15 +00:00
|
|
|
arch_spin_lock(&stack_trace_max_lock);
|
2008-08-28 03:31:01 +00:00
|
|
|
|
2013-03-14 03:34:22 +00:00
|
|
|
/* In case another CPU set the tracer_frame on us */
|
|
|
|
if (unlikely(!frame_size))
|
|
|
|
this_size -= tracer_frame;
|
|
|
|
|
2008-08-28 03:31:01 +00:00
|
|
|
/* a race could have already updated it */
|
2015-10-30 05:25:39 +00:00
|
|
|
if (this_size <= stack_trace_max_size)
|
2008-08-28 03:31:01 +00:00
|
|
|
goto out;
|
|
|
|
|
2015-10-30 05:25:39 +00:00
|
|
|
stack_trace_max_size = this_size;
|
2008-08-28 03:31:01 +00:00
|
|
|
|
2019-04-25 09:45:17 +00:00
|
|
|
stack_trace_nr_entries = stack_trace_save(stack_dump_trace,
|
|
|
|
ARRAY_SIZE(stack_dump_trace) - 1,
|
|
|
|
0);
|
2008-08-28 03:31:01 +00:00
|
|
|
|
2015-07-16 17:24:54 +00:00
|
|
|
/* Skip over the overhead of the stack tracer itself */
|
2019-04-25 09:45:17 +00:00
|
|
|
for (i = 0; i < stack_trace_nr_entries; i++) {
|
2015-07-16 17:24:54 +00:00
|
|
|
if (stack_dump_trace[i] == ip)
|
|
|
|
break;
|
|
|
|
}
|
2013-03-14 01:25:35 +00:00
|
|
|
|
2016-01-29 15:22:41 +00:00
|
|
|
/*
|
|
|
|
* Some archs may not have the passed in ip in the dump.
|
|
|
|
* If that happens, we need to show everything.
|
|
|
|
*/
|
2019-04-25 09:45:17 +00:00
|
|
|
if (i == stack_trace_nr_entries)
|
2016-01-29 15:22:41 +00:00
|
|
|
i = 0;
|
|
|
|
|
2008-08-29 20:51:43 +00:00
|
|
|
/*
|
|
|
|
* Now find where in the stack these are.
|
|
|
|
*/
|
2015-07-16 17:24:54 +00:00
|
|
|
x = 0;
|
2013-03-14 00:43:57 +00:00
|
|
|
start = stack;
|
2008-08-29 20:51:43 +00:00
|
|
|
top = (unsigned long *)
|
|
|
|
(((unsigned long)start & ~(THREAD_SIZE-1)) + THREAD_SIZE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Loop through all the entries. One of the entries may
|
|
|
|
* for some reason be missed on the stack, so we may
|
|
|
|
* have to account for them. If they are all there, this
|
|
|
|
* loop will only happen once. This code only takes place
|
|
|
|
* on a new max, so it is far from a fast path.
|
|
|
|
*/
|
2019-04-25 09:45:17 +00:00
|
|
|
while (i < stack_trace_nr_entries) {
|
2008-12-03 16:04:50 +00:00
|
|
|
int found = 0;
|
2008-08-29 20:51:43 +00:00
|
|
|
|
2015-10-30 05:25:39 +00:00
|
|
|
stack_trace_index[x] = this_size;
|
2008-08-29 20:51:43 +00:00
|
|
|
p = start;
|
|
|
|
|
2019-04-25 09:45:17 +00:00
|
|
|
for (; p < top && i < stack_trace_nr_entries; p++) {
|
2016-02-12 20:46:00 +00:00
|
|
|
/*
|
|
|
|
* The READ_ONCE_NOCHECK is used to let KASAN know that
|
|
|
|
* this is not a stack-out-of-bounds error.
|
|
|
|
*/
|
|
|
|
if ((READ_ONCE_NOCHECK(*p)) == stack_dump_trace[i]) {
|
2015-07-16 17:24:54 +00:00
|
|
|
stack_dump_trace[x] = stack_dump_trace[i++];
|
2015-10-30 05:25:39 +00:00
|
|
|
this_size = stack_trace_index[x++] =
|
2008-08-29 20:51:43 +00:00
|
|
|
(top - p) * sizeof(unsigned long);
|
2008-12-03 16:04:50 +00:00
|
|
|
found = 1;
|
2008-08-29 20:51:43 +00:00
|
|
|
/* Start the search from here */
|
|
|
|
start = p + 1;
|
2013-03-14 03:34:22 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-07-16 17:24:54 +00:00
|
|
|
if (unlikely(!tracer_frame)) {
|
2013-03-14 03:34:22 +00:00
|
|
|
tracer_frame = (p - stack) *
|
|
|
|
sizeof(unsigned long);
|
2015-10-30 05:25:39 +00:00
|
|
|
stack_trace_max_size -= tracer_frame;
|
2013-03-14 03:34:22 +00:00
|
|
|
}
|
2008-08-29 20:51:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-03 16:04:50 +00:00
|
|
|
if (!found)
|
|
|
|
i++;
|
2008-08-29 20:51:43 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 15:28:59 +00:00
|
|
|
#ifdef ARCH_FTRACE_SHIFT_STACK_TRACER
|
|
|
|
/*
|
|
|
|
* Some archs will store the link register before calling
|
|
|
|
* nested functions. This means the saved return address
|
|
|
|
* comes after the local storage, and we need to shift
|
|
|
|
* for that.
|
|
|
|
*/
|
|
|
|
if (x > 1) {
|
|
|
|
memmove(&stack_trace_index[0], &stack_trace_index[1],
|
|
|
|
sizeof(stack_trace_index[0]) * (x - 1));
|
|
|
|
x--;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-04-25 09:45:17 +00:00
|
|
|
stack_trace_nr_entries = x;
|
2015-07-16 17:24:54 +00:00
|
|
|
|
2014-09-12 13:16:18 +00:00
|
|
|
if (task_stack_end_corrupted(current)) {
|
2019-04-25 09:44:54 +00:00
|
|
|
print_max_stack();
|
2014-06-02 04:33:12 +00:00
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
|
2008-08-28 03:31:01 +00:00
|
|
|
out:
|
2015-11-03 19:50:15 +00:00
|
|
|
arch_spin_unlock(&stack_trace_max_lock);
|
2008-12-02 20:34:05 +00:00
|
|
|
local_irq_restore(flags);
|
2008-08-28 03:31:01 +00:00
|
|
|
}
|
|
|
|
|
2020-01-03 03:02:41 +00:00
|
|
|
/* Some archs may not define MCOUNT_INSN_SIZE */
|
|
|
|
#ifndef MCOUNT_INSN_SIZE
|
|
|
|
# define MCOUNT_INSN_SIZE 0
|
|
|
|
#endif
|
|
|
|
|
2008-08-28 03:31:01 +00:00
|
|
|
static void
|
2011-08-09 16:50:46 +00:00
|
|
|
stack_trace_call(unsigned long ip, unsigned long parent_ip,
|
2020-10-28 21:42:17 +00:00
|
|
|
struct ftrace_ops *op, struct ftrace_regs *fregs)
|
2008-08-28 03:31:01 +00:00
|
|
|
{
|
2013-03-14 00:43:57 +00:00
|
|
|
unsigned long stack;
|
2008-08-28 03:31:01 +00:00
|
|
|
|
2010-06-03 13:36:50 +00:00
|
|
|
preempt_disable_notrace();
|
2008-08-28 03:31:01 +00:00
|
|
|
|
|
|
|
/* no atomic needed, we only modify this variable by this cpu */
|
2017-04-06 19:47:32 +00:00
|
|
|
__this_cpu_inc(disable_stack_tracer);
|
|
|
|
if (__this_cpu_read(disable_stack_tracer) != 1)
|
2008-08-28 03:31:01 +00:00
|
|
|
goto out;
|
|
|
|
|
2017-12-05 09:41:51 +00:00
|
|
|
/* If rcu is not watching, then save stack trace can fail */
|
|
|
|
if (!rcu_is_watching())
|
|
|
|
goto out;
|
|
|
|
|
2015-07-16 17:24:54 +00:00
|
|
|
ip += MCOUNT_INSN_SIZE;
|
2013-03-14 03:34:22 +00:00
|
|
|
|
|
|
|
check_stack(ip, &stack);
|
2008-08-28 03:31:01 +00:00
|
|
|
|
|
|
|
out:
|
2017-04-06 19:47:32 +00:00
|
|
|
__this_cpu_dec(disable_stack_tracer);
|
2008-08-28 03:31:01 +00:00
|
|
|
/* prevent recursion in schedule */
|
2010-06-03 13:36:50 +00:00
|
|
|
preempt_enable_notrace();
|
2008-08-28 03:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct ftrace_ops trace_ops __read_mostly =
|
|
|
|
{
|
|
|
|
.func = stack_trace_call,
|
|
|
|
};
|
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
stack_max_size_read(struct file *filp, char __user *ubuf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
unsigned long *ptr = filp->private_data;
|
|
|
|
char buf[64];
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = snprintf(buf, sizeof(buf), "%ld\n", *ptr);
|
|
|
|
if (r > sizeof(buf))
|
|
|
|
r = sizeof(buf);
|
|
|
|
return simple_read_from_buffer(ubuf, count, ppos, buf, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
stack_max_size_write(struct file *filp, const char __user *ubuf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
long *ptr = filp->private_data;
|
|
|
|
unsigned long val, flags;
|
|
|
|
int ret;
|
|
|
|
|
2011-06-07 19:58:27 +00:00
|
|
|
ret = kstrtoul_from_user(ubuf, count, 10, &val);
|
|
|
|
if (ret)
|
2008-08-28 03:31:01 +00:00
|
|
|
return ret;
|
|
|
|
|
2008-12-02 20:34:05 +00:00
|
|
|
local_irq_save(flags);
|
2010-02-02 07:32:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* In case we trace inside arch_spin_lock() or after (NMI),
|
|
|
|
* we will cause circular lock, so we also need to increase
|
2017-04-06 19:47:32 +00:00
|
|
|
* the percpu disable_stack_tracer here.
|
2010-02-02 07:32:09 +00:00
|
|
|
*/
|
2017-04-06 19:47:32 +00:00
|
|
|
__this_cpu_inc(disable_stack_tracer);
|
2010-02-02 07:32:09 +00:00
|
|
|
|
2015-11-03 19:50:15 +00:00
|
|
|
arch_spin_lock(&stack_trace_max_lock);
|
2008-08-28 03:31:01 +00:00
|
|
|
*ptr = val;
|
2015-11-03 19:50:15 +00:00
|
|
|
arch_spin_unlock(&stack_trace_max_lock);
|
2010-02-02 07:32:09 +00:00
|
|
|
|
2017-04-06 19:47:32 +00:00
|
|
|
__this_cpu_dec(disable_stack_tracer);
|
2008-12-02 20:34:05 +00:00
|
|
|
local_irq_restore(flags);
|
2008-08-28 03:31:01 +00:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2008-12-17 04:06:40 +00:00
|
|
|
static const struct file_operations stack_max_size_fops = {
|
2008-08-28 03:31:01 +00:00
|
|
|
.open = tracing_open_generic,
|
|
|
|
.read = stack_max_size_read,
|
|
|
|
.write = stack_max_size_write,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-15 16:52:59 +00:00
|
|
|
.llseek = default_llseek,
|
2008-08-28 03:31:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void *
|
2009-08-17 08:53:37 +00:00
|
|
|
__next(struct seq_file *m, loff_t *pos)
|
2008-08-28 03:31:01 +00:00
|
|
|
{
|
2009-08-17 08:53:37 +00:00
|
|
|
long n = *pos - 1;
|
2008-08-28 03:31:01 +00:00
|
|
|
|
2019-04-25 09:45:17 +00:00
|
|
|
if (n >= stack_trace_nr_entries)
|
2008-08-28 03:31:01 +00:00
|
|
|
return NULL;
|
|
|
|
|
2009-08-17 08:53:37 +00:00
|
|
|
m->private = (void *)n;
|
2008-08-29 20:51:43 +00:00
|
|
|
return &m->private;
|
2008-08-28 03:31:01 +00:00
|
|
|
}
|
|
|
|
|
2009-08-17 08:53:37 +00:00
|
|
|
static void *
|
|
|
|
t_next(struct seq_file *m, void *v, loff_t *pos)
|
2008-08-28 03:31:01 +00:00
|
|
|
{
|
2009-08-17 08:53:37 +00:00
|
|
|
(*pos)++;
|
|
|
|
return __next(m, pos);
|
|
|
|
}
|
2008-08-28 03:31:01 +00:00
|
|
|
|
2009-08-17 08:53:37 +00:00
|
|
|
static void *t_start(struct seq_file *m, loff_t *pos)
|
|
|
|
{
|
2008-08-28 03:31:01 +00:00
|
|
|
local_irq_disable();
|
2010-02-02 07:32:09 +00:00
|
|
|
|
2017-04-06 19:47:32 +00:00
|
|
|
__this_cpu_inc(disable_stack_tracer);
|
2010-02-02 07:32:09 +00:00
|
|
|
|
2015-11-03 19:50:15 +00:00
|
|
|
arch_spin_lock(&stack_trace_max_lock);
|
2008-08-28 03:31:01 +00:00
|
|
|
|
function tracing: fix wrong position computing of stack_trace
Impact: make output of stack_trace complete if buffer overruns
When read buffer overruns, the output of stack_trace isn't complete.
When printing records with seq_printf in t_show, if the read buffer
has overruned by the current record, then this record won't be
printed to user space through read buffer, it will just be dropped in
this printing.
When next printing, t_start should return the "*pos"th record, which
is the one dropped by previous printing, but it just returns
(m->private + *pos)th record.
Here we use a more sane method to implement seq_operations which can
be found in kernel code. Thus we needn't initialize m->private.
About testing, it's not easy to overrun read buffer, but we can use
seq_printf to print more padding bytes in t_show, then it's easy to
check whether or not records are lost.
This commit has been tested on both condition of overrun and non
overrun.
Signed-off-by: Liming Wang <liming.wang@windriver.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2008-11-21 03:00:18 +00:00
|
|
|
if (*pos == 0)
|
|
|
|
return SEQ_START_TOKEN;
|
|
|
|
|
2009-08-17 08:53:37 +00:00
|
|
|
return __next(m, pos);
|
2008-08-28 03:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void t_stop(struct seq_file *m, void *p)
|
|
|
|
{
|
2015-11-03 19:50:15 +00:00
|
|
|
arch_spin_unlock(&stack_trace_max_lock);
|
2010-02-02 07:32:09 +00:00
|
|
|
|
2017-04-06 19:47:32 +00:00
|
|
|
__this_cpu_dec(disable_stack_tracer);
|
2010-02-02 07:32:09 +00:00
|
|
|
|
2008-08-28 03:31:01 +00:00
|
|
|
local_irq_enable();
|
|
|
|
}
|
|
|
|
|
2015-04-15 23:18:22 +00:00
|
|
|
static void trace_lookup_stack(struct seq_file *m, long i)
|
2008-08-28 03:31:01 +00:00
|
|
|
{
|
2008-08-29 20:51:43 +00:00
|
|
|
unsigned long addr = stack_dump_trace[i];
|
2008-08-28 03:31:01 +00:00
|
|
|
|
2015-04-15 23:18:22 +00:00
|
|
|
seq_printf(m, "%pS\n", (void *)addr);
|
2008-08-28 03:31:01 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 23:42:29 +00:00
|
|
|
static void print_disabled(struct seq_file *m)
|
|
|
|
{
|
|
|
|
seq_puts(m, "#\n"
|
|
|
|
"# Stack tracer disabled\n"
|
|
|
|
"#\n"
|
|
|
|
"# To enable the stack tracer, either add 'stacktrace' to the\n"
|
|
|
|
"# kernel command line\n"
|
|
|
|
"# or 'echo 1 > /proc/sys/kernel/stack_tracer_enabled'\n"
|
|
|
|
"#\n");
|
|
|
|
}
|
|
|
|
|
2008-08-28 03:31:01 +00:00
|
|
|
static int t_show(struct seq_file *m, void *v)
|
|
|
|
{
|
function tracing: fix wrong position computing of stack_trace
Impact: make output of stack_trace complete if buffer overruns
When read buffer overruns, the output of stack_trace isn't complete.
When printing records with seq_printf in t_show, if the read buffer
has overruned by the current record, then this record won't be
printed to user space through read buffer, it will just be dropped in
this printing.
When next printing, t_start should return the "*pos"th record, which
is the one dropped by previous printing, but it just returns
(m->private + *pos)th record.
Here we use a more sane method to implement seq_operations which can
be found in kernel code. Thus we needn't initialize m->private.
About testing, it's not easy to overrun read buffer, but we can use
seq_printf to print more padding bytes in t_show, then it's easy to
check whether or not records are lost.
This commit has been tested on both condition of overrun and non
overrun.
Signed-off-by: Liming Wang <liming.wang@windriver.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2008-11-21 03:00:18 +00:00
|
|
|
long i;
|
2008-08-29 20:51:43 +00:00
|
|
|
int size;
|
|
|
|
|
function tracing: fix wrong position computing of stack_trace
Impact: make output of stack_trace complete if buffer overruns
When read buffer overruns, the output of stack_trace isn't complete.
When printing records with seq_printf in t_show, if the read buffer
has overruned by the current record, then this record won't be
printed to user space through read buffer, it will just be dropped in
this printing.
When next printing, t_start should return the "*pos"th record, which
is the one dropped by previous printing, but it just returns
(m->private + *pos)th record.
Here we use a more sane method to implement seq_operations which can
be found in kernel code. Thus we needn't initialize m->private.
About testing, it's not easy to overrun read buffer, but we can use
seq_printf to print more padding bytes in t_show, then it's easy to
check whether or not records are lost.
This commit has been tested on both condition of overrun and non
overrun.
Signed-off-by: Liming Wang <liming.wang@windriver.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2008-11-21 03:00:18 +00:00
|
|
|
if (v == SEQ_START_TOKEN) {
|
2009-03-13 04:00:58 +00:00
|
|
|
seq_printf(m, " Depth Size Location"
|
2008-08-29 20:51:43 +00:00
|
|
|
" (%d entries)\n"
|
2009-03-13 04:00:58 +00:00
|
|
|
" ----- ---- --------\n",
|
2019-04-25 09:45:17 +00:00
|
|
|
stack_trace_nr_entries);
|
2009-03-12 23:42:29 +00:00
|
|
|
|
2015-10-30 05:25:39 +00:00
|
|
|
if (!stack_tracer_enabled && !stack_trace_max_size)
|
2009-03-12 23:42:29 +00:00
|
|
|
print_disabled(m);
|
|
|
|
|
2008-08-29 20:51:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-08-28 03:31:01 +00:00
|
|
|
|
function tracing: fix wrong position computing of stack_trace
Impact: make output of stack_trace complete if buffer overruns
When read buffer overruns, the output of stack_trace isn't complete.
When printing records with seq_printf in t_show, if the read buffer
has overruned by the current record, then this record won't be
printed to user space through read buffer, it will just be dropped in
this printing.
When next printing, t_start should return the "*pos"th record, which
is the one dropped by previous printing, but it just returns
(m->private + *pos)th record.
Here we use a more sane method to implement seq_operations which can
be found in kernel code. Thus we needn't initialize m->private.
About testing, it's not easy to overrun read buffer, but we can use
seq_printf to print more padding bytes in t_show, then it's easy to
check whether or not records are lost.
This commit has been tested on both condition of overrun and non
overrun.
Signed-off-by: Liming Wang <liming.wang@windriver.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2008-11-21 03:00:18 +00:00
|
|
|
i = *(long *)v;
|
|
|
|
|
2019-04-25 09:45:17 +00:00
|
|
|
if (i >= stack_trace_nr_entries)
|
2008-08-28 03:31:01 +00:00
|
|
|
return 0;
|
|
|
|
|
2019-04-25 09:45:17 +00:00
|
|
|
if (i + 1 == stack_trace_nr_entries)
|
2015-10-30 05:25:39 +00:00
|
|
|
size = stack_trace_index[i];
|
2008-08-29 20:51:43 +00:00
|
|
|
else
|
2015-10-30 05:25:39 +00:00
|
|
|
size = stack_trace_index[i] - stack_trace_index[i+1];
|
2008-08-29 20:51:43 +00:00
|
|
|
|
2015-10-30 05:25:39 +00:00
|
|
|
seq_printf(m, "%3ld) %8d %5d ", i, stack_trace_index[i], size);
|
2008-08-29 20:51:43 +00:00
|
|
|
|
|
|
|
trace_lookup_stack(m, i);
|
2008-08-28 03:31:01 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-17 04:06:40 +00:00
|
|
|
static const struct seq_operations stack_trace_seq_ops = {
|
2008-08-28 03:31:01 +00:00
|
|
|
.start = t_start,
|
|
|
|
.next = t_next,
|
|
|
|
.stop = t_stop,
|
|
|
|
.show = t_show,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int stack_trace_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2019-10-11 21:22:50 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = security_locked_down(LOCKDOWN_TRACEFS);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2009-07-23 03:28:40 +00:00
|
|
|
return seq_open(file, &stack_trace_seq_ops);
|
2008-08-28 03:31:01 +00:00
|
|
|
}
|
|
|
|
|
2008-12-17 04:06:40 +00:00
|
|
|
static const struct file_operations stack_trace_fops = {
|
2008-08-28 03:31:01 +00:00
|
|
|
.open = stack_trace_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
2009-07-23 03:28:40 +00:00
|
|
|
.release = seq_release,
|
2008-08-28 03:31:01 +00:00
|
|
|
};
|
|
|
|
|
2017-07-11 23:21:04 +00:00
|
|
|
#ifdef CONFIG_DYNAMIC_FTRACE
|
|
|
|
|
2011-12-19 19:44:09 +00:00
|
|
|
static int
|
|
|
|
stack_trace_filter_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2017-06-29 14:05:45 +00:00
|
|
|
struct ftrace_ops *ops = inode->i_private;
|
|
|
|
|
2019-10-11 21:22:50 +00:00
|
|
|
/* Checks for tracefs lockdown */
|
2017-06-29 14:05:45 +00:00
|
|
|
return ftrace_regex_open(ops, FTRACE_ITER_FILTER,
|
2011-12-19 19:44:09 +00:00
|
|
|
inode, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations stack_trace_filter_fops = {
|
|
|
|
.open = stack_trace_filter_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.write = ftrace_filter_write,
|
2013-12-21 22:39:40 +00:00
|
|
|
.llseek = tracing_lseek,
|
2011-12-19 19:44:09 +00:00
|
|
|
.release = ftrace_regex_release,
|
|
|
|
};
|
|
|
|
|
2017-07-11 23:21:04 +00:00
|
|
|
#endif /* CONFIG_DYNAMIC_FTRACE */
|
|
|
|
|
2008-12-17 04:06:40 +00:00
|
|
|
int
|
sysctl: treewide: constify the ctl_table argument of proc_handlers
const qualify the struct ctl_table argument in the proc_handler function
signatures. This is a prerequisite to moving the static ctl_table
structs into .rodata data which will ensure that proc_handler function
pointers cannot be modified.
This patch has been generated by the following coccinelle script:
```
virtual patch
@r1@
identifier ctl, write, buffer, lenp, ppos;
identifier func !~ "appldata_(timer|interval)_handler|sched_(rt|rr)_handler|rds_tcp_skbuf_handler|proc_sctp_do_(hmac_alg|rto_min|rto_max|udp_port|alpha_beta|auth|probe_interval)";
@@
int func(
- struct ctl_table *ctl
+ const struct ctl_table *ctl
,int write, void *buffer, size_t *lenp, loff_t *ppos);
@r2@
identifier func, ctl, write, buffer, lenp, ppos;
@@
int func(
- struct ctl_table *ctl
+ const struct ctl_table *ctl
,int write, void *buffer, size_t *lenp, loff_t *ppos)
{ ... }
@r3@
identifier func;
@@
int func(
- struct ctl_table *
+ const struct ctl_table *
,int , void *, size_t *, loff_t *);
@r4@
identifier func, ctl;
@@
int func(
- struct ctl_table *ctl
+ const struct ctl_table *ctl
,int , void *, size_t *, loff_t *);
@r5@
identifier func, write, buffer, lenp, ppos;
@@
int func(
- struct ctl_table *
+ const struct ctl_table *
,int write, void *buffer, size_t *lenp, loff_t *ppos);
```
* Code formatting was adjusted in xfs_sysctl.c to comply with code
conventions. The xfs_stats_clear_proc_handler,
xfs_panic_mask_proc_handler and xfs_deprecated_dointvec_minmax where
adjusted.
* The ctl_table argument in proc_watchdog_common was const qualified.
This is called from a proc_handler itself and is calling back into
another proc_handler, making it necessary to change it as part of the
proc_handler migration.
Co-developed-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Co-developed-by: Joel Granados <j.granados@samsung.com>
Signed-off-by: Joel Granados <j.granados@samsung.com>
2024-07-24 18:59:29 +00:00
|
|
|
stack_trace_sysctl(const struct ctl_table *table, int write, void *buffer,
|
2020-06-03 05:52:37 +00:00
|
|
|
size_t *lenp, loff_t *ppos)
|
2008-12-17 04:06:40 +00:00
|
|
|
{
|
2019-04-25 09:44:54 +00:00
|
|
|
int was_enabled;
|
2008-12-17 04:06:40 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&stack_sysctl_mutex);
|
2019-04-25 09:44:54 +00:00
|
|
|
was_enabled = !!stack_tracer_enabled;
|
2008-12-17 04:06:40 +00:00
|
|
|
|
2009-09-23 22:57:19 +00:00
|
|
|
ret = proc_dointvec(table, write, buffer, lenp, ppos);
|
2008-12-17 04:06:40 +00:00
|
|
|
|
2019-04-25 09:44:54 +00:00
|
|
|
if (ret || !write || (was_enabled == !!stack_tracer_enabled))
|
2008-12-17 04:06:40 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (stack_tracer_enabled)
|
|
|
|
register_ftrace_function(&trace_ops);
|
|
|
|
else
|
|
|
|
unregister_ftrace_function(&trace_ops);
|
|
|
|
out:
|
|
|
|
mutex_unlock(&stack_sysctl_mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-12-20 03:01:00 +00:00
|
|
|
static char stack_trace_filter_buf[COMMAND_LINE_SIZE+1] __initdata;
|
|
|
|
|
2008-12-17 04:06:40 +00:00
|
|
|
static __init int enable_stacktrace(char *str)
|
|
|
|
{
|
2018-12-22 04:10:26 +00:00
|
|
|
int len;
|
|
|
|
|
|
|
|
if ((len = str_has_prefix(str, "_filter=")))
|
|
|
|
strncpy(stack_trace_filter_buf, str + len, COMMAND_LINE_SIZE);
|
2011-12-20 03:01:00 +00:00
|
|
|
|
2008-12-17 14:43:00 +00:00
|
|
|
stack_tracer_enabled = 1;
|
2008-12-17 04:06:40 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("stacktrace", enable_stacktrace);
|
|
|
|
|
2008-08-28 03:31:01 +00:00
|
|
|
static __init int stack_trace_init(void)
|
|
|
|
{
|
2020-07-12 01:10:36 +00:00
|
|
|
int ret;
|
2008-08-28 03:31:01 +00:00
|
|
|
|
2020-07-12 01:10:36 +00:00
|
|
|
ret = tracing_init_dentry();
|
|
|
|
if (ret)
|
2013-04-10 00:18:12 +00:00
|
|
|
return 0;
|
2008-08-28 03:31:01 +00:00
|
|
|
|
2021-08-18 15:24:51 +00:00
|
|
|
trace_create_file("stack_max_size", TRACE_MODE_WRITE, NULL,
|
2015-10-30 05:25:39 +00:00
|
|
|
&stack_trace_max_size, &stack_max_size_fops);
|
2008-08-28 03:31:01 +00:00
|
|
|
|
2021-08-18 15:24:51 +00:00
|
|
|
trace_create_file("stack_trace", TRACE_MODE_READ, NULL,
|
2009-03-26 23:25:38 +00:00
|
|
|
NULL, &stack_trace_fops);
|
2008-08-28 03:31:01 +00:00
|
|
|
|
2017-07-11 23:21:04 +00:00
|
|
|
#ifdef CONFIG_DYNAMIC_FTRACE
|
2021-08-18 15:24:51 +00:00
|
|
|
trace_create_file("stack_trace_filter", TRACE_MODE_WRITE, NULL,
|
2017-06-29 14:05:45 +00:00
|
|
|
&trace_ops, &stack_trace_filter_fops);
|
2017-07-11 23:21:04 +00:00
|
|
|
#endif
|
2011-12-19 19:44:09 +00:00
|
|
|
|
2011-12-20 03:01:00 +00:00
|
|
|
if (stack_trace_filter_buf[0])
|
|
|
|
ftrace_set_early_filter(&trace_ops, stack_trace_filter_buf, 1);
|
|
|
|
|
2008-12-17 14:43:00 +00:00
|
|
|
if (stack_tracer_enabled)
|
2008-12-17 04:06:40 +00:00
|
|
|
register_ftrace_function(&trace_ops);
|
2008-08-28 03:31:01 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
device_initcall(stack_trace_init);
|