Skip to content

Commit 593c754

Browse files
committed
Merge branch 'parisc-5.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux
Pull parisc updates from Helge Deller: "Dynamic ftrace support by Sven Schnelle and a header guard fix by Denis Efremov" * 'parisc-5.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux: parisc: asm: psw.h: missing header guard parisc: add dynamic ftrace compiler.h: add CC_USING_PATCHABLE_FUNCTION_ENTRY parisc: use pr_debug() in kernel/module.c parisc: add WARN_ON() to clear_fixmap parisc: add spinlock to patch function parisc: add support for patching multiple words
2 parents 565eb5f + b3d5f31 commit 593c754

15 files changed

Lines changed: 359 additions & 61 deletions

File tree

‎arch/parisc/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ config PARISC
5959
select HAVE_ARCH_KGDB
6060
select HAVE_KPROBES
6161
select HAVE_KRETPROBES
62+
select HAVE_DYNAMIC_FTRACE if $(cc-option,-fpatchable-function-entry=1,1)
63+
select HAVE_FTRACE_MCOUNT_RECORD if HAVE_DYNAMIC_FTRACE
6264

6365
help
6466
The PA-RISC microprocessor is designed by Hewlett-Packard and used

‎arch/parisc/Makefile‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ ifneq ($(SUBARCH),$(UTS_MACHINE))
4747
endif
4848
endif
4949

50+
ifdef CONFIG_DYNAMIC_FTRACE
51+
ifdef CONFIG_64BIT
52+
NOP_COUNT := 8
53+
else
54+
NOP_COUNT := 5
55+
endif
56+
57+
export CC_USING_RECORD_MCOUNT:=1
58+
export CC_USING_PATCHABLE_FUNCTION_ENTRY:=1
59+
60+
KBUILD_AFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY=1
61+
KBUILD_CFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY=1 \
62+
-DFTRACE_PATCHABLE_FUNCTION_SIZE=$(NOP_COUNT)
63+
64+
CC_FLAGS_FTRACE := -fpatchable-function-entry=$(NOP_COUNT),$(shell echo $$(($(NOP_COUNT)-1)))
65+
KBUILD_LDFLAGS_MODULE += -T $(srctree)/arch/parisc/kernel/module.lds
66+
endif
67+
5068
OBJCOPY_FLAGS =-O binary -R .note -R .comment -S
5169

5270
cflags-y := -pipe

‎arch/parisc/include/asm/ftrace.h‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,23 @@
55
#ifndef __ASSEMBLY__
66
extern void mcount(void);
77

8-
#define MCOUNT_INSN_SIZE 4
9-
8+
#define MCOUNT_ADDR ((unsigned long)mcount)
9+
#define MCOUNT_INSN_SIZE 4
10+
#define CC_USING_NOP_MCOUNT
1011
extern unsigned long sys_call_table[];
1112

1213
extern unsigned long return_address(unsigned int);
1314

15+
#ifdef CONFIG_DYNAMIC_FTRACE
16+
extern void ftrace_caller(void);
17+
18+
struct dyn_arch_ftrace {
19+
};
20+
21+
unsigned long ftrace_call_adjust(unsigned long addr);
22+
23+
#endif
24+
1425
#define ftrace_return_address(n) return_address(n)
1526

1627
#endif /* __ASSEMBLY__ */

‎arch/parisc/include/asm/patch.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
/* stop machine and patch kernel text */
66
void patch_text(void *addr, unsigned int insn);
7+
void patch_text_multiple(void *addr, u32 *insn, unsigned int len);
78

89
/* patch kernel text with machine already stopped (e.g. in kgdb) */
9-
void __patch_text(void *addr, unsigned int insn);
10+
void __patch_text(void *addr, u32 insn);
11+
void __patch_text_multiple(void *addr, u32 *insn, unsigned int len);
1012

1113
#endif

‎arch/parisc/include/asm/psw.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
22
#ifndef _PARISC_PSW_H
3-
3+
#define _PARISC_PSW_H
44

55
#define PSW_I 0x00000001
66
#define PSW_D 0x00000002

‎arch/parisc/kernel/Makefile‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ obj-y := cache.o pacache.o setup.o pdt.o traps.o time.o irq.o \
1414

1515
ifdef CONFIG_FUNCTION_TRACER
1616
# Do not profile debug and lowlevel utilities
17-
CFLAGS_REMOVE_ftrace.o = -pg
18-
CFLAGS_REMOVE_cache.o = -pg
19-
CFLAGS_REMOVE_perf.o = -pg
20-
CFLAGS_REMOVE_unwind.o = -pg
17+
CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE)
18+
CFLAGS_REMOVE_cache.o = $(CC_FLAGS_FTRACE)
19+
CFLAGS_REMOVE_perf.o = $(CC_FLAGS_FTRACE)
20+
CFLAGS_REMOVE_unwind.o = $(CC_FLAGS_FTRACE)
21+
CFLAGS_REMOVE_patch.o = $(CC_FLAGS_FTRACE)
2122
endif
2223

2324
obj-$(CONFIG_SMP) += smp.o

‎arch/parisc/kernel/entry.S‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,70 @@ ftrace_stub:
20122012
#endif
20132013
ENDPROC_CFI(mcount)
20142014

2015+
#ifdef CONFIG_DYNAMIC_FTRACE
2016+
2017+
#ifdef CONFIG_64BIT
2018+
#define FTRACE_FRAME_SIZE (2*FRAME_SIZE)
2019+
#else
2020+
#define FTRACE_FRAME_SIZE FRAME_SIZE
2021+
#endif
2022+
ENTRY_CFI(ftrace_caller, caller,frame=FTRACE_FRAME_SIZE,CALLS,SAVE_RP,SAVE_SP)
2023+
ftrace_caller:
2024+
.global ftrace_caller
2025+
2026+
STREG %r3, -FTRACE_FRAME_SIZE+1*REG_SZ(%sp)
2027+
ldo -FTRACE_FRAME_SIZE(%sp), %r3
2028+
STREG %rp, -RP_OFFSET(%r3)
2029+
2030+
/* Offset 0 is already allocated for %r1 */
2031+
STREG %r23, 2*REG_SZ(%r3)
2032+
STREG %r24, 3*REG_SZ(%r3)
2033+
STREG %r25, 4*REG_SZ(%r3)
2034+
STREG %r26, 5*REG_SZ(%r3)
2035+
STREG %r28, 6*REG_SZ(%r3)
2036+
STREG %r29, 7*REG_SZ(%r3)
2037+
#ifdef CONFIG_64BIT
2038+
STREG %r19, 8*REG_SZ(%r3)
2039+
STREG %r20, 9*REG_SZ(%r3)
2040+
STREG %r21, 10*REG_SZ(%r3)
2041+
STREG %r22, 11*REG_SZ(%r3)
2042+
STREG %r27, 12*REG_SZ(%r3)
2043+
STREG %r31, 13*REG_SZ(%r3)
2044+
loadgp
2045+
ldo -16(%sp),%r29
2046+
#endif
2047+
LDREG 0(%r3), %r25
2048+
copy %rp, %r26
2049+
ldo -8(%r25), %r25
2050+
b,l ftrace_function_trampoline, %rp
2051+
copy %r3, %r24
2052+
2053+
LDREG -RP_OFFSET(%r3), %rp
2054+
LDREG 2*REG_SZ(%r3), %r23
2055+
LDREG 3*REG_SZ(%r3), %r24
2056+
LDREG 4*REG_SZ(%r3), %r25
2057+
LDREG 5*REG_SZ(%r3), %r26
2058+
LDREG 6*REG_SZ(%r3), %r28
2059+
LDREG 7*REG_SZ(%r3), %r29
2060+
#ifdef CONFIG_64BIT
2061+
LDREG 8*REG_SZ(%r3), %r19
2062+
LDREG 9*REG_SZ(%r3), %r20
2063+
LDREG 10*REG_SZ(%r3), %r21
2064+
LDREG 11*REG_SZ(%r3), %r22
2065+
LDREG 12*REG_SZ(%r3), %r27
2066+
LDREG 13*REG_SZ(%r3), %r31
2067+
#endif
2068+
LDREG 1*REG_SZ(%r3), %r3
2069+
2070+
LDREGM -FTRACE_FRAME_SIZE(%sp), %r1
2071+
/* Adjust return point to jump back to beginning of traced function */
2072+
ldo -4(%r1), %r1
2073+
bv,n (%r1)
2074+
2075+
ENDPROC_CFI(ftrace_caller)
2076+
2077+
#endif
2078+
20152079
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
20162080
.align 8
20172081
ENTRY_CFI(return_to_handler, caller,frame=FRAME_SIZE)

‎arch/parisc/kernel/ftrace.c‎

Lines changed: 120 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
* Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
88
*
99
* future possible enhancements:
10-
* - add CONFIG_DYNAMIC_FTRACE
1110
* - add CONFIG_STACK_TRACER
1211
*/
1312

1413
#include <linux/init.h>
1514
#include <linux/ftrace.h>
15+
#include <linux/uaccess.h>
1616

1717
#include <asm/assembly.h>
1818
#include <asm/sections.h>
1919
#include <asm/ftrace.h>
20-
20+
#include <asm/patch.h>
2121

2222
#define __hot __attribute__ ((__section__ (".text.hot")))
2323

@@ -50,13 +50,11 @@ void notrace __hot ftrace_function_trampoline(unsigned long parent,
5050
unsigned long self_addr,
5151
unsigned long org_sp_gr3)
5252
{
53-
extern ftrace_func_t ftrace_trace_function; /* depends on CONFIG_DYNAMIC_FTRACE */
54-
55-
if (ftrace_trace_function != ftrace_stub) {
56-
/* struct ftrace_ops *op, struct pt_regs *regs); */
57-
ftrace_trace_function(parent, self_addr, NULL, NULL);
58-
return;
59-
}
53+
#ifndef CONFIG_DYNAMIC_FTRACE
54+
extern ftrace_func_t ftrace_trace_function;
55+
#endif
56+
if (ftrace_trace_function != ftrace_stub)
57+
ftrace_trace_function(self_addr, parent, NULL, NULL);
6058

6159
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
6260
if (ftrace_graph_return != (trace_func_graph_ret_t) ftrace_stub ||
@@ -75,3 +73,116 @@ void notrace __hot ftrace_function_trampoline(unsigned long parent,
7573
#endif
7674
}
7775

76+
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
77+
int ftrace_enable_ftrace_graph_caller(void)
78+
{
79+
return 0;
80+
}
81+
82+
int ftrace_disable_ftrace_graph_caller(void)
83+
{
84+
return 0;
85+
}
86+
#endif
87+
88+
#ifdef CONFIG_DYNAMIC_FTRACE
89+
90+
int __init ftrace_dyn_arch_init(void)
91+
{
92+
return 0;
93+
}
94+
int ftrace_update_ftrace_func(ftrace_func_t func)
95+
{
96+
return 0;
97+
}
98+
99+
unsigned long ftrace_call_adjust(unsigned long addr)
100+
{
101+
return addr+(FTRACE_PATCHABLE_FUNCTION_SIZE-1)*4;
102+
}
103+
104+
int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
105+
{
106+
u32 insn[FTRACE_PATCHABLE_FUNCTION_SIZE];
107+
u32 *tramp;
108+
int size, ret, i;
109+
void *ip;
110+
111+
#ifdef CONFIG_64BIT
112+
unsigned long addr2 =
113+
(unsigned long)dereference_function_descriptor((void *)addr);
114+
115+
u32 ftrace_trampoline[] = {
116+
0x73c10208, /* std,ma r1,100(sp) */
117+
0x0c2110c1, /* ldd -10(r1),r1 */
118+
0xe820d002, /* bve,n (r1) */
119+
addr2 >> 32,
120+
addr2 & 0xffffffff,
121+
0xe83f1fd7, /* b,l,n .-14,r1 */
122+
};
123+
124+
u32 ftrace_trampoline_unaligned[] = {
125+
addr2 >> 32,
126+
addr2 & 0xffffffff,
127+
0x37de0200, /* ldo 100(sp),sp */
128+
0x73c13e01, /* std r1,-100(sp) */
129+
0x34213ff9, /* ldo -4(r1),r1 */
130+
0x50213fc1, /* ldd -20(r1),r1 */
131+
0xe820d002, /* bve,n (r1) */
132+
0xe83f1fcf, /* b,l,n .-20,r1 */
133+
};
134+
135+
BUILD_BUG_ON(ARRAY_SIZE(ftrace_trampoline_unaligned) >
136+
FTRACE_PATCHABLE_FUNCTION_SIZE);
137+
#else
138+
u32 ftrace_trampoline[] = {
139+
(u32)addr,
140+
0x6fc10080, /* stw,ma r1,40(sp) */
141+
0x48213fd1, /* ldw -18(r1),r1 */
142+
0xe820c002, /* bv,n r0(r1) */
143+
0xe83f1fdf, /* b,l,n .-c,r1 */
144+
};
145+
#endif
146+
147+
BUILD_BUG_ON(ARRAY_SIZE(ftrace_trampoline) >
148+
FTRACE_PATCHABLE_FUNCTION_SIZE);
149+
150+
size = sizeof(ftrace_trampoline);
151+
tramp = ftrace_trampoline;
152+
153+
#ifdef CONFIG_64BIT
154+
if (rec->ip & 0x4) {
155+
size = sizeof(ftrace_trampoline_unaligned);
156+
tramp = ftrace_trampoline_unaligned;
157+
}
158+
#endif
159+
160+
ip = (void *)(rec->ip + 4 - size);
161+
162+
ret = probe_kernel_read(insn, ip, size);
163+
if (ret)
164+
return ret;
165+
166+
for (i = 0; i < size / 4; i++) {
167+
if (insn[i] != INSN_NOP)
168+
return -EINVAL;
169+
}
170+
171+
__patch_text_multiple(ip, tramp, size);
172+
return 0;
173+
}
174+
175+
int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec,
176+
unsigned long addr)
177+
{
178+
u32 insn[FTRACE_PATCHABLE_FUNCTION_SIZE];
179+
int i;
180+
181+
for (i = 0; i < ARRAY_SIZE(insn); i++)
182+
insn[i] = INSN_NOP;
183+
184+
__patch_text_multiple((void *)rec->ip + 4 - sizeof(insn),
185+
insn, sizeof(insn));
186+
return 0;
187+
}
188+
#endif

0 commit comments

Comments
 (0)