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 */
|
2005-04-16 22:20:36 +00:00
|
|
|
#ifndef _ASM_GENERIC_SECTIONS_H_
|
|
|
|
#define _ASM_GENERIC_SECTIONS_H_
|
|
|
|
|
|
|
|
/* References to section boundaries */
|
|
|
|
|
2014-10-09 22:30:30 +00:00
|
|
|
#include <linux/compiler.h>
|
2016-01-16 00:58:18 +00:00
|
|
|
#include <linux/types.h>
|
2014-10-09 22:30:30 +00:00
|
|
|
|
vmlinux.lds: add comments for global variables and clean up useless declarations
The original goal of this patchset is to fix the bug reported by
https://bugzilla.kernel.org/show_bug.cgi?id=53501 Now it has also been
expanded to reduce common code used by memory initializion.
Patch 1-7:
1) add comments for global variables exported by vmlinux.lds
2) normalize global variables exported by vmlinux.lds
Patch 8:
Introduce helper functions mem_init_print_info() and
get_num_physpages()
Patch 9:
Avoid using global variable num_physpages at runtime
Patch 10:
Don't update num_physpages in memory_hotplug.c
Patch 11-40:
Modify arch mm initialization code to:
1) Simplify mem_init() by using mem_init_print_info()
2) Prepare for killing global variable num_physpages
Patch 41:
Kill the global variable num_physpages
With all patches applied, mem_init(), free_initmem(), free_initrd_mem()
could be as simple as below. This patch series has reduced about 1.2K
lines of code in total.
#ifndef CONFIG_DISCONTIGMEM
void __init
mem_init(void)
{
max_mapnr = max_low_pfn;
free_all_bootmem();
high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
mem_init_print_info(NULL);
}
#endif /* CONFIG_DISCONTIGMEM */
void
free_initmem(void)
{
free_initmem_default(-1);
}
#ifdef CONFIG_BLK_DEV_INITRD
void
free_initrd_mem(unsigned long start, unsigned long end)
{
free_reserved_area(start, end, -1, "initrd");
}
#endif
Due to hardware resource limitations, I have only tested this on x86_64.
And the messages reported on an x86_64 system are:
Log message before applying patches:
Memory: 7745676k/8910848k available (6934k kernel code, 836024k absent, 329148k reserved, 6343k data, 1012k init)
Log message after applying patches:
Memory: 7744624K/8074824K available (6969K kernel code, 1011K data, 2828K rodata, 1016K init, 9640K bss, 330200K reserved)
Great thanks to Vineet Gupta for testing on ARC.
This patch:
Document global variables exported from vmlinux.lds.
1) Add comments about usage guidelines for global variables exported
from vmlinux.lds.S.
2) Remove unused __initdata_begin[] and __initdata_end[].
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Vineet Gupta <vgupta@synopsys.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:03:33 +00:00
|
|
|
/*
|
|
|
|
* Usage guidelines:
|
|
|
|
* _text, _data: architecture specific, don't use them in arch-independent code
|
|
|
|
* [_stext, _etext]: contains .text.* sections, may also contain .rodata.*
|
|
|
|
* and/or .init.* sections
|
|
|
|
* [_sdata, _edata]: contains .data.* sections, may also contain .rodata.*
|
|
|
|
* and/or .init.* sections.
|
|
|
|
* [__start_rodata, __end_rodata]: contains .rodata.* sections
|
2017-03-31 22:11:58 +00:00
|
|
|
* [__start_ro_after_init, __end_ro_after_init]:
|
|
|
|
* contains .data..ro_after_init section
|
vmlinux.lds: add comments for global variables and clean up useless declarations
The original goal of this patchset is to fix the bug reported by
https://bugzilla.kernel.org/show_bug.cgi?id=53501 Now it has also been
expanded to reduce common code used by memory initializion.
Patch 1-7:
1) add comments for global variables exported by vmlinux.lds
2) normalize global variables exported by vmlinux.lds
Patch 8:
Introduce helper functions mem_init_print_info() and
get_num_physpages()
Patch 9:
Avoid using global variable num_physpages at runtime
Patch 10:
Don't update num_physpages in memory_hotplug.c
Patch 11-40:
Modify arch mm initialization code to:
1) Simplify mem_init() by using mem_init_print_info()
2) Prepare for killing global variable num_physpages
Patch 41:
Kill the global variable num_physpages
With all patches applied, mem_init(), free_initmem(), free_initrd_mem()
could be as simple as below. This patch series has reduced about 1.2K
lines of code in total.
#ifndef CONFIG_DISCONTIGMEM
void __init
mem_init(void)
{
max_mapnr = max_low_pfn;
free_all_bootmem();
high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
mem_init_print_info(NULL);
}
#endif /* CONFIG_DISCONTIGMEM */
void
free_initmem(void)
{
free_initmem_default(-1);
}
#ifdef CONFIG_BLK_DEV_INITRD
void
free_initrd_mem(unsigned long start, unsigned long end)
{
free_reserved_area(start, end, -1, "initrd");
}
#endif
Due to hardware resource limitations, I have only tested this on x86_64.
And the messages reported on an x86_64 system are:
Log message before applying patches:
Memory: 7745676k/8910848k available (6934k kernel code, 836024k absent, 329148k reserved, 6343k data, 1012k init)
Log message after applying patches:
Memory: 7744624K/8074824K available (6969K kernel code, 1011K data, 2828K rodata, 1016K init, 9640K bss, 330200K reserved)
Great thanks to Vineet Gupta for testing on ARC.
This patch:
Document global variables exported from vmlinux.lds.
1) Add comments about usage guidelines for global variables exported
from vmlinux.lds.S.
2) Remove unused __initdata_begin[] and __initdata_end[].
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Vineet Gupta <vgupta@synopsys.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:03:33 +00:00
|
|
|
* [__init_begin, __init_end]: contains .init.* sections, but .init.text.*
|
|
|
|
* may be out of this range on some architectures.
|
|
|
|
* [_sinittext, _einittext]: contains .init.text.* sections
|
|
|
|
* [__bss_start, __bss_stop]: contains BSS sections
|
|
|
|
*
|
|
|
|
* Following global variables are optional and may be unavailable on some
|
|
|
|
* architectures and/or kernel configurations.
|
|
|
|
* _text, _data
|
|
|
|
* __kprobes_text_start, __kprobes_text_end
|
|
|
|
* __entry_text_start, __entry_text_end
|
|
|
|
* __ctors_start, __ctors_end
|
2017-08-03 02:38:21 +00:00
|
|
|
* __irqentry_text_start, __irqentry_text_end
|
|
|
|
* __softirqentry_text_start, __softirqentry_text_end
|
sections: split dereference_function_descriptor()
There are two format specifiers to print out a pointer in symbolic
format: '%pS/%ps' and '%pF/%pf'. On most architectures, the two
mean exactly the same thing, but some architectures (ia64, ppc64,
parisc64) use an indirect pointer for C function pointers, where
the function pointer points to a function descriptor (which in
turn contains the actual pointer to the code). The '%pF/%pf, when
used appropriately, automatically does the appropriate function
descriptor dereference on such architectures.
The "when used appropriately" part is tricky. Basically this is
a subtle ABI detail, specific to some platforms, that made it to
the API level and people can be unaware of it and miss the whole
"we need to dereference the function" business out. [1] proves
that point (note that it fixes only '%pF' and '%pS', there might
be '%pf' and '%ps' cases as well).
It appears that we can handle everything within the affected
arches and make '%pS/%ps' smart enough to retire '%pF/%pf'.
Function descriptors live in .opd elf section and all affected
arches (ia64, ppc64, parisc64) handle it properly for kernel
and modules. So we, technically, can decide if the dereference
is needed by simply looking at the pointer: if it belongs to
.opd section then we need to dereference it.
The kernel and modules have their own .opd sections, obviously,
that's why we need to split dereference_function_descriptor()
and use separate kernel and module dereference arch callbacks.
This patch does the first step, it
a) adds dereference_kernel_function_descriptor() function.
b) adds a weak alias to dereference_module_function_descriptor()
function.
So, for the time being, we will have:
1) dereference_function_descriptor()
A generic function, that simply dereferences the pointer. There is
bunch of places that call it: kgdbts, init/main.c, extable, etc.
2) dereference_kernel_function_descriptor()
A function to call on kernel symbols that does kernel .opd section
address range test.
3) dereference_module_function_descriptor()
A function to call on modules' symbols that does modules' .opd
section address range test.
[1] https://marc.info/?l=linux-kernel&m=150472969730573
Link: http://lkml.kernel.org/r/20171109234830.5067-2-sergey.senozhatsky@gmail.com
To: Fenghua Yu <fenghua.yu@intel.com>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: Paul Mackerras <paulus@samba.org>
To: Michael Ellerman <mpe@ellerman.id.au>
To: James Bottomley <jejb@parisc-linux.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-ia64@vger.kernel.org
Cc: linux-parisc@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Tested-by: Tony Luck <tony.luck@intel.com> #ia64
Tested-by: Santosh Sivaraj <santosh@fossix.org> #powerpc
Tested-by: Helge Deller <deller@gmx.de> #parisc64
Signed-off-by: Petr Mladek <pmladek@suse.com>
2017-11-09 23:48:25 +00:00
|
|
|
* __start_opd, __end_opd
|
vmlinux.lds: add comments for global variables and clean up useless declarations
The original goal of this patchset is to fix the bug reported by
https://bugzilla.kernel.org/show_bug.cgi?id=53501 Now it has also been
expanded to reduce common code used by memory initializion.
Patch 1-7:
1) add comments for global variables exported by vmlinux.lds
2) normalize global variables exported by vmlinux.lds
Patch 8:
Introduce helper functions mem_init_print_info() and
get_num_physpages()
Patch 9:
Avoid using global variable num_physpages at runtime
Patch 10:
Don't update num_physpages in memory_hotplug.c
Patch 11-40:
Modify arch mm initialization code to:
1) Simplify mem_init() by using mem_init_print_info()
2) Prepare for killing global variable num_physpages
Patch 41:
Kill the global variable num_physpages
With all patches applied, mem_init(), free_initmem(), free_initrd_mem()
could be as simple as below. This patch series has reduced about 1.2K
lines of code in total.
#ifndef CONFIG_DISCONTIGMEM
void __init
mem_init(void)
{
max_mapnr = max_low_pfn;
free_all_bootmem();
high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
mem_init_print_info(NULL);
}
#endif /* CONFIG_DISCONTIGMEM */
void
free_initmem(void)
{
free_initmem_default(-1);
}
#ifdef CONFIG_BLK_DEV_INITRD
void
free_initrd_mem(unsigned long start, unsigned long end)
{
free_reserved_area(start, end, -1, "initrd");
}
#endif
Due to hardware resource limitations, I have only tested this on x86_64.
And the messages reported on an x86_64 system are:
Log message before applying patches:
Memory: 7745676k/8910848k available (6934k kernel code, 836024k absent, 329148k reserved, 6343k data, 1012k init)
Log message after applying patches:
Memory: 7744624K/8074824K available (6969K kernel code, 1011K data, 2828K rodata, 1016K init, 9640K bss, 330200K reserved)
Great thanks to Vineet Gupta for testing on ARC.
This patch:
Document global variables exported from vmlinux.lds.
1) Add comments about usage guidelines for global variables exported
from vmlinux.lds.S.
2) Remove unused __initdata_begin[] and __initdata_end[].
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Vineet Gupta <vgupta@synopsys.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-07-03 22:03:33 +00:00
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
extern char _text[], _stext[], _etext[];
|
|
|
|
extern char _data[], _sdata[], _edata[];
|
|
|
|
extern char __bss_start[], __bss_stop[];
|
|
|
|
extern char __init_begin[], __init_end[];
|
|
|
|
extern char _sinittext[], _einittext[];
|
2017-03-31 22:11:58 +00:00
|
|
|
extern char __start_ro_after_init[], __end_ro_after_init[];
|
2005-04-16 22:20:36 +00:00
|
|
|
extern char _end[];
|
2009-01-13 11:41:35 +00:00
|
|
|
extern char __per_cpu_load[], __per_cpu_start[], __per_cpu_end[];
|
2005-09-06 22:19:26 +00:00
|
|
|
extern char __kprobes_text_start[], __kprobes_text_end[];
|
2011-03-07 18:10:39 +00:00
|
|
|
extern char __entry_text_start[], __entry_text_end[];
|
2006-07-01 11:36:30 +00:00
|
|
|
extern char __start_rodata[], __end_rodata[];
|
2017-08-03 02:38:21 +00:00
|
|
|
extern char __irqentry_text_start[], __irqentry_text_end[];
|
|
|
|
extern char __softirqentry_text_start[], __softirqentry_text_end[];
|
2017-11-17 23:27:03 +00:00
|
|
|
extern char __start_once[], __end_once[];
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-06-17 23:28:03 +00:00
|
|
|
/* Start and end of .ctors section - used for constructor calls. */
|
|
|
|
extern char __ctors_start[], __ctors_end[];
|
|
|
|
|
sections: split dereference_function_descriptor()
There are two format specifiers to print out a pointer in symbolic
format: '%pS/%ps' and '%pF/%pf'. On most architectures, the two
mean exactly the same thing, but some architectures (ia64, ppc64,
parisc64) use an indirect pointer for C function pointers, where
the function pointer points to a function descriptor (which in
turn contains the actual pointer to the code). The '%pF/%pf, when
used appropriately, automatically does the appropriate function
descriptor dereference on such architectures.
The "when used appropriately" part is tricky. Basically this is
a subtle ABI detail, specific to some platforms, that made it to
the API level and people can be unaware of it and miss the whole
"we need to dereference the function" business out. [1] proves
that point (note that it fixes only '%pF' and '%pS', there might
be '%pf' and '%ps' cases as well).
It appears that we can handle everything within the affected
arches and make '%pS/%ps' smart enough to retire '%pF/%pf'.
Function descriptors live in .opd elf section and all affected
arches (ia64, ppc64, parisc64) handle it properly for kernel
and modules. So we, technically, can decide if the dereference
is needed by simply looking at the pointer: if it belongs to
.opd section then we need to dereference it.
The kernel and modules have their own .opd sections, obviously,
that's why we need to split dereference_function_descriptor()
and use separate kernel and module dereference arch callbacks.
This patch does the first step, it
a) adds dereference_kernel_function_descriptor() function.
b) adds a weak alias to dereference_module_function_descriptor()
function.
So, for the time being, we will have:
1) dereference_function_descriptor()
A generic function, that simply dereferences the pointer. There is
bunch of places that call it: kgdbts, init/main.c, extable, etc.
2) dereference_kernel_function_descriptor()
A function to call on kernel symbols that does kernel .opd section
address range test.
3) dereference_module_function_descriptor()
A function to call on modules' symbols that does modules' .opd
section address range test.
[1] https://marc.info/?l=linux-kernel&m=150472969730573
Link: http://lkml.kernel.org/r/20171109234830.5067-2-sergey.senozhatsky@gmail.com
To: Fenghua Yu <fenghua.yu@intel.com>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: Paul Mackerras <paulus@samba.org>
To: Michael Ellerman <mpe@ellerman.id.au>
To: James Bottomley <jejb@parisc-linux.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-ia64@vger.kernel.org
Cc: linux-parisc@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Tested-by: Tony Luck <tony.luck@intel.com> #ia64
Tested-by: Santosh Sivaraj <santosh@fossix.org> #powerpc
Tested-by: Helge Deller <deller@gmx.de> #parisc64
Signed-off-by: Petr Mladek <pmladek@suse.com>
2017-11-09 23:48:25 +00:00
|
|
|
/* Start and end of .opd section - used for function descriptors. */
|
|
|
|
extern char __start_opd[], __end_opd[];
|
|
|
|
|
2020-03-09 21:47:17 +00:00
|
|
|
/* Start and end of instrumentation protected text section */
|
|
|
|
extern char __noinstr_text_start[], __noinstr_text_end[];
|
|
|
|
|
2014-10-09 22:30:30 +00:00
|
|
|
extern __visible const void __nosave_begin, __nosave_end;
|
|
|
|
|
sections: split dereference_function_descriptor()
There are two format specifiers to print out a pointer in symbolic
format: '%pS/%ps' and '%pF/%pf'. On most architectures, the two
mean exactly the same thing, but some architectures (ia64, ppc64,
parisc64) use an indirect pointer for C function pointers, where
the function pointer points to a function descriptor (which in
turn contains the actual pointer to the code). The '%pF/%pf, when
used appropriately, automatically does the appropriate function
descriptor dereference on such architectures.
The "when used appropriately" part is tricky. Basically this is
a subtle ABI detail, specific to some platforms, that made it to
the API level and people can be unaware of it and miss the whole
"we need to dereference the function" business out. [1] proves
that point (note that it fixes only '%pF' and '%pS', there might
be '%pf' and '%ps' cases as well).
It appears that we can handle everything within the affected
arches and make '%pS/%ps' smart enough to retire '%pF/%pf'.
Function descriptors live in .opd elf section and all affected
arches (ia64, ppc64, parisc64) handle it properly for kernel
and modules. So we, technically, can decide if the dereference
is needed by simply looking at the pointer: if it belongs to
.opd section then we need to dereference it.
The kernel and modules have their own .opd sections, obviously,
that's why we need to split dereference_function_descriptor()
and use separate kernel and module dereference arch callbacks.
This patch does the first step, it
a) adds dereference_kernel_function_descriptor() function.
b) adds a weak alias to dereference_module_function_descriptor()
function.
So, for the time being, we will have:
1) dereference_function_descriptor()
A generic function, that simply dereferences the pointer. There is
bunch of places that call it: kgdbts, init/main.c, extable, etc.
2) dereference_kernel_function_descriptor()
A function to call on kernel symbols that does kernel .opd section
address range test.
3) dereference_module_function_descriptor()
A function to call on modules' symbols that does modules' .opd
section address range test.
[1] https://marc.info/?l=linux-kernel&m=150472969730573
Link: http://lkml.kernel.org/r/20171109234830.5067-2-sergey.senozhatsky@gmail.com
To: Fenghua Yu <fenghua.yu@intel.com>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: Paul Mackerras <paulus@samba.org>
To: Michael Ellerman <mpe@ellerman.id.au>
To: James Bottomley <jejb@parisc-linux.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-ia64@vger.kernel.org
Cc: linux-parisc@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Tested-by: Tony Luck <tony.luck@intel.com> #ia64
Tested-by: Santosh Sivaraj <santosh@fossix.org> #powerpc
Tested-by: Helge Deller <deller@gmx.de> #parisc64
Signed-off-by: Petr Mladek <pmladek@suse.com>
2017-11-09 23:48:25 +00:00
|
|
|
/* Function descriptor handling (if any). Override in asm/sections.h */
|
2022-02-15 12:41:02 +00:00
|
|
|
#ifdef CONFIG_HAVE_FUNCTION_DESCRIPTORS
|
2022-02-15 12:41:04 +00:00
|
|
|
void *dereference_function_descriptor(void *ptr);
|
|
|
|
void *dereference_kernel_function_descriptor(void *ptr);
|
2022-02-15 12:41:02 +00:00
|
|
|
#else
|
2020-08-09 05:30:06 +00:00
|
|
|
#define dereference_function_descriptor(p) ((void *)(p))
|
|
|
|
#define dereference_kernel_function_descriptor(p) ((void *)(p))
|
2022-02-15 12:41:03 +00:00
|
|
|
|
|
|
|
/* An address is simply the address of the function. */
|
|
|
|
typedef struct {
|
|
|
|
unsigned long addr;
|
|
|
|
} func_desc_t;
|
2008-09-04 01:43:36 +00:00
|
|
|
#endif
|
|
|
|
|
2022-02-15 12:41:02 +00:00
|
|
|
static inline bool have_function_descriptors(void)
|
|
|
|
{
|
|
|
|
return IS_ENABLED(CONFIG_HAVE_FUNCTION_DESCRIPTORS);
|
|
|
|
}
|
|
|
|
|
2016-01-16 00:58:18 +00:00
|
|
|
/**
|
|
|
|
* memory_contains - checks if an object is contained within a memory region
|
|
|
|
* @begin: virtual address of the beginning of the memory region
|
|
|
|
* @end: virtual address of the end of the memory region
|
|
|
|
* @virt: virtual address of the memory object
|
|
|
|
* @size: size of the memory object
|
|
|
|
*
|
|
|
|
* Returns: true if the object specified by @virt and @size is entirely
|
|
|
|
* contained within the memory region defined by @begin and @end, false
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
static inline bool memory_contains(void *begin, void *end, void *virt,
|
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
return virt >= begin && virt + size <= end;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* memory_intersects - checks if the region occupied by an object intersects
|
|
|
|
* with another memory region
|
2022-08-19 08:11:45 +00:00
|
|
|
* @begin: virtual address of the beginning of the memory region
|
2016-01-16 00:58:18 +00:00
|
|
|
* @end: virtual address of the end of the memory region
|
|
|
|
* @virt: virtual address of the memory object
|
|
|
|
* @size: size of the memory object
|
|
|
|
*
|
|
|
|
* Returns: true if an object's memory region, specified by @virt and @size,
|
|
|
|
* intersects with the region specified by @begin and @end, false otherwise.
|
|
|
|
*/
|
|
|
|
static inline bool memory_intersects(void *begin, void *end, void *virt,
|
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
void *vend = virt + size;
|
|
|
|
|
2022-08-19 08:11:45 +00:00
|
|
|
if (virt < end && vend > begin)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2016-01-16 00:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* init_section_contains - checks if an object is contained within the init
|
|
|
|
* section
|
|
|
|
* @virt: virtual address of the memory object
|
|
|
|
* @size: size of the memory object
|
|
|
|
*
|
|
|
|
* Returns: true if the object specified by @virt and @size is entirely
|
|
|
|
* contained within the init section, false otherwise.
|
|
|
|
*/
|
|
|
|
static inline bool init_section_contains(void *virt, size_t size)
|
|
|
|
{
|
|
|
|
return memory_contains(__init_begin, __init_end, virt, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* init_section_intersects - checks if the region occupied by an object
|
|
|
|
* intersects with the init section
|
|
|
|
* @virt: virtual address of the memory object
|
|
|
|
* @size: size of the memory object
|
|
|
|
*
|
|
|
|
* Returns: true if an object's memory region, specified by @virt and @size,
|
|
|
|
* intersects with the init section, false otherwise.
|
|
|
|
*/
|
|
|
|
static inline bool init_section_intersects(void *virt, size_t size)
|
|
|
|
{
|
|
|
|
return memory_intersects(__init_begin, __init_end, virt, size);
|
|
|
|
}
|
|
|
|
|
2021-11-09 02:33:51 +00:00
|
|
|
/**
|
|
|
|
* is_kernel_core_data - checks if the pointer address is located in the
|
2021-11-22 14:24:56 +00:00
|
|
|
* .data or .bss section
|
2021-11-09 02:33:51 +00:00
|
|
|
*
|
|
|
|
* @addr: address to check
|
|
|
|
*
|
2021-11-22 14:24:56 +00:00
|
|
|
* Returns: true if the address is located in .data or .bss, false otherwise.
|
2021-11-09 02:33:51 +00:00
|
|
|
* Note: On some archs it may return true for core RODATA, and false
|
|
|
|
* for others. But will always be true for core RW data.
|
|
|
|
*/
|
|
|
|
static inline bool is_kernel_core_data(unsigned long addr)
|
|
|
|
{
|
2021-11-22 14:24:56 +00:00
|
|
|
if (addr >= (unsigned long)_sdata && addr < (unsigned long)_edata)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (addr >= (unsigned long)__bss_start &&
|
|
|
|
addr < (unsigned long)__bss_stop)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2021-11-09 02:33:51 +00:00
|
|
|
}
|
|
|
|
|
2018-10-14 15:20:08 +00:00
|
|
|
/**
|
|
|
|
* is_kernel_rodata - checks if the pointer address is located in the
|
|
|
|
* .rodata section
|
|
|
|
*
|
|
|
|
* @addr: address to check
|
|
|
|
*
|
|
|
|
* Returns: true if the address is located in .rodata, false otherwise.
|
|
|
|
*/
|
|
|
|
static inline bool is_kernel_rodata(unsigned long addr)
|
|
|
|
{
|
|
|
|
return addr >= (unsigned long)__start_rodata &&
|
|
|
|
addr < (unsigned long)__end_rodata;
|
|
|
|
}
|
|
|
|
|
2024-03-13 18:01:03 +00:00
|
|
|
static inline bool is_kernel_ro_after_init(unsigned long addr)
|
|
|
|
{
|
|
|
|
return addr >= (unsigned long)__start_ro_after_init &&
|
|
|
|
addr < (unsigned long)__end_ro_after_init;
|
|
|
|
}
|
2021-11-09 02:33:54 +00:00
|
|
|
/**
|
|
|
|
* is_kernel_inittext - checks if the pointer address is located in the
|
|
|
|
* .init.text section
|
|
|
|
*
|
|
|
|
* @addr: address to check
|
|
|
|
*
|
|
|
|
* Returns: true if the address is located in .init.text, false otherwise.
|
|
|
|
*/
|
|
|
|
static inline bool is_kernel_inittext(unsigned long addr)
|
|
|
|
{
|
|
|
|
return addr >= (unsigned long)_sinittext &&
|
|
|
|
addr < (unsigned long)_einittext;
|
|
|
|
}
|
|
|
|
|
2021-11-09 02:34:02 +00:00
|
|
|
/**
|
|
|
|
* __is_kernel_text - checks if the pointer address is located in the
|
|
|
|
* .text section
|
|
|
|
*
|
|
|
|
* @addr: address to check
|
|
|
|
*
|
|
|
|
* Returns: true if the address is located in .text, false otherwise.
|
|
|
|
* Note: an internal helper, only check the range of _stext to _etext.
|
|
|
|
*/
|
|
|
|
static inline bool __is_kernel_text(unsigned long addr)
|
|
|
|
{
|
|
|
|
return addr >= (unsigned long)_stext &&
|
|
|
|
addr < (unsigned long)_etext;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* __is_kernel - checks if the pointer address is located in the kernel range
|
|
|
|
*
|
|
|
|
* @addr: address to check
|
|
|
|
*
|
|
|
|
* Returns: true if the address is located in the kernel range, false otherwise.
|
2022-01-07 00:13:02 +00:00
|
|
|
* Note: an internal helper, check the range of _stext to _end,
|
|
|
|
* and range from __init_begin to __init_end, which can be outside
|
|
|
|
* of the _stext to _end range.
|
2021-11-09 02:34:02 +00:00
|
|
|
*/
|
|
|
|
static inline bool __is_kernel(unsigned long addr)
|
|
|
|
{
|
2022-01-07 00:13:02 +00:00
|
|
|
return ((addr >= (unsigned long)_stext &&
|
|
|
|
addr < (unsigned long)_end) ||
|
|
|
|
(addr >= (unsigned long)__init_begin &&
|
|
|
|
addr < (unsigned long)__init_end));
|
2021-11-09 02:34:02 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif /* _ASM_GENERIC_SECTIONS_H_ */
|