All of lore.kernel.org
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: Jiri Olsa <jolsa@kernel.org>
Cc: llvm@lists.linux.dev, kbuild-all@lists.01.org,
	linux-kernel@vger.kernel.org
Subject: [jolsa-perf:bpf/batch 16/29] kernel/bpf/syscall.c:2776:8: error: implicit declaration of function 'bpf_tramp_id_single'
Date: Fri, 19 Nov 2021 01:01:45 +0800	[thread overview]
Message-ID: <202111190134.VHanZU6M-lkp@intel.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 12869 bytes --]

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git bpf/batch
head:   5f1f613266bf58f8424a93e1f8b99c4ac8fa6c2b
commit: 378851fb026c8aeef2c2f622957a91a1f0fae87f [16/29] bpf: Add bpf_tramp_id_single function
config: hexagon-randconfig-r035-20211118 (attached as .config)
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=378851fb026c8aeef2c2f622957a91a1f0fae87f
        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 378851fb026c8aeef2c2f622957a91a1f0fae87f
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=hexagon 

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

All errors (new ones prefixed by >>):

   kernel/bpf/syscall.c:2668:15: error: implicit declaration of function 'bpf_tramp_attach_unlink' [-Werror,-Wimplicit-function-declaration]
           WARN_ON_ONCE(bpf_tramp_attach_unlink(attach));
                        ^
   kernel/bpf/syscall.c:2672:2: error: implicit declaration of function 'bpf_tramp_detach' [-Werror,-Wimplicit-function-declaration]
           bpf_tramp_detach(attach);
           ^
>> kernel/bpf/syscall.c:2776:8: error: implicit declaration of function 'bpf_tramp_id_single' [-Werror,-Wimplicit-function-declaration]
                   id = bpf_tramp_id_single(tgt_prog, NULL, btf_id);
                        ^
   kernel/bpf/syscall.c:2776:6: warning: incompatible integer to pointer conversion assigning to 'struct bpf_tramp_id *' from 'int' [-Wint-conversion]
                   id = bpf_tramp_id_single(tgt_prog, NULL, btf_id);
                      ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/bpf/syscall.c:2831:8: error: implicit declaration of function 'bpf_tramp_id_single' [-Werror,-Wimplicit-function-declaration]
                   id = bpf_tramp_id_single(NULL, prog->aux->attach_btf, btf_id);
                        ^
   kernel/bpf/syscall.c:2831:6: warning: incompatible integer to pointer conversion assigning to 'struct bpf_tramp_id *' from 'int' [-Wint-conversion]
                   id = bpf_tramp_id_single(NULL, prog->aux->attach_btf, btf_id);
                      ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/bpf/syscall.c:2839:8: error: implicit declaration of function 'bpf_tramp_id_is_empty' [-Werror,-Wimplicit-function-declaration]
               (!bpf_tramp_id_is_empty(id) &&
                 ^
   kernel/bpf/syscall.c:2840:8: error: implicit declaration of function 'bpf_tramp_id_is_equal' [-Werror,-Wimplicit-function-declaration]
                 bpf_tramp_id_is_equal(id, prog->aux->dst_attach->id))) {
                 ^
   kernel/bpf/syscall.c:2840:8: note: did you mean 'bpf_tramp_id_is_empty'?
   kernel/bpf/syscall.c:2839:8: note: 'bpf_tramp_id_is_empty' declared here
               (!bpf_tramp_id_is_empty(id) &&
                 ^
   kernel/bpf/syscall.c:2854:12: error: implicit declaration of function 'bpf_tramp_attach' [-Werror,-Wimplicit-function-declaration]
                   attach = bpf_tramp_attach(id, tgt_prog, prog);
                            ^
   kernel/bpf/syscall.c:2854:10: warning: incompatible integer to pointer conversion assigning to 'struct bpf_tramp_attach *' from 'int' [-Wint-conversion]
                   attach = bpf_tramp_attach(id, tgt_prog, prog);
                          ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/bpf/syscall.c:2875:8: error: implicit declaration of function 'bpf_tramp_attach_link' [-Werror,-Wimplicit-function-declaration]
           err = bpf_tramp_attach_link(attach);
                 ^
   kernel/bpf/syscall.c:2898:3: error: implicit declaration of function 'bpf_tramp_detach' [-Werror,-Wimplicit-function-declaration]
                   bpf_tramp_detach(prog->aux->dst_attach);
                   ^
   kernel/bpf/syscall.c:2913:2: error: implicit declaration of function 'bpf_tramp_id_free' [-Werror,-Wimplicit-function-declaration]
           bpf_tramp_id_free(id);
           ^
   3 warnings and 10 errors generated.
--
>> kernel/bpf/verifier.c:13998:7: error: implicit declaration of function 'bpf_tramp_id_single' [-Werror,-Wimplicit-function-declaration]
           id = bpf_tramp_id_single(NULL, prog->aux->attach_btf, btf_id);
                ^
   kernel/bpf/verifier.c:13998:5: warning: incompatible integer to pointer conversion assigning to 'struct bpf_tramp_id *' from 'int' [-Wint-conversion]
           id = bpf_tramp_id_single(NULL, prog->aux->attach_btf, btf_id);
              ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/bpf/verifier.c:14004:11: error: implicit declaration of function 'bpf_tramp_attach' [-Werror,-Wimplicit-function-declaration]
           attach = bpf_tramp_attach(id, tgt_prog, prog);
                    ^
   kernel/bpf/verifier.c:14004:9: warning: incompatible integer to pointer conversion assigning to 'struct bpf_tramp_attach *' from 'int' [-Wint-conversion]
           attach = bpf_tramp_attach(id, tgt_prog, prog);
                  ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/bpf/verifier.c:14006:3: error: implicit declaration of function 'bpf_tramp_id_free' [-Werror,-Wimplicit-function-declaration]
                   bpf_tramp_id_free(id);
                   ^
   kernel/bpf/verifier.c:14006:3: note: did you mean 'bpf_tramp_id_single'?
   kernel/bpf/verifier.c:13998:7: note: 'bpf_tramp_id_single' declared here
           id = bpf_tramp_id_single(NULL, prog->aux->attach_btf, btf_id);
                ^
   2 warnings and 3 errors generated.


vim +/bpf_tramp_id_single +2776 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			tgt_prog = bpf_prog_get(tgt_prog_fd);
  2770			if (IS_ERR(tgt_prog)) {
  2771				err = PTR_ERR(tgt_prog);
  2772				tgt_prog = NULL;
  2773				goto out_put_prog;
  2774			}
  2775	
> 2776			id = bpf_tramp_id_single(tgt_prog, NULL, btf_id);
  2777			if (!id) {
  2778				err = -ENOMEM;
  2779				goto out_put_prog;
  2780			}
  2781		}
  2782	
  2783		link = kzalloc(sizeof(*link), GFP_USER);
  2784		if (!link) {
  2785			err = -ENOMEM;
  2786			goto out_put_prog;
  2787		}
  2788		bpf_link_init(&link->link, BPF_LINK_TYPE_TRACING,
  2789			      &bpf_tracing_link_lops, prog);
  2790		link->attach_type = prog->expected_attach_type;
  2791	
  2792		mutex_lock(&prog->aux->dst_mutex);
  2793	
  2794		if (!prog_extension && prog->aux->attach) {
  2795			err = -EBUSY;
  2796			goto out_unlock;
  2797		}
  2798	
  2799		/* There are a few possible cases here:
  2800		 *
  2801		 * - if prog->aux->dst_trampoline is set, the program was just loaded
  2802		 *   and not yet attached to anything, so we can use the values stored
  2803		 *   in prog->aux
  2804		 *
  2805		 * - if prog->aux->dst_trampoline is NULL, the program has already been
  2806	         *   attached to a target and its initial target was cleared (below)
  2807		 *
  2808		 * - if tgt_prog != NULL, the caller specified tgt_prog_fd +
  2809		 *   target_btf_id using the link_create API.
  2810		 *
  2811		 * - if tgt_prog == NULL when this function was called using the old
  2812		 *   raw_tracepoint_open API, and we need a target from prog->aux
  2813		 *
  2814		 * - if prog->aux->dst_trampoline and tgt_prog is NULL, the program
  2815		 *   was detached and is going for re-attachment.
  2816		 */
  2817		if (!prog->aux->dst_attach && !tgt_prog) {
  2818			/*
  2819			 * Allow re-attach for TRACING and LSM programs. If it's
  2820			 * currently linked, bpf_trampoline_link_prog will fail.
  2821			 * EXT programs need to specify tgt_prog_fd, so they
  2822			 * re-attach in separate code path.
  2823			 */
  2824			if (prog->type != BPF_PROG_TYPE_TRACING &&
  2825			    prog->type != BPF_PROG_TYPE_LSM) {
  2826				err = -EINVAL;
  2827				goto out_unlock;
  2828			}
  2829	
  2830			btf_id = prog->aux->attach_btf_id;
  2831			id = bpf_tramp_id_single(NULL, prog->aux->attach_btf, btf_id);
  2832			if (!id) {
  2833				err = -ENOMEM;
  2834				goto out_unlock;
  2835			}
  2836		}
  2837	
  2838		if (!prog->aux->dst_attach ||
  2839		    (!bpf_tramp_id_is_empty(id) &&
  2840		      bpf_tramp_id_is_equal(id, prog->aux->dst_attach->id))) {
  2841			/* If there is no saved target, or the specified target is
  2842			 * different from the destination specified at load time, we
  2843			 * need a new trampoline and a check for compatibility
  2844			 */
  2845			struct bpf_attach_target_info tgt_info = {};
  2846	
  2847			err = bpf_check_attach_target(NULL, prog, tgt_prog, btf_id,
  2848						      &tgt_info);
  2849			if (err)
  2850				goto out_unlock;
  2851	
  2852			id->addr[0] = (void *) tgt_info.tgt_addr;
  2853	
  2854			attach = bpf_tramp_attach(id, tgt_prog, prog);
  2855			if (IS_ERR(attach)) {
  2856				err = PTR_ERR(attach);
  2857				goto out_unlock;
  2858			}
  2859		} else {
  2860			/* The caller didn't specify a target, or the target was the
  2861			 * same as the destination supplied during program load. This
  2862			 * means we can reuse the trampoline and reference from program
  2863			 * load time, and there is no need to allocate a new one. This
  2864			 * can only happen once for any program, as the saved values in
  2865			 * prog->aux are cleared below.
  2866			 */
  2867			attach = prog->aux->dst_attach;
  2868			tgt_prog = prog->aux->dst_prog;
  2869		}
  2870	
  2871		err = bpf_link_prime(&link->link, &link_primer);
  2872		if (err)
  2873			goto out_unlock;
  2874	
  2875		err = bpf_tramp_attach_link(attach);
  2876		if (err) {
  2877			bpf_link_cleanup(&link_primer);
  2878			link = NULL;
  2879			goto out_unlock;
  2880		}
  2881	
  2882		link->tgt_prog = tgt_prog;
  2883		if (prog_extension)
  2884			link->attach = attach;
  2885		else
  2886			prog->aux->attach = attach;
  2887	
  2888		/* Always clear the trampoline and target prog from prog->aux to make
  2889		 * sure the original attach destination is not kept alive after a
  2890		 * program is (re-)attached to another target.
  2891		 */
  2892		if (prog->aux->dst_prog &&
  2893		    (tgt_prog_fd || attach != prog->aux->dst_attach))
  2894			/* got extra prog ref from syscall, or attaching to different prog */
  2895			bpf_prog_put(prog->aux->dst_prog);
  2896		if (prog->aux->dst_attach && attach != prog->aux->dst_attach)
  2897			/* we allocated a new trampoline, so free the old one */
  2898			bpf_tramp_detach(prog->aux->dst_attach);
  2899	
  2900		prog->aux->dst_prog = NULL;
  2901		prog->aux->dst_attach = NULL;
  2902		mutex_unlock(&prog->aux->dst_mutex);
  2903	
  2904		return bpf_link_settle(&link_primer);
  2905	out_unlock:
  2906		if (attach && attach != prog->aux->dst_attach)
  2907			bpf_tramp_detach(attach);
  2908		mutex_unlock(&prog->aux->dst_mutex);
  2909		kfree(link);
  2910	out_put_prog:
  2911		if (tgt_prog_fd && tgt_prog)
  2912			bpf_prog_put(tgt_prog);
  2913		bpf_tramp_id_free(id);
  2914		return err;
  2915	}
  2916	

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

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 23348 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: kernel test robot <lkp@intel.com>
To: kbuild-all@lists.01.org
Subject: [jolsa-perf:bpf/batch 16/29] kernel/bpf/syscall.c:2776:8: error: implicit declaration of function 'bpf_tramp_id_single'
Date: Fri, 19 Nov 2021 01:01:45 +0800	[thread overview]
Message-ID: <202111190134.VHanZU6M-lkp@intel.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 13162 bytes --]

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git bpf/batch
head:   5f1f613266bf58f8424a93e1f8b99c4ac8fa6c2b
commit: 378851fb026c8aeef2c2f622957a91a1f0fae87f [16/29] bpf: Add bpf_tramp_id_single function
config: hexagon-randconfig-r035-20211118 (attached as .config)
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=378851fb026c8aeef2c2f622957a91a1f0fae87f
        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 378851fb026c8aeef2c2f622957a91a1f0fae87f
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=hexagon 

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

All errors (new ones prefixed by >>):

   kernel/bpf/syscall.c:2668:15: error: implicit declaration of function 'bpf_tramp_attach_unlink' [-Werror,-Wimplicit-function-declaration]
           WARN_ON_ONCE(bpf_tramp_attach_unlink(attach));
                        ^
   kernel/bpf/syscall.c:2672:2: error: implicit declaration of function 'bpf_tramp_detach' [-Werror,-Wimplicit-function-declaration]
           bpf_tramp_detach(attach);
           ^
>> kernel/bpf/syscall.c:2776:8: error: implicit declaration of function 'bpf_tramp_id_single' [-Werror,-Wimplicit-function-declaration]
                   id = bpf_tramp_id_single(tgt_prog, NULL, btf_id);
                        ^
   kernel/bpf/syscall.c:2776:6: warning: incompatible integer to pointer conversion assigning to 'struct bpf_tramp_id *' from 'int' [-Wint-conversion]
                   id = bpf_tramp_id_single(tgt_prog, NULL, btf_id);
                      ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/bpf/syscall.c:2831:8: error: implicit declaration of function 'bpf_tramp_id_single' [-Werror,-Wimplicit-function-declaration]
                   id = bpf_tramp_id_single(NULL, prog->aux->attach_btf, btf_id);
                        ^
   kernel/bpf/syscall.c:2831:6: warning: incompatible integer to pointer conversion assigning to 'struct bpf_tramp_id *' from 'int' [-Wint-conversion]
                   id = bpf_tramp_id_single(NULL, prog->aux->attach_btf, btf_id);
                      ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/bpf/syscall.c:2839:8: error: implicit declaration of function 'bpf_tramp_id_is_empty' [-Werror,-Wimplicit-function-declaration]
               (!bpf_tramp_id_is_empty(id) &&
                 ^
   kernel/bpf/syscall.c:2840:8: error: implicit declaration of function 'bpf_tramp_id_is_equal' [-Werror,-Wimplicit-function-declaration]
                 bpf_tramp_id_is_equal(id, prog->aux->dst_attach->id))) {
                 ^
   kernel/bpf/syscall.c:2840:8: note: did you mean 'bpf_tramp_id_is_empty'?
   kernel/bpf/syscall.c:2839:8: note: 'bpf_tramp_id_is_empty' declared here
               (!bpf_tramp_id_is_empty(id) &&
                 ^
   kernel/bpf/syscall.c:2854:12: error: implicit declaration of function 'bpf_tramp_attach' [-Werror,-Wimplicit-function-declaration]
                   attach = bpf_tramp_attach(id, tgt_prog, prog);
                            ^
   kernel/bpf/syscall.c:2854:10: warning: incompatible integer to pointer conversion assigning to 'struct bpf_tramp_attach *' from 'int' [-Wint-conversion]
                   attach = bpf_tramp_attach(id, tgt_prog, prog);
                          ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/bpf/syscall.c:2875:8: error: implicit declaration of function 'bpf_tramp_attach_link' [-Werror,-Wimplicit-function-declaration]
           err = bpf_tramp_attach_link(attach);
                 ^
   kernel/bpf/syscall.c:2898:3: error: implicit declaration of function 'bpf_tramp_detach' [-Werror,-Wimplicit-function-declaration]
                   bpf_tramp_detach(prog->aux->dst_attach);
                   ^
   kernel/bpf/syscall.c:2913:2: error: implicit declaration of function 'bpf_tramp_id_free' [-Werror,-Wimplicit-function-declaration]
           bpf_tramp_id_free(id);
           ^
   3 warnings and 10 errors generated.
--
>> kernel/bpf/verifier.c:13998:7: error: implicit declaration of function 'bpf_tramp_id_single' [-Werror,-Wimplicit-function-declaration]
           id = bpf_tramp_id_single(NULL, prog->aux->attach_btf, btf_id);
                ^
   kernel/bpf/verifier.c:13998:5: warning: incompatible integer to pointer conversion assigning to 'struct bpf_tramp_id *' from 'int' [-Wint-conversion]
           id = bpf_tramp_id_single(NULL, prog->aux->attach_btf, btf_id);
              ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/bpf/verifier.c:14004:11: error: implicit declaration of function 'bpf_tramp_attach' [-Werror,-Wimplicit-function-declaration]
           attach = bpf_tramp_attach(id, tgt_prog, prog);
                    ^
   kernel/bpf/verifier.c:14004:9: warning: incompatible integer to pointer conversion assigning to 'struct bpf_tramp_attach *' from 'int' [-Wint-conversion]
           attach = bpf_tramp_attach(id, tgt_prog, prog);
                  ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/bpf/verifier.c:14006:3: error: implicit declaration of function 'bpf_tramp_id_free' [-Werror,-Wimplicit-function-declaration]
                   bpf_tramp_id_free(id);
                   ^
   kernel/bpf/verifier.c:14006:3: note: did you mean 'bpf_tramp_id_single'?
   kernel/bpf/verifier.c:13998:7: note: 'bpf_tramp_id_single' declared here
           id = bpf_tramp_id_single(NULL, prog->aux->attach_btf, btf_id);
                ^
   2 warnings and 3 errors generated.


vim +/bpf_tramp_id_single +2776 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			tgt_prog = bpf_prog_get(tgt_prog_fd);
  2770			if (IS_ERR(tgt_prog)) {
  2771				err = PTR_ERR(tgt_prog);
  2772				tgt_prog = NULL;
  2773				goto out_put_prog;
  2774			}
  2775	
> 2776			id = bpf_tramp_id_single(tgt_prog, NULL, btf_id);
  2777			if (!id) {
  2778				err = -ENOMEM;
  2779				goto out_put_prog;
  2780			}
  2781		}
  2782	
  2783		link = kzalloc(sizeof(*link), GFP_USER);
  2784		if (!link) {
  2785			err = -ENOMEM;
  2786			goto out_put_prog;
  2787		}
  2788		bpf_link_init(&link->link, BPF_LINK_TYPE_TRACING,
  2789			      &bpf_tracing_link_lops, prog);
  2790		link->attach_type = prog->expected_attach_type;
  2791	
  2792		mutex_lock(&prog->aux->dst_mutex);
  2793	
  2794		if (!prog_extension && prog->aux->attach) {
  2795			err = -EBUSY;
  2796			goto out_unlock;
  2797		}
  2798	
  2799		/* There are a few possible cases here:
  2800		 *
  2801		 * - if prog->aux->dst_trampoline is set, the program was just loaded
  2802		 *   and not yet attached to anything, so we can use the values stored
  2803		 *   in prog->aux
  2804		 *
  2805		 * - if prog->aux->dst_trampoline is NULL, the program has already been
  2806	         *   attached to a target and its initial target was cleared (below)
  2807		 *
  2808		 * - if tgt_prog != NULL, the caller specified tgt_prog_fd +
  2809		 *   target_btf_id using the link_create API.
  2810		 *
  2811		 * - if tgt_prog == NULL when this function was called using the old
  2812		 *   raw_tracepoint_open API, and we need a target from prog->aux
  2813		 *
  2814		 * - if prog->aux->dst_trampoline and tgt_prog is NULL, the program
  2815		 *   was detached and is going for re-attachment.
  2816		 */
  2817		if (!prog->aux->dst_attach && !tgt_prog) {
  2818			/*
  2819			 * Allow re-attach for TRACING and LSM programs. If it's
  2820			 * currently linked, bpf_trampoline_link_prog will fail.
  2821			 * EXT programs need to specify tgt_prog_fd, so they
  2822			 * re-attach in separate code path.
  2823			 */
  2824			if (prog->type != BPF_PROG_TYPE_TRACING &&
  2825			    prog->type != BPF_PROG_TYPE_LSM) {
  2826				err = -EINVAL;
  2827				goto out_unlock;
  2828			}
  2829	
  2830			btf_id = prog->aux->attach_btf_id;
  2831			id = bpf_tramp_id_single(NULL, prog->aux->attach_btf, btf_id);
  2832			if (!id) {
  2833				err = -ENOMEM;
  2834				goto out_unlock;
  2835			}
  2836		}
  2837	
  2838		if (!prog->aux->dst_attach ||
  2839		    (!bpf_tramp_id_is_empty(id) &&
  2840		      bpf_tramp_id_is_equal(id, prog->aux->dst_attach->id))) {
  2841			/* If there is no saved target, or the specified target is
  2842			 * different from the destination specified at load time, we
  2843			 * need a new trampoline and a check for compatibility
  2844			 */
  2845			struct bpf_attach_target_info tgt_info = {};
  2846	
  2847			err = bpf_check_attach_target(NULL, prog, tgt_prog, btf_id,
  2848						      &tgt_info);
  2849			if (err)
  2850				goto out_unlock;
  2851	
  2852			id->addr[0] = (void *) tgt_info.tgt_addr;
  2853	
  2854			attach = bpf_tramp_attach(id, tgt_prog, prog);
  2855			if (IS_ERR(attach)) {
  2856				err = PTR_ERR(attach);
  2857				goto out_unlock;
  2858			}
  2859		} else {
  2860			/* The caller didn't specify a target, or the target was the
  2861			 * same as the destination supplied during program load. This
  2862			 * means we can reuse the trampoline and reference from program
  2863			 * load time, and there is no need to allocate a new one. This
  2864			 * can only happen once for any program, as the saved values in
  2865			 * prog->aux are cleared below.
  2866			 */
  2867			attach = prog->aux->dst_attach;
  2868			tgt_prog = prog->aux->dst_prog;
  2869		}
  2870	
  2871		err = bpf_link_prime(&link->link, &link_primer);
  2872		if (err)
  2873			goto out_unlock;
  2874	
  2875		err = bpf_tramp_attach_link(attach);
  2876		if (err) {
  2877			bpf_link_cleanup(&link_primer);
  2878			link = NULL;
  2879			goto out_unlock;
  2880		}
  2881	
  2882		link->tgt_prog = tgt_prog;
  2883		if (prog_extension)
  2884			link->attach = attach;
  2885		else
  2886			prog->aux->attach = attach;
  2887	
  2888		/* Always clear the trampoline and target prog from prog->aux to make
  2889		 * sure the original attach destination is not kept alive after a
  2890		 * program is (re-)attached to another target.
  2891		 */
  2892		if (prog->aux->dst_prog &&
  2893		    (tgt_prog_fd || attach != prog->aux->dst_attach))
  2894			/* got extra prog ref from syscall, or attaching to different prog */
  2895			bpf_prog_put(prog->aux->dst_prog);
  2896		if (prog->aux->dst_attach && attach != prog->aux->dst_attach)
  2897			/* we allocated a new trampoline, so free the old one */
  2898			bpf_tramp_detach(prog->aux->dst_attach);
  2899	
  2900		prog->aux->dst_prog = NULL;
  2901		prog->aux->dst_attach = NULL;
  2902		mutex_unlock(&prog->aux->dst_mutex);
  2903	
  2904		return bpf_link_settle(&link_primer);
  2905	out_unlock:
  2906		if (attach && attach != prog->aux->dst_attach)
  2907			bpf_tramp_detach(attach);
  2908		mutex_unlock(&prog->aux->dst_mutex);
  2909		kfree(link);
  2910	out_put_prog:
  2911		if (tgt_prog_fd && tgt_prog)
  2912			bpf_prog_put(tgt_prog);
  2913		bpf_tramp_id_free(id);
  2914		return err;
  2915	}
  2916	

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

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 23348 bytes --]

             reply	other threads:[~2021-11-18 17:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-18 17:01 kernel test robot [this message]
2021-11-18 17:01 ` [jolsa-perf:bpf/batch 16/29] kernel/bpf/syscall.c:2776:8: error: implicit declaration of function 'bpf_tramp_id_single' kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202111190134.VHanZU6M-lkp@intel.com \
    --to=lkp@intel.com \
    --cc=jolsa@kernel.org \
    --cc=kbuild-all@lists.01.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.