Skip to content

Commit a19b2a9

Browse files
committed
Merge branch 'bpf-next/master' into for-next
No conflict. Signed-off-by: Daniel Borkmann <[email protected]>
2 parents 9cd56ab + dc0fe95 commit a19b2a9

File tree

12 files changed

+226
-399
lines changed

12 files changed

+226
-399
lines changed

arch/riscv/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,6 @@ config TOOLCHAIN_HAS_ZACAS
714714

715715
config RISCV_ISA_ZACAS
716716
bool "Zacas extension support for atomic CAS"
717-
depends on TOOLCHAIN_HAS_ZACAS
718717
depends on RISCV_ALTERNATIVE
719718
default y
720719
help

arch/riscv/include/asm/cmpxchg.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
({ \
134134
if (IS_ENABLED(CONFIG_RISCV_ISA_ZABHA) && \
135135
IS_ENABLED(CONFIG_RISCV_ISA_ZACAS) && \
136+
IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZACAS) && \
136137
riscv_has_extension_unlikely(RISCV_ISA_EXT_ZABHA) && \
137138
riscv_has_extension_unlikely(RISCV_ISA_EXT_ZACAS)) { \
138139
r = o; \
@@ -180,6 +181,7 @@
180181
r, p, co, o, n) \
181182
({ \
182183
if (IS_ENABLED(CONFIG_RISCV_ISA_ZACAS) && \
184+
IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZACAS) && \
183185
riscv_has_extension_unlikely(RISCV_ISA_EXT_ZACAS)) { \
184186
r = o; \
185187
\
@@ -315,7 +317,7 @@
315317
arch_cmpxchg_release((ptr), (o), (n)); \
316318
})
317319

318-
#if defined(CONFIG_64BIT) && defined(CONFIG_RISCV_ISA_ZACAS)
320+
#if defined(CONFIG_64BIT) && defined(CONFIG_RISCV_ISA_ZACAS) && defined(CONFIG_TOOLCHAIN_HAS_ZACAS)
319321

320322
#define system_has_cmpxchg128() riscv_has_extension_unlikely(RISCV_ISA_EXT_ZACAS)
321323

@@ -351,7 +353,7 @@ union __u128_halves {
351353
#define arch_cmpxchg128_local(ptr, o, n) \
352354
__arch_cmpxchg128((ptr), (o), (n), "")
353355

354-
#endif /* CONFIG_64BIT && CONFIG_RISCV_ISA_ZACAS */
356+
#endif /* CONFIG_64BIT && CONFIG_RISCV_ISA_ZACAS && CONFIG_TOOLCHAIN_HAS_ZACAS */
355357

356358
#ifdef CONFIG_RISCV_ISA_ZAWRS
357359
/*

arch/riscv/kernel/setup.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ static void __init riscv_spinlock_init(void)
290290

291291
if (IS_ENABLED(CONFIG_RISCV_ISA_ZABHA) &&
292292
IS_ENABLED(CONFIG_RISCV_ISA_ZACAS) &&
293+
IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZACAS) &&
293294
riscv_isa_extension_available(NULL, ZABHA) &&
294295
riscv_isa_extension_available(NULL, ZACAS)) {
295296
using_ext = "using Zabha";

arch/riscv/net/bpf_jit.h

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,15 @@
1313
#include <linux/filter.h>
1414
#include <asm/cacheflush.h>
1515

16+
/* verify runtime detection extension status */
17+
#define rv_ext_enabled(ext) \
18+
(IS_ENABLED(CONFIG_RISCV_ISA_##ext) && riscv_has_extension_likely(RISCV_ISA_EXT_##ext))
19+
1620
static inline bool rvc_enabled(void)
1721
{
1822
return IS_ENABLED(CONFIG_RISCV_ISA_C);
1923
}
2024

21-
static inline bool rvzba_enabled(void)
22-
{
23-
return IS_ENABLED(CONFIG_RISCV_ISA_ZBA) && riscv_has_extension_likely(RISCV_ISA_EXT_ZBA);
24-
}
25-
26-
static inline bool rvzbb_enabled(void)
27-
{
28-
return IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && riscv_has_extension_likely(RISCV_ISA_EXT_ZBB);
29-
}
30-
3125
enum {
3226
RV_REG_ZERO = 0, /* The constant value 0 */
3327
RV_REG_RA = 1, /* Return address */
@@ -84,6 +78,8 @@ struct rv_jit_context {
8478
int epilogue_offset;
8579
int *offset; /* BPF to RV */
8680
int nexentries;
81+
int ex_insn_off;
82+
int ex_jmp_off;
8783
unsigned long flags;
8884
int stack_size;
8985
u64 arena_vm_start;
@@ -757,6 +753,17 @@ static inline u16 rvc_swsp(u32 imm8, u8 rs2)
757753
return rv_css_insn(0x6, imm, rs2, 0x2);
758754
}
759755

756+
/* RVZACAS instructions. */
757+
static inline u32 rvzacas_amocas_w(u8 rd, u8 rs2, u8 rs1, u8 aq, u8 rl)
758+
{
759+
return rv_amo_insn(0x5, aq, rl, rs2, rs1, 2, rd, 0x2f);
760+
}
761+
762+
static inline u32 rvzacas_amocas_d(u8 rd, u8 rs2, u8 rs1, u8 aq, u8 rl)
763+
{
764+
return rv_amo_insn(0x5, aq, rl, rs2, rs1, 3, rd, 0x2f);
765+
}
766+
760767
/* RVZBA instructions. */
761768
static inline u32 rvzba_sh2add(u8 rd, u8 rs1, u8 rs2)
762769
{
@@ -1123,7 +1130,7 @@ static inline void emit_sw(u8 rs1, s32 off, u8 rs2, struct rv_jit_context *ctx)
11231130

11241131
static inline void emit_sh2add(u8 rd, u8 rs1, u8 rs2, struct rv_jit_context *ctx)
11251132
{
1126-
if (rvzba_enabled()) {
1133+
if (rv_ext_enabled(ZBA)) {
11271134
emit(rvzba_sh2add(rd, rs1, rs2), ctx);
11281135
return;
11291136
}
@@ -1134,7 +1141,7 @@ static inline void emit_sh2add(u8 rd, u8 rs1, u8 rs2, struct rv_jit_context *ctx
11341141

11351142
static inline void emit_sh3add(u8 rd, u8 rs1, u8 rs2, struct rv_jit_context *ctx)
11361143
{
1137-
if (rvzba_enabled()) {
1144+
if (rv_ext_enabled(ZBA)) {
11381145
emit(rvzba_sh3add(rd, rs1, rs2), ctx);
11391146
return;
11401147
}
@@ -1184,7 +1191,7 @@ static inline void emit_subw(u8 rd, u8 rs1, u8 rs2, struct rv_jit_context *ctx)
11841191

11851192
static inline void emit_sextb(u8 rd, u8 rs, struct rv_jit_context *ctx)
11861193
{
1187-
if (rvzbb_enabled()) {
1194+
if (rv_ext_enabled(ZBB)) {
11881195
emit(rvzbb_sextb(rd, rs), ctx);
11891196
return;
11901197
}
@@ -1195,7 +1202,7 @@ static inline void emit_sextb(u8 rd, u8 rs, struct rv_jit_context *ctx)
11951202

11961203
static inline void emit_sexth(u8 rd, u8 rs, struct rv_jit_context *ctx)
11971204
{
1198-
if (rvzbb_enabled()) {
1205+
if (rv_ext_enabled(ZBB)) {
11991206
emit(rvzbb_sexth(rd, rs), ctx);
12001207
return;
12011208
}
@@ -1211,7 +1218,7 @@ static inline void emit_sextw(u8 rd, u8 rs, struct rv_jit_context *ctx)
12111218

12121219
static inline void emit_zexth(u8 rd, u8 rs, struct rv_jit_context *ctx)
12131220
{
1214-
if (rvzbb_enabled()) {
1221+
if (rv_ext_enabled(ZBB)) {
12151222
emit(rvzbb_zexth(rd, rs), ctx);
12161223
return;
12171224
}
@@ -1222,7 +1229,7 @@ static inline void emit_zexth(u8 rd, u8 rs, struct rv_jit_context *ctx)
12221229

12231230
static inline void emit_zextw(u8 rd, u8 rs, struct rv_jit_context *ctx)
12241231
{
1225-
if (rvzba_enabled()) {
1232+
if (rv_ext_enabled(ZBA)) {
12261233
emit(rvzba_zextw(rd, rs), ctx);
12271234
return;
12281235
}
@@ -1233,7 +1240,7 @@ static inline void emit_zextw(u8 rd, u8 rs, struct rv_jit_context *ctx)
12331240

12341241
static inline void emit_bswap(u8 rd, s32 imm, struct rv_jit_context *ctx)
12351242
{
1236-
if (rvzbb_enabled()) {
1243+
if (rv_ext_enabled(ZBB)) {
12371244
int bits = 64 - imm;
12381245

12391246
emit(rvzbb_rev8(rd, rd), ctx);
@@ -1289,6 +1296,35 @@ static inline void emit_bswap(u8 rd, s32 imm, struct rv_jit_context *ctx)
12891296
emit_mv(rd, RV_REG_T2, ctx);
12901297
}
12911298

1299+
static inline void emit_cmpxchg(u8 rd, u8 rs, u8 r0, bool is64, struct rv_jit_context *ctx)
1300+
{
1301+
int jmp_offset;
1302+
1303+
if (rv_ext_enabled(ZACAS)) {
1304+
ctx->ex_insn_off = ctx->ninsns;
1305+
emit(is64 ? rvzacas_amocas_d(r0, rs, rd, 1, 1) :
1306+
rvzacas_amocas_w(r0, rs, rd, 1, 1), ctx);
1307+
ctx->ex_jmp_off = ctx->ninsns;
1308+
if (!is64)
1309+
emit_zextw(r0, r0, ctx);
1310+
return;
1311+
}
1312+
1313+
if (is64)
1314+
emit_mv(RV_REG_T2, r0, ctx);
1315+
else
1316+
emit_addiw(RV_REG_T2, r0, 0, ctx);
1317+
emit(is64 ? rv_lr_d(r0, 0, rd, 0, 0) :
1318+
rv_lr_w(r0, 0, rd, 0, 0), ctx);
1319+
jmp_offset = ninsns_rvoff(8);
1320+
emit(rv_bne(RV_REG_T2, r0, jmp_offset >> 1), ctx);
1321+
emit(is64 ? rv_sc_d(RV_REG_T3, rs, rd, 0, 1) :
1322+
rv_sc_w(RV_REG_T3, rs, rd, 0, 1), ctx);
1323+
jmp_offset = ninsns_rvoff(-6);
1324+
emit(rv_bne(RV_REG_T3, 0, jmp_offset >> 1), ctx);
1325+
emit_fence_rw_rw(ctx);
1326+
}
1327+
12921328
#endif /* __riscv_xlen == 64 */
12931329

12941330
void bpf_jit_build_prologue(struct rv_jit_context *ctx, bool is_subprog);

0 commit comments

Comments
 (0)