[jolsa-perf:bpf/batch 13/29] kernel/bpf/syscall.c:2858:24: warning: assignment to 'struct bpf_tramp_attach *' from 'int' makes pointer from integer without a cast

From: kernel test robot
Date: Thu Nov 18 2021 - 10:19:11 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git bpf/batch
head: 5f1f613266bf58f8424a93e1f8b99c4ac8fa6c2b
commit: c04eb2ad90ed0981f4dc7d04249a9c84726f9ef0 [13/29] bpf: Add bpf_tramp_attach layer for trampoline attachment
config: sh-randconfig-r025-20211118 (attached as .config)
compiler: sh4-linux-gcc (GCC) 11.2.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://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git/commit/?id=c04eb2ad90ed0981f4dc7d04249a9c84726f9ef0
git remote add jolsa-perf https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
git fetch --no-tags jolsa-perf bpf/batch
git checkout c04eb2ad90ed0981f4dc7d04249a9c84726f9ef0
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross ARCH=sh

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>

All warnings (new ones prefixed by >>):

cc1: warning: arch/sh/include/mach-rsk: No such file or directory [-Wmissing-include-dirs]
cc1: warning: arch/sh/include/mach-rsk: No such file or directory [-Wmissing-include-dirs]
In file included from arch/sh/include/asm/bug.h:112,
from include/linux/ktime.h:26,
from include/linux/timer.h:6,
from include/linux/workqueue.h:9,
from include/linux/bpf.h:9,
from kernel/bpf/syscall.c:4:
kernel/bpf/syscall.c: In function 'bpf_tracing_link_release':
kernel/bpf/syscall.c:2668:22: error: implicit declaration of function 'bpf_tramp_attach_unlink'; did you mean 'bpf_cgroup_storage_unlink'? [-Werror=implicit-function-declaration]
2668 | WARN_ON_ONCE(bpf_tramp_attach_unlink(attach));
| ^~~~~~~~~~~~~~~~~~~~~~~
include/asm-generic/bug.h:166:32: note: in definition of macro 'WARN_ON'
166 | int __ret_warn_on = !!(condition); \
| ^~~~~~~~~
kernel/bpf/syscall.c:2668:9: note: in expansion of macro 'WARN_ON_ONCE'
2668 | WARN_ON_ONCE(bpf_tramp_attach_unlink(attach));
| ^~~~~~~~~~~~
kernel/bpf/syscall.c:2672:9: error: implicit declaration of function 'bpf_tramp_detach' [-Werror=implicit-function-declaration]
2672 | bpf_tramp_detach(attach);
| ^~~~~~~~~~~~~~~~
kernel/bpf/syscall.c: In function 'bpf_tracing_prog_attach':
kernel/bpf/syscall.c:2769:22: error: implicit declaration of function 'bpf_tramp_id_alloc'; did you mean 'bpf_map_kzalloc'? [-Werror=implicit-function-declaration]
2769 | id = bpf_tramp_id_alloc();
| ^~~~~~~~~~~~~~~~~~
| bpf_map_kzalloc
kernel/bpf/syscall.c:2769:20: warning: assignment to 'struct bpf_tramp_id *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
2769 | id = bpf_tramp_id_alloc();
| ^
kernel/bpf/syscall.c:2782:17: error: implicit declaration of function 'bpf_tramp_id_init' [-Werror=implicit-function-declaration]
2782 | bpf_tramp_id_init(id, tgt_prog, NULL, btf_id);
| ^~~~~~~~~~~~~~~~~
kernel/bpf/syscall.c:2832:20: warning: assignment to 'struct bpf_tramp_id *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
2832 | id = bpf_tramp_id_alloc();
| ^
kernel/bpf/syscall.c:2843:15: error: implicit declaration of function 'bpf_tramp_id_is_empty' [-Werror=implicit-function-declaration]
2843 | (!bpf_tramp_id_is_empty(id) &&
| ^~~~~~~~~~~~~~~~~~~~~
kernel/bpf/syscall.c:2844:15: error: implicit declaration of function 'bpf_tramp_id_is_equal' [-Werror=implicit-function-declaration]
2844 | bpf_tramp_id_is_equal(id, prog->aux->dst_attach->id))) {
| ^~~~~~~~~~~~~~~~~~~~~
kernel/bpf/syscall.c:2858:26: error: implicit declaration of function 'bpf_tramp_attach'; did you mean 'bpf_iter_link_attach'? [-Werror=implicit-function-declaration]
2858 | attach = bpf_tramp_attach(id, tgt_prog, prog);
| ^~~~~~~~~~~~~~~~
| bpf_iter_link_attach
>> kernel/bpf/syscall.c:2858:24: warning: assignment to 'struct bpf_tramp_attach *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
2858 | attach = bpf_tramp_attach(id, tgt_prog, prog);
| ^
kernel/bpf/syscall.c:2879:15: error: implicit declaration of function 'bpf_tramp_attach_link' [-Werror=implicit-function-declaration]
2879 | err = bpf_tramp_attach_link(attach);
| ^~~~~~~~~~~~~~~~~~~~~
kernel/bpf/syscall.c:2917:9: error: implicit declaration of function 'bpf_tramp_id_free' [-Werror=implicit-function-declaration]
2917 | bpf_tramp_id_free(id);
| ^~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
--
cc1: warning: arch/sh/include/mach-rsk: No such file or directory [-Wmissing-include-dirs]
cc1: warning: arch/sh/include/mach-rsk: No such file or directory [-Wmissing-include-dirs]
kernel/bpf/verifier.c: In function 'check_attach_btf_id':
kernel/bpf/verifier.c:13998:14: error: implicit declaration of function 'bpf_tramp_id_alloc'; did you mean 'bpf_map_kzalloc'? [-Werror=implicit-function-declaration]
13998 | id = bpf_tramp_id_alloc();
| ^~~~~~~~~~~~~~~~~~
| bpf_map_kzalloc
kernel/bpf/verifier.c:13998:12: warning: assignment to 'struct bpf_tramp_id *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
13998 | id = bpf_tramp_id_alloc();
| ^
kernel/bpf/verifier.c:14002:9: error: implicit declaration of function 'bpf_tramp_id_init' [-Werror=implicit-function-declaration]
14002 | bpf_tramp_id_init(id, tgt_prog, prog->aux->attach_btf, btf_id);
| ^~~~~~~~~~~~~~~~~
kernel/bpf/verifier.c:14005:18: error: implicit declaration of function 'bpf_tramp_attach'; did you mean 'bpf_iter_link_attach'? [-Werror=implicit-function-declaration]
14005 | attach = bpf_tramp_attach(id, tgt_prog, prog);
| ^~~~~~~~~~~~~~~~
| bpf_iter_link_attach
>> kernel/bpf/verifier.c:14005:16: warning: assignment to 'struct bpf_tramp_attach *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
14005 | attach = bpf_tramp_attach(id, tgt_prog, prog);
| ^
kernel/bpf/verifier.c:14007:17: error: implicit declaration of function 'bpf_tramp_id_free' [-Werror=implicit-function-declaration]
14007 | bpf_tramp_id_free(id);
| ^~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors


vim +2858 kernel/bpf/syscall.c

2718
2719 static int bpf_tracing_prog_attach(struct bpf_prog *prog,
2720 int tgt_prog_fd,
2721 u32 btf_id)
2722 {
2723 bool prog_extension = prog->type == BPF_PROG_TYPE_EXT;
2724 struct bpf_tramp_attach *attach = NULL;
2725 struct bpf_link_primer link_primer;
2726 struct bpf_prog *tgt_prog = NULL;
2727 struct bpf_tracing_link *link;
2728 struct bpf_tramp_id *id = NULL;
2729 int err;
2730
2731 switch (prog->type) {
2732 case BPF_PROG_TYPE_TRACING:
2733 if (prog->expected_attach_type != BPF_TRACE_FENTRY &&
2734 prog->expected_attach_type != BPF_TRACE_FEXIT &&
2735 prog->expected_attach_type != BPF_MODIFY_RETURN) {
2736 err = -EINVAL;
2737 goto out_put_prog;
2738 }
2739 break;
2740 case BPF_PROG_TYPE_EXT:
2741 if (prog->expected_attach_type != 0) {
2742 err = -EINVAL;
2743 goto out_put_prog;
2744 }
2745 break;
2746 case BPF_PROG_TYPE_LSM:
2747 if (prog->expected_attach_type != BPF_LSM_MAC) {
2748 err = -EINVAL;
2749 goto out_put_prog;
2750 }
2751 break;
2752 default:
2753 err = -EINVAL;
2754 goto out_put_prog;
2755 }
2756
2757 if (!!tgt_prog_fd != !!btf_id) {
2758 err = -EINVAL;
2759 goto out_put_prog;
2760 }
2761
2762 if (tgt_prog_fd) {
2763 /* For now we only allow new targets for BPF_PROG_TYPE_EXT */
2764 if (prog->type != BPF_PROG_TYPE_EXT) {
2765 err = -EINVAL;
2766 goto out_put_prog;
2767 }
2768
2769 id = bpf_tramp_id_alloc();
2770 if (!id) {
2771 err = -ENOMEM;
2772 goto out_put_prog;
2773 }
2774
2775 tgt_prog = bpf_prog_get(tgt_prog_fd);
2776 if (IS_ERR(tgt_prog)) {
2777 err = PTR_ERR(tgt_prog);
2778 tgt_prog = NULL;
2779 goto out_put_prog;
2780 }
2781
2782 bpf_tramp_id_init(id, tgt_prog, NULL, btf_id);
2783 }
2784
2785 link = kzalloc(sizeof(*link), GFP_USER);
2786 if (!link) {
2787 err = -ENOMEM;
2788 goto out_put_prog;
2789 }
2790 bpf_link_init(&link->link, BPF_LINK_TYPE_TRACING,
2791 &bpf_tracing_link_lops, prog);
2792 link->attach_type = prog->expected_attach_type;
2793
2794 mutex_lock(&prog->aux->dst_mutex);
2795
2796 if (!prog_extension && prog->aux->attach) {
2797 err = -EBUSY;
2798 goto out_unlock;
2799 }
2800
2801 /* There are a few possible cases here:
2802 *
2803 * - if prog->aux->dst_trampoline is set, the program was just loaded
2804 * and not yet attached to anything, so we can use the values stored
2805 * in prog->aux
2806 *
2807 * - if prog->aux->dst_trampoline is NULL, the program has already been
2808 * attached to a target and its initial target was cleared (below)
2809 *
2810 * - if tgt_prog != NULL, the caller specified tgt_prog_fd +
2811 * target_btf_id using the link_create API.
2812 *
2813 * - if tgt_prog == NULL when this function was called using the old
2814 * raw_tracepoint_open API, and we need a target from prog->aux
2815 *
2816 * - if prog->aux->dst_trampoline and tgt_prog is NULL, the program
2817 * was detached and is going for re-attachment.
2818 */
2819 if (!prog->aux->dst_attach && !tgt_prog) {
2820 /*
2821 * Allow re-attach for TRACING and LSM programs. If it's
2822 * currently linked, bpf_trampoline_link_prog will fail.
2823 * EXT programs need to specify tgt_prog_fd, so they
2824 * re-attach in separate code path.
2825 */
2826 if (prog->type != BPF_PROG_TYPE_TRACING &&
2827 prog->type != BPF_PROG_TYPE_LSM) {
2828 err = -EINVAL;
2829 goto out_unlock;
2830 }
2831
2832 id = bpf_tramp_id_alloc();
2833 if (!id) {
2834 err = -ENOMEM;
2835 goto out_unlock;
2836 }
2837
2838 btf_id = prog->aux->attach_btf_id;
2839 bpf_tramp_id_init(id, NULL, prog->aux->attach_btf, btf_id);
2840 }
2841
2842 if (!prog->aux->dst_attach ||
2843 (!bpf_tramp_id_is_empty(id) &&
> 2844 bpf_tramp_id_is_equal(id, prog->aux->dst_attach->id))) {
2845 /* If there is no saved target, or the specified target is
2846 * different from the destination specified at load time, we
2847 * need a new trampoline and a check for compatibility
2848 */
2849 struct bpf_attach_target_info tgt_info = {};
2850
2851 err = bpf_check_attach_target(NULL, prog, tgt_prog, btf_id,
2852 &tgt_info);
2853 if (err)
2854 goto out_unlock;
2855
2856 id->addr = (void *) tgt_info.tgt_addr;
2857
> 2858 attach = bpf_tramp_attach(id, tgt_prog, prog);
2859 if (IS_ERR(attach)) {
2860 err = PTR_ERR(attach);
2861 goto out_unlock;
2862 }
2863 } else {
2864 /* The caller didn't specify a target, or the target was the
2865 * same as the destination supplied during program load. This
2866 * means we can reuse the trampoline and reference from program
2867 * load time, and there is no need to allocate a new one. This
2868 * can only happen once for any program, as the saved values in
2869 * prog->aux are cleared below.
2870 */
2871 attach = prog->aux->dst_attach;
2872 tgt_prog = prog->aux->dst_prog;
2873 }
2874
2875 err = bpf_link_prime(&link->link, &link_primer);
2876 if (err)
2877 goto out_unlock;
2878
2879 err = bpf_tramp_attach_link(attach);
2880 if (err) {
2881 bpf_link_cleanup(&link_primer);
2882 link = NULL;
2883 goto out_unlock;
2884 }
2885
2886 link->tgt_prog = tgt_prog;
2887 if (prog_extension)
2888 link->attach = attach;
2889 else
2890 prog->aux->attach = attach;
2891
2892 /* Always clear the trampoline and target prog from prog->aux to make
2893 * sure the original attach destination is not kept alive after a
2894 * program is (re-)attached to another target.
2895 */
2896 if (prog->aux->dst_prog &&
2897 (tgt_prog_fd || attach != prog->aux->dst_attach))
2898 /* got extra prog ref from syscall, or attaching to different prog */
2899 bpf_prog_put(prog->aux->dst_prog);
2900 if (prog->aux->dst_attach && attach != prog->aux->dst_attach)
2901 /* we allocated a new trampoline, so free the old one */
2902 bpf_tramp_detach(prog->aux->dst_attach);
2903
2904 prog->aux->dst_prog = NULL;
2905 prog->aux->dst_attach = NULL;
2906 mutex_unlock(&prog->aux->dst_mutex);
2907
2908 return bpf_link_settle(&link_primer);
2909 out_unlock:
2910 if (attach && attach != prog->aux->dst_attach)
2911 bpf_tramp_detach(attach);
2912 mutex_unlock(&prog->aux->dst_mutex);
2913 kfree(link);
2914 out_put_prog:
2915 if (tgt_prog_fd && tgt_prog)
2916 bpf_prog_put(tgt_prog);
2917 bpf_tramp_id_free(id);
2918 return err;
2919 }
2920

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip