Skip to content

Commit f183d26

Browse files
committed
Merge tag 'csky-for-linus-5.7-rc1' of git://github.com/c-sky/csky-linux
Pull csky updates from Guo Ren: - Add kproobes/uprobes support - Add lockdep, rseq, gcov support - Fixup init_fpu - Fixup ftrace_modify deadlock - Fixup speculative execution on IO area * tag 'csky-for-linus-5.7-rc1' of git://github.com/c-sky/csky-linux: csky: Fixup cpu speculative execution to IO area csky: Add uprobes support csky: Add kprobes supported csky: Enable LOCKDEP_SUPPORT csky: Enable the gcov function csky: Fixup get wrong psr value from phyical reg csky/ftrace: Fixup ftrace_modify_code deadlock without CPU_HAS_ICACHE_INS csky: Implement ftrace with regs csky: Add support for restartable sequence csky: Implement ptrace regs and stack API csky: Fixup init_fpu compile warning with __init
2 parents b6ff107 + aefd946 commit f183d26

34 files changed

+1807
-74
lines changed

arch/csky/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ config CSKY
33
def_bool y
44
select ARCH_32BIT_OFF_T
55
select ARCH_HAS_DMA_PREP_COHERENT
6+
select ARCH_HAS_GCOV_PROFILE_ALL
67
select ARCH_HAS_SYNC_DMA_FOR_CPU
78
select ARCH_HAS_SYNC_DMA_FOR_DEVICE
89
select ARCH_USE_BUILTIN_BSWAP
@@ -38,16 +39,22 @@ config CSKY
3839
select HAVE_ARCH_AUDITSYSCALL
3940
select HAVE_COPY_THREAD_TLS
4041
select HAVE_DYNAMIC_FTRACE
42+
select HAVE_DYNAMIC_FTRACE_WITH_REGS
4143
select HAVE_FUNCTION_TRACER
4244
select HAVE_FUNCTION_GRAPH_TRACER
4345
select HAVE_FTRACE_MCOUNT_RECORD
4446
select HAVE_KERNEL_GZIP
4547
select HAVE_KERNEL_LZO
4648
select HAVE_KERNEL_LZMA
49+
select HAVE_KPROBES if !CPU_CK610
50+
select HAVE_KPROBES_ON_FTRACE if !CPU_CK610
51+
select HAVE_KRETPROBES if !CPU_CK610
4752
select HAVE_PERF_EVENTS
4853
select HAVE_PERF_REGS
4954
select HAVE_PERF_USER_STACK_DUMP
5055
select HAVE_DMA_CONTIGUOUS
56+
select HAVE_REGS_AND_STACK_ACCESS_API
57+
select HAVE_RSEQ
5158
select HAVE_STACKPROTECTOR
5259
select HAVE_SYSCALL_TRACEPOINTS
5360
select MAY_HAVE_SPARSE_IRQ
@@ -65,6 +72,12 @@ config CSKY
6572
select PCI_SYSCALL if PCI
6673
select PCI_MSI if PCI
6774

75+
config LOCKDEP_SUPPORT
76+
def_bool y
77+
78+
config ARCH_SUPPORTS_UPROBES
79+
def_bool y if !CPU_CK610
80+
6881
config CPU_HAS_CACHEV2
6982
bool
7083

arch/csky/abiv1/inc/abi/entry.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,7 @@
172172
addi r6, 0xe
173173
cpwcr r6, cpcr30
174174

175-
lsri r6, 28
176-
addi r6, 2
177-
lsli r6, 28
178-
addi r6, 0xe
175+
movi r6, 0
179176
cpwcr r6, cpcr31
180177
.endm
181178

arch/csky/abiv2/fpu.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
#define MTCR_DIST 0xC0006420
1111
#define MFCR_DIST 0xC0006020
1212

13-
void __init init_fpu(void)
14-
{
15-
mtcr("cr<1, 2>", 0);
16-
}
17-
1813
/*
1914
* fpu_libc_helper() is to help libc to excute:
2015
* - mfcr %a, cr<1, 2>

arch/csky/abiv2/inc/abi/entry.h

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,66 @@
100100
rte
101101
.endm
102102

103+
.macro SAVE_REGS_FTRACE
104+
subi sp, 152
105+
stw tls, (sp, 0)
106+
stw lr, (sp, 4)
107+
108+
mfcr lr, psr
109+
stw lr, (sp, 12)
110+
111+
addi lr, sp, 152
112+
stw lr, (sp, 16)
113+
114+
stw a0, (sp, 20)
115+
stw a0, (sp, 24)
116+
stw a1, (sp, 28)
117+
stw a2, (sp, 32)
118+
stw a3, (sp, 36)
119+
120+
addi sp, 40
121+
stm r4-r13, (sp)
122+
123+
addi sp, 40
124+
stm r16-r30, (sp)
125+
#ifdef CONFIG_CPU_HAS_HILO
126+
mfhi lr
127+
stw lr, (sp, 60)
128+
mflo lr
129+
stw lr, (sp, 64)
130+
mfcr lr, cr14
131+
stw lr, (sp, 68)
132+
#endif
133+
subi sp, 80
134+
.endm
135+
136+
.macro RESTORE_REGS_FTRACE
137+
ldw tls, (sp, 0)
138+
ldw a0, (sp, 16)
139+
mtcr a0, ss0
140+
141+
#ifdef CONFIG_CPU_HAS_HILO
142+
ldw a0, (sp, 140)
143+
mthi a0
144+
ldw a0, (sp, 144)
145+
mtlo a0
146+
ldw a0, (sp, 148)
147+
mtcr a0, cr14
148+
#endif
149+
150+
ldw a0, (sp, 24)
151+
ldw a1, (sp, 28)
152+
ldw a2, (sp, 32)
153+
ldw a3, (sp, 36)
154+
155+
addi sp, 40
156+
ldm r4-r13, (sp)
157+
addi sp, 40
158+
ldm r16-r30, (sp)
159+
addi sp, 72
160+
mfcr sp, ss0
161+
.endm
162+
103163
.macro SAVE_SWITCH_STACK
104164
subi sp, 64
105165
stm r4-r11, (sp)
@@ -230,11 +290,8 @@
230290
addi r6, 0x1ce
231291
mtcr r6, cr<30, 15> /* Set MSA0 */
232292

233-
lsri r6, 28
234-
addi r6, 2
235-
lsli r6, 28
236-
addi r6, 0x1ce
237-
mtcr r6, cr<31, 15> /* Set MSA1 */
293+
movi r6, 0
294+
mtcr r6, cr<31, 15> /* Clr MSA1 */
238295

239296
/* enable MMU */
240297
mfcr r6, cr18

arch/csky/abiv2/inc/abi/fpu.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
int fpu_libc_helper(struct pt_regs *regs);
1111
void fpu_fpe(struct pt_regs *regs);
12-
void __init init_fpu(void);
12+
13+
static inline void init_fpu(void) { mtcr("cr<1, 2>", 0); }
1314

1415
void save_to_user_fp(struct user_fp *user_fp);
1516
void restore_from_user_fp(struct user_fp *user_fp);

arch/csky/abiv2/mcount.S

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include <linux/linkage.h>
55
#include <asm/ftrace.h>
6+
#include <abi/entry.h>
7+
#include <asm/asm-offsets.h>
68

79
/*
810
* csky-gcc with -pg will put the following asm after prologue:
@@ -44,6 +46,22 @@
4446
jmp t1
4547
.endm
4648

49+
.macro mcount_enter_regs
50+
subi sp, 8
51+
stw lr, (sp, 0)
52+
stw r8, (sp, 4)
53+
SAVE_REGS_FTRACE
54+
.endm
55+
56+
.macro mcount_exit_regs
57+
RESTORE_REGS_FTRACE
58+
ldw t1, (sp, 0)
59+
ldw r8, (sp, 4)
60+
ldw lr, (sp, 8)
61+
addi sp, 12
62+
jmp t1
63+
.endm
64+
4765
.macro save_return_regs
4866
subi sp, 16
4967
stw a0, (sp, 0)
@@ -122,6 +140,8 @@ ENTRY(ftrace_caller)
122140
ldw a0, (sp, 16)
123141
subi a0, 4
124142
ldw a1, (sp, 24)
143+
lrw a2, function_trace_op
144+
ldw a2, (a2, 0)
125145

126146
nop
127147
GLOBAL(ftrace_call)
@@ -157,3 +177,31 @@ ENTRY(return_to_handler)
157177
jmp lr
158178
END(return_to_handler)
159179
#endif
180+
181+
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
182+
ENTRY(ftrace_regs_caller)
183+
mcount_enter_regs
184+
185+
lrw t1, PT_FRAME_SIZE
186+
add t1, sp
187+
188+
ldw a0, (t1, 0)
189+
subi a0, 4
190+
ldw a1, (t1, 8)
191+
lrw a2, function_trace_op
192+
ldw a2, (a2, 0)
193+
mov a3, sp
194+
195+
nop
196+
GLOBAL(ftrace_regs_call)
197+
nop32_stub
198+
199+
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
200+
nop
201+
GLOBAL(ftrace_graph_regs_call)
202+
nop32_stub
203+
#endif
204+
205+
mcount_exit_regs
206+
ENDPROC(ftrace_regs_caller)
207+
#endif /* CONFIG_DYNAMIC_FTRACE */

arch/csky/include/asm/ftrace.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
1212

13+
#define ARCH_SUPPORTS_FTRACE_OPS 1
14+
1315
#define MCOUNT_ADDR ((unsigned long)_mcount)
1416

1517
#ifndef __ASSEMBLY__

arch/csky/include/asm/kprobes.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
3+
#ifndef __ASM_CSKY_KPROBES_H
4+
#define __ASM_CSKY_KPROBES_H
5+
6+
#include <asm-generic/kprobes.h>
7+
8+
#ifdef CONFIG_KPROBES
9+
#include <linux/types.h>
10+
#include <linux/ptrace.h>
11+
#include <linux/percpu.h>
12+
13+
#define __ARCH_WANT_KPROBES_INSN_SLOT
14+
#define MAX_INSN_SIZE 1
15+
16+
#define flush_insn_slot(p) do { } while (0)
17+
#define kretprobe_blacklist_size 0
18+
19+
#include <asm/probes.h>
20+
21+
struct prev_kprobe {
22+
struct kprobe *kp;
23+
unsigned int status;
24+
};
25+
26+
/* Single step context for kprobe */
27+
struct kprobe_step_ctx {
28+
unsigned long ss_pending;
29+
unsigned long match_addr;
30+
};
31+
32+
/* per-cpu kprobe control block */
33+
struct kprobe_ctlblk {
34+
unsigned int kprobe_status;
35+
unsigned long saved_sr;
36+
struct prev_kprobe prev_kprobe;
37+
struct kprobe_step_ctx ss_ctx;
38+
};
39+
40+
void arch_remove_kprobe(struct kprobe *p);
41+
int kprobe_fault_handler(struct pt_regs *regs, unsigned int trapnr);
42+
int kprobe_breakpoint_handler(struct pt_regs *regs);
43+
int kprobe_single_step_handler(struct pt_regs *regs);
44+
void kretprobe_trampoline(void);
45+
void __kprobes *trampoline_probe_handler(struct pt_regs *regs);
46+
47+
#endif /* CONFIG_KPROBES */
48+
#endif /* __ASM_CSKY_KPROBES_H */

arch/csky/include/asm/probes.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#ifndef __ASM_CSKY_PROBES_H
4+
#define __ASM_CSKY_PROBES_H
5+
6+
typedef u32 probe_opcode_t;
7+
typedef void (probes_handler_t) (u32 opcode, long addr, struct pt_regs *);
8+
9+
/* architecture specific copy of original instruction */
10+
struct arch_probe_insn {
11+
probe_opcode_t *insn;
12+
probes_handler_t *handler;
13+
/* restore address after simulation */
14+
unsigned long restore;
15+
};
16+
17+
#ifdef CONFIG_KPROBES
18+
typedef u32 kprobe_opcode_t;
19+
struct arch_specific_insn {
20+
struct arch_probe_insn api;
21+
};
22+
#endif
23+
24+
#endif /* __ASM_CSKY_PROBES_H */

arch/csky/include/asm/processor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ extern struct cpuinfo_csky cpu_data[];
4343
struct thread_struct {
4444
unsigned long ksp; /* kernel stack pointer */
4545
unsigned long sr; /* saved status register */
46+
unsigned long trap_no; /* saved status register */
4647

4748
/* FPU regs */
4849
struct user_fp __aligned(16) user_fp;

arch/csky/include/asm/ptrace.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
#include <uapi/asm/ptrace.h>
88
#include <asm/traps.h>
99
#include <linux/types.h>
10+
#include <linux/compiler.h>
1011

1112
#ifndef __ASSEMBLY__
1213

1314
#define PS_S 0x80000000 /* Supervisor Mode */
1415

16+
#define USR_BKPT 0x1464
17+
1518
#define arch_has_single_step() (1)
1619
#define current_pt_regs() \
1720
({ (struct pt_regs *)((char *)current_thread_info() + THREAD_SIZE) - 1; })
@@ -22,6 +25,18 @@
2225
#define instruction_pointer(regs) ((regs)->pc)
2326
#define profile_pc(regs) instruction_pointer(regs)
2427

28+
static inline void instruction_pointer_set(struct pt_regs *regs,
29+
unsigned long val)
30+
{
31+
regs->pc = val;
32+
}
33+
34+
#if defined(__CSKYABIV2__)
35+
#define MAX_REG_OFFSET offsetof(struct pt_regs, dcsr)
36+
#else
37+
#define MAX_REG_OFFSET offsetof(struct pt_regs, regs[9])
38+
#endif
39+
2540
static inline bool in_syscall(struct pt_regs const *regs)
2641
{
2742
return ((regs->sr >> 16) & 0xff) == VEC_TRAP0;
@@ -37,5 +52,33 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
3752
return regs->a0;
3853
}
3954

55+
/* Valid only for Kernel mode traps. */
56+
static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
57+
{
58+
return regs->usp;
59+
}
60+
61+
extern int regs_query_register_offset(const char *name);
62+
extern unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
63+
unsigned int n);
64+
65+
/*
66+
* regs_get_register() - get register value from its offset
67+
* @regs: pt_regs from which register value is gotten
68+
* @offset: offset of the register.
69+
*
70+
* regs_get_register returns the value of a register whose offset from @regs.
71+
* The @offset is the offset of the register in struct pt_regs.
72+
* If @offset is bigger than MAX_REG_OFFSET, this returns 0.
73+
*/
74+
static inline unsigned long regs_get_register(struct pt_regs *regs,
75+
unsigned int offset)
76+
{
77+
if (unlikely(offset > MAX_REG_OFFSET))
78+
return 0;
79+
80+
return *(unsigned long *)((unsigned long)regs + offset);
81+
}
82+
4083
#endif /* __ASSEMBLY__ */
4184
#endif /* __ASM_CSKY_PTRACE_H */

0 commit comments

Comments
 (0)