BPF List
 help / color / mirror / Atom feed
* [PATCH net-next 1/2] bpf: save extended inner map info for percpu array maps as well
@ 2024-05-15  6:24 Andrii Nakryiko
  2024-05-15  6:24 ` [PATCH net-next 2/2] selftests/bpf: add more variations of map-in-map situations Andrii Nakryiko
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Andrii Nakryiko @ 2024-05-15  6:24 UTC (permalink / raw)
  To: netdev, bpf, ast, daniel, martin.lau
  Cc: torvalds, Andrii Nakryiko, Jakub Kicinski

ARRAY_OF_MAPS and HASH_OF_MAPS map types have special logic to save
a few extra fields required for correct operations of ARRAY maps, when
they are used as inner maps. PERCPU_ARRAY maps have similar
requirements as they now support generating inline element lookup
logic. So make sure that both classes of maps are handled correctly.

Reported-by: Jakub Kicinski <kuba@kernel.org>
Fixes: db69718b8efa ("bpf: inline bpf_map_lookup_elem() for PERCPU_ARRAY maps")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 kernel/bpf/map_in_map.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/map_in_map.c b/kernel/bpf/map_in_map.c
index 8ef269e66ba5..b4f18c85d7bc 100644
--- a/kernel/bpf/map_in_map.c
+++ b/kernel/bpf/map_in_map.c
@@ -32,7 +32,7 @@ struct bpf_map *bpf_map_meta_alloc(int inner_map_ufd)
 
 	inner_map_meta_size = sizeof(*inner_map_meta);
 	/* In some cases verifier needs to access beyond just base map. */
-	if (inner_map->ops == &array_map_ops)
+	if (inner_map->ops == &array_map_ops || inner_map->ops == &percpu_array_map_ops)
 		inner_map_meta_size = sizeof(struct bpf_array);
 
 	inner_map_meta = kzalloc(inner_map_meta_size, GFP_USER);
@@ -68,7 +68,7 @@ struct bpf_map *bpf_map_meta_alloc(int inner_map_ufd)
 
 	/* Misc members not needed in bpf_map_meta_equal() check. */
 	inner_map_meta->ops = inner_map->ops;
-	if (inner_map->ops == &array_map_ops) {
+	if (inner_map->ops == &array_map_ops || inner_map->ops == &percpu_array_map_ops) {
 		struct bpf_array *inner_array_meta =
 			container_of(inner_map_meta, struct bpf_array, map);
 		struct bpf_array *inner_array = container_of(inner_map, struct bpf_array, map);
-- 
2.43.0


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

* [PATCH net-next 2/2] selftests/bpf: add more variations of map-in-map situations
  2024-05-15  6:24 [PATCH net-next 1/2] bpf: save extended inner map info for percpu array maps as well Andrii Nakryiko
@ 2024-05-15  6:24 ` Andrii Nakryiko
  2024-05-15 15:26   ` Kumar Kartikeya Dwivedi
  2024-05-15 15:25 ` [PATCH net-next 1/2] bpf: save extended inner map info for percpu array maps as well Kumar Kartikeya Dwivedi
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Andrii Nakryiko @ 2024-05-15  6:24 UTC (permalink / raw)
  To: netdev, bpf, ast, daniel, martin.lau
  Cc: torvalds, Andrii Nakryiko, Jakub Kicinski

Add test cases validating usage of PERCPU_ARRAY and PERCPU_HASH maps as
inner maps.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/testing/selftests/bpf/progs/map_kptr.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tools/testing/selftests/bpf/progs/map_kptr.c b/tools/testing/selftests/bpf/progs/map_kptr.c
index da30f0d59364..ab0ce1d01a4a 100644
--- a/tools/testing/selftests/bpf/progs/map_kptr.c
+++ b/tools/testing/selftests/bpf/progs/map_kptr.c
@@ -110,10 +110,14 @@ DEFINE_MAP_OF_MAP(BPF_MAP_TYPE_ARRAY_OF_MAPS, array_map, array_of_array_maps);
 DEFINE_MAP_OF_MAP(BPF_MAP_TYPE_ARRAY_OF_MAPS, hash_map, array_of_hash_maps);
 DEFINE_MAP_OF_MAP(BPF_MAP_TYPE_ARRAY_OF_MAPS, hash_malloc_map, array_of_hash_malloc_maps);
 DEFINE_MAP_OF_MAP(BPF_MAP_TYPE_ARRAY_OF_MAPS, lru_hash_map, array_of_lru_hash_maps);
+DEFINE_MAP_OF_MAP(BPF_MAP_TYPE_ARRAY_OF_MAPS, pcpu_array_map, array_of_pcpu_array_maps);
+DEFINE_MAP_OF_MAP(BPF_MAP_TYPE_ARRAY_OF_MAPS, pcpu_hash_map, array_of_pcpu_hash_maps);
 DEFINE_MAP_OF_MAP(BPF_MAP_TYPE_HASH_OF_MAPS, array_map, hash_of_array_maps);
 DEFINE_MAP_OF_MAP(BPF_MAP_TYPE_HASH_OF_MAPS, hash_map, hash_of_hash_maps);
 DEFINE_MAP_OF_MAP(BPF_MAP_TYPE_HASH_OF_MAPS, hash_malloc_map, hash_of_hash_malloc_maps);
 DEFINE_MAP_OF_MAP(BPF_MAP_TYPE_HASH_OF_MAPS, lru_hash_map, hash_of_lru_hash_maps);
+DEFINE_MAP_OF_MAP(BPF_MAP_TYPE_HASH_OF_MAPS, pcpu_array_map, hash_of_pcpu_array_maps);
+DEFINE_MAP_OF_MAP(BPF_MAP_TYPE_HASH_OF_MAPS, pcpu_hash_map, hash_of_pcpu_hash_maps);
 
 #define WRITE_ONCE(x, val) ((*(volatile typeof(x) *) &(x)) = (val))
 
@@ -204,6 +208,8 @@ int test_map_kptr(struct __sk_buff *ctx)
 	TEST(hash_map);
 	TEST(hash_malloc_map);
 	TEST(lru_hash_map);
+	TEST(pcpu_array_map);
+	TEST(pcpu_hash_map);
 
 #undef TEST
 	return 0;
@@ -281,10 +287,14 @@ int test_map_in_map_kptr(struct __sk_buff *ctx)
 	TEST(array_of_hash_maps);
 	TEST(array_of_hash_malloc_maps);
 	TEST(array_of_lru_hash_maps);
+	TEST(array_of_pcpu_array_maps);
+	TEST(array_of_pcpu_hash_maps);
 	TEST(hash_of_array_maps);
 	TEST(hash_of_hash_maps);
 	TEST(hash_of_hash_malloc_maps);
 	TEST(hash_of_lru_hash_maps);
+	TEST(hash_of_pcpu_array_maps);
+	TEST(hash_of_pcpu_hash_maps);
 
 #undef TEST
 	return 0;
-- 
2.43.0


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

* Re: [PATCH net-next 1/2] bpf: save extended inner map info for percpu array maps as well
  2024-05-15  6:24 [PATCH net-next 1/2] bpf: save extended inner map info for percpu array maps as well Andrii Nakryiko
  2024-05-15  6:24 ` [PATCH net-next 2/2] selftests/bpf: add more variations of map-in-map situations Andrii Nakryiko
@ 2024-05-15 15:25 ` Kumar Kartikeya Dwivedi
  2024-05-15 16:55 ` Alexei Starovoitov
  2024-05-15 16:58 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 6+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2024-05-15 15:25 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: netdev, bpf, ast, daniel, martin.lau, torvalds, Jakub Kicinski

On Wed, 15 May 2024 at 08:24, Andrii Nakryiko <andrii@kernel.org> wrote:
>
> ARRAY_OF_MAPS and HASH_OF_MAPS map types have special logic to save
> a few extra fields required for correct operations of ARRAY maps, when
> they are used as inner maps. PERCPU_ARRAY maps have similar
> requirements as they now support generating inline element lookup
> logic. So make sure that both classes of maps are handled correctly.
>
> Reported-by: Jakub Kicinski <kuba@kernel.org>
> Fixes: db69718b8efa ("bpf: inline bpf_map_lookup_elem() for PERCPU_ARRAY maps")
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> ---

Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>

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

* Re: [PATCH net-next 2/2] selftests/bpf: add more variations of map-in-map situations
  2024-05-15  6:24 ` [PATCH net-next 2/2] selftests/bpf: add more variations of map-in-map situations Andrii Nakryiko
@ 2024-05-15 15:26   ` Kumar Kartikeya Dwivedi
  0 siblings, 0 replies; 6+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2024-05-15 15:26 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: netdev, bpf, ast, daniel, martin.lau, torvalds, Jakub Kicinski

On Wed, 15 May 2024 at 08:25, Andrii Nakryiko <andrii@kernel.org> wrote:
>
> Add test cases validating usage of PERCPU_ARRAY and PERCPU_HASH maps as
> inner maps.
>
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> ---

Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>

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

* Re: [PATCH net-next 1/2] bpf: save extended inner map info for percpu array maps as well
  2024-05-15  6:24 [PATCH net-next 1/2] bpf: save extended inner map info for percpu array maps as well Andrii Nakryiko
  2024-05-15  6:24 ` [PATCH net-next 2/2] selftests/bpf: add more variations of map-in-map situations Andrii Nakryiko
  2024-05-15 15:25 ` [PATCH net-next 1/2] bpf: save extended inner map info for percpu array maps as well Kumar Kartikeya Dwivedi
@ 2024-05-15 16:55 ` Alexei Starovoitov
  2024-05-15 16:58 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 6+ messages in thread
From: Alexei Starovoitov @ 2024-05-15 16:55 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Network Development, bpf, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Linus Torvalds, Jakub Kicinski

On Tue, May 14, 2024 at 11:24 PM Andrii Nakryiko <andrii@kernel.org> wrote:
>
> ARRAY_OF_MAPS and HASH_OF_MAPS map types have special logic to save
> a few extra fields required for correct operations of ARRAY maps, when
> they are used as inner maps. PERCPU_ARRAY maps have similar
> requirements as they now support generating inline element lookup
> logic. So make sure that both classes of maps are handled correctly.
>
> Reported-by: Jakub Kicinski <kuba@kernel.org>
> Fixes: db69718b8efa ("bpf: inline bpf_map_lookup_elem() for PERCPU_ARRAY maps")
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> ---
>  kernel/bpf/map_in_map.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/bpf/map_in_map.c b/kernel/bpf/map_in_map.c
> index 8ef269e66ba5..b4f18c85d7bc 100644
> --- a/kernel/bpf/map_in_map.c
> +++ b/kernel/bpf/map_in_map.c
> @@ -32,7 +32,7 @@ struct bpf_map *bpf_map_meta_alloc(int inner_map_ufd)
>
>         inner_map_meta_size = sizeof(*inner_map_meta);
>         /* In some cases verifier needs to access beyond just base map. */
> -       if (inner_map->ops == &array_map_ops)
> +       if (inner_map->ops == &array_map_ops || inner_map->ops == &percpu_array_map_ops)
>                 inner_map_meta_size = sizeof(struct bpf_array);

Applied the fix to stop the bleeding,
but we need to fix this fragility long term.

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

* Re: [PATCH net-next 1/2] bpf: save extended inner map info for percpu array maps as well
  2024-05-15  6:24 [PATCH net-next 1/2] bpf: save extended inner map info for percpu array maps as well Andrii Nakryiko
                   ` (2 preceding siblings ...)
  2024-05-15 16:55 ` Alexei Starovoitov
@ 2024-05-15 16:58 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-05-15 16:58 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: netdev, bpf, ast, daniel, martin.lau, torvalds, kuba

Hello:

This series was applied to bpf/bpf.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Tue, 14 May 2024 23:24:39 -0700 you wrote:
> ARRAY_OF_MAPS and HASH_OF_MAPS map types have special logic to save
> a few extra fields required for correct operations of ARRAY maps, when
> they are used as inner maps. PERCPU_ARRAY maps have similar
> requirements as they now support generating inline element lookup
> logic. So make sure that both classes of maps are handled correctly.
> 
> Reported-by: Jakub Kicinski <kuba@kernel.org>
> Fixes: db69718b8efa ("bpf: inline bpf_map_lookup_elem() for PERCPU_ARRAY maps")
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> 
> [...]

Here is the summary with links:
  - [net-next,1/2] bpf: save extended inner map info for percpu array maps as well
    https://git.kernel.org/bpf/bpf/c/9ee982290831
  - [net-next,2/2] selftests/bpf: add more variations of map-in-map situations
    https://git.kernel.org/bpf/bpf/c/2322113ac9d0

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] 6+ messages in thread

end of thread, other threads:[~2024-05-15 16:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-15  6:24 [PATCH net-next 1/2] bpf: save extended inner map info for percpu array maps as well Andrii Nakryiko
2024-05-15  6:24 ` [PATCH net-next 2/2] selftests/bpf: add more variations of map-in-map situations Andrii Nakryiko
2024-05-15 15:26   ` Kumar Kartikeya Dwivedi
2024-05-15 15:25 ` [PATCH net-next 1/2] bpf: save extended inner map info for percpu array maps as well Kumar Kartikeya Dwivedi
2024-05-15 16:55 ` Alexei Starovoitov
2024-05-15 16:58 ` 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