public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/3] bpf: Fix strict mode calculation
@ 2022-02-07 14:50 Mauricio Vásquez
  2022-02-07 14:50 ` [PATCH bpf-next v2 1/3] libbpf: Remove mode check in libbpf_set_strict_mode() Mauricio Vásquez
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Mauricio Vásquez @ 2022-02-07 14:50 UTC (permalink / raw)
  To: netdev, bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Quentin Monnet

This series fixes a bad calculation of strict mode in two places. It
also updates libbpf to make it easier for the users to disable a
specific LIBBPF_STRICT_* flag.

v1 -> v2:
- remove check in libbpf_set_strict_mode()
- split in different commits

v1: https://lore.kernel.org/bpf/20220204220435.301896-1-mauricio@kinvolk.io/

Mauricio Vásquez (3):
  libbpf: Remove mode check in libbpf_set_strict_mode()
  bpftool: Fix strict mode calculation
  selftests/bpf: Fix strict mode calculation

 tools/bpf/bpftool/main.c                     | 5 +----
 tools/lib/bpf/libbpf.c                       | 8 --------
 tools/testing/selftests/bpf/prog_tests/btf.c | 2 +-
 3 files changed, 2 insertions(+), 13 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH bpf-next v2 1/3] libbpf: Remove mode check in libbpf_set_strict_mode()
  2022-02-07 14:50 [PATCH bpf-next v2 0/3] bpf: Fix strict mode calculation Mauricio Vásquez
@ 2022-02-07 14:50 ` Mauricio Vásquez
  2022-02-07 14:50 ` [PATCH bpf-next v2 2/3] bpftool: Fix strict mode calculation Mauricio Vásquez
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Mauricio Vásquez @ 2022-02-07 14:50 UTC (permalink / raw)
  To: netdev, bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Quentin Monnet

libbpf_set_strict_mode() checks that the passed mode doesn't contain
extra bits for LIBBPF_STRICT_* flags that don't exist yet.

It makes it difficult for applications to disable some strict flags as
something like "LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS"
is rejected by this check and they have to use a rather complicated
formula to calculate it.[0]

One possibility is to change LIBBPF_STRICT_ALL to only contain the bits
of all existing LIBBPF_STRICT_* flags instead of 0xffffffff. However
it's not possible because the idea is that applications compiled against
older libbpf_legacy.h would still be opting into latest
LIBBPF_STRICT_ALL features.[1]

The other possibility is to remove that check so something like
"LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS" is allowed. It's
what this commit does.

[0]: https://lore.kernel.org/bpf/20220204220435.301896-1-mauricio@kinvolk.io/
[1]: https://lore.kernel.org/bpf/CAEf4BzaTWa9fELJLh+bxnOb0P1EMQmaRbJVG0L+nXZdy0b8G3Q@mail.gmail.com/

Fixes: 93b8952d223a ("libbpf: deprecate legacy BPF map definitions")

Signed-off-by: Mauricio Vásquez <mauricio@kinvolk•io>
---
 tools/lib/bpf/libbpf.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 81605de8654e..d5bac4ed7023 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -156,14 +156,6 @@ enum libbpf_strict_mode libbpf_mode = LIBBPF_STRICT_NONE;
 
 int libbpf_set_strict_mode(enum libbpf_strict_mode mode)
 {
-	/* __LIBBPF_STRICT_LAST is the last power-of-2 value used + 1, so to
-	 * get all possible values we compensate last +1, and then (2*x - 1)
-	 * to get the bit mask
-	 */
-	if (mode != LIBBPF_STRICT_ALL
-	    && (mode & ~((__LIBBPF_STRICT_LAST - 1) * 2 - 1)))
-		return errno = EINVAL, -EINVAL;
-
 	libbpf_mode = mode;
 	return 0;
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH bpf-next v2 2/3] bpftool: Fix strict mode calculation
  2022-02-07 14:50 [PATCH bpf-next v2 0/3] bpf: Fix strict mode calculation Mauricio Vásquez
  2022-02-07 14:50 ` [PATCH bpf-next v2 1/3] libbpf: Remove mode check in libbpf_set_strict_mode() Mauricio Vásquez
@ 2022-02-07 14:50 ` Mauricio Vásquez
  2022-02-07 14:50 ` [PATCH bpf-next v2 3/3] selftests/bpf: " Mauricio Vásquez
  2022-02-07 20:20 ` [PATCH bpf-next v2 0/3] bpf: " patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Mauricio Vásquez @ 2022-02-07 14:50 UTC (permalink / raw)
  To: netdev, bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Quentin Monnet

"(__LIBBPF_STRICT_LAST - 1) & ~LIBBPF_STRICT_MAP_DEFINITIONS" is wrong
as it is equal to 0 (LIBBPF_STRICT_NONE). Let's use
"LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS" now that the
previous commit makes it possible in libbpf.

Fixes: 93b8952d223a ("libbpf: deprecate legacy BPF map definitions")

Signed-off-by: Mauricio Vásquez <mauricio@kinvolk•io>
---
 tools/bpf/bpftool/main.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
index 9d01fa9de033..490f7bd54e4c 100644
--- a/tools/bpf/bpftool/main.c
+++ b/tools/bpf/bpftool/main.c
@@ -478,14 +478,11 @@ int main(int argc, char **argv)
 	}
 
 	if (!legacy_libbpf) {
-		enum libbpf_strict_mode mode;
-
 		/* Allow legacy map definitions for skeleton generation.
 		 * It will still be rejected if users use LIBBPF_STRICT_ALL
 		 * mode for loading generated skeleton.
 		 */
-		mode = (__LIBBPF_STRICT_LAST - 1) & ~LIBBPF_STRICT_MAP_DEFINITIONS;
-		ret = libbpf_set_strict_mode(mode);
+		ret = libbpf_set_strict_mode(LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS);
 		if (ret)
 			p_err("failed to enable libbpf strict mode: %d", ret);
 	}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH bpf-next v2 3/3] selftests/bpf: Fix strict mode calculation
  2022-02-07 14:50 [PATCH bpf-next v2 0/3] bpf: Fix strict mode calculation Mauricio Vásquez
  2022-02-07 14:50 ` [PATCH bpf-next v2 1/3] libbpf: Remove mode check in libbpf_set_strict_mode() Mauricio Vásquez
  2022-02-07 14:50 ` [PATCH bpf-next v2 2/3] bpftool: Fix strict mode calculation Mauricio Vásquez
@ 2022-02-07 14:50 ` Mauricio Vásquez
  2022-02-07 20:20 ` [PATCH bpf-next v2 0/3] bpf: " patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Mauricio Vásquez @ 2022-02-07 14:50 UTC (permalink / raw)
  To: netdev, bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Quentin Monnet

"(__LIBBPF_STRICT_LAST - 1) & ~LIBBPF_STRICT_MAP_DEFINITIONS" is wrong
as it is equal to 0 (LIBBPF_STRICT_NONE). Let's use
"LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS" now that the
previous commit makes it possible in libbpf.

Fixes: 93b8952d223a ("libbpf: deprecate legacy BPF map definitions")

Signed-off-by: Mauricio Vásquez <mauricio@kinvolk•io>
---
 tools/testing/selftests/bpf/prog_tests/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/btf.c b/tools/testing/selftests/bpf/prog_tests/btf.c
index 14f9b6136794..4b93789acd86 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf.c
@@ -4561,7 +4561,7 @@ static void do_test_file(unsigned int test_num)
 	btf_ext__free(btf_ext);
 
 	/* temporary disable LIBBPF_STRICT_MAP_DEFINITIONS to test legacy maps */
-	libbpf_set_strict_mode((__LIBBPF_STRICT_LAST - 1) & ~LIBBPF_STRICT_MAP_DEFINITIONS);
+	libbpf_set_strict_mode(LIBBPF_STRICT_ALL & ~LIBBPF_STRICT_MAP_DEFINITIONS);
 	obj = bpf_object__open(test->file);
 	err = libbpf_get_error(obj);
 	if (CHECK(err, "obj: %d", err))
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next v2 0/3] bpf: Fix strict mode calculation
  2022-02-07 14:50 [PATCH bpf-next v2 0/3] bpf: Fix strict mode calculation Mauricio Vásquez
                   ` (2 preceding siblings ...)
  2022-02-07 14:50 ` [PATCH bpf-next v2 3/3] selftests/bpf: " Mauricio Vásquez
@ 2022-02-07 20:20 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-02-07 20:20 UTC (permalink / raw)
  To: =?utf-8?q?Mauricio_V=C3=A1squez_=3Cmauricio=40kinvolk=2Eio=3E?=
  Cc: netdev, bpf, ast, daniel, andrii, quentin

Hello:

This series was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel•org>:

On Mon,  7 Feb 2022 09:50:49 -0500 you wrote:
> This series fixes a bad calculation of strict mode in two places. It
> also updates libbpf to make it easier for the users to disable a
> specific LIBBPF_STRICT_* flag.
> 
> v1 -> v2:
> - remove check in libbpf_set_strict_mode()
> - split in different commits
> 
> [...]

Here is the summary with links:
  - [bpf-next,v2,1/3] libbpf: Remove mode check in libbpf_set_strict_mode()
    https://git.kernel.org/bpf/bpf-next/c/e4e835c87bb5
  - [bpf-next,v2,2/3] bpftool: Fix strict mode calculation
    https://git.kernel.org/bpf/bpf-next/c/da7af0aa20f8
  - [bpf-next,v2,3/3] selftests/bpf: Fix strict mode calculation
    https://git.kernel.org/bpf/bpf-next/c/2b9e2eadc9c8

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-02-07 20:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-07 14:50 [PATCH bpf-next v2 0/3] bpf: Fix strict mode calculation Mauricio Vásquez
2022-02-07 14:50 ` [PATCH bpf-next v2 1/3] libbpf: Remove mode check in libbpf_set_strict_mode() Mauricio Vásquez
2022-02-07 14:50 ` [PATCH bpf-next v2 2/3] bpftool: Fix strict mode calculation Mauricio Vásquez
2022-02-07 14:50 ` [PATCH bpf-next v2 3/3] selftests/bpf: " Mauricio Vásquez
2022-02-07 20:20 ` [PATCH bpf-next v2 0/3] bpf: " patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox