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,15 @@ 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_member __kptr_ref *ptr;
629
+ * }
624
630
*/
625
- static const char btf_str_sec [] = "\0bpf_spin_lock\0val\0cnt\0l\0bpf_timer\0timer\0t" ;
631
+ static const char btf_str_sec [] = "\0bpf_spin_lock\0val\0cnt\0l\0bpf_timer\0timer\0t"
632
+ "\0btf_ptr\0prog_test_ref_kfunc\0ptr\0kptr\0kptr_ref"
633
+ "\0prog_test_member" ;
626
634
static __u32 btf_raw_types [] = {
627
635
/* int */
628
636
BTF_TYPE_INT_ENC (0 , BTF_INT_SIGNED , 0 , 32 , 4 ), /* [1] */
@@ -638,6 +646,22 @@ static __u32 btf_raw_types[] = {
638
646
/* struct timer */ /* [5] */
639
647
BTF_TYPE_ENC (35 , BTF_INFO_ENC (BTF_KIND_STRUCT , 0 , 1 ), 16 ),
640
648
BTF_MEMBER_ENC (41 , 4 , 0 ), /* struct bpf_timer t; */
649
+ /* struct prog_test_ref_kfunc */ /* [6] */
650
+ BTF_STRUCT_ENC (51 , 0 , 0 ),
651
+ BTF_STRUCT_ENC (89 , 0 , 0 ), /* [7] */
652
+ /* type tag "kptr" */
653
+ BTF_TYPE_TAG_ENC (75 , 6 ), /* [8] */
654
+ /* type tag "kptr_ref" */
655
+ BTF_TYPE_TAG_ENC (80 , 6 ), /* [9] */
656
+ BTF_TYPE_TAG_ENC (80 , 7 ), /* [10] */
657
+ BTF_PTR_ENC (8 ), /* [11] */
658
+ BTF_PTR_ENC (9 ), /* [12] */
659
+ BTF_PTR_ENC (10 ), /* [13] */
660
+ /* struct btf_ptr */ /* [14] */
661
+ BTF_STRUCT_ENC (43 , 3 , 24 ),
662
+ BTF_MEMBER_ENC (71 , 11 , 0 ), /* struct prog_test_ref_kfunc __kptr *ptr; */
663
+ BTF_MEMBER_ENC (71 , 12 , 64 ), /* struct prog_test_ref_kfunc __kptr_ref *ptr; */
664
+ BTF_MEMBER_ENC (71 , 13 , 128 ), /* struct prog_test_member __kptr_ref *ptr; */
641
665
};
642
666
643
667
static int load_btf (void )
@@ -727,6 +751,25 @@ static int create_map_timer(void)
727
751
return fd ;
728
752
}
729
753
754
+ static int create_map_kptr (void )
755
+ {
756
+ LIBBPF_OPTS (bpf_map_create_opts , opts ,
757
+ .btf_key_type_id = 1 ,
758
+ .btf_value_type_id = 14 ,
759
+ );
760
+ int fd , btf_fd ;
761
+
762
+ btf_fd = load_btf ();
763
+ if (btf_fd < 0 )
764
+ return -1 ;
765
+
766
+ opts .btf_fd = btf_fd ;
767
+ fd = bpf_map_create (BPF_MAP_TYPE_ARRAY , "test_map" , 4 , 24 , 1 , & opts );
768
+ if (fd < 0 )
769
+ printf ("Failed to create map with btf_id pointer\n" );
770
+ return fd ;
771
+ }
772
+
730
773
static char bpf_vlog [UINT_MAX >> 8 ];
731
774
732
775
static void do_test_fixup (struct bpf_test * test , enum bpf_prog_type prog_type ,
@@ -754,6 +797,7 @@ static void do_test_fixup(struct bpf_test *test, enum bpf_prog_type prog_type,
754
797
int * fixup_map_reuseport_array = test -> fixup_map_reuseport_array ;
755
798
int * fixup_map_ringbuf = test -> fixup_map_ringbuf ;
756
799
int * fixup_map_timer = test -> fixup_map_timer ;
800
+ int * fixup_map_kptr = test -> fixup_map_kptr ;
757
801
struct kfunc_btf_id_pair * fixup_kfunc_btf_id = test -> fixup_kfunc_btf_id ;
758
802
759
803
if (test -> fill_helper ) {
@@ -947,6 +991,13 @@ static void do_test_fixup(struct bpf_test *test, enum bpf_prog_type prog_type,
947
991
fixup_map_timer ++ ;
948
992
} while (* fixup_map_timer );
949
993
}
994
+ if (* fixup_map_kptr ) {
995
+ map_fds [22 ] = create_map_kptr ();
996
+ do {
997
+ prog [* fixup_map_kptr ].imm = map_fds [22 ];
998
+ fixup_map_kptr ++ ;
999
+ } while (* fixup_map_kptr );
1000
+ }
950
1001
951
1002
/* Patch in kfunc BTF IDs */
952
1003
if (fixup_kfunc_btf_id -> kfunc ) {
0 commit comments