netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Jared Kangas <jkangas@redhat.com>
Cc: bpf@vger.kernel.org, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
	martin.lau@kernel.org, ast@kernel.org, johannes.berg@intel.com,
	kafai@fb.com, songliubraving@fb.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf] bpf: use attach_btf instead of vmlinux in bpf_sk_storage_tracing_allowed
Date: Thu, 16 Jan 2025 12:03:53 -0800	[thread overview]
Message-ID: <9e5b183e-5dd5-4d3d-b3e6-09ad5e7262dc@linux.dev> (raw)
In-Reply-To: <20250116162356.1054047-1-jkangas@redhat.com>

On 1/16/25 8:23 AM, Jared Kangas wrote:
> diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c
> index 2f4ed83a75ae..74584dd12550 100644
> --- a/net/core/bpf_sk_storage.c
> +++ b/net/core/bpf_sk_storage.c
> @@ -352,8 +352,8 @@ const struct bpf_func_proto bpf_sk_storage_delete_proto = {
>   
>   static bool bpf_sk_storage_tracing_allowed(const struct bpf_prog *prog)
>   {
> -	const struct btf *btf_vmlinux;
>   	const struct btf_type *t;
> +	const struct btf *btf;
>   	const char *tname;
>   	u32 btf_id;
>   
> @@ -371,12 +371,12 @@ static bool bpf_sk_storage_tracing_allowed(const struct bpf_prog *prog)
>   		return true;
>   	case BPF_TRACE_FENTRY:
>   	case BPF_TRACE_FEXIT:
> -		btf_vmlinux = bpf_get_btf_vmlinux();
> -		if (IS_ERR_OR_NULL(btf_vmlinux))
> +		btf = prog->aux->attach_btf;
> +		if (!btf)
>   			return false;
>   		btf_id = prog->aux->attach_btf_id;
> -		t = btf_type_by_id(btf_vmlinux, btf_id);
> -		tname = btf_name_by_offset(btf_vmlinux, t->name_off);
> +		t = btf_type_by_id(btf, btf_id);
> +		tname = btf_name_by_offset(btf, t->name_off);
>   		return !!strncmp(tname, "bpf_sk_storage",
>   				 strlen("bpf_sk_storage"));

Thanks for the report.

There is a prog->aux->attach_func_name, so it can be directly used, like:

	case BPF_TRACE_FENTRY:
	case BPF_TRACE_FEXIT:
		return !!strncmp(prog->aux->attach_func_name, "bpf_sk_storage",
				 strlen("bpf_sk_storage"));

The above should do for the fix.

No need to check for null on attach_func_name. It should have been checked 
earlier in bpf_check_attach_target (the "tname" variable).

pw-bot: cr


  reply	other threads:[~2025-01-16 20:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-16 16:23 [PATCH bpf] bpf: use attach_btf instead of vmlinux in bpf_sk_storage_tracing_allowed Jared Kangas
2025-01-16 20:03 ` Martin KaFai Lau [this message]
2025-01-17 16:42   ` Jared Kangas
2025-01-18  0:37     ` Martin KaFai Lau

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=9e5b183e-5dd5-4d3d-b3e6-09ad5e7262dc@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=jkangas@redhat.com \
    --cc=johannes.berg@intel.com \
    --cc=kafai@fb.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=songliubraving@fb.com \
    /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;
as well as URLs for NNTP newsgroup(s).