Skip to content

Commit

Permalink
Merge tag 'csky-for-linus-5.9-rc1' of https://github.com/c-sky/csky-l…
Browse files Browse the repository at this point in the history
…inux

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
  • Loading branch information
torvalds committed Aug 6, 2020
2 parents bbcf9cd + bdcd93e commit 2044513
Show file tree
Hide file tree
Showing 19 changed files with 318 additions and 143 deletions.
29 changes: 28 additions & 1 deletion arch/csky/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ config CSKY
select ARCH_USE_BUILTIN_BSWAP
select ARCH_USE_QUEUED_RWLOCKS if NR_CPUS>2
select ARCH_WANT_FRAME_POINTERS if !CPU_CK610
select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT
select COMMON_CLK
select CLKSRC_MMIO
select CSKY_MPINTC if CPU_CK860
Expand Down Expand Up @@ -38,11 +39,16 @@ config CSKY
select GX6605S_TIMER if CPU_CK610
select HAVE_ARCH_TRACEHOOK
select HAVE_ARCH_AUDITSYSCALL
select HAVE_ARCH_MMAP_RND_BITS
select HAVE_ARCH_SECCOMP_FILTER
select HAVE_CONTEXT_TRACKING
select HAVE_VIRT_CPU_ACCOUNTING_GEN
select HAVE_DEBUG_BUGVERBOSE
select HAVE_DYNAMIC_FTRACE
select HAVE_DYNAMIC_FTRACE_WITH_REGS
select HAVE_FUNCTION_TRACER
select HAVE_FUNCTION_GRAPH_TRACER
select HAVE_FUNCTION_ERROR_INJECTION
select HAVE_FTRACE_MCOUNT_RECORD
select HAVE_KERNEL_GZIP
select HAVE_KERNEL_LZO
Expand Down Expand Up @@ -148,6 +154,14 @@ config L1_CACHE_SHIFT
default "5" if (CPU_CK807 || CPU_CK810)
default "6" if (CPU_CK860)

config ARCH_MMAP_RND_BITS_MIN
default 8

# max bits determined by the following formula:
# VA_BITS - PAGE_SHIFT - 3
config ARCH_MMAP_RND_BITS_MAX
default 17

menu "Processor type and features"

choice
Expand Down Expand Up @@ -266,7 +280,7 @@ config NR_CPUS
int "Maximum number of CPUs (2-32)"
range 2 32
depends on SMP
default "2"
default "4"

config HIGHMEM
bool "High Memory Support"
Expand Down Expand Up @@ -295,3 +309,16 @@ endmenu
source "arch/csky/Kconfig.platforms"

source "kernel/Kconfig.hz"

config SECCOMP
bool "Enable seccomp to safely compute untrusted bytecode"
help
This kernel feature is useful for number crunching applications
that may need to compute untrusted bytecode during their
execution. By using pipes or other transports made available to
the process as file descriptors supporting the read/write
syscalls, it's possible to isolate those applications in
their own address space using seccomp. Once seccomp is
enabled via prctl(PR_SET_SECCOMP), it cannot be disabled
and the task is only allowed to execute a few safe syscalls
defined by each seccomp mode.
3 changes: 0 additions & 3 deletions arch/csky/abiv2/inc/abi/entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@

.macro RESTORE_REGS_FTRACE
ldw tls, (sp, 0)
ldw a0, (sp, 16)
mtcr a0, ss0

#ifdef CONFIG_CPU_HAS_HILO
ldw a0, (sp, 140)
Expand All @@ -158,7 +156,6 @@
addi sp, 40
ldm r16-r30, (sp)
addi sp, 72
mfcr sp, ss0
.endm

.macro SAVE_SWITCH_STACK
Expand Down
4 changes: 3 additions & 1 deletion arch/csky/abiv2/mcount.S
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@

.macro mcount_exit_regs
RESTORE_REGS_FTRACE
ldw t1, (sp, 0)
subi sp, 152
ldw t1, (sp, 4)
addi sp, 152
ldw r8, (sp, 4)
ldw lr, (sp, 8)
addi sp, 12
Expand Down
1 change: 1 addition & 0 deletions arch/csky/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ generic-y += gpio.h
generic-y += kvm_para.h
generic-y += local64.h
generic-y += qrwlock.h
generic-y += seccomp.h
generic-y += user.h
generic-y += vmlinux.lds.h
3 changes: 2 additions & 1 deletion arch/csky/include/asm/bug.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ do { \

struct pt_regs;

void die_if_kernel(char *str, struct pt_regs *regs, int nr);
void die(struct pt_regs *regs, const char *str);
void show_regs(struct pt_regs *regs);
void show_code(struct pt_regs *regs);

#endif /* __ASM_CSKY_BUG_H */
11 changes: 11 additions & 0 deletions arch/csky/include/asm/irq_work.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* SPDX-License-Identifier: GPL-2.0 */

#ifndef __ASM_CSKY_IRQ_WORK_H
#define __ASM_CSKY_IRQ_WORK_H

static inline bool arch_irq_work_has_interrupt(void)
{
return true;
}
extern void arch_irq_work_raise(void);
#endif /* __ASM_CSKY_IRQ_WORK_H */
6 changes: 0 additions & 6 deletions arch/csky/include/asm/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ static inline void release_thread(struct task_struct *dead_task)

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

#define copy_segments(tsk, mm) do { } while (0)
#define release_segments(mm) do { } while (0)
#define forget_segments() do { } while (0)

extern unsigned long thread_saved_pc(struct task_struct *tsk);

unsigned long get_wchan(struct task_struct *p);

#define KSTK_EIP(tsk) (task_pt_regs(tsk)->pc)
Expand Down
7 changes: 7 additions & 0 deletions arch/csky/include/asm/ptrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define user_mode(regs) (!((regs)->sr & PS_S))
#define instruction_pointer(regs) ((regs)->pc)
#define profile_pc(regs) instruction_pointer(regs)
#define trap_no(regs) ((regs->sr >> 16) & 0xff)

static inline void instruction_pointer_set(struct pt_regs *regs,
unsigned long val)
Expand Down Expand Up @@ -52,6 +53,12 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
return regs->a0;
}

static inline void regs_set_return_value(struct pt_regs *regs,
unsigned long val)
{
regs->a0 = val;
}

/* Valid only for Kernel mode traps. */
static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
{
Expand Down
2 changes: 1 addition & 1 deletion arch/csky/include/asm/thread_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ static inline struct thread_info *current_thread_info(void)
_TIF_NOTIFY_RESUME | _TIF_UPROBE)

#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
_TIF_SYSCALL_TRACEPOINT)
_TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)

#endif /* _ASM_CSKY_THREAD_INFO_H */
28 changes: 28 additions & 0 deletions arch/csky/kernel/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@
#endif
.endm

.macro context_tracking
#ifdef CONFIG_CONTEXT_TRACKING
mfcr a0, epsr
btsti a0, 31
bt 1f
jbsr context_tracking_user_exit
ldw a0, (sp, LSAVE_A0)
ldw a1, (sp, LSAVE_A1)
ldw a2, (sp, LSAVE_A2)
ldw a3, (sp, LSAVE_A3)
#if defined(__CSKYABIV1__)
ldw r6, (sp, LSAVE_A4)
ldw r7, (sp, LSAVE_A5)
#endif
1:
#endif
.endm

.macro tlbop_begin name, val0, val1, val2
ENTRY(csky_\name)
mtcr a3, ss2
Expand Down Expand Up @@ -103,6 +121,7 @@ ENTRY(csky_\name)
.endm
.macro tlbop_end is_write
zero_fp
context_tracking
RD_MEH a2
psrset ee, ie
mov a0, sp
Expand All @@ -128,6 +147,7 @@ tlbop_end 1
ENTRY(csky_systemcall)
SAVE_ALL TRAP0_SIZE
zero_fp
context_tracking
psrset ee, ie

lrw r9, __NR_syscalls
Expand Down Expand Up @@ -168,6 +188,8 @@ ENTRY(csky_systemcall)
csky_syscall_trace:
mov a0, sp /* sp = pt_regs pointer */
jbsr syscall_trace_enter
cmpnei a0, 0
bt 1f
/* Prepare args before do system call */
ldw a0, (sp, LSAVE_A0)
ldw a1, (sp, LSAVE_A1)
Expand All @@ -188,6 +210,7 @@ csky_syscall_trace:
#endif
stw a0, (sp, LSAVE_A0) /* Save return value */

1:
#ifdef CONFIG_DEBUG_RSEQ
mov a0, sp
jbsr rseq_syscall
Expand Down Expand Up @@ -234,6 +257,9 @@ ret_from_exception:
and r10, r9
cmpnei r10, 0
bt exit_work
#ifdef CONFIG_CONTEXT_TRACKING
jbsr context_tracking_user_enter
#endif
1:
#ifdef CONFIG_PREEMPTION
mov r9, sp
Expand Down Expand Up @@ -274,6 +300,7 @@ work_resched:
ENTRY(csky_trap)
SAVE_ALL 0
zero_fp
context_tracking
psrset ee
mov a0, sp /* Push Stack pointer arg */
jbsr trap_c /* Call C-level trap handler */
Expand Down Expand Up @@ -308,6 +335,7 @@ ENTRY(csky_get_tls)
ENTRY(csky_irq)
SAVE_ALL 0
zero_fp
context_tracking
psrset ee

#ifdef CONFIG_TRACE_IRQFLAGS
Expand Down
10 changes: 0 additions & 10 deletions arch/csky/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ asmlinkage void ret_from_kernel_thread(void);
*/
void flush_thread(void){}

/*
* Return saved PC from a blocked thread
*/
unsigned long thread_saved_pc(struct task_struct *tsk)
{
struct switch_stack *sw = (struct switch_stack *)tsk->thread.sp;

return sw->r15;
}

int copy_thread(unsigned long clone_flags,
unsigned long usp,
unsigned long kthread_arg,
Expand Down
37 changes: 8 additions & 29 deletions arch/csky/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,20 @@ long arch_ptrace(struct task_struct *child, long request,
return ret;
}

asmlinkage void syscall_trace_enter(struct pt_regs *regs)
asmlinkage int syscall_trace_enter(struct pt_regs *regs)
{
if (test_thread_flag(TIF_SYSCALL_TRACE))
if (tracehook_report_syscall_entry(regs))
syscall_set_nr(current, regs, -1);
return -1;

if (secure_computing() == -1)
return -1;

if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
trace_sys_enter(regs, syscall_get_nr(current, regs));

audit_syscall_entry(regs_syscallid(regs), regs->a0, regs->a1, regs->a2, regs->a3);
return 0;
}

asmlinkage void syscall_trace_exit(struct pt_regs *regs)
Expand All @@ -343,13 +347,8 @@ asmlinkage void syscall_trace_exit(struct pt_regs *regs)
trace_sys_exit(regs, syscall_get_return_value(current, regs));
}

extern void show_stack(struct task_struct *task, unsigned long *stack, const char *loglvl);
void show_regs(struct pt_regs *fp)
{
unsigned long *sp;
unsigned char *tp;
int i;

pr_info("\nCURRENT PROCESS:\n\n");
pr_info("COMM=%s PID=%d\n", current->comm, current->pid);

Expand Down Expand Up @@ -396,29 +395,9 @@ void show_regs(struct pt_regs *fp)
fp->regs[0], fp->regs[1], fp->regs[2], fp->regs[3]);
pr_info("r10: 0x%08lx r11: 0x%08lx r12: 0x%08lx r13: 0x%08lx\n",
fp->regs[4], fp->regs[5], fp->regs[6], fp->regs[7]);
pr_info("r14: 0x%08lx r1: 0x%08lx r15: 0x%08lx\n",
fp->regs[8], fp->regs[9], fp->lr);
pr_info("r14: 0x%08lx r1: 0x%08lx\n",
fp->regs[8], fp->regs[9]);
#endif

pr_info("\nCODE:");
tp = ((unsigned char *) fp->pc) - 0x20;
tp += ((int)tp % 4) ? 2 : 0;
for (sp = (unsigned long *) tp, i = 0; (i < 0x40); i += 4) {
if ((i % 0x10) == 0)
pr_cont("\n%08x: ", (int) (tp + i));
pr_cont("%08x ", (int) *sp++);
}
pr_cont("\n");

pr_info("\nKERNEL STACK:");
tp = ((unsigned char *) fp) - 0x40;
for (sp = (unsigned long *) tp, i = 0; (i < 0xc0); i += 4) {
if ((i % 0x10) == 0)
pr_cont("\n%08x: ", (int) (tp + i));
pr_cont("%08x ", (int) *sp++);
}
pr_cont("\n");

show_stack(NULL, (unsigned long *)fp->regs[4], KERN_INFO);
return;
}
Loading

0 comments on commit 2044513

Please sign in to comment.