Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'riscv-for-linus-4.15-rc8_cleanups' of git://git.kernel.org/pub/scm/linux/kernel/git/palmer/linux

Pull RISC-V updates from Palmer Dabbelt:
"This contains what I hope are the last RISC-V changes to go into 4.15.
I know it's a bit last minute, but I think they're all fairly small
changes:

- SR_* constants have been renamed to match the latest ISA
specification.

- Some CONFIG_MMU #ifdef cruft has been removed. We've never
supported !CONFIG_MMU.

- __NR_riscv_flush_icache is now visible to userspace. We were hoping
to avoid making this public in order to force userspace to call the
vDSO entry, but it looks like QEMU's user-mode emulation doesn't
want to emulate a vDSO. In order to allow glibc to fall back to a
system call when the vDSO entry doesn't exist we're just

- Our defconfig is no long empty. This is another one that just
slipped through the cracks. The defconfig isn't perfect, but it's
at least close to what users will want for the first RISC-V
development board. Getting closer is kind of splitting hairs here:
none of the RISC-V specific drivers are in yet, so it's not like
things will boot out of the box.

The only one that's strictly necessary is the __NR_riscv_flush_icache
change, as I want that to be part of the public API starting from our
first kernel so nobody has to worry about it. The others are nice to
haves, but they seem sane for 4.15 to me"

* tag 'riscv-for-linus-4.15-rc8_cleanups' of git://git.kernel.org/pub/scm/linux/kernel/git/palmer/linux:
riscv: rename SR_* constants to match the spec
riscv: remove CONFIG_MMU ifdefs
RISC-V: Make __NR_riscv_flush_icache visible to userspace
RISC-V: Add a basic defconfig

+119 -71
+75
arch/riscv/configs/defconfig
··· 1 + CONFIG_SMP=y 2 + CONFIG_PCI=y 3 + CONFIG_PCIE_XILINX=y 4 + CONFIG_SYSVIPC=y 5 + CONFIG_POSIX_MQUEUE=y 6 + CONFIG_IKCONFIG=y 7 + CONFIG_IKCONFIG_PROC=y 8 + CONFIG_CGROUPS=y 9 + CONFIG_CGROUP_SCHED=y 10 + CONFIG_CFS_BANDWIDTH=y 11 + CONFIG_CGROUP_BPF=y 12 + CONFIG_NAMESPACES=y 13 + CONFIG_USER_NS=y 14 + CONFIG_BLK_DEV_INITRD=y 15 + CONFIG_EXPERT=y 16 + CONFIG_CHECKPOINT_RESTORE=y 17 + CONFIG_BPF_SYSCALL=y 18 + CONFIG_NET=y 19 + CONFIG_PACKET=y 20 + CONFIG_UNIX=y 21 + CONFIG_INET=y 22 + CONFIG_IP_MULTICAST=y 23 + CONFIG_IP_ADVANCED_ROUTER=y 24 + CONFIG_IP_PNP=y 25 + CONFIG_IP_PNP_DHCP=y 26 + CONFIG_IP_PNP_BOOTP=y 27 + CONFIG_IP_PNP_RARP=y 28 + CONFIG_NETLINK_DIAG=y 29 + CONFIG_DEVTMPFS=y 30 + CONFIG_BLK_DEV_LOOP=y 31 + CONFIG_VIRTIO_BLK=y 32 + CONFIG_BLK_DEV_SD=y 33 + CONFIG_BLK_DEV_SR=y 34 + CONFIG_ATA=y 35 + CONFIG_SATA_AHCI=y 36 + CONFIG_SATA_AHCI_PLATFORM=y 37 + CONFIG_NETDEVICES=y 38 + CONFIG_VIRTIO_NET=y 39 + CONFIG_MACB=y 40 + CONFIG_E1000E=y 41 + CONFIG_R8169=y 42 + CONFIG_MICROSEMI_PHY=y 43 + CONFIG_INPUT_MOUSEDEV=y 44 + CONFIG_SERIAL_8250=y 45 + CONFIG_SERIAL_8250_CONSOLE=y 46 + CONFIG_SERIAL_OF_PLATFORM=y 47 + # CONFIG_PTP_1588_CLOCK is not set 48 + CONFIG_DRM=y 49 + CONFIG_DRM_RADEON=y 50 + CONFIG_FRAMEBUFFER_CONSOLE=y 51 + CONFIG_USB=y 52 + CONFIG_USB_XHCI_HCD=y 53 + CONFIG_USB_XHCI_PLATFORM=y 54 + CONFIG_USB_EHCI_HCD=y 55 + CONFIG_USB_EHCI_HCD_PLATFORM=y 56 + CONFIG_USB_OHCI_HCD=y 57 + CONFIG_USB_OHCI_HCD_PLATFORM=y 58 + CONFIG_USB_STORAGE=y 59 + CONFIG_USB_UAS=y 60 + CONFIG_VIRTIO_MMIO=y 61 + CONFIG_RAS=y 62 + CONFIG_EXT4_FS=y 63 + CONFIG_EXT4_FS_POSIX_ACL=y 64 + CONFIG_AUTOFS4_FS=y 65 + CONFIG_MSDOS_FS=y 66 + CONFIG_VFAT_FS=y 67 + CONFIG_TMPFS=y 68 + CONFIG_TMPFS_POSIX_ACL=y 69 + CONFIG_NFS_FS=y 70 + CONFIG_NFS_V4=y 71 + CONFIG_NFS_V4_1=y 72 + CONFIG_NFS_V4_2=y 73 + CONFIG_ROOT_NFS=y 74 + # CONFIG_RCU_TRACE is not set 75 + CONFIG_CRYPTO_USER_API_HASH=y
+4 -4
arch/riscv/include/asm/csr.h
··· 17 17 #include <linux/const.h> 18 18 19 19 /* Status register flags */ 20 - #define SR_IE _AC(0x00000002, UL) /* Interrupt Enable */ 21 - #define SR_PIE _AC(0x00000020, UL) /* Previous IE */ 22 - #define SR_PS _AC(0x00000100, UL) /* Previously Supervisor */ 23 - #define SR_SUM _AC(0x00040000, UL) /* Supervisor may access User Memory */ 20 + #define SR_SIE _AC(0x00000002, UL) /* Supervisor Interrupt Enable */ 21 + #define SR_SPIE _AC(0x00000020, UL) /* Previous Supervisor IE */ 22 + #define SR_SPP _AC(0x00000100, UL) /* Previously Supervisor */ 23 + #define SR_SUM _AC(0x00040000, UL) /* Supervisor may access User Memory */ 24 24 25 25 #define SR_FS _AC(0x00006000, UL) /* Floating-point Status */ 26 26 #define SR_FS_OFF _AC(0x00000000, UL)
-4
arch/riscv/include/asm/io.h
··· 21 21 22 22 #include <linux/types.h> 23 23 24 - #ifdef CONFIG_MMU 25 - 26 24 extern void __iomem *ioremap(phys_addr_t offset, unsigned long size); 27 25 28 26 /* ··· 33 35 #define ioremap_wt(addr, size) ioremap((addr), (size)) 34 36 35 37 extern void iounmap(volatile void __iomem *addr); 36 - 37 - #endif /* CONFIG_MMU */ 38 38 39 39 /* Generic IO read/write. These perform native-endian accesses. */ 40 40 #define __raw_writeb __raw_writeb
+5 -5
arch/riscv/include/asm/irqflags.h
··· 27 27 /* unconditionally enable interrupts */ 28 28 static inline void arch_local_irq_enable(void) 29 29 { 30 - csr_set(sstatus, SR_IE); 30 + csr_set(sstatus, SR_SIE); 31 31 } 32 32 33 33 /* unconditionally disable interrupts */ 34 34 static inline void arch_local_irq_disable(void) 35 35 { 36 - csr_clear(sstatus, SR_IE); 36 + csr_clear(sstatus, SR_SIE); 37 37 } 38 38 39 39 /* get status and disable interrupts */ 40 40 static inline unsigned long arch_local_irq_save(void) 41 41 { 42 - return csr_read_clear(sstatus, SR_IE); 42 + return csr_read_clear(sstatus, SR_SIE); 43 43 } 44 44 45 45 /* test flags */ 46 46 static inline int arch_irqs_disabled_flags(unsigned long flags) 47 47 { 48 - return !(flags & SR_IE); 48 + return !(flags & SR_SIE); 49 49 } 50 50 51 51 /* test hardware interrupt enable bit */ ··· 57 57 /* set interrupt enabled status */ 58 58 static inline void arch_local_irq_restore(unsigned long flags) 59 59 { 60 - csr_set(sstatus, flags & SR_IE); 60 + csr_set(sstatus, flags & SR_SIE); 61 61 } 62 62 63 63 #endif /* _ASM_RISCV_IRQFLAGS_H */
-4
arch/riscv/include/asm/pgtable.h
··· 20 20 21 21 #ifndef __ASSEMBLY__ 22 22 23 - #ifdef CONFIG_MMU 24 - 25 23 /* Page Upper Directory not used in RISC-V */ 26 24 #include <asm-generic/pgtable-nopud.h> 27 25 #include <asm/page.h> ··· 410 412 { 411 413 /* No page table caches to initialize */ 412 414 } 413 - 414 - #endif /* CONFIG_MMU */ 415 415 416 416 #define VMALLOC_SIZE (KERN_VIRT_SIZE >> 1) 417 417 #define VMALLOC_END (PAGE_OFFSET - 1)
+1 -1
arch/riscv/include/asm/ptrace.h
··· 66 66 #define REG_FMT "%08lx" 67 67 #endif 68 68 69 - #define user_mode(regs) (((regs)->sstatus & SR_PS) == 0) 69 + #define user_mode(regs) (((regs)->sstatus & SR_SPP) == 0) 70 70 71 71 72 72 /* Helpers for working with the instruction pointer */
-4
arch/riscv/include/asm/tlbflush.h
··· 15 15 #ifndef _ASM_RISCV_TLBFLUSH_H 16 16 #define _ASM_RISCV_TLBFLUSH_H 17 17 18 - #ifdef CONFIG_MMU 19 - 20 18 #include <linux/mm_types.h> 21 19 22 20 /* ··· 61 63 { 62 64 flush_tlb_all(); 63 65 } 64 - 65 - #endif /* CONFIG_MMU */ 66 66 67 67 #endif /* _ASM_RISCV_TLBFLUSH_H */
-12
arch/riscv/include/asm/uaccess.h
··· 127 127 * call. 128 128 */ 129 129 130 - #ifdef CONFIG_MMU 131 130 #define __get_user_asm(insn, x, ptr, err) \ 132 131 do { \ 133 132 uintptr_t __tmp; \ ··· 152 153 __disable_user_access(); \ 153 154 (x) = __x; \ 154 155 } while (0) 155 - #endif /* CONFIG_MMU */ 156 156 157 157 #ifdef CONFIG_64BIT 158 158 #define __get_user_8(x, ptr, err) \ 159 159 __get_user_asm("ld", x, ptr, err) 160 160 #else /* !CONFIG_64BIT */ 161 - #ifdef CONFIG_MMU 162 161 #define __get_user_8(x, ptr, err) \ 163 162 do { \ 164 163 u32 __user *__ptr = (u32 __user *)(ptr); \ ··· 190 193 (x) = (__typeof__(x))((__typeof__((x)-(x)))( \ 191 194 (((u64)__hi << 32) | __lo))); \ 192 195 } while (0) 193 - #endif /* CONFIG_MMU */ 194 196 #endif /* CONFIG_64BIT */ 195 197 196 198 ··· 263 267 ((x) = 0, -EFAULT); \ 264 268 }) 265 269 266 - 267 - #ifdef CONFIG_MMU 268 270 #define __put_user_asm(insn, x, ptr, err) \ 269 271 do { \ 270 272 uintptr_t __tmp; \ ··· 286 292 : "rJ" (__x), "i" (-EFAULT)); \ 287 293 __disable_user_access(); \ 288 294 } while (0) 289 - #endif /* CONFIG_MMU */ 290 - 291 295 292 296 #ifdef CONFIG_64BIT 293 297 #define __put_user_8(x, ptr, err) \ 294 298 __put_user_asm("sd", x, ptr, err) 295 299 #else /* !CONFIG_64BIT */ 296 - #ifdef CONFIG_MMU 297 300 #define __put_user_8(x, ptr, err) \ 298 301 do { \ 299 302 u32 __user *__ptr = (u32 __user *)(ptr); \ ··· 320 329 : "rJ" (__x), "rJ" (__x >> 32), "i" (-EFAULT)); \ 321 330 __disable_user_access(); \ 322 331 } while (0) 323 - #endif /* CONFIG_MMU */ 324 332 #endif /* CONFIG_64BIT */ 325 333 326 334 ··· 428 438 * will set "err" to -EFAULT, while successful accesses return the previous 429 439 * value. 430 440 */ 431 - #ifdef CONFIG_MMU 432 441 #define __cmpxchg_user(ptr, old, new, err, size, lrb, scb) \ 433 442 ({ \ 434 443 __typeof__(ptr) __ptr = (ptr); \ ··· 497 508 (err) = __err; \ 498 509 __ret; \ 499 510 }) 500 - #endif /* CONFIG_MMU */ 501 511 502 512 #endif /* _ASM_RISCV_UACCESS_H */
+1
arch/riscv/include/asm/unistd.h
··· 14 14 #define __ARCH_HAVE_MMU 15 15 #define __ARCH_WANT_SYS_CLONE 16 16 #include <uapi/asm/unistd.h> 17 + #include <uapi/asm/syscalls.h>
-28
arch/riscv/include/asm/vdso-syscalls.h
··· 1 - /* 2 - * Copyright (C) 2017 SiFive 3 - * 4 - * This program is free software; you can redistribute it and/or modify 5 - * it under the terms of the GNU General Public License version 2 as 6 - * published by the Free Software Foundation. 7 - * 8 - * This program is distributed in the hope that it will be useful, 9 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 - * GNU General Public License for more details. 12 - * 13 - * You should have received a copy of the GNU General Public License 14 - * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 - */ 16 - 17 - #ifndef _ASM_RISCV_VDSO_SYSCALLS_H 18 - #define _ASM_RISCV_VDSO_SYSCALLS_H 19 - 20 - #ifdef CONFIG_SMP 21 - 22 - /* These syscalls are only used by the vDSO and are not in the uapi. */ 23 - #define __NR_riscv_flush_icache (__NR_arch_specific_syscall + 15) 24 - __SYSCALL(__NR_riscv_flush_icache, sys_riscv_flush_icache) 25 - 26 - #endif 27 - 28 - #endif /* _ASM_RISCV_VDSO_H */
+26
arch/riscv/include/uapi/asm/syscalls.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * Copyright (C) 2017 SiFive 4 + */ 5 + 6 + #ifndef _ASM__UAPI__SYSCALLS_H 7 + #define _ASM__UAPI__SYSCALLS_H 8 + 9 + /* 10 + * Allows the instruction cache to be flushed from userspace. Despite RISC-V 11 + * having a direct 'fence.i' instruction available to userspace (which we 12 + * can't trap!), that's not actually viable when running on Linux because the 13 + * kernel might schedule a process on another hart. There is no way for 14 + * userspace to handle this without invoking the kernel (as it doesn't know the 15 + * thread->hart mappings), so we've defined a RISC-V specific system call to 16 + * flush the instruction cache. 17 + * 18 + * __NR_riscv_flush_icache is defined to flush the instruction cache over an 19 + * address range, with the flush applying to either all threads or just the 20 + * caller. We don't currently do anything with the address range, that's just 21 + * in there for forwards compatibility. 22 + */ 23 + #define __NR_riscv_flush_icache (__NR_arch_specific_syscall + 15) 24 + __SYSCALL(__NR_riscv_flush_icache, sys_riscv_flush_icache) 25 + 26 + #endif
+4 -4
arch/riscv/kernel/entry.S
··· 196 196 addi s2, s2, 0x4 197 197 REG_S s2, PT_SEPC(sp) 198 198 /* System calls run with interrupts enabled */ 199 - csrs sstatus, SR_IE 199 + csrs sstatus, SR_SIE 200 200 /* Trace syscalls, but only if requested by the user. */ 201 201 REG_L t0, TASK_TI_FLAGS(tp) 202 202 andi t0, t0, _TIF_SYSCALL_TRACE ··· 224 224 225 225 ret_from_exception: 226 226 REG_L s0, PT_SSTATUS(sp) 227 - csrc sstatus, SR_IE 228 - andi s0, s0, SR_PS 227 + csrc sstatus, SR_SIE 228 + andi s0, s0, SR_SPP 229 229 bnez s0, restore_all 230 230 231 231 resume_userspace: ··· 255 255 bnez s1, work_resched 256 256 work_notifysig: 257 257 /* Handle pending signals and notify-resume requests */ 258 - csrs sstatus, SR_IE /* Enable interrupts for do_notify_resume() */ 258 + csrs sstatus, SR_SIE /* Enable interrupts for do_notify_resume() */ 259 259 move a0, sp /* pt_regs */ 260 260 move a1, s0 /* current_thread_info->flags */ 261 261 tail do_notify_resume
+2 -2
arch/riscv/kernel/process.c
··· 76 76 void start_thread(struct pt_regs *regs, unsigned long pc, 77 77 unsigned long sp) 78 78 { 79 - regs->sstatus = SR_PIE /* User mode, irqs on */ | SR_FS_INITIAL; 79 + regs->sstatus = SR_SPIE /* User mode, irqs on */ | SR_FS_INITIAL; 80 80 regs->sepc = pc; 81 81 regs->sp = sp; 82 82 set_fs(USER_DS); ··· 110 110 const register unsigned long gp __asm__ ("gp"); 111 111 memset(childregs, 0, sizeof(struct pt_regs)); 112 112 childregs->gp = gp; 113 - childregs->sstatus = SR_PS | SR_PIE; /* Supervisor, irqs on */ 113 + childregs->sstatus = SR_SPP | SR_SPIE; /* Supervisor, irqs on */ 114 114 115 115 p->thread.ra = (unsigned long)ret_from_kernel_thread; 116 116 p->thread.s[0] = usp; /* fn */
-1
arch/riscv/kernel/syscall_table.c
··· 23 23 void *sys_call_table[__NR_syscalls] = { 24 24 [0 ... __NR_syscalls - 1] = sys_ni_syscall, 25 25 #include <asm/unistd.h> 26 - #include <asm/vdso-syscalls.h> 27 26 };
-1
arch/riscv/kernel/vdso/flush_icache.S
··· 13 13 14 14 #include <linux/linkage.h> 15 15 #include <asm/unistd.h> 16 - #include <asm/vdso-syscalls.h> 17 16 18 17 .text 19 18 /* int __vdso_flush_icache(void *start, void *end, unsigned long flags); */
+1 -1
arch/riscv/mm/fault.c
··· 63 63 goto vmalloc_fault; 64 64 65 65 /* Enable interrupts if they were enabled in the parent context. */ 66 - if (likely(regs->sstatus & SR_PIE)) 66 + if (likely(regs->sstatus & SR_SPIE)) 67 67 local_irq_enable(); 68 68 69 69 /*