File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed
tools/testing/selftests/bpf/progs Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
#include <linux/bpf.h>
4
4
#include <bpf/bpf_helpers.h>
5
+ #include <bpf/bpf_core_read.h>
5
6
#include "../../../include/linux/filter.h"
6
7
#include "bpf_misc.h"
8
+ #include <stdbool.h>
9
+ #include "bpf_kfuncs.h"
7
10
8
11
SEC ("raw_tp" )
9
12
__arch_x86_64
@@ -842,4 +845,56 @@ __naked int bpf_fastcall_max_stack_fail(void)
842
845
);
843
846
}
844
847
848
+ SEC ("cgroup/getsockname_unix" )
849
+ __xlated ("0: r2 = 1" )
850
+ /* bpf_cast_to_kern_ctx is replaced by a single assignment */
851
+ __xlated ("1: r0 = r1" )
852
+ __xlated ("2: r0 = r2" )
853
+ __xlated ("3: exit" )
854
+ __success
855
+ __naked void kfunc_bpf_cast_to_kern_ctx (void )
856
+ {
857
+ asm volatile (
858
+ "r2 = 1;"
859
+ "*(u64 *)(r10 - 32) = r2;"
860
+ "call %[bpf_cast_to_kern_ctx];"
861
+ "r2 = *(u64 *)(r10 - 32);"
862
+ "r0 = r2;"
863
+ "exit;"
864
+ :
865
+ : __imm (bpf_cast_to_kern_ctx )
866
+ : __clobber_all );
867
+ }
868
+
869
+ SEC ("raw_tp" )
870
+ __xlated ("3: r3 = 1" )
871
+ /* bpf_rdonly_cast is replaced by a single assignment */
872
+ __xlated ("4: r0 = r1" )
873
+ __xlated ("5: r0 = r3" )
874
+ void kfunc_bpf_rdonly_cast (void )
875
+ {
876
+ asm volatile (
877
+ "r2 = %[btf_id];"
878
+ "r3 = 1;"
879
+ "*(u64 *)(r10 - 32) = r3;"
880
+ "call %[bpf_rdonly_cast];"
881
+ "r3 = *(u64 *)(r10 - 32);"
882
+ "r0 = r3;"
883
+ :
884
+ : __imm (bpf_rdonly_cast ),
885
+ [btf_id ]"r" (bpf_core_type_id_kernel (union bpf_attr ))
886
+ : __clobber_common );
887
+ }
888
+
889
+ /* BTF FUNC records are not generated for kfuncs referenced
890
+ * from inline assembly. These records are necessary for
891
+ * libbpf to link the program. The function below is a hack
892
+ * to ensure that BTF FUNC records are generated.
893
+ */
894
+ void kfunc_root (void )
895
+ {
896
+ bpf_cast_to_kern_ctx (0 );
897
+ bpf_rdonly_cast (0 , 0 );
898
+ }
899
+
845
900
char _license [] SEC ("license" ) = "GPL" ;
You can’t perform that action at this time.
0 commit comments