Message ID | 20230127214353.628551-1-grantseltzer@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | BPF |
Headers | show |
Series | [bpf-next] Add support for tracing programs in BPF_PROG_RUN | expand |
Hi Grant, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on bpf-next/master] url: https://github.com/intel-lab-lkp/linux/commits/Grant-Seltzer/Add-support-for-tracing-programs-in-BPF_PROG_RUN/20230128-130222 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master patch link: https://lore.kernel.org/r/20230127214353.628551-1-grantseltzer%40gmail.com patch subject: [PATCH bpf-next] Add support for tracing programs in BPF_PROG_RUN config: powerpc-allmodconfig (https://download.01.org/0day-ci/archive/20230128/202301281606.OPSk1bci-lkp@intel.com/config) compiler: powerpc-linux-gcc (GCC) 12.1.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/990088d6233eb15a4a42a83a998f47432305d4d7 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Grant-Seltzer/Add-support-for-tracing-programs-in-BPF_PROG_RUN/20230128-130222 git checkout 990088d6233eb15a4a42a83a998f47432305d4d7 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=powerpc olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash net/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): net/bpf/test_run.c: In function 'bpf_prog_test_run_tracing': >> net/bpf/test_run.c:818:30: warning: variable 'ret' set but not used [-Wunused-but-set-variable] 818 | u16 side_effect = 0, ret = 0; | ^~~ >> net/bpf/test_run.c:818:13: warning: variable 'side_effect' set but not used [-Wunused-but-set-variable] 818 | u16 side_effect = 0, ret = 0; | ^~~~~~~~~~~ vim +/ret +818 net/bpf/test_run.c 990088d6233eb1 Grant Seltzer 2023-01-27 812 da00d2f117a08f KP Singh 2020-03-04 813 int bpf_prog_test_run_tracing(struct bpf_prog *prog, da00d2f117a08f KP Singh 2020-03-04 814 const union bpf_attr *kattr, da00d2f117a08f KP Singh 2020-03-04 815 union bpf_attr __user *uattr) da00d2f117a08f KP Singh 2020-03-04 816 { d923021c2ce12a Yonghong Song 2020-06-30 817 struct bpf_fentry_test_t arg = {}; 3d08b6f29cf33a KP Singh 2020-03-04 @818 u16 side_effect = 0, ret = 0; 990088d6233eb1 Grant Seltzer 2023-01-27 819 int b = 2, err = -EFAULT, current_cpu; 990088d6233eb1 Grant Seltzer 2023-01-27 820 990088d6233eb1 Grant Seltzer 2023-01-27 821 void __user *ctx_in = u64_to_user_ptr(kattr->test.ctx_in); 990088d6233eb1 Grant Seltzer 2023-01-27 822 __u32 ctx_size_in = kattr->test.ctx_size_in; 990088d6233eb1 Grant Seltzer 2023-01-27 823 struct bpf_tracing_test_run_info info; 990088d6233eb1 Grant Seltzer 2023-01-27 824 int cpu = kattr->test.cpu; da00d2f117a08f KP Singh 2020-03-04 825 b530e9e1063ed2 Toke Høiland-Jørgensen 2022-03-09 826 if (kattr->test.flags || kattr->test.cpu || kattr->test.batch_size) 1b4d60ec162f82 Song Liu 2020-09-25 827 return -EINVAL; 1b4d60ec162f82 Song Liu 2020-09-25 828 da00d2f117a08f KP Singh 2020-03-04 829 switch (prog->expected_attach_type) { da00d2f117a08f KP Singh 2020-03-04 830 case BPF_TRACE_FENTRY: da00d2f117a08f KP Singh 2020-03-04 831 case BPF_TRACE_FEXIT: faeb2dce084aff Alexei Starovoitov 2019-11-14 832 if (bpf_fentry_test1(1) != 2 || faeb2dce084aff Alexei Starovoitov 2019-11-14 833 bpf_fentry_test2(2, 3) != 5 || faeb2dce084aff Alexei Starovoitov 2019-11-14 834 bpf_fentry_test3(4, 5, 6) != 15 || faeb2dce084aff Alexei Starovoitov 2019-11-14 835 bpf_fentry_test4((void *)7, 8, 9, 10) != 34 || faeb2dce084aff Alexei Starovoitov 2019-11-14 836 bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 || d923021c2ce12a Yonghong Song 2020-06-30 837 bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111 || d923021c2ce12a Yonghong Song 2020-06-30 838 bpf_fentry_test7((struct bpf_fentry_test_t *)0) != 0 || d923021c2ce12a Yonghong Song 2020-06-30 839 bpf_fentry_test8(&arg) != 0) da00d2f117a08f KP Singh 2020-03-04 840 goto out; da00d2f117a08f KP Singh 2020-03-04 841 break; 3d08b6f29cf33a KP Singh 2020-03-04 842 case BPF_MODIFY_RETURN: 3d08b6f29cf33a KP Singh 2020-03-04 843 ret = bpf_modify_return_test(1, &b); 3d08b6f29cf33a KP Singh 2020-03-04 844 if (b != 2) 3d08b6f29cf33a KP Singh 2020-03-04 845 side_effect = 1; 3d08b6f29cf33a KP Singh 2020-03-04 846 break; da00d2f117a08f KP Singh 2020-03-04 847 default: da00d2f117a08f KP Singh 2020-03-04 848 goto out; a25ecd9d1e6024 Colin Ian King 2019-11-18 849 } da00d2f117a08f KP Singh 2020-03-04 850 990088d6233eb1 Grant Seltzer 2023-01-27 851 /* doesn't support data_in/out, ctx_out, duration, or repeat */ 990088d6233eb1 Grant Seltzer 2023-01-27 852 if (kattr->test.data_in || kattr->test.data_out || 990088d6233eb1 Grant Seltzer 2023-01-27 853 kattr->test.ctx_out || kattr->test.duration || 990088d6233eb1 Grant Seltzer 2023-01-27 854 kattr->test.repeat || kattr->test.batch_size) 990088d6233eb1 Grant Seltzer 2023-01-27 855 return -EINVAL; 990088d6233eb1 Grant Seltzer 2023-01-27 856 990088d6233eb1 Grant Seltzer 2023-01-27 857 if (ctx_size_in < prog->aux->max_ctx_offset || 990088d6233eb1 Grant Seltzer 2023-01-27 858 ctx_size_in > MAX_BPF_FUNC_ARGS * sizeof(u64)) 990088d6233eb1 Grant Seltzer 2023-01-27 859 return -EINVAL; 990088d6233eb1 Grant Seltzer 2023-01-27 860 990088d6233eb1 Grant Seltzer 2023-01-27 861 if ((kattr->test.flags & BPF_F_TEST_RUN_ON_CPU) == 0 && cpu != 0) 990088d6233eb1 Grant Seltzer 2023-01-27 862 return -EINVAL; 990088d6233eb1 Grant Seltzer 2023-01-27 863 990088d6233eb1 Grant Seltzer 2023-01-27 864 if (ctx_size_in) { 990088d6233eb1 Grant Seltzer 2023-01-27 865 info.ctx = memdup_user(ctx_in, ctx_size_in); 990088d6233eb1 Grant Seltzer 2023-01-27 866 if (IS_ERR(info.ctx)) 990088d6233eb1 Grant Seltzer 2023-01-27 867 return PTR_ERR(info.ctx); 990088d6233eb1 Grant Seltzer 2023-01-27 868 } else { 990088d6233eb1 Grant Seltzer 2023-01-27 869 info.ctx = NULL; 990088d6233eb1 Grant Seltzer 2023-01-27 870 } 3d08b6f29cf33a KP Singh 2020-03-04 871 da00d2f117a08f KP Singh 2020-03-04 872 err = 0; 990088d6233eb1 Grant Seltzer 2023-01-27 873 info.prog = prog; 990088d6233eb1 Grant Seltzer 2023-01-27 874 990088d6233eb1 Grant Seltzer 2023-01-27 875 current_cpu = get_cpu(); 990088d6233eb1 Grant Seltzer 2023-01-27 876 if ((kattr->test.flags & BPF_F_TEST_RUN_ON_CPU) == 0 || 990088d6233eb1 Grant Seltzer 2023-01-27 877 cpu == current_cpu) { 990088d6233eb1 Grant Seltzer 2023-01-27 878 __bpf_prog_test_run_tracing(&info); 990088d6233eb1 Grant Seltzer 2023-01-27 879 } else if (cpu >= nr_cpu_ids || !cpu_online(cpu)) { 990088d6233eb1 Grant Seltzer 2023-01-27 880 /* smp_call_function_single() also checks cpu_online() 990088d6233eb1 Grant Seltzer 2023-01-27 881 * after csd_lock(). However, since cpu is from user 990088d6233eb1 Grant Seltzer 2023-01-27 882 * space, let's do an extra quick check to filter out 990088d6233eb1 Grant Seltzer 2023-01-27 883 * invalid value before smp_call_function_single(). 990088d6233eb1 Grant Seltzer 2023-01-27 884 */ 990088d6233eb1 Grant Seltzer 2023-01-27 885 err = -ENXIO; 990088d6233eb1 Grant Seltzer 2023-01-27 886 } else { 990088d6233eb1 Grant Seltzer 2023-01-27 887 err = smp_call_function_single(cpu, __bpf_prog_test_run_tracing, 990088d6233eb1 Grant Seltzer 2023-01-27 888 &info, 1); 990088d6233eb1 Grant Seltzer 2023-01-27 889 } 990088d6233eb1 Grant Seltzer 2023-01-27 890 put_cpu(); 990088d6233eb1 Grant Seltzer 2023-01-27 891 990088d6233eb1 Grant Seltzer 2023-01-27 892 if (!err && 990088d6233eb1 Grant Seltzer 2023-01-27 893 copy_to_user(&uattr->test.retval, &info.retval, sizeof(u32))) 990088d6233eb1 Grant Seltzer 2023-01-27 894 err = -EFAULT; 990088d6233eb1 Grant Seltzer 2023-01-27 895 990088d6233eb1 Grant Seltzer 2023-01-27 896 kfree(info.ctx); 990088d6233eb1 Grant Seltzer 2023-01-27 897 da00d2f117a08f KP Singh 2020-03-04 898 out: da00d2f117a08f KP Singh 2020-03-04 899 trace_bpf_test_finish(&err); da00d2f117a08f KP Singh 2020-03-04 900 return err; 1cf1cae963c2e6 Alexei Starovoitov 2017-03-30 901 } 1cf1cae963c2e6 Alexei Starovoitov 2017-03-30 902
Hi Grant, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on bpf-next/master] url: https://github.com/intel-lab-lkp/linux/commits/Grant-Seltzer/Add-support-for-tracing-programs-in-BPF_PROG_RUN/20230128-130222 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master patch link: https://lore.kernel.org/r/20230127214353.628551-1-grantseltzer%40gmail.com patch subject: [PATCH bpf-next] Add support for tracing programs in BPF_PROG_RUN config: i386-randconfig-a012-20230123 (https://download.01.org/0day-ci/archive/20230128/202301281621.DfTZgf4X-lkp@intel.com/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/990088d6233eb15a4a42a83a998f47432305d4d7 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Grant-Seltzer/Add-support-for-tracing-programs-in-BPF_PROG_RUN/20230128-130222 git checkout 990088d6233eb15a4a42a83a998f47432305d4d7 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash net/bpf/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): >> net/bpf/test_run.c:818:23: warning: variable 'ret' set but not used [-Wunused-but-set-variable] u16 side_effect = 0, ret = 0; ^ >> net/bpf/test_run.c:818:6: warning: variable 'side_effect' set but not used [-Wunused-but-set-variable] u16 side_effect = 0, ret = 0; ^ 2 warnings generated. vim +/ret +818 net/bpf/test_run.c 990088d6233eb1 Grant Seltzer 2023-01-27 812 da00d2f117a08f KP Singh 2020-03-04 813 int bpf_prog_test_run_tracing(struct bpf_prog *prog, da00d2f117a08f KP Singh 2020-03-04 814 const union bpf_attr *kattr, da00d2f117a08f KP Singh 2020-03-04 815 union bpf_attr __user *uattr) da00d2f117a08f KP Singh 2020-03-04 816 { d923021c2ce12a Yonghong Song 2020-06-30 817 struct bpf_fentry_test_t arg = {}; 3d08b6f29cf33a KP Singh 2020-03-04 @818 u16 side_effect = 0, ret = 0; 990088d6233eb1 Grant Seltzer 2023-01-27 819 int b = 2, err = -EFAULT, current_cpu; 990088d6233eb1 Grant Seltzer 2023-01-27 820 990088d6233eb1 Grant Seltzer 2023-01-27 821 void __user *ctx_in = u64_to_user_ptr(kattr->test.ctx_in); 990088d6233eb1 Grant Seltzer 2023-01-27 822 __u32 ctx_size_in = kattr->test.ctx_size_in; 990088d6233eb1 Grant Seltzer 2023-01-27 823 struct bpf_tracing_test_run_info info; 990088d6233eb1 Grant Seltzer 2023-01-27 824 int cpu = kattr->test.cpu; da00d2f117a08f KP Singh 2020-03-04 825 b530e9e1063ed2 Toke Høiland-Jørgensen 2022-03-09 826 if (kattr->test.flags || kattr->test.cpu || kattr->test.batch_size) 1b4d60ec162f82 Song Liu 2020-09-25 827 return -EINVAL; 1b4d60ec162f82 Song Liu 2020-09-25 828 da00d2f117a08f KP Singh 2020-03-04 829 switch (prog->expected_attach_type) { da00d2f117a08f KP Singh 2020-03-04 830 case BPF_TRACE_FENTRY: da00d2f117a08f KP Singh 2020-03-04 831 case BPF_TRACE_FEXIT: faeb2dce084aff Alexei Starovoitov 2019-11-14 832 if (bpf_fentry_test1(1) != 2 || faeb2dce084aff Alexei Starovoitov 2019-11-14 833 bpf_fentry_test2(2, 3) != 5 || faeb2dce084aff Alexei Starovoitov 2019-11-14 834 bpf_fentry_test3(4, 5, 6) != 15 || faeb2dce084aff Alexei Starovoitov 2019-11-14 835 bpf_fentry_test4((void *)7, 8, 9, 10) != 34 || faeb2dce084aff Alexei Starovoitov 2019-11-14 836 bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 || d923021c2ce12a Yonghong Song 2020-06-30 837 bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111 || d923021c2ce12a Yonghong Song 2020-06-30 838 bpf_fentry_test7((struct bpf_fentry_test_t *)0) != 0 || d923021c2ce12a Yonghong Song 2020-06-30 839 bpf_fentry_test8(&arg) != 0) da00d2f117a08f KP Singh 2020-03-04 840 goto out; da00d2f117a08f KP Singh 2020-03-04 841 break; 3d08b6f29cf33a KP Singh 2020-03-04 842 case BPF_MODIFY_RETURN: 3d08b6f29cf33a KP Singh 2020-03-04 843 ret = bpf_modify_return_test(1, &b); 3d08b6f29cf33a KP Singh 2020-03-04 844 if (b != 2) 3d08b6f29cf33a KP Singh 2020-03-04 845 side_effect = 1; 3d08b6f29cf33a KP Singh 2020-03-04 846 break; da00d2f117a08f KP Singh 2020-03-04 847 default: da00d2f117a08f KP Singh 2020-03-04 848 goto out; a25ecd9d1e6024 Colin Ian King 2019-11-18 849 } da00d2f117a08f KP Singh 2020-03-04 850 990088d6233eb1 Grant Seltzer 2023-01-27 851 /* doesn't support data_in/out, ctx_out, duration, or repeat */ 990088d6233eb1 Grant Seltzer 2023-01-27 852 if (kattr->test.data_in || kattr->test.data_out || 990088d6233eb1 Grant Seltzer 2023-01-27 853 kattr->test.ctx_out || kattr->test.duration || 990088d6233eb1 Grant Seltzer 2023-01-27 854 kattr->test.repeat || kattr->test.batch_size) 990088d6233eb1 Grant Seltzer 2023-01-27 855 return -EINVAL; 990088d6233eb1 Grant Seltzer 2023-01-27 856 990088d6233eb1 Grant Seltzer 2023-01-27 857 if (ctx_size_in < prog->aux->max_ctx_offset || 990088d6233eb1 Grant Seltzer 2023-01-27 858 ctx_size_in > MAX_BPF_FUNC_ARGS * sizeof(u64)) 990088d6233eb1 Grant Seltzer 2023-01-27 859 return -EINVAL; 990088d6233eb1 Grant Seltzer 2023-01-27 860 990088d6233eb1 Grant Seltzer 2023-01-27 861 if ((kattr->test.flags & BPF_F_TEST_RUN_ON_CPU) == 0 && cpu != 0) 990088d6233eb1 Grant Seltzer 2023-01-27 862 return -EINVAL; 990088d6233eb1 Grant Seltzer 2023-01-27 863 990088d6233eb1 Grant Seltzer 2023-01-27 864 if (ctx_size_in) { 990088d6233eb1 Grant Seltzer 2023-01-27 865 info.ctx = memdup_user(ctx_in, ctx_size_in); 990088d6233eb1 Grant Seltzer 2023-01-27 866 if (IS_ERR(info.ctx)) 990088d6233eb1 Grant Seltzer 2023-01-27 867 return PTR_ERR(info.ctx); 990088d6233eb1 Grant Seltzer 2023-01-27 868 } else { 990088d6233eb1 Grant Seltzer 2023-01-27 869 info.ctx = NULL; 990088d6233eb1 Grant Seltzer 2023-01-27 870 } 3d08b6f29cf33a KP Singh 2020-03-04 871 da00d2f117a08f KP Singh 2020-03-04 872 err = 0; 990088d6233eb1 Grant Seltzer 2023-01-27 873 info.prog = prog; 990088d6233eb1 Grant Seltzer 2023-01-27 874 990088d6233eb1 Grant Seltzer 2023-01-27 875 current_cpu = get_cpu(); 990088d6233eb1 Grant Seltzer 2023-01-27 876 if ((kattr->test.flags & BPF_F_TEST_RUN_ON_CPU) == 0 || 990088d6233eb1 Grant Seltzer 2023-01-27 877 cpu == current_cpu) { 990088d6233eb1 Grant Seltzer 2023-01-27 878 __bpf_prog_test_run_tracing(&info); 990088d6233eb1 Grant Seltzer 2023-01-27 879 } else if (cpu >= nr_cpu_ids || !cpu_online(cpu)) { 990088d6233eb1 Grant Seltzer 2023-01-27 880 /* smp_call_function_single() also checks cpu_online() 990088d6233eb1 Grant Seltzer 2023-01-27 881 * after csd_lock(). However, since cpu is from user 990088d6233eb1 Grant Seltzer 2023-01-27 882 * space, let's do an extra quick check to filter out 990088d6233eb1 Grant Seltzer 2023-01-27 883 * invalid value before smp_call_function_single(). 990088d6233eb1 Grant Seltzer 2023-01-27 884 */ 990088d6233eb1 Grant Seltzer 2023-01-27 885 err = -ENXIO; 990088d6233eb1 Grant Seltzer 2023-01-27 886 } else { 990088d6233eb1 Grant Seltzer 2023-01-27 887 err = smp_call_function_single(cpu, __bpf_prog_test_run_tracing, 990088d6233eb1 Grant Seltzer 2023-01-27 888 &info, 1); 990088d6233eb1 Grant Seltzer 2023-01-27 889 } 990088d6233eb1 Grant Seltzer 2023-01-27 890 put_cpu(); 990088d6233eb1 Grant Seltzer 2023-01-27 891 990088d6233eb1 Grant Seltzer 2023-01-27 892 if (!err && 990088d6233eb1 Grant Seltzer 2023-01-27 893 copy_to_user(&uattr->test.retval, &info.retval, sizeof(u32))) 990088d6233eb1 Grant Seltzer 2023-01-27 894 err = -EFAULT; 990088d6233eb1 Grant Seltzer 2023-01-27 895 990088d6233eb1 Grant Seltzer 2023-01-27 896 kfree(info.ctx); 990088d6233eb1 Grant Seltzer 2023-01-27 897 da00d2f117a08f KP Singh 2020-03-04 898 out: da00d2f117a08f KP Singh 2020-03-04 899 trace_bpf_test_finish(&err); da00d2f117a08f KP Singh 2020-03-04 900 return err; 1cf1cae963c2e6 Alexei Starovoitov 2017-03-30 901 } 1cf1cae963c2e6 Alexei Starovoitov 2017-03-30 902
I see I left in a couple of unused variables, but I'm now questioning their purpose. KP, as the original author, can you explain the purpose of the `bpf_modify_return_test`? Since this function is running in the context of the bpf syscall and not the bpf program itself, how would the side effect of the addition operation (I guess simulating the attached function running) ever not happen? If we adopt actually running the BPF program, should there just be a check for setting the upper 16 bits to represent 'side effects'?
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c index 8da0d73b368e..e4023c7b3bc7 100644 --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -794,14 +794,34 @@ static void *bpf_test_init(const union bpf_attr *kattr, u32 user_size, return data; } +struct bpf_tracing_test_run_info { + struct bpf_prog *prog; + void *ctx; + u32 retval; +}; + +static void +__bpf_prog_test_run_tracing(void *data) +{ + struct bpf_tracing_test_run_info *info = data; + + rcu_read_lock(); + info->retval = bpf_prog_run(info->prog, info->ctx); + rcu_read_unlock(); +} + int bpf_prog_test_run_tracing(struct bpf_prog *prog, const union bpf_attr *kattr, union bpf_attr __user *uattr) { struct bpf_fentry_test_t arg = {}; u16 side_effect = 0, ret = 0; - int b = 2, err = -EFAULT; - u32 retval = 0; + int b = 2, err = -EFAULT, current_cpu; + + void __user *ctx_in = u64_to_user_ptr(kattr->test.ctx_in); + __u32 ctx_size_in = kattr->test.ctx_size_in; + struct bpf_tracing_test_run_info info; + int cpu = kattr->test.cpu; if (kattr->test.flags || kattr->test.cpu || kattr->test.batch_size) return -EINVAL; @@ -828,11 +848,53 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog, goto out; } - retval = ((u32)side_effect << 16) | ret; - if (copy_to_user(&uattr->test.retval, &retval, sizeof(retval))) - goto out; + /* doesn't support data_in/out, ctx_out, duration, or repeat */ + if (kattr->test.data_in || kattr->test.data_out || + kattr->test.ctx_out || kattr->test.duration || + kattr->test.repeat || kattr->test.batch_size) + return -EINVAL; + + if (ctx_size_in < prog->aux->max_ctx_offset || + ctx_size_in > MAX_BPF_FUNC_ARGS * sizeof(u64)) + return -EINVAL; + + if ((kattr->test.flags & BPF_F_TEST_RUN_ON_CPU) == 0 && cpu != 0) + return -EINVAL; + + if (ctx_size_in) { + info.ctx = memdup_user(ctx_in, ctx_size_in); + if (IS_ERR(info.ctx)) + return PTR_ERR(info.ctx); + } else { + info.ctx = NULL; + } err = 0; + info.prog = prog; + + current_cpu = get_cpu(); + if ((kattr->test.flags & BPF_F_TEST_RUN_ON_CPU) == 0 || + cpu == current_cpu) { + __bpf_prog_test_run_tracing(&info); + } else if (cpu >= nr_cpu_ids || !cpu_online(cpu)) { + /* smp_call_function_single() also checks cpu_online() + * after csd_lock(). However, since cpu is from user + * space, let's do an extra quick check to filter out + * invalid value before smp_call_function_single(). + */ + err = -ENXIO; + } else { + err = smp_call_function_single(cpu, __bpf_prog_test_run_tracing, + &info, 1); + } + put_cpu(); + + if (!err && + copy_to_user(&uattr->test.retval, &info.retval, sizeof(u32))) + err = -EFAULT; + + kfree(info.ctx); + out: trace_bpf_test_finish(&err); return err;
This patch changes the behavior of how BPF_PROG_RUN treats tracing (fentry/fexit) programs. Previously only a return value is injected but the actual program was not run. New behavior mirrors that of running raw tracepoint BPF programs which actually runs the instructions of the program via `bpf_prog_run()` Tracing programs only needs to support an input context so we validate that non-relevant attributes are not set. Signed-off-by: Grant Seltzer <grantseltzer@gmail.com> --- net/bpf/test_run.c | 72 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 5 deletions(-)