53
53
#define MAX_INSNS BPF_MAXINSNS
54
54
#define MAX_TEST_INSNS 1000000
55
55
#define MAX_FIXUPS 8
56
- #define MAX_NR_MAPS 22
56
+ #define MAX_NR_MAPS 23
57
57
#define MAX_TEST_RUNS 8
58
58
#define POINTER_VALUE 0xcafe4all
59
59
#define TEST_DATA_LEN 64
@@ -101,6 +101,7 @@ struct bpf_test {
101
101
int fixup_map_reuseport_array [MAX_FIXUPS ];
102
102
int fixup_map_ringbuf [MAX_FIXUPS ];
103
103
int fixup_map_timer [MAX_FIXUPS ];
104
+ int fixup_map_kptr [MAX_FIXUPS ];
104
105
struct kfunc_btf_id_pair fixup_kfunc_btf_id [MAX_FIXUPS ];
105
106
/* Expected verifier log output for result REJECT or VERBOSE_ACCEPT.
106
107
* Can be a tab-separated sequence of expected strings. An empty string
@@ -621,8 +622,16 @@ static int create_cgroup_storage(bool percpu)
621
622
* struct timer {
622
623
* struct bpf_timer t;
623
624
* };
625
+ * struct btf_ptr {
626
+ * struct prog_test_ref_kfunc __kptr *ptr;
627
+ * struct prog_test_ref_kfunc __kptr_ref *ptr;
628
+ * struct prog_test_ref_kfunc __kptr_percpu *ptr;
629
+ * struct prog_test_ref_kfunc __kptr_user *ptr;
630
+ * }
624
631
*/
625
- static const char btf_str_sec [] = "\0bpf_spin_lock\0val\0cnt\0l\0bpf_timer\0timer\0t" ;
632
+ static const char btf_str_sec [] = "\0bpf_spin_lock\0val\0cnt\0l\0bpf_timer\0timer\0t"
633
+ "\0btf_ptr\0prog_test_ref_kfunc\0ptr\0kptr\0kptr_ref"
634
+ "\0kptr_percpu\0kptr_user" ;
626
635
static __u32 btf_raw_types [] = {
627
636
/* int */
628
637
BTF_TYPE_INT_ENC (0 , BTF_INT_SIGNED , 0 , 32 , 4 ), /* [1] */
@@ -638,6 +647,26 @@ static __u32 btf_raw_types[] = {
638
647
/* struct timer */ /* [5] */
639
648
BTF_TYPE_ENC (35 , BTF_INFO_ENC (BTF_KIND_STRUCT , 0 , 1 ), 16 ),
640
649
BTF_MEMBER_ENC (41 , 4 , 0 ), /* struct bpf_timer t; */
650
+ /* struct prog_test_ref_kfunc */ /* [6] */
651
+ BTF_STRUCT_ENC (51 , 0 , 0 ),
652
+ /* type tag "kptr" */
653
+ BTF_TYPE_TAG_ENC (75 , 6 ), /* [7] */
654
+ /* type tag "kptr_ref" */
655
+ BTF_TYPE_TAG_ENC (80 , 6 ), /* [8] */
656
+ /* type tag "kptr_percpu" */
657
+ BTF_TYPE_TAG_ENC (89 , 6 ), /* [9] */
658
+ /* type tag "kptr_user" */
659
+ BTF_TYPE_TAG_ENC (101 , 6 ), /* [10] */
660
+ BTF_PTR_ENC (7 ), /* [11] */
661
+ BTF_PTR_ENC (8 ), /* [12] */
662
+ BTF_PTR_ENC (9 ), /* [13] */
663
+ BTF_PTR_ENC (10 ), /* [14] */
664
+ /* struct btf_ptr */ /* [15] */
665
+ BTF_STRUCT_ENC (43 , 4 , 32 ),
666
+ BTF_MEMBER_ENC (71 , 11 , 0 ), /* struct prog_test_ref_kfunc __kptr *ptr; */
667
+ BTF_MEMBER_ENC (71 , 12 , 64 ), /* struct prog_test_ref_kfunc __kptr_ref *ptr; */
668
+ BTF_MEMBER_ENC (71 , 13 , 128 ), /* struct prog_test_ref_kfunc __kptr_percpu *ptr; */
669
+ BTF_MEMBER_ENC (71 , 14 , 192 ), /* struct prog_test_ref_kfunc __kptr_user *ptr; */
641
670
};
642
671
643
672
static int load_btf (void )
@@ -727,6 +756,25 @@ static int create_map_timer(void)
727
756
return fd ;
728
757
}
729
758
759
+ static int create_map_kptr (void )
760
+ {
761
+ LIBBPF_OPTS (bpf_map_create_opts , opts ,
762
+ .btf_key_type_id = 1 ,
763
+ .btf_value_type_id = 15 ,
764
+ );
765
+ int fd , btf_fd ;
766
+
767
+ btf_fd = load_btf ();
768
+ if (btf_fd < 0 )
769
+ return -1 ;
770
+
771
+ opts .btf_fd = btf_fd ;
772
+ fd = bpf_map_create (BPF_MAP_TYPE_ARRAY , "test_map" , 4 , 32 , 1 , & opts );
773
+ if (fd < 0 )
774
+ printf ("Failed to create map with btf_id pointer\n" );
775
+ return fd ;
776
+ }
777
+
730
778
static char bpf_vlog [UINT_MAX >> 8 ];
731
779
732
780
static void do_test_fixup (struct bpf_test * test , enum bpf_prog_type prog_type ,
@@ -754,6 +802,7 @@ static void do_test_fixup(struct bpf_test *test, enum bpf_prog_type prog_type,
754
802
int * fixup_map_reuseport_array = test -> fixup_map_reuseport_array ;
755
803
int * fixup_map_ringbuf = test -> fixup_map_ringbuf ;
756
804
int * fixup_map_timer = test -> fixup_map_timer ;
805
+ int * fixup_map_kptr = test -> fixup_map_kptr ;
757
806
struct kfunc_btf_id_pair * fixup_kfunc_btf_id = test -> fixup_kfunc_btf_id ;
758
807
759
808
if (test -> fill_helper ) {
@@ -947,6 +996,13 @@ static void do_test_fixup(struct bpf_test *test, enum bpf_prog_type prog_type,
947
996
fixup_map_timer ++ ;
948
997
} while (* fixup_map_timer );
949
998
}
999
+ if (* fixup_map_kptr ) {
1000
+ map_fds [22 ] = create_map_kptr ();
1001
+ do {
1002
+ prog [* fixup_map_kptr ].imm = map_fds [22 ];
1003
+ fixup_map_kptr ++ ;
1004
+ } while (* fixup_map_kptr );
1005
+ }
950
1006
951
1007
/* Patch in kfunc BTF IDs */
952
1008
if (fixup_kfunc_btf_id -> kfunc ) {
0 commit comments