Skip to contentSkip to conversation

bpf: Allow to use kfunc XDP hints and frags together

PATCH Applied Larysa Zaremba 4 participants 4 messages Sep 15, 2023 BPF

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 bpf: Allow to use kfunc XDP hints and frags together

There is no fundamental reason, why multi-buffer XDP and XDP kfunc RX hints cannot coexist in a single program.

Allow those features to be used together by modifying the flags condition for dev-bound-only programs, segments are still prohibited for fully offloaded programs, hence additional check.

---
 kernel/bpf/offload.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/bpf/offload.c +8 -1
index ee35f33a96d1..9d8e508c9b86 100644
@@ -232,7 +232,14 @@ int bpf_prog_dev_bound_init(struct bpf_prog *prog, union bpf_attr *attr)
 	    attr->prog_type != BPF_PROG_TYPE_XDP)
 		return -EINVAL;
 
-	if (attr->prog_flags & ~BPF_F_XDP_DEV_BOUND_ONLY)
+	if (attr->prog_flags & ~(BPF_F_XDP_DEV_BOUND_ONLY | BPF_F_XDP_HAS_FRAGS))
+		return -EINVAL;
+
+	/* Frags are allowed only if program is dev-bound-only, but not
+	 * if it is requesting bpf offload.
+	 */
+	if (attr->prog_flags & BPF_F_XDP_HAS_FRAGS &&
+	    !(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY))
 		return -EINVAL;
 
 	if (attr->prog_type == BPF_PROG_TYPE_SCHED_CLS &&
Signature · 1 line
2.41.0
Acked-by on v2 1/1
#1 lore raw
Quoted 4 lines · Larysa Zaremba

There is no fundamental reason, why multi-buffer XDP and XDP kfunc RX hints cannot coexist in a single program.

Quoted 8 lines

Allow those features to be used together by modifying the flags condition for dev-bound-only programs, segments are still prohibited for fully offloaded programs, hence additional check.

Thank you!

Quoted 27 lines
---
 kernel/bpf/offload.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/bpf/offload.c +8 -2
index ee35f33a96d1..9d8e508c9b86 100644
@@ -232,7 +232,14 @@ int bpf_prog_dev_bound_init(struct bpf_prog *prog, union bpf_attr *attr)
            attr->prog_type != BPF_PROG_TYPE_XDP)
                return -EINVAL;
 
-       if (attr->prog_flags & ~BPF_F_XDP_DEV_BOUND_ONLY)
+       if (attr->prog_flags & ~(BPF_F_XDP_DEV_BOUND_ONLY | BPF_F_XDP_HAS_FRAGS))
+               return -EINVAL;
+
+       /* Frags are allowed only if program is dev-bound-only, but not
+        * if it is requesting bpf offload.
+        */
+       if (attr->prog_flags & BPF_F_XDP_HAS_FRAGS &&
+           !(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY))
                return -EINVAL;
 
        if (attr->prog_type == BPF_PROG_TYPE_SCHED_CLS &&
--

2.41.0

#2 lore raw
In reply to Larysa Zaremba
This patch was applied to bpf/bpf-next.git (master) by Martin KaFai Lau <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Martin KaFai Lau <[email protected]>:

Quoted 8 lines · On Fri, 15 Sep 2023 10:39:10 +0200 you wrote:

There is no fundamental reason, why multi-buffer XDP and XDP kfunc RX hints cannot coexist in a single program.

Allow those features to be used together by modifying the flags condition for dev-bound-only programs, segments are still prohibited for fully offloaded programs, hence additional check.

[...]

Here is the summary with links:
- [bpf-next,v2] bpf: Allow to use kfunc XDP hints and frags together

    https://git.kernel.org/bpf/bpf-next/c/9b2b86332a9b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#3 lore raw
In reply to Larysa Zaremba
Quoted 6 lines · Larysa Zaremba

There is no fundamental reason, why multi-buffer XDP and XDP kfunc RX hints cannot coexist in a single program.

Allow those features to be used together by modifying the flags condition for dev-bound-only programs, segments are still prohibited for fully offloaded programs, hence additional check.

Applied. Please do follow up with a test. Thanks.