Skip to content

Commit 03de3e4

Browse files
committed
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
2 parents cd80aff + 5efaf92 commit 03de3e4

11 files changed

Lines changed: 166 additions & 27 deletions

File tree

Documentation/arch/riscv/hwprobe.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,14 @@ The following keys are defined:
281281
* :c:macro:`RISCV_HWPROBE_EXT_ZICBOP`: The Zicbop extension is supported, as
282282
ratified in commit 3dd606f ("Create cmobase-v1.0.pdf") of riscv-CMOs.
283283

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+
284292
* :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: Deprecated. Returns similar values to
285293
:c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF`, but the key was
286294
mistakenly classified as a bitmask rather than a value.

Documentation/devicetree/bindings/riscv/extensions.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,20 @@ properties:
377377
guarantee on LR/SC sequences, as ratified in commit b1d806605f87
378378
("Updated to ratified state.") of the riscv profiles specification.
379379

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+
380394
- const: zk
381395
description:
382396
The standard Zk Standard Scalar cryptography extension as ratified
@@ -882,6 +896,16 @@ properties:
882896
anyOf:
883897
- const: v
884898
- const: zve32x
899+
# Zclsd depends on Zilsd and Zca
900+
- if:
901+
contains:
902+
anyOf:
903+
- const: zclsd
904+
then:
905+
contains:
906+
allOf:
907+
- const: zilsd
908+
- const: zca
885909

886910
allOf:
887911
# Zcf extension does not exist on rv64
@@ -899,6 +923,18 @@ allOf:
899923
not:
900924
contains:
901925
const: zcf
926+
# Zilsd extension does not exist on rv64
927+
- if:
928+
properties:
929+
riscv,isa-base:
930+
contains:
931+
const: rv64i
932+
then:
933+
properties:
934+
riscv,isa-extensions:
935+
not:
936+
contains:
937+
const: zilsd
902938

903939
additionalProperties: true
904940
...

arch/riscv/include/asm/atomic.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ ATOMIC_OPS(xor, xor, i)
203203
" add %[rc], %[p], %[a]\n" \
204204
" sc." sfx ".rl %[rc], %[rc], %[c]\n" \
205205
" bnez %[rc], 0b\n" \
206-
" fence rw, rw\n" \
206+
RISCV_FULL_BARRIER \
207207
"1:\n" \
208208
: [p]"=&r" (_prev), [rc]"=&r" (_rc), [c]"+A" (counter) \
209209
: [a]"r" (_a), [u]"r" (_u) \
@@ -242,7 +242,7 @@ static __always_inline s64 arch_atomic64_fetch_add_unless(atomic64_t *v, s64 a,
242242
" addi %[rc], %[p], 1\n" \
243243
" sc." sfx ".rl %[rc], %[rc], %[c]\n" \
244244
" bnez %[rc], 0b\n" \
245-
" fence rw, rw\n" \
245+
RISCV_FULL_BARRIER \
246246
"1:\n" \
247247
: [p]"=&r" (_prev), [rc]"=&r" (_rc), [c]"+A" (counter) \
248248
: \
@@ -268,7 +268,7 @@ static __always_inline bool arch_atomic_inc_unless_negative(atomic_t *v)
268268
" addi %[rc], %[p], -1\n" \
269269
" sc." sfx ".rl %[rc], %[rc], %[c]\n" \
270270
" bnez %[rc], 0b\n" \
271-
" fence rw, rw\n" \
271+
RISCV_FULL_BARRIER \
272272
"1:\n" \
273273
: [p]"=&r" (_prev), [rc]"=&r" (_rc), [c]"+A" (counter) \
274274
: \
@@ -294,7 +294,7 @@ static __always_inline bool arch_atomic_dec_unless_positive(atomic_t *v)
294294
" bltz %[rc], 1f\n" \
295295
" sc." sfx ".rl %[rc], %[rc], %[c]\n" \
296296
" bnez %[rc], 0b\n" \
297-
" fence rw, rw\n" \
297+
RISCV_FULL_BARRIER \
298298
"1:\n" \
299299
: [p]"=&r" (_prev), [rc]"=&r" (_rc), [c]"+A" (counter) \
300300
: \

arch/riscv/include/asm/hwcap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@
108108
#define RISCV_ISA_EXT_ZICBOP 99
109109
#define RISCV_ISA_EXT_SVRSW60T59B 100
110110
#define RISCV_ISA_EXT_ZALASR 101
111+
#define RISCV_ISA_EXT_ZILSD 102
112+
#define RISCV_ISA_EXT_ZCLSD 103
111113

112114
#define RISCV_ISA_EXT_XLINUXENVCFG 127
113115

arch/riscv/include/asm/pgtable.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,13 @@ extern int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long a
660660
static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
661661
unsigned long address, pte_t *ptep)
662662
{
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
664670

665671
page_table_check_pte_clear(mm, pte);
666672

@@ -997,7 +1003,13 @@ static inline int pmdp_test_and_clear_young(struct vm_area_struct *vma,
9971003
static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
9981004
unsigned long address, pmd_t *pmdp)
9991005
{
1000-
pmd_t pmd = __pmd(atomic_long_xchg((atomic_long_t *)pmdp, 0));
1006+
#ifdef CONFIG_SMP
1007+
pmd_t pmd = __pmd(xchg(&pmdp->pmd, 0));
1008+
#else
1009+
pmd_t pmd = *pmdp;
1010+
1011+
pmd_clear(pmdp);
1012+
#endif
10011013

10021014
page_table_check_pmd_clear(mm, pmd);
10031015

arch/riscv/include/asm/sbi.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ enum sbi_ext_id {
3737
SBI_EXT_NACL = 0x4E41434C,
3838
SBI_EXT_FWFT = 0x46574654,
3939
SBI_EXT_MPXY = 0x4D505859,
40+
SBI_EXT_DBTR = 0x44425452,
4041

4142
/* Experimentals extensions must lie within this range */
4243
SBI_EXT_EXPERIMENTAL_START = 0x08000000,
@@ -505,6 +506,34 @@ enum sbi_mpxy_rpmi_attribute_id {
505506
#define SBI_MPXY_CHAN_CAP_SEND_WITHOUT_RESP BIT(4)
506507
#define SBI_MPXY_CHAN_CAP_GET_NOTIFICATIONS BIT(5)
507508

509+
/* SBI debug triggers function IDs */
510+
enum sbi_ext_dbtr_fid {
511+
SBI_EXT_DBTR_NUM_TRIGGERS = 0,
512+
SBI_EXT_DBTR_SETUP_SHMEM,
513+
SBI_EXT_DBTR_TRIG_READ,
514+
SBI_EXT_DBTR_TRIG_INSTALL,
515+
SBI_EXT_DBTR_TRIG_UPDATE,
516+
SBI_EXT_DBTR_TRIG_UNINSTALL,
517+
SBI_EXT_DBTR_TRIG_ENABLE,
518+
SBI_EXT_DBTR_TRIG_DISABLE,
519+
};
520+
521+
struct sbi_dbtr_data_msg {
522+
unsigned long tstate;
523+
unsigned long tdata1;
524+
unsigned long tdata2;
525+
unsigned long tdata3;
526+
};
527+
528+
struct sbi_dbtr_id_msg {
529+
unsigned long idx;
530+
};
531+
532+
union sbi_dbtr_shmem_entry {
533+
struct sbi_dbtr_data_msg data;
534+
struct sbi_dbtr_id_msg id;
535+
};
536+
508537
/* SBI spec version fields */
509538
#define SBI_SPEC_VERSION_DEFAULT 0x1
510539
#define SBI_SPEC_VERSION_MAJOR_SHIFT 24

arch/riscv/include/asm/vector.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ static inline bool riscv_v_vstate_ctrl_user_allowed(void) { return false; }
424424
#define riscv_v_thread_free(tsk) do {} while (0)
425425
#define riscv_v_setup_ctx_cache() do {} while (0)
426426
#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)
427430

428431
#endif /* CONFIG_RISCV_ISA_V */
429432

arch/riscv/include/uapi/asm/hwprobe.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ struct riscv_hwprobe {
8484
#define RISCV_HWPROBE_EXT_ZABHA (1ULL << 58)
8585
#define RISCV_HWPROBE_EXT_ZALASR (1ULL << 59)
8686
#define RISCV_HWPROBE_EXT_ZICBOP (1ULL << 60)
87+
#define RISCV_HWPROBE_EXT_ZILSD (1ULL << 61)
88+
#define RISCV_HWPROBE_EXT_ZCLSD (1ULL << 62)
89+
8790
#define RISCV_HWPROBE_KEY_CPUPERF_0 5
8891
#define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0)
8992
#define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0)

arch/riscv/kernel/cpufeature.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,28 @@ static int riscv_ext_zcf_validate(const struct riscv_isa_ext_data *data,
242242
return -EPROBE_DEFER;
243243
}
244244

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+
245267
static int riscv_vector_f_validate(const struct riscv_isa_ext_data *data,
246268
const unsigned long *isa_bitmap)
247269
{
@@ -484,6 +506,8 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = {
484506
__RISCV_ISA_EXT_DATA_VALIDATE(zcd, RISCV_ISA_EXT_ZCD, riscv_ext_zcd_validate),
485507
__RISCV_ISA_EXT_DATA_VALIDATE(zcf, RISCV_ISA_EXT_ZCF, riscv_ext_zcf_validate),
486508
__RISCV_ISA_EXT_DATA_VALIDATE(zcmop, RISCV_ISA_EXT_ZCMOP, riscv_ext_zca_depends),
509+
__RISCV_ISA_EXT_DATA_VALIDATE(zclsd, RISCV_ISA_EXT_ZCLSD, riscv_ext_zclsd_validate),
510+
__RISCV_ISA_EXT_DATA_VALIDATE(zilsd, RISCV_ISA_EXT_ZILSD, riscv_ext_zilsd_validate),
487511
__RISCV_ISA_EXT_DATA(zba, RISCV_ISA_EXT_ZBA),
488512
__RISCV_ISA_EXT_DATA(zbb, RISCV_ISA_EXT_ZBB),
489513
__RISCV_ISA_EXT_DATA(zbc, RISCV_ISA_EXT_ZBC),

arch/riscv/kernel/signal.c

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,19 @@ static long save_fp_state(struct pt_regs *regs,
6868
#define restore_fp_state(task, regs) (0)
6969
#endif
7070

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)
7472
{
75-
struct __riscv_ctx_hdr __user *hdr;
7673
struct __sc_riscv_v_state __user *state;
7774
void __user *datap;
7875
long err;
7976

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;
8384
/* Point datap right after the end of __sc_riscv_v_state */
8485
datap = state + 1;
8586

@@ -97,15 +98,11 @@ static long save_v_state(struct pt_regs *regs, void __user **sc_vec)
9798
err |= __put_user((__force void *)datap, &state->v_state.datap);
9899
/* Copy the whole vector content to user space datap. */
99100
err |= __copy_to_user(datap, current->thread.vstate.datap, riscv_v_vsize);
100-
/* Copy magic to the user space after saving all vector conetext */
101-
err |= __put_user(RISCV_V_MAGIC, &hdr->magic);
102-
err |= __put_user(riscv_v_sc_size, &hdr->size);
103101
if (unlikely(err))
104-
return err;
102+
return -EFAULT;
105103

106-
/* Only progress the sv_vec if everything has done successfully */
107-
*sc_vec += riscv_v_sc_size;
108-
return 0;
104+
/* Only return the size if everything has done successfully */
105+
return riscv_v_sc_size;
109106
}
110107

111108
/*
@@ -142,10 +139,20 @@ static long __restore_v_state(struct pt_regs *regs, void __user *sc_vec)
142139
*/
143140
return copy_from_user(current->thread.vstate.datap, datap, riscv_v_vsize);
144141
}
145-
#else
146-
#define save_v_state(task, regs) (0)
147-
#define __restore_v_state(task, regs) (0)
148-
#endif
142+
143+
struct arch_ext_priv {
144+
__u32 magic;
145+
long (*save)(struct pt_regs *regs, void __user *sc_vec);
146+
};
147+
148+
struct arch_ext_priv arch_ext_list[] = {
149+
{
150+
.magic = RISCV_V_MAGIC,
151+
.save = &save_v_state,
152+
},
153+
};
154+
155+
const size_t nr_arch_exts = ARRAY_SIZE(arch_ext_list);
149156

150157
static long restore_sigcontext(struct pt_regs *regs,
151158
struct sigcontext __user *sc)
@@ -270,16 +277,29 @@ static long setup_sigcontext(struct rt_sigframe __user *frame,
270277
{
271278
struct sigcontext __user *sc = &frame->uc.uc_mcontext;
272279
struct __riscv_ctx_hdr __user *sc_ext_ptr = &sc->sc_extdesc.hdr;
273-
long err;
280+
struct arch_ext_priv *arch_ext;
281+
long err, i, ext_size;
274282

275283
/* sc_regs is structured the same as the start of pt_regs */
276284
err = __copy_to_user(&sc->sc_regs, regs, sizeof(sc->sc_regs));
277285
/* Save the floating-point state. */
278286
if (has_fpu())
279287
err |= save_fp_state(regs, &sc->sc_fpregs);
280288
/* Save the vector state. */
281-
if ((has_vector() || has_xtheadvector()) && riscv_v_vstate_query(regs))
282-
err |= save_v_state(regs, (void __user **)&sc_ext_ptr);
289+
for (i = 0; i < nr_arch_exts; i++) {
290+
arch_ext = &arch_ext_list[i];
291+
if (!arch_ext->save)
292+
continue;
293+
294+
ext_size = arch_ext->save(regs, sc_ext_ptr + 1);
295+
if (ext_size <= 0) {
296+
err |= ext_size;
297+
} else {
298+
err |= __put_user(arch_ext->magic, &sc_ext_ptr->magic);
299+
err |= __put_user(ext_size, &sc_ext_ptr->size);
300+
sc_ext_ptr = (void *)sc_ext_ptr + ext_size;
301+
}
302+
}
283303
/* Write zero to fp-reserved space and check it on restore_sigcontext */
284304
err |= __put_user(0, &sc->sc_extdesc.reserved);
285305
/* And put END __riscv_ctx_hdr at the end. */

0 commit comments

Comments
 (0)