BPF List
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Pramukh Naduthota <pnaduthota@google.com>
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	song@kernel.org, yhs@fb.com, john.fastabend@gmail.com,
	kpsingh@kernel.org, sdf@google.com, haoluo@google.com,
	jolsa@kernel.org, bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf 1/2] Ignore RDONLY_PROG for devmaps in libbpf to allow re-loading of pinned devmaps
Date: Tue, 27 Sep 2022 17:39:59 -0700	[thread overview]
Message-ID: <d6f272a6-020e-6a46-d86a-72c2dcc15264@linux.dev> (raw)
In-Reply-To: <20220927182345.149171-2-pnaduthota@google.com>

On 9/27/22 11:23 AM, Pramukh Naduthota wrote:
> Ignore BPF_F_RDONLY_PROG when checking for compatibility for devmaps. The
> kernel adds the flag to all devmap creates, and this breaks pinning
> behavior, as libbpf will then check the actual vs user supplied flags and
> see this difference. Work around this by adding RDONLY_PROG to the
> users's flags when testing against the pinned map
> 
> Fixes: 57a00f41644f ("libbpf: Add auto-pinning of maps when loading BPF objects")
> Signed-off-by: Pramukh Naduthota <pnaduthota@google.com>
> ---
>   tools/lib/bpf/libbpf.c | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 50d41815f4..a3dae26d82 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -4818,6 +4818,7 @@ static bool map_is_reuse_compat(const struct bpf_map *map, int map_fd)
>   	char msg[STRERR_BUFSIZE];
>   	__u32 map_info_len;
>   	int err;
> +	unsigned int effective_flags = map->def.map_flags;
>   
>   	map_info_len = sizeof(map_info);
>   
> @@ -4830,11 +4831,16 @@ static bool map_is_reuse_compat(const struct bpf_map *map, int map_fd)
>   		return false;
>   	}
>   
> +	/* The kernel adds RDONLY_PROG to devmaps */
> +	if (map->def.type == BPF_MAP_TYPE_DEVMAP ||
> +	    map->def.type == BPF_MAP_TYPE_DEVMAP_HASH)
> +		effective_flags |= BPF_F_RDONLY_PROG;

May be set BPF_F_RDONLY_PROG in effective_flags only when map->def.map_flags 
does not have both BPF_F_RDONLY_PROG and BPF_F_WRONLY_PROG set?  Just in case 
the devmap may support setting them during map creation in the future.

> +
>   	return (map_info.type == map->def.type &&
>   		map_info.key_size == map->def.key_size &&
>   		map_info.value_size == map->def.value_size &&
>   		map_info.max_entries == map->def.max_entries &&
> -		map_info.map_flags == map->def.map_flags &&
> +		map_info.map_flags == effective_flags &&
>   		map_info.map_extra == map->map_extra);
>   }
>   


  reply	other threads:[~2022-09-28  0:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-27 18:23 [PATCH bpf 0/2] Fix pinning devmaps Pramukh Naduthota
2022-09-27 18:23 ` [PATCH bpf 1/2] Ignore RDONLY_PROG for devmaps in libbpf to allow re-loading of pinned devmaps Pramukh Naduthota
2022-09-28  0:39   ` Martin KaFai Lau [this message]
2022-09-30 21:03     ` Andrii Nakryiko
2022-10-14 20:32       ` Pramukh Naduthota
2022-09-27 18:23 ` [PATCH bpf 2/2] Add selftests for devmap pinning Pramukh Naduthota
2022-09-27 20:30   ` Pramukh Naduthota
2022-09-30 21:05   ` Andrii Nakryiko

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=d6f272a6-020e-6a46-d86a-72c2dcc15264@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=pnaduthota@google.com \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=yhs@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