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 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Kernel unwinding support
|
|
|
|
*
|
|
|
|
* (c) 2002-2004 Randolph Chung <tausq@debian.org>
|
|
|
|
*
|
|
|
|
* Derived partially from the IA64 implementation. The PA-RISC
|
|
|
|
* Runtime Architecture Document is also a useful reference to
|
|
|
|
* understand what is happening here
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
2006-12-16 00:34:36 +08:00
|
|
|
#include <linux/sched.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/slab.h>
|
2009-11-07 07:07:42 +08:00
|
|
|
#include <linux/sort.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/assembly.h>
|
2007-06-12 14:27:32 +08:00
|
|
|
#include <asm/asm-offsets.h>
|
|
|
|
#include <asm/ptrace.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/unwind.h>
|
|
|
|
|
|
|
|
/* #define DEBUG 1 */
|
|
|
|
#ifdef DEBUG
|
2018-06-29 04:21:24 +08:00
|
|
|
#define dbg(x...) pr_debug(x)
|
2005-04-17 06:20:36 +08:00
|
|
|
#else
|
|
|
|
#define dbg(x...)
|
|
|
|
#endif
|
|
|
|
|
2009-11-29 04:33:11 +08:00
|
|
|
#define KERNEL_START (KERNEL_BINARY_TEXT_START)
|
2007-06-12 14:27:32 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
extern struct unwind_table_entry __start___unwind[];
|
|
|
|
extern struct unwind_table_entry __stop___unwind[];
|
|
|
|
|
2017-08-05 05:54:19 +08:00
|
|
|
static DEFINE_SPINLOCK(unwind_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* the kernel unwind block is not dynamically allocated so that
|
|
|
|
* we can call unwind_init as early in the bootup process as
|
|
|
|
* possible (before the slab allocator is initialized)
|
|
|
|
*/
|
2019-05-11 02:55:51 +08:00
|
|
|
static struct unwind_table kernel_unwind_table __ro_after_init;
|
2005-04-17 06:20:36 +08:00
|
|
|
static LIST_HEAD(unwind_tables);
|
|
|
|
|
|
|
|
static inline const struct unwind_table_entry *
|
|
|
|
find_unwind_entry_in_table(const struct unwind_table *table, unsigned long addr)
|
|
|
|
{
|
|
|
|
const struct unwind_table_entry *e = NULL;
|
|
|
|
unsigned long lo, hi, mid;
|
|
|
|
|
|
|
|
lo = 0;
|
|
|
|
hi = table->length - 1;
|
|
|
|
|
|
|
|
while (lo <= hi) {
|
|
|
|
mid = (hi - lo) / 2 + lo;
|
|
|
|
e = &table->table[mid];
|
|
|
|
if (addr < e->region_start)
|
|
|
|
hi = mid - 1;
|
|
|
|
else if (addr > e->region_end)
|
|
|
|
lo = mid + 1;
|
|
|
|
else
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct unwind_table_entry *
|
|
|
|
find_unwind_entry(unsigned long addr)
|
|
|
|
{
|
|
|
|
struct unwind_table *table;
|
|
|
|
const struct unwind_table_entry *e = NULL;
|
|
|
|
|
|
|
|
if (addr >= kernel_unwind_table.start &&
|
|
|
|
addr <= kernel_unwind_table.end)
|
|
|
|
e = find_unwind_entry_in_table(&kernel_unwind_table, addr);
|
parisc: Fix backtrace on PA-RISC
This patch fixes backtrace on PA-RISC
There were several problems:
1) The code that decodes instructions handles instructions that subtract
from the stack pointer incorrectly. If the instruction subtracts the
number X from the stack pointer the code increases the frame size by
(0x100000000-X). This results in invalid accesses to memory and
recursive page faults.
2) Because gcc reorders blocks, handling instructions that subtract from
the frame pointer is incorrect. For example, this function
int f(int a)
{
if (__builtin_expect(a, 1))
return a;
g();
return a;
}
is compiled in such a way, that the code that decreases the stack
pointer for the first "return a" is placed before the code for "g" call.
If we recognize this decrement, we mistakenly believe that the frame
size for the "g" call is zero.
To fix problems 1) and 2), the patch doesn't recognize instructions that
decrease the stack pointer at all. To further safeguard the unwind code
against nonsense values, we don't allow frame size larger than
Total_frame_size.
3) The backtrace is not locked. If stack dump races with module unload,
invalid table can be accessed.
This patch adds a spinlock when processing module tables.
Note, that for correct backtrace, you need recent binutils.
Binutils 2.18 from Debian 5 produce garbage unwind tables.
Binutils 2.21 work better (it sometimes forgets function frames, but at
least it doesn't generate garbage).
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Helge Deller <deller@gmx.de>
2011-06-29 06:48:19 +08:00
|
|
|
else {
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&unwind_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
list_for_each_entry(table, &unwind_tables, list) {
|
|
|
|
if (addr >= table->start &&
|
|
|
|
addr <= table->end)
|
|
|
|
e = find_unwind_entry_in_table(table, addr);
|
2010-09-10 18:47:59 +08:00
|
|
|
if (e) {
|
|
|
|
/* Move-to-front to exploit common traces */
|
|
|
|
list_move(&table->list, &unwind_tables);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
2010-09-10 18:47:59 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
parisc: Fix backtrace on PA-RISC
This patch fixes backtrace on PA-RISC
There were several problems:
1) The code that decodes instructions handles instructions that subtract
from the stack pointer incorrectly. If the instruction subtracts the
number X from the stack pointer the code increases the frame size by
(0x100000000-X). This results in invalid accesses to memory and
recursive page faults.
2) Because gcc reorders blocks, handling instructions that subtract from
the frame pointer is incorrect. For example, this function
int f(int a)
{
if (__builtin_expect(a, 1))
return a;
g();
return a;
}
is compiled in such a way, that the code that decreases the stack
pointer for the first "return a" is placed before the code for "g" call.
If we recognize this decrement, we mistakenly believe that the frame
size for the "g" call is zero.
To fix problems 1) and 2), the patch doesn't recognize instructions that
decrease the stack pointer at all. To further safeguard the unwind code
against nonsense values, we don't allow frame size larger than
Total_frame_size.
3) The backtrace is not locked. If stack dump races with module unload,
invalid table can be accessed.
This patch adds a spinlock when processing module tables.
Note, that for correct backtrace, you need recent binutils.
Binutils 2.18 from Debian 5 produce garbage unwind tables.
Binutils 2.21 work better (it sometimes forgets function frames, but at
least it doesn't generate garbage).
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Helge Deller <deller@gmx.de>
2011-06-29 06:48:19 +08:00
|
|
|
spin_unlock_irqrestore(&unwind_lock, flags);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unwind_table_init(struct unwind_table *table, const char *name,
|
|
|
|
unsigned long base_addr, unsigned long gp,
|
|
|
|
void *table_start, void *table_end)
|
|
|
|
{
|
|
|
|
struct unwind_table_entry *start = table_start;
|
|
|
|
struct unwind_table_entry *end =
|
|
|
|
(struct unwind_table_entry *)table_end - 1;
|
|
|
|
|
|
|
|
table->name = name;
|
|
|
|
table->base_addr = base_addr;
|
|
|
|
table->gp = gp;
|
|
|
|
table->start = base_addr + start->region_start;
|
|
|
|
table->end = base_addr + end->region_end;
|
|
|
|
table->table = (struct unwind_table_entry *)table_start;
|
|
|
|
table->length = end - start + 1;
|
|
|
|
INIT_LIST_HEAD(&table->list);
|
|
|
|
|
|
|
|
for (; start <= end; start++) {
|
|
|
|
if (start < end &&
|
|
|
|
start->region_end > (start+1)->region_start) {
|
2018-08-05 06:03:29 +08:00
|
|
|
pr_warn("Out of order unwind entry! %px and %px\n",
|
|
|
|
start, start+1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
start->region_start += base_addr;
|
|
|
|
start->region_end += base_addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-07 07:07:42 +08:00
|
|
|
static int cmp_unwind_table_entry(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
return ((const struct unwind_table_entry *)a)->region_start
|
|
|
|
- ((const struct unwind_table_entry *)b)->region_start;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static void
|
|
|
|
unwind_table_sort(struct unwind_table_entry *start,
|
|
|
|
struct unwind_table_entry *finish)
|
|
|
|
{
|
2009-11-07 07:07:42 +08:00
|
|
|
sort(start, finish - start, sizeof(struct unwind_table_entry),
|
|
|
|
cmp_unwind_table_entry, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct unwind_table *
|
|
|
|
unwind_table_add(const char *name, unsigned long base_addr,
|
|
|
|
unsigned long gp,
|
|
|
|
void *start, void *end)
|
|
|
|
{
|
|
|
|
struct unwind_table *table;
|
|
|
|
unsigned long flags;
|
|
|
|
struct unwind_table_entry *s = (struct unwind_table_entry *)start;
|
|
|
|
struct unwind_table_entry *e = (struct unwind_table_entry *)end;
|
|
|
|
|
|
|
|
unwind_table_sort(s, e);
|
|
|
|
|
|
|
|
table = kmalloc(sizeof(struct unwind_table), GFP_USER);
|
|
|
|
if (table == NULL)
|
|
|
|
return NULL;
|
|
|
|
unwind_table_init(table, name, base_addr, gp, start, end);
|
|
|
|
spin_lock_irqsave(&unwind_lock, flags);
|
|
|
|
list_add_tail(&table->list, &unwind_tables);
|
|
|
|
spin_unlock_irqrestore(&unwind_lock, flags);
|
|
|
|
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
|
|
|
void unwind_table_remove(struct unwind_table *table)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&unwind_lock, flags);
|
|
|
|
list_del(&table->list);
|
|
|
|
spin_unlock_irqrestore(&unwind_lock, flags);
|
|
|
|
|
|
|
|
kfree(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called from setup_arch to import the kernel unwind info */
|
2013-12-01 04:23:20 +08:00
|
|
|
int __init unwind_init(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
long start, stop;
|
|
|
|
register unsigned long gp __asm__ ("r27");
|
|
|
|
|
|
|
|
start = (long)&__start___unwind[0];
|
|
|
|
stop = (long)&__stop___unwind[0];
|
|
|
|
|
2018-06-29 04:21:24 +08:00
|
|
|
dbg("unwind_init: start = 0x%lx, end = 0x%lx, entries = %lu\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
start, stop,
|
|
|
|
(stop - start) / sizeof(struct unwind_table_entry));
|
|
|
|
|
|
|
|
unwind_table_init(&kernel_unwind_table, "kernel", KERNEL_START,
|
|
|
|
gp,
|
|
|
|
&__start___unwind[0], &__stop___unwind[0]);
|
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
printk("region 0x%x-0x%x\n",
|
|
|
|
__start___unwind[i].region_start,
|
|
|
|
__start___unwind[i].region_end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-06-12 14:27:32 +08:00
|
|
|
static int unwind_special(struct unwind_frame_info *info, unsigned long pc, int frame_size)
|
|
|
|
{
|
2018-08-05 06:03:29 +08:00
|
|
|
/*
|
|
|
|
* We have to use void * instead of a function pointer, because
|
|
|
|
* function pointers aren't a pointer to the function on 64-bit.
|
|
|
|
* Make them const so the compiler knows they live in .text
|
2018-08-21 20:31:32 +08:00
|
|
|
* Note: We could use dereference_kernel_function_descriptor()
|
|
|
|
* instead but we want to keep it simple here.
|
2018-08-05 06:03:29 +08:00
|
|
|
*/
|
|
|
|
extern void * const handle_interruption;
|
|
|
|
extern void * const ret_from_kernel_thread;
|
|
|
|
extern void * const syscall_exit;
|
|
|
|
extern void * const intr_return;
|
|
|
|
extern void * const _switch_to_ret;
|
|
|
|
#ifdef CONFIG_IRQSTACKS
|
2018-08-21 20:31:32 +08:00
|
|
|
extern void * const _call_on_stack;
|
2018-08-05 06:03:29 +08:00
|
|
|
#endif /* CONFIG_IRQSTACKS */
|
|
|
|
|
|
|
|
if (pc == (unsigned long) &handle_interruption) {
|
2007-06-12 14:27:32 +08:00
|
|
|
struct pt_regs *regs = (struct pt_regs *)(info->sp - frame_size - PT_SZ_ALGN);
|
|
|
|
dbg("Unwinding through handle_interruption()\n");
|
|
|
|
info->prev_sp = regs->gr[30];
|
|
|
|
info->prev_ip = regs->iaoq[0];
|
2018-08-05 06:03:29 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pc == (unsigned long) &ret_from_kernel_thread ||
|
|
|
|
pc == (unsigned long) &syscall_exit) {
|
|
|
|
info->prev_sp = info->prev_ip = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pc == (unsigned long) &intr_return) {
|
|
|
|
struct pt_regs *regs;
|
|
|
|
|
|
|
|
dbg("Found intr_return()\n");
|
|
|
|
regs = (struct pt_regs *)(info->sp - PT_SZ_ALGN);
|
|
|
|
info->prev_sp = regs->gr[30];
|
|
|
|
info->prev_ip = regs->iaoq[0];
|
|
|
|
info->rp = regs->gr[2];
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pc == (unsigned long) &_switch_to_ret) {
|
|
|
|
info->prev_sp = info->sp - CALLEE_SAVE_FRAME_SIZE;
|
|
|
|
info->prev_ip = *(unsigned long *)(info->prev_sp - RP_OFFSET);
|
|
|
|
return 1;
|
|
|
|
}
|
2007-06-12 14:27:32 +08:00
|
|
|
|
2018-08-05 06:03:29 +08:00
|
|
|
#ifdef CONFIG_IRQSTACKS
|
2018-08-21 20:31:32 +08:00
|
|
|
if (pc == (unsigned long) &_call_on_stack) {
|
2018-08-05 06:03:29 +08:00
|
|
|
info->prev_sp = *(unsigned long *)(info->sp - FRAME_SIZE - REG_SZ);
|
|
|
|
info->prev_ip = *(unsigned long *)(info->sp - FRAME_SIZE - RP_OFFSET);
|
2007-06-12 14:27:32 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2018-08-05 06:03:29 +08:00
|
|
|
#endif
|
2007-06-12 14:27:32 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static void unwind_frame_regs(struct unwind_frame_info *info)
|
|
|
|
{
|
|
|
|
const struct unwind_table_entry *e;
|
|
|
|
unsigned long npc;
|
|
|
|
unsigned int insn;
|
|
|
|
long frame_size = 0;
|
|
|
|
int looking_for_rp, rpoffset = 0;
|
|
|
|
|
|
|
|
e = find_unwind_entry(info->ip);
|
|
|
|
if (e == NULL) {
|
|
|
|
unsigned long sp;
|
|
|
|
|
2018-08-05 06:03:29 +08:00
|
|
|
dbg("Cannot find unwind entry for %pS; forced unwinding\n",
|
|
|
|
(void *) info->ip);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Since we are doing the unwinding blind, we don't know if
|
|
|
|
we are adjusting the stack correctly or extracting the rp
|
|
|
|
correctly. The rp is checked to see if it belongs to the
|
|
|
|
kernel text section, if not we assume we don't have a
|
|
|
|
correct stack frame and we continue to unwind the stack.
|
|
|
|
This is not quite correct, and will fail for loadable
|
|
|
|
modules. */
|
|
|
|
sp = info->sp & ~63;
|
|
|
|
do {
|
|
|
|
unsigned long tmp;
|
|
|
|
|
|
|
|
info->prev_sp = sp - 64;
|
|
|
|
info->prev_ip = 0;
|
2017-09-18 03:05:02 +08:00
|
|
|
|
|
|
|
/* The stack is at the end inside the thread_union
|
|
|
|
* struct. If we reach data, we have reached the
|
|
|
|
* beginning of the stack and should stop unwinding. */
|
|
|
|
if (info->prev_sp >= (unsigned long) task_thread_info(info->t) &&
|
|
|
|
info->prev_sp < ((unsigned long) task_thread_info(info->t)
|
|
|
|
+ THREAD_SZ_ALGN)) {
|
|
|
|
info->prev_sp = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-10-01 01:26:03 +08:00
|
|
|
if (copy_from_kernel_nofault(&tmp,
|
|
|
|
(void *)info->prev_sp - RP_OFFSET, sizeof(tmp)))
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
info->prev_ip = tmp;
|
|
|
|
sp = info->prev_sp;
|
2013-12-01 04:23:20 +08:00
|
|
|
} while (!kernel_text_address(info->prev_ip));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
info->rp = 0;
|
|
|
|
|
|
|
|
dbg("analyzing func @ %lx with no unwind info, setting "
|
|
|
|
"prev_sp=%lx prev_ip=%lx\n", info->ip,
|
|
|
|
info->prev_sp, info->prev_ip);
|
|
|
|
} else {
|
|
|
|
dbg("e->start = 0x%x, e->end = 0x%x, Save_SP = %d, "
|
|
|
|
"Save_RP = %d, Millicode = %d size = %u\n",
|
|
|
|
e->region_start, e->region_end, e->Save_SP, e->Save_RP,
|
|
|
|
e->Millicode, e->Total_frame_size);
|
|
|
|
|
|
|
|
looking_for_rp = e->Save_RP;
|
|
|
|
|
|
|
|
for (npc = e->region_start;
|
|
|
|
(frame_size < (e->Total_frame_size << 3) ||
|
|
|
|
looking_for_rp) &&
|
|
|
|
npc < info->ip;
|
|
|
|
npc += 4) {
|
|
|
|
|
|
|
|
insn = *(unsigned int *)npc;
|
|
|
|
|
parisc: Fix backtrace on PA-RISC
This patch fixes backtrace on PA-RISC
There were several problems:
1) The code that decodes instructions handles instructions that subtract
from the stack pointer incorrectly. If the instruction subtracts the
number X from the stack pointer the code increases the frame size by
(0x100000000-X). This results in invalid accesses to memory and
recursive page faults.
2) Because gcc reorders blocks, handling instructions that subtract from
the frame pointer is incorrect. For example, this function
int f(int a)
{
if (__builtin_expect(a, 1))
return a;
g();
return a;
}
is compiled in such a way, that the code that decreases the stack
pointer for the first "return a" is placed before the code for "g" call.
If we recognize this decrement, we mistakenly believe that the frame
size for the "g" call is zero.
To fix problems 1) and 2), the patch doesn't recognize instructions that
decrease the stack pointer at all. To further safeguard the unwind code
against nonsense values, we don't allow frame size larger than
Total_frame_size.
3) The backtrace is not locked. If stack dump races with module unload,
invalid table can be accessed.
This patch adds a spinlock when processing module tables.
Note, that for correct backtrace, you need recent binutils.
Binutils 2.18 from Debian 5 produce garbage unwind tables.
Binutils 2.21 work better (it sometimes forgets function frames, but at
least it doesn't generate garbage).
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Helge Deller <deller@gmx.de>
2011-06-29 06:48:19 +08:00
|
|
|
if ((insn & 0xffffc001) == 0x37de0000 ||
|
|
|
|
(insn & 0xffe00001) == 0x6fc00000) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* ldo X(sp), sp, or stwm X,D(sp) */
|
parisc: Fix backtrace on PA-RISC
This patch fixes backtrace on PA-RISC
There were several problems:
1) The code that decodes instructions handles instructions that subtract
from the stack pointer incorrectly. If the instruction subtracts the
number X from the stack pointer the code increases the frame size by
(0x100000000-X). This results in invalid accesses to memory and
recursive page faults.
2) Because gcc reorders blocks, handling instructions that subtract from
the frame pointer is incorrect. For example, this function
int f(int a)
{
if (__builtin_expect(a, 1))
return a;
g();
return a;
}
is compiled in such a way, that the code that decreases the stack
pointer for the first "return a" is placed before the code for "g" call.
If we recognize this decrement, we mistakenly believe that the frame
size for the "g" call is zero.
To fix problems 1) and 2), the patch doesn't recognize instructions that
decrease the stack pointer at all. To further safeguard the unwind code
against nonsense values, we don't allow frame size larger than
Total_frame_size.
3) The backtrace is not locked. If stack dump races with module unload,
invalid table can be accessed.
This patch adds a spinlock when processing module tables.
Note, that for correct backtrace, you need recent binutils.
Binutils 2.18 from Debian 5 produce garbage unwind tables.
Binutils 2.21 work better (it sometimes forgets function frames, but at
least it doesn't generate garbage).
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Helge Deller <deller@gmx.de>
2011-06-29 06:48:19 +08:00
|
|
|
frame_size += (insn & 0x3fff) >> 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
dbg("analyzing func @ %lx, insn=%08x @ "
|
|
|
|
"%lx, frame_size = %ld\n", info->ip,
|
|
|
|
insn, npc, frame_size);
|
parisc: Fix backtrace on PA-RISC
This patch fixes backtrace on PA-RISC
There were several problems:
1) The code that decodes instructions handles instructions that subtract
from the stack pointer incorrectly. If the instruction subtracts the
number X from the stack pointer the code increases the frame size by
(0x100000000-X). This results in invalid accesses to memory and
recursive page faults.
2) Because gcc reorders blocks, handling instructions that subtract from
the frame pointer is incorrect. For example, this function
int f(int a)
{
if (__builtin_expect(a, 1))
return a;
g();
return a;
}
is compiled in such a way, that the code that decreases the stack
pointer for the first "return a" is placed before the code for "g" call.
If we recognize this decrement, we mistakenly believe that the frame
size for the "g" call is zero.
To fix problems 1) and 2), the patch doesn't recognize instructions that
decrease the stack pointer at all. To further safeguard the unwind code
against nonsense values, we don't allow frame size larger than
Total_frame_size.
3) The backtrace is not locked. If stack dump races with module unload,
invalid table can be accessed.
This patch adds a spinlock when processing module tables.
Note, that for correct backtrace, you need recent binutils.
Binutils 2.18 from Debian 5 produce garbage unwind tables.
Binutils 2.21 work better (it sometimes forgets function frames, but at
least it doesn't generate garbage).
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Helge Deller <deller@gmx.de>
2011-06-29 06:48:19 +08:00
|
|
|
} else if ((insn & 0xffe00009) == 0x73c00008) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* std,ma X,D(sp) */
|
parisc: Fix backtrace on PA-RISC
This patch fixes backtrace on PA-RISC
There were several problems:
1) The code that decodes instructions handles instructions that subtract
from the stack pointer incorrectly. If the instruction subtracts the
number X from the stack pointer the code increases the frame size by
(0x100000000-X). This results in invalid accesses to memory and
recursive page faults.
2) Because gcc reorders blocks, handling instructions that subtract from
the frame pointer is incorrect. For example, this function
int f(int a)
{
if (__builtin_expect(a, 1))
return a;
g();
return a;
}
is compiled in such a way, that the code that decreases the stack
pointer for the first "return a" is placed before the code for "g" call.
If we recognize this decrement, we mistakenly believe that the frame
size for the "g" call is zero.
To fix problems 1) and 2), the patch doesn't recognize instructions that
decrease the stack pointer at all. To further safeguard the unwind code
against nonsense values, we don't allow frame size larger than
Total_frame_size.
3) The backtrace is not locked. If stack dump races with module unload,
invalid table can be accessed.
This patch adds a spinlock when processing module tables.
Note, that for correct backtrace, you need recent binutils.
Binutils 2.18 from Debian 5 produce garbage unwind tables.
Binutils 2.21 work better (it sometimes forgets function frames, but at
least it doesn't generate garbage).
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Helge Deller <deller@gmx.de>
2011-06-29 06:48:19 +08:00
|
|
|
frame_size += ((insn >> 4) & 0x3ff) << 3;
|
2005-04-17 06:20:36 +08:00
|
|
|
dbg("analyzing func @ %lx, insn=%08x @ "
|
|
|
|
"%lx, frame_size = %ld\n", info->ip,
|
|
|
|
insn, npc, frame_size);
|
|
|
|
} else if (insn == 0x6bc23fd9) {
|
|
|
|
/* stw rp,-20(sp) */
|
|
|
|
rpoffset = 20;
|
|
|
|
looking_for_rp = 0;
|
|
|
|
dbg("analyzing func @ %lx, insn=stw rp,"
|
|
|
|
"-20(sp) @ %lx\n", info->ip, npc);
|
|
|
|
} else if (insn == 0x0fc212c1) {
|
|
|
|
/* std rp,-16(sr0,sp) */
|
|
|
|
rpoffset = 16;
|
|
|
|
looking_for_rp = 0;
|
|
|
|
dbg("analyzing func @ %lx, insn=std rp,"
|
|
|
|
"-16(sp) @ %lx\n", info->ip, npc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
parisc: Fix backtrace on PA-RISC
This patch fixes backtrace on PA-RISC
There were several problems:
1) The code that decodes instructions handles instructions that subtract
from the stack pointer incorrectly. If the instruction subtracts the
number X from the stack pointer the code increases the frame size by
(0x100000000-X). This results in invalid accesses to memory and
recursive page faults.
2) Because gcc reorders blocks, handling instructions that subtract from
the frame pointer is incorrect. For example, this function
int f(int a)
{
if (__builtin_expect(a, 1))
return a;
g();
return a;
}
is compiled in such a way, that the code that decreases the stack
pointer for the first "return a" is placed before the code for "g" call.
If we recognize this decrement, we mistakenly believe that the frame
size for the "g" call is zero.
To fix problems 1) and 2), the patch doesn't recognize instructions that
decrease the stack pointer at all. To further safeguard the unwind code
against nonsense values, we don't allow frame size larger than
Total_frame_size.
3) The backtrace is not locked. If stack dump races with module unload,
invalid table can be accessed.
This patch adds a spinlock when processing module tables.
Note, that for correct backtrace, you need recent binutils.
Binutils 2.18 from Debian 5 produce garbage unwind tables.
Binutils 2.21 work better (it sometimes forgets function frames, but at
least it doesn't generate garbage).
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Helge Deller <deller@gmx.de>
2011-06-29 06:48:19 +08:00
|
|
|
if (frame_size > e->Total_frame_size << 3)
|
|
|
|
frame_size = e->Total_frame_size << 3;
|
|
|
|
|
2007-06-12 14:27:32 +08:00
|
|
|
if (!unwind_special(info, e->region_start, frame_size)) {
|
|
|
|
info->prev_sp = info->sp - frame_size;
|
|
|
|
if (e->Millicode)
|
|
|
|
info->rp = info->r31;
|
|
|
|
else if (rpoffset)
|
|
|
|
info->rp = *(unsigned long *)(info->prev_sp - rpoffset);
|
|
|
|
info->prev_ip = info->rp;
|
|
|
|
info->rp = 0;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
dbg("analyzing func @ %lx, setting prev_sp=%lx "
|
|
|
|
"prev_ip=%lx npc=%lx\n", info->ip, info->prev_sp,
|
|
|
|
info->prev_ip, npc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void unwind_frame_init(struct unwind_frame_info *info, struct task_struct *t,
|
|
|
|
struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
memset(info, 0, sizeof(struct unwind_frame_info));
|
|
|
|
info->t = t;
|
|
|
|
info->sp = regs->gr[30];
|
|
|
|
info->ip = regs->iaoq[0];
|
|
|
|
info->rp = regs->gr[2];
|
|
|
|
info->r31 = regs->gr[31];
|
|
|
|
|
|
|
|
dbg("(%d) Start unwind from sp=%08lx ip=%08lx\n",
|
|
|
|
t ? (int)t->pid : -1, info->sp, info->ip);
|
|
|
|
}
|
|
|
|
|
|
|
|
void unwind_frame_init_from_blocked_task(struct unwind_frame_info *info, struct task_struct *t)
|
|
|
|
{
|
|
|
|
struct pt_regs *r = &t->thread.regs;
|
|
|
|
struct pt_regs *r2;
|
|
|
|
|
2008-12-18 06:57:34 +08:00
|
|
|
r2 = kmalloc(sizeof(struct pt_regs), GFP_ATOMIC);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!r2)
|
|
|
|
return;
|
|
|
|
*r2 = *r;
|
|
|
|
r2->gr[30] = r->ksp;
|
|
|
|
r2->iaoq[0] = r->kpc;
|
|
|
|
unwind_frame_init(info, t, r2);
|
|
|
|
kfree(r2);
|
|
|
|
}
|
|
|
|
|
2018-08-17 23:00:08 +08:00
|
|
|
#define get_parisc_stackpointer() ({ \
|
|
|
|
unsigned long sp; \
|
|
|
|
__asm__("copy %%r30, %0" : "=r"(sp)); \
|
|
|
|
(sp); \
|
|
|
|
})
|
|
|
|
|
|
|
|
void unwind_frame_init_task(struct unwind_frame_info *info,
|
|
|
|
struct task_struct *task, struct pt_regs *regs)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-08-17 23:00:08 +08:00
|
|
|
task = task ? task : current;
|
|
|
|
|
|
|
|
if (task == current) {
|
|
|
|
struct pt_regs r;
|
|
|
|
|
|
|
|
if (!regs) {
|
|
|
|
memset(&r, 0, sizeof(r));
|
|
|
|
r.iaoq[0] = _THIS_IP_;
|
|
|
|
r.gr[2] = _RET_IP_;
|
|
|
|
r.gr[30] = get_parisc_stackpointer();
|
|
|
|
regs = &r;
|
|
|
|
}
|
2018-10-16 14:21:48 +08:00
|
|
|
unwind_frame_init(info, task, regs);
|
2018-08-17 23:00:08 +08:00
|
|
|
} else {
|
|
|
|
unwind_frame_init_from_blocked_task(info, task);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int unwind_once(struct unwind_frame_info *next_frame)
|
|
|
|
{
|
|
|
|
unwind_frame_regs(next_frame);
|
|
|
|
|
|
|
|
if (next_frame->prev_sp == 0 ||
|
|
|
|
next_frame->prev_ip == 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
next_frame->sp = next_frame->prev_sp;
|
|
|
|
next_frame->ip = next_frame->prev_ip;
|
|
|
|
next_frame->prev_sp = 0;
|
|
|
|
next_frame->prev_ip = 0;
|
|
|
|
|
|
|
|
dbg("(%d) Continue unwind to sp=%08lx ip=%08lx\n",
|
|
|
|
next_frame->t ? (int)next_frame->t->pid : -1,
|
|
|
|
next_frame->sp, next_frame->ip);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int unwind_to_user(struct unwind_frame_info *info)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
do {
|
|
|
|
ret = unwind_once(info);
|
|
|
|
} while (!ret && !(info->ip & 3));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2009-10-26 05:48:36 +08:00
|
|
|
|
|
|
|
unsigned long return_address(unsigned int level)
|
|
|
|
{
|
|
|
|
struct unwind_frame_info info;
|
|
|
|
|
|
|
|
/* initialize unwind info */
|
2018-08-17 23:00:08 +08:00
|
|
|
unwind_frame_init_task(&info, current, NULL);
|
2009-10-26 05:48:36 +08:00
|
|
|
|
|
|
|
/* unwind stack */
|
2018-08-17 23:00:08 +08:00
|
|
|
level += 2;
|
2009-10-26 05:48:36 +08:00
|
|
|
do {
|
|
|
|
if (unwind_once(&info) < 0 || info.ip == 0)
|
|
|
|
return 0;
|
2013-12-01 04:23:20 +08:00
|
|
|
if (!kernel_text_address(info.ip))
|
2009-10-26 05:48:36 +08:00
|
|
|
return 0;
|
|
|
|
} while (info.ip && level--);
|
|
|
|
|
|
|
|
return info.ip;
|
|
|
|
}
|