@@ -511,57 +511,54 @@ static void emit_stx_insn(u8 rd, s16 off, u8 rs, u8 size, struct rv_jit_context
511
511
}
512
512
}
513
513
514
- static int emit_ldx (u8 rd , s16 off , u8 rs , u8 size , bool sign_ext ,
514
+ static void emit_ldx (u8 rd , s16 off , u8 rs , u8 size , bool sign_ext ,
515
515
struct rv_jit_context * ctx )
516
516
{
517
- int insns_start ;
518
-
519
517
if (is_12b_int (off )) {
520
- insns_start = ctx -> ninsns ;
518
+ ctx -> ex_insn_off = ctx -> ninsns ;
521
519
emit_ldx_insn (rd , off , rs , size , sign_ext , ctx );
522
- return ctx -> ninsns - insns_start ;
520
+ ctx -> ex_jmp_off = ctx -> ninsns ;
521
+ return ;
523
522
}
524
523
525
524
emit_imm (RV_REG_T1 , off , ctx );
526
525
emit_add (RV_REG_T1 , RV_REG_T1 , rs , ctx );
527
- insns_start = ctx -> ninsns ;
526
+ ctx -> ex_insn_off = ctx -> ninsns ;
528
527
emit_ldx_insn (rd , 0 , RV_REG_T1 , size , sign_ext , ctx );
529
- return ctx -> ninsns - insns_start ;
528
+ ctx -> ex_jmp_off = ctx -> ninsns ;
530
529
}
531
530
532
- static int emit_st (u8 rd , s16 off , s32 imm , u8 size , struct rv_jit_context * ctx )
531
+ static void emit_st (u8 rd , s16 off , s32 imm , u8 size , struct rv_jit_context * ctx )
533
532
{
534
- int insns_start ;
535
-
536
533
emit_imm (RV_REG_T1 , imm , ctx );
537
534
if (is_12b_int (off )) {
538
- insns_start = ctx -> ninsns ;
535
+ ctx -> ex_insn_off = ctx -> ninsns ;
539
536
emit_stx_insn (rd , off , RV_REG_T1 , size , ctx );
540
- return ctx -> ninsns - insns_start ;
537
+ ctx -> ex_jmp_off = ctx -> ninsns ;
538
+ return ;
541
539
}
542
540
543
541
emit_imm (RV_REG_T2 , off , ctx );
544
542
emit_add (RV_REG_T2 , RV_REG_T2 , rd , ctx );
545
- insns_start = ctx -> ninsns ;
543
+ ctx -> ex_insn_off = ctx -> ninsns ;
546
544
emit_stx_insn (RV_REG_T2 , 0 , RV_REG_T1 , size , ctx );
547
- return ctx -> ninsns - insns_start ;
545
+ ctx -> ex_jmp_off = ctx -> ninsns ;
548
546
}
549
547
550
- static int emit_stx (u8 rd , s16 off , u8 rs , u8 size , struct rv_jit_context * ctx )
548
+ static void emit_stx (u8 rd , s16 off , u8 rs , u8 size , struct rv_jit_context * ctx )
551
549
{
552
- int insns_start ;
553
-
554
550
if (is_12b_int (off )) {
555
- insns_start = ctx -> ninsns ;
551
+ ctx -> ex_insn_off = ctx -> ninsns ;
556
552
emit_stx_insn (rd , off , rs , size , ctx );
557
- return ctx -> ninsns - insns_start ;
553
+ ctx -> ex_jmp_off = ctx -> ninsns ;
554
+ return ;
558
555
}
559
556
560
557
emit_imm (RV_REG_T1 , off , ctx );
561
558
emit_add (RV_REG_T1 , RV_REG_T1 , rd , ctx );
562
- insns_start = ctx -> ninsns ;
559
+ ctx -> ex_insn_off = ctx -> ninsns ;
563
560
emit_stx_insn (RV_REG_T1 , 0 , rs , size , ctx );
564
- return ctx -> ninsns - insns_start ;
561
+ ctx -> ex_jmp_off = ctx -> ninsns ;
565
562
}
566
563
567
564
static int emit_atomic_ld_st (u8 rd , u8 rs , const struct bpf_insn * insn ,
@@ -700,31 +697,31 @@ bool ex_handler_bpf(const struct exception_table_entry *ex,
700
697
}
701
698
702
699
/* For accesses to BTF pointers, add an entry to the exception table */
703
- static int add_exception_handler (const struct bpf_insn * insn ,
704
- struct rv_jit_context * ctx ,
705
- int dst_reg , int insn_len )
700
+ static int add_exception_handler (const struct bpf_insn * insn , int dst_reg ,
701
+ struct rv_jit_context * ctx )
706
702
{
707
703
struct exception_table_entry * ex ;
708
704
unsigned long pc ;
709
705
off_t ins_offset ;
710
706
off_t fixup_offset ;
711
707
712
708
if (!ctx -> insns || !ctx -> ro_insns || !ctx -> prog -> aux -> extable ||
713
- (BPF_MODE (insn -> code ) != BPF_PROBE_MEM && BPF_MODE (insn -> code ) != BPF_PROBE_MEMSX &&
714
- BPF_MODE (insn -> code ) != BPF_PROBE_MEM32 ))
709
+ ctx -> ex_insn_off <= 0 || ctx -> ex_jmp_off <= 0 )
715
710
return 0 ;
716
711
717
- if (WARN_ON_ONCE (ctx -> nexentries >= ctx -> prog -> aux -> num_exentries ))
718
- return - EINVAL ;
712
+ if (BPF_MODE (insn -> code ) != BPF_PROBE_MEM &&
713
+ BPF_MODE (insn -> code ) != BPF_PROBE_MEMSX &&
714
+ BPF_MODE (insn -> code ) != BPF_PROBE_MEM32 )
715
+ return 0 ;
719
716
720
- if (WARN_ON_ONCE (insn_len > ctx -> ninsns ))
717
+ if (WARN_ON_ONCE (ctx -> nexentries >= ctx -> prog -> aux -> num_exentries ))
721
718
return - EINVAL ;
722
719
723
- if (WARN_ON_ONCE (! rvc_enabled () && insn_len == 1 ))
720
+ if (WARN_ON_ONCE (ctx -> ex_insn_off > ctx -> ninsns || ctx -> ex_jmp_off > ctx -> ninsns ))
724
721
return - EINVAL ;
725
722
726
723
ex = & ctx -> prog -> aux -> extable [ctx -> nexentries ];
727
- pc = (unsigned long )& ctx -> ro_insns [ctx -> ninsns - insn_len ];
724
+ pc = (unsigned long )& ctx -> ro_insns [ctx -> ex_insn_off ];
728
725
729
726
/*
730
727
* This is the relative offset of the instruction that may fault from
@@ -748,7 +745,7 @@ static int add_exception_handler(const struct bpf_insn *insn,
748
745
* that may fault. The execution will jump to this after handling the
749
746
* fault.
750
747
*/
751
- fixup_offset = (long )& ex -> fixup - (pc + insn_len * sizeof ( u16 )) ;
748
+ fixup_offset = (long )& ex -> fixup - (long ) & ctx -> ro_insns [ ctx -> ex_jmp_off ] ;
752
749
if (!FIELD_FIT (BPF_FIXUP_OFFSET_MASK , fixup_offset ))
753
750
return - ERANGE ;
754
751
@@ -765,6 +762,8 @@ static int add_exception_handler(const struct bpf_insn *insn,
765
762
FIELD_PREP (BPF_FIXUP_REG_MASK , dst_reg );
766
763
ex -> type = EX_TYPE_BPF ;
767
764
765
+ ctx -> ex_insn_off = 0 ;
766
+ ctx -> ex_jmp_off = 0 ;
768
767
ctx -> nexentries ++ ;
769
768
return 0 ;
770
769
}
@@ -1774,7 +1773,6 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
1774
1773
case BPF_LDX | BPF_PROBE_MEM32 | BPF_DW :
1775
1774
{
1776
1775
bool sign_ext ;
1777
- int insn_len ;
1778
1776
1779
1777
sign_ext = BPF_MODE (insn -> code ) == BPF_MEMSX ||
1780
1778
BPF_MODE (insn -> code ) == BPF_PROBE_MEMSX ;
@@ -1784,9 +1782,9 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
1784
1782
rs = RV_REG_T2 ;
1785
1783
}
1786
1784
1787
- insn_len = emit_ldx (rd , off , rs , BPF_SIZE (code ), sign_ext , ctx );
1785
+ emit_ldx (rd , off , rs , BPF_SIZE (code ), sign_ext , ctx );
1788
1786
1789
- ret = add_exception_handler (insn , ctx , rd , insn_len );
1787
+ ret = add_exception_handler (insn , rd , ctx );
1790
1788
if (ret )
1791
1789
return ret ;
1792
1790
@@ -1809,21 +1807,17 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
1809
1807
case BPF_ST | BPF_PROBE_MEM32 | BPF_H :
1810
1808
case BPF_ST | BPF_PROBE_MEM32 | BPF_W :
1811
1809
case BPF_ST | BPF_PROBE_MEM32 | BPF_DW :
1812
- {
1813
- int insn_len ;
1814
-
1815
1810
if (BPF_MODE (insn -> code ) == BPF_PROBE_MEM32 ) {
1816
1811
emit_add (RV_REG_T3 , rd , RV_REG_ARENA , ctx );
1817
1812
rd = RV_REG_T3 ;
1818
1813
}
1819
1814
1820
- insn_len = emit_st (rd , off , imm , BPF_SIZE (code ), ctx );
1815
+ emit_st (rd , off , imm , BPF_SIZE (code ), ctx );
1821
1816
1822
- ret = add_exception_handler (insn , ctx , REG_DONT_CLEAR_MARKER , insn_len );
1817
+ ret = add_exception_handler (insn , REG_DONT_CLEAR_MARKER , ctx );
1823
1818
if (ret )
1824
1819
return ret ;
1825
1820
break ;
1826
- }
1827
1821
1828
1822
/* STX: *(size *)(dst + off) = src */
1829
1823
case BPF_STX | BPF_MEM | BPF_B :
@@ -1835,21 +1829,17 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
1835
1829
case BPF_STX | BPF_PROBE_MEM32 | BPF_H :
1836
1830
case BPF_STX | BPF_PROBE_MEM32 | BPF_W :
1837
1831
case BPF_STX | BPF_PROBE_MEM32 | BPF_DW :
1838
- {
1839
- int insn_len ;
1840
-
1841
1832
if (BPF_MODE (insn -> code ) == BPF_PROBE_MEM32 ) {
1842
1833
emit_add (RV_REG_T2 , rd , RV_REG_ARENA , ctx );
1843
1834
rd = RV_REG_T2 ;
1844
1835
}
1845
1836
1846
- insn_len = emit_stx (rd , off , rs , BPF_SIZE (code ), ctx );
1837
+ emit_stx (rd , off , rs , BPF_SIZE (code ), ctx );
1847
1838
1848
- ret = add_exception_handler (insn , ctx , REG_DONT_CLEAR_MARKER , insn_len );
1839
+ ret = add_exception_handler (insn , REG_DONT_CLEAR_MARKER , ctx );
1849
1840
if (ret )
1850
1841
return ret ;
1851
1842
break ;
1852
- }
1853
1843
1854
1844
case BPF_STX | BPF_ATOMIC | BPF_B :
1855
1845
case BPF_STX | BPF_ATOMIC | BPF_H :
0 commit comments