]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
riscv, bpf: Add rv_ext_enabled macro for runtime detection extentsion
authorPu Lehui <pulehui@huawei.com>
Sat, 19 Jul 2025 09:17:25 +0000 (09:17 +0000)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 15 Aug 2025 08:46:51 +0000 (10:46 +0200)
Add rv_ext_enabled macro to check whether the runtime detection
extension is enabled.

Signed-off-by: Pu Lehui <pulehui@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Tested-by: Björn Töpel <bjorn@rivosinc.com>
Reviewed-by: Björn Töpel <bjorn@rivosinc.com>
Acked-by: Björn Töpel <bjorn@kernel.org>
Link: https://lore.kernel.org/bpf/20250719091730.2660197-6-pulehui@huaweicloud.com
arch/riscv/net/bpf_jit.h

index e7b032dfd17f0ff8e2e23c8921b6914b6402d00c..0964df48c25eafe36d220c0f84271b2f8ca670d2 100644 (file)
 #include <linux/filter.h>
 #include <asm/cacheflush.h>
 
+/* verify runtime detection extension status */
+#define rv_ext_enabled(ext) \
+       (IS_ENABLED(CONFIG_RISCV_ISA_##ext) && riscv_has_extension_likely(RISCV_ISA_EXT_##ext))
+
 static inline bool rvc_enabled(void)
 {
        return IS_ENABLED(CONFIG_RISCV_ISA_C);
 }
 
-static inline bool rvzba_enabled(void)
-{
-       return IS_ENABLED(CONFIG_RISCV_ISA_ZBA) && riscv_has_extension_likely(RISCV_ISA_EXT_ZBA);
-}
-
-static inline bool rvzbb_enabled(void)
-{
-       return IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && riscv_has_extension_likely(RISCV_ISA_EXT_ZBB);
-}
-
 enum {
        RV_REG_ZERO =   0,      /* The constant value 0 */
        RV_REG_RA =     1,      /* Return address */
@@ -1123,7 +1117,7 @@ static inline void emit_sw(u8 rs1, s32 off, u8 rs2, struct rv_jit_context *ctx)
 
 static inline void emit_sh2add(u8 rd, u8 rs1, u8 rs2, struct rv_jit_context *ctx)
 {
-       if (rvzba_enabled()) {
+       if (rv_ext_enabled(ZBA)) {
                emit(rvzba_sh2add(rd, rs1, rs2), ctx);
                return;
        }
@@ -1134,7 +1128,7 @@ static inline void emit_sh2add(u8 rd, u8 rs1, u8 rs2, struct rv_jit_context *ctx
 
 static inline void emit_sh3add(u8 rd, u8 rs1, u8 rs2, struct rv_jit_context *ctx)
 {
-       if (rvzba_enabled()) {
+       if (rv_ext_enabled(ZBA)) {
                emit(rvzba_sh3add(rd, rs1, rs2), ctx);
                return;
        }
@@ -1184,7 +1178,7 @@ static inline void emit_subw(u8 rd, u8 rs1, u8 rs2, struct rv_jit_context *ctx)
 
 static inline void emit_sextb(u8 rd, u8 rs, struct rv_jit_context *ctx)
 {
-       if (rvzbb_enabled()) {
+       if (rv_ext_enabled(ZBB)) {
                emit(rvzbb_sextb(rd, rs), ctx);
                return;
        }
@@ -1195,7 +1189,7 @@ static inline void emit_sextb(u8 rd, u8 rs, struct rv_jit_context *ctx)
 
 static inline void emit_sexth(u8 rd, u8 rs, struct rv_jit_context *ctx)
 {
-       if (rvzbb_enabled()) {
+       if (rv_ext_enabled(ZBB)) {
                emit(rvzbb_sexth(rd, rs), ctx);
                return;
        }
@@ -1211,7 +1205,7 @@ static inline void emit_sextw(u8 rd, u8 rs, struct rv_jit_context *ctx)
 
 static inline void emit_zexth(u8 rd, u8 rs, struct rv_jit_context *ctx)
 {
-       if (rvzbb_enabled()) {
+       if (rv_ext_enabled(ZBB)) {
                emit(rvzbb_zexth(rd, rs), ctx);
                return;
        }
@@ -1222,7 +1216,7 @@ static inline void emit_zexth(u8 rd, u8 rs, struct rv_jit_context *ctx)
 
 static inline void emit_zextw(u8 rd, u8 rs, struct rv_jit_context *ctx)
 {
-       if (rvzba_enabled()) {
+       if (rv_ext_enabled(ZBA)) {
                emit(rvzba_zextw(rd, rs), ctx);
                return;
        }
@@ -1233,7 +1227,7 @@ static inline void emit_zextw(u8 rd, u8 rs, struct rv_jit_context *ctx)
 
 static inline void emit_bswap(u8 rd, s32 imm, struct rv_jit_context *ctx)
 {
-       if (rvzbb_enabled()) {
+       if (rv_ext_enabled(ZBB)) {
                int bits = 64 - imm;
 
                emit(rvzbb_rev8(rd, rd), ctx);