public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Tony Ambardar <tony.ambardar@gmail.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
	Miguel Ojeda <ojeda@kernel.org>,
	kernel test robot <lkp@intel.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH bpf v2 2/2] bpf: Harden __bpf_kfunc tag against linker kfunc removal
Date: Tue, 4 Jun 2024 09:56:33 +0200	[thread overview]
Message-ID: <Zl7IscCtZVKjgP2h@krava> (raw)
In-Reply-To: <e9c64e9b5c073dabd457ff45128aabcab7630098.1717477560.git.Tony.Ambardar@gmail.com>

On Mon, Jun 03, 2024 at 10:23:16PM -0700, Tony Ambardar wrote:
> BPF kfuncs are often not directly referenced and may be inadvertently
> removed by optimization steps during kernel builds, thus the __bpf_kfunc
> tag mitigates against this removal by including the __used macro. However,
> this macro alone does not prevent removal during linking, and may still
> yield build warnings (e.g. on mips64el):
> 
>     LD      vmlinux
>     BTFIDS  vmlinux
>   WARN: resolve_btfids: unresolved symbol bpf_verify_pkcs7_signature
>   WARN: resolve_btfids: unresolved symbol bpf_lookup_user_key
>   WARN: resolve_btfids: unresolved symbol bpf_lookup_system_key
>   WARN: resolve_btfids: unresolved symbol bpf_key_put
>   WARN: resolve_btfids: unresolved symbol bpf_iter_task_next
>   WARN: resolve_btfids: unresolved symbol bpf_iter_css_task_new
>   WARN: resolve_btfids: unresolved symbol bpf_get_file_xattr
>   WARN: resolve_btfids: unresolved symbol bpf_ct_insert_entry
>   WARN: resolve_btfids: unresolved symbol bpf_cgroup_release
>   WARN: resolve_btfids: unresolved symbol bpf_cgroup_from_id
>   WARN: resolve_btfids: unresolved symbol bpf_cgroup_acquire
>   WARN: resolve_btfids: unresolved symbol bpf_arena_free_pages
>     NM      System.map
>     SORTTAB vmlinux
>     OBJCOPY vmlinux.32
> 
> Update the __bpf_kfunc tag to better guard against linker optimization by
> including the new __retain compiler macro, which fixes the warnings above.
> 
> Verify the __retain macro with readelf by checking object flags for 'R':
> 
>   $ readelf -Wa kernel/trace/bpf_trace.o
>   Section Headers:
>     [Nr]  Name              Type     Address  Off  Size ES Flg Lk Inf Al
>   ...
>     [178] .text.bpf_key_put PROGBITS 00000000 6420 0050 00 AXR  0   0  8
>   ...
>   Key to Flags:
>   ...
>     R (retain), D (mbind), p (processor specific)
> 
> Link: https://lore.kernel.org/bpf/ZlmGoT9KiYLZd91S@krava/T/
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/r/202401211357.OCX9yllM-lkp@intel.com/
> Fixes: 57e7c169cd6a ("bpf: Add __bpf_kfunc tag for marking kernel functions as kfuncs")
> Cc: stable@vger.kernel.org # v6.6+
> Signed-off-by: Tony Ambardar <Tony.Ambardar@gmail.com>

tested on mips64 cross build and the warnings are gone
and related functions are in the vmlinux

patchset looks good to me

Tested-by: Jiri Olsa <jolsa@kernel.org>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

> ---
>  include/linux/btf.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/btf.h b/include/linux/btf.h
> index f9e56fd12a9f..7c3e40c3295e 100644
> --- a/include/linux/btf.h
> +++ b/include/linux/btf.h
> @@ -82,7 +82,7 @@
>   * as to avoid issues such as the compiler inlining or eliding either a static
>   * kfunc, or a global kfunc in an LTO build.
>   */
> -#define __bpf_kfunc __used noinline
> +#define __bpf_kfunc __used __retain noinline
>  
>  #define __bpf_kfunc_start_defs()					       \
>  	__diag_push();							       \
> -- 
> 2.34.1
> 

  reply	other threads:[~2024-06-04  7:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Zl2GtXy7+Xfr66lX@kodidev-ubuntu>
     [not found] ` <cover.1717413886.git.Tony.Ambardar@gmail.com>
2024-06-03 12:16   ` [PATCH bpf v1 1/2] Compiler Attributes: Add __retain macro Tony Ambardar
2024-06-03 13:57     ` Miguel Ojeda
2024-06-04  2:37       ` Tony Ambardar
2024-06-03 12:16   ` [PATCH bpf v1 2/2] bpf: Harden __bpf_kfunc tag against linker kfunc removal Tony Ambardar
     [not found]   ` <cover.1717477560.git.Tony.Ambardar@gmail.com>
2024-06-04  5:23     ` [PATCH bpf v2 1/2] compiler_types.h: Define __retain for __attribute__((__retain__)) Tony Ambardar
2024-06-05  5:55       ` Yonghong Song
2024-06-10 22:56         ` Tony Ambardar
2024-06-14 18:47           ` Yonghong Song
2024-06-15  6:57             ` Tony Ambardar
2024-06-17  3:26               ` Yonghong Song
2024-06-04  5:23     ` [PATCH bpf v2 2/2] bpf: Harden __bpf_kfunc tag against linker kfunc removal Tony Ambardar
2024-06-04  7:56       ` Jiri Olsa [this message]
2024-06-25 10:46       ` Geert Uytterhoeven
2024-06-26  9:52         ` Jiri Olsa
2024-06-26 11:40           ` Geert Uytterhoeven

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=Zl7IscCtZVKjgP2h@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=kpsingh@kernel.org \
    --cc=lkp@intel.com \
    --cc=martin.lau@linux.dev \
    --cc=ojeda@kernel.org \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tony.ambardar@gmail.com \
    --cc=yonghong.song@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox