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 15:07:57 +01:00
// SPDX-License-Identifier: GPL-2.0
2009-06-12 10:26:44 +02:00
/*
* Dynamic function tracer architecture backend .
*
2014-09-03 13:26:23 +02:00
* Copyright IBM Corp . 2009 , 2014
2009-06-12 10:26:44 +02:00
*
2022-01-28 12:10:57 +01:00
* Author ( s ) : Martin Schwidefsky < schwidefsky @ de . ibm . com >
2009-06-12 10:26:44 +02:00
*/
2014-10-15 12:17:38 +02:00
# include <linux/moduleloader.h>
2009-06-12 10:26:46 +02:00
# include <linux/hardirq.h>
2009-06-12 10:26:44 +02:00
# include <linux/uaccess.h>
# include <linux/ftrace.h>
# include <linux/kernel.h>
# include <linux/types.h>
2011-01-05 12:48:11 +01:00
# include <linux/kprobes.h>
2009-06-12 10:26:47 +02:00
# include <trace/syscall.h>
2010-02-26 22:37:43 +01:00
# include <asm/asm-offsets.h>
2021-10-01 14:21:43 +02:00
# include <asm/text-patching.h>
2014-10-15 12:17:38 +02:00
# include <asm/cacheflush.h>
s390/ftrace: implement hotpatching
s390 allows hotpatching the mask of a conditional jump instruction.
Make use of this feature in order to avoid the expensive stop_machine()
call.
The new trampolines are split in 3 stages:
- A first stage is a 6-byte relative conditional long branch located at
each function's entry point. Its offset always points to the second
stage for the corresponding function, and its mask is either all 0s
(ftrace off) or all 1s (ftrace on). The code for flipping the mask is
borrowed from ftrace_{enable,disable}_ftrace_graph_caller. After
flipping, ftrace_arch_code_modify_post_process() syncs with all the
other CPUs by sending SIGPs.
- Second stages for vmlinux are stored in a separate part of the .text
section reserved by the linker script, and in dynamically allocated
memory for modules. This prevents the icache pollution. The total
size of second stages is about 1.5% of that of the kernel image.
Putting second stages in the .bss section is possible and decreases
the size of the non-compressed vmlinux, but splits the kernel 1:1
mapping, which is a bad tradeoff.
Each second stage contains a call to the third stage, a pointer to
the part of the intercepted function right after the first stage, and
a pointer to an interceptor function (e.g. ftrace_caller).
Second stages are 8-byte aligned for the future direct calls
implementation.
- There are only two copies of the third stage: in the .text section
for vmlinux and in dynamically allocated memory for modules. It can be
an expoline, which is relatively large, so inlining it into each
second stage is prohibitively expensive.
As a result of this organization, phoronix-test-suite with ftrace off
does not show any performance degradation.
Suggested-by: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Vasily Gorbik <gor@linux.ibm.com>
Co-developed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20210728212546.128248-3-iii@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2021-07-28 23:25:46 +02:00
# include <asm/ftrace.lds.h>
# include <asm/nospec-branch.h>
2017-05-08 15:58:08 -07:00
# include <asm/set_memory.h>
2013-09-06 19:10:48 +02:00
# include "entry.h"
s390/ftrace: implement hotpatching
s390 allows hotpatching the mask of a conditional jump instruction.
Make use of this feature in order to avoid the expensive stop_machine()
call.
The new trampolines are split in 3 stages:
- A first stage is a 6-byte relative conditional long branch located at
each function's entry point. Its offset always points to the second
stage for the corresponding function, and its mask is either all 0s
(ftrace off) or all 1s (ftrace on). The code for flipping the mask is
borrowed from ftrace_{enable,disable}_ftrace_graph_caller. After
flipping, ftrace_arch_code_modify_post_process() syncs with all the
other CPUs by sending SIGPs.
- Second stages for vmlinux are stored in a separate part of the .text
section reserved by the linker script, and in dynamically allocated
memory for modules. This prevents the icache pollution. The total
size of second stages is about 1.5% of that of the kernel image.
Putting second stages in the .bss section is possible and decreases
the size of the non-compressed vmlinux, but splits the kernel 1:1
mapping, which is a bad tradeoff.
Each second stage contains a call to the third stage, a pointer to
the part of the intercepted function right after the first stage, and
a pointer to an interceptor function (e.g. ftrace_caller).
Second stages are 8-byte aligned for the future direct calls
implementation.
- There are only two copies of the third stage: in the .text section
for vmlinux and in dynamically allocated memory for modules. It can be
an expoline, which is relatively large, so inlining it into each
second stage is prohibitively expensive.
As a result of this organization, phoronix-test-suite with ftrace off
does not show any performance degradation.
Suggested-by: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Vasily Gorbik <gor@linux.ibm.com>
Co-developed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20210728212546.128248-3-iii@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2021-07-28 23:25:46 +02:00
# include "ftrace.h"
2009-06-12 10:26:44 +02:00
2011-01-05 12:48:11 +01:00
/*
2020-11-12 15:54:47 +01:00
* To generate function prologue either gcc ' s hotpatch feature ( since gcc 4.8 )
* or a combination of - pg - mrecord - mcount - mnop - mcount - mfentry flags
* ( since gcc 9 / clang 10 ) is used .
* In both cases the original and also the disabled function prologue contains
* only a single six byte instruction and looks like this :
* > brcl 0 , 0 # offset 0
* To enable ftrace the code gets patched like above and afterwards looks
* like this :
2014-10-15 12:17:38 +02:00
* > brasl % r0 , ftrace_caller # offset 0
2020-11-12 15:54:47 +01:00
*
* The instruction will be patched by ftrace_make_call / ftrace_make_nop .
2014-09-03 13:26:23 +02:00
* The ftrace function gets called with a non - standard C function call ABI
* where r0 contains the return address . It is also expected that the called
* function only clobbers r0 and r1 , but restores r2 - r15 .
2014-10-15 12:17:38 +02:00
* For module code we can ' t directly jump to ftrace caller , but need a
* trampoline ( ftrace_plt ) , which clobbers also r1 .
2011-01-05 12:48:11 +01:00
*/
2009-06-12 10:26:44 +02:00
2021-06-25 23:50:07 +02:00
void * ftrace_func __read_mostly = ftrace_stub ;
s390/ftrace: implement hotpatching
s390 allows hotpatching the mask of a conditional jump instruction.
Make use of this feature in order to avoid the expensive stop_machine()
call.
The new trampolines are split in 3 stages:
- A first stage is a 6-byte relative conditional long branch located at
each function's entry point. Its offset always points to the second
stage for the corresponding function, and its mask is either all 0s
(ftrace off) or all 1s (ftrace on). The code for flipping the mask is
borrowed from ftrace_{enable,disable}_ftrace_graph_caller. After
flipping, ftrace_arch_code_modify_post_process() syncs with all the
other CPUs by sending SIGPs.
- Second stages for vmlinux are stored in a separate part of the .text
section reserved by the linker script, and in dynamically allocated
memory for modules. This prevents the icache pollution. The total
size of second stages is about 1.5% of that of the kernel image.
Putting second stages in the .bss section is possible and decreases
the size of the non-compressed vmlinux, but splits the kernel 1:1
mapping, which is a bad tradeoff.
Each second stage contains a call to the third stage, a pointer to
the part of the intercepted function right after the first stage, and
a pointer to an interceptor function (e.g. ftrace_caller).
Second stages are 8-byte aligned for the future direct calls
implementation.
- There are only two copies of the third stage: in the .text section
for vmlinux and in dynamically allocated memory for modules. It can be
an expoline, which is relatively large, so inlining it into each
second stage is prohibitively expensive.
As a result of this organization, phoronix-test-suite with ftrace off
does not show any performance degradation.
Suggested-by: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Vasily Gorbik <gor@linux.ibm.com>
Co-developed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20210728212546.128248-3-iii@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2021-07-28 23:25:46 +02:00
struct ftrace_insn {
u16 opc ;
s32 disp ;
} __packed ;
asm (
" .align 16 \n "
" ftrace_shared_hotpatch_trampoline_br: \n "
" lmg %r0,%r1,2(%r1) \n "
" br %r1 \n "
" ftrace_shared_hotpatch_trampoline_br_end: \n "
) ;
# ifdef CONFIG_EXPOLINE
asm (
" .align 16 \n "
" ftrace_shared_hotpatch_trampoline_exrl: \n "
" lmg %r0,%r1,2(%r1) \n "
2022-02-25 10:39:02 +01:00
" exrl %r0,0f \n "
s390/ftrace: implement hotpatching
s390 allows hotpatching the mask of a conditional jump instruction.
Make use of this feature in order to avoid the expensive stop_machine()
call.
The new trampolines are split in 3 stages:
- A first stage is a 6-byte relative conditional long branch located at
each function's entry point. Its offset always points to the second
stage for the corresponding function, and its mask is either all 0s
(ftrace off) or all 1s (ftrace on). The code for flipping the mask is
borrowed from ftrace_{enable,disable}_ftrace_graph_caller. After
flipping, ftrace_arch_code_modify_post_process() syncs with all the
other CPUs by sending SIGPs.
- Second stages for vmlinux are stored in a separate part of the .text
section reserved by the linker script, and in dynamically allocated
memory for modules. This prevents the icache pollution. The total
size of second stages is about 1.5% of that of the kernel image.
Putting second stages in the .bss section is possible and decreases
the size of the non-compressed vmlinux, but splits the kernel 1:1
mapping, which is a bad tradeoff.
Each second stage contains a call to the third stage, a pointer to
the part of the intercepted function right after the first stage, and
a pointer to an interceptor function (e.g. ftrace_caller).
Second stages are 8-byte aligned for the future direct calls
implementation.
- There are only two copies of the third stage: in the .text section
for vmlinux and in dynamically allocated memory for modules. It can be
an expoline, which is relatively large, so inlining it into each
second stage is prohibitively expensive.
As a result of this organization, phoronix-test-suite with ftrace off
does not show any performance degradation.
Suggested-by: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Vasily Gorbik <gor@linux.ibm.com>
Co-developed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20210728212546.128248-3-iii@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2021-07-28 23:25:46 +02:00
" j . \n "
" 0: br %r1 \n "
" ftrace_shared_hotpatch_trampoline_exrl_end: \n "
) ;
# endif /* CONFIG_EXPOLINE */
# ifdef CONFIG_MODULES
static char * ftrace_plt ;
# endif /* CONFIG_MODULES */
static const char * ftrace_shared_hotpatch_trampoline ( const char * * end )
{
const char * tstart , * tend ;
tstart = ftrace_shared_hotpatch_trampoline_br ;
tend = ftrace_shared_hotpatch_trampoline_br_end ;
# ifdef CONFIG_EXPOLINE
if ( ! nospec_disable ) {
2022-02-24 22:43:31 +01:00
tstart = ftrace_shared_hotpatch_trampoline_exrl ;
tend = ftrace_shared_hotpatch_trampoline_exrl_end ;
s390/ftrace: implement hotpatching
s390 allows hotpatching the mask of a conditional jump instruction.
Make use of this feature in order to avoid the expensive stop_machine()
call.
The new trampolines are split in 3 stages:
- A first stage is a 6-byte relative conditional long branch located at
each function's entry point. Its offset always points to the second
stage for the corresponding function, and its mask is either all 0s
(ftrace off) or all 1s (ftrace on). The code for flipping the mask is
borrowed from ftrace_{enable,disable}_ftrace_graph_caller. After
flipping, ftrace_arch_code_modify_post_process() syncs with all the
other CPUs by sending SIGPs.
- Second stages for vmlinux are stored in a separate part of the .text
section reserved by the linker script, and in dynamically allocated
memory for modules. This prevents the icache pollution. The total
size of second stages is about 1.5% of that of the kernel image.
Putting second stages in the .bss section is possible and decreases
the size of the non-compressed vmlinux, but splits the kernel 1:1
mapping, which is a bad tradeoff.
Each second stage contains a call to the third stage, a pointer to
the part of the intercepted function right after the first stage, and
a pointer to an interceptor function (e.g. ftrace_caller).
Second stages are 8-byte aligned for the future direct calls
implementation.
- There are only two copies of the third stage: in the .text section
for vmlinux and in dynamically allocated memory for modules. It can be
an expoline, which is relatively large, so inlining it into each
second stage is prohibitively expensive.
As a result of this organization, phoronix-test-suite with ftrace off
does not show any performance degradation.
Suggested-by: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Vasily Gorbik <gor@linux.ibm.com>
Co-developed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20210728212546.128248-3-iii@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2021-07-28 23:25:46 +02:00
}
# endif /* CONFIG_EXPOLINE */
if ( end )
* end = tend ;
return tstart ;
}
bool ftrace_need_init_nop ( void )
{
2021-09-13 16:08:33 +02:00
return true ;
s390/ftrace: implement hotpatching
s390 allows hotpatching the mask of a conditional jump instruction.
Make use of this feature in order to avoid the expensive stop_machine()
call.
The new trampolines are split in 3 stages:
- A first stage is a 6-byte relative conditional long branch located at
each function's entry point. Its offset always points to the second
stage for the corresponding function, and its mask is either all 0s
(ftrace off) or all 1s (ftrace on). The code for flipping the mask is
borrowed from ftrace_{enable,disable}_ftrace_graph_caller. After
flipping, ftrace_arch_code_modify_post_process() syncs with all the
other CPUs by sending SIGPs.
- Second stages for vmlinux are stored in a separate part of the .text
section reserved by the linker script, and in dynamically allocated
memory for modules. This prevents the icache pollution. The total
size of second stages is about 1.5% of that of the kernel image.
Putting second stages in the .bss section is possible and decreases
the size of the non-compressed vmlinux, but splits the kernel 1:1
mapping, which is a bad tradeoff.
Each second stage contains a call to the third stage, a pointer to
the part of the intercepted function right after the first stage, and
a pointer to an interceptor function (e.g. ftrace_caller).
Second stages are 8-byte aligned for the future direct calls
implementation.
- There are only two copies of the third stage: in the .text section
for vmlinux and in dynamically allocated memory for modules. It can be
an expoline, which is relatively large, so inlining it into each
second stage is prohibitively expensive.
As a result of this organization, phoronix-test-suite with ftrace off
does not show any performance degradation.
Suggested-by: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Vasily Gorbik <gor@linux.ibm.com>
Co-developed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20210728212546.128248-3-iii@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2021-07-28 23:25:46 +02:00
}
int ftrace_init_nop ( struct module * mod , struct dyn_ftrace * rec )
{
static struct ftrace_hotpatch_trampoline * next_vmlinux_trampoline =
__ftrace_hotpatch_trampolines_start ;
static const char orig [ 6 ] = { 0xc0 , 0x04 , 0x00 , 0x00 , 0x00 , 0x00 } ;
static struct ftrace_hotpatch_trampoline * trampoline ;
struct ftrace_hotpatch_trampoline * * next_trampoline ;
struct ftrace_hotpatch_trampoline * trampolines_end ;
struct ftrace_hotpatch_trampoline tmp ;
struct ftrace_insn * insn ;
const char * shared ;
s32 disp ;
BUILD_BUG_ON ( sizeof ( struct ftrace_hotpatch_trampoline ) ! =
SIZEOF_FTRACE_HOTPATCH_TRAMPOLINE ) ;
next_trampoline = & next_vmlinux_trampoline ;
trampolines_end = __ftrace_hotpatch_trampolines_end ;
shared = ftrace_shared_hotpatch_trampoline ( NULL ) ;
# ifdef CONFIG_MODULES
if ( mod ) {
next_trampoline = & mod - > arch . next_trampoline ;
trampolines_end = mod - > arch . trampolines_end ;
shared = ftrace_plt ;
}
# endif
if ( WARN_ON_ONCE ( * next_trampoline > = trampolines_end ) )
return - ENOMEM ;
trampoline = ( * next_trampoline ) + + ;
/* Check for the compiler-generated fentry nop (brcl 0, .). */
if ( WARN_ON_ONCE ( memcmp ( ( const void * ) rec - > ip , & orig , sizeof ( orig ) ) ) )
return - EINVAL ;
/* Generate the trampoline. */
tmp . brasl_opc = 0xc015 ; /* brasl %r1, shared */
tmp . brasl_disp = ( shared - ( const char * ) & trampoline - > brasl_opc ) / 2 ;
tmp . interceptor = FTRACE_ADDR ;
tmp . rest_of_intercepted_function = rec - > ip + sizeof ( struct ftrace_insn ) ;
s390_kernel_write ( trampoline , & tmp , sizeof ( tmp ) ) ;
/* Generate a jump to the trampoline. */
disp = ( ( char * ) trampoline - ( char * ) rec - > ip ) / 2 ;
insn = ( struct ftrace_insn * ) rec - > ip ;
s390_kernel_write ( & insn - > disp , & disp , sizeof ( disp ) ) ;
return 0 ;
}
2009-06-12 10:26:44 +02:00
2022-02-23 13:02:59 +01:00
static struct ftrace_hotpatch_trampoline * ftrace_get_trampoline ( struct dyn_ftrace * rec )
{
struct ftrace_hotpatch_trampoline * trampoline ;
struct ftrace_insn insn ;
s64 disp ;
u16 opc ;
if ( copy_from_kernel_nofault ( & insn , ( void * ) rec - > ip , sizeof ( insn ) ) )
return ERR_PTR ( - EFAULT ) ;
disp = ( s64 ) insn . disp * 2 ;
trampoline = ( void * ) ( rec - > ip + disp ) ;
if ( get_kernel_nofault ( opc , & trampoline - > brasl_opc ) )
return ERR_PTR ( - EFAULT ) ;
if ( opc ! = 0xc015 )
return ERR_PTR ( - EINVAL ) ;
return trampoline ;
}
2014-08-15 13:01:46 +02:00
int ftrace_modify_call ( struct dyn_ftrace * rec , unsigned long old_addr ,
unsigned long addr )
{
2022-02-23 13:02:59 +01:00
struct ftrace_hotpatch_trampoline * trampoline ;
u64 old ;
trampoline = ftrace_get_trampoline ( rec ) ;
if ( IS_ERR ( trampoline ) )
return PTR_ERR ( trampoline ) ;
if ( get_kernel_nofault ( old , & trampoline - > interceptor ) )
return - EFAULT ;
if ( old ! = old_addr )
return - EINVAL ;
s390_kernel_write ( & trampoline - > interceptor , & addr , sizeof ( addr ) ) ;
2014-08-15 13:01:46 +02:00
return 0 ;
}
2009-06-12 10:26:44 +02:00
2022-01-23 20:20:09 +01:00
static int ftrace_patch_branch_mask ( void * addr , u16 expected , bool enable )
s390/ftrace: implement hotpatching
s390 allows hotpatching the mask of a conditional jump instruction.
Make use of this feature in order to avoid the expensive stop_machine()
call.
The new trampolines are split in 3 stages:
- A first stage is a 6-byte relative conditional long branch located at
each function's entry point. Its offset always points to the second
stage for the corresponding function, and its mask is either all 0s
(ftrace off) or all 1s (ftrace on). The code for flipping the mask is
borrowed from ftrace_{enable,disable}_ftrace_graph_caller. After
flipping, ftrace_arch_code_modify_post_process() syncs with all the
other CPUs by sending SIGPs.
- Second stages for vmlinux are stored in a separate part of the .text
section reserved by the linker script, and in dynamically allocated
memory for modules. This prevents the icache pollution. The total
size of second stages is about 1.5% of that of the kernel image.
Putting second stages in the .bss section is possible and decreases
the size of the non-compressed vmlinux, but splits the kernel 1:1
mapping, which is a bad tradeoff.
Each second stage contains a call to the third stage, a pointer to
the part of the intercepted function right after the first stage, and
a pointer to an interceptor function (e.g. ftrace_caller).
Second stages are 8-byte aligned for the future direct calls
implementation.
- There are only two copies of the third stage: in the .text section
for vmlinux and in dynamically allocated memory for modules. It can be
an expoline, which is relatively large, so inlining it into each
second stage is prohibitively expensive.
As a result of this organization, phoronix-test-suite with ftrace off
does not show any performance degradation.
Suggested-by: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Vasily Gorbik <gor@linux.ibm.com>
Co-developed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20210728212546.128248-3-iii@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2021-07-28 23:25:46 +02:00
{
2022-01-23 20:20:09 +01:00
u16 old ;
u8 op ;
s390/ftrace: implement hotpatching
s390 allows hotpatching the mask of a conditional jump instruction.
Make use of this feature in order to avoid the expensive stop_machine()
call.
The new trampolines are split in 3 stages:
- A first stage is a 6-byte relative conditional long branch located at
each function's entry point. Its offset always points to the second
stage for the corresponding function, and its mask is either all 0s
(ftrace off) or all 1s (ftrace on). The code for flipping the mask is
borrowed from ftrace_{enable,disable}_ftrace_graph_caller. After
flipping, ftrace_arch_code_modify_post_process() syncs with all the
other CPUs by sending SIGPs.
- Second stages for vmlinux are stored in a separate part of the .text
section reserved by the linker script, and in dynamically allocated
memory for modules. This prevents the icache pollution. The total
size of second stages is about 1.5% of that of the kernel image.
Putting second stages in the .bss section is possible and decreases
the size of the non-compressed vmlinux, but splits the kernel 1:1
mapping, which is a bad tradeoff.
Each second stage contains a call to the third stage, a pointer to
the part of the intercepted function right after the first stage, and
a pointer to an interceptor function (e.g. ftrace_caller).
Second stages are 8-byte aligned for the future direct calls
implementation.
- There are only two copies of the third stage: in the .text section
for vmlinux and in dynamically allocated memory for modules. It can be
an expoline, which is relatively large, so inlining it into each
second stage is prohibitively expensive.
As a result of this organization, phoronix-test-suite with ftrace off
does not show any performance degradation.
Suggested-by: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Vasily Gorbik <gor@linux.ibm.com>
Co-developed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20210728212546.128248-3-iii@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2021-07-28 23:25:46 +02:00
2022-01-23 20:20:09 +01:00
if ( get_kernel_nofault ( old , addr ) )
return - EFAULT ;
if ( old ! = expected )
return - EINVAL ;
/* set mask field to all ones or zeroes */
op = enable ? 0xf4 : 0x04 ;
s390_kernel_write ( ( char * ) addr + 1 , & op , sizeof ( op ) ) ;
return 0 ;
s390/ftrace: implement hotpatching
s390 allows hotpatching the mask of a conditional jump instruction.
Make use of this feature in order to avoid the expensive stop_machine()
call.
The new trampolines are split in 3 stages:
- A first stage is a 6-byte relative conditional long branch located at
each function's entry point. Its offset always points to the second
stage for the corresponding function, and its mask is either all 0s
(ftrace off) or all 1s (ftrace on). The code for flipping the mask is
borrowed from ftrace_{enable,disable}_ftrace_graph_caller. After
flipping, ftrace_arch_code_modify_post_process() syncs with all the
other CPUs by sending SIGPs.
- Second stages for vmlinux are stored in a separate part of the .text
section reserved by the linker script, and in dynamically allocated
memory for modules. This prevents the icache pollution. The total
size of second stages is about 1.5% of that of the kernel image.
Putting second stages in the .bss section is possible and decreases
the size of the non-compressed vmlinux, but splits the kernel 1:1
mapping, which is a bad tradeoff.
Each second stage contains a call to the third stage, a pointer to
the part of the intercepted function right after the first stage, and
a pointer to an interceptor function (e.g. ftrace_caller).
Second stages are 8-byte aligned for the future direct calls
implementation.
- There are only two copies of the third stage: in the .text section
for vmlinux and in dynamically allocated memory for modules. It can be
an expoline, which is relatively large, so inlining it into each
second stage is prohibitively expensive.
As a result of this organization, phoronix-test-suite with ftrace off
does not show any performance degradation.
Suggested-by: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Vasily Gorbik <gor@linux.ibm.com>
Co-developed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20210728212546.128248-3-iii@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2021-07-28 23:25:46 +02:00
}
2009-06-12 10:26:44 +02:00
int ftrace_make_nop ( struct module * mod , struct dyn_ftrace * rec ,
unsigned long addr )
{
2022-01-23 20:20:09 +01:00
/* Expect brcl 0xf,... */
return ftrace_patch_branch_mask ( ( void * ) rec - > ip , 0xc0f4 , false ) ;
s390/ftrace: implement hotpatching
s390 allows hotpatching the mask of a conditional jump instruction.
Make use of this feature in order to avoid the expensive stop_machine()
call.
The new trampolines are split in 3 stages:
- A first stage is a 6-byte relative conditional long branch located at
each function's entry point. Its offset always points to the second
stage for the corresponding function, and its mask is either all 0s
(ftrace off) or all 1s (ftrace on). The code for flipping the mask is
borrowed from ftrace_{enable,disable}_ftrace_graph_caller. After
flipping, ftrace_arch_code_modify_post_process() syncs with all the
other CPUs by sending SIGPs.
- Second stages for vmlinux are stored in a separate part of the .text
section reserved by the linker script, and in dynamically allocated
memory for modules. This prevents the icache pollution. The total
size of second stages is about 1.5% of that of the kernel image.
Putting second stages in the .bss section is possible and decreases
the size of the non-compressed vmlinux, but splits the kernel 1:1
mapping, which is a bad tradeoff.
Each second stage contains a call to the third stage, a pointer to
the part of the intercepted function right after the first stage, and
a pointer to an interceptor function (e.g. ftrace_caller).
Second stages are 8-byte aligned for the future direct calls
implementation.
- There are only two copies of the third stage: in the .text section
for vmlinux and in dynamically allocated memory for modules. It can be
an expoline, which is relatively large, so inlining it into each
second stage is prohibitively expensive.
As a result of this organization, phoronix-test-suite with ftrace off
does not show any performance degradation.
Suggested-by: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Vasily Gorbik <gor@linux.ibm.com>
Co-developed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20210728212546.128248-3-iii@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2021-07-28 23:25:46 +02:00
}
2009-06-12 10:26:44 +02:00
int ftrace_make_call ( struct dyn_ftrace * rec , unsigned long addr )
{
2022-02-23 13:02:59 +01:00
struct ftrace_hotpatch_trampoline * trampoline ;
trampoline = ftrace_get_trampoline ( rec ) ;
if ( IS_ERR ( trampoline ) )
return PTR_ERR ( trampoline ) ;
s390_kernel_write ( & trampoline - > interceptor , & addr , sizeof ( addr ) ) ;
2022-01-23 20:20:09 +01:00
/* Expect brcl 0x0,... */
return ftrace_patch_branch_mask ( ( void * ) rec - > ip , 0xc004 , true ) ;
2009-06-12 10:26:44 +02:00
}
int ftrace_update_ftrace_func ( ftrace_func_t func )
{
2021-06-25 23:50:07 +02:00
ftrace_func = func ;
2009-06-12 10:26:44 +02:00
return 0 ;
}
s390/ftrace: implement hotpatching
s390 allows hotpatching the mask of a conditional jump instruction.
Make use of this feature in order to avoid the expensive stop_machine()
call.
The new trampolines are split in 3 stages:
- A first stage is a 6-byte relative conditional long branch located at
each function's entry point. Its offset always points to the second
stage for the corresponding function, and its mask is either all 0s
(ftrace off) or all 1s (ftrace on). The code for flipping the mask is
borrowed from ftrace_{enable,disable}_ftrace_graph_caller. After
flipping, ftrace_arch_code_modify_post_process() syncs with all the
other CPUs by sending SIGPs.
- Second stages for vmlinux are stored in a separate part of the .text
section reserved by the linker script, and in dynamically allocated
memory for modules. This prevents the icache pollution. The total
size of second stages is about 1.5% of that of the kernel image.
Putting second stages in the .bss section is possible and decreases
the size of the non-compressed vmlinux, but splits the kernel 1:1
mapping, which is a bad tradeoff.
Each second stage contains a call to the third stage, a pointer to
the part of the intercepted function right after the first stage, and
a pointer to an interceptor function (e.g. ftrace_caller).
Second stages are 8-byte aligned for the future direct calls
implementation.
- There are only two copies of the third stage: in the .text section
for vmlinux and in dynamically allocated memory for modules. It can be
an expoline, which is relatively large, so inlining it into each
second stage is prohibitively expensive.
As a result of this organization, phoronix-test-suite with ftrace off
does not show any performance degradation.
Suggested-by: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Vasily Gorbik <gor@linux.ibm.com>
Co-developed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20210728212546.128248-3-iii@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2021-07-28 23:25:46 +02:00
void arch_ftrace_update_code ( int command )
{
2021-09-13 16:08:33 +02:00
ftrace_modify_all_code ( command ) ;
s390/ftrace: implement hotpatching
s390 allows hotpatching the mask of a conditional jump instruction.
Make use of this feature in order to avoid the expensive stop_machine()
call.
The new trampolines are split in 3 stages:
- A first stage is a 6-byte relative conditional long branch located at
each function's entry point. Its offset always points to the second
stage for the corresponding function, and its mask is either all 0s
(ftrace off) or all 1s (ftrace on). The code for flipping the mask is
borrowed from ftrace_{enable,disable}_ftrace_graph_caller. After
flipping, ftrace_arch_code_modify_post_process() syncs with all the
other CPUs by sending SIGPs.
- Second stages for vmlinux are stored in a separate part of the .text
section reserved by the linker script, and in dynamically allocated
memory for modules. This prevents the icache pollution. The total
size of second stages is about 1.5% of that of the kernel image.
Putting second stages in the .bss section is possible and decreases
the size of the non-compressed vmlinux, but splits the kernel 1:1
mapping, which is a bad tradeoff.
Each second stage contains a call to the third stage, a pointer to
the part of the intercepted function right after the first stage, and
a pointer to an interceptor function (e.g. ftrace_caller).
Second stages are 8-byte aligned for the future direct calls
implementation.
- There are only two copies of the third stage: in the .text section
for vmlinux and in dynamically allocated memory for modules. It can be
an expoline, which is relatively large, so inlining it into each
second stage is prohibitively expensive.
As a result of this organization, phoronix-test-suite with ftrace off
does not show any performance degradation.
Suggested-by: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Vasily Gorbik <gor@linux.ibm.com>
Co-developed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20210728212546.128248-3-iii@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2021-07-28 23:25:46 +02:00
}
2022-05-18 10:36:40 +08:00
void ftrace_arch_code_modify_post_process ( void )
s390/ftrace: implement hotpatching
s390 allows hotpatching the mask of a conditional jump instruction.
Make use of this feature in order to avoid the expensive stop_machine()
call.
The new trampolines are split in 3 stages:
- A first stage is a 6-byte relative conditional long branch located at
each function's entry point. Its offset always points to the second
stage for the corresponding function, and its mask is either all 0s
(ftrace off) or all 1s (ftrace on). The code for flipping the mask is
borrowed from ftrace_{enable,disable}_ftrace_graph_caller. After
flipping, ftrace_arch_code_modify_post_process() syncs with all the
other CPUs by sending SIGPs.
- Second stages for vmlinux are stored in a separate part of the .text
section reserved by the linker script, and in dynamically allocated
memory for modules. This prevents the icache pollution. The total
size of second stages is about 1.5% of that of the kernel image.
Putting second stages in the .bss section is possible and decreases
the size of the non-compressed vmlinux, but splits the kernel 1:1
mapping, which is a bad tradeoff.
Each second stage contains a call to the third stage, a pointer to
the part of the intercepted function right after the first stage, and
a pointer to an interceptor function (e.g. ftrace_caller).
Second stages are 8-byte aligned for the future direct calls
implementation.
- There are only two copies of the third stage: in the .text section
for vmlinux and in dynamically allocated memory for modules. It can be
an expoline, which is relatively large, so inlining it into each
second stage is prohibitively expensive.
As a result of this organization, phoronix-test-suite with ftrace off
does not show any performance degradation.
Suggested-by: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Vasily Gorbik <gor@linux.ibm.com>
Co-developed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20210728212546.128248-3-iii@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2021-07-28 23:25:46 +02:00
{
2021-10-01 14:21:43 +02:00
/*
* Flush any pre - fetched instructions on all
* CPUs to make the new code visible .
*/
text_poke_sync_lock ( ) ;
s390/ftrace: implement hotpatching
s390 allows hotpatching the mask of a conditional jump instruction.
Make use of this feature in order to avoid the expensive stop_machine()
call.
The new trampolines are split in 3 stages:
- A first stage is a 6-byte relative conditional long branch located at
each function's entry point. Its offset always points to the second
stage for the corresponding function, and its mask is either all 0s
(ftrace off) or all 1s (ftrace on). The code for flipping the mask is
borrowed from ftrace_{enable,disable}_ftrace_graph_caller. After
flipping, ftrace_arch_code_modify_post_process() syncs with all the
other CPUs by sending SIGPs.
- Second stages for vmlinux are stored in a separate part of the .text
section reserved by the linker script, and in dynamically allocated
memory for modules. This prevents the icache pollution. The total
size of second stages is about 1.5% of that of the kernel image.
Putting second stages in the .bss section is possible and decreases
the size of the non-compressed vmlinux, but splits the kernel 1:1
mapping, which is a bad tradeoff.
Each second stage contains a call to the third stage, a pointer to
the part of the intercepted function right after the first stage, and
a pointer to an interceptor function (e.g. ftrace_caller).
Second stages are 8-byte aligned for the future direct calls
implementation.
- There are only two copies of the third stage: in the .text section
for vmlinux and in dynamically allocated memory for modules. It can be
an expoline, which is relatively large, so inlining it into each
second stage is prohibitively expensive.
As a result of this organization, phoronix-test-suite with ftrace off
does not show any performance degradation.
Suggested-by: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Vasily Gorbik <gor@linux.ibm.com>
Co-developed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20210728212546.128248-3-iii@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2021-07-28 23:25:46 +02:00
}
2017-05-02 12:38:57 +02:00
# ifdef CONFIG_MODULES
2014-10-15 12:17:38 +02:00
static int __init ftrace_plt_init ( void )
{
s390/ftrace: implement hotpatching
s390 allows hotpatching the mask of a conditional jump instruction.
Make use of this feature in order to avoid the expensive stop_machine()
call.
The new trampolines are split in 3 stages:
- A first stage is a 6-byte relative conditional long branch located at
each function's entry point. Its offset always points to the second
stage for the corresponding function, and its mask is either all 0s
(ftrace off) or all 1s (ftrace on). The code for flipping the mask is
borrowed from ftrace_{enable,disable}_ftrace_graph_caller. After
flipping, ftrace_arch_code_modify_post_process() syncs with all the
other CPUs by sending SIGPs.
- Second stages for vmlinux are stored in a separate part of the .text
section reserved by the linker script, and in dynamically allocated
memory for modules. This prevents the icache pollution. The total
size of second stages is about 1.5% of that of the kernel image.
Putting second stages in the .bss section is possible and decreases
the size of the non-compressed vmlinux, but splits the kernel 1:1
mapping, which is a bad tradeoff.
Each second stage contains a call to the third stage, a pointer to
the part of the intercepted function right after the first stage, and
a pointer to an interceptor function (e.g. ftrace_caller).
Second stages are 8-byte aligned for the future direct calls
implementation.
- There are only two copies of the third stage: in the .text section
for vmlinux and in dynamically allocated memory for modules. It can be
an expoline, which is relatively large, so inlining it into each
second stage is prohibitively expensive.
As a result of this organization, phoronix-test-suite with ftrace off
does not show any performance degradation.
Suggested-by: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Vasily Gorbik <gor@linux.ibm.com>
Co-developed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20210728212546.128248-3-iii@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2021-07-28 23:25:46 +02:00
const char * start , * end ;
2014-10-15 12:17:38 +02:00
s390/ftrace: implement hotpatching
s390 allows hotpatching the mask of a conditional jump instruction.
Make use of this feature in order to avoid the expensive stop_machine()
call.
The new trampolines are split in 3 stages:
- A first stage is a 6-byte relative conditional long branch located at
each function's entry point. Its offset always points to the second
stage for the corresponding function, and its mask is either all 0s
(ftrace off) or all 1s (ftrace on). The code for flipping the mask is
borrowed from ftrace_{enable,disable}_ftrace_graph_caller. After
flipping, ftrace_arch_code_modify_post_process() syncs with all the
other CPUs by sending SIGPs.
- Second stages for vmlinux are stored in a separate part of the .text
section reserved by the linker script, and in dynamically allocated
memory for modules. This prevents the icache pollution. The total
size of second stages is about 1.5% of that of the kernel image.
Putting second stages in the .bss section is possible and decreases
the size of the non-compressed vmlinux, but splits the kernel 1:1
mapping, which is a bad tradeoff.
Each second stage contains a call to the third stage, a pointer to
the part of the intercepted function right after the first stage, and
a pointer to an interceptor function (e.g. ftrace_caller).
Second stages are 8-byte aligned for the future direct calls
implementation.
- There are only two copies of the third stage: in the .text section
for vmlinux and in dynamically allocated memory for modules. It can be
an expoline, which is relatively large, so inlining it into each
second stage is prohibitively expensive.
As a result of this organization, phoronix-test-suite with ftrace off
does not show any performance degradation.
Suggested-by: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Vasily Gorbik <gor@linux.ibm.com>
Co-developed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20210728212546.128248-3-iii@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2021-07-28 23:25:46 +02:00
ftrace_plt = module_alloc ( PAGE_SIZE ) ;
2014-10-15 12:17:38 +02:00
if ( ! ftrace_plt )
panic ( " cannot allocate ftrace plt \n " ) ;
s390/ftrace: implement hotpatching
s390 allows hotpatching the mask of a conditional jump instruction.
Make use of this feature in order to avoid the expensive stop_machine()
call.
The new trampolines are split in 3 stages:
- A first stage is a 6-byte relative conditional long branch located at
each function's entry point. Its offset always points to the second
stage for the corresponding function, and its mask is either all 0s
(ftrace off) or all 1s (ftrace on). The code for flipping the mask is
borrowed from ftrace_{enable,disable}_ftrace_graph_caller. After
flipping, ftrace_arch_code_modify_post_process() syncs with all the
other CPUs by sending SIGPs.
- Second stages for vmlinux are stored in a separate part of the .text
section reserved by the linker script, and in dynamically allocated
memory for modules. This prevents the icache pollution. The total
size of second stages is about 1.5% of that of the kernel image.
Putting second stages in the .bss section is possible and decreases
the size of the non-compressed vmlinux, but splits the kernel 1:1
mapping, which is a bad tradeoff.
Each second stage contains a call to the third stage, a pointer to
the part of the intercepted function right after the first stage, and
a pointer to an interceptor function (e.g. ftrace_caller).
Second stages are 8-byte aligned for the future direct calls
implementation.
- There are only two copies of the third stage: in the .text section
for vmlinux and in dynamically allocated memory for modules. It can be
an expoline, which is relatively large, so inlining it into each
second stage is prohibitively expensive.
As a result of this organization, phoronix-test-suite with ftrace off
does not show any performance degradation.
Suggested-by: Sven Schnelle <svens@linux.ibm.com>
Suggested-by: Vasily Gorbik <gor@linux.ibm.com>
Co-developed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20210728212546.128248-3-iii@linux.ibm.com
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
2021-07-28 23:25:46 +02:00
start = ftrace_shared_hotpatch_trampoline ( & end ) ;
memcpy ( ftrace_plt , start , end - start ) ;
set_memory_ro ( ( unsigned long ) ftrace_plt , 1 ) ;
2014-10-15 12:17:38 +02:00
return 0 ;
}
device_initcall ( ftrace_plt_init ) ;
2017-05-02 12:38:57 +02:00
# endif /* CONFIG_MODULES */
2009-06-12 10:26:46 +02:00
# ifdef CONFIG_FUNCTION_GRAPH_TRACER
/*
* Hook the return address and push it in the stack of return addresses
* in current thread info .
*/
2019-02-18 16:51:28 +01:00
unsigned long prepare_ftrace_return ( unsigned long ra , unsigned long sp ,
unsigned long ip )
2009-06-12 10:26:46 +02:00
{
2014-10-27 15:49:06 +01:00
if ( unlikely ( ftrace_graph_is_dead ( ) ) )
goto out ;
2009-06-12 10:26:46 +02:00
if ( unlikely ( atomic_read ( & current - > tracing_graph_pause ) ) )
goto out ;
2016-01-18 13:12:19 +01:00
ip - = MCOUNT_INSN_SIZE ;
2019-02-18 16:51:28 +01:00
if ( ! function_graph_enter ( ra , ip , 0 , ( void * ) sp ) )
ra = ( unsigned long ) return_to_handler ;
2009-06-12 10:26:46 +02:00
out :
2019-02-18 16:51:28 +01:00
return ra ;
2009-06-12 10:26:46 +02:00
}
2014-10-22 12:42:38 +02:00
NOKPROBE_SYMBOL ( prepare_ftrace_return ) ;
2011-01-05 12:48:11 +01:00
/*
* Patch the kernel code at ftrace_graph_caller location . The instruction
2014-10-08 10:03:08 +02:00
* there is branch relative on condition . To enable the ftrace graph code
* block , we simply patch the mask field of the instruction to zero and
* turn the instruction into a nop .
* To disable the ftrace graph code the mask field will be patched to
* all ones , which turns the instruction into an unconditional branch .
2011-01-05 12:48:11 +01:00
*/
2014-08-15 12:33:46 +02:00
int ftrace_enable_ftrace_graph_caller ( void )
{
2022-01-23 20:20:09 +01:00
int rc ;
/* Expect brc 0xf,... */
rc = ftrace_patch_branch_mask ( ftrace_graph_caller , 0xa7f4 , false ) ;
if ( rc )
return rc ;
2021-10-01 14:24:42 +02:00
text_poke_sync_lock ( ) ;
2015-03-13 12:55:56 +01:00
return 0 ;
2014-08-15 12:33:46 +02:00
}
int ftrace_disable_ftrace_graph_caller ( void )
{
2022-01-23 20:20:09 +01:00
int rc ;
/* Expect brc 0x0,... */
rc = ftrace_patch_branch_mask ( ftrace_graph_caller , 0xa704 , true ) ;
if ( rc )
return rc ;
2021-10-01 14:24:42 +02:00
text_poke_sync_lock ( ) ;
2015-03-13 12:55:56 +01:00
return 0 ;
2014-08-15 12:33:46 +02:00
}
2009-06-12 10:26:46 +02:00
# endif /* CONFIG_FUNCTION_GRAPH_TRACER */
2020-01-21 12:31:47 +01:00
# ifdef CONFIG_KPROBES_ON_FTRACE
void kprobe_ftrace_handler ( unsigned long ip , unsigned long parent_ip ,
2020-10-28 17:42:17 -04:00
struct ftrace_ops * ops , struct ftrace_regs * fregs )
2020-01-21 12:31:47 +01:00
{
struct kprobe_ctlblk * kcb ;
2020-10-28 17:42:17 -04:00
struct pt_regs * regs ;
2020-11-05 21:32:40 -05:00
struct kprobe * p ;
int bit ;
2020-01-21 12:31:47 +01:00
2020-11-05 21:32:46 -05:00
bit = ftrace_test_recursion_trylock ( ip , parent_ip ) ;
2020-11-05 21:32:40 -05:00
if ( bit < 0 )
2020-01-21 12:31:47 +01:00
return ;
2020-10-28 17:42:17 -04:00
regs = ftrace_get_regs ( fregs ) ;
2020-11-05 21:32:40 -05:00
p = get_kprobe ( ( kprobe_opcode_t * ) ip ) ;
2022-02-22 14:53:47 +01:00
if ( ! regs | | unlikely ( ! p ) | | kprobe_disabled ( p ) )
2020-11-05 21:32:40 -05:00
goto out ;
2020-01-21 12:31:47 +01:00
if ( kprobe_running ( ) ) {
kprobes_inc_nmissed_count ( p ) ;
2020-11-05 21:32:40 -05:00
goto out ;
2020-01-21 12:31:47 +01:00
}
__this_cpu_write ( current_kprobe , p ) ;
kcb = get_kprobe_ctlblk ( ) ;
kcb - > kprobe_status = KPROBE_HIT_ACTIVE ;
instruction_pointer_set ( regs , ip ) ;
if ( ! p - > pre_handler | | ! p - > pre_handler ( p , regs ) ) {
instruction_pointer_set ( regs , ip + MCOUNT_INSN_SIZE ) ;
if ( unlikely ( p - > post_handler ) ) {
kcb - > kprobe_status = KPROBE_HIT_SSDONE ;
p - > post_handler ( p , regs , 0 ) ;
}
}
__this_cpu_write ( current_kprobe , NULL ) ;
2020-11-05 21:32:40 -05:00
out :
ftrace_test_recursion_unlock ( bit ) ;
2020-01-21 12:31:47 +01:00
}
NOKPROBE_SYMBOL ( kprobe_ftrace_handler ) ;
int arch_prepare_kprobe_ftrace ( struct kprobe * p )
{
p - > ainsn . insn = NULL ;
return 0 ;
}
# endif