BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v2] bpf: Update the comments in maybe_wait_bpf_programs()
@ 2023-12-11  8:34 Hou Tao
  2023-12-11 14:58 ` Yonghong Song
  2023-12-14  1:10 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: Hou Tao @ 2023-12-11  8:34 UTC (permalink / raw)
  To: bpf
  Cc: Martin KaFai Lau, Alexei Starovoitov, Andrii Nakryiko, Song Liu,
	Hao Luo, Yonghong Song, Daniel Borkmann, KP Singh,
	Stanislav Fomichev, Jiri Olsa, John Fastabend, houtao1

From: Hou Tao <houtao1@huawei.com>

Since commit 638e4b825d52 ("bpf: Allows per-cpu maps and map-in-map in
sleepable programs"), sleepable BPF program can also use map-in-map, but
maybe_wait_bpf_programs() doesn't handle it accordingly. The main reason
is that using synchronize_rcu_tasks_trace() to wait for the completions
of these sleepable BPF programs may incur a very long delay and
userspace may think it is hung, so the wait for sleepable BPF programs
is skipped. Update the comments in maybe_wait_bpf_programs() to reflect
the reason.

Signed-off-by: Hou Tao <houtao1@huawei.com>
---
v2:
  * Don't handle sleepable BPF programs due to the potential long delay
  * Update the comments in maybe_wait_bpf_programs() accordingly

v1: https://lore.kernel.org/bpf/20231208102355.2628918-8-houtao@huaweicloud.com/
  * Handle sleepable BPF programs in maybe_wait_bpf_programs()

 kernel/bpf/syscall.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 0496b78b80f7..3fcf7741146a 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -142,9 +142,13 @@ static u32 bpf_map_value_size(const struct bpf_map *map)
 
 static void maybe_wait_bpf_programs(struct bpf_map *map)
 {
-	/* Wait for any running BPF programs to complete so that
-	 * userspace, when we return to it, knows that all programs
-	 * that could be running use the new map value.
+	/* Wait for any running non-sleepable BPF programs to complete so that
+	 * userspace, when we return to it, knows that all non-sleepable
+	 * programs that could be running use the new map value. For sleepable
+	 * BPF programs, synchronize_rcu_tasks_trace() should be used to wait
+	 * for the completions of these programs, but considering the waiting
+	 * time can be very long and userspace may think it will hang forever,
+	 * so don't handle sleepable BPF programs now.
 	 */
 	if (map->map_type == BPF_MAP_TYPE_HASH_OF_MAPS ||
 	    map->map_type == BPF_MAP_TYPE_ARRAY_OF_MAPS)
-- 
2.29.2


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

* Re: [PATCH bpf-next v2] bpf: Update the comments in maybe_wait_bpf_programs()
  2023-12-11  8:34 [PATCH bpf-next v2] bpf: Update the comments in maybe_wait_bpf_programs() Hou Tao
@ 2023-12-11 14:58 ` Yonghong Song
  2023-12-11 20:06   ` John Fastabend
  2023-12-14  1:10 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: Yonghong Song @ 2023-12-11 14:58 UTC (permalink / raw)
  To: Hou Tao, bpf
  Cc: Martin KaFai Lau, Alexei Starovoitov, Andrii Nakryiko, Song Liu,
	Hao Luo, Daniel Borkmann, KP Singh, Stanislav Fomichev, Jiri Olsa,
	John Fastabend, houtao1


On 12/11/23 12:34 AM, Hou Tao wrote:
> From: Hou Tao <houtao1@huawei.com>
>
> Since commit 638e4b825d52 ("bpf: Allows per-cpu maps and map-in-map in
> sleepable programs"), sleepable BPF program can also use map-in-map, but
> maybe_wait_bpf_programs() doesn't handle it accordingly. The main reason
> is that using synchronize_rcu_tasks_trace() to wait for the completions
> of these sleepable BPF programs may incur a very long delay and
> userspace may think it is hung, so the wait for sleepable BPF programs
> is skipped. Update the comments in maybe_wait_bpf_programs() to reflect
> the reason.
>
> Signed-off-by: Hou Tao <houtao1@huawei.com>

Acked-by: Yonghong Song <yonghong.song@linux.dev>



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

* Re: [PATCH bpf-next v2] bpf: Update the comments in maybe_wait_bpf_programs()
  2023-12-11 14:58 ` Yonghong Song
@ 2023-12-11 20:06   ` John Fastabend
  0 siblings, 0 replies; 4+ messages in thread
From: John Fastabend @ 2023-12-11 20:06 UTC (permalink / raw)
  To: Yonghong Song, Hou Tao, bpf
  Cc: Martin KaFai Lau, Alexei Starovoitov, Andrii Nakryiko, Song Liu,
	Hao Luo, Daniel Borkmann, KP Singh, Stanislav Fomichev, Jiri Olsa,
	John Fastabend, houtao1

Yonghong Song wrote:
> 
> On 12/11/23 12:34 AM, Hou Tao wrote:
> > From: Hou Tao <houtao1@huawei.com>
> >
> > Since commit 638e4b825d52 ("bpf: Allows per-cpu maps and map-in-map in
> > sleepable programs"), sleepable BPF program can also use map-in-map, but
> > maybe_wait_bpf_programs() doesn't handle it accordingly. The main reason
> > is that using synchronize_rcu_tasks_trace() to wait for the completions
> > of these sleepable BPF programs may incur a very long delay and
> > userspace may think it is hung, so the wait for sleepable BPF programs
> > is skipped. Update the comments in maybe_wait_bpf_programs() to reflect
> > the reason.
> >
> > Signed-off-by: Hou Tao <houtao1@huawei.com>
> 
> Acked-by: Yonghong Song <yonghong.song@linux.dev>
> 
> 

Useful info if you are needing this property.

Acked-by: John Fastabend <john.fastabend@gmail.com>

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

* Re: [PATCH bpf-next v2] bpf: Update the comments in maybe_wait_bpf_programs()
  2023-12-11  8:34 [PATCH bpf-next v2] bpf: Update the comments in maybe_wait_bpf_programs() Hou Tao
  2023-12-11 14:58 ` Yonghong Song
@ 2023-12-14  1:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-12-14  1:10 UTC (permalink / raw)
  To: Hou Tao
  Cc: bpf, martin.lau, alexei.starovoitov, andrii, song, haoluo,
	yonghong.song, daniel, kpsingh, sdf, jolsa, john.fastabend,
	houtao1

Hello:

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

On Mon, 11 Dec 2023 16:34:47 +0800 you wrote:
> From: Hou Tao <houtao1@huawei.com>
> 
> Since commit 638e4b825d52 ("bpf: Allows per-cpu maps and map-in-map in
> sleepable programs"), sleepable BPF program can also use map-in-map, but
> maybe_wait_bpf_programs() doesn't handle it accordingly. The main reason
> is that using synchronize_rcu_tasks_trace() to wait for the completions
> of these sleepable BPF programs may incur a very long delay and
> userspace may think it is hung, so the wait for sleepable BPF programs
> is skipped. Update the comments in maybe_wait_bpf_programs() to reflect
> the reason.
> 
> [...]

Here is the summary with links:
  - [bpf-next,v2] bpf: Update the comments in maybe_wait_bpf_programs()
    https://git.kernel.org/bpf/bpf-next/c/2a0c6b41eec9

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

end of thread, other threads:[~2023-12-14  1:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-11  8:34 [PATCH bpf-next v2] bpf: Update the comments in maybe_wait_bpf_programs() Hou Tao
2023-12-11 14:58 ` Yonghong Song
2023-12-11 20:06   ` John Fastabend
2023-12-14  1:10 ` 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