Zbb string optimizations and call support in alternatives
v2 cover Zbb string optimizations and call support in alternatives
From: Heiko Stuebner <[email protected]>
The Zbb extension can be used to make string functions run a lot faster.
To allow There are essentially two problems to solve:
- making it possible for str* functions to replace what they do in a performant way
This is done by inlining the core functions and then using alternatives to call the actual variant.
This of course will need a more intelligent selection mechanism down the road when more variants may exist using different available extensions.
- actually allowing calls in alternatives
Function calls use auipc + jalr to reach those 32bit relative addresses but when they're compiled the offset will be wrong as alternatives live in a different section. So when the patch gets applied the address will point to the wrong location.
So similar to arm64 the target addresses need to be updated.
This is probably also helpful for other things needing more complex code in alternatives.
In my half-scientific test-case of running the functions in question on a 95 character string in a loop of 10000 iterations, the Zbb variants shave off around 2/3 of the original runtime.
For v2 I got into some sort of cleanup spree for the general instruction parsing that already existed. A number of places do their own instruction parsing and I tried consolidating some of them.
Noteable, the kvm parts still do, but I had to stop somewhere :-)
changes since v1:
- a number of generalizations/cleanups for instruction parsing
- use accessor function to access instructions (Emil)
- actually patch the correct location when having more than one instruction in an alternative block
- string function cleanups (comments etc) (Conor)
- move zbb extension above s* extensions in cpu.c lists
changes since rfc:
- make Zbb code actually work
- drop some unneeded patches
- a lot of cleanups
Heiko Stuebner (13):
RISC-V: add prefix to all constants/macros in parse_asm.h
RISC-V: detach funct-values from their offset
RISC-V: add ebreak instructions to definitions
RISC-V: Move riscv_insn_is_* macros into a common header
RISC-V: rename parse_asm.h to insn.h
RISC-V: kprobes: use central defined funct3 constants
RISC-V: add auipc elements to parse_asm header
RISC-V: add U-type imm parsing to parse_asm header
RISC-V: add rd reg parsing to parse_asm header
RISC-V: fix auipc-jalr addresses in patched alternatives efi/riscv: libstub: mark when compiling libstub
RISC-V: add infrastructure to allow different str* implementations
RISC-V: add zbb support to string functions
arch/riscv/Kconfig | 23 ++ arch/riscv/include/asm/alternative.h | 3 + arch/riscv/include/asm/errata_list.h | 3 +- arch/riscv/include/asm/hwcap.h | 1 + arch/riscv/include/asm/insn.h | 292 +++++++++++++++++++++++ arch/riscv/include/asm/parse_asm.h | 219 ----------------- arch/riscv/include/asm/string.h | 83 +++++++ arch/riscv/kernel/alternative.c | 72 ++++++ arch/riscv/kernel/cpu.c | 1 + arch/riscv/kernel/cpufeature.c | 29 ++- arch/riscv/kernel/image-vars.h | 6 +- arch/riscv/kernel/kgdb.c | 63 ++--- arch/riscv/kernel/probes/simulate-insn.c | 19 +- arch/riscv/kernel/probes/simulate-insn.h | 26 +- arch/riscv/lib/Makefile | 6 + arch/riscv/lib/strcmp.S | 38 +++ arch/riscv/lib/strcmp_zbb.S | 96 ++++++++ arch/riscv/lib/strlen.S | 29 +++ arch/riscv/lib/strlen_zbb.S | 115 +++++++++ arch/riscv/lib/strncmp.S | 41 ++++ arch/riscv/lib/strncmp_zbb.S | 112 +++++++++ drivers/firmware/efi/libstub/Makefile | 2 +- 22 files changed, 978 insertions(+), 301 deletions(-) create mode 100644 arch/riscv/include/asm/insn.h delete mode 100644 arch/riscv/include/asm/parse_asm.h create mode 100644 arch/riscv/lib/strcmp.S create mode 100644 arch/riscv/lib/strcmp_zbb.S create mode 100644 arch/riscv/lib/strlen.S create mode 100644 arch/riscv/lib/strlen_zbb.S create mode 100644 arch/riscv/lib/strncmp.S create mode 100644 arch/riscv/lib/strncmp_zbb.S
Signature · 7 lines
2.35.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v2 1/13 RISC-V: add prefix to all constants/macros in parse_asm.h
From: Heiko Stuebner <[email protected]>
Some of the constants and macros already have suitable RV_, RVG_ or RVC_ prefixes.
Extend this to the rest of the file as well, as we want to use these things in a broader scope soon.
--- arch/riscv/include/asm/parse_asm.h | 194 ++++++++++++++--------------- arch/riscv/kernel/kgdb.c | 12 +- 2 files changed, 103 insertions(+), 103 deletions(-)
arch/riscv/include/asm/parse_asm.h +97 -97
@@ -6,37 +6,37 @@#include <linux/bits.h> /* The bit field of immediate value in I-type instruction */ -#define I_IMM_SIGN_OPOFF 31 -#define I_IMM_11_0_OPOFF 20 -#define I_IMM_SIGN_OFF 12 -#define I_IMM_11_0_OFF 0 -#define I_IMM_11_0_MASK GENMASK(11, 0) +#define RV_I_IMM_SIGN_OPOFF 31 +#define RV_I_IMM_11_0_OPOFF 20 +#define RV_I_IMM_SIGN_OFF 12 +#define RV_I_IMM_11_0_OFF 0 +#define RV_I_IMM_11_0_MASK GENMASK(11, 0)/* The bit field of immediate value in J-type instruction */ -#define J_IMM_SIGN_OPOFF 31 -#define J_IMM_10_1_OPOFF 21 -#define J_IMM_11_OPOFF 20 -#define J_IMM_19_12_OPOFF 12 -#define J_IMM_SIGN_OFF 20 -#define J_IMM_10_1_OFF 1 -#define J_IMM_11_OFF 11 -#define J_IMM_19_12_OFF 12 -#define J_IMM_10_1_MASK GENMASK(9, 0) -#define J_IMM_11_MASK GENMASK(0, 0) -#define J_IMM_19_12_MASK GENMASK(7, 0) +#define RV_J_IMM_SIGN_OPOFF 31 +#define RV_J_IMM_10_1_OPOFF 21 +#define RV_J_IMM_11_OPOFF 20 +#define RV_J_IMM_19_12_OPOFF 12 +#define RV_J_IMM_SIGN_OFF 20 +#define RV_J_IMM_10_1_OFF 1 +#define RV_J_IMM_11_OFF 11 +#define RV_J_IMM_19_12_OFF 12 +#define RV_J_IMM_10_1_MASK GENMASK(9, 0) +#define RV_J_IMM_11_MASK GENMASK(0, 0) +#define RV_J_IMM_19_12_MASK GENMASK(7, 0)/* The bit field of immediate value in B-type instruction */ -#define B_IMM_SIGN_OPOFF 31 -#define B_IMM_10_5_OPOFF 25 -#define B_IMM_4_1_OPOFF 8 -#define B_IMM_11_OPOFF 7 -#define B_IMM_SIGN_OFF 12 -#define B_IMM_10_5_OFF 5 -#define B_IMM_4_1_OFF 1 -#define B_IMM_11_OFF 11 -#define B_IMM_10_5_MASK GENMASK(5, 0) -#define B_IMM_4_1_MASK GENMASK(3, 0) -#define B_IMM_11_MASK GENMASK(0, 0) +#define RV_B_IMM_SIGN_OPOFF 31 +#define RV_B_IMM_10_5_OPOFF 25 +#define RV_B_IMM_4_1_OPOFF 8 +#define RV_B_IMM_11_OPOFF 7 +#define RV_B_IMM_SIGN_OFF 12 +#define RV_B_IMM_10_5_OFF 5 +#define RV_B_IMM_4_1_OFF 1 +#define RV_B_IMM_11_OFF 11 +#define RV_B_IMM_10_5_MASK GENMASK(5, 0) +#define RV_B_IMM_4_1_MASK GENMASK(3, 0) +#define RV_B_IMM_11_MASK GENMASK(0, 0)/* The register offset in RVG instruction */ #define RVG_RS1_OPOFF 15
@@ -100,71 +100,71 @@#define RVC_C2_RD_OPOFF 7/* parts of opcode for RVG*/ -#define OPCODE_BRANCH 0x63 -#define OPCODE_JALR 0x67 -#define OPCODE_JAL 0x6f -#define OPCODE_SYSTEM 0x73 +#define RVG_OPCODE_BRANCH 0x63 +#define RVG_OPCODE_JALR 0x67 +#define RVG_OPCODE_JAL 0x6f +#define RVG_OPCODE_SYSTEM 0x73/* parts of opcode for RVC*/ -#define OPCODE_C_0 0x0 -#define OPCODE_C_1 0x1 -#define OPCODE_C_2 0x2 +#define RVC_OPCODE_C0 0x0 +#define RVC_OPCODE_C1 0x1 +#define RVC_OPCODE_C2 0x2/* parts of funct3 code for I, M, A extension*/ -#define FUNCT3_JALR 0x0 -#define FUNCT3_BEQ 0x0 -#define FUNCT3_BNE 0x1000 -#define FUNCT3_BLT 0x4000 -#define FUNCT3_BGE 0x5000 -#define FUNCT3_BLTU 0x6000 -#define FUNCT3_BGEU 0x7000 +#define RVG_FUNCT3_JALR 0x0 +#define RVG_FUNCT3_BEQ 0x0 +#define RVG_FUNCT3_BNE 0x1000 +#define RVG_FUNCT3_BLT 0x4000 +#define RVG_FUNCT3_BGE 0x5000 +#define RVG_FUNCT3_BLTU 0x6000 +#define RVG_FUNCT3_BGEU 0x7000/* parts of funct3 code for C extension*/ -#define FUNCT3_C_BEQZ 0xc000 -#define FUNCT3_C_BNEZ 0xe000 -#define FUNCT3_C_J 0xa000 -#define FUNCT3_C_JAL 0x2000 -#define FUNCT4_C_JR 0x8000 -#define FUNCT4_C_JALR 0xf000 - -#define FUNCT12_SRET 0x10200000 - -#define MATCH_JALR (FUNCT3_JALR | OPCODE_JALR) -#define MATCH_JAL (OPCODE_JAL) -#define MATCH_BEQ (FUNCT3_BEQ | OPCODE_BRANCH) -#define MATCH_BNE (FUNCT3_BNE | OPCODE_BRANCH) -#define MATCH_BLT (FUNCT3_BLT | OPCODE_BRANCH) -#define MATCH_BGE (FUNCT3_BGE | OPCODE_BRANCH) -#define MATCH_BLTU (FUNCT3_BLTU | OPCODE_BRANCH) -#define MATCH_BGEU (FUNCT3_BGEU | OPCODE_BRANCH) -#define MATCH_SRET (FUNCT12_SRET | OPCODE_SYSTEM) -#define MATCH_C_BEQZ (FUNCT3_C_BEQZ | OPCODE_C_1) -#define MATCH_C_BNEZ (FUNCT3_C_BNEZ | OPCODE_C_1) -#define MATCH_C_J (FUNCT3_C_J | OPCODE_C_1) -#define MATCH_C_JAL (FUNCT3_C_JAL | OPCODE_C_1) -#define MATCH_C_JR (FUNCT4_C_JR | OPCODE_C_2) -#define MATCH_C_JALR (FUNCT4_C_JALR | OPCODE_C_2) - -#define MASK_JALR 0x707f -#define MASK_JAL 0x7f -#define MASK_C_JALR 0xf07f -#define MASK_C_JR 0xf07f -#define MASK_C_JAL 0xe003 -#define MASK_C_J 0xe003 -#define MASK_BEQ 0x707f -#define MASK_BNE 0x707f -#define MASK_BLT 0x707f -#define MASK_BGE 0x707f -#define MASK_BLTU 0x707f -#define MASK_BGEU 0x707f -#define MASK_C_BEQZ 0xe003 -#define MASK_C_BNEZ 0xe003 -#define MASK_SRET 0xffffffff +#define RVC_FUNCT3_C_BEQZ 0xc000 +#define RVC_FUNCT3_C_BNEZ 0xe000 +#define RVC_FUNCT3_C_J 0xa000 +#define RVC_FUNCT3_C_JAL 0x2000 +#define RVC_FUNCT4_C_JR 0x8000 +#define RVC_FUNCT4_C_JALR 0xf000 + +#define RVG_FUNCT12_SRET 0x10200000 + +#define RVG_MATCH_JALR (RVG_FUNCT3_JALR | RVG_OPCODE_JALR) +#define RVG_MATCH_JAL (RVG_OPCODE_JAL) +#define RVG_MATCH_BEQ (RVG_FUNCT3_BEQ | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BNE (RVG_FUNCT3_BNE | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BLT (RVG_FUNCT3_BLT | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BGE (RVG_FUNCT3_BGE | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BLTU (RVG_FUNCT3_BLTU | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BGEU (RVG_FUNCT3_BGEU | RVG_OPCODE_BRANCH) +#define RVG_MATCH_SRET (RVG_FUNCT12_SRET | RVG_OPCODE_SYSTEM) +#define RVC_MATCH_C_BEQZ (RVC_FUNCT3_C_BEQZ | RVC_OPCODE_C1) +#define RVC_MATCH_C_BNEZ (RVC_FUNCT3_C_BNEZ | RVC_OPCODE_C1) +#define RVC_MATCH_C_J (RVC_FUNCT3_C_J | RVC_OPCODE_C1) +#define RVC_MATCH_C_JAL (RVC_FUNCT3_C_JAL | RVC_OPCODE_C1) +#define RVC_MATCH_C_JR (RVC_FUNCT4_C_JR | RVC_OPCODE_C2) +#define RVC_MATCH_C_JALR (RVC_FUNCT4_C_JALR | RVC_OPCODE_C2) + +#define RVG_MASK_JALR 0x707f +#define RVG_MASK_JAL 0x7f +#define RVC_MASK_C_JALR 0xf07f +#define RVC_MASK_C_JR 0xf07f +#define RVC_MASK_C_JAL 0xe003 +#define RVC_MASK_C_J 0xe003 +#define RVG_MASK_BEQ 0x707f +#define RVG_MASK_BNE 0x707f +#define RVG_MASK_BLT 0x707f +#define RVG_MASK_BGE 0x707f +#define RVG_MASK_BLTU 0x707f +#define RVG_MASK_BGEU 0x707f +#define RVC_MASK_C_BEQZ 0xe003 +#define RVC_MASK_C_BNEZ 0xe003 +#define RVG_MASK_SRET 0xffffffff#define __INSN_LENGTH_MASK _UL(0x3)#define __INSN_LENGTH_GE_32 _UL(0x3)#define __INSN_OPCODE_MASK _UL(0x7F) -#define __INSN_BRANCH_OPCODE _UL(OPCODE_BRANCH) +#define __INSN_BRANCH_OPCODE _UL(RVG_OPCODE_BRANCH)/* Define a series of is_XXX_insn functions to check if the value INSN * is an instance of instruction XXX.
@@ -180,26 +180,26 @@ static inline bool is_ ## INSN_NAME ## _insn(long insn) \#define RV_X (X , s, mask) (((X) >> (s)) & (mask))#define RVC_X (X , s, mask) RV_X(X, s, mask) -#define EXTRACT_JTYPE_IMM (x) \ +#define RV_EXTRACT_JTYPE_IMM (x) \ ({typeof(x) x_ = (x); \ - (RV_X(x_, J_IMM_10_1_OPOFF, J_IMM_10_1_MASK) << J_IMM_10_1_OFF) | \ - (RV_X(x_, J_IMM_11_OPOFF, J_IMM_11_MASK) << J_IMM_11_OFF) | \ - (RV_X(x_, J_IMM_19_12_OPOFF, J_IMM_19_12_MASK) << J_IMM_19_12_OFF) | \ - (RV_IMM_SIGN(x_) << J_IMM_SIGN_OFF); }) + (RV_X(x_, RV_J_IMM_10_1_OPOFF, RV_J_IMM_10_1_MASK) << RV_J_IMM_10_1_OFF) | \ + (RV_X(x_, RV_J_IMM_11_OPOFF, RV_J_IMM_11_MASK) << RV_J_IMM_11_OFF) | \ + (RV_X(x_, RV_J_IMM_19_12_OPOFF, RV_J_IMM_19_12_MASK) << RV_J_IMM_19_12_OFF) | \ + (RV_IMM_SIGN(x_) << RV_J_IMM_SIGN_OFF); }) -#define EXTRACT_ITYPE_IMM (x) \ +#define RV_EXTRACT_ITYPE_IMM (x) \ ({typeof(x) x_ = (x); \ - (RV_X(x_, I_IMM_11_0_OPOFF, I_IMM_11_0_MASK)) | \ - (RV_IMM_SIGN(x_) << I_IMM_SIGN_OFF); }) + (RV_X(x_, RV_I_IMM_11_0_OPOFF, RV_I_IMM_11_0_MASK)) | \ + (RV_IMM_SIGN(x_) << RV_I_IMM_SIGN_OFF); }) -#define EXTRACT_BTYPE_IMM (x) \ +#define RV_EXTRACT_BTYPE_IMM (x) \ ({typeof(x) x_ = (x); \ - (RV_X(x_, B_IMM_4_1_OPOFF, B_IMM_4_1_MASK) << B_IMM_4_1_OFF) | \ - (RV_X(x_, B_IMM_10_5_OPOFF, B_IMM_10_5_MASK) << B_IMM_10_5_OFF) | \ - (RV_X(x_, B_IMM_11_OPOFF, B_IMM_11_MASK) << B_IMM_11_OFF) | \ - (RV_IMM_SIGN(x_) << B_IMM_SIGN_OFF); }) + (RV_X(x_, RV_B_IMM_4_1_OPOFF, RV_B_IMM_4_1_MASK) << RV_B_IMM_4_1_OFF) | \ + (RV_X(x_, RV_B_IMM_10_5_OPOFF, RV_B_IMM_10_5_MASK) << RV_B_IMM_10_5_OFF) | \ + (RV_X(x_, RV_B_IMM_11_OPOFF, RV_B_IMM_11_MASK) << RV_B_IMM_11_OFF) | \ + (RV_IMM_SIGN(x_) << RV_B_IMM_SIGN_OFF); }) -#define EXTRACT_RVC_J_IMM (x) \ +#define RVC_EXTRACT_JTYPE_IMM (x) \ ({typeof(x) x_ = (x); \ (RVC_X(x_, RVC_J_IMM_3_1_OPOFF, RVC_J_IMM_3_1_MASK) << RVC_J_IMM_3_1_OFF) | \ (RVC_X(x_, RVC_J_IMM_4_OPOFF, RVC_J_IMM_4_MASK) << RVC_J_IMM_4_OFF) | \
@@ -210,7 +210,7 @@ static inline bool is_ ## INSN_NAME ## _insn(long insn) \ (RVC_X (x_,RVC_J_IMM_10_OPOFF ,RVC_J_IMM_10_MASK ) <<RVC_J_IMM_10_OFF ) | \ (RVC_IMM_SIGN(x_) << RVC_J_IMM_SIGN_OFF); }) -#define EXTRACT_RVC_B_IMM (x) \ +#define RVC_EXTRACT_BTYPE_IMM (x) \ ({typeof(x) x_ = (x); \ (RVC_X(x_, RVC_B_IMM_2_1_OPOFF, RVC_B_IMM_2_1_MASK) << RVC_B_IMM_2_1_OFF) | \ (RVC_X(x_, RVC_B_IMM_4_3_OPOFF, RVC_B_IMM_4_3_MASK) << RVC_B_IMM_4_3_OFF) | \
arch/riscv/kernel/kgdb.c +6 -6
@@ -69,19 +69,19 @@ static int get_step_address(struct pt_regs *regs, unsigned long *next_addr) rs1_num =decode_register_index (op_code,RVC_C2_RS1_OPOFF ); *next_addr = regs_ptr[rs1_num]; }else if (is_c_j_insn (op_code) ||is_c_jal_insn (op_code)) { - *next_addr =EXTRACT_RVC_J_IMM (op_code) + pc; + *next_addr =RVC_EXTRACT_JTYPE_IMM (op_code) + pc; }else if (is_c_beqz_insn (op_code)) { rs1_num =decode_register_index_short (op_code,RVC_C1_RS1_OPOFF );if (!rs1_num || regs_ptr[rs1_num] ==0 ) - *next_addr =EXTRACT_RVC_B_IMM (op_code) + pc; + *next_addr =RVC_EXTRACT_BTYPE_IMM (op_code) + pc;else *next_addr = pc +2 ; }else if (is_c_bnez_insn (op_code)) { rs1_num =decode_register_index_short (op_code,RVC_C1_RS1_OPOFF );if (rs1_num && regs_ptr[rs1_num] !=0 ) - *next_addr =EXTRACT_RVC_B_IMM (op_code) + pc; + *next_addr =RVC_EXTRACT_BTYPE_IMM (op_code) + pc;else *next_addr = pc +2 ; }else {
@@ -90,7 +90,7 @@ static int get_step_address(struct pt_regs *regs, unsigned long *next_addr) }else {if ((op_code & __INSN_OPCODE_MASK) == __INSN_BRANCH_OPCODE) {bool result = false; -long imm =EXTRACT_BTYPE_IMM (op_code); +long imm =RV_EXTRACT_BTYPE_IMM (op_code);unsigned long rs1_val =0 , rs2_val =0 ; rs1_num =decode_register_index (op_code,RVG_RS1_OPOFF );
@@ -121,12 +121,12 @@ static int get_step_address(struct pt_regs *regs, unsigned long *next_addr)else *next_addr = pc +4 ; }else if (is_jal_insn (op_code)) { - *next_addr =EXTRACT_JTYPE_IMM (op_code) + pc; + *next_addr =RV_EXTRACT_JTYPE_IMM (op_code) + pc; }else if (is_jalr_insn (op_code)) { rs1_num =decode_register_index (op_code,RVG_RS1_OPOFF );if (rs1_num) *next_addr = ((unsigned long *)regs)[rs1_num]; - *next_addr +=EXTRACT_ITYPE_IMM (op_code); + *next_addr +=RV_EXTRACT_ITYPE_IMM (op_code); }else if (is_sret_insn (op_code)) { *next_addr = pc; }else {
Signature · 7 lines
2.35.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 01/13] RISC-V: add prefix to all constants/macros in parse_asm.h
Quoted 7 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
Some of the constants and macros already have suitable
RV_,RVG_orRVC_prefixes.Extend this to the rest of the file as well, as we want to use these things in a broader scope soon.
What's up with the "weird" 57 character lines here?
Either way, I hate these sort of diffs and my brain just switches off while trying to read them. Perhaps there's a way to make git spit these out that shows
-
+
-
+
rather than
-
-
+
+
and I could be more confident, but it seems okay to me...
Quoted 307 lines
Signed-off-by Heiko Stuebner <[email protected]>--- arch/riscv/include/asm/parse_asm.h | 194 ++++++++++++++--------------- arch/riscv/kernel/kgdb.c | 12 +- 2 files changed, 103 insertions(+), 103 deletions(-)arch/riscv/include/asm/parse_asm.h +97
-97@@ -6,37 +6,37 @@#include <linux/bits.h> /* The bit field of immediate value in I-type instruction */ -#define I_IMM_SIGN_OPOFF 31 -#define I_IMM_11_0_OPOFF 20 -#define I_IMM_SIGN_OFF 12 -#define I_IMM_11_0_OFF 0 -#define I_IMM_11_0_MASK GENMASK(11, 0) +#define RV_I_IMM_SIGN_OPOFF 31 +#define RV_I_IMM_11_0_OPOFF 20 +#define RV_I_IMM_SIGN_OFF 12 +#define RV_I_IMM_11_0_OFF 0 +#define RV_I_IMM_11_0_MASK GENMASK(11, 0)/* The bit field of immediate value in J-type instruction */ -#define J_IMM_SIGN_OPOFF 31 -#define J_IMM_10_1_OPOFF 21 -#define J_IMM_11_OPOFF 20 -#define J_IMM_19_12_OPOFF 12 -#define J_IMM_SIGN_OFF 20 -#define J_IMM_10_1_OFF 1 -#define J_IMM_11_OFF 11 -#define J_IMM_19_12_OFF 12 -#define J_IMM_10_1_MASK GENMASK(9, 0) -#define J_IMM_11_MASK GENMASK(0, 0) -#define J_IMM_19_12_MASK GENMASK(7, 0) +#define RV_J_IMM_SIGN_OPOFF 31 +#define RV_J_IMM_10_1_OPOFF 21 +#define RV_J_IMM_11_OPOFF 20 +#define RV_J_IMM_19_12_OPOFF 12 +#define RV_J_IMM_SIGN_OFF 20 +#define RV_J_IMM_10_1_OFF 1 +#define RV_J_IMM_11_OFF 11 +#define RV_J_IMM_19_12_OFF 12 +#define RV_J_IMM_10_1_MASK GENMASK(9, 0) +#define RV_J_IMM_11_MASK GENMASK(0, 0) +#define RV_J_IMM_19_12_MASK GENMASK(7, 0)/* The bit field of immediate value in B-type instruction */ -#define B_IMM_SIGN_OPOFF 31 -#define B_IMM_10_5_OPOFF 25 -#define B_IMM_4_1_OPOFF 8 -#define B_IMM_11_OPOFF 7 -#define B_IMM_SIGN_OFF 12 -#define B_IMM_10_5_OFF 5 -#define B_IMM_4_1_OFF 1 -#define B_IMM_11_OFF 11 -#define B_IMM_10_5_MASK GENMASK(5, 0) -#define B_IMM_4_1_MASK GENMASK(3, 0) -#define B_IMM_11_MASK GENMASK(0, 0) +#define RV_B_IMM_SIGN_OPOFF 31 +#define RV_B_IMM_10_5_OPOFF 25 +#define RV_B_IMM_4_1_OPOFF 8 +#define RV_B_IMM_11_OPOFF 7 +#define RV_B_IMM_SIGN_OFF 12 +#define RV_B_IMM_10_5_OFF 5 +#define RV_B_IMM_4_1_OFF 1 +#define RV_B_IMM_11_OFF 11 +#define RV_B_IMM_10_5_MASK GENMASK(5, 0) +#define RV_B_IMM_4_1_MASK GENMASK(3, 0) +#define RV_B_IMM_11_MASK GENMASK(0, 0)/* The register offset in RVG instruction */ #define RVG_RS1_OPOFF 15@@ -100,71 +100,71 @@#define RVC_C2_RD_OPOFF 7/* parts of opcode for RVG*/ -#define OPCODE_BRANCH 0x63 -#define OPCODE_JALR 0x67 -#define OPCODE_JAL 0x6f -#define OPCODE_SYSTEM 0x73 +#define RVG_OPCODE_BRANCH 0x63 +#define RVG_OPCODE_JALR 0x67 +#define RVG_OPCODE_JAL 0x6f +#define RVG_OPCODE_SYSTEM 0x73/* parts of opcode for RVC*/ -#define OPCODE_C_0 0x0 -#define OPCODE_C_1 0x1 -#define OPCODE_C_2 0x2 +#define RVC_OPCODE_C0 0x0 +#define RVC_OPCODE_C1 0x1 +#define RVC_OPCODE_C2 0x2/* parts of funct3 code for I, M, A extension*/ -#define FUNCT3_JALR 0x0 -#define FUNCT3_BEQ 0x0 -#define FUNCT3_BNE 0x1000 -#define FUNCT3_BLT 0x4000 -#define FUNCT3_BGE 0x5000 -#define FUNCT3_BLTU 0x6000 -#define FUNCT3_BGEU 0x7000 +#define RVG_FUNCT3_JALR 0x0 +#define RVG_FUNCT3_BEQ 0x0 +#define RVG_FUNCT3_BNE 0x1000 +#define RVG_FUNCT3_BLT 0x4000 +#define RVG_FUNCT3_BGE 0x5000 +#define RVG_FUNCT3_BLTU 0x6000 +#define RVG_FUNCT3_BGEU 0x7000/* parts of funct3 code for C extension*/ -#define FUNCT3_C_BEQZ 0xc000 -#define FUNCT3_C_BNEZ 0xe000 -#define FUNCT3_C_J 0xa000 -#define FUNCT3_C_JAL 0x2000 -#define FUNCT4_C_JR 0x8000 -#define FUNCT4_C_JALR 0xf000 - -#define FUNCT12_SRET 0x10200000 - -#define MATCH_JALR (FUNCT3_JALR | OPCODE_JALR) -#define MATCH_JAL (OPCODE_JAL) -#define MATCH_BEQ (FUNCT3_BEQ | OPCODE_BRANCH) -#define MATCH_BNE (FUNCT3_BNE | OPCODE_BRANCH) -#define MATCH_BLT (FUNCT3_BLT | OPCODE_BRANCH) -#define MATCH_BGE (FUNCT3_BGE | OPCODE_BRANCH) -#define MATCH_BLTU (FUNCT3_BLTU | OPCODE_BRANCH) -#define MATCH_BGEU (FUNCT3_BGEU | OPCODE_BRANCH) -#define MATCH_SRET (FUNCT12_SRET | OPCODE_SYSTEM) -#define MATCH_C_BEQZ (FUNCT3_C_BEQZ | OPCODE_C_1) -#define MATCH_C_BNEZ (FUNCT3_C_BNEZ | OPCODE_C_1) -#define MATCH_C_J (FUNCT3_C_J | OPCODE_C_1) -#define MATCH_C_JAL (FUNCT3_C_JAL | OPCODE_C_1) -#define MATCH_C_JR (FUNCT4_C_JR | OPCODE_C_2) -#define MATCH_C_JALR (FUNCT4_C_JALR | OPCODE_C_2) - -#define MASK_JALR 0x707f -#define MASK_JAL 0x7f -#define MASK_C_JALR 0xf07f -#define MASK_C_JR 0xf07f -#define MASK_C_JAL 0xe003 -#define MASK_C_J 0xe003 -#define MASK_BEQ 0x707f -#define MASK_BNE 0x707f -#define MASK_BLT 0x707f -#define MASK_BGE 0x707f -#define MASK_BLTU 0x707f -#define MASK_BGEU 0x707f -#define MASK_C_BEQZ 0xe003 -#define MASK_C_BNEZ 0xe003 -#define MASK_SRET 0xffffffff +#define RVC_FUNCT3_C_BEQZ 0xc000 +#define RVC_FUNCT3_C_BNEZ 0xe000 +#define RVC_FUNCT3_C_J 0xa000 +#define RVC_FUNCT3_C_JAL 0x2000 +#define RVC_FUNCT4_C_JR 0x8000 +#define RVC_FUNCT4_C_JALR 0xf000 + +#define RVG_FUNCT12_SRET 0x10200000 + +#define RVG_MATCH_JALR (RVG_FUNCT3_JALR | RVG_OPCODE_JALR) +#define RVG_MATCH_JAL (RVG_OPCODE_JAL) +#define RVG_MATCH_BEQ (RVG_FUNCT3_BEQ | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BNE (RVG_FUNCT3_BNE | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BLT (RVG_FUNCT3_BLT | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BGE (RVG_FUNCT3_BGE | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BLTU (RVG_FUNCT3_BLTU | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BGEU (RVG_FUNCT3_BGEU | RVG_OPCODE_BRANCH) +#define RVG_MATCH_SRET (RVG_FUNCT12_SRET | RVG_OPCODE_SYSTEM) +#define RVC_MATCH_C_BEQZ (RVC_FUNCT3_C_BEQZ | RVC_OPCODE_C1) +#define RVC_MATCH_C_BNEZ (RVC_FUNCT3_C_BNEZ | RVC_OPCODE_C1) +#define RVC_MATCH_C_J (RVC_FUNCT3_C_J | RVC_OPCODE_C1) +#define RVC_MATCH_C_JAL (RVC_FUNCT3_C_JAL | RVC_OPCODE_C1) +#define RVC_MATCH_C_JR (RVC_FUNCT4_C_JR | RVC_OPCODE_C2) +#define RVC_MATCH_C_JALR (RVC_FUNCT4_C_JALR | RVC_OPCODE_C2) + +#define RVG_MASK_JALR 0x707f +#define RVG_MASK_JAL 0x7f +#define RVC_MASK_C_JALR 0xf07f +#define RVC_MASK_C_JR 0xf07f +#define RVC_MASK_C_JAL 0xe003 +#define RVC_MASK_C_J 0xe003 +#define RVG_MASK_BEQ 0x707f +#define RVG_MASK_BNE 0x707f +#define RVG_MASK_BLT 0x707f +#define RVG_MASK_BGE 0x707f +#define RVG_MASK_BLTU 0x707f +#define RVG_MASK_BGEU 0x707f +#define RVC_MASK_C_BEQZ 0xe003 +#define RVC_MASK_C_BNEZ 0xe003 +#define RVG_MASK_SRET 0xffffffff#define __INSN_LENGTH_MASK _UL(0x3)#define __INSN_LENGTH_GE_32 _UL(0x3)#define __INSN_OPCODE_MASK _UL(0x7F) -#define __INSN_BRANCH_OPCODE _UL(OPCODE_BRANCH) +#define __INSN_BRANCH_OPCODE _UL(RVG_OPCODE_BRANCH)/* Define a series of is_XXX_insn functions to check if the value INSN * is an instance of instruction XXX. @@ -180,26 +180,26 @@ static inline bool is_ ## INSN_NAME ## _insn(long insn) \#define RV_X (X , s, mask) (((X) >> (s)) & (mask))#define RVC_X (X , s, mask) RV_X(X, s, mask) -#define EXTRACT_JTYPE_IMM (x) \ +#define RV_EXTRACT_JTYPE_IMM (x) \ ({typeof(x) x_ = (x); \ - (RV_X(x_, J_IMM_10_1_OPOFF, J_IMM_10_1_MASK) << J_IMM_10_1_OFF) | \ - (RV_X(x_, J_IMM_11_OPOFF, J_IMM_11_MASK) << J_IMM_11_OFF) | \ - (RV_X(x_, J_IMM_19_12_OPOFF, J_IMM_19_12_MASK) << J_IMM_19_12_OFF) | \ - (RV_IMM_SIGN(x_) << J_IMM_SIGN_OFF); }) + (RV_X(x_, RV_J_IMM_10_1_OPOFF, RV_J_IMM_10_1_MASK) << RV_J_IMM_10_1_OFF) | \ + (RV_X(x_, RV_J_IMM_11_OPOFF, RV_J_IMM_11_MASK) << RV_J_IMM_11_OFF) | \ + (RV_X(x_, RV_J_IMM_19_12_OPOFF, RV_J_IMM_19_12_MASK) << RV_J_IMM_19_12_OFF) | \ + (RV_IMM_SIGN(x_) << RV_J_IMM_SIGN_OFF); }) -#define EXTRACT_ITYPE_IMM (x) \ +#define RV_EXTRACT_ITYPE_IMM (x) \ ({typeof(x) x_ = (x); \ - (RV_X(x_, I_IMM_11_0_OPOFF, I_IMM_11_0_MASK)) | \ - (RV_IMM_SIGN(x_) << I_IMM_SIGN_OFF); }) + (RV_X(x_, RV_I_IMM_11_0_OPOFF, RV_I_IMM_11_0_MASK)) | \ + (RV_IMM_SIGN(x_) << RV_I_IMM_SIGN_OFF); }) -#define EXTRACT_BTYPE_IMM (x) \ +#define RV_EXTRACT_BTYPE_IMM (x) \ ({typeof(x) x_ = (x); \ - (RV_X(x_, B_IMM_4_1_OPOFF, B_IMM_4_1_MASK) << B_IMM_4_1_OFF) | \ - (RV_X(x_, B_IMM_10_5_OPOFF, B_IMM_10_5_MASK) << B_IMM_10_5_OFF) | \ - (RV_X(x_, B_IMM_11_OPOFF, B_IMM_11_MASK) << B_IMM_11_OFF) | \ - (RV_IMM_SIGN(x_) << B_IMM_SIGN_OFF); }) + (RV_X(x_, RV_B_IMM_4_1_OPOFF, RV_B_IMM_4_1_MASK) << RV_B_IMM_4_1_OFF) | \ + (RV_X(x_, RV_B_IMM_10_5_OPOFF, RV_B_IMM_10_5_MASK) << RV_B_IMM_10_5_OFF) | \ + (RV_X(x_, RV_B_IMM_11_OPOFF, RV_B_IMM_11_MASK) << RV_B_IMM_11_OFF) | \ + (RV_IMM_SIGN(x_) << RV_B_IMM_SIGN_OFF); }) -#define EXTRACT_RVC_J_IMM (x) \ +#define RVC_EXTRACT_JTYPE_IMM (x) \ ({typeof(x) x_ = (x); \ (RVC_X(x_, RVC_J_IMM_3_1_OPOFF, RVC_J_IMM_3_1_MASK) << RVC_J_IMM_3_1_OFF) | \ (RVC_X(x_, RVC_J_IMM_4_OPOFF, RVC_J_IMM_4_MASK) << RVC_J_IMM_4_OFF) | \@@ -210,7 +210,7 @@ static inline bool is_ ## INSN_NAME ## _insn(long insn) \ (RVC_X (x_,RVC_J_IMM_10_OPOFF ,RVC_J_IMM_10_MASK ) <<RVC_J_IMM_10_OFF ) | \ (RVC_IMM_SIGN(x_) << RVC_J_IMM_SIGN_OFF); }) -#define EXTRACT_RVC_B_IMM (x) \ +#define RVC_EXTRACT_BTYPE_IMM (x) \ ({typeof(x) x_ = (x); \ (RVC_X(x_, RVC_B_IMM_2_1_OPOFF, RVC_B_IMM_2_1_MASK) << RVC_B_IMM_2_1_OFF) | \ (RVC_X(x_, RVC_B_IMM_4_3_OPOFF, RVC_B_IMM_4_3_MASK) << RVC_B_IMM_4_3_OFF) | \arch/riscv/kernel/kgdb.c +6
-6@@ -69,19 +69,19 @@ static int get_step_address(struct pt_regs *regs, unsigned long *next_addr) rs1_num =decode_register_index (op_code,RVC_C2_RS1_OPOFF ); *next_addr = regs_ptr[rs1_num]; }else if (is_c_j_insn (op_code) ||is_c_jal_insn (op_code)) { - *next_addr =EXTRACT_RVC_J_IMM (op_code) + pc; + *next_addr =RVC_EXTRACT_JTYPE_IMM (op_code) + pc; }else if (is_c_beqz_insn (op_code)) { rs1_num =decode_register_index_short (op_code,RVC_C1_RS1_OPOFF );if (!rs1_num || regs_ptr[rs1_num] ==0 ) - *next_addr =EXTRACT_RVC_B_IMM (op_code) + pc; + *next_addr =RVC_EXTRACT_BTYPE_IMM (op_code) + pc;else *next_addr = pc +2 ; }else if (is_c_bnez_insn (op_code)) { rs1_num =decode_register_index_short (op_code,RVC_C1_RS1_OPOFF );if (rs1_num && regs_ptr[rs1_num] !=0 ) - *next_addr =EXTRACT_RVC_B_IMM (op_code) + pc; + *next_addr =RVC_EXTRACT_BTYPE_IMM (op_code) + pc;else *next_addr = pc +2 ; }else {@@ -90,7 +90,7 @@ static int get_step_address(struct pt_regs *regs, unsigned long *next_addr) }else {if ((op_code & __INSN_OPCODE_MASK) == __INSN_BRANCH_OPCODE) {bool result = false; -long imm =EXTRACT_BTYPE_IMM (op_code); +long imm =RV_EXTRACT_BTYPE_IMM (op_code);unsigned long rs1_val =0 , rs2_val =0 ; rs1_num =decode_register_index (op_code,RVG_RS1_OPOFF );@@ -121,12 +121,12 @@ static int get_step_address(struct pt_regs *regs, unsigned long *next_addr)else *next_addr = pc +4 ; }else if (is_jal_insn (op_code)) { - *next_addr =EXTRACT_JTYPE_IMM (op_code) + pc; + *next_addr =RV_EXTRACT_JTYPE_IMM (op_code) + pc; }else if (is_jalr_insn (op_code)) { rs1_num =decode_register_index (op_code,RVG_RS1_OPOFF );if (rs1_num) *next_addr = ((unsigned long *)regs)[rs1_num]; - *next_addr +=EXTRACT_ITYPE_IMM (op_code); + *next_addr +=RV_EXTRACT_ITYPE_IMM (op_code); }else if (is_sret_insn (op_code)) { *next_addr = pc; }else {Signature · 1 line
2.35.1
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 01/13] RISC-V: add prefix to all constants/macros in parse_asm.h
Am Dienstag, 29. November 2022, 23:19:57 CET schrieb Conor Dooley:
Quoted 10 lines · Heiko Stuebner
Quoted 7 lines
From: Heiko Stuebner <[email protected]>
Some of the constants and macros already have suitable
RV_,RVG_orRVC_prefixes.Extend this to the rest of the file as well, as we want to use these things in a broader scope soon.
What's up with the "weird" 57 character lines here?
that is my brain shouting "you need to wrap lines" too early. I did make them longer now, but the line count won't change :-) .
arch/riscv/include/asm/parse_asm.h line 131
Quoted 12 lines
Either way, I hate these sort of diffs and my brain just switches off while trying to read them. Perhaps there's a way to make git spit these out that shows
arch/riscv/include/asm/parse_asm.h +2
-2- + - +rather than
arch/riscv/include/asm/parse_asm.h +2
-2- - + +
I know that feeling well :-)
Quoted 2 lines
and I could be more confident, but it seems okay to me...
Reviewed-by Conor Dooley <[email protected]>
thanks
Heiko
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Andrew Jones
Reviewed-byRe: [PATCH v2 01/13] RISC-V: add prefix to all constants/macros in parse_asm.h
Quoted 16 lines · Heiko Stübner
Am Dienstag, 29. November 2022, 23:19:57 CET schrieb Conor Dooley:
Quoted 10 lines · Heiko Stuebner
Quoted 7 lines
From: Heiko Stuebner <[email protected]>
Some of the constants and macros already have suitable
RV_,RVG_orRVC_prefixes.Extend this to the rest of the file as well, as we want to use these things in a broader scope soon.
What's up with the "weird" 57 character lines here?
that is my brain shouting "you need to wrap lines" too early. I did make them longer now, but the line count won't change :-) .
Quoted 14 lines
arch/riscv/include/asm/parse_asm.h line 131
Quoted 12 lines
Either way, I hate these sort of diffs and my brain just switches off while trying to read them. Perhaps there's a way to make git spit these out that shows
arch/riscv/include/asm/parse_asm.h +2
-2- + - +rather than
arch/riscv/include/asm/parse_asm.h +2
-2- - + +I know that feeling well :-)
After b4'ing the patch into git, you can do
git show --word-diff=color --word-diff-regex=. <patch-commit-id>
to see just what was added/removed.
Doing that, plus some greps to make sure all names got changed everywhere, looks good to me.
Thanks,
drew
Quoted 11 lines
Quoted 4 lines
and I could be more confident, but it seems okay to me...
Reviewed-by Conor Dooley <[email protected]>thanks
Heiko
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v2 2/13 RISC-V: detach funct-values from their offset
In reply to Heiko StuebnerFrom: Heiko Stuebner <[email protected]>
Only carry the actual values for the funct3, funct4, etc instruction fields without directly including the shift to the target position.
Instead use macros to move the values to their target positions when needed.
This at the same time also reduces the use of magic numbers, one would need a spec manual to understand.
--- arch/riscv/include/asm/parse_asm.h | 100 +++++++++++++++++------------ 1 file changed, 59 insertions(+), 41 deletions(-)
arch/riscv/include/asm/parse_asm.h +59 -41
@@ -5,6 +5,15 @@#include <linux/bits.h> +#define RV_INSN_FUNCT3_MASK GENMASK(14, 12) +#define RV_INSN_FUNCT3_OPOFF 12 +#define RV_INSN_OPCODE_MASK GENMASK(6, 0) +#define RV_INSN_OPCODE_OPOFF 0 +#define RV_INSN_FUNCT12_OPOFF 20 + +#define RV_ENCODE_FUNCT3 (f_) (RVG_FUNCT3_##f_ << RV_INSN_FUNCT3_OPOFF) +#define RV_ENCODE_FUNCT12 (f_) (RVG_FUNCT12_##f_ << RV_INSN_FUNCT12_OPOFF) +/* The bit field of immediate value in I-type instruction */ #define RV_I_IMM_SIGN_OPOFF 31#define RV_I_IMM_11_0_OPOFF 20
@@ -84,6 +93,15 @@#define RVC_B_IMM_2_1_MASK GENMASK(1, 0)#define RVC_B_IMM_5_MASK GENMASK(0, 0) +#define RVC_INSN_FUNCT4_MASK GENMASK(15, 12) +#define RVC_INSN_FUNCT4_OPOFF 12 +#define RVC_INSN_FUNCT3_MASK GENMASK(15, 13) +#define RVC_INSN_FUNCT3_OPOFF 13 +#define RVC_INSN_J_RS2_MASK GENMASK(6, 2) +#define RVC_INSN_OPCODE_MASK GENMASK(1, 0) +#define RVC_ENCODE_FUNCT3 (f_) (RVC_FUNCT3_##f_ << RVC_INSN_FUNCT3_OPOFF) +#define RVC_ENCODE_FUNCT4 (f_) (RVC_FUNCT4_##f_ << RVC_INSN_FUNCT4_OPOFF) +/* The register offset in RVC op=C0 instruction */ #define RVC_C0_RS1_OPOFF 7#define RVC_C0_RS2_OPOFF 2
@@ -113,52 +131,52 @@/* parts of funct3 code for I, M, A extension*/ #define RVG_FUNCT3_JALR 0x0#define RVG_FUNCT3_BEQ 0x0 -#define RVG_FUNCT3_BNE 0x1000 -#define RVG_FUNCT3_BLT 0x4000 -#define RVG_FUNCT3_BGE 0x5000 -#define RVG_FUNCT3_BLTU 0x6000 -#define RVG_FUNCT3_BGEU 0x7000 +#define RVG_FUNCT3_BNE 0x1 +#define RVG_FUNCT3_BLT 0x4 +#define RVG_FUNCT3_BGE 0x5 +#define RVG_FUNCT3_BLTU 0x6 +#define RVG_FUNCT3_BGEU 0x7/* parts of funct3 code for C extension*/ -#define RVC_FUNCT3_C_BEQZ 0xc000 -#define RVC_FUNCT3_C_BNEZ 0xe000 -#define RVC_FUNCT3_C_J 0xa000 -#define RVC_FUNCT3_C_JAL 0x2000 -#define RVC_FUNCT4_C_JR 0x8000 -#define RVC_FUNCT4_C_JALR 0xf000 +#define RVC_FUNCT3_C_BEQZ 0x6 +#define RVC_FUNCT3_C_BNEZ 0x7 +#define RVC_FUNCT3_C_J 0x5 +#define RVC_FUNCT3_C_JAL 0x1 +#define RVC_FUNCT4_C_JR 0x8 +#define RVC_FUNCT4_C_JALR 0x9 -#define RVG_FUNCT12_SRET 0x10200000 +#define RVG_FUNCT12_SRET 0x102 -#define RVG_MATCH_JALR (RVG_FUNCT3_JALR | RVG_OPCODE_JALR) +#define RVG_MATCH_JALR (RV_ENCODE_FUNCT3(JALR) | RVG_OPCODE_JALR)#define RVG_MATCH_JAL (RVG_OPCODE_JAL) -#define RVG_MATCH_BEQ (RVG_FUNCT3_BEQ | RVG_OPCODE_BRANCH) -#define RVG_MATCH_BNE (RVG_FUNCT3_BNE | RVG_OPCODE_BRANCH) -#define RVG_MATCH_BLT (RVG_FUNCT3_BLT | RVG_OPCODE_BRANCH) -#define RVG_MATCH_BGE (RVG_FUNCT3_BGE | RVG_OPCODE_BRANCH) -#define RVG_MATCH_BLTU (RVG_FUNCT3_BLTU | RVG_OPCODE_BRANCH) -#define RVG_MATCH_BGEU (RVG_FUNCT3_BGEU | RVG_OPCODE_BRANCH) -#define RVG_MATCH_SRET (RVG_FUNCT12_SRET | RVG_OPCODE_SYSTEM) -#define RVC_MATCH_C_BEQZ (RVC_FUNCT3_C_BEQZ | RVC_OPCODE_C1) -#define RVC_MATCH_C_BNEZ (RVC_FUNCT3_C_BNEZ | RVC_OPCODE_C1) -#define RVC_MATCH_C_J (RVC_FUNCT3_C_J | RVC_OPCODE_C1) -#define RVC_MATCH_C_JAL (RVC_FUNCT3_C_JAL | RVC_OPCODE_C1) -#define RVC_MATCH_C_JR (RVC_FUNCT4_C_JR | RVC_OPCODE_C2) -#define RVC_MATCH_C_JALR (RVC_FUNCT4_C_JALR | RVC_OPCODE_C2) - -#define RVG_MASK_JALR 0x707f -#define RVG_MASK_JAL 0x7f -#define RVC_MASK_C_JALR 0xf07f -#define RVC_MASK_C_JR 0xf07f -#define RVC_MASK_C_JAL 0xe003 -#define RVC_MASK_C_J 0xe003 -#define RVG_MASK_BEQ 0x707f -#define RVG_MASK_BNE 0x707f -#define RVG_MASK_BLT 0x707f -#define RVG_MASK_BGE 0x707f -#define RVG_MASK_BLTU 0x707f -#define RVG_MASK_BGEU 0x707f -#define RVC_MASK_C_BEQZ 0xe003 -#define RVC_MASK_C_BNEZ 0xe003 +#define RVG_MATCH_BEQ (RV_ENCODE_FUNCT3(BEQ) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BNE (RV_ENCODE_FUNCT3(BNE) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BLT (RV_ENCODE_FUNCT3(BLT) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BGE (RV_ENCODE_FUNCT3(BGE) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BLTU (RV_ENCODE_FUNCT3(BLTU) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BGEU (RV_ENCODE_FUNCT3(BGEU) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_SRET (RV_ENCODE_FUNCT12(SRET) | RVG_OPCODE_SYSTEM) +#define RVC_MATCH_C_BEQZ (RVC_ENCODE_FUNCT3(C_BEQZ) | RVC_OPCODE_C1) +#define RVC_MATCH_C_BNEZ (RVC_ENCODE_FUNCT3(C_BNEZ) | RVC_OPCODE_C1) +#define RVC_MATCH_C_J (RVC_ENCODE_FUNCT3(C_J) | RVC_OPCODE_C1) +#define RVC_MATCH_C_JAL (RVC_ENCODE_FUNCT3(C_JAL) | RVC_OPCODE_C1) +#define RVC_MATCH_C_JR (RVC_ENCODE_FUNCT4(C_JR) | RVC_OPCODE_C2) +#define RVC_MATCH_C_JALR (RVC_ENCODE_FUNCT4(C_JALR) | RVC_OPCODE_C2) + +#define RVG_MASK_JALR (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_JAL (RV_INSN_OPCODE_MASK) +#define RVC_MASK_C_JALR (RVC_INSN_FUNCT4_MASK | RVC_INSN_J_RS2_MASK | RVC_INSN_OPCODE_MASK) +#define RVC_MASK_C_JR (RVC_INSN_FUNCT4_MASK | RVC_INSN_J_RS2_MASK | RVC_INSN_OPCODE_MASK) +#define RVC_MASK_C_JAL (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK) +#define RVC_MASK_C_J (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK) +#define RVG_MASK_BEQ (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BNE (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BLT (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BGE (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BLTU (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BGEU (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVC_MASK_C_BEQZ (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK) +#define RVC_MASK_C_BNEZ (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK)#define RVG_MASK_SRET 0xffffffff#define __INSN_LENGTH_MASK _UL(0x3)
Signature · 7 lines
2.35.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 02/13] RISC-V: detach funct-values from their offset
Quoted 4 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
Only carry the actual values for the funct3, funct4, etc instruction fields without directly including the shift to the target position.
"Only carry the actual values..." didn't really make sense to me until I actually looked at the diff. I'm not sure what "better" wording to suggest though... "Rather than defining funct3 (...) etc instruction fields, pre-shifted to their target positions, define the values themselves."
Is that better? I don't know, but at least I didn't say "I hate this" without trying to help :)
Quoted 5 lines
Instead use macros to move the values to their target positions when needed.
This at the same time also reduces the use of magic numbers, one would need a spec manual to understand.
I'm always down to avoid having to read a spec :)
Quoted 26 lines
Signed-off-by Heiko Stuebner <[email protected]>--- arch/riscv/include/asm/parse_asm.h | 100 +++++++++++++++++------------ 1 file changed, 59 insertions(+), 41 deletions(-)arch/riscv/include/asm/parse_asm.h +9
-0@@ -5,6 +5,15 @@#include <linux/bits.h> +#define RV_INSN_FUNCT3_MASK GENMASK(14, 12) +#define RV_INSN_FUNCT3_OPOFF 12 +#define RV_INSN_OPCODE_MASK GENMASK(6, 0) +#define RV_INSN_OPCODE_OPOFF 0 +#define RV_INSN_FUNCT12_OPOFF 20 + +#define RV_ENCODE_FUNCT3 (f_) (RVG_FUNCT3_##f_ << RV_INSN_FUNCT3_OPOFF) +#define RV_ENCODE_FUNCT12 (f_) (RVG_FUNCT12_##f_ << RV_INSN_FUNCT12_OPOFF) +/* The bit field of immediate value in I-type instruction */ #define RV_I_IMM_SIGN_OPOFF 31#define RV_I_IMM_11_0_OPOFF 20
arch/riscv/include/asm/parse_asm.h line 100
Quoted 8 lines
arch/riscv/include/asm/parse_asm.h +5
-0@@ -84,6 +93,15 @@#define RVC_B_IMM_2_1_MASK GENMASK(1, 0)#define RVC_B_IMM_5_MASK GENMASK(0, 0) +#define RVC_INSN_FUNCT4_MASK GENMASK(15, 12) +#define RVC_INSN_FUNCT4_OPOFF 12 +#define RVC_INSN_FUNCT3_MASK GENMASK(15, 13) +#define RVC_INSN_FUNCT3_OPOFF 13 +#define RVC_INSN_J_RS2_MASK GENMASK(6, 2)
Since I won't feel comfortable reviewing this without checking the specs, I did and god is Table 1.1 in the v1.7 compressed spec horrifically formatted. The numbers aren't even consistently spaced. My poor OCD! I thought they made these things with adoc or LaTeX...
Quoted 101 lines
arch/riscv/include/asm/parse_asm.h +45
-41+#define RVC_INSN_OPCODE_MASK GENMASK(1, 0) +#define RVC_ENCODE_FUNCT3 (f_) (RVC_FUNCT3_##f_ << RVC_INSN_FUNCT3_OPOFF) +#define RVC_ENCODE_FUNCT4 (f_) (RVC_FUNCT4_##f_ << RVC_INSN_FUNCT4_OPOFF) +/* The register offset in RVC op=C0 instruction */ #define RVC_C0_RS1_OPOFF 7#define RVC_C0_RS2_OPOFF 2@@ -113,52 +131,52 @@/* parts of funct3 code for I, M, A extension*/ #define RVG_FUNCT3_JALR 0x0#define RVG_FUNCT3_BEQ 0x0 -#define RVG_FUNCT3_BNE 0x1000 -#define RVG_FUNCT3_BLT 0x4000 -#define RVG_FUNCT3_BGE 0x5000 -#define RVG_FUNCT3_BLTU 0x6000 -#define RVG_FUNCT3_BGEU 0x7000 +#define RVG_FUNCT3_BNE 0x1 +#define RVG_FUNCT3_BLT 0x4 +#define RVG_FUNCT3_BGE 0x5 +#define RVG_FUNCT3_BLTU 0x6 +#define RVG_FUNCT3_BGEU 0x7/* parts of funct3 code for C extension*/ -#define RVC_FUNCT3_C_BEQZ 0xc000 -#define RVC_FUNCT3_C_BNEZ 0xe000 -#define RVC_FUNCT3_C_J 0xa000 -#define RVC_FUNCT3_C_JAL 0x2000 -#define RVC_FUNCT4_C_JR 0x8000 -#define RVC_FUNCT4_C_JALR 0xf000 +#define RVC_FUNCT3_C_BEQZ 0x6 +#define RVC_FUNCT3_C_BNEZ 0x7 +#define RVC_FUNCT3_C_J 0x5 +#define RVC_FUNCT3_C_JAL 0x1 +#define RVC_FUNCT4_C_JR 0x8 +#define RVC_FUNCT4_C_JALR 0x9 -#define RVG_FUNCT12_SRET 0x10200000 +#define RVG_FUNCT12_SRET 0x102 -#define RVG_MATCH_JALR (RVG_FUNCT3_JALR | RVG_OPCODE_JALR) +#define RVG_MATCH_JALR (RV_ENCODE_FUNCT3(JALR) | RVG_OPCODE_JALR)#define RVG_MATCH_JAL (RVG_OPCODE_JAL) -#define RVG_MATCH_BEQ (RVG_FUNCT3_BEQ | RVG_OPCODE_BRANCH) -#define RVG_MATCH_BNE (RVG_FUNCT3_BNE | RVG_OPCODE_BRANCH) -#define RVG_MATCH_BLT (RVG_FUNCT3_BLT | RVG_OPCODE_BRANCH) -#define RVG_MATCH_BGE (RVG_FUNCT3_BGE | RVG_OPCODE_BRANCH) -#define RVG_MATCH_BLTU (RVG_FUNCT3_BLTU | RVG_OPCODE_BRANCH) -#define RVG_MATCH_BGEU (RVG_FUNCT3_BGEU | RVG_OPCODE_BRANCH) -#define RVG_MATCH_SRET (RVG_FUNCT12_SRET | RVG_OPCODE_SYSTEM) -#define RVC_MATCH_C_BEQZ (RVC_FUNCT3_C_BEQZ | RVC_OPCODE_C1) -#define RVC_MATCH_C_BNEZ (RVC_FUNCT3_C_BNEZ | RVC_OPCODE_C1) -#define RVC_MATCH_C_J (RVC_FUNCT3_C_J | RVC_OPCODE_C1) -#define RVC_MATCH_C_JAL (RVC_FUNCT3_C_JAL | RVC_OPCODE_C1) -#define RVC_MATCH_C_JR (RVC_FUNCT4_C_JR | RVC_OPCODE_C2) -#define RVC_MATCH_C_JALR (RVC_FUNCT4_C_JALR | RVC_OPCODE_C2) - -#define RVG_MASK_JALR 0x707f -#define RVG_MASK_JAL 0x7f -#define RVC_MASK_C_JALR 0xf07f -#define RVC_MASK_C_JR 0xf07f -#define RVC_MASK_C_JAL 0xe003 -#define RVC_MASK_C_J 0xe003 -#define RVG_MASK_BEQ 0x707f -#define RVG_MASK_BNE 0x707f -#define RVG_MASK_BLT 0x707f -#define RVG_MASK_BGE 0x707f -#define RVG_MASK_BLTU 0x707f -#define RVG_MASK_BGEU 0x707f -#define RVC_MASK_C_BEQZ 0xe003 -#define RVC_MASK_C_BNEZ 0xe003 +#define RVG_MATCH_BEQ (RV_ENCODE_FUNCT3(BEQ) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BNE (RV_ENCODE_FUNCT3(BNE) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BLT (RV_ENCODE_FUNCT3(BLT) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BGE (RV_ENCODE_FUNCT3(BGE) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BLTU (RV_ENCODE_FUNCT3(BLTU) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BGEU (RV_ENCODE_FUNCT3(BGEU) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_SRET (RV_ENCODE_FUNCT12(SRET) | RVG_OPCODE_SYSTEM) +#define RVC_MATCH_C_BEQZ (RVC_ENCODE_FUNCT3(C_BEQZ) | RVC_OPCODE_C1) +#define RVC_MATCH_C_BNEZ (RVC_ENCODE_FUNCT3(C_BNEZ) | RVC_OPCODE_C1) +#define RVC_MATCH_C_J (RVC_ENCODE_FUNCT3(C_J) | RVC_OPCODE_C1) +#define RVC_MATCH_C_JAL (RVC_ENCODE_FUNCT3(C_JAL) | RVC_OPCODE_C1) +#define RVC_MATCH_C_JR (RVC_ENCODE_FUNCT4(C_JR) | RVC_OPCODE_C2) +#define RVC_MATCH_C_JALR (RVC_ENCODE_FUNCT4(C_JALR) | RVC_OPCODE_C2) + +#define RVG_MASK_JALR (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_JAL (RV_INSN_OPCODE_MASK) +#define RVC_MASK_C_JALR (RVC_INSN_FUNCT4_MASK | RVC_INSN_J_RS2_MASK | RVC_INSN_OPCODE_MASK) +#define RVC_MASK_C_JR (RVC_INSN_FUNCT4_MASK | RVC_INSN_J_RS2_MASK | RVC_INSN_OPCODE_MASK) +#define RVC_MASK_C_JAL (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK) +#define RVC_MASK_C_J (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK) +#define RVG_MASK_BEQ (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BNE (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BLT (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BGE (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BLTU (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BGEU (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVC_MASK_C_BEQZ (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK) +#define RVC_MASK_C_BNEZ (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK)#define RVG_MASK_SRET 0xffffffff
Quoted 1 line
#define
__INSN_LENGTH_MASK_UL(0x3)
My eyes got tired near the end of this, but I had a good through and spot checked against the values in the spec docs and all came up good for me. I definitely like the cases where you manage to avoid using defines that'd require an RE effort to figure out what the actual fields are.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 02/13] RISC-V: detach funct-values from their offset
In reply to Heiko StuebnerWoops, I built this commit in isolation and:
/stuff/linux/arch/riscv/kernel/kgdb.c:32:32: error: use of undeclared identifier 'MASK_JALR' DECLARE_INSN(jalr, MATCH_JALR, MASK_JALR)
^
/stuff/linux/arch/riscv/kernel/kgdb.c:32:20: error: use of undeclared identifier 'MATCH_JALR'
DECLARE_INSN(jalr, MATCH_JALR, MASK_JALR)
^
/stuff/linux/arch/riscv/kernel/kgdb.c:33:30: error: use of undeclared identifier 'MASK_JAL'
DECLARE_INSN(jal, MATCH_JAL, MASK_JAL)
^
/stuff/linux/arch/riscv/kernel/kgdb.c:33:19: error: use of undeclared identifier 'MATCH_JAL'
DECLARE_INSN(jal, MATCH_JAL, MASK_JAL)
^
/stuff/linux/arch/riscv/kernel/kgdb.c:34:32: error: use of undeclared identifier 'MASK_C_JR'
DECLARE_INSN(c_jr, MATCH_C_JR, MASK_C_JR)
^
/stuff/linux/arch/riscv/kernel/kgdb.c:34:20: error: use of undeclared identifier 'MATCH_C_JR'
DECLARE_INSN(c_jr, MATCH_C_JR, MASK_C_JR)
^
/stuff/linux/arch/riscv/kernel/kgdb.c:35:36: error: use of undeclared identifier 'MASK_C_JALR'
DECLARE_INSN(c_jalr, MATCH_C_JALR, MASK_C_JALR)
^
/stuff/linux/arch/riscv/kernel/kgdb.c:35:22: error: use of undeclared identifier 'MATCH_C_JALR'
DECLARE_INSN(c_jalr, MATCH_C_JALR, MASK_C_JALR)
^
/stuff/linux/arch/riscv/kernel/kgdb.c:36:30: error: use of undeclared identifier 'MASK_C_J'
DECLARE_INSN(c_j, MATCH_C_J, MASK_C_J)
^
/stuff/linux/arch/riscv/kernel/kgdb.c:36:19: error: use of undeclared identifier 'MATCH_C_J'
DECLARE_INSN(c_j, MATCH_C_J, MASK_C_J)
^
/stuff/linux/arch/riscv/kernel/kgdb.c:37:30: error: use of undeclared identifier 'MASK_BEQ'
DECLARE_INSN(beq, MATCH_BEQ, MASK_BEQ)
^
/stuff/linux/arch/riscv/kernel/kgdb.c:37:19: error: use of undeclared identifier 'MATCH_BEQ'
DECLARE_INSN(beq, MATCH_BEQ, MASK_BEQ)
^
/stuff/linux/arch/riscv/kernel/kgdb.c:38:30: error: use of undeclared identifier 'MASK_BNE'
DECLARE_INSN(bne, MATCH_BNE, MASK_BNE)
^
/stuff/linux/arch/riscv/kernel/kgdb.c:38:19: error: use of undeclared identifier 'MATCH_BNE'
DECLARE_INSN(bne, MATCH_BNE, MASK_BNE)
^
/stuff/linux/arch/riscv/kernel/kgdb.c:39:30: error: use of undeclared identifier 'MASK_BLT'
DECLARE_INSN(blt, MATCH_BLT, MASK_BLT)
^
/stuff/linux/arch/riscv/kernel/kgdb.c:39:19: error: use of undeclared identifier 'MATCH_BLT'
DECLARE_INSN(blt, MATCH_BLT, MASK_BLT)
^
/stuff/linux/arch/riscv/kernel/kgdb.c:40:30: error: use of undeclared identifier 'MASK_BGE'
DECLARE_INSN(bge, MATCH_BGE, MASK_BGE)
^
/stuff/linux/arch/riscv/kernel/kgdb.c:40:19: error: use of undeclared identifier 'MATCH_BGE'
DECLARE_INSN(bge, MATCH_BGE, MASK_BGE)
^
/stuff/linux/arch/riscv/kernel/kgdb.c:41:32: error: use of undeclared identifier 'MASK_BLTU'
DECLARE_INSN(bltu, MATCH_BLTU, MASK_BLTU)
^fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[5]: *** [/stuff/linux/scripts/Makefile.build:250: arch/riscv/kernel/kgdb.o] Error 1
:(
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 02/13] RISC-V: detach funct-values from their offset
Am Mittwoch, 30. November 2022, 00:01:10 CET schrieb Conor Dooley:
Quoted 7 lines
Woops, I built this commit in isolation and:
/stuff/linux/arch/riscv/kernel/kgdb.c:32:32: error: use of undeclared identifier 'MASK_JALR'DECLARE_INSN(jalr, MATCH_JALR, MASK_JALR)^ /stuff/linux/arch/riscv/kernel/kgdb.c:32:20: error: use of undeclared identifier 'MATCH_JALR' DECLARE_INSN(jalr, MATCH_JALR, MASK_JALR) ^
actually that is patch1's fault, that added the prefixes in the first place, and I've fixed it there.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 02/13] RISC-V: detach funct-values from their offset
Quoted 11 lines · Heiko Stübner
Am Mittwoch, 30. November 2022, 00:01:10 CET schrieb Conor Dooley:
Quoted 7 lines
Woops, I built this commit in isolation and:
/stuff/linux/arch/riscv/kernel/kgdb.c:32:32: error: use of undeclared identifier 'MASK_JALR'DECLARE_INSN(jalr, MATCH_JALR, MASK_JALR)^ /stuff/linux/arch/riscv/kernel/kgdb.c:32:20: error: use of undeclared identifier 'MATCH_JALR' DECLARE_INSN(jalr, MATCH_JALR, MASK_JALR) ^actually that is patch1's fault, that added the prefixes in the first place, and I've fixed it there.
I guess I should have done my grepping for patch1's review with only it checked out...
git rebase -i -x '<build command line>' <series-base-commit>
is our friend.
Thanks,
drew
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 02/13] RISC-V: detach funct-values from their offset
Am Mittwoch, 30. November 2022, 15:16:58 CET schrieb Andrew Jones:
Quoted 10 lines · Heiko Stübner
Quoted 9 lines
Am Mittwoch, 30. November 2022, 00:01:10 CET schrieb Conor Dooley:
Quoted 7 lines
Woops, I built this commit in isolation and:
/stuff/linux/arch/riscv/kernel/kgdb.c:32:32: error: use of undeclared identifier 'MASK_JALR'DECLARE_INSN(jalr, MATCH_JALR, MASK_JALR)^ /stuff/linux/arch/riscv/kernel/kgdb.c:32:20: error: use of undeclared identifier 'MATCH_JALR' DECLARE_INSN(jalr, MATCH_JALR, MASK_JALR) ^
Quoted 7 lines
Quoted 2 lines
actually that is patch1's fault, that added the prefixes in the first place, and I've fixed it there.
I guess I should have done my grepping for patch1's review with only it checked out...
git rebase -i -x '<build command line>' <series-base-commit>
voodoo :-D
I'm doing that manually right now, I need to address Conor's comments anyway ;-) .
Heiko
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 02/13] RISC-V: detach funct-values from their offset
In reply to Heiko StuebnerQuoted 64 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
Only carry the actual values for the funct3, funct4, etc instruction fields without directly including the shift to the target position.
Instead use macros to move the values to their target positions when needed.
This at the same time also reduces the use of magic numbers, one would need a spec manual to understand.
Signed-off-by Heiko Stuebner <[email protected]>--- arch/riscv/include/asm/parse_asm.h | 100 +++++++++++++++++------------ 1 file changed, 59 insertions(+), 41 deletions(-)arch/riscv/include/asm/parse_asm.h +21
-5@@ -5,6 +5,15 @@#include <linux/bits.h> +#define RV_INSN_FUNCT3_MASK GENMASK(14, 12) +#define RV_INSN_FUNCT3_OPOFF 12 +#define RV_INSN_OPCODE_MASK GENMASK(6, 0) +#define RV_INSN_OPCODE_OPOFF 0 +#define RV_INSN_FUNCT12_OPOFF 20 + +#define RV_ENCODE_FUNCT3 (f_) (RVG_FUNCT3_##f_ << RV_INSN_FUNCT3_OPOFF) +#define RV_ENCODE_FUNCT12 (f_) (RVG_FUNCT12_##f_ << RV_INSN_FUNCT12_OPOFF) +/* The bit field of immediate value in I-type instruction */ #define RV_I_IMM_SIGN_OPOFF 31#define RV_I_IMM_11_0_OPOFF 20@@ -84,6 +93,15 @@#define RVC_B_IMM_2_1_MASK GENMASK(1, 0)#define RVC_B_IMM_5_MASK GENMASK(0, 0) +#define RVC_INSN_FUNCT4_MASK GENMASK(15, 12) +#define RVC_INSN_FUNCT4_OPOFF 12 +#define RVC_INSN_FUNCT3_MASK GENMASK(15, 13) +#define RVC_INSN_FUNCT3_OPOFF 13 +#define RVC_INSN_J_RS2_MASK GENMASK(6, 2) +#define RVC_INSN_OPCODE_MASK GENMASK(1, 0) +#define RVC_ENCODE_FUNCT3 (f_) (RVC_FUNCT3_##f_ << RVC_INSN_FUNCT3_OPOFF) +#define RVC_ENCODE_FUNCT4 (f_) (RVC_FUNCT4_##f_ << RVC_INSN_FUNCT4_OPOFF) +/* The register offset in RVC op=C0 instruction */ #define RVC_C0_RS1_OPOFF 7#define RVC_C0_RS2_OPOFF 2@@ -113,52 +131,52 @@/* parts of funct3 code for I, M, A extension*/ #define RVG_FUNCT3_JALR 0x0#define RVG_FUNCT3_BEQ 0x0 -#define RVG_FUNCT3_BNE 0x1000 -#define RVG_FUNCT3_BLT 0x4000 -#define RVG_FUNCT3_BGE 0x5000 -#define RVG_FUNCT3_BLTU 0x6000 -#define RVG_FUNCT3_BGEU 0x7000 +#define RVG_FUNCT3_BNE 0x1 +#define RVG_FUNCT3_BLT 0x4 +#define RVG_FUNCT3_BGE 0x5
arch/riscv/include/asm/parse_asm.h line 128
Quoted 10 lines
arch/riscv/include/asm/parse_asm.h +2
-6+#define RVG_FUNCT3_BLTU 0x6 +#define RVG_FUNCT3_BGEU 0x7/* parts of funct3 code for C extension*/ -#define RVC_FUNCT3_C_BEQZ 0xc000 -#define RVC_FUNCT3_C_BNEZ 0xe000 -#define RVC_FUNCT3_C_J 0xa000 -#define RVC_FUNCT3_C_JAL 0x2000 -#define RVC_FUNCT4_C_JR 0x8000 -#define RVC_FUNCT4_C_JALR 0xf000
^^ this looks wrong
arch/riscv/include/asm/parse_asm.h line 146
Quoted 6 lines
arch/riscv/include/asm/parse_asm.h +6
-0+#define RVC_FUNCT3_C_BEQZ 0x6 +#define RVC_FUNCT3_C_BNEZ 0x7 +#define RVC_FUNCT3_C_J 0x5 +#define RVC_FUNCT3_C_JAL 0x1 +#define RVC_FUNCT4_C_JR 0x8 +#define RVC_FUNCT4_C_JALR 0x9
^^ and this looks right,
but we should fix that with a separate patch
Quoted 69 lines
arch/riscv/include/asm/parse_asm.h +30
-30-#define RVG_FUNCT12_SRET 0x10200000 +#define RVG_FUNCT12_SRET 0x102 -#define RVG_MATCH_JALR (RVG_FUNCT3_JALR | RVG_OPCODE_JALR) +#define RVG_MATCH_JALR (RV_ENCODE_FUNCT3(JALR) | RVG_OPCODE_JALR)#define RVG_MATCH_JAL (RVG_OPCODE_JAL) -#define RVG_MATCH_BEQ (RVG_FUNCT3_BEQ | RVG_OPCODE_BRANCH) -#define RVG_MATCH_BNE (RVG_FUNCT3_BNE | RVG_OPCODE_BRANCH) -#define RVG_MATCH_BLT (RVG_FUNCT3_BLT | RVG_OPCODE_BRANCH) -#define RVG_MATCH_BGE (RVG_FUNCT3_BGE | RVG_OPCODE_BRANCH) -#define RVG_MATCH_BLTU (RVG_FUNCT3_BLTU | RVG_OPCODE_BRANCH) -#define RVG_MATCH_BGEU (RVG_FUNCT3_BGEU | RVG_OPCODE_BRANCH) -#define RVG_MATCH_SRET (RVG_FUNCT12_SRET | RVG_OPCODE_SYSTEM) -#define RVC_MATCH_C_BEQZ (RVC_FUNCT3_C_BEQZ | RVC_OPCODE_C1) -#define RVC_MATCH_C_BNEZ (RVC_FUNCT3_C_BNEZ | RVC_OPCODE_C1) -#define RVC_MATCH_C_J (RVC_FUNCT3_C_J | RVC_OPCODE_C1) -#define RVC_MATCH_C_JAL (RVC_FUNCT3_C_JAL | RVC_OPCODE_C1) -#define RVC_MATCH_C_JR (RVC_FUNCT4_C_JR | RVC_OPCODE_C2) -#define RVC_MATCH_C_JALR (RVC_FUNCT4_C_JALR | RVC_OPCODE_C2) - -#define RVG_MASK_JALR 0x707f -#define RVG_MASK_JAL 0x7f -#define RVC_MASK_C_JALR 0xf07f -#define RVC_MASK_C_JR 0xf07f -#define RVC_MASK_C_JAL 0xe003 -#define RVC_MASK_C_J 0xe003 -#define RVG_MASK_BEQ 0x707f -#define RVG_MASK_BNE 0x707f -#define RVG_MASK_BLT 0x707f -#define RVG_MASK_BGE 0x707f -#define RVG_MASK_BLTU 0x707f -#define RVG_MASK_BGEU 0x707f -#define RVC_MASK_C_BEQZ 0xe003 -#define RVC_MASK_C_BNEZ 0xe003 +#define RVG_MATCH_BEQ (RV_ENCODE_FUNCT3(BEQ) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BNE (RV_ENCODE_FUNCT3(BNE) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BLT (RV_ENCODE_FUNCT3(BLT) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BGE (RV_ENCODE_FUNCT3(BGE) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BLTU (RV_ENCODE_FUNCT3(BLTU) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BGEU (RV_ENCODE_FUNCT3(BGEU) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_SRET (RV_ENCODE_FUNCT12(SRET) | RVG_OPCODE_SYSTEM) +#define RVC_MATCH_C_BEQZ (RVC_ENCODE_FUNCT3(C_BEQZ) | RVC_OPCODE_C1) +#define RVC_MATCH_C_BNEZ (RVC_ENCODE_FUNCT3(C_BNEZ) | RVC_OPCODE_C1) +#define RVC_MATCH_C_J (RVC_ENCODE_FUNCT3(C_J) | RVC_OPCODE_C1) +#define RVC_MATCH_C_JAL (RVC_ENCODE_FUNCT3(C_JAL) | RVC_OPCODE_C1) +#define RVC_MATCH_C_JR (RVC_ENCODE_FUNCT4(C_JR) | RVC_OPCODE_C2) +#define RVC_MATCH_C_JALR (RVC_ENCODE_FUNCT4(C_JALR) | RVC_OPCODE_C2) + +#define RVG_MASK_JALR (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_JAL (RV_INSN_OPCODE_MASK) +#define RVC_MASK_C_JALR (RVC_INSN_FUNCT4_MASK | RVC_INSN_J_RS2_MASK | RVC_INSN_OPCODE_MASK) +#define RVC_MASK_C_JR (RVC_INSN_FUNCT4_MASK | RVC_INSN_J_RS2_MASK | RVC_INSN_OPCODE_MASK) +#define RVC_MASK_C_JAL (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK) +#define RVC_MASK_C_J (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK) +#define RVG_MASK_BEQ (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BNE (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BLT (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BGE (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BLTU (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BGEU (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVC_MASK_C_BEQZ (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK) +#define RVC_MASK_C_BNEZ (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK)#define RVG_MASK_SRET 0xffffffff#define __INSN_LENGTH_MASK _UL(0x3)Signature · 1 line
2.35.1
Thanks,
drew
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v2 3/13 RISC-V: add ebreak instructions to definitions
In reply to Heiko StuebnerFrom: Heiko Stuebner <[email protected]>
kprobes need to match ebreaks instructions, so add the necessary data to enable us to centralize that functionality.
--- arch/riscv/include/asm/parse_asm.h | 6 ++++++ 1 file changed, 6 insertions(+)
arch/riscv/include/asm/parse_asm.h +6 -0
@@ -144,7 +144,9 @@#define RVC_FUNCT3_C_JAL 0x1#define RVC_FUNCT4_C_JR 0x8#define RVC_FUNCT4_C_JALR 0x9 +#define RVC_FUNCT4_C_EBREAK 0x9 +#define RVG_FUNCT12_EBREAK 0x1#define RVG_FUNCT12_SRET 0x102#define RVG_MATCH_JALR (RV_ENCODE_FUNCT3(JALR) | RVG_OPCODE_JALR)
@@ -155,6 +157,7 @@#define RVG_MATCH_BGE (RV_ENCODE_FUNCT3(BGE) | RVG_OPCODE_BRANCH)#define RVG_MATCH_BLTU (RV_ENCODE_FUNCT3(BLTU) | RVG_OPCODE_BRANCH)#define RVG_MATCH_BGEU (RV_ENCODE_FUNCT3(BGEU) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_EBREAK (RV_ENCODE_FUNCT12(EBREAK) | RVG_OPCODE_SYSTEM)#define RVG_MATCH_SRET (RV_ENCODE_FUNCT12(SRET) | RVG_OPCODE_SYSTEM)#define RVC_MATCH_C_BEQZ (RVC_ENCODE_FUNCT3(C_BEQZ) | RVC_OPCODE_C1)#define RVC_MATCH_C_BNEZ (RVC_ENCODE_FUNCT3(C_BNEZ) | RVC_OPCODE_C1)
@@ -162,6 +165,7 @@#define RVC_MATCH_C_JAL (RVC_ENCODE_FUNCT3(C_JAL) | RVC_OPCODE_C1)#define RVC_MATCH_C_JR (RVC_ENCODE_FUNCT4(C_JR) | RVC_OPCODE_C2)#define RVC_MATCH_C_JALR (RVC_ENCODE_FUNCT4(C_JALR) | RVC_OPCODE_C2) +#define RVC_MATCH_C_EBREAK (RVC_ENCODE_FUNCT4(C_EBREAK) | RVC_OPCODE_C2)#define RVG_MASK_JALR (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK)#define RVG_MASK_JAL (RV_INSN_OPCODE_MASK)
@@ -177,6 +181,8 @@#define RVG_MASK_BGEU (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK)#define RVC_MASK_C_BEQZ (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK)#define RVC_MASK_C_BNEZ (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK) +#define RVC_MASK_C_EBREAK 0xffff +#define RVG_MASK_EBREAK 0xffffffff#define RVG_MASK_SRET 0xffffffff#define __INSN_LENGTH_MASK _UL(0x3)
Signature · 7 lines
2.35.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 03/13] RISC-V: add ebreak instructions to definitions
Quoted 3 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
kprobes need to match ebreaks instructions, so add the necessary
nit: ebreaks or ebreak instructions - but should it be stylised with capitals to match the spec?
Otherwise this looks grand?
Quoted 49 lines
data to enable us to centralize that functionality.
Signed-off-by Heiko Stuebner <[email protected]>--- arch/riscv/include/asm/parse_asm.h | 6 ++++++ 1 file changed, 6 insertions(+)arch/riscv/include/asm/parse_asm.h +6
-0@@ -144,7 +144,9 @@#define RVC_FUNCT3_C_JAL 0x1#define RVC_FUNCT4_C_JR 0x8#define RVC_FUNCT4_C_JALR 0x9 +#define RVC_FUNCT4_C_EBREAK 0x9 +#define RVG_FUNCT12_EBREAK 0x1#define RVG_FUNCT12_SRET 0x102#define RVG_MATCH_JALR (RV_ENCODE_FUNCT3(JALR) | RVG_OPCODE_JALR)@@ -155,6 +157,7 @@#define RVG_MATCH_BGE (RV_ENCODE_FUNCT3(BGE) | RVG_OPCODE_BRANCH)#define RVG_MATCH_BLTU (RV_ENCODE_FUNCT3(BLTU) | RVG_OPCODE_BRANCH)#define RVG_MATCH_BGEU (RV_ENCODE_FUNCT3(BGEU) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_EBREAK (RV_ENCODE_FUNCT12(EBREAK) | RVG_OPCODE_SYSTEM)#define RVG_MATCH_SRET (RV_ENCODE_FUNCT12(SRET) | RVG_OPCODE_SYSTEM)#define RVC_MATCH_C_BEQZ (RVC_ENCODE_FUNCT3(C_BEQZ) | RVC_OPCODE_C1)#define RVC_MATCH_C_BNEZ (RVC_ENCODE_FUNCT3(C_BNEZ) | RVC_OPCODE_C1)@@ -162,6 +165,7 @@#define RVC_MATCH_C_JAL (RVC_ENCODE_FUNCT3(C_JAL) | RVC_OPCODE_C1)#define RVC_MATCH_C_JR (RVC_ENCODE_FUNCT4(C_JR) | RVC_OPCODE_C2)#define RVC_MATCH_C_JALR (RVC_ENCODE_FUNCT4(C_JALR) | RVC_OPCODE_C2) +#define RVC_MATCH_C_EBREAK (RVC_ENCODE_FUNCT4(C_EBREAK) | RVC_OPCODE_C2)#define RVG_MASK_JALR (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK)#define RVG_MASK_JAL (RV_INSN_OPCODE_MASK)@@ -177,6 +181,8 @@#define RVG_MASK_BGEU (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK)#define RVC_MASK_C_BEQZ (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK)#define RVC_MASK_C_BNEZ (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK) +#define RVC_MASK_C_EBREAK 0xffff +#define RVG_MASK_EBREAK 0xffffffff#define RVG_MASK_SRET 0xffffffff#define __INSN_LENGTH_MASK _UL(0x3)Signature · 1 line
2.35.1
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 03/13] RISC-V: add ebreak instructions to definitions
In reply to Heiko StuebnerQuoted 9 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
kprobes need to match ebreaks instructions, so add the necessary data to enable us to centralize that functionality.
Signed-off-by Heiko Stuebner <[email protected]>--- arch/riscv/include/asm/parse_asm.h | 6 ++++++ 1 file changed, 6 insertions(+)
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v2 4/13 RISC-V: Move riscv_insn_is_* macros into a common header
In reply to Heiko StuebnerFrom: Heiko Stuebner <[email protected]>
Right now the riscv kernel has (at least) two independent sets of functions to check if an encoded instruction is of a specific type. One in kgdb and one kprobes simulate-insn code.
More parts of the kernel will probably need this in the future, so instead of allowing this duplication to go on further, move macros that do the function declaration in a common header, similar to at least aarch64.
--- arch/riscv/include/asm/parse_asm.h | 41 ++++++++++++++++---- arch/riscv/kernel/kgdb.c | 49 ++++++++---------------- arch/riscv/kernel/probes/simulate-insn.h | 26 +++---------- 3 files changed, 54 insertions(+), 62 deletions(-)
arch/riscv/include/asm/parse_asm.h +34 -7
@@ -190,13 +190,40 @@#define __INSN_OPCODE_MASK _UL(0x7F)#define __INSN_BRANCH_OPCODE _UL(RVG_OPCODE_BRANCH) -/* Define a series of is_XXX_insn functions to check if the value INSN -* is an instance of instruction XXX. -*/ -#define DECLARE_INSN (INSN_NAME ,INSN_MATCH ,INSN_MASK ) \ -static inline bool is_ ## INSN_NAME ## _insn(long insn) \ -{ \ - return (insn & (INSN_MASK)) == (INSN_MATCH); \ +#define __RISCV_INSN_FUNCS (name, mask, val) \ +static __always_inline bool riscv_insn_is_##name(u32 code) \ +{ \ + BUILD_BUG_ON(~(mask) & (val)); \ + return (code & (mask)) == (val); \ +} \ + +#if __riscv_xlen ==32 +/* C.JAL is an RV32C-only instruction */ +__RISCV_INSN_FUNCS(c_jal, RVC_MASK_C_JAL, RVC_MATCH_C_JAL) +#else +#define riscv_insn_is_c_jal (opcode) 0 +#endif +__RISCV_INSN_FUNCS(jalr, RVG_MASK_JALR, RVG_MATCH_JALR) +__RISCV_INSN_FUNCS(jal, RVG_MASK_JAL, RVG_MATCH_JAL) +__RISCV_INSN_FUNCS(c_jr, RVC_MASK_C_JR, RVC_MATCH_C_JR) +__RISCV_INSN_FUNCS(c_jalr, RVC_MASK_C_JALR, RVC_MATCH_C_JALR) +__RISCV_INSN_FUNCS(c_j, RVC_MASK_C_J, RVC_MATCH_C_J) +__RISCV_INSN_FUNCS(beq, RVG_MASK_BEQ, RVG_MATCH_BEQ) +__RISCV_INSN_FUNCS(bne, RVG_MASK_BNE, RVG_MATCH_BNE) +__RISCV_INSN_FUNCS(blt, RVG_MASK_BLT, RVG_MATCH_BLT) +__RISCV_INSN_FUNCS(bge, RVG_MASK_BGE, RVG_MATCH_BGE) +__RISCV_INSN_FUNCS(bltu, RVG_MASK_BLTU, RVG_MATCH_BLTU) +__RISCV_INSN_FUNCS(bgeu, RVG_MASK_BGEU, RVG_MATCH_BGEU) +__RISCV_INSN_FUNCS(c_beqz, RVC_MASK_C_BEQZ, RVC_MATCH_C_BEQZ) +__RISCV_INSN_FUNCS(c_bnez, RVC_MASK_C_BNEZ, RVC_MATCH_C_BNEZ) +__RISCV_INSN_FUNCS(c_ebreak, RVC_MASK_C_EBREAK, RVC_MATCH_C_EBREAK) +__RISCV_INSN_FUNCS(ebreak, RVG_MASK_EBREAK, RVG_MATCH_EBREAK) +__RISCV_INSN_FUNCS (sret,RVG_MASK_SRET ,RVG_MATCH_SRET ) + +/* special case to catch _any_ branch instruction */ +static __always_inline bool riscv_insn_is_branch(u32 code) +{ +return (code &RV_INSN_OPCODE_MASK ) ==RVG_OPCODE_BRANCH ; }#define RV_IMM_SIGN (x) (-(((x) >> 31) & 1))
arch/riscv/kernel/kgdb.c +15 -34
95 lines not on this page · raw message
arch/riscv/kernel/probes/simulate-insn.h +5 -21
@@ -3,14 +3,7 @@#ifndef _RISCV_KERNEL_PROBES_SIMULATE_INSN_H#define _RISCV_KERNEL_PROBES_SIMULATE_INSN_H -#define __RISCV_INSN_FUNCS (name, mask, val) \ -static __always_inline bool riscv_insn_is_##name(probe_opcode_t code) \ -{ \ - BUILD_BUG_ON(~(mask) & (val)); \ - return (code & (mask)) == (val); \ -} \ -bool simulate_##name(u32 opcode, unsigned long addr, \ - struct pt_regs *regs) +#include <asm/parse_asm.h> #define RISCV_INSN_REJECTED (name, code) \ do { \
@@ -30,18 +23,9 @@ __RISCV_INSN_FUNCS(fence, 0x7f, 0x0f); } \ }while (0 ) -__RISCV_INSN_FUNCS (c_j,0xe003 ,0xa001 ); -__RISCV_INSN_FUNCS (c_jr,0xf007 ,0x8002 ); -__RISCV_INSN_FUNCS (c_jal,0xe003 ,0x2001 ); -__RISCV_INSN_FUNCS (c_jalr,0xf007 ,0x9002 ); -__RISCV_INSN_FUNCS (c_beqz,0xe003 ,0xc001 ); -__RISCV_INSN_FUNCS (c_bnez,0xe003 ,0xe001 ); -__RISCV_INSN_FUNCS (c_ebreak,0xffff ,0x9002 ); - -__RISCV_INSN_FUNCS (auipc,0x7f ,0x17 ); -__RISCV_INSN_FUNCS (branch,0x7f ,0x63 ); - -__RISCV_INSN_FUNCS (jal,0x7f ,0x6f ); -__RISCV_INSN_FUNCS (jalr,0x707f ,0x67 ); +bool simulate_auipc(u32 opcode, unsigned long addr, struct pt_regs *regs); +bool simulate_branch (u32 opcode,unsigned long addr,struct pt_regs *regs); +bool simulate_jal (u32 opcode,unsigned long addr,struct pt_regs *regs); +bool simulate_jalr (u32 opcode,unsigned long addr,struct pt_regs *regs);#endif /* _RISCV_KERNEL_PROBES_SIMULATE_INSN_H */
Signature · 7 lines
2.35.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 04/13] RISC-V: Move riscv_insn_is_* macros into a common header
Quoted 49 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
Right now the riscv kernel has (at least) two independent sets of functions to check if an encoded instruction is of a specific type. One in kgdb and one kprobes simulate-insn code.
More parts of the kernel will probably need this in the future, so instead of allowing this duplication to go on further, move macros that do the function declaration in a common header, similar to at least aarch64.
Signed-off-by Heiko Stuebner <[email protected]>--- arch/riscv/include/asm/parse_asm.h | 41 ++++++++++++++++---- arch/riscv/kernel/kgdb.c | 49 ++++++++---------------- arch/riscv/kernel/probes/simulate-insn.h | 26 +++---------- 3 files changed, 54 insertions(+), 62 deletions(-)arch/riscv/kernel/probes/simulate-insn.h +1
-15@@ -3,14 +3,7 @@#ifndef _RISCV_KERNEL_PROBES_SIMULATE_INSN_H#define _RISCV_KERNEL_PROBES_SIMULATE_INSN_H -#define __RISCV_INSN_FUNCS (name, mask, val) \ -static __always_inline bool riscv_insn_is_##name(probe_opcode_t code) \ -{ \ - BUILD_BUG_ON(~(mask) & (val)); \ - return (code & (mask)) == (val); \ -} \ -bool simulate_##name(u32 opcode, unsigned long addr, \ - struct pt_regs *regs) +#include <asm/parse_asm.h> #define RISCV_INSN_REJECTED (name, code) \ do { \@@ -30,18 +23,9 @@ __RISCV_INSN_FUNCS(fence, 0x7f, 0x0f); } \ }while (0 ) -__RISCV_INSN_FUNCS (c_j,0xe003 ,0xa001 ); -__RISCV_INSN_FUNCS (c_jr,0xf007 ,0x8002 ); -__RISCV_INSN_FUNCS (c_jal,0xe003 ,0x2001 ); -__RISCV_INSN_FUNCS (c_jalr,0xf007 ,0x9002 ); -__RISCV_INSN_FUNCS (c_beqz,0xe003 ,0xc001 ); -__RISCV_INSN_FUNCS (c_bnez,0xe003 ,0xe001 ); -__RISCV_INSN_FUNCS (c_ebreak,0xffff ,0x9002 );
arch/riscv/kernel/probes/simulate-insn.h __RISCV_INSN_FUNCS(fence, 0x7f, 0x0f); · line 29
Quoted 10 lines
arch/riscv/kernel/probes/simulate-insn.h +4
-6- -__RISCV_INSN_FUNCS (auipc,0x7f ,0x17 ); -__RISCV_INSN_FUNCS (branch,0x7f ,0x63 ); - -__RISCV_INSN_FUNCS (jal,0x7f ,0x6f ); -__RISCV_INSN_FUNCS (jalr,0x707f ,0x67 ); +bool simulate_auipc (u32 opcode,unsigned long addr,struct pt_regs *regs); +bool simulate_branch (u32 opcode,unsigned long addr,struct pt_regs *regs); +bool simulate_jal (u32 opcode,unsigned long addr,struct pt_regs *regs); +bool simulate_jalr (u32 opcode,unsigned long addr,struct pt_regs *regs);
I assume the other ones didn't actually have a user and so didn't need a function created? Code movement here looks fine. Dropping the double definitions is always nice :)
Thanks,
Conor.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 04/13] RISC-V: Move riscv_insn_is_* macros into a common header
Quoted 65 lines · Conor Dooley
Quoted 49 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
Right now the riscv kernel has (at least) two independent sets of functions to check if an encoded instruction is of a specific type. One in kgdb and one kprobes simulate-insn code.
More parts of the kernel will probably need this in the future, so instead of allowing this duplication to go on further, move macros that do the function declaration in a common header, similar to at least aarch64.
Signed-off-by Heiko Stuebner <[email protected]>--- arch/riscv/include/asm/parse_asm.h | 41 ++++++++++++++++---- arch/riscv/kernel/kgdb.c | 49 ++++++++---------------- arch/riscv/kernel/probes/simulate-insn.h | 26 +++---------- 3 files changed, 54 insertions(+), 62 deletions(-)arch/riscv/kernel/probes/simulate-insn.h +1
-15@@ -3,14 +3,7 @@#ifndef _RISCV_KERNEL_PROBES_SIMULATE_INSN_H#define _RISCV_KERNEL_PROBES_SIMULATE_INSN_H -#define __RISCV_INSN_FUNCS (name, mask, val) \ -static __always_inline bool riscv_insn_is_##name(probe_opcode_t code) \ -{ \ - BUILD_BUG_ON(~(mask) & (val)); \ - return (code & (mask)) == (val); \ -} \ -bool simulate_##name(u32 opcode, unsigned long addr, \ - struct pt_regs *regs) +#include <asm/parse_asm.h> #define RISCV_INSN_REJECTED (name, code) \ do { \@@ -30,18 +23,9 @@ __RISCV_INSN_FUNCS(fence, 0x7f, 0x0f); } \ }while (0 ) -__RISCV_INSN_FUNCS (c_j,0xe003 ,0xa001 ); -__RISCV_INSN_FUNCS (c_jr,0xf007 ,0x8002 ); -__RISCV_INSN_FUNCS (c_jal,0xe003 ,0x2001 ); -__RISCV_INSN_FUNCS (c_jalr,0xf007 ,0x9002 ); -__RISCV_INSN_FUNCS (c_beqz,0xe003 ,0xc001 ); -__RISCV_INSN_FUNCS (c_bnez,0xe003 ,0xe001 ); -__RISCV_INSN_FUNCS (c_ebreak,0xffff ,0x9002 );arch/riscv/kernel/probes/simulate-insn.h __RISCV_INSN_FUNCS(fence, 0x7f, 0x0f); · line 29
Quoted 10 lines
arch/riscv/kernel/probes/simulate-insn.h +4
-6- -__RISCV_INSN_FUNCS (auipc,0x7f ,0x17 ); -__RISCV_INSN_FUNCS (branch,0x7f ,0x63 ); - -__RISCV_INSN_FUNCS (jal,0x7f ,0x6f ); -__RISCV_INSN_FUNCS (jalr,0x707f ,0x67 ); +bool simulate_auipc (u32 opcode,unsigned long addr,struct pt_regs *regs); +bool simulate_branch (u32 opcode,unsigned long addr,struct pt_regs *regs); +bool simulate_jal (u32 opcode,unsigned long addr,struct pt_regs *regs); +bool simulate_jalr (u32 opcode,unsigned long addr,struct pt_regs *regs);I assume the other ones didn't actually have a user and so didn't need a function created? Code movement here looks fine. Dropping the double definitions is always nice :)
Quoted 1 line
Reviewed-by Conor Dooley <[email protected]>
I should've waited for allmodconfig on this particular commit to finish:
/stuff/linux/arch/riscv/kernel/probes/decode-insn.c:43:2: error: call to undeclared function 'riscv_insn_is_auipc'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
RISCV_INSN_SET_SIMULATE(auipc, insn);
^
/stuff/linux/arch/riscv/kernel/probes/simulate-insn.h:20:7: note: expanded from macro 'RISCV_INSN_SET_SIMULATE'
if (riscv_insn_is_##name(code)) { \
^<scratch space>:62:1: note: expanded from hereriscv_insn_is_auipc
^
1 error generated.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 04/13] RISC-V: Move riscv_insn_is_* macros into a common header
In reply to Conor DooleyAm Mittwoch, 30. November 2022, 00:09:31 CET schrieb Conor Dooley:
Quoted 55 lines · Heiko Stuebner
Quoted 54 lines
From: Heiko Stuebner <[email protected]>
Right now the riscv kernel has (at least) two independent sets of functions to check if an encoded instruction is of a specific type. One in kgdb and one kprobes simulate-insn code.
More parts of the kernel will probably need this in the future, so instead of allowing this duplication to go on further, move macros that do the function declaration in a common header, similar to at least aarch64.
Signed-off-by Heiko Stuebner <[email protected]>--- arch/riscv/include/asm/parse_asm.h | 41 ++++++++++++++++---- arch/riscv/kernel/kgdb.c | 49 ++++++++---------------- arch/riscv/kernel/probes/simulate-insn.h | 26 +++---------- 3 files changed, 54 insertions(+), 62 deletions(-)arch/riscv/kernel/probes/simulate-insn.h +1
-20@@ -3,14 +3,7 @@#ifndef _RISCV_KERNEL_PROBES_SIMULATE_INSN_H#define _RISCV_KERNEL_PROBES_SIMULATE_INSN_H -#define __RISCV_INSN_FUNCS (name, mask, val) \ -static __always_inline bool riscv_insn_is_##name(probe_opcode_t code) \ -{ \ - BUILD_BUG_ON(~(mask) & (val)); \ - return (code & (mask)) == (val); \ -} \ -bool simulate_##name(u32 opcode, unsigned long addr, \ - struct pt_regs *regs) +#include <asm/parse_asm.h> #define RISCV_INSN_REJECTED (name, code) \ do { \@@ -30,18 +23,9 @@ __RISCV_INSN_FUNCS(fence, 0x7f, 0x0f); } \ }while (0 ) -__RISCV_INSN_FUNCS (c_j,0xe003 ,0xa001 ); -__RISCV_INSN_FUNCS (c_jr,0xf007 ,0x8002 ); -__RISCV_INSN_FUNCS (c_jal,0xe003 ,0x2001 ); -__RISCV_INSN_FUNCS (c_jalr,0xf007 ,0x9002 ); -__RISCV_INSN_FUNCS (c_beqz,0xe003 ,0xc001 ); -__RISCV_INSN_FUNCS (c_bnez,0xe003 ,0xe001 ); -__RISCV_INSN_FUNCS (c_ebreak,0xffff ,0x9002 ); - -__RISCV_INSN_FUNCS (auipc,0x7f ,0x17 ); -__RISCV_INSN_FUNCS (branch,0x7f ,0x63 ); - -__RISCV_INSN_FUNCS (jal,0x7f ,0x6f );
Quoted 8 lines
arch/riscv/kernel/probes/simulate-insn.h __RISCV_INSN_FUNCS(fence, 0x7f, 0x0f); · line 29
Quoted 5 lines
arch/riscv/kernel/probes/simulate-insn.h +4
-1-__RISCV_INSN_FUNCS (jalr,0x707f ,0x67 ); +bool simulate_auipc (u32 opcode,unsigned long addr,struct pt_regs *regs); +bool simulate_branch (u32 opcode,unsigned long addr,struct pt_regs *regs); +bool simulate_jal (u32 opcode,unsigned long addr,struct pt_regs *regs); +bool simulate_jalr (u32 opcode,unsigned long addr,struct pt_regs *regs);I assume the other ones didn't actually have a user and so didn't need a function created?
Yep, simulate-insn.c only actually defined these functions, so the original macro just defined empty prototypes for the rest.
Heiko
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 04/13] RISC-V: Move riscv_insn_is_* macros into a common header
In reply to Heiko StuebnerQuoted 11 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
Right now the riscv kernel has (at least) two independent sets of functions to check if an encoded instruction is of a specific type. One in kgdb and one kprobes simulate-insn code.
More parts of the kernel will probably need this in the future, so instead of allowing this duplication to go on further, move macros that do the function declaration in a common header, similar to at least aarch64.
Quoted 6 lines
Signed-off-by Heiko Stuebner <[email protected]>--- arch/riscv/include/asm/parse_asm.h | 41 ++++++++++++++++---- arch/riscv/kernel/kgdb.c | 49 ++++++++---------------- arch/riscv/kernel/probes/simulate-insn.h | 26 +++---------- 3 files changed, 54 insertions(+), 62 deletions(-)
Besides the missing auipc definition Conor found, LGTM
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v2 5/13 RISC-V: rename parse_asm.h to insn.h
In reply to Heiko StuebnerFrom: Heiko Stuebner <[email protected]>
The current parse_asm header should become a more centralized place for everything concerning parsing and constructing instructions.
We already have a header insn-def.h similar to aarch64, so rename parse_asm.h to insn.h (again similar to aarch64) to show that it's meant for more than simple instruction parsing.
---
arch/riscv/include/asm/{parse_asm.h => insn.h} | 0
arch/riscv/kernel/kgdb.c | 2 +-
arch/riscv/kernel/probes/simulate-insn.h | 2 +-
3 files changed, 2 insertions(+), 2 deletions(-)
rename arch/riscv/include/asm/{parse_asm.h => insn.h} (100%)arch/riscv/include/asm/insn.h renamed from arch/riscv/include/asm/parse_asm.h +0 -0
arch/riscv/kernel/kgdb.c +1 -1
@@ -11,7 +11,7 @@#include <linux/string.h> #include <asm/cacheflush.h> #include <asm/gdb_xml.h> -#include <asm/parse_asm.h> +#include <asm/insn.h> enum {NOT_KGDB_BREAK =0 ,
arch/riscv/kernel/probes/simulate-insn.h +1 -1
@@ -3,7 +3,7 @@#ifndef _RISCV_KERNEL_PROBES_SIMULATE_INSN_H#define _RISCV_KERNEL_PROBES_SIMULATE_INSN_H -#include <asm/parse_asm.h> +#include <asm/insn.h> #define RISCV_INSN_REJECTED (name, code) \ do { \
Signature · 7 lines
2.35.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 05/13] RISC-V: rename parse_asm.h to insn.h
Quoted 4 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
The current
parse_asmheader should become a more centralized place for everything concerning parsing and constructing instructions.
Heh, I opened this mail in mutt without reading $subject and my gut instinct was to say "parse_asm" doesn't feel like the right name for this content...
Quoted 3 lines
We already have a header
insn-def.hsimilar to aarch64, so renameparse_asm.htoinsn.h(again similar to aarch64) to show that it's meant for more than simple instruction parsing.
...and then I realised what that patch was doing :) rg parse_asm | wc -l
0
Still doesn't build though due to trailing stuff from prior commits.
Quoted 41 lines
Signed-off-by Heiko Stuebner <[email protected]>--- arch/riscv/include/asm/{parse_asm.h => insn.h} | 0 arch/riscv/kernel/kgdb.c | 2 +- arch/riscv/kernel/probes/simulate-insn.h | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename arch/riscv/include/asm/{parse_asm.h => insn.h} (100%)arch/riscv/include/asm/insn.h renamed from arch/riscv/include/asm/parse_asm.h +0
-0arch/riscv/kernel/kgdb.c +1
-1@@ -11,7 +11,7 @@#include <linux/string.h> #include <asm/cacheflush.h> #include <asm/gdb_xml.h> -#include <asm/parse_asm.h> +#include <asm/insn.h> enum {NOT_KGDB_BREAK =0 ,arch/riscv/kernel/probes/simulate-insn.h +1
-1@@ -3,7 +3,7 @@#ifndef _RISCV_KERNEL_PROBES_SIMULATE_INSN_H#define _RISCV_KERNEL_PROBES_SIMULATE_INSN_H -#include <asm/parse_asm.h> +#include <asm/insn.h> #define RISCV_INSN_REJECTED (name, code) \ do { \Signature · 1 line
2.35.1
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 05/13] RISC-V: rename parse_asm.h to insn.h
In reply to Heiko StuebnerQuoted 9 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
The current
parse_asmheader should become a more centralized place for everything concerning parsing and constructing instructions.We already have a header
insn-def.hsimilar to aarch64, so renameparse_asm.htoinsn.h(again similar to aarch64) to show that it's meant for more than simple instruction parsing.
Quoted 8 lines
Signed-off-by Heiko Stuebner <[email protected]>--- arch/riscv/include/asm/{parse_asm.h => insn.h} | 0 arch/riscv/kernel/kgdb.c | 2 +- arch/riscv/kernel/probes/simulate-insn.h | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename arch/riscv/include/asm/{parse_asm.h => insn.h} (100%)
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v2 6/13 RISC-V: kprobes: use central defined funct3 constants
In reply to Heiko StuebnerFrom: Heiko Stuebner <[email protected]>
Don't redefine values that are already available in a central header. Use the central ones instead.
--- arch/riscv/kernel/probes/simulate-insn.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-)
arch/riscv/kernel/probes/simulate-insn.c +6 -13
@@ -136,13 +136,6 @@ bool __kprobes simulate_auipc(u32 opcode, unsigned long addr, struct pt_regs *re#define branch_offset (opcode) \ sign_extend32((branch_imm(opcode)), 12) -#define BRANCH_BEQ 0x0 -#define BRANCH_BNE 0x1 -#define BRANCH_BLT 0x4 -#define BRANCH_BGE 0x5 -#define BRANCH_BLTU 0x6 -#define BRANCH_BGEU 0x7 -bool __kprobes simulate_branch (u32 opcode,unsigned long addr,struct pt_regs *regs) {/*
@@ -169,22 +162,22 @@ bool __kprobes simulate_branch(u32 opcode, unsigned long addr, struct pt_regs *r offset_tmp =branch_offset (opcode);switch (branch_funct3 (opcode)) { -case BRANCH_BEQ : +case RVG_FUNCT3_BEQ : offset = (rs1_val == rs2_val) ? offset_tmp :4 ;break ; -case BRANCH_BNE : +case RVG_FUNCT3_BNE : offset = (rs1_val != rs2_val) ? offset_tmp :4 ;break ; -case BRANCH_BLT : +case RVG_FUNCT3_BLT : offset = ((long )rs1_val < (long )rs2_val) ? offset_tmp :4 ;break ; -case BRANCH_BGE : +case RVG_FUNCT3_BGE : offset = ((long )rs1_val >= (long )rs2_val) ? offset_tmp :4 ;break ; -case BRANCH_BLTU : +case RVG_FUNCT3_BLTU : offset = (rs1_val < rs2_val) ? offset_tmp :4 ;break ; -case BRANCH_BGEU : +case RVG_FUNCT3_BGEU : offset = (rs1_val >= rs2_val) ? offset_tmp :4 ;break ;default :
Signature · 7 lines
2.35.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 06/13] RISC-V: kprobes: use central defined funct3 constants
Quoted 3 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
Don't redefine values that are already available in a central header.
Which central header?
Being intentionally dense, but it'd be nice to mention it since it's not in the diffstat?
Quoted 44 lines
Use the central ones instead.
Signed-off-by Heiko Stuebner <[email protected]>--- arch/riscv/kernel/probes/simulate-insn.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-)arch/riscv/kernel/probes/simulate-insn.c +4
-11@@ -136,13 +136,6 @@ bool __kprobes simulate_auipc(u32 opcode, unsigned long addr, struct pt_regs *re#define branch_offset (opcode) \ sign_extend32((branch_imm(opcode)), 12) -#define BRANCH_BEQ 0x0 -#define BRANCH_BNE 0x1 -#define BRANCH_BLT 0x4 -#define BRANCH_BGE 0x5 -#define BRANCH_BLTU 0x6 -#define BRANCH_BGEU 0x7 -bool __kprobes simulate_branch (u32 opcode,unsigned long addr,struct pt_regs *regs) {/* @@ -169,22 +162,22 @@ bool __kprobes simulate_branch(u32 opcode, unsigned long addr, struct pt_regs *r offset_tmp =branch_offset (opcode);switch (branch_funct3 (opcode)) { -case BRANCH_BEQ : +case RVG_FUNCT3_BEQ : offset = (rs1_val == rs2_val) ? offset_tmp :4 ;break ; -case BRANCH_BNE : +case RVG_FUNCT3_BNE : offset = (rs1_val != rs2_val) ? offset_tmp :4 ;break ; -case BRANCH_BLT : +case RVG_FUNCT3_BLT : offset = ((long )rs1_val < (long )rs2_val) ? offset_tmp :4 ;break ; -case BRANCH_BGE : +case RVG_FUNCT3_BGE : offset = ((long )rs1_val >= (long )rs2_val) ? offset_tmp :4 ;
arch/riscv/kernel/probes/simulate-insn.c bool __kprobes simulate_branch(u32 opcode, unsigned long addr, struct pt_regs *r · line 183
Quoted 10 lines
arch/riscv/kernel/probes/simulate-insn.c +2
-2break ; -case BRANCH_BLTU : +case RVG_FUNCT3_BLTU : offset = (rs1_val < rs2_val) ? offset_tmp :4 ;break ; -case BRANCH_BGEU : +case RVG_FUNCT3_BGEU : offset = (rs1_val >= rs2_val) ? offset_tmp :4 ;break ;default :
Still suffering from the carried-in build issues, but this change also looks grand in isolation?
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 06/13] RISC-V: kprobes: use central defined funct3 constants
Am Mittwoch, 30. November 2022, 00:22:10 CET schrieb Conor Dooley:
Quoted 8 lines · Heiko Stuebner
Quoted 3 lines
From: Heiko Stuebner <[email protected]>
Don't redefine values that are already available in a central header.
Which central header?
Being intentionally dense, but it'd be nice to mention it since it's not in the diffstat?
It's now:
Don't redefine values that are already available in the central header asm/insn.h . Use the values from there instead.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 06/13] RISC-V: kprobes: use central defined funct3 constants
In reply to Heiko StuebnerQuoted 10 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
Don't redefine values that are already available in a central header. Use the central ones instead.
Signed-off-by Heiko Stuebner <[email protected]>--- arch/riscv/kernel/probes/simulate-insn.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-)
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v2 7/13 RISC-V: add auipc elements to parse_asm header
In reply to Heiko StuebnerFrom: Heiko Stuebner <[email protected]>
We will want to use the opcode parsing outside kdb as well and need at least the auipc element there.
--- arch/riscv/include/asm/insn.h | 4 ++++ 1 file changed, 4 insertions(+)
arch/riscv/include/asm/insn.h +4 -0
@@ -118,6 +118,7 @@#define RVC_C2_RD_OPOFF 7/* parts of opcode for RVG*/ +#define RVG_OPCODE_AUIPC 0x17#define RVG_OPCODE_BRANCH 0x63#define RVG_OPCODE_JALR 0x67#define RVG_OPCODE_JAL 0x6f
@@ -149,6 +150,7 @@#define RVG_FUNCT12_EBREAK 0x1#define RVG_FUNCT12_SRET 0x102 +#define RVG_MATCH_AUIPC (RVG_OPCODE_AUIPC)#define RVG_MATCH_JALR (RV_ENCODE_FUNCT3(JALR) | RVG_OPCODE_JALR)#define RVG_MATCH_JAL (RVG_OPCODE_JAL)#define RVG_MATCH_BEQ (RV_ENCODE_FUNCT3(BEQ) | RVG_OPCODE_BRANCH)
@@ -167,6 +169,7 @@#define RVC_MATCH_C_JALR (RVC_ENCODE_FUNCT4(C_JALR) | RVC_OPCODE_C2)#define RVC_MATCH_C_EBREAK (RVC_ENCODE_FUNCT4(C_EBREAK) | RVC_OPCODE_C2) +#define RVG_MASK_AUIPC RV_INSN_OPCODE_MASK#define RVG_MASK_JALR (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK)#define RVG_MASK_JAL (RV_INSN_OPCODE_MASK)#define RVC_MASK_C_JALR (RVC_INSN_FUNCT4_MASK | RVC_INSN_J_RS2_MASK | RVC_INSN_OPCODE_MASK)
@@ -203,6 +206,7 @@ __RISCV_INSN_FUNCS(c_jal, RVC_MASK_C_JAL, RVC_MATCH_C_JAL)#else #define riscv_insn_is_c_jal (opcode) 0#endif +__RISCV_INSN_FUNCS(auipc, RVG_MASK_AUIPC, RVG_MATCH_AUIPC) __RISCV_INSN_FUNCS(jalr, RVG_MASK_JALR, RVG_MATCH_JALR) __RISCV_INSN_FUNCS(jal, RVG_MASK_JAL, RVG_MATCH_JAL)__RISCV_INSN_FUNCS (c_jr,RVC_MASK_C_JR ,RVC_MATCH_C_JR )
Signature · 7 lines
2.35.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 07/13] RISC-V: add auipc elements to parse_asm header
Quoted 2 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
RISC-V: add auipc elements toparse_asmheader
This header is no longer called parse_asm ;)
Quoted 1 line
We will want to use the opcode parsing outside kdb as well and need
Will we? Commit bikeshedding time, but mentioning the motivation would be appreciated.
Quoted 36 lines
at least the auipc element there.
Signed-off-by Heiko Stuebner <[email protected]>--- arch/riscv/include/asm/insn.h | 4 ++++ 1 file changed, 4 insertions(+)arch/riscv/include/asm/insn.h +3
-0@@ -118,6 +118,7 @@#define RVC_C2_RD_OPOFF 7/* parts of opcode for RVG*/ +#define RVG_OPCODE_AUIPC 0x17#define RVG_OPCODE_BRANCH 0x63#define RVG_OPCODE_JALR 0x67#define RVG_OPCODE_JAL 0x6f@@ -149,6 +150,7 @@#define RVG_FUNCT12_EBREAK 0x1#define RVG_FUNCT12_SRET 0x102 +#define RVG_MATCH_AUIPC (RVG_OPCODE_AUIPC)#define RVG_MATCH_JALR (RV_ENCODE_FUNCT3(JALR) | RVG_OPCODE_JALR)#define RVG_MATCH_JAL (RVG_OPCODE_JAL)#define RVG_MATCH_BEQ (RV_ENCODE_FUNCT3(BEQ) | RVG_OPCODE_BRANCH)@@ -167,6 +169,7 @@#define RVC_MATCH_C_JALR (RVC_ENCODE_FUNCT4(C_JALR) | RVC_OPCODE_C2)#define RVC_MATCH_C_EBREAK (RVC_ENCODE_FUNCT4(C_EBREAK) | RVC_OPCODE_C2) +#define RVG_MASK_AUIPC RV_INSN_OPCODE_MASK#define RVG_MASK_JALR (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK)#define RVG_MASK_JAL (RV_INSN_OPCODE_MASK)#define RVC_MASK_C_JALR (RVC_INSN_FUNCT4_MASK | RVC_INSN_J_RS2_MASK | RVC_INSN_OPCODE_MASK)
arch/riscv/include/asm/insn.h __RISCV_INSN_FUNCS(c_jal, RVC_MASK_C_JAL, RVC_MATCH_C_JAL) · line 212
Quoted 7 lines
arch/riscv/include/asm/insn.h +1
-0@@ -203,6 +206,7 @@ __RISCV_INSN_FUNCS(c_jal, RVC_MASK_C_JAL, RVC_MATCH_C_JAL)#else #define riscv_insn_is_c_jal (opcode) 0#endif +__RISCV_INSN_FUNCS(auipc, RVG_MASK_AUIPC, RVG_MATCH_AUIPC) __RISCV_INSN_FUNCS(jalr, RVG_MASK_JALR, RVG_MATCH_JALR) __RISCV_INSN_FUNCS(jal, RVG_MASK_JAL, RVG_MATCH_JAL)__RISCV_INSN_FUNCS (c_jr,RVC_MASK_C_JR ,RVC_MATCH_C_JR )
This fixes the build error that's been lingering for a few patches, so please re-order things so as not to break bisection :)
With the nits above fixed & assuming that this survives as its own commit:
Thanks,
Conor.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 07/13] RISC-V: add auipc elements to parse_asm header
Am Mittwoch, 30. November 2022, 00:36:12 CET schrieb Conor Dooley:
Quoted 5 lines · Heiko Stuebner
Quoted 2 lines
From: Heiko Stuebner <[email protected]>
RISC-V: add auipc elements toparse_asmheaderThis header is no longer called
parse_asm;)
With this commit moving more in front, the naming fits again ;-)
Quoted 11 lines
Quoted 4 lines
+__RISCV_INSN_FUNCS(auipc,
RVG_MASK_AUIPC,RVG_MATCH_AUIPC)
__RISCV_INSN_FUNCS(jalr, RVG_MASK_JALR, RVG_MATCH_JALR)__RISCV_INSN_FUNCS(jal, RVG_MASK_JAL, RVG_MATCH_JAL)__RISCV_INSN_FUNCS(c_jr, RVC_MASK_C_JR, RVC_MATCH_C_JR)This fixes the build error that's been lingering for a few patches, so please re-order things so as not to break bisection :)
With the nits above fixed & assuming that this survives as its own commit:
Reviewed-by Conor Dooley <[email protected]>
I've moved it more in front now and reworded the commit message a bit.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 07/13] RISC-V: add auipc elements to parse_asm header
In reply to Heiko StuebnerQuoted 9 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
We will want to use the opcode parsing outside kdb as well and need at least the auipc element there.
Signed-off-by Heiko Stuebner <[email protected]>--- arch/riscv/include/asm/insn.h | 4 ++++ 1 file changed, 4 insertions(+)
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v2 8/13 RISC-V: add U-type imm parsing to parse_asm header
In reply to Heiko StuebnerFrom: Heiko Stuebner <[email protected]>
Similar to other existing types, allow extracting the immediate for a U-type instruction.
U-type immediates are special in that regard, that the value in the instruction in bits [31:12] already represents the same bits of the immediate, so no shifting is required.
--- arch/riscv/include/asm/insn.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/riscv/include/asm/insn.h +13 -0
@@ -34,6 +34,15 @@#define RV_J_IMM_11_MASK GENMASK(0, 0)#define RV_J_IMM_19_12_MASK GENMASK(7, 0) +/* +* U-type IMMs contain the upper 20bits [31:20] of an immediate with +* the rest filled in by zeros, so no shifting required. Similarly, +* bit31 contains the signed state, so no sign extension necessary. +*/ +#define RV_U_IMM_SIGN_OPOFF 31 +#define RV_U_IMM_31_12_OPOFF 0 +#define RV_U_IMM_31_12_MASK GENMASK(31, 12) +/* The bit field of immediate value in B-type instruction */ #define RV_B_IMM_SIGN_OPOFF 31#define RV_B_IMM_10_5_OPOFF 25
@@ -235,6 +244,10 @@ static __always_inline bool riscv_insn_is_branch(u32 code)#define RV_X (X , s, mask) (((X) >> (s)) & (mask))#define RVC_X (X , s, mask) RV_X(X, s, mask) +#define RV_EXTRACT_UTYPE_IMM (x) \ + ({typeof(x) x_ = (x); \ + (RV_X(x_, RV_U_IMM_31_12_OPOFF, RV_U_IMM_31_12_MASK)); }) +#define RV_EXTRACT_JTYPE_IMM (x) \ ({typeof(x) x_ = (x); \ (RV_X(x_, RV_J_IMM_10_1_OPOFF, RV_J_IMM_10_1_MASK) << RV_J_IMM_10_1_OFF) | \
Signature · 7 lines
2.35.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 08/13] RISC-V: add U-type imm parsing to parse_asm header
Quoted 3 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
RISC-V: add U-type imm parsing to
parse_asmheader
Ditto.
Quoted 8 lines
Similar to other existing types, allow extracting the immediate for a U-type instruction.
U-type immediates are special in that regard, that the value in the instruction in bits [31:12] already represents the same bits of the immediate, so no shifting is required.
Signed-off-by Heiko Stuebner <[email protected]>
How is this different to the patch I left an R-b for on v1? It doesn't look different, so
?
Quoted 38 lines
--- arch/riscv/include/asm/insn.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)arch/riscv/include/asm/insn.h +13
-0@@ -34,6 +34,15 @@#define RV_J_IMM_11_MASK GENMASK(0, 0)#define RV_J_IMM_19_12_MASK GENMASK(7, 0) +/* +* U-type IMMs contain the upper 20bits [31:20] of an immediate with +* the rest filled in by zeros, so no shifting required. Similarly, +* bit31 contains the signed state, so no sign extension necessary. +*/ +#define RV_U_IMM_SIGN_OPOFF 31 +#define RV_U_IMM_31_12_OPOFF 0 +#define RV_U_IMM_31_12_MASK GENMASK(31, 12) +/* The bit field of immediate value in B-type instruction */ #define RV_B_IMM_SIGN_OPOFF 31#define RV_B_IMM_10_5_OPOFF 25@@ -235,6 +244,10 @@ static __always_inline bool riscv_insn_is_branch(u32 code)#define RV_X (X , s, mask) (((X) >> (s)) & (mask))#define RVC_X (X , s, mask) RV_X(X, s, mask) +#define RV_EXTRACT_UTYPE_IMM (x) \ + ({typeof(x) x_ = (x); \ + (RV_X(x_, RV_U_IMM_31_12_OPOFF, RV_U_IMM_31_12_MASK)); }) +#define RV_EXTRACT_JTYPE_IMM (x) \ ({typeof(x) x_ = (x); \ (RV_X(x_, RV_J_IMM_10_1_OPOFF, RV_J_IMM_10_1_MASK) << RV_J_IMM_10_1_OFF) | \Signature · 1 line
2.35.1
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 08/13] RISC-V: add U-type imm parsing to parse_asm header
Am Mittwoch, 30. November 2022, 00:38:32 CET schrieb Conor Dooley:
Quoted 10 lines · Heiko Stuebner
Quoted 3 lines
From: Heiko Stuebner <[email protected]>
RISC-V: add U-type imm parsing to
parse_asmheaderDitto.
Quoted 3 lines
Similar to other existing types, allow extracting the immediate for a U-type instruction.
Quoted 7 lines
Quoted 5 lines
U-type immediates are special in that regard, that the value in the instruction in bits [31:12] already represents the same bits of the immediate, so no shifting is required.
Signed-off-by Heiko Stuebner <[email protected]>How is this different to the patch I left an R-b for on v1?
Somehow with having changed so much for v2, it felt strange carrying over many of the R-b-s. Though yeah, this one could've made it :-)
Heiko
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 08/13] RISC-V: add U-type imm parsing to parse_asm header
Quoted 15 lines · Heiko Stübner
Am Mittwoch, 30. November 2022, 00:38:32 CET schrieb Conor Dooley:
Quoted 14 lines · Heiko Stuebner
Quoted 3 lines
From: Heiko Stuebner <[email protected]>
RISC-V: add U-type imm parsing to
parse_asmheaderDitto.
Quoted 7 lines
Similar to other existing types, allow extracting the immediate for a U-type instruction.
U-type immediates are special in that regard, that the value in the instruction in bits [31:12] already represents the same bits of the immediate, so no shifting is required.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Heiko Stuebner <[email protected]>How is this different to the patch I left an R-b for on v1?
Somehow with having changed so much for v2, it felt strange carrying over many of the R-b-s. Though yeah, this one could've made it :-)
Yah, hard to know what to do.. Worth mentioning it explicitly though I think if you do drop tags so that people know where they stand.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 08/13] RISC-V: add U-type imm parsing to parse_asm header
In reply to Heiko StuebnerQuoted 5 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
Similar to other existing types, allow extracting the immediate for a U-type instruction.
Quoted 8 lines
U-type immediates are special in that regard, that the value in the instruction in bits [31:12] already represents the same bits of the immediate, so no shifting is required.
Signed-off-by Heiko Stuebner <[email protected]>--- arch/riscv/include/asm/insn.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
With the s/parse_asm/insn/ <<<$SUBJECT that Conor pointed out.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v2 9/13 RISC-V: add rd reg parsing to parse_asm header
In reply to Heiko StuebnerFrom: Heiko Stuebner <[email protected]>
Add a macro to allow parsing of the rd register from an instruction.
--- arch/riscv/include/asm/insn.h | 5 +++++ 1 file changed, 5 insertions(+)
arch/riscv/include/asm/insn.h +5 -0
@@ -60,6 +60,7 @@#define RVG_RS1_OPOFF 15#define RVG_RS2_OPOFF 20#define RVG_RD_OPOFF 7 +#define RVG_RD_MASK GENMASK(4, 0)/* The bit field of immediate value in RVC J instruction */ #define RVC_J_IMM_SIGN_OPOFF 12
@@ -244,6 +245,10 @@ static __always_inline bool riscv_insn_is_branch(u32 code)#define RV_X (X , s, mask) (((X) >> (s)) & (mask))#define RVC_X (X , s, mask) RV_X(X, s, mask) +#define RV_EXTRACT_RD_REG (x) \ + ({typeof(x) x_ = (x); \ + (RV_X(x_, RVG_RD_OPOFF, RVG_RD_MASK)); }) +#define RV_EXTRACT_UTYPE_IMM (x) \ ({typeof(x) x_ = (x); \ (RV_X(x_, RV_U_IMM_31_12_OPOFF, RV_U_IMM_31_12_MASK)); })
Signature · 7 lines
2.35.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 09/13] RISC-V: add rd reg parsing to parse_asm header
Quoted 2 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
RISC-V: add rd reg parsing toparse_asmheader
Same as all these patches, they need the header name fixed up :)
Quoted 4 lines
Add a macro to allow parsing of the rd register from an instruction.
Signed-off-by Heiko Stuebner <[email protected]>
Again, looks to be otherwise the same as what I left an R-b for on v1?
Quoted 30 lines
--- arch/riscv/include/asm/insn.h | 5 +++++ 1 file changed, 5 insertions(+)arch/riscv/include/asm/insn.h +5
-0@@ -60,6 +60,7 @@#define RVG_RS1_OPOFF 15#define RVG_RS2_OPOFF 20#define RVG_RD_OPOFF 7 +#define RVG_RD_MASK GENMASK(4, 0)/* The bit field of immediate value in RVC J instruction */ #define RVC_J_IMM_SIGN_OPOFF 12@@ -244,6 +245,10 @@ static __always_inline bool riscv_insn_is_branch(u32 code)#define RV_X (X , s, mask) (((X) >> (s)) & (mask))#define RVC_X (X , s, mask) RV_X(X, s, mask) +#define RV_EXTRACT_RD_REG (x) \ + ({typeof(x) x_ = (x); \ + (RV_X(x_, RVG_RD_OPOFF, RVG_RD_MASK)); }) +#define RV_EXTRACT_UTYPE_IMM (x) \ ({typeof(x) x_ = (x); \ (RV_X(x_, RV_U_IMM_31_12_OPOFF, RV_U_IMM_31_12_MASK)); })Signature · 1 line
2.35.1
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 09/13] RISC-V: add rd reg parsing to parse_asm header
In reply to Heiko StuebnerQuoted 8 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
Add a macro to allow parsing of the rd register from an instruction.
Signed-off-by Heiko Stuebner <[email protected]>--- arch/riscv/include/asm/insn.h | 5 +++++ 1 file changed, 5 insertions(+)
With Conor's $SUBJECT correction,
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v2 10/13 RISC-V: fix auipc-jalr addresses in patched alternatives
In reply to Heiko StuebnerFrom: Heiko Stuebner <[email protected]>
Alternatives live in a different section, so addresses used by call functions will point to wrong locations after the patch got applied.
Similar to arm64, adjust the location to consider that offset.
--- arch/riscv/include/asm/alternative.h | 3 ++ arch/riscv/kernel/alternative.c | 72 ++++++++++++++++++++++++++++ arch/riscv/kernel/cpufeature.c | 11 ++++- 3 files changed, 84 insertions(+), 2 deletions(-)
arch/riscv/include/asm/alternative.h +3 -0
@@ -27,6 +27,9 @@ void __init apply_boot_alternatives(void);void __init apply_early_boot_alternatives (void );void apply_module_alternatives (void *start,size_t length); +void riscv_alternative_fix_auipc_jalr (void *alt_ptr,unsigned int len, +int patch_offset); +struct alt_entry {void *old_ptr;/* address of original instruciton or data */ void *alt_ptr;/* address of replacement instruction or data */
arch/riscv/kernel/alternative.c +72 -0
84 lines not on this page · raw message
arch/riscv/kernel/cpufeature.c +9 -2
@@ -316,8 +316,15 @@ void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin, } tmp = (1U << alt->errata_id); -if (cpu_req_feature & tmp) -patch_text_nosync (alt->old_ptr, alt->alt_ptr, alt->alt_len); +if (cpu_req_feature & tmp) { +/* do the basic patching */ +patch_text_nosync (alt->old_ptr, alt->alt_ptr, + alt->alt_len); + +riscv_alternative_fix_auipc_jalr (alt->old_ptr, + alt->alt_len, + alt->old_ptr - alt->alt_ptr); + } } }#endif
Signature · 7 lines
2.35.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 10/13] RISC-V: fix auipc-jalr addresses in patched alternatives
Quoted 8 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
Alternatives live in a different section, so addresses used by call functions will point to wrong locations after the patch got applied.
Similar to arm64, adjust the location to consider that offset.
Signed-off-by Heiko Stuebner <[email protected]>
This looks like an improved version of what I gave an R-b for last time?
Quoted 140 lines
--- arch/riscv/include/asm/alternative.h | 3 ++ arch/riscv/kernel/alternative.c | 72 ++++++++++++++++++++++++++++ arch/riscv/kernel/cpufeature.c | 11 ++++- 3 files changed, 84 insertions(+), 2 deletions(-)arch/riscv/include/asm/alternative.h +3
-0@@ -27,6 +27,9 @@ void __init apply_boot_alternatives(void);void __init apply_early_boot_alternatives (void );void apply_module_alternatives (void *start,size_t length); +void riscv_alternative_fix_auipc_jalr (void *alt_ptr,unsigned int len, +int patch_offset); +struct alt_entry {void *old_ptr;/* address of original instruciton or data */ void *alt_ptr;/* address of replacement instruction or data */ arch/riscv/kernel/alternative.c +72
-0@@ -15,6 +15,8 @@#include <asm/vendorid_list.h> #include <asm/sbi.h> #include <asm/csr.h> +#include <asm/insn.h> +#include <asm/patch.h> struct cpu_manufacturer_info_t {unsigned long vendor_id;@@ -53,6 +55,76 @@ static void __init_or_module riscv_fill_cpu_mfr_info(struct cpu_manufacturer_inf } } +static unsigned int riscv_instruction_at (void *p,unsigned int offset) +{ +u16 *parcel = p + (offset *sizeof (u32)); + +return (unsigned int )parcel[0 ] | (unsigned int )parcel[1 ] <<16 ; +} + +static inline bool riscv_insn_is_auipc_jalr (u32 insn1,u32 insn2) +{ +return riscv_insn_is_auipc (insn1) &&riscv_insn_is_jalr (insn2); +} + +#define JALR_SIGN_MASK BIT(RV_I_IMM_SIGN_OPOFF - RV_I_IMM_11_0_OPOFF) +#define AUIPC_PAD (0x00001000) + +#define to_jalr_imm (value) \ + ((value & RV_I_IMM_11_0_MASK) << RV_I_IMM_11_0_OPOFF) + +#define to_auipc_imm (value) \ + ((value & JALR_SIGN_MASK) ? \ + ((value & RV_U_IMM_31_12_MASK) + AUIPC_PAD) : \ + (value & RV_U_IMM_31_12_MASK)) + +void riscv_alternative_fix_auipc_jalr (void *alt_ptr,unsigned int len, +int patch_offset) +{ +int num_instr = len /sizeof (u32); +unsigned int call[2 ]; +int i; +int imm; +u32 rd1; + +/* +* stop one instruction before the end, as we're checking +* for auipc + jalr +*/ +for (i =0 ; i < num_instr -1 ; i++) { +u32 inst1 =riscv_instruction_at (alt_ptr, i); +u32 inst2 =riscv_instruction_at (alt_ptr, i +1 ); + +if (!riscv_insn_is_auipc_jalr (inst1, inst2)) +continue ; + +/* call will use ra register */ + rd1 =RV_EXTRACT_RD_REG (inst1); +if (rd1 !=1 ) +continue ; + +/* get and adjust new target address */ + imm =RV_EXTRACT_UTYPE_IMM (inst1); + imm +=RV_EXTRACT_ITYPE_IMM (inst2); + imm -= patch_offset; + +/* pick the original auipc + jalr */ + call[0 ] = inst1; + call[1 ] = inst2; + +/* drop the old IMMs */ + call[0 ] &= ~(RV_U_IMM_31_12_MASK ); + call[1 ] &= ~(RV_I_IMM_11_0_MASK <<RV_I_IMM_11_0_OPOFF ); + +/* add the adapted IMMs */ + call[0 ] |=to_auipc_imm (imm); + call[1 ] |=to_jalr_imm (imm); + +/* patch the call place again */ +patch_text_nosync (alt_ptr + i *sizeof (u32), call,8 ); + } +} +/* * This is called very early in the boot process (directly after we run * a feature detect on the boot CPU). No need to worry about other CPUs arch/riscv/kernel/cpufeature.c +9
-2@@ -316,8 +316,15 @@ void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin, } tmp = (1U << alt->errata_id); -if (cpu_req_feature & tmp) -patch_text_nosync (alt->old_ptr, alt->alt_ptr, alt->alt_len); +if (cpu_req_feature & tmp) { +/* do the basic patching */ +patch_text_nosync (alt->old_ptr, alt->alt_ptr, + alt->alt_len); + +riscv_alternative_fix_auipc_jalr (alt->old_ptr, + alt->alt_len, + alt->old_ptr - alt->alt_ptr); + } } }#endif Signature · 7 lines
2.35.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v2 11/13 efi/riscv: libstub: mark when compiling libstub
In reply to Heiko StuebnerFrom: Heiko Stuebner <[email protected]>
We may want to runtime-optimize some core functions (str*, mem*), but not have this leak into libstub and cause build issues. Instead libstub, for the short while it's running, should just use the generic implementation.
So, to be able to determine whether functions, that are used both in libstub and the main kernel, are getting compiled as part of libstub or not, add a compile-flag we can check via #ifdef.
--- drivers/firmware/efi/libstub/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/libstub/Makefile +1 -1
@@ -25,7 +25,7 @@ cflags-$(CONFIG_ARM) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \ -fno-builtin -fpic \ $(call cc-option,-mno-single-pic-base) cflags-$(CONFIG_RISCV) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \ - -fpic + -fpic -DRISCV_EFISTUB cflags-$(CONFIG_LOONGARCH) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \ -fpie
Signature · 7 lines
2.35.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v2 12/13 RISC-V: add infrastructure to allow different str* implementations
In reply to Heiko StuebnerFrom: Heiko Stuebner <[email protected]>
Depending on supported extensions on specific RISC-V cores, optimized str* functions might make sense.
This adds basic infrastructure to allow patching the function calls via alternatives later on.
The main idea is to have the core str* functions be inline functions which then call the most optimized variant and this call then be replaced via alternatives.
The big advantage is that we don't need additional calls. Though we need to duplicate the generic functions as the main code expects either itself or the architecture to provide the str* functions.
The added *_generic functions are done in assembler (taken from disassembling the main-kernel functions for now) to allow us to control the used registers.
--- arch/riscv/include/asm/string.h | 66 +++++++++++++++++++++++++++++++++ arch/riscv/kernel/image-vars.h | 6 +-- arch/riscv/lib/Makefile | 3 ++ arch/riscv/lib/strcmp.S | 38 +++++++++++++++++++ arch/riscv/lib/strlen.S | 29 +++++++++++++++ arch/riscv/lib/strncmp.S | 41 ++++++++++++++++++++ 6 files changed, 180 insertions(+), 3 deletions(-) create mode 100644 arch/riscv/lib/strcmp.S create mode 100644 arch/riscv/lib/strlen.S create mode 100644 arch/riscv/lib/strncmp.S
arch/riscv/include/asm/string.h +66 -0
@@ -18,6 +18,72 @@ extern asmlinkage void *__memcpy(void *, const void *, size_t);#define __HAVE_ARCH_MEMMOVE extern asmlinkage void *memmove(void *, const void *, size_t); extern asmlinkage void *__memmove(void *, const void *, size_t); + +#define __HAVE_ARCH_STRCMP +extern asmlinkage int __strcmp_generic(const char *cs, const char *ct); + +static inline int strcmp (const char *cs,const char *ct) +{ +#ifdef RISCV_EFISTUB +return __strcmp_generic (cs, ct); +#else + register const char *a0 asm("a0") = cs; + register const char *a1 asm("a1") = ct; + registerint a0_out asm("a0" ); + + asmvolatile ("call __strcmp_generic\n\t" + :"=r" (a0_out) + :"r" (a0),"r" (a1) + :"ra" ,"t0" ,"t1" ,"t2" ); + +return a0_out; +#endif +} + +#define __HAVE_ARCH_STRNCMP +extern asmlinkage int __strncmp_generic(const char *cs, +const char *ct,size_t count); + +static inline int strncmp (const char *cs,const char *ct,size_t count) +{ +#ifdef RISCV_EFISTUB +return __strncmp_generic (cs, ct, count); +#else + register const char *a0 asm("a0") = cs; + register const char *a1 asm("a1") = ct; + register size_t a2 asm("a2") = count; + registerint a0_out asm("a0" ); + + asmvolatile ("call __strncmp_generic\n\t" + :"=r" (a0_out) + :"r" (a0),"r" (a1),"r" (a2) + :"ra" ,"t0" ,"t1" ,"t2" ); + +return a0_out; +#endif +} + +#define __HAVE_ARCH_STRLEN +extern asmlinkage __kernel_size_t __strlen_generic(const char *); + +static inline __kernel_size_t strlen (const char *s) +{ +#ifdef RISCV_EFISTUB +return __strlen_generic (s); +#else + register const char *a0 asm("a0") = s; + registerint a0_out asm("a0" ); + + asmvolatile ( +"call __strlen_generic\n\t" + :"=r" (a0_out) + :"r" (a0) + :"ra" ,"t0" ,"t1" ); + +return a0_out; +#endif +} +/* For those files which don't want to check by kasan. */ #if defined(CONFIG_KASAN ) && !defined(__SANITIZE_ADDRESS__)#define memcpy (dst, src, len) __memcpy(dst, src, len)
arch/riscv/kernel/image-vars.h +3 -3
@@ -25,10 +25,10 @@*/ __efistub_memcmp = memcmp; __efistub_memchr = memchr; -__efistub_strlen = strlen; +__efistub___strlen_generic = __strlen_generic; __efistub_strnlen = strnlen; -__efistub_strcmp = strcmp; -__efistub_strncmp = strncmp; +__efistub___strcmp_generic = __strcmp_generic; +__efistub___strncmp_generic = __strncmp_generic; __efistub_strrchr = strrchr; __efistub__start = _start;
arch/riscv/lib/Makefile +3 -0
@@ -3,6 +3,9 @@ lib-y += delay.o lib-y += memcpy.o lib-y += memset.o lib-y += memmove.o +lib-y += strcmp.o +lib-y += strlen.o +lib-y += strncmp.o lib-$(CONFIG_MMU) += uaccess.o lib-$(CONFIG_64BIT) += tishift.o
arch/riscv/lib/strcmp.S new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <linux/linkage.h> +#include <asm/asm.h> +#include <asm-generic/export.h> + +/* int __strcmp_generic(const char *cs, const char *ct) */ +ENTRY(__strcmp_generic) + /* + * Returns + * a0 - comparison result, value like strcmp + * + * Parameters + * a0 - string1 + * a1 - string2 + * + * Clobbers + * t0, t1, t2 + */ + mv t2, a1 +1: + lbu t1, 0(a0) + lbu t0, 0(a1) + addi a0, a0, 1 + addi a1, a1, 1 + beq t1, t0, 3f + li a0, 1 + bgeu t1, t0, 2f + li a0, -1 +2: + mv a1, t2 + ret +3: + bnez t1, 1b + li a0, 0 + j 2b +END(__strcmp_generic) +EXPORT_SYMBOL(__strcmp_generic)
arch/riscv/lib/strlen.S new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <linux/linkage.h> +#include <asm/asm.h> +#include <asm-generic/export.h> + +/* int __strlen_generic(const char *s) */ +ENTRY(__strlen_generic) + /* + * Returns + * a0 - string length + * + * Parameters + * a0 - String to measure + * + * Clobbers: + * t0, t1 + */ + mv t1, a0 +1: + lbu t0, 0(t1) + bnez t0, 2f + sub a0, t1, a0 + ret +2: + addi t1, t1, 1 + j 1b +END(__strlen_generic) +EXPORT_SYMBOL(__strlen_generic)
arch/riscv/lib/strncmp.S new file +41 -0
41 lines not on this page · raw message
Signature · 7 lines
2.35.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH v2 13/13 RISC-V: add zbb support to string functions
In reply to Heiko StuebnerFrom: Heiko Stuebner <[email protected]>
Add handling for ZBB extension and add support for using it as a variant for optimized string functions.
--- arch/riscv/Kconfig | 23 ++++++ arch/riscv/include/asm/errata_list.h | 3 +- arch/riscv/include/asm/hwcap.h | 1 + arch/riscv/include/asm/string.h | 29 +++++-- arch/riscv/kernel/cpu.c | 1 + arch/riscv/kernel/cpufeature.c | 18 +++++ arch/riscv/lib/Makefile | 3 + arch/riscv/lib/strcmp_zbb.S | 96 ++++++++++++++++++++++ arch/riscv/lib/strlen_zbb.S | 115 +++++++++++++++++++++++++++ arch/riscv/lib/strncmp_zbb.S | 112 ++++++++++++++++++++++++++ 10 files changed, 394 insertions(+), 7 deletions(-) create mode 100644 arch/riscv/lib/strcmp_zbb.S create mode 100644 arch/riscv/lib/strlen_zbb.S create mode 100644 arch/riscv/lib/strncmp_zbb.S
arch/riscv/Kconfig +23 -0
@@ -411,6 +411,29 @@ config RISCV_ISA_SVPBMT If you don't know what to do here, say Y. +config TOOLCHAIN_HAS_ZBB + bool + default y + depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zbb) + depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbb) + depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900 + +config RISCV_ISA_ZBB + bool "Zbb extension support for bit manipulation instructions" + depends on TOOLCHAIN_HAS_ZBB + depends on !XIP_KERNEL && MMU + select RISCV_ALTERNATIVE + default y + help + Adds support to dynamically detect the presence of the ZBB + extension (basic bit manipulation) and enable its usage. + + The Zbb extension provides instructions to accelerate a number + of bit-specific operations (count bit population, sign extending, + bitrotation, etc). + + If you don't know what to do here, say Y. + config TOOLCHAIN_HAS_ZICBOM bool default y
arch/riscv/include/asm/errata_list.h +2 -1
@@ -24,7 +24,8 @@#define CPUFEATURE_SVPBMT 0#define CPUFEATURE_ZICBOM 1 -#define CPUFEATURE_NUMBER 2 +#define CPUFEATURE_ZBB 2 +#define CPUFEATURE_NUMBER 3#ifdef __ASSEMBLY__
arch/riscv/include/asm/hwcap.h +1 -0
@@ -59,6 +59,7 @@ enum riscv_isa_ext_id {RISCV_ISA_EXT_ZIHINTPAUSE ,RISCV_ISA_EXT_SSTC ,RISCV_ISA_EXT_SVINVAL , +RISCV_ISA_EXT_ZBB , RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX, };
arch/riscv/include/asm/string.h +23 -6
@@ -6,6 +6,8 @@#ifndef _ASM_RISCV_STRING_H#define _ASM_RISCV_STRING_H +#include <asm/alternative-macros.h> +#include <asm/errata_list.h> #include <linux/types.h> #include <linux/linkage.h>
@@ -21,6 +23,7 @@ extern asmlinkage void *__memmove(void *, const void *, size_t);#define __HAVE_ARCH_STRCMP extern asmlinkage int __strcmp_generic(const char *cs, const char *ct); +extern asmlinkage int __strcmp_zbb(const char *cs, const char *ct);static inline int strcmp (const char *cs,const char *ct) {
@@ -31,10 +34,14 @@ static inline int strcmp(const char *cs, const char *ct) register const char *a1 asm("a1") = ct; registerint a0_out asm("a0" ); - asmvolatile ("call __strcmp_generic\n\t" + asm volatile( + ALTERNATIVE( + "call __strcmp_generic\n\t", + "call __strcmp_zbb\n\t", + 0, CPUFEATURE_ZBB, CONFIG_RISCV_ISA_ZBB) : "=r"(a0_out) : "r"(a0), "r"(a1) - :"ra" ,"t0" ,"t1" ,"t2" ); + : "ra", "t0", "t1", "t2", "t3", "t4", "t5");return a0_out;#endif
@@ -43,6 +50,8 @@ static inline int strcmp(const char *cs, const char *ct)#define __HAVE_ARCH_STRNCMP extern asmlinkage int __strncmp_generic(const char *cs,const char *ct,size_t count); +extern asmlinkage int __strncmp_zbb(const char *cs, +const char *ct,size_t count);static inline int strncmp (const char *cs,const char *ct,size_t count) {
@@ -54,10 +63,14 @@ static inline int strncmp(const char *cs, const char *ct, size_t count) register size_t a2 asm("a2") = count; registerint a0_out asm("a0" ); - asmvolatile ("call __strncmp_generic\n\t" + asm volatile( + ALTERNATIVE( + "call __strncmp_generic\n\t", + "call __strncmp_zbb\n\t", + 0, CPUFEATURE_ZBB, CONFIG_RISCV_ISA_ZBB) : "=r"(a0_out) : "r"(a0), "r"(a1), "r"(a2) - :"ra" ,"t0" ,"t1" ,"t2" ); + : "ra", "t0", "t1", "t2", "t3", "t4", "t5", "t6");return a0_out;#endif
@@ -65,6 +78,7 @@ static inline int strncmp(const char *cs, const char *ct, size_t count)#define __HAVE_ARCH_STRLEN extern asmlinkage __kernel_size_t __strlen_generic(const char *); +extern asmlinkage __kernel_size_t __strlen_zbb(const char *);static inline __kernel_size_t strlen (const char *s) {
@@ -75,10 +89,13 @@ static inline __kernel_size_t strlen(const char *s) registerint a0_out asm("a0" ); asm volatile( -"call __strlen_generic\n\t" + ALTERNATIVE( + "call __strlen_generic\n\t", + "call __strlen_zbb\n\t", + 0, CPUFEATURE_ZBB, CONFIG_RISCV_ISA_ZBB) : "=r"(a0_out) : "r"(a0) - :"ra" ,"t0" ,"t1" ); + : "ra", "t0", "t1", "t2", "t3");return a0_out;#endif
arch/riscv/kernel/cpu.c +1 -0
@@ -162,6 +162,7 @@ arch_initcall(riscv_cpuinfo_init);* extensions by an underscore. */ static struct riscv_isa_ext_data isa_ext_arr[] = { +__RISCV_ISA_EXT_DATA (zbb,RISCV_ISA_EXT_ZBB ),__RISCV_ISA_EXT_DATA (sscofpmf,RISCV_ISA_EXT_SSCOFPMF ),__RISCV_ISA_EXT_DATA (sstc,RISCV_ISA_EXT_SSTC ),__RISCV_ISA_EXT_DATA (svinval,RISCV_ISA_EXT_SVINVAL ),
arch/riscv/kernel/cpufeature.c +18 -0
@@ -199,6 +199,7 @@ void __init riscv_fill_hwcap(void) this_hwcap |= isa2hwcap[(unsigned char )(*ext)];set_bit (*ext -'a' , this_isa); }else { +SET_ISA_EXT_MAP ("zbb" ,RISCV_ISA_EXT_ZBB );SET_ISA_EXT_MAP ("sscofpmf" ,RISCV_ISA_EXT_SSCOFPMF );SET_ISA_EXT_MAP ("svpbmt" ,RISCV_ISA_EXT_SVPBMT );SET_ISA_EXT_MAP ("zicbom" ,RISCV_ISA_EXT_ZICBOM );
@@ -278,6 +279,20 @@ static bool __init_or_module cpufeature_probe_zicbom(unsigned int stage)return true; } +static bool __init_or_module cpufeature_probe_zbb(unsigned int stage) +{ +if (!IS_ENABLED (CONFIG_RISCV_ISA_ZBB )) +return false; + +if (stage ==RISCV_ALTERNATIVES_EARLY_BOOT ) +return false; + +if (!riscv_isa_extension_available (NULL ,ZBB )) +return false; + +return true; +} +/* * Probe presence of individual extensions. *
@@ -295,6 +310,9 @@ static u32 __init_or_module cpufeature_probe(unsigned int stage)if (cpufeature_probe_zicbom (stage)) cpu_req_feature |=BIT (CPUFEATURE_ZICBOM ); +if (cpufeature_probe_zbb (stage)) + cpu_req_feature |=BIT (CPUFEATURE_ZBB ); +return cpu_req_feature; }
arch/riscv/lib/Makefile +3 -0
@@ -4,8 +4,11 @@ lib-y += memcpy.o lib-y += memset.o lib-y += memmove.o lib-y += strcmp.o +lib-$(CONFIG_RISCV_ISA_ZBB) += strcmp_zbb.o lib-y += strlen.o +lib-$(CONFIG_RISCV_ISA_ZBB) += strlen_zbb.o lib-y += strncmp.o +lib-$(CONFIG_RISCV_ISA_ZBB) += strncmp_zbb.o lib-$(CONFIG_MMU) += uaccess.o lib-$(CONFIG_64BIT) += tishift.o
arch/riscv/lib/strcmp_zbb.S new file +96 -0
96 lines not on this page · raw message
arch/riscv/lib/strlen_zbb.S new file +115 -0
115 lines not on this page · raw message
arch/riscv/lib/strncmp_zbb.S new file +112 -0
112 lines not on this page · raw message
Signature · 7 lines
2.35.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 13/13] RISC-V: add zbb support to string functions
Quoted 15 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
Add handling for ZBB extension and add support for using it as a variant for optimized string functions.
Co-developed-by Christoph Muellner <[email protected]>Signed-off-by Christoph Muellner <[email protected]>Signed-off-by Heiko Stuebner <[email protected]>---
arch/riscv/include/asm/errata_list.h +0
-0
arch/riscv/include/asm/errata_list.h line 27
Quoted 5 lines
arch/riscv/include/asm/errata_list.h +1
-1@@ -24,7 +24,8 @@#define CPUFEATURE_SVPBMT 0#define CPUFEATURE_ZICBOM 1 -#define CPUFEATURE_NUMBER 2 +#define CPUFEATURE_ZBB 2
I was going to complain that you did not align these but none of the other "errata" are /shrug
arch/riscv/include/asm/hwcap.h enum riscv_isa_ext_id { · line 62
Quoted 13 lines
arch/riscv/include/asm/errata_list.h +1
-0+#define CPUFEATURE_NUMBER 3#ifdef __ASSEMBLY__arch/riscv/include/asm/hwcap.h +1
-0@@ -59,6 +59,7 @@ enum riscv_isa_ext_id {RISCV_ISA_EXT_ZIHINTPAUSE ,RISCV_ISA_EXT_SSTC ,RISCV_ISA_EXT_SVINVAL , + RISCV_ISA_EXT_ZBB,
I'll avoid commenting on this for now haha. I've caused enough havoc.
Quoted 21 lines
arch/riscv/include/asm/hwcap.h +0
-0RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX, };arch/riscv/kernel/cpu.c +1
-0@@ -162,6 +162,7 @@ arch_initcall(riscv_cpuinfo_init);* extensions by an underscore. */ static struct riscv_isa_ext_data isa_ext_arr[] = { +__RISCV_ISA_EXT_DATA (zbb,RISCV_ISA_EXT_ZBB ),__RISCV_ISA_EXT_DATA (sscofpmf,RISCV_ISA_EXT_SSCOFPMF ),__RISCV_ISA_EXT_DATA (sstc,RISCV_ISA_EXT_SSTC ),__RISCV_ISA_EXT_DATA (svinval,RISCV_ISA_EXT_SVINVAL ),arch/riscv/kernel/cpufeature.c +0
-0
arch/riscv/kernel/cpufeature.c void __init riscv_fill_hwcap(void) · line 205
Quoted 7 lines
arch/riscv/kernel/cpufeature.c +1
-0@@ -199,6 +199,7 @@ void __init riscv_fill_hwcap(void) this_hwcap |= isa2hwcap[(unsigned char )(*ext)];set_bit (*ext -'a' , this_isa); }else { +SET_ISA_EXT_MAP ("zbb" ,RISCV_ISA_EXT_ZBB );SET_ISA_EXT_MAP ("sscofpmf" ,RISCV_ISA_EXT_SSCOFPMF );SET_ISA_EXT_MAP ("svpbmt" ,RISCV_ISA_EXT_SVPBMT );SET_ISA_EXT_MAP ("zicbom" ,RISCV_ISA_EXT_ZICBOM );
This all looks fair, and since I was happy with it matching the "reference" implementation in the spec doc etc last time & you've cleaned up the readability bits & bobs:
Thanks,
Conor.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 13/13] RISC-V: add zbb support to string functions
In reply to Heiko StuebnerQuoted 21 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
Add handling for ZBB extension and add support for using it as a variant for optimized string functions.
Co-developed-by Christoph Muellner <[email protected]>Signed-off-by Christoph Muellner <[email protected]>Signed-off-by Heiko Stuebner <[email protected]>arch/riscv/Kconfig +12
-0+config TOOLCHAIN_HAS_ZBB + bool + default y + depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zbb) + depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbb) + depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900 + +config RISCV_ISA_ZBB + bool "Zbb extension support for bit manipulation instructions" + depends on TOOLCHAIN_HAS_ZBB + depends on !XIP_KERNEL && MMU + select RISCV_ALTERNATIVE
arch/riscv/Kconfig config RISCV_ISA_SVPBMT · line 435
Quoted 10 lines
arch/riscv/Kconfig +10
-0+ default y + help + Adds support to dynamically detect the presence of the ZBB + extension (basic bit manipulation) and enable its usage. + + The Zbb extension provides instructions to accelerate a number + of bit-specific operations (count bit population, sign extending, + bitrotation, etc). + + If you don't know what to do here, say Y.
/stuff/linux/arch/riscv/lib/strncmp_zbb.S:23:9: warning: unknown option, expected 'push', 'pop', 'rvc', 'norvc', 'relax' or 'norelax' .option arch,+zbb
^
/stuff/linux/arch/riscv/lib/strncmp_zbb.S:56:2: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation) or 'Zbp' (Permutation 'Zb' Instructions)
orc.b t3, t0
^
/stuff/linux/arch/riscv/lib/strncmp_zbb.S:67:2: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation) or 'Zbp' (Permutation 'Zb' Instructions) or 'Zbkb' (Bitmanip instructions for Cryptography)
rev8 t0, t0
^
/stuff/linux/arch/riscv/lib/strncmp_zbb.S:68:2: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation) or 'Zbp' (Permutation 'Zb' Instructions) or 'Zbkb' (Bitmanip instructions for Cryptography)
rev8 t1, t1
^
make[4]: *** [/stuff/linux/scripts/Makefile.build:382: arch/riscv/lib/strncmp_zbb.o] Error 1
So there's something wrong in 13/13 somewhere, but the failure itself is a bit odd? At least, at odds with your support stuff here.
CONFIG_CC_VERSION_TEXT="ClangBuiltLinux clang version 15.0.4 (5c68a1cb123161b54b72ce90e7975d95a8eaf2a4)" CONFIG_CC_IS_CLANG=yCONFIG_CLANG_VERSION=150004CONFIG_AS_IS_LLVM=yCONFIG_AS_VERSION=150004CONFIG_LD_IS_LLD=yCONFIG_LLD_VERSION=150004
Thanks,
Conor.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [PATCH v2 13/13] RISC-V: add zbb support to string functions
Am Mittwoch, 30. November 2022, 18:14:49 CET schrieb Conor Dooley:
Quoted 47 lines · Heiko Stuebner
Quoted 21 lines
From: Heiko Stuebner <[email protected]>
Add handling for ZBB extension and add support for using it as a variant for optimized string functions.
Co-developed-by Christoph Muellner <[email protected]>Signed-off-by Christoph Muellner <[email protected]>Signed-off-by Heiko Stuebner <[email protected]>arch/riscv/Kconfig +12
-0+config TOOLCHAIN_HAS_ZBB + bool + default y + depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zbb) + depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbb) + depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900 + +config RISCV_ISA_ZBB + bool "Zbb extension support for bit manipulation instructions" + depends on TOOLCHAIN_HAS_ZBB + depends on !XIP_KERNEL && MMU + select RISCV_ALTERNATIVEarch/riscv/Kconfig config RISCV_ISA_SVPBMT · line 435
Quoted 10 lines
arch/riscv/Kconfig +10
-0+ default y + help + Adds support to dynamically detect the presence of the ZBB + extension (basic bit manipulation) and enable its usage. + + The Zbb extension provides instructions to accelerate a number + of bit-specific operations (count bit population, sign extending, + bitrotation, etc). + + If you don't know what to do here, say Y./stuff/linux/arch/riscv/lib/strncmp_zbb.S:23:9: warning: unknown option, expected 'push', 'pop', 'rvc', 'norvc', 'relax' or 'norelax' .option arch,+zbb
^/stuff/linux/arch/riscv/lib/strncmp_zbb.S:56:2: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation) or 'Zbp' (Permutation 'Zb' Instructions)
orc.b t3, t0
^
/stuff/linux/arch/riscv/lib/strncmp_zbb.S:67:2: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation) or 'Zbp' (Permutation 'Zb' Instructions) or 'Zbkb' (Bitmanip instructions for Cryptography)
rev8 t0, t0
^
/stuff/linux/arch/riscv/lib/strncmp_zbb.S:68:2: error: instruction requires the following: 'Zbb' (Basic Bit-Manipulation) or 'Zbp' (Permutation 'Zb' Instructions) or 'Zbkb' (Bitmanip instructions for Cryptography)
rev8 t1, t1
^
make[4]: *** [/stuff/linux/scripts/Makefile.build:382:arch/riscv/lib/strncmp_zbb.o] Error 1
Quoted 2 lines
So there's something wrong in 13/13 somewhere, but the failure itself is a bit odd? At least, at odds with your support stuff here.
Thanks to google I now know that llvm doesn't support the arch directive yet [0]. The rest is of course just fallout, because of the not-enabled zbb support.
That review over there also seems to be going slowly, so I guess for the time being I need way stricter depends, limiting this to binutils.
[0] https://reviews.llvm.org/D123515
Quoted 8 lines
CONFIG_CC_VERSION_TEXT="ClangBuiltLinuxclang version 15.0.4 (5c68a1cb123161b54b72ce90e7975d95a8eaf2a4)"CONFIG_CC_IS_CLANG=yCONFIG_CLANG_VERSION=150004CONFIG_AS_IS_LLVM=yCONFIG_AS_VERSION=150004CONFIG_LD_IS_LLD=yCONFIG_LLD_VERSION=150004
Quoted 4 lines
Thanks,
Conor.
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Yo Heiko,
Quoted 33 lines · Heiko Stuebner
From: Heiko Stuebner <[email protected]>
The Zbb extension can be used to make string functions run a lot faster.
To allow There are essentially two problems to solve:
- making it possible for str* functions to replace what they do in a performant wayThis is done by inlining the core functions and then using alternatives to call the actual variant.
This of course will need a more intelligent selection mechanism down the road when more variants may exist using different available extensions.
- actually allowing calls in alternatives
Function calls use auipc + jalr to reach those 32bit relative addresses but when they're compiled the offset will be wrong as alternatives live in a different section. So when the patch gets applied the address will point to the wrong location.So similar to arm64 the target addresses need to be updated.
This is probably also helpful for other things needing more complex code in alternatives.
In my half-scientific test-case of running the functions in question on a 95 character string in a loop of 10000 iterations, the Zbb variants shave off around 2/3 of the original runtime.
Quoted 5 lines
For v2 I got into some sort of cleanup spree for the general instruction parsing that already existed. A number of places do their own instruction parsing and I tried consolidating some of them.
Noteable, the kvm parts still do, but I had to stop somewhere :-)
One minor thing, since I don't see it mentioned nor a base-commit, could you note what the series is based on? I'm sure by the time this is closer to being applied it will be capable of being build automagically but for now (at least on the patchwork side of things) it's not being built as it cannot figure out where to apply it:
https://patchwork.kernel.org/project/linux-riscv/list/?series=699641
Thanks,
Conor.
Quoted 51 lines
changes since v1:
- a number of generalizations/cleanups for instruction parsing
- use accessor function to access instructions (Emil)
- actually patch the correct location when having more than one instruction in an alternative block
- string function cleanups (comments etc) (Conor)
- move zbb extension above s* extensions incpu.clistschanges since rfc:
- make Zbb code actually work
- drop some unneeded patches
- a lot of cleanupsHeiko Stuebner (13):
RISC-V: add prefix to all constants/macros inparse_asm.h
RISC-V: detach funct-values from their offset
RISC-V: add ebreak instructions to definitions
RISC-V: Move riscv_insn_is_* macros into a common header
RISC-V: renameparse_asm.htoinsn.h
RISC-V: kprobes: use central defined funct3 constants
RISC-V: add auipc elements toparse_asmheader
RISC-V: add U-type imm parsing toparse_asmheader
RISC-V: add rd reg parsing toparse_asmheader
RISC-V: fix auipc-jalr addresses in patched alternatives efi/riscv: libstub: mark when compiling libstub
RISC-V: add infrastructure to allow different str* implementations
RISC-V: add zbb support to string functionsarch/riscv/Kconfig | 23 ++ arch/riscv/include/asm/alternative.h | 3 + arch/riscv/include/asm/errata_list.h | 3 +- arch/riscv/include/asm/hwcap.h | 1 + arch/riscv/include/asm/insn.h | 292 +++++++++++++++++++++++ arch/riscv/include/asm/parse_asm.h | 219 ----------------- arch/riscv/include/asm/string.h | 83 +++++++ arch/riscv/kernel/alternative.c | 72 ++++++ arch/riscv/kernel/cpu.c | 1 + arch/riscv/kernel/cpufeature.c | 29 ++- arch/riscv/kernel/image-vars.h | 6 +- arch/riscv/kernel/kgdb.c | 63 ++--- arch/riscv/kernel/probes/simulate-insn.c | 19 +- arch/riscv/kernel/probes/simulate-insn.h | 26 +- arch/riscv/lib/Makefile | 6 + arch/riscv/lib/strcmp.S | 38 +++ arch/riscv/lib/strcmp_zbb.S | 96 ++++++++ arch/riscv/lib/strlen.S | 29 +++ arch/riscv/lib/strlen_zbb.S | 115 +++++++++ arch/riscv/lib/strncmp.S | 41 ++++ arch/riscv/lib/strncmp_zbb.S | 112 +++++++++ drivers/firmware/efi/libstub/Makefile | 2 +- 22 files changed, 978 insertions(+), 301 deletions(-)
Quoted 12 lines
create mode 100644 arch/riscv/include/asm/insn.h delete mode 100644 arch/riscv/include/asm/parse_asm.h create mode 100644 arch/riscv/lib/strcmp.S create mode 100644 arch/riscv/lib/strcmp_zbb.S create mode 100644 arch/riscv/lib/strlen.S create mode 100644 arch/riscv/lib/strlen_zbb.S create mode 100644 arch/riscv/lib/strncmp.S create mode 100644 arch/riscv/lib/strncmp_zbb.SSignature · 1 line
2.35.1
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv