misc cleanups v2
Subsystems (4)
Hi Palmer,
below is a number of small cleanups and improvements that started piling up during work to support the RISC-V kernel in nommu port. While that port isn't quite ready yet these patches should be useful on their own.
Changes since v1:
- fix up a few patch descriptions
- fix the interrupt cause patch to actually compile without further prep patches, doh!
- remove dead code related to non-framepointer builds
- remove another big endian ifdef
- add another patch from my nommu stack to clean up the parse_dtb calling conventions
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH 1/12 riscv: use asm-generic/extable.h
--- arch/riscv/include/asm/Kbuild | 1 + arch/riscv/include/asm/uaccess.h | 7 +------ 2 files changed, 2 insertions(+), 6 deletions(-)
arch/riscv/include/asm/Kbuild +1 -0
@@ -4,6 +4,7 @@ generic-y += compat.h generic-y += cputime.h generic-y += device.h generic-y += div64.h +generic-y += extable.h generic-y += dma.h generic-y += dma-contiguous.h generic-y += dma-mapping.h
arch/riscv/include/asm/uaccess.h +1 -6
@@ -23,6 +23,7 @@#include <linux/compiler.h> #include <linux/thread_info.h> #include <asm/byteorder.h> +#include <asm/extable.h> #include <asm/asm.h> #define __enable_user_access () \
@@ -98,12 +99,6 @@ static inline int __access_ok(unsigned long addr, unsigned long size)* on our cache or tlb entries. */ -struct exception_table_entry { -unsigned long insn, fixup; -}; - -extern int fixup_exception (struct pt_regs *state); -#if defined(__LITTLE_ENDIAN)#define __MSW 1#define __LSW 0
Signature · 7 lines
2.20.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH 2/12 riscv: turn mm_segment_t into a struct
In reply to Christoph HellwigThis matches what other heavily used architectures do, and will allow us to easily use <asm-generic/uaccess.h> for the nommu case.
--- arch/riscv/include/asm/thread_info.h | 4 +++- arch/riscv/include/asm/uaccess.h | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-)
arch/riscv/include/asm/thread_info.h +3 -1
@@ -28,7 +28,9 @@#include <asm/processor.h> #include <asm/csr.h> -typedef unsigned long mm_segment_t ; +typedef struct { +unsigned long seg; +}mm_segment_t ;/* * low level task data that entry.S needs immediate access to
arch/riscv/include/asm/uaccess.h +7 -5
@@ -39,8 +39,10 @@* For historical reasons, these macros are grossly misnamed. */ -#define KERNEL_DS (~0UL) -#define USER_DS (TASK_SIZE) +#define MAKE_MM_SEG (s) ((mm_segment_t) { (s) }) + +#define KERNEL_DS MAKE_MM_SEG(~0UL) +#define USER_DS MAKE_MM_SEG(TASK_SIZE)#define get_fs () (current_thread_info()->addr_limit)
@@ -49,9 +51,9 @@ static inline void set_fs(mm_segment_t fs)current_thread_info ()->addr_limit = fs; } -#define segment_eq (a, b) ((a) == (b)) +#define segment_eq (a, b) ((a).seg == (b).seg) -#define user_addr_max () (get_fs()) +#define user_addr_max () (get_fs().seg)/**
@@ -83,7 +85,7 @@ static inline int __access_ok(unsigned long addr, unsigned long size) {const mm_segment_t fs =get_fs (); -return (size <= fs) && (addr <= (fs - size)); +return size <= fs.seg && addr <= fs.seg - size; }/*
Signature · 7 lines
2.20.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH 3/12 riscv: remove unreachable big endian code
In reply to Christoph HellwigRISC-V is always little endian.
--- arch/riscv/include/asm/elf.h | 6 ------ arch/riscv/include/asm/uaccess.h | 9 +-------- 2 files changed, 1 insertion(+), 14 deletions(-)
arch/riscv/include/asm/elf.h +0 -6
@@ -27,13 +27,7 @@#define ELF_CLASS ELFCLASS32#endif -#if defined(__LITTLE_ENDIAN)#define ELF_DATA ELFDATA2LSB -#elif defined(__BIG_ENDIAN) -#define ELF_DATA ELFDATA2MSB -#else -#error "Unknown endianness" -#endif /* * This is used to ensure we don't load something for the wrong architecture.
arch/riscv/include/asm/uaccess.h +1 -8
@@ -101,15 +101,8 @@ static inline int __access_ok(unsigned long addr, unsigned long size)* on our cache or tlb entries. */ -#if defined(__LITTLE_ENDIAN) -#define __MSW 1#define __LSW 0 -#elif defined(__BIG_ENDIAN) -#define __MSW 0 -#define __LSW 1 -#else -#error "Unknown endianness" -#endif +#define __MSW 1/* * The "__xxx" versions of the user access functions do not verify the address
Signature · 7 lines
2.20.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH 4/12 riscv: remove CONFIG_RISCV_ISA_A
In reply to Christoph HellwigThis option is always enabled, and not supporting the A extensions would create a complete ABI trainwreck, so there is no point in even slightly encouraging such an idea by keeping this unselectable code around.
--- arch/riscv/Kconfig | 6 +----- arch/riscv/Makefile | 5 ++--- arch/riscv/include/asm/futex.h | 13 ------------- 3 files changed, 3 insertions(+), 21 deletions(-)
arch/riscv/Kconfig +1 -5
@@ -27,7 +27,7 @@ config RISCV select GENERIC_STRNCPY_FROM_USER select GENERIC_STRNLEN_USER select GENERIC_SMP_IDLE_THREAD - select GENERIC_ATOMIC64 if !64BIT || !RISCV_ISA_A + select GENERIC_ATOMIC64 if !64BIT select HAVE_ARCH_AUDITSYSCALL select HAVE_MEMBLOCK_NODE_MAP select HAVE_DMA_CONTIGUOUS
@@ -35,7 +35,6 @@ config RISCV select HAVE_PERF_EVENTS select HAVE_SYSCALL_TRACEPOINTS select IRQ_DOMAIN - select RISCV_ISA_A if SMP select SPARSE_IRQ select SYSCTL_EXCEPTION_TRACE select HAVE_ARCH_TRACEHOOK
@@ -197,9 +196,6 @@ config RISCV_ISA_C If you don't know what to do here, say Y. -config RISCV_ISA_A - def_bool y - menu "supported PMU type" depends on PERF_EVENTS
arch/riscv/Makefile +2 -3
@@ -39,9 +39,8 @@ endif KBUILD_CFLAGS += -Wall # ISA string setting -riscv-march-$(CONFIG_ARCH_RV32I) := rv32im -riscv-march-$(CONFIG_ARCH_RV64I) := rv64im -riscv-march-$(CONFIG_RISCV_ISA_A) := $(riscv-march-y)a +riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima +riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
arch/riscv/include/asm/futex.h +0 -13
@@ -7,18 +7,6 @@#ifndef _ASM_FUTEX_H#define _ASM_FUTEX_H -#ifndef CONFIG_RISCV_ISA_A -/* -* Use the generic interrupt disabling versions if the A extension -* is not supported. -*/ -#ifdef CONFIG_SMP -#error "Can't support generic futex calls without A extension on SMP" -#endif -#include <asm-generic/futex.h> - -#else /* CONFIG_RISCV_ISA_A */ -#include <linux/futex.h> #include <linux/uaccess.h> #include <linux/errno.h>
@@ -124,5 +112,4 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, return ret; } -#endif /* CONFIG_RISCV_ISA_A */ #endif /* _ASM_FUTEX_H */
Signature · 7 lines
2.20.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH 5/12 riscv: clear all pending interrupts when booting
In reply to Christoph HellwigJust in case an old interrupt is pending make sure we clear everything asserted before this kernel started. Based on similar M-mode code in opensbi.
--- arch/riscv/kernel/head.S | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/riscv/kernel/head.S +2 -1
@@ -22,8 +22,9 @@ __INIT ENTRY(_start) - /* Mask all interrupts */ + /* Mask and clear all interrupts */ csrw sie, zero + csrw sip, zero /* Load the global pointer */ .option push
Signature · 7 lines
2.20.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH 6/12 riscv: simplify the stack pointer setup in head.S
In reply to Christoph HellwigWe don't need THREAD_SIZE in asm-offsets.c as we can just calculate the value of init_thread_union + THREAD_SIZE using cpp, just like we do a few lines above.
--- arch/riscv/kernel/asm-offsets.c | 3 --- arch/riscv/kernel/head.S | 5 +---- 2 files changed, 1 insertion(+), 7 deletions(-)
arch/riscv/kernel/asm-offsets.c +0 -3
@@ -312,9 +312,6 @@ void asm_offsets(void) - offsetof(struct task_struct, thread.fstate.f[0]) ); -/* The assembler needs access to THREAD_SIZE as well. */ -DEFINE (ASM_THREAD_SIZE ,THREAD_SIZE ); -/* * We allocate a pt_regs on the stack when entering the kernel. This * ensures the alignment is sane.
arch/riscv/kernel/head.S +1 -4
@@ -69,10 +69,7 @@ clear_bss_done: /* Restore C environment */ la tp, init_task sw zero, TASK_TI_CPU(tp) - - la sp, init_thread_union - li a0, ASM_THREAD_SIZE - add sp, sp, a0 + la sp, init_thread_union + THREAD_SIZE /* Start the kernel */ mv a0, s0
Signature · 7 lines
2.20.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH 7/12 riscv: cleanup the parse_dtb calling conventions
In reply to Christoph HellwigNo need to pass the hartid, and the dtb address passed is a physical address, so don't pretend it is a kernel pointer.
--- arch/riscv/kernel/head.S | 3 +-- arch/riscv/kernel/setup.c | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-)
arch/riscv/kernel/head.S +1 -2
@@ -72,8 +72,7 @@ clear_bss_done: la sp, init_thread_union + THREAD_SIZE /* Start the kernel */ - mv a0, s0 - mv a1, s1 + mv a0, s1 call parse_dtb tail start_kernel
arch/riscv/kernel/setup.c +4 -2
@@ -52,9 +52,11 @@ struct screen_info screen_info = {atomic_t hart_lottery;unsigned long boot_cpu_hartid; -void __init parse_dtb (unsigned int hartid,void *dtb) +void __init parse_dtb (phys_addr_t dtb_phys) { -if (early_init_dt_scan (__va (dtb))) +void *dtb =__va (dtb_phys); + +if (early_init_dt_scan (dtb))return ;pr_err ("No DTB passed to the kernel\n" );
Signature · 7 lines
2.20.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH 8/12 riscv: remove unreachable !CONFIG_FRAME_POINTER code
In reply to Christoph HellwigThe RISC-V port selects CONFIG_ARCH_WANT_FRAME_POINTERS, which causes CONFIG_FRAME_POINTER to always be set. Remove the unreachable code for the !CONFIG_FRAME_POINTER case.
--- arch/riscv/include/asm/ftrace.h | 6 +----- arch/riscv/kernel/stacktrace.c | 37 --------------------------------- 2 files changed, 1 insertion(+), 42 deletions(-)
arch/riscv/include/asm/ftrace.h +1 -5
@@ -1,11 +1,7 @@/* SPDX-License-Identifier: GPL-2.0 */ /* Copyright (C) 2017 Andes Technology Corporation */ -/* -* The graph frame test is not possible if CONFIG_FRAME_POINTER is not enabled. -* Check arch/riscv/kernel/mcount.S for detail. -*/ -#if defined(CONFIG_FUNCTION_GRAPH_TRACER ) && defined(CONFIG_FRAME_POINTER ) +#ifdef CONFIG_FUNCTION_GRAPH_TRACER #define HAVE_FUNCTION_GRAPH_FP_TEST #endif #define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
arch/riscv/kernel/stacktrace.c +0 -37
@@ -20,8 +20,6 @@#include <linux/stacktrace.h> #include <linux/ftrace.h> -#ifdef CONFIG_FRAME_POINTER -struct stackframe {unsigned long fp;unsigned long ra;
@@ -73,41 +71,6 @@ static void notrace walk_stackframe(struct task_struct *task, } } -#else /* !CONFIG_FRAME_POINTER */ - -static void notrace walk_stackframe(struct task_struct *task, -struct pt_regs *regs,bool (*fn)(unsigned long ,void *),void *arg) -{ -unsigned long sp, pc; -unsigned long *ksp; - -if (regs) { - sp =GET_USP (regs); - pc =GET_IP (regs); - }else if (task ==NULL || task == current) { -const registerunsigned long current_sp __asm__ ("sp" ); - sp = current_sp; - pc = (unsigned long )walk_stackframe; - }else { -/* task blocked in __switch_to */ - sp = task->thread.sp; - pc = task->thread.ra; - } - -if (unlikely (sp &0x7 )) -return ; - - ksp = (unsigned long *)sp; -while (!kstack_end (ksp)) { -if (__kernel_text_address (pc) &&unlikely (fn (pc, arg))) -break ; - pc = (*ksp++) -0x4 ; - } -} - -#endif /* CONFIG_FRAME_POINTER */ - -static bool print_trace_address (unsigned long pc,void *arg) {print_ip_sym (pc);
Signature · 7 lines
2.20.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH 9/12 riscv: remove unreachable !HAVE_FUNCTION_GRAPH_RET_ADDR_PTR code
In reply to Christoph HellwigHAVE_FUNCTION_GRAPH_RET_ADDR_PTR is always defined for RISC-V.
--- arch/riscv/kernel/stacktrace.c | 4 ---- 1 file changed, 4 deletions(-)
arch/riscv/kernel/stacktrace.c +0 -4
@@ -62,12 +62,8 @@ static void notrace walk_stackframe(struct task_struct *task, frame = (struct stackframe *)fp -1 ; sp = fp; fp = frame->fp; -#ifdef HAVE_FUNCTION_GRAPH_RET_ADDR_PTR pc =ftrace_graph_ret_addr (current,NULL , frame->ra, (unsigned long *)(fp -8 )); -#else - pc = frame->ra -0x4 ; -#endif } }
Signature · 7 lines
2.20.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH 10/12 riscv: remove duplicate macros from ptrace.h
In reply to Christoph HellwigNo need to have two names for the same thing.
--- arch/riscv/include/asm/ptrace.h | 21 ++++++--------------- arch/riscv/kernel/stacktrace.c | 6 +++--- arch/riscv/kernel/traps.c | 2 +- 3 files changed, 10 insertions(+), 19 deletions(-)
arch/riscv/include/asm/ptrace.h +6 -15
@@ -70,47 +70,38 @@ struct pt_regs {/* Helpers for working with the instruction pointer */ -#define GET_IP (regs) ((regs)->sepc) -#define SET_IP (regs, val) (GET_IP(regs) = (val)) -static inline unsigned long instruction_pointer (struct pt_regs *regs) { -return GET_IP (regs); +return regs->sepc; }static inline void instruction_pointer_set (struct pt_regs *regs,unsigned long val) { -SET_IP (regs, val); + regs->sepc = val; }#define profile_pc (regs) instruction_pointer(regs)/* Helpers for working with the user stack pointer */ -#define GET_USP (regs) ((regs)->sp) -#define SET_USP (regs, val) (GET_USP(regs) = (val)) -static inline unsigned long user_stack_pointer (struct pt_regs *regs) { -return GET_USP (regs); +return regs->sp; }static inline void user_stack_pointer_set (struct pt_regs *regs,unsigned long val) { -SET_USP (regs, val); + regs->sp = val; }/* Helpers for working with the frame pointer */ -#define GET_FP (regs) ((regs)->s0) -#define SET_FP (regs, val) (GET_FP(regs) = (val)) -static inline unsigned long frame_pointer (struct pt_regs *regs) { -return GET_FP (regs); +return regs->s0; }static inline void frame_pointer_set (struct pt_regs *regs,unsigned long val) { -SET_FP (regs, val); + regs->s0 = val; }static inline unsigned long regs_return_value (struct pt_regs *regs)
arch/riscv/kernel/stacktrace.c +3 -3
@@ -31,9 +31,9 @@ static void notrace walk_stackframe(struct task_struct *task,unsigned long fp, sp, pc;if (regs) { - fp =GET_FP (regs); - sp =GET_USP (regs); - pc =GET_IP (regs); + fp =frame_pointer (regs); + sp =user_stack_pointer (regs); + pc =instruction_pointer (regs); }else if (task ==NULL || task == current) {const registerunsigned long current_sp __asm__ ("sp" ); fp = (unsigned long )__builtin_frame_address (0 );
arch/riscv/kernel/traps.c +1 -1
@@ -70,7 +70,7 @@ void do_trap(struct pt_regs *regs, int signo, int code, && printk_ratelimit()) {pr_info ("%s[%d]: unhandled signal %d code 0x%x at 0x" REG_FMT , tsk->comm,task_pid_nr (tsk), signo, code, addr); -print_vma_addr (KERN_CONT " in " ,GET_IP (regs)); +print_vma_addr (KERN_CONT " in " ,instruction_pointer (regs));pr_cont ("\n" );show_regs (regs); }
Signature · 7 lines
2.20.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH 11/12 riscv: print the unexpected interrupt cause
In reply to Christoph HellwigThis has been helpful when debugging my pending nommu port.
--- arch/riscv/kernel/irq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/riscv/kernel/irq.c +2 -1
@@ -54,7 +54,8 @@ asmlinkage void __irq_entry do_IRQ(struct pt_regs *regs)handle_arch_irq (regs);break ;default : -panic ("unexpected interrupt cause" ); +pr_alert ("unexpected interrupt cause 0x%lx" , regs->scause); +BUG (); }irq_exit ();
Signature · 7 lines
2.20.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH 11/12] riscv: print the unexpected interrupt cause
Στις 2019-04-12 17:39, Christoph Hellwig έγραψε:
Quoted 12 lines
This has been helpful when debugging my pending nommu port.
Signed-off-by Christoph Hellwig <[email protected]>--- arch/riscv/kernel/irq.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/riscv/kernel/irq.c +0
-0
arch/riscv/kernel/irq.c asmlinkage void __irq_entry do_IRQ(struct pt_regs · line 61
Quoted 9 lines
arch/riscv/kernel/irq.c +2
-1@@ -54,7 +54,8 @@ asmlinkage void __irq_entry do_IRQ(struct pt_regs *regs)handle_arch_irq (regs);break ;default : -panic ("unexpected interrupt cause" ); +pr_alert ("unexpected interrupt cause 0x%lx" , regs->scause); +BUG (); }irq_exit ();
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH 12/12 riscv: call pm_power_off from machine_halt / machine_power_off
In reply to Christoph HellwigThis way any override of pm_power_off also affects the halt path and we don't need additional infrastructure for it.
Also remove the pm_power_off export - at least for now we don't have any modular drivers overriding it.
--- arch/riscv/kernel/reset.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
arch/riscv/kernel/reset.c +9 -6
@@ -12,11 +12,15 @@*/ #include <linux/reboot.h> -#include <linux/export.h> #include <asm/sbi.h> -void (*pm_power_off)(void ) = machine_power_off; -EXPORT_SYMBOL (pm_power_off); +static void default_power_off (void ) +{ +sbi_shutdown (); +while (1 ); +} + +void (*pm_power_off)(void ) = default_power_off;void machine_restart (char *cmd) {
@@ -26,11 +30,10 @@ void machine_restart(char *cmd)void machine_halt (void ) { -machine_power_off (); +pm_power_off (); }void machine_power_off (void ) { -sbi_shutdown (); -while (1 ); +pm_power_off (); }
Signature · 7 lines
2.20.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv