@@ -577,6 +577,24 @@ static void emit_stx_insn(u8 rd, s16 off, u8 rs, u8 size, struct rv_jit_context
577577 }
578578}
579579
580+ static int emit_st (u8 rd , s16 off , s32 imm , u8 size , struct rv_jit_context * ctx )
581+ {
582+ int insns_start ;
583+
584+ emit_imm (RV_REG_T1 , imm , ctx );
585+ if (is_12b_int (off )) {
586+ insns_start = ctx -> ninsns ;
587+ emit_stx_insn (rd , off , RV_REG_T1 , size , ctx );
588+ return ctx -> ninsns - insns_start ;
589+ }
590+
591+ emit_imm (RV_REG_T2 , off , ctx );
592+ emit_add (RV_REG_T2 , RV_REG_T2 , rd , ctx );
593+ insns_start = ctx -> ninsns ;
594+ emit_stx_insn (RV_REG_T2 , 0 , RV_REG_T1 , size , ctx );
595+ return ctx -> ninsns - insns_start ;
596+ }
597+
580598static int emit_stx (u8 rd , s16 off , u8 rs , u8 size , struct rv_jit_context * ctx )
581599{
582600 int insns_start ;
@@ -1870,128 +1888,27 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
18701888
18711889 /* ST: *(size *)(dst + off) = imm */
18721890 case BPF_ST | BPF_MEM | BPF_B :
1873- emit_imm (RV_REG_T1 , imm , ctx );
1874- if (is_12b_int (off )) {
1875- emit (rv_sb (rd , off , RV_REG_T1 ), ctx );
1876- break ;
1877- }
1878-
1879- emit_imm (RV_REG_T2 , off , ctx );
1880- emit_add (RV_REG_T2 , RV_REG_T2 , rd , ctx );
1881- emit (rv_sb (RV_REG_T2 , 0 , RV_REG_T1 ), ctx );
1882- break ;
1883-
18841891 case BPF_ST | BPF_MEM | BPF_H :
1885- emit_imm (RV_REG_T1 , imm , ctx );
1886- if (is_12b_int (off )) {
1887- emit (rv_sh (rd , off , RV_REG_T1 ), ctx );
1888- break ;
1889- }
1890-
1891- emit_imm (RV_REG_T2 , off , ctx );
1892- emit_add (RV_REG_T2 , RV_REG_T2 , rd , ctx );
1893- emit (rv_sh (RV_REG_T2 , 0 , RV_REG_T1 ), ctx );
1894- break ;
18951892 case BPF_ST | BPF_MEM | BPF_W :
1896- emit_imm (RV_REG_T1 , imm , ctx );
1897- if (is_12b_int (off )) {
1898- emit_sw (rd , off , RV_REG_T1 , ctx );
1899- break ;
1900- }
1901-
1902- emit_imm (RV_REG_T2 , off , ctx );
1903- emit_add (RV_REG_T2 , RV_REG_T2 , rd , ctx );
1904- emit_sw (RV_REG_T2 , 0 , RV_REG_T1 , ctx );
1905- break ;
19061893 case BPF_ST | BPF_MEM | BPF_DW :
1907- emit_imm (RV_REG_T1 , imm , ctx );
1908- if (is_12b_int (off )) {
1909- emit_sd (rd , off , RV_REG_T1 , ctx );
1910- break ;
1911- }
1912-
1913- emit_imm (RV_REG_T2 , off , ctx );
1914- emit_add (RV_REG_T2 , RV_REG_T2 , rd , ctx );
1915- emit_sd (RV_REG_T2 , 0 , RV_REG_T1 , ctx );
1916- break ;
1917-
1894+ /* ST | PROBE_MEM32: *(size *)(dst + RV_REG_ARENA + off) = imm */
19181895 case BPF_ST | BPF_PROBE_MEM32 | BPF_B :
19191896 case BPF_ST | BPF_PROBE_MEM32 | BPF_H :
19201897 case BPF_ST | BPF_PROBE_MEM32 | BPF_W :
19211898 case BPF_ST | BPF_PROBE_MEM32 | BPF_DW :
19221899 {
1923- int insn_len , insns_start ;
1924-
1925- emit_add (RV_REG_T3 , rd , RV_REG_ARENA , ctx );
1926- rd = RV_REG_T3 ;
1927-
1928- /* Load imm to a register then store it */
1929- emit_imm (RV_REG_T1 , imm , ctx );
1930-
1931- switch (BPF_SIZE (code )) {
1932- case BPF_B :
1933- if (is_12b_int (off )) {
1934- insns_start = ctx -> ninsns ;
1935- emit (rv_sb (rd , off , RV_REG_T1 ), ctx );
1936- insn_len = ctx -> ninsns - insns_start ;
1937- break ;
1938- }
1939-
1940- emit_imm (RV_REG_T2 , off , ctx );
1941- emit_add (RV_REG_T2 , RV_REG_T2 , rd , ctx );
1942- insns_start = ctx -> ninsns ;
1943- emit (rv_sb (RV_REG_T2 , 0 , RV_REG_T1 ), ctx );
1944- insn_len = ctx -> ninsns - insns_start ;
1945- break ;
1946- case BPF_H :
1947- if (is_12b_int (off )) {
1948- insns_start = ctx -> ninsns ;
1949- emit (rv_sh (rd , off , RV_REG_T1 ), ctx );
1950- insn_len = ctx -> ninsns - insns_start ;
1951- break ;
1952- }
1953-
1954- emit_imm (RV_REG_T2 , off , ctx );
1955- emit_add (RV_REG_T2 , RV_REG_T2 , rd , ctx );
1956- insns_start = ctx -> ninsns ;
1957- emit (rv_sh (RV_REG_T2 , 0 , RV_REG_T1 ), ctx );
1958- insn_len = ctx -> ninsns - insns_start ;
1959- break ;
1960- case BPF_W :
1961- if (is_12b_int (off )) {
1962- insns_start = ctx -> ninsns ;
1963- emit_sw (rd , off , RV_REG_T1 , ctx );
1964- insn_len = ctx -> ninsns - insns_start ;
1965- break ;
1966- }
1967-
1968- emit_imm (RV_REG_T2 , off , ctx );
1969- emit_add (RV_REG_T2 , RV_REG_T2 , rd , ctx );
1970- insns_start = ctx -> ninsns ;
1971- emit_sw (RV_REG_T2 , 0 , RV_REG_T1 , ctx );
1972- insn_len = ctx -> ninsns - insns_start ;
1973- break ;
1974- case BPF_DW :
1975- if (is_12b_int (off )) {
1976- insns_start = ctx -> ninsns ;
1977- emit_sd (rd , off , RV_REG_T1 , ctx );
1978- insn_len = ctx -> ninsns - insns_start ;
1979- break ;
1980- }
1900+ int insn_len ;
19811901
1982- emit_imm (RV_REG_T2 , off , ctx );
1983- emit_add (RV_REG_T2 , RV_REG_T2 , rd , ctx );
1984- insns_start = ctx -> ninsns ;
1985- emit_sd (RV_REG_T2 , 0 , RV_REG_T1 , ctx );
1986- insn_len = ctx -> ninsns - insns_start ;
1987- break ;
1902+ if (BPF_MODE (insn -> code ) == BPF_PROBE_MEM32 ) {
1903+ emit_add (RV_REG_T3 , rd , RV_REG_ARENA , ctx );
1904+ rd = RV_REG_T3 ;
19881905 }
19891906
1990- ret = add_exception_handler (insn , ctx , REG_DONT_CLEAR_MARKER ,
1991- insn_len );
1907+ insn_len = emit_st (rd , off , imm , BPF_SIZE (code ), ctx );
1908+
1909+ ret = add_exception_handler (insn , ctx , REG_DONT_CLEAR_MARKER , insn_len );
19921910 if (ret )
19931911 return ret ;
1994-
19951912 break ;
19961913 }
19971914
0 commit comments