Skip to content

Commit 2044513

Browse files
committed
Merge tag 'csky-for-linus-5.9-rc1' of https://github.com/c-sky/csky-linux
Pull arch/csky updates from Guo Ren: "New features: - seccomp-filter - err-injection - top-down&random mmap-layout - irq_work - show_ipi - context-tracking Fixes & Optimizations: - kprobe_on_ftrace - optimize panic print" * tag 'csky-for-linus-5.9-rc1' of https://github.com/c-sky/csky-linux: csky: Add context tracking support csky: Add arch_show_interrupts for IPI interrupts csky: Add irq_work support csky: Fixup warning by EXPORT_SYMBOL(kmap) csky: Set CONFIG_NR_CPU 4 as default csky: Use top-down mmap layout csky: Optimize the trap processing flow csky: Add support for function error injection csky: Fixup kprobes handler couldn't change pc csky: Fixup duplicated restore sp in RESTORE_REGS_FTRACE csky: Add cpu feature register hint for smp csky: Add SECCOMP_FILTER supported csky: remove unusued thread_saved_pc and *_segments functions/macros
2 parents bbcf9cd + bdcd93e commit 2044513

File tree

19 files changed

+318
-143
lines changed

19 files changed

+318
-143
lines changed

arch/csky/Kconfig

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ config CSKY
99
select ARCH_USE_BUILTIN_BSWAP
1010
select ARCH_USE_QUEUED_RWLOCKS if NR_CPUS>2
1111
select ARCH_WANT_FRAME_POINTERS if !CPU_CK610
12+
select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT
1213
select COMMON_CLK
1314
select CLKSRC_MMIO
1415
select CSKY_MPINTC if CPU_CK860
@@ -38,11 +39,16 @@ config CSKY
3839
select GX6605S_TIMER if CPU_CK610
3940
select HAVE_ARCH_TRACEHOOK
4041
select HAVE_ARCH_AUDITSYSCALL
42+
select HAVE_ARCH_MMAP_RND_BITS
43+
select HAVE_ARCH_SECCOMP_FILTER
44+
select HAVE_CONTEXT_TRACKING
45+
select HAVE_VIRT_CPU_ACCOUNTING_GEN
4146
select HAVE_DEBUG_BUGVERBOSE
4247
select HAVE_DYNAMIC_FTRACE
4348
select HAVE_DYNAMIC_FTRACE_WITH_REGS
4449
select HAVE_FUNCTION_TRACER
4550
select HAVE_FUNCTION_GRAPH_TRACER
51+
select HAVE_FUNCTION_ERROR_INJECTION
4652
select HAVE_FTRACE_MCOUNT_RECORD
4753
select HAVE_KERNEL_GZIP
4854
select HAVE_KERNEL_LZO
@@ -148,6 +154,14 @@ config L1_CACHE_SHIFT
148154
default "5" if (CPU_CK807 || CPU_CK810)
149155
default "6" if (CPU_CK860)
150156

157+
config ARCH_MMAP_RND_BITS_MIN
158+
default 8
159+
160+
# max bits determined by the following formula:
161+
# VA_BITS - PAGE_SHIFT - 3
162+
config ARCH_MMAP_RND_BITS_MAX
163+
default 17
164+
151165
menu "Processor type and features"
152166

153167
choice
@@ -266,7 +280,7 @@ config NR_CPUS
266280
int "Maximum number of CPUs (2-32)"
267281
range 2 32
268282
depends on SMP
269-
default "2"
283+
default "4"
270284

271285
config HIGHMEM
272286
bool "High Memory Support"
@@ -295,3 +309,16 @@ endmenu
295309
source "arch/csky/Kconfig.platforms"
296310

297311
source "kernel/Kconfig.hz"
312+
313+
config SECCOMP
314+
bool "Enable seccomp to safely compute untrusted bytecode"
315+
help
316+
This kernel feature is useful for number crunching applications
317+
that may need to compute untrusted bytecode during their
318+
execution. By using pipes or other transports made available to
319+
the process as file descriptors supporting the read/write
320+
syscalls, it's possible to isolate those applications in
321+
their own address space using seccomp. Once seccomp is
322+
enabled via prctl(PR_SET_SECCOMP), it cannot be disabled
323+
and the task is only allowed to execute a few safe syscalls
324+
defined by each seccomp mode.

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

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

137137
.macro RESTORE_REGS_FTRACE
138138
ldw tls, (sp, 0)
139-
ldw a0, (sp, 16)
140-
mtcr a0, ss0
141139

142140
#ifdef CONFIG_CPU_HAS_HILO
143141
ldw a0, (sp, 140)
@@ -158,7 +156,6 @@
158156
addi sp, 40
159157
ldm r16-r30, (sp)
160158
addi sp, 72
161-
mfcr sp, ss0
162159
.endm
163160

164161
.macro SAVE_SWITCH_STACK

arch/csky/abiv2/mcount.S

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555

5656
.macro mcount_exit_regs
5757
RESTORE_REGS_FTRACE
58-
ldw t1, (sp, 0)
58+
subi sp, 152
59+
ldw t1, (sp, 4)
60+
addi sp, 152
5961
ldw r8, (sp, 4)
6062
ldw lr, (sp, 8)
6163
addi sp, 12

arch/csky/include/asm/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ generic-y += gpio.h
44
generic-y += kvm_para.h
55
generic-y += local64.h
66
generic-y += qrwlock.h
7+
generic-y += seccomp.h
78
generic-y += user.h
89
generic-y += vmlinux.lds.h

arch/csky/include/asm/bug.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ do { \
2020

2121
struct pt_regs;
2222

23-
void die_if_kernel(char *str, struct pt_regs *regs, int nr);
23+
void die(struct pt_regs *regs, const char *str);
2424
void show_regs(struct pt_regs *regs);
25+
void show_code(struct pt_regs *regs);
2526

2627
#endif /* __ASM_CSKY_BUG_H */

arch/csky/include/asm/irq_work.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#ifndef __ASM_CSKY_IRQ_WORK_H
4+
#define __ASM_CSKY_IRQ_WORK_H
5+
6+
static inline bool arch_irq_work_has_interrupt(void)
7+
{
8+
return true;
9+
}
10+
extern void arch_irq_work_raise(void);
11+
#endif /* __ASM_CSKY_IRQ_WORK_H */

arch/csky/include/asm/processor.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ static inline void release_thread(struct task_struct *dead_task)
8282

8383
extern int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
8484

85-
#define copy_segments(tsk, mm) do { } while (0)
86-
#define release_segments(mm) do { } while (0)
87-
#define forget_segments() do { } while (0)
88-
89-
extern unsigned long thread_saved_pc(struct task_struct *tsk);
90-
9185
unsigned long get_wchan(struct task_struct *p);
9286

9387
#define KSTK_EIP(tsk) (task_pt_regs(tsk)->pc)

arch/csky/include/asm/ptrace.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define user_mode(regs) (!((regs)->sr & PS_S))
2525
#define instruction_pointer(regs) ((regs)->pc)
2626
#define profile_pc(regs) instruction_pointer(regs)
27+
#define trap_no(regs) ((regs->sr >> 16) & 0xff)
2728

2829
static inline void instruction_pointer_set(struct pt_regs *regs,
2930
unsigned long val)
@@ -52,6 +53,12 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
5253
return regs->a0;
5354
}
5455

56+
static inline void regs_set_return_value(struct pt_regs *regs,
57+
unsigned long val)
58+
{
59+
regs->a0 = val;
60+
}
61+
5562
/* Valid only for Kernel mode traps. */
5663
static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
5764
{

arch/csky/include/asm/thread_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,6 @@ static inline struct thread_info *current_thread_info(void)
8585
_TIF_NOTIFY_RESUME | _TIF_UPROBE)
8686

8787
#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
88-
_TIF_SYSCALL_TRACEPOINT)
88+
_TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
8989

9090
#endif /* _ASM_CSKY_THREAD_INFO_H */

arch/csky/kernel/entry.S

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@
2323
#endif
2424
.endm
2525

26+
.macro context_tracking
27+
#ifdef CONFIG_CONTEXT_TRACKING
28+
mfcr a0, epsr
29+
btsti a0, 31
30+
bt 1f
31+
jbsr context_tracking_user_exit
32+
ldw a0, (sp, LSAVE_A0)
33+
ldw a1, (sp, LSAVE_A1)
34+
ldw a2, (sp, LSAVE_A2)
35+
ldw a3, (sp, LSAVE_A3)
36+
#if defined(__CSKYABIV1__)
37+
ldw r6, (sp, LSAVE_A4)
38+
ldw r7, (sp, LSAVE_A5)
39+
#endif
40+
1:
41+
#endif
42+
.endm
43+
2644
.macro tlbop_begin name, val0, val1, val2
2745
ENTRY(csky_\name)
2846
mtcr a3, ss2
@@ -103,6 +121,7 @@ ENTRY(csky_\name)
103121
.endm
104122
.macro tlbop_end is_write
105123
zero_fp
124+
context_tracking
106125
RD_MEH a2
107126
psrset ee, ie
108127
mov a0, sp
@@ -128,6 +147,7 @@ tlbop_end 1
128147
ENTRY(csky_systemcall)
129148
SAVE_ALL TRAP0_SIZE
130149
zero_fp
150+
context_tracking
131151
psrset ee, ie
132152

133153
lrw r9, __NR_syscalls
@@ -168,6 +188,8 @@ ENTRY(csky_systemcall)
168188
csky_syscall_trace:
169189
mov a0, sp /* sp = pt_regs pointer */
170190
jbsr syscall_trace_enter
191+
cmpnei a0, 0
192+
bt 1f
171193
/* Prepare args before do system call */
172194
ldw a0, (sp, LSAVE_A0)
173195
ldw a1, (sp, LSAVE_A1)
@@ -188,6 +210,7 @@ csky_syscall_trace:
188210
#endif
189211
stw a0, (sp, LSAVE_A0) /* Save return value */
190212

213+
1:
191214
#ifdef CONFIG_DEBUG_RSEQ
192215
mov a0, sp
193216
jbsr rseq_syscall
@@ -234,6 +257,9 @@ ret_from_exception:
234257
and r10, r9
235258
cmpnei r10, 0
236259
bt exit_work
260+
#ifdef CONFIG_CONTEXT_TRACKING
261+
jbsr context_tracking_user_enter
262+
#endif
237263
1:
238264
#ifdef CONFIG_PREEMPTION
239265
mov r9, sp
@@ -274,6 +300,7 @@ work_resched:
274300
ENTRY(csky_trap)
275301
SAVE_ALL 0
276302
zero_fp
303+
context_tracking
277304
psrset ee
278305
mov a0, sp /* Push Stack pointer arg */
279306
jbsr trap_c /* Call C-level trap handler */
@@ -308,6 +335,7 @@ ENTRY(csky_get_tls)
308335
ENTRY(csky_irq)
309336
SAVE_ALL 0
310337
zero_fp
338+
context_tracking
311339
psrset ee
312340

313341
#ifdef CONFIG_TRACE_IRQFLAGS

0 commit comments

Comments
 (0)