Skip to content

Commit 07025b5

Browse files
committed
Merge tag 'riscv-for-linus-6.19-mw1' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux
Pull RISC-V updates from Paul Walmsley: - Enable parallel hotplug for RISC-V - Optimize vector regset allocation for ptrace() - Add a kernel selftest for the vector ptrace interface - Enable the userspace RAID6 test to build and run using RISC-V vectors - Add initial support for the Zalasr RISC-V ratified ISA extension - For the Zicbop RISC-V ratified ISA extension to userspace, expose hardware and kernel support to userspace and add a kselftest for Zicbop - Convert open-coded instances of 'asm goto's that are controlled by runtime ALTERNATIVEs to use riscv_has_extension_{un,}likely(), following arm64's alternative_has_cap_{un,}likely() - Remove an unnecessary mask in the GFP flags used in some calls to pagetable_alloc() * tag 'riscv-for-linus-6.19-mw1' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: selftests/riscv: Add Zicbop prefetch test riscv: hwprobe: Expose Zicbop extension and its block size riscv: Introduce Zalasr instructions riscv: hwprobe: Export Zalasr extension dt-bindings: riscv: Add Zalasr ISA extension description riscv: Add ISA extension parsing for Zalasr selftests: riscv: Add test for the Vector ptrace interface riscv: ptrace: Optimize the allocation of vector regset raid6: test: Add support for RISC-V raid6: riscv: Allow code to be compiled in userspace raid6: riscv: Prevent compiler from breaking inline vector assembly code riscv: cmpxchg: Use riscv_has_extension_likely riscv: bitops: Use riscv_has_extension_likely riscv: hweight: Use riscv_has_extension_likely riscv: checksum: Use riscv_has_extension_likely riscv: pgtable: Use riscv_has_extension_unlikely riscv: Remove __GFP_HIGHMEM masking RISC-V: Enable HOTPLUG_PARALLEL for secondary CPUs
2 parents ad952db + a131fd6 commit 07025b5

28 files changed

Lines changed: 657 additions & 306 deletions

File tree

Documentation/arch/riscv/hwprobe.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ The following keys are defined:
249249
defined in the in the RISC-V ISA manual starting from commit e87412e621f1
250250
("integrate Zaamo and Zalrsc text (#1304)").
251251

252+
* :c:macro:`RISCV_HWPROBE_EXT_ZALASR`: The Zalasr extension is supported as
253+
frozen at commit 194f0094 ("Version 0.9 for freeze") of riscv-zalasr.
254+
252255
* :c:macro:`RISCV_HWPROBE_EXT_ZALRSC`: The Zalrsc extension is supported as
253256
defined in the in the RISC-V ISA manual starting from commit e87412e621f1
254257
("integrate Zaamo and Zalrsc text (#1304)").
@@ -275,6 +278,9 @@ The following keys are defined:
275278
ratified in commit 49f49c842ff9 ("Update to Rafified state") of
276279
riscv-zabha.
277280

281+
* :c:macro:`RISCV_HWPROBE_EXT_ZICBOP`: The Zicbop extension is supported, as
282+
ratified in commit 3dd606f ("Create cmobase-v1.0.pdf") of riscv-CMOs.
283+
278284
* :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: Deprecated. Returns similar values to
279285
:c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF`, but the key was
280286
mistakenly classified as a bitmask rather than a value.
@@ -369,4 +375,7 @@ The following keys are defined:
369375

370376
* :c:macro:`RISCV_HWPROBE_VENDOR_EXT_XSFVFWMACCQQQ`: The Xsfvfwmaccqqq
371377
vendor extension is supported in version 1.0 of Matrix Multiply Accumulate
372-
Instruction Extensions Specification.
378+
Instruction Extensions Specification.
379+
380+
* :c:macro:`RISCV_HWPROBE_KEY_ZICBOP_BLOCK_SIZE`: An unsigned int which
381+
represents the size of the Zicbop block in bytes.

Documentation/devicetree/bindings/riscv/extensions.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ properties:
248248
is supported as ratified at commit 5059e0ca641c ("update to
249249
ratified") of the riscv-zacas.
250250
251+
- const: zalasr
252+
description: |
253+
The standard Zalasr extension for load-acquire/store-release as frozen
254+
at commit 194f0094 ("Version 0.9 for freeze") of riscv-zalasr.
255+
251256
- const: zalrsc
252257
description: |
253258
The standard Zalrsc extension for load-reserved/store-conditional as

arch/riscv/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ config RISCV
200200
select HAVE_SAMPLE_FTRACE_DIRECT_MULTI
201201
select HAVE_STACKPROTECTOR
202202
select HAVE_SYSCALL_TRACEPOINTS
203-
select HOTPLUG_CORE_SYNC_DEAD if HOTPLUG_CPU
203+
select HOTPLUG_PARALLEL if HOTPLUG_CPU
204204
select IRQ_DOMAIN
205205
select IRQ_FORCED_THREADING
206206
select KASAN_VMALLOC if KASAN

arch/riscv/include/asm/arch_hweight.h

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919

2020
static __always_inline unsigned int __arch_hweight32(unsigned int w)
2121
{
22-
#if defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB)
23-
asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
24-
RISCV_ISA_EXT_ZBB, 1)
25-
: : : : legacy);
22+
if (!(IS_ENABLED(CONFIG_RISCV_ISA_ZBB) &&
23+
IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB) &&
24+
riscv_has_extension_likely(RISCV_ISA_EXT_ZBB)))
25+
return __sw_hweight32(w);
2626

2727
asm (".option push\n"
2828
".option arch,+zbb\n"
@@ -31,10 +31,6 @@ static __always_inline unsigned int __arch_hweight32(unsigned int w)
3131
: "=r" (w) : "r" (w) :);
3232

3333
return w;
34-
35-
legacy:
36-
#endif
37-
return __sw_hweight32(w);
3834
}
3935

4036
static inline unsigned int __arch_hweight16(unsigned int w)
@@ -50,10 +46,10 @@ static inline unsigned int __arch_hweight8(unsigned int w)
5046
#if BITS_PER_LONG == 64
5147
static __always_inline unsigned long __arch_hweight64(__u64 w)
5248
{
53-
#if defined(CONFIG_RISCV_ISA_ZBB) && defined(CONFIG_TOOLCHAIN_HAS_ZBB)
54-
asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
55-
RISCV_ISA_EXT_ZBB, 1)
56-
: : : : legacy);
49+
if (!(IS_ENABLED(CONFIG_RISCV_ISA_ZBB) &&
50+
IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB) &&
51+
riscv_has_extension_likely(RISCV_ISA_EXT_ZBB)))
52+
return __sw_hweight64(w);
5753

5854
asm (".option push\n"
5955
".option arch,+zbb\n"
@@ -62,10 +58,6 @@ static __always_inline unsigned long __arch_hweight64(__u64 w)
6258
: "=r" (w) : "r" (w) :);
6359

6460
return w;
65-
66-
legacy:
67-
#endif
68-
return __sw_hweight64(w);
6961
}
7062
#else /* BITS_PER_LONG == 64 */
7163
static inline unsigned long __arch_hweight64(__u64 w)

arch/riscv/include/asm/bitops.h

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@
4747

4848
static __always_inline __attribute_const__ unsigned long variable__ffs(unsigned long word)
4949
{
50-
asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
51-
RISCV_ISA_EXT_ZBB, 1)
52-
: : : : legacy);
50+
if (!riscv_has_extension_likely(RISCV_ISA_EXT_ZBB))
51+
return generic___ffs(word);
5352

5453
asm volatile (".option push\n"
5554
".option arch,+zbb\n"
@@ -58,9 +57,6 @@ static __always_inline __attribute_const__ unsigned long variable__ffs(unsigned
5857
: "=r" (word) : "r" (word) :);
5958

6059
return word;
61-
62-
legacy:
63-
return generic___ffs(word);
6460
}
6561

6662
/**
@@ -76,9 +72,8 @@ static __always_inline __attribute_const__ unsigned long variable__ffs(unsigned
7672

7773
static __always_inline __attribute_const__ unsigned long variable__fls(unsigned long word)
7874
{
79-
asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
80-
RISCV_ISA_EXT_ZBB, 1)
81-
: : : : legacy);
75+
if (!riscv_has_extension_likely(RISCV_ISA_EXT_ZBB))
76+
return generic___fls(word);
8277

8378
asm volatile (".option push\n"
8479
".option arch,+zbb\n"
@@ -87,9 +82,6 @@ static __always_inline __attribute_const__ unsigned long variable__fls(unsigned
8782
: "=r" (word) : "r" (word) :);
8883

8984
return BITS_PER_LONG - 1 - word;
90-
91-
legacy:
92-
return generic___fls(word);
9385
}
9486

9587
/**
@@ -105,9 +97,8 @@ static __always_inline __attribute_const__ unsigned long variable__fls(unsigned
10597

10698
static __always_inline __attribute_const__ int variable_ffs(int x)
10799
{
108-
asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
109-
RISCV_ISA_EXT_ZBB, 1)
110-
: : : : legacy);
100+
if (!riscv_has_extension_likely(RISCV_ISA_EXT_ZBB))
101+
return generic_ffs(x);
111102

112103
if (!x)
113104
return 0;
@@ -119,9 +110,6 @@ static __always_inline __attribute_const__ int variable_ffs(int x)
119110
: "=r" (x) : "r" (x) :);
120111

121112
return x + 1;
122-
123-
legacy:
124-
return generic_ffs(x);
125113
}
126114

127115
/**
@@ -137,9 +125,8 @@ static __always_inline __attribute_const__ int variable_ffs(int x)
137125

138126
static __always_inline int variable_fls(unsigned int x)
139127
{
140-
asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0,
141-
RISCV_ISA_EXT_ZBB, 1)
142-
: : : : legacy);
128+
if (!riscv_has_extension_likely(RISCV_ISA_EXT_ZBB))
129+
return generic_fls(x);
143130

144131
if (!x)
145132
return 0;
@@ -151,9 +138,6 @@ static __always_inline int variable_fls(unsigned int x)
151138
: "=r" (x) : "r" (x) :);
152139

153140
return 32 - x;
154-
155-
legacy:
156-
return generic_fls(x);
157141
}
158142

159143
/**

arch/riscv/include/asm/checksum.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,11 @@ static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
4949
* ZBB only saves three instructions on 32-bit and five on 64-bit so not
5050
* worth checking if supported without Alternatives.
5151
*/
52-
if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB)) {
52+
if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) &&
53+
IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB) &&
54+
riscv_has_extension_likely(RISCV_ISA_EXT_ZBB)) {
5355
unsigned long fold_temp;
5456

55-
asm goto(ALTERNATIVE("j %l[no_zbb]", "nop", 0,
56-
RISCV_ISA_EXT_ZBB, 1)
57-
:
58-
:
59-
:
60-
: no_zbb);
61-
6257
if (IS_ENABLED(CONFIG_32BIT)) {
6358
asm(".option push \n\
6459
.option arch,+zbb \n\
@@ -81,7 +76,7 @@ static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
8176
}
8277
return (__force __sum16)(csum >> 16);
8378
}
84-
no_zbb:
79+
8580
#ifndef CONFIG_32BIT
8681
csum += ror64(csum, 32);
8782
csum >>= 32;

arch/riscv/include/asm/cmpxchg.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,10 @@ static __always_inline void __cmpwait(volatile void *ptr,
373373
u32 *__ptr32b;
374374
ulong __s, __val, __mask;
375375

376-
asm goto(ALTERNATIVE("j %l[no_zawrs]", "nop",
377-
0, RISCV_ISA_EXT_ZAWRS, 1)
378-
: : : : no_zawrs);
376+
if (!riscv_has_extension_likely(RISCV_ISA_EXT_ZAWRS)) {
377+
ALT_RISCV_PAUSE();
378+
return;
379+
}
379380

380381
switch (size) {
381382
case 1:
@@ -437,11 +438,6 @@ static __always_inline void __cmpwait(volatile void *ptr,
437438
default:
438439
BUILD_BUG();
439440
}
440-
441-
return;
442-
443-
no_zawrs:
444-
ALT_RISCV_PAUSE();
445441
}
446442

447443
#define __cmpwait_relaxed(ptr, val) \

arch/riscv/include/asm/hwcap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
#define RISCV_ISA_EXT_ZALRSC 98
108108
#define RISCV_ISA_EXT_ZICBOP 99
109109
#define RISCV_ISA_EXT_SVRSW60T59B 100
110+
#define RISCV_ISA_EXT_ZALASR 101
110111

111112
#define RISCV_ISA_EXT_XLINUXENVCFG 127
112113

arch/riscv/include/asm/hwprobe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <uapi/asm/hwprobe.h>
1010

11-
#define RISCV_HWPROBE_MAX_KEY 14
11+
#define RISCV_HWPROBE_MAX_KEY 15
1212

1313
static inline bool riscv_hwprobe_key_is_valid(__s64 key)
1414
{

arch/riscv/include/asm/insn-def.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
#define RV___RS1(v) __RV_REG(v)
180180
#define RV___RS2(v) __RV_REG(v)
181181

182+
#define RV_OPCODE_AMO RV_OPCODE(47)
182183
#define RV_OPCODE_MISC_MEM RV_OPCODE(15)
183184
#define RV_OPCODE_OP_IMM RV_OPCODE(19)
184185
#define RV_OPCODE_SYSTEM RV_OPCODE(115)
@@ -208,6 +209,84 @@
208209
__ASM_STR(.error "hlv.d requires 64-bit support")
209210
#endif
210211

212+
#define LB_AQ(dest, addr) \
213+
INSN_R(OPCODE_AMO, FUNC3(0), FUNC7(26), \
214+
RD(dest), RS1(addr), __RS2(0))
215+
216+
#define LB_AQRL(dest, addr) \
217+
INSN_R(OPCODE_AMO, FUNC3(0), FUNC7(27), \
218+
RD(dest), RS1(addr), __RS2(0))
219+
220+
#define LH_AQ(dest, addr) \
221+
INSN_R(OPCODE_AMO, FUNC3(1), FUNC7(26), \
222+
RD(dest), RS1(addr), __RS2(0))
223+
224+
#define LH_AQRL(dest, addr) \
225+
INSN_R(OPCODE_AMO, FUNC3(1), FUNC7(27), \
226+
RD(dest), RS1(addr), __RS2(0))
227+
228+
#define LW_AQ(dest, addr) \
229+
INSN_R(OPCODE_AMO, FUNC3(2), FUNC7(26), \
230+
RD(dest), RS1(addr), __RS2(0))
231+
232+
#define LW_AQRL(dest, addr) \
233+
INSN_R(OPCODE_AMO, FUNC3(2), FUNC7(27), \
234+
RD(dest), RS1(addr), __RS2(0))
235+
236+
#define SB_RL(src, addr) \
237+
INSN_R(OPCODE_AMO, FUNC3(0), FUNC7(29), \
238+
__RD(0), RS1(addr), RS2(src))
239+
240+
#define SB_AQRL(src, addr) \
241+
INSN_R(OPCODE_AMO, FUNC3(0), FUNC7(31), \
242+
__RD(0), RS1(addr), RS2(src))
243+
244+
#define SH_RL(src, addr) \
245+
INSN_R(OPCODE_AMO, FUNC3(1), FUNC7(29), \
246+
__RD(0), RS1(addr), RS2(src))
247+
248+
#define SH_AQRL(src, addr) \
249+
INSN_R(OPCODE_AMO, FUNC3(1), FUNC7(31), \
250+
__RD(0), RS1(addr), RS2(src))
251+
252+
#define SW_RL(src, addr) \
253+
INSN_R(OPCODE_AMO, FUNC3(2), FUNC7(29), \
254+
__RD(0), RS1(addr), RS2(src))
255+
256+
#define SW_AQRL(src, addr) \
257+
INSN_R(OPCODE_AMO, FUNC3(2), FUNC7(31), \
258+
__RD(0), RS1(addr), RS2(src))
259+
260+
#ifdef CONFIG_64BIT
261+
#define LD_AQ(dest, addr) \
262+
INSN_R(OPCODE_AMO, FUNC3(3), FUNC7(26), \
263+
RD(dest), RS1(addr), __RS2(0))
264+
265+
#define LD_AQRL(dest, addr) \
266+
INSN_R(OPCODE_AMO, FUNC3(3), FUNC7(27), \
267+
RD(dest), RS1(addr), __RS2(0))
268+
269+
#define SD_RL(src, addr) \
270+
INSN_R(OPCODE_AMO, FUNC3(3), FUNC7(29), \
271+
__RD(0), RS1(addr), RS2(src))
272+
273+
#define SD_AQRL(src, addr) \
274+
INSN_R(OPCODE_AMO, FUNC3(3), FUNC7(31), \
275+
__RD(0), RS1(addr), RS2(src))
276+
#else
277+
#define LD_AQ(dest, addr) \
278+
__ASM_STR(.error "ld.aq requires 64-bit support")
279+
280+
#define LD_AQRL(dest, addr) \
281+
__ASM_STR(.error "ld.aqrl requires 64-bit support")
282+
283+
#define SD_RL(dest, addr) \
284+
__ASM_STR(.error "sd.rl requires 64-bit support")
285+
286+
#define SD_AQRL(dest, addr) \
287+
__ASM_STR(.error "sd.aqrl requires 64-bit support")
288+
#endif
289+
211290
#define SINVAL_VMA(vaddr, asid) \
212291
INSN_R(OPCODE_SYSTEM, FUNC3(0), FUNC7(11), \
213292
__RD(0), RS1(vaddr), RS2(asid))

0 commit comments

Comments
 (0)