Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f0bddf5

Browse files
guoren83palmer-dabbelt
authored andcommitted
riscv: entry: Convert to generic entry
This patch converts riscv to use the generic entry infrastructure from kernel/entry/*. The generic entry makes maintainers' work easier and codes more elegant. Here are the changes: - More clear entry.S with handle_exception and ret_from_exception - Get rid of complex custom signal implementation - Move syscall procedure from assembly to C, which is much more readable. - Connect ret_from_fork & ret_from_kernel_thread to generic entry. - Wrap with irqentry_enter/exit and syscall_enter/exit_from_user_mode - Use the standard preemption code instead of custom Suggested-by: Huacai Chen <[email protected]> Reviewed-by: Björn Töpel <[email protected]> Tested-by: Yipeng Zou <[email protected]> Tested-by: Jisheng Zhang <[email protected]> Signed-off-by: Guo Ren <[email protected]> Signed-off-by: Guo Ren <[email protected]> Cc: Ben Hutchings <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent d0db02c commit f0bddf5

File tree

14 files changed

+210
-315
lines changed

14 files changed

+210
-315
lines changed

arch/riscv/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ config RISCV
6060
select GENERIC_ATOMIC64 if !64BIT
6161
select GENERIC_CLOCKEVENTS_BROADCAST if SMP
6262
select GENERIC_EARLY_IOREMAP
63+
select GENERIC_ENTRY
6364
select GENERIC_GETTIMEOFDAY if HAVE_GENERIC_VDSO
6465
select GENERIC_IDLE_POLL_SETUP
6566
select GENERIC_IOREMAP if MMU

arch/riscv/include/asm/asm-prototypes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ DECLARE_DO_ERROR_INFO(do_trap_break);
2727

2828
asmlinkage unsigned long get_overflow_stack(void);
2929
asmlinkage void handle_bad_stack(struct pt_regs *regs);
30+
asmlinkage void do_page_fault(struct pt_regs *regs);
31+
asmlinkage void do_irq(struct pt_regs *regs);
3032

3133
#endif /* _ASM_RISCV_PROTOTYPES_H */

arch/riscv/include/asm/csr.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#define SR_UXL _AC(0x300000000, UL) /* XLEN mask for U-mode */
4141
#define SR_UXL_32 _AC(0x100000000, UL) /* XLEN = 32 for U-mode */
4242
#define SR_UXL_64 _AC(0x200000000, UL) /* XLEN = 64 for U-mode */
43-
#define SR_UXL_SHIFT 32
4443
#endif
4544

4645
/* SATP flags */
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_RISCV_ENTRY_COMMON_H
4+
#define _ASM_RISCV_ENTRY_COMMON_H
5+
6+
#include <asm/stacktrace.h>
7+
8+
void handle_page_fault(struct pt_regs *regs);
9+
void handle_break(struct pt_regs *regs);
10+
11+
#endif /* _ASM_RISCV_ENTRY_COMMON_H */

arch/riscv/include/asm/ptrace.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ struct pt_regs {
5353
unsigned long orig_a0;
5454
};
5555

56+
#define PTRACE_SYSEMU 0x1f
57+
#define PTRACE_SYSEMU_SINGLESTEP 0x20
58+
5659
#ifdef CONFIG_64BIT
5760
#define REG_FMT "%016lx"
5861
#else
@@ -121,8 +124,6 @@ extern unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
121124

122125
void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
123126
unsigned long frame_pointer);
124-
int do_syscall_trace_enter(struct pt_regs *regs);
125-
void do_syscall_trace_exit(struct pt_regs *regs);
126127

127128
/**
128129
* regs_get_register() - get register value from its offset
@@ -172,6 +173,11 @@ static inline unsigned long regs_get_kernel_argument(struct pt_regs *regs,
172173
return 0;
173174
}
174175

176+
static inline int regs_irqs_disabled(struct pt_regs *regs)
177+
{
178+
return !(regs->status & SR_PIE);
179+
}
180+
175181
#endif /* __ASSEMBLY__ */
176182

177183
#endif /* _ASM_RISCV_PTRACE_H */

arch/riscv/include/asm/stacktrace.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ extern void notrace walk_stackframe(struct task_struct *task, struct pt_regs *re
1616
extern void dump_backtrace(struct pt_regs *regs, struct task_struct *task,
1717
const char *loglvl);
1818

19+
static inline bool on_thread_stack(void)
20+
{
21+
return !(((unsigned long)(current->stack) ^ current_stack_pointer) & ~(THREAD_SIZE - 1));
22+
}
23+
1924
#endif /* _ASM_RISCV_STACKTRACE_H */

arch/riscv/include/asm/syscall.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,26 @@ static inline int syscall_get_arch(struct task_struct *task)
7474
#endif
7575
}
7676

77+
typedef long (*syscall_t)(ulong, ulong, ulong, ulong, ulong, ulong, ulong);
78+
static inline void syscall_handler(struct pt_regs *regs, ulong syscall)
79+
{
80+
syscall_t fn;
81+
82+
#ifdef CONFIG_COMPAT
83+
if ((regs->status & SR_UXL) == SR_UXL_32)
84+
fn = compat_sys_call_table[syscall];
85+
else
86+
#endif
87+
fn = sys_call_table[syscall];
88+
89+
regs->a0 = fn(regs->orig_a0, regs->a1, regs->a2,
90+
regs->a3, regs->a4, regs->a5, regs->a6);
91+
}
92+
93+
static inline bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs)
94+
{
95+
return false;
96+
}
97+
7798
asmlinkage long sys_riscv_flush_icache(uintptr_t, uintptr_t, uintptr_t);
7899
#endif /* _ASM_RISCV_SYSCALL_H */

arch/riscv/include/asm/thread_info.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct thread_info {
6767
long kernel_sp; /* Kernel stack pointer */
6868
long user_sp; /* User stack pointer */
6969
int cpu;
70+
unsigned long syscall_work; /* SYSCALL_WORK_ flags */
7071
};
7172

7273
/*
@@ -89,35 +90,23 @@ struct thread_info {
8990
* - pending work-to-be-done flags are in lowest half-word
9091
* - other flags in upper half-word(s)
9192
*/
92-
#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
9393
#define TIF_NOTIFY_RESUME 1 /* callback before returning to user */
9494
#define TIF_SIGPENDING 2 /* signal pending */
9595
#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
9696
#define TIF_RESTORE_SIGMASK 4 /* restore signal mask in do_signal() */
9797
#define TIF_MEMDIE 5 /* is terminating due to OOM killer */
98-
#define TIF_SYSCALL_TRACEPOINT 6 /* syscall tracepoint instrumentation */
99-
#define TIF_SYSCALL_AUDIT 7 /* syscall auditing */
100-
#define TIF_SECCOMP 8 /* syscall secure computing */
10198
#define TIF_NOTIFY_SIGNAL 9 /* signal notifications exist */
10299
#define TIF_UPROBE 10 /* uprobe breakpoint or singlestep */
103100
#define TIF_32BIT 11 /* compat-mode 32bit process */
104101

105-
#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
106102
#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
107103
#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
108104
#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
109-
#define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
110-
#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
111-
#define _TIF_SECCOMP (1 << TIF_SECCOMP)
112105
#define _TIF_NOTIFY_SIGNAL (1 << TIF_NOTIFY_SIGNAL)
113106
#define _TIF_UPROBE (1 << TIF_UPROBE)
114107

115108
#define _TIF_WORK_MASK \
116109
(_TIF_NOTIFY_RESUME | _TIF_SIGPENDING | _TIF_NEED_RESCHED | \
117110
_TIF_NOTIFY_SIGNAL | _TIF_UPROBE)
118111

119-
#define _TIF_SYSCALL_WORK \
120-
(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_AUDIT | \
121-
_TIF_SECCOMP)
122-
123112
#endif /* _ASM_RISCV_THREAD_INFO_H */

0 commit comments

Comments
 (0)