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

Pull RISC-V updates from Paul Walmsley:
"Nothing exotic here; these are the cleanup and new ISA extension
probing patches (not including CFI):

- Add probing and userspace reporting support for the standard RISC-V
ISA extensions Zilsd and Zclsd, which implement load/store dual
instructions on RV32

- Abstract the register saving code in setup_sigcontext() so it can
be used for stateful RISC-V ISA extensions beyond the vector
extension

- Add the SBI extension ID and some initial data structure
definitions for the RISC-V standard SBI debug trigger extension

- Clean up some code slightly: change some page table functions to
avoid atomic operations oinn !SMP and to avoid unnecessary casts to
atomic_long_t; and use the existing RISCV_FULL_BARRIER macro in
place of some open-coded 'fence rw,rw' instructions"

* tag 'riscv-for-linus-6.19-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux:
riscv: Add SBI debug trigger extension and function ids
riscv/atomic.h: use RISCV_FULL_BARRIER in _arch_atomic* function.
riscv: hwprobe: export Zilsd and Zclsd ISA extensions
riscv: add ISA extension parsing for Zilsd and Zclsd
dt-bindings: riscv: add Zilsd and Zclsd extension descriptions
riscv: mm: use xchg() on non-atomic_long_t variables, not atomic_long_xchg()
riscv: mm: ptep_get_and_clear(): avoid atomic ops when !CONFIG_SMP
riscv: mm: pmdp_huge_get_and_clear(): avoid atomic ops when !CONFIG_SMP
riscv: signal: abstract header saving for setup_sigcontext

Changed files
+166 -27
Documentation
arch
riscv
devicetree
bindings
arch
+8
Documentation/arch/riscv/hwprobe.rst
··· 281 281 * :c:macro:`RISCV_HWPROBE_EXT_ZICBOP`: The Zicbop extension is supported, as 282 282 ratified in commit 3dd606f ("Create cmobase-v1.0.pdf") of riscv-CMOs. 283 283 284 + * :c:macro:`RISCV_HWPROBE_EXT_ZILSD`: The Zilsd extension is supported as 285 + defined in the RISC-V ISA manual starting from commit f88abf1 ("Integrating 286 + load/store pair for RV32 with the main manual") of the riscv-isa-manual. 287 + 288 + * :c:macro:`RISCV_HWPROBE_EXT_ZCLSD`: The Zclsd extension is supported as 289 + defined in the RISC-V ISA manual starting from commit f88abf1 ("Integrating 290 + load/store pair for RV32 with the main manual") of the riscv-isa-manual. 291 + 284 292 * :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: Deprecated. Returns similar values to 285 293 :c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF`, but the key was 286 294 mistakenly classified as a bitmask rather than a value.
+36
Documentation/devicetree/bindings/riscv/extensions.yaml
··· 377 377 guarantee on LR/SC sequences, as ratified in commit b1d806605f87 378 378 ("Updated to ratified state.") of the riscv profiles specification. 379 379 380 + - const: zilsd 381 + description: 382 + The standard Zilsd extension which provides support for aligned 383 + register-pair load and store operations in 32-bit instruction 384 + encodings, as ratified in commit f88abf1 ("Integrating 385 + load/store pair for RV32 with the main manual") of riscv-isa-manual. 386 + 387 + - const: zclsd 388 + description: 389 + The Zclsd extension implements the compressed (16-bit) version of the 390 + Load/Store Pair for RV32. As with Zilsd, this extension was ratified 391 + in commit f88abf1 ("Integrating load/store pair for RV32 with the 392 + main manual") of riscv-isa-manual. 393 + 380 394 - const: zk 381 395 description: 382 396 The standard Zk Standard Scalar cryptography extension as ratified ··· 896 882 anyOf: 897 883 - const: v 898 884 - const: zve32x 885 + # Zclsd depends on Zilsd and Zca 886 + - if: 887 + contains: 888 + anyOf: 889 + - const: zclsd 890 + then: 891 + contains: 892 + allOf: 893 + - const: zilsd 894 + - const: zca 899 895 900 896 allOf: 901 897 # Zcf extension does not exist on rv64 ··· 923 899 not: 924 900 contains: 925 901 const: zcf 902 + # Zilsd extension does not exist on rv64 903 + - if: 904 + properties: 905 + riscv,isa-base: 906 + contains: 907 + const: rv64i 908 + then: 909 + properties: 910 + riscv,isa-extensions: 911 + not: 912 + contains: 913 + const: zilsd 926 914 927 915 additionalProperties: true 928 916 ...
+4 -4
arch/riscv/include/asm/atomic.h
··· 203 203 " add %[rc], %[p], %[a]\n" \ 204 204 " sc." sfx ".rl %[rc], %[rc], %[c]\n" \ 205 205 " bnez %[rc], 0b\n" \ 206 - " fence rw, rw\n" \ 206 + RISCV_FULL_BARRIER \ 207 207 "1:\n" \ 208 208 : [p]"=&r" (_prev), [rc]"=&r" (_rc), [c]"+A" (counter) \ 209 209 : [a]"r" (_a), [u]"r" (_u) \ ··· 242 242 " addi %[rc], %[p], 1\n" \ 243 243 " sc." sfx ".rl %[rc], %[rc], %[c]\n" \ 244 244 " bnez %[rc], 0b\n" \ 245 - " fence rw, rw\n" \ 245 + RISCV_FULL_BARRIER \ 246 246 "1:\n" \ 247 247 : [p]"=&r" (_prev), [rc]"=&r" (_rc), [c]"+A" (counter) \ 248 248 : \ ··· 268 268 " addi %[rc], %[p], -1\n" \ 269 269 " sc." sfx ".rl %[rc], %[rc], %[c]\n" \ 270 270 " bnez %[rc], 0b\n" \ 271 - " fence rw, rw\n" \ 271 + RISCV_FULL_BARRIER \ 272 272 "1:\n" \ 273 273 : [p]"=&r" (_prev), [rc]"=&r" (_rc), [c]"+A" (counter) \ 274 274 : \ ··· 294 294 " bltz %[rc], 1f\n" \ 295 295 " sc." sfx ".rl %[rc], %[rc], %[c]\n" \ 296 296 " bnez %[rc], 0b\n" \ 297 - " fence rw, rw\n" \ 297 + RISCV_FULL_BARRIER \ 298 298 "1:\n" \ 299 299 : [p]"=&r" (_prev), [rc]"=&r" (_rc), [c]"+A" (counter) \ 300 300 : \
+2
arch/riscv/include/asm/hwcap.h
··· 108 108 #define RISCV_ISA_EXT_ZICBOP 99 109 109 #define RISCV_ISA_EXT_SVRSW60T59B 100 110 110 #define RISCV_ISA_EXT_ZALASR 101 111 + #define RISCV_ISA_EXT_ZILSD 102 112 + #define RISCV_ISA_EXT_ZCLSD 103 111 113 112 114 #define RISCV_ISA_EXT_XLINUXENVCFG 127 113 115
+14 -2
arch/riscv/include/asm/pgtable.h
··· 660 660 static inline pte_t ptep_get_and_clear(struct mm_struct *mm, 661 661 unsigned long address, pte_t *ptep) 662 662 { 663 - pte_t pte = __pte(atomic_long_xchg((atomic_long_t *)ptep, 0)); 663 + #ifdef CONFIG_SMP 664 + pte_t pte = __pte(xchg(&ptep->pte, 0)); 665 + #else 666 + pte_t pte = *ptep; 667 + 668 + set_pte(ptep, __pte(0)); 669 + #endif 664 670 665 671 page_table_check_pte_clear(mm, pte); 666 672 ··· 1003 997 static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm, 1004 998 unsigned long address, pmd_t *pmdp) 1005 999 { 1006 - pmd_t pmd = __pmd(atomic_long_xchg((atomic_long_t *)pmdp, 0)); 1000 + #ifdef CONFIG_SMP 1001 + pmd_t pmd = __pmd(xchg(&pmdp->pmd, 0)); 1002 + #else 1003 + pmd_t pmd = *pmdp; 1004 + 1005 + pmd_clear(pmdp); 1006 + #endif 1007 1007 1008 1008 page_table_check_pmd_clear(mm, pmd); 1009 1009
+29
arch/riscv/include/asm/sbi.h
··· 37 37 SBI_EXT_NACL = 0x4E41434C, 38 38 SBI_EXT_FWFT = 0x46574654, 39 39 SBI_EXT_MPXY = 0x4D505859, 40 + SBI_EXT_DBTR = 0x44425452, 40 41 41 42 /* Experimentals extensions must lie within this range */ 42 43 SBI_EXT_EXPERIMENTAL_START = 0x08000000, ··· 505 504 #define SBI_MPXY_CHAN_CAP_SEND_WITH_RESP BIT(3) 506 505 #define SBI_MPXY_CHAN_CAP_SEND_WITHOUT_RESP BIT(4) 507 506 #define SBI_MPXY_CHAN_CAP_GET_NOTIFICATIONS BIT(5) 507 + 508 + /* SBI debug triggers function IDs */ 509 + enum sbi_ext_dbtr_fid { 510 + SBI_EXT_DBTR_NUM_TRIGGERS = 0, 511 + SBI_EXT_DBTR_SETUP_SHMEM, 512 + SBI_EXT_DBTR_TRIG_READ, 513 + SBI_EXT_DBTR_TRIG_INSTALL, 514 + SBI_EXT_DBTR_TRIG_UPDATE, 515 + SBI_EXT_DBTR_TRIG_UNINSTALL, 516 + SBI_EXT_DBTR_TRIG_ENABLE, 517 + SBI_EXT_DBTR_TRIG_DISABLE, 518 + }; 519 + 520 + struct sbi_dbtr_data_msg { 521 + unsigned long tstate; 522 + unsigned long tdata1; 523 + unsigned long tdata2; 524 + unsigned long tdata3; 525 + }; 526 + 527 + struct sbi_dbtr_id_msg { 528 + unsigned long idx; 529 + }; 530 + 531 + union sbi_dbtr_shmem_entry { 532 + struct sbi_dbtr_data_msg data; 533 + struct sbi_dbtr_id_msg id; 534 + }; 508 535 509 536 /* SBI spec version fields */ 510 537 #define SBI_SPEC_VERSION_DEFAULT 0x1
+3
arch/riscv/include/asm/vector.h
··· 424 424 #define riscv_v_thread_free(tsk) do {} while (0) 425 425 #define riscv_v_setup_ctx_cache() do {} while (0) 426 426 #define riscv_v_thread_alloc(tsk) do {} while (0) 427 + #define get_cpu_vector_context() do {} while (0) 428 + #define put_cpu_vector_context() do {} while (0) 429 + #define riscv_v_vstate_set_restore(task, regs) do {} while (0) 427 430 428 431 #endif /* CONFIG_RISCV_ISA_V */ 429 432
+3
arch/riscv/include/uapi/asm/hwprobe.h
··· 84 84 #define RISCV_HWPROBE_EXT_ZABHA (1ULL << 58) 85 85 #define RISCV_HWPROBE_EXT_ZALASR (1ULL << 59) 86 86 #define RISCV_HWPROBE_EXT_ZICBOP (1ULL << 60) 87 + #define RISCV_HWPROBE_EXT_ZILSD (1ULL << 61) 88 + #define RISCV_HWPROBE_EXT_ZCLSD (1ULL << 62) 89 + 87 90 #define RISCV_HWPROBE_KEY_CPUPERF_0 5 88 91 #define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0) 89 92 #define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0)
+24
arch/riscv/kernel/cpufeature.c
··· 242 242 return -EPROBE_DEFER; 243 243 } 244 244 245 + static int riscv_ext_zilsd_validate(const struct riscv_isa_ext_data *data, 246 + const unsigned long *isa_bitmap) 247 + { 248 + if (IS_ENABLED(CONFIG_64BIT)) 249 + return -EINVAL; 250 + 251 + return 0; 252 + } 253 + 254 + static int riscv_ext_zclsd_validate(const struct riscv_isa_ext_data *data, 255 + const unsigned long *isa_bitmap) 256 + { 257 + if (IS_ENABLED(CONFIG_64BIT)) 258 + return -EINVAL; 259 + 260 + if (__riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_ZILSD) && 261 + __riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_ZCA)) 262 + return 0; 263 + 264 + return -EPROBE_DEFER; 265 + } 266 + 245 267 static int riscv_vector_f_validate(const struct riscv_isa_ext_data *data, 246 268 const unsigned long *isa_bitmap) 247 269 { ··· 506 484 __RISCV_ISA_EXT_DATA_VALIDATE(zcd, RISCV_ISA_EXT_ZCD, riscv_ext_zcd_validate), 507 485 __RISCV_ISA_EXT_DATA_VALIDATE(zcf, RISCV_ISA_EXT_ZCF, riscv_ext_zcf_validate), 508 486 __RISCV_ISA_EXT_DATA_VALIDATE(zcmop, RISCV_ISA_EXT_ZCMOP, riscv_ext_zca_depends), 487 + __RISCV_ISA_EXT_DATA_VALIDATE(zclsd, RISCV_ISA_EXT_ZCLSD, riscv_ext_zclsd_validate), 488 + __RISCV_ISA_EXT_DATA_VALIDATE(zilsd, RISCV_ISA_EXT_ZILSD, riscv_ext_zilsd_validate), 509 489 __RISCV_ISA_EXT_DATA(zba, RISCV_ISA_EXT_ZBA), 510 490 __RISCV_ISA_EXT_DATA(zbb, RISCV_ISA_EXT_ZBB), 511 491 __RISCV_ISA_EXT_DATA(zbc, RISCV_ISA_EXT_ZBC),
+41 -21
arch/riscv/kernel/signal.c
··· 68 68 #define restore_fp_state(task, regs) (0) 69 69 #endif 70 70 71 - #ifdef CONFIG_RISCV_ISA_V 72 - 73 - static long save_v_state(struct pt_regs *regs, void __user **sc_vec) 71 + static long save_v_state(struct pt_regs *regs, void __user *sc_vec) 74 72 { 75 - struct __riscv_ctx_hdr __user *hdr; 76 73 struct __sc_riscv_v_state __user *state; 77 74 void __user *datap; 78 75 long err; 79 76 80 - hdr = *sc_vec; 81 - /* Place state to the user's signal context space after the hdr */ 82 - state = (struct __sc_riscv_v_state __user *)(hdr + 1); 77 + if (!IS_ENABLED(CONFIG_RISCV_ISA_V) || 78 + !((has_vector() || has_xtheadvector()) && 79 + riscv_v_vstate_query(regs))) 80 + return 0; 81 + 82 + /* Place state to the user's signal context space */ 83 + state = (struct __sc_riscv_v_state __user *)sc_vec; 83 84 /* Point datap right after the end of __sc_riscv_v_state */ 84 85 datap = state + 1; 85 86 ··· 98 97 err |= __put_user((__force void *)datap, &state->v_state.datap); 99 98 /* Copy the whole vector content to user space datap. */ 100 99 err |= __copy_to_user(datap, current->thread.vstate.datap, riscv_v_vsize); 101 - /* Copy magic to the user space after saving all vector conetext */ 102 - err |= __put_user(RISCV_V_MAGIC, &hdr->magic); 103 - err |= __put_user(riscv_v_sc_size, &hdr->size); 104 100 if (unlikely(err)) 105 - return err; 101 + return -EFAULT; 106 102 107 - /* Only progress the sv_vec if everything has done successfully */ 108 - *sc_vec += riscv_v_sc_size; 109 - return 0; 103 + /* Only return the size if everything has done successfully */ 104 + return riscv_v_sc_size; 110 105 } 111 106 112 107 /* ··· 139 142 */ 140 143 return copy_from_user(current->thread.vstate.datap, datap, riscv_v_vsize); 141 144 } 142 - #else 143 - #define save_v_state(task, regs) (0) 144 - #define __restore_v_state(task, regs) (0) 145 - #endif 145 + 146 + struct arch_ext_priv { 147 + __u32 magic; 148 + long (*save)(struct pt_regs *regs, void __user *sc_vec); 149 + }; 150 + 151 + struct arch_ext_priv arch_ext_list[] = { 152 + { 153 + .magic = RISCV_V_MAGIC, 154 + .save = &save_v_state, 155 + }, 156 + }; 157 + 158 + const size_t nr_arch_exts = ARRAY_SIZE(arch_ext_list); 146 159 147 160 static long restore_sigcontext(struct pt_regs *regs, 148 161 struct sigcontext __user *sc) ··· 277 270 { 278 271 struct sigcontext __user *sc = &frame->uc.uc_mcontext; 279 272 struct __riscv_ctx_hdr __user *sc_ext_ptr = &sc->sc_extdesc.hdr; 280 - long err; 273 + struct arch_ext_priv *arch_ext; 274 + long err, i, ext_size; 281 275 282 276 /* sc_regs is structured the same as the start of pt_regs */ 283 277 err = __copy_to_user(&sc->sc_regs, regs, sizeof(sc->sc_regs)); ··· 286 278 if (has_fpu()) 287 279 err |= save_fp_state(regs, &sc->sc_fpregs); 288 280 /* Save the vector state. */ 289 - if ((has_vector() || has_xtheadvector()) && riscv_v_vstate_query(regs)) 290 - err |= save_v_state(regs, (void __user **)&sc_ext_ptr); 281 + for (i = 0; i < nr_arch_exts; i++) { 282 + arch_ext = &arch_ext_list[i]; 283 + if (!arch_ext->save) 284 + continue; 285 + 286 + ext_size = arch_ext->save(regs, sc_ext_ptr + 1); 287 + if (ext_size <= 0) { 288 + err |= ext_size; 289 + } else { 290 + err |= __put_user(arch_ext->magic, &sc_ext_ptr->magic); 291 + err |= __put_user(ext_size, &sc_ext_ptr->size); 292 + sc_ext_ptr = (void *)sc_ext_ptr + ext_size; 293 + } 294 + } 291 295 /* Write zero to fp-reserved space and check it on restore_sigcontext */ 292 296 err |= __put_user(0, &sc->sc_extdesc.reserved); 293 297 /* And put END __riscv_ctx_hdr at the end. */
+2
arch/riscv/kernel/sys_hwprobe.c
··· 121 121 EXT_KEY(ZBS); 122 122 EXT_KEY(ZCA); 123 123 EXT_KEY(ZCB); 124 + EXT_KEY(ZCLSD); 124 125 EXT_KEY(ZCMOP); 125 126 EXT_KEY(ZICBOM); 126 127 EXT_KEY(ZICBOP); ··· 131 130 EXT_KEY(ZIHINTNTL); 132 131 EXT_KEY(ZIHINTPAUSE); 133 132 EXT_KEY(ZIHPM); 133 + EXT_KEY(ZILSD); 134 134 EXT_KEY(ZIMOP); 135 135 EXT_KEY(ZKND); 136 136 EXT_KEY(ZKNE);