Merge tag 'riscv-for-linus-5.14-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux

Pull RISC-V fixes from Palmer Dabbelt:

- properly set the memory size, which fixes 32-bit systems

- allow initrd to load anywhere in memory, rather that restricting it
to the first 256MiB

- fix the 'mem=' parameter on 64-bit systems to properly account for
the maximum supported memory now that the kernel is outside the
linear map

- avoid installing mappings into the last 4KiB of memory, which
conflicts with error values

- avoid the stack from being freed while it is being walked

- a handful of fixes to the new copy to/from user routines

* tag 'riscv-for-linus-5.14-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux:
riscv: __asm_copy_to-from_user: Fix: Typos in comments
riscv: __asm_copy_to-from_user: Remove unnecessary size check
riscv: __asm_copy_to-from_user: Fix: fail on RV32
riscv: __asm_copy_to-from_user: Fix: overrun copy
riscv: stacktrace: pin the task's stack in get_wchan
riscv: Make sure the kernel mapping does not overlap with IS_ERR_VALUE
riscv: Make sure the linear mapping does not use the kernel mapping
riscv: Fix memory_limit for 64-bit kernel
RISC-V: load initrd wherever it fits into memory
riscv: Fix 32-bit RISC-V boot failure

+48 -21
+2 -2
arch/riscv/include/asm/efi.h
··· 27 27 28 28 #define ARCH_EFI_IRQ_FLAGS_MASK (SR_IE | SR_SPIE) 29 29 30 - /* Load initrd at enough distance from DRAM start */ 30 + /* Load initrd anywhere in system RAM */ 31 31 static inline unsigned long efi_get_max_initrd_addr(unsigned long image_addr) 32 32 { 33 - return image_addr + SZ_256M; 33 + return ULONG_MAX; 34 34 } 35 35 36 36 #define alloc_screen_info(x...) (&screen_info)
+5 -1
arch/riscv/kernel/stacktrace.c
··· 132 132 { 133 133 unsigned long pc = 0; 134 134 135 - if (likely(task && task != current && !task_is_running(task))) 135 + if (likely(task && task != current && !task_is_running(task))) { 136 + if (!try_get_task_stack(task)) 137 + return 0; 136 138 walk_stackframe(task, NULL, save_wchan, &pc); 139 + put_task_stack(task); 140 + } 137 141 return pc; 138 142 } 139 143
+13 -14
arch/riscv/lib/uaccess.S
··· 30 30 * t0 - end of uncopied dst 31 31 */ 32 32 add t0, a0, a2 33 - bgtu a0, t0, 5f 34 33 35 34 /* 36 35 * Use byte copy only if too small. 36 + * SZREG holds 4 for RV32 and 8 for RV64 37 37 */ 38 - li a3, 8*SZREG /* size must be larger than size in word_copy */ 38 + li a3, 9*SZREG /* size must be larger than size in word_copy */ 39 39 bltu a2, a3, .Lbyte_copy_tail 40 40 41 41 /* 42 - * Copy first bytes until dst is align to word boundary. 42 + * Copy first bytes until dst is aligned to word boundary. 43 43 * a0 - start of dst 44 44 * t1 - start of aligned dst 45 45 */ 46 46 addi t1, a0, SZREG-1 47 47 andi t1, t1, ~(SZREG-1) 48 48 /* dst is already aligned, skip */ 49 - beq a0, t1, .Lskip_first_bytes 49 + beq a0, t1, .Lskip_align_dst 50 50 1: 51 51 /* a5 - one byte for copying data */ 52 52 fixup lb a5, 0(a1), 10f ··· 55 55 addi a0, a0, 1 /* dst */ 56 56 bltu a0, t1, 1b /* t1 - start of aligned dst */ 57 57 58 - .Lskip_first_bytes: 58 + .Lskip_align_dst: 59 59 /* 60 60 * Now dst is aligned. 61 61 * Use shift-copy if src is misaligned. ··· 72 72 * 73 73 * a0 - start of aligned dst 74 74 * a1 - start of aligned src 75 - * a3 - a1 & mask:(SZREG-1) 76 75 * t0 - end of aligned dst 77 76 */ 78 - addi t0, t0, -(8*SZREG-1) /* not to over run */ 77 + addi t0, t0, -(8*SZREG) /* not to over run */ 79 78 2: 80 79 fixup REG_L a4, 0(a1), 10f 81 80 fixup REG_L a5, SZREG(a1), 10f ··· 96 97 addi a1, a1, 8*SZREG 97 98 bltu a0, t0, 2b 98 99 99 - addi t0, t0, 8*SZREG-1 /* revert to original value */ 100 + addi t0, t0, 8*SZREG /* revert to original value */ 100 101 j .Lbyte_copy_tail 101 102 102 103 .Lshift_copy: ··· 106 107 * For misaligned copy we still perform aligned word copy, but 107 108 * we need to use the value fetched from the previous iteration and 108 109 * do some shifts. 109 - * This is safe because reading less than a word size. 110 + * This is safe because reading is less than a word size. 110 111 * 111 112 * a0 - start of aligned dst 112 113 * a1 - start of src ··· 116 117 */ 117 118 /* calculating aligned word boundary for dst */ 118 119 andi t1, t0, ~(SZREG-1) 119 - /* Converting unaligned src to aligned arc */ 120 + /* Converting unaligned src to aligned src */ 120 121 andi a1, a1, ~(SZREG-1) 121 122 122 123 /* ··· 124 125 * t3 - prev shift 125 126 * t4 - current shift 126 127 */ 127 - slli t3, a3, LGREG 128 + slli t3, a3, 3 /* converting bytes in a3 to bits */ 128 129 li a5, SZREG*8 129 130 sub t4, a5, t3 130 131 131 - /* Load the first word to combine with seceond word */ 132 + /* Load the first word to combine with second word */ 132 133 fixup REG_L a5, 0(a1), 10f 133 134 134 135 3: ··· 160 161 * a1 - start of remaining src 161 162 * t0 - end of remaining dst 162 163 */ 163 - bgeu a0, t0, 5f 164 + bgeu a0, t0, .Lout_copy_user /* check if end of copy */ 164 165 4: 165 166 fixup lb a5, 0(a1), 10f 166 167 addi a1, a1, 1 /* src */ ··· 168 169 addi a0, a0, 1 /* dst */ 169 170 bltu a0, t0, 4b /* t0 - end of dst */ 170 171 171 - 5: 172 + .Lout_copy_user: 172 173 /* Disable access to user memory */ 173 174 csrc CSR_STATUS, t6 174 175 li a0, 0
+28 -4
arch/riscv/mm/init.c
··· 127 127 } 128 128 129 129 /* 130 - * The default maximal physical memory size is -PAGE_OFFSET, 131 - * limit the memory size via mem. 130 + * The default maximal physical memory size is -PAGE_OFFSET for 32-bit kernel, 131 + * whereas for 64-bit kernel, the end of the virtual address space is occupied 132 + * by the modules/BPF/kernel mappings which reduces the available size of the 133 + * linear mapping. 134 + * Limit the memory size via mem. 132 135 */ 136 + #ifdef CONFIG_64BIT 137 + static phys_addr_t memory_limit = -PAGE_OFFSET - SZ_4G; 138 + #else 133 139 static phys_addr_t memory_limit = -PAGE_OFFSET; 140 + #endif 134 141 135 142 static int __init early_mem(char *p) 136 143 { ··· 159 152 { 160 153 phys_addr_t vmlinux_end = __pa_symbol(&_end); 161 154 phys_addr_t vmlinux_start = __pa_symbol(&_start); 162 - phys_addr_t max_mapped_addr = __pa(~(ulong)0); 155 + phys_addr_t __maybe_unused max_mapped_addr; 163 156 phys_addr_t dram_end; 164 157 165 158 #ifdef CONFIG_XIP_KERNEL ··· 182 175 memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start); 183 176 184 177 dram_end = memblock_end_of_DRAM(); 178 + 179 + #ifndef CONFIG_64BIT 185 180 /* 186 181 * memblock allocator is not aware of the fact that last 4K bytes of 187 182 * the addressable memory can not be mapped because of IS_ERR_VALUE 188 183 * macro. Make sure that last 4k bytes are not usable by memblock 189 - * if end of dram is equal to maximum addressable memory. 184 + * if end of dram is equal to maximum addressable memory. For 64-bit 185 + * kernel, this problem can't happen here as the end of the virtual 186 + * address space is occupied by the kernel mapping then this check must 187 + * be done in create_kernel_page_table. 190 188 */ 189 + max_mapped_addr = __pa(~(ulong)0); 191 190 if (max_mapped_addr == (dram_end - 1)) 192 191 memblock_set_current_limit(max_mapped_addr - 4096); 192 + #endif 193 193 194 194 min_low_pfn = PFN_UP(memblock_start_of_DRAM()); 195 195 max_low_pfn = max_pfn = PFN_DOWN(dram_end); ··· 584 570 BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0); 585 571 BUG_ON((kernel_map.phys_addr % map_size) != 0); 586 572 573 + #ifdef CONFIG_64BIT 574 + /* 575 + * The last 4K bytes of the addressable memory can not be mapped because 576 + * of IS_ERR_VALUE macro. 577 + */ 578 + BUG_ON((kernel_map.virt_addr + kernel_map.size) > ADDRESS_SPACE_END - SZ_4K); 579 + #endif 580 + 587 581 pt_ops.alloc_pte = alloc_pte_early; 588 582 pt_ops.get_pte_virt = get_pte_virt_early; 589 583 #ifndef __PAGETABLE_PMD_FOLDED ··· 731 709 if (start <= __pa(PAGE_OFFSET) && 732 710 __pa(PAGE_OFFSET) < end) 733 711 start = __pa(PAGE_OFFSET); 712 + if (end >= __pa(PAGE_OFFSET) + memory_limit) 713 + end = __pa(PAGE_OFFSET) + memory_limit; 734 714 735 715 map_size = best_map_size(start, end - start); 736 716 for (pa = start; pa < end; pa += map_size) {