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

Pull RISC-V fixes from Palmer Dabbelt:

- A fix for TASK_SIZE on rv64/NOMMU, to reflect the lack of user/kernel
separation

- A fix to avoid loading rv64/NOMMU kernel past the start of RAM

- A fix for RISCV_HWPROBE_EXT_ZVFHMIN on ilp32 to avoid signed integer
overflow in the bitmask

- The sud_test kselftest has been fixed to properly swizzle the syscall
number into the return register, which are not the same on RISC-V

- A fix for a build warning in the perf tools on rv32

- A fix for the CBO selftests, to avoid non-constants leaking into the
inline asm

- A pair of fixes for T-Head PBMT errata probing, which has been
renamed MAE by the vendor

* tag 'riscv-for-linus-6.9-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux:
RISC-V: selftests: cbo: Ensure asm operands match constraints, take 2
perf riscv: Fix the warning due to the incompatible type
riscv: T-Head: Test availability bit before enabling MAE errata
riscv: thead: Rename T-Head PBMT to MAE
selftests: sud_test: return correct emulated syscall value on RISC-V
riscv: hwprobe: fix invalid sign extension for RISCV_HWPROBE_EXT_ZVFHMIN
riscv: Fix loading 64-bit NOMMU kernels past the start of RAM
riscv: Fix TASK_SIZE on 64-bit NOMMU

Changed files
+59 -29
arch
riscv
errata
thead
include
mm
tools
perf
arch
riscv
util
testing
selftests
riscv
hwprobe
syscall_user_dispatch
+4 -4
arch/riscv/Kconfig.errata
··· 82 82 83 83 Otherwise, please say "N" here to avoid unnecessary overhead. 84 84 85 - config ERRATA_THEAD_PBMT 86 - bool "Apply T-Head memory type errata" 85 + config ERRATA_THEAD_MAE 86 + bool "Apply T-Head's memory attribute extension (XTheadMae) errata" 87 87 depends on ERRATA_THEAD && 64BIT && MMU 88 88 select RISCV_ALTERNATIVE_EARLY 89 89 default y 90 90 help 91 - This will apply the memory type errata to handle the non-standard 92 - memory type bits in page-table-entries on T-Head SoCs. 91 + This will apply the memory attribute extension errata to handle the 92 + non-standard PTE utilization on T-Head SoCs (XTheadMae). 93 93 94 94 If you don't know what to do here, say "Y". 95 95
+15 -9
arch/riscv/errata/thead/errata.c
··· 19 19 #include <asm/patch.h> 20 20 #include <asm/vendorid_list.h> 21 21 22 - static bool errata_probe_pbmt(unsigned int stage, 23 - unsigned long arch_id, unsigned long impid) 22 + #define CSR_TH_SXSTATUS 0x5c0 23 + #define SXSTATUS_MAEE _AC(0x200000, UL) 24 + 25 + static bool errata_probe_mae(unsigned int stage, 26 + unsigned long arch_id, unsigned long impid) 24 27 { 25 - if (!IS_ENABLED(CONFIG_ERRATA_THEAD_PBMT)) 28 + if (!IS_ENABLED(CONFIG_ERRATA_THEAD_MAE)) 26 29 return false; 27 30 28 31 if (arch_id != 0 || impid != 0) 29 32 return false; 30 33 31 - if (stage == RISCV_ALTERNATIVES_EARLY_BOOT || 32 - stage == RISCV_ALTERNATIVES_MODULE) 33 - return true; 34 + if (stage != RISCV_ALTERNATIVES_EARLY_BOOT && 35 + stage != RISCV_ALTERNATIVES_MODULE) 36 + return false; 34 37 35 - return false; 38 + if (!(csr_read(CSR_TH_SXSTATUS) & SXSTATUS_MAEE)) 39 + return false; 40 + 41 + return true; 36 42 } 37 43 38 44 /* ··· 146 140 { 147 141 u32 cpu_req_errata = 0; 148 142 149 - if (errata_probe_pbmt(stage, archid, impid)) 150 - cpu_req_errata |= BIT(ERRATA_THEAD_PBMT); 143 + if (errata_probe_mae(stage, archid, impid)) 144 + cpu_req_errata |= BIT(ERRATA_THEAD_MAE); 151 145 152 146 errata_probe_cmo(stage, archid, impid); 153 147
+10 -10
arch/riscv/include/asm/errata_list.h
··· 23 23 #endif 24 24 25 25 #ifdef CONFIG_ERRATA_THEAD 26 - #define ERRATA_THEAD_PBMT 0 26 + #define ERRATA_THEAD_MAE 0 27 27 #define ERRATA_THEAD_PMU 1 28 28 #define ERRATA_THEAD_NUMBER 2 29 29 #endif ··· 53 53 * in the default case. 54 54 */ 55 55 #define ALT_SVPBMT_SHIFT 61 56 - #define ALT_THEAD_PBMT_SHIFT 59 56 + #define ALT_THEAD_MAE_SHIFT 59 57 57 #define ALT_SVPBMT(_val, prot) \ 58 58 asm(ALTERNATIVE_2("li %0, 0\t\nnop", \ 59 59 "li %0, %1\t\nslli %0,%0,%3", 0, \ 60 60 RISCV_ISA_EXT_SVPBMT, CONFIG_RISCV_ISA_SVPBMT, \ 61 61 "li %0, %2\t\nslli %0,%0,%4", THEAD_VENDOR_ID, \ 62 - ERRATA_THEAD_PBMT, CONFIG_ERRATA_THEAD_PBMT) \ 62 + ERRATA_THEAD_MAE, CONFIG_ERRATA_THEAD_MAE) \ 63 63 : "=r"(_val) \ 64 64 : "I"(prot##_SVPBMT >> ALT_SVPBMT_SHIFT), \ 65 - "I"(prot##_THEAD >> ALT_THEAD_PBMT_SHIFT), \ 65 + "I"(prot##_THEAD >> ALT_THEAD_MAE_SHIFT), \ 66 66 "I"(ALT_SVPBMT_SHIFT), \ 67 - "I"(ALT_THEAD_PBMT_SHIFT)) 67 + "I"(ALT_THEAD_MAE_SHIFT)) 68 68 69 - #ifdef CONFIG_ERRATA_THEAD_PBMT 69 + #ifdef CONFIG_ERRATA_THEAD_MAE 70 70 /* 71 71 * IO/NOCACHE memory types are handled together with svpbmt, 72 72 * so on T-Head chips, check if no other memory type is set, ··· 83 83 "slli t3, t3, %3\n\t" \ 84 84 "or %0, %0, t3\n\t" \ 85 85 "2:", THEAD_VENDOR_ID, \ 86 - ERRATA_THEAD_PBMT, CONFIG_ERRATA_THEAD_PBMT) \ 86 + ERRATA_THEAD_MAE, CONFIG_ERRATA_THEAD_MAE) \ 87 87 : "+r"(_val) \ 88 - : "I"(_PAGE_MTMASK_THEAD >> ALT_THEAD_PBMT_SHIFT), \ 89 - "I"(_PAGE_PMA_THEAD >> ALT_THEAD_PBMT_SHIFT), \ 90 - "I"(ALT_THEAD_PBMT_SHIFT) \ 88 + : "I"(_PAGE_MTMASK_THEAD >> ALT_THEAD_MAE_SHIFT), \ 89 + "I"(_PAGE_PMA_THEAD >> ALT_THEAD_MAE_SHIFT), \ 90 + "I"(ALT_THEAD_MAE_SHIFT) \ 91 91 : "t3") 92 92 #else 93 93 #define ALT_THEAD_PMA(_val)
+1 -1
arch/riscv/include/asm/page.h
··· 89 89 #define PTE_FMT "%08lx" 90 90 #endif 91 91 92 - #ifdef CONFIG_64BIT 92 + #if defined(CONFIG_64BIT) && defined(CONFIG_MMU) 93 93 /* 94 94 * We override this value as its generic definition uses __pa too early in 95 95 * the boot process (before kernel_map.va_pa_offset is set).
+1 -1
arch/riscv/include/asm/pgtable.h
··· 896 896 #define PAGE_SHARED __pgprot(0) 897 897 #define PAGE_KERNEL __pgprot(0) 898 898 #define swapper_pg_dir NULL 899 - #define TASK_SIZE 0xffffffffUL 899 + #define TASK_SIZE _AC(-1, UL) 900 900 #define VMALLOC_START _AC(0, UL) 901 901 #define VMALLOC_END TASK_SIZE 902 902
+1 -1
arch/riscv/include/uapi/asm/hwprobe.h
··· 54 54 #define RISCV_HWPROBE_EXT_ZFHMIN (1 << 28) 55 55 #define RISCV_HWPROBE_EXT_ZIHINTNTL (1 << 29) 56 56 #define RISCV_HWPROBE_EXT_ZVFH (1 << 30) 57 - #define RISCV_HWPROBE_EXT_ZVFHMIN (1 << 31) 57 + #define RISCV_HWPROBE_EXT_ZVFHMIN (1ULL << 31) 58 58 #define RISCV_HWPROBE_EXT_ZFA (1ULL << 32) 59 59 #define RISCV_HWPROBE_EXT_ZTSO (1ULL << 33) 60 60 #define RISCV_HWPROBE_EXT_ZACAS (1ULL << 34)
+1 -1
arch/riscv/mm/init.c
··· 231 231 * In 64-bit, any use of __va/__pa before this point is wrong as we 232 232 * did not know the start of DRAM before. 233 233 */ 234 - if (IS_ENABLED(CONFIG_64BIT)) 234 + if (IS_ENABLED(CONFIG_64BIT) && IS_ENABLED(CONFIG_MMU)) 235 235 kernel_map.va_pa_offset = PAGE_OFFSET - phys_ram_base; 236 236 237 237 /*
+1 -1
tools/perf/arch/riscv/util/header.c
··· 41 41 char *mimpid = NULL; 42 42 char *cpuid = NULL; 43 43 int read; 44 - unsigned long line_sz; 44 + size_t line_sz; 45 45 FILE *cpuinfo; 46 46 47 47 cpuinfo = fopen(CPUINFO, "r");
+1 -1
tools/testing/selftests/riscv/hwprobe/cbo.c
··· 19 19 #include "hwprobe.h" 20 20 #include "../../kselftest.h" 21 21 22 - #define MK_CBO(fn) cpu_to_le32((fn) << 20 | 10 << 15 | 2 << 12 | 0 << 7 | 15) 22 + #define MK_CBO(fn) le32_bswap((uint32_t)(fn) << 20 | 10 << 15 | 2 << 12 | 0 << 7 | 15) 23 23 24 24 static char mem[4096] __aligned(4096) = { [0 ... 4095] = 0xa5 }; 25 25
+10
tools/testing/selftests/riscv/hwprobe/hwprobe.h
··· 4 4 #include <stddef.h> 5 5 #include <asm/hwprobe.h> 6 6 7 + #if __BYTE_ORDER == __BIG_ENDIAN 8 + # define le32_bswap(_x) \ 9 + ((((_x) & 0x000000ffU) << 24) | \ 10 + (((_x) & 0x0000ff00U) << 8) | \ 11 + (((_x) & 0x00ff0000U) >> 8) | \ 12 + (((_x) & 0xff000000U) >> 24)) 13 + #else 14 + # define le32_bswap(_x) (_x) 15 + #endif 16 + 7 17 /* 8 18 * Rather than relying on having a new enough libc to define this, just do it 9 19 * ourselves. This way we don't need to be coupled to a new-enough libc to
+14
tools/testing/selftests/syscall_user_dispatch/sud_test.c
··· 158 158 159 159 /* In preparation for sigreturn. */ 160 160 SYSCALL_DISPATCH_OFF(glob_sel); 161 + 162 + /* 163 + * The tests for argument handling assume that `syscall(x) == x`. This 164 + * is a NOP on x86 because the syscall number is passed in %rax, which 165 + * happens to also be the function ABI return register. Other 166 + * architectures may need to swizzle the arguments around. 167 + */ 168 + #if defined(__riscv) 169 + /* REG_A7 is not defined in libc headers */ 170 + # define REG_A7 (REG_A0 + 7) 171 + 172 + ((ucontext_t *)ucontext)->uc_mcontext.__gregs[REG_A0] = 173 + ((ucontext_t *)ucontext)->uc_mcontext.__gregs[REG_A7]; 174 + #endif 161 175 } 162 176 163 177 TEST(dispatch_and_return)