Skip to contentSkip to conversation

bpf: Allow to use kfunc XDP hints and frags together

PATCH Superseded Larysa Zaremba 3 participants 7 messages Sep 14, 2023 BPF

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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 conditions.

---
 kernel/bpf/offload.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/bpf/offload.c +5 -1
index ee35f33a96d1..43aded96c79b 100644
@@ -232,7 +232,11 @@ 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;
+
+	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
#1 lore raw
Quoted 24 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 conditions.

---
 kernel/bpf/offload.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/bpf/offload.c +3 -1
index ee35f33a96d1..43aded96c79b 100644
@@ -232,7 +232,11 @@ 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;
+

[..]

kernel/bpf/offload.c int bpf_prog_dev_bound_init(struct bpf_prog *prog, union bpf_attr *attr) · line 240

Quoted 3 lines
kernel/bpf/offload.c +2 -0
+	if (attr->prog_flags & BPF_F_XDP_HAS_FRAGS &&
+	    !(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY))
 		return -EINVAL;

Any reason we have 'attr->prog_flags & BPF_F_XDP_HAS_FRAGS' part here? Seems like doing '!(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY)' should be enough, right? We only want to bail out here when BPF_F_XDP_DEV_BOUND_ONLY is not set and we don't really care whether BPF_F_XDP_HAS_FRAGS is set or not at this point.

#2 lore raw
Quoted 28 lines · Stanislav Fomichev
Quoted 24 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 conditions.

---
 kernel/bpf/offload.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/bpf/offload.c +3 -1
index ee35f33a96d1..43aded96c79b 100644
@@ -232,7 +232,11 @@ 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;
+

[..]

Quoted 9 lines

kernel/bpf/offload.c int bpf_prog_dev_bound_init(struct bpf_prog *prog, union bpf_attr *attr) · line 240

Quoted 3 lines
kernel/bpf/offload.c +2 -0
+	if (attr->prog_flags & BPF_F_XDP_HAS_FRAGS &&
+	    !(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY))
 		return -EINVAL;

Any reason we have 'attr->prog_flags & BPF_F_XDP_HAS_FRAGS' part here? Seems like doing '!(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY)' should be enough, right? We only want to bail out here when BPF_F_XDP_DEV_BOUND_ONLY is not set and we don't really care whether BPF_F_XDP_HAS_FRAGS is set or not at this point.

If !(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY) at this point, program could be requesting offload.

Now I have thought about those conditions once more and they could be reduced to this:

if (attr->prog_flags & ~(BPF_F_XDP_DEV_BOUND_ONLY) &&

    attr->prog_flags != (BPF_F_XDP_DEV_BOUND_ONLY | BPF_F_XDP_HAS_FRAGS))
	return -EINVAL;

What do you think?

#3 lore raw
Quoted 43 lines · Larysa Zaremba
Quoted 32 lines · Stanislav Fomichev
Quoted 24 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 conditions.

---
 kernel/bpf/offload.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/bpf/offload.c +3 -1
index ee35f33a96d1..43aded96c79b 100644
@@ -232,7 +232,11 @@ 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;
+

[..]

kernel/bpf/offload.c int bpf_prog_dev_bound_init(struct bpf_prog *prog, union bpf_attr *attr) · line 240

Quoted 3 lines
kernel/bpf/offload.c +2 -0
+   if (attr->prog_flags & BPF_F_XDP_HAS_FRAGS &&
+       !(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY))
            return -EINVAL;
Quoted 5 lines

Any reason we have 'attr->prog_flags & BPF_F_XDP_HAS_FRAGS' part here? Seems like doing '!(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY)' should be enough, right? We only want to bail out here when BPF_F_XDP_DEV_BOUND_ONLY is not set and we don't really care whether BPF_F_XDP_HAS_FRAGS is set or not at this point.

If !(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY) at this point, program could be requesting offload.

Quoted 8 lines

Now I have thought about those conditions once more and they could be reduced to this:

if (attr->prog_flags & ~(BPF_F_XDP_DEV_BOUND_ONLY) &&

    attr->prog_flags != (BPF_F_XDP_DEV_BOUND_ONLY | BPF_F_XDP_HAS_FRAGS))
        return -EINVAL;

What do you think?

Ah, so this check is here to protect against the mbuf+offloaded combination? (looking at that other thread with Maciej) Let's keep your current way with two separate checks, but let's add your "/* Frags are allowed only if program is dev-bound-only, but not if it is requesting
bpf offload. */" as a comment to the second check?

#4 lore raw
Quoted 51 lines · Stanislav Fomichev
Quoted 50 lines · Larysa Zaremba
Quoted 32 lines · Stanislav Fomichev
Quoted 24 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 conditions.

---
 kernel/bpf/offload.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/bpf/offload.c +3 -1
index ee35f33a96d1..43aded96c79b 100644
@@ -232,7 +232,11 @@ 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;
+

[..]

kernel/bpf/offload.c int bpf_prog_dev_bound_init(struct bpf_prog *prog, union bpf_attr *attr) · line 240

Quoted 3 lines
kernel/bpf/offload.c +2 -0
+   if (attr->prog_flags & BPF_F_XDP_HAS_FRAGS &&
+       !(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY))
            return -EINVAL;
Quoted 5 lines

Any reason we have 'attr->prog_flags & BPF_F_XDP_HAS_FRAGS' part here? Seems like doing '!(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY)' should be enough, right? We only want to bail out here when BPF_F_XDP_DEV_BOUND_ONLY is not set and we don't really care whether BPF_F_XDP_HAS_FRAGS is set or not at this point.

If !(attr->prog_flags & BPF_F_XDP_DEV_BOUND_ONLY) at this point, program could be requesting offload.

Now I have thought about those conditions once more and they could be reduced to this:

if (attr->prog_flags & ~(BPF_F_XDP_DEV_BOUND_ONLY) &&

    attr->prog_flags != (BPF_F_XDP_DEV_BOUND_ONLY | BPF_F_XDP_HAS_FRAGS))
        return -EINVAL;
Quoted 8 lines
Quoted 1 line

What do you think?

Ah, so this check is here to protect against the mbuf+offloaded combination? (looking at that other thread with Maciej) Let's keep your current way with two separate checks, but let's add your "/* Frags are allowed only if program is dev-bound-only, but not if it is requesting
bpf offload. */" as a comment to the second check?

Ok, sound good to me.

Reviewed-by on v1 1/1
#5 lore raw
In reply to Larysa Zaremba
Quoted 8 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 conditions.

Though it would be worth spelling out something in the commit msg about additional check you're adding (frags flag can't go without dev bound)

Quoted 25 lines
---
 kernel/bpf/offload.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/bpf/offload.c +5 -1
index ee35f33a96d1..43aded96c79b 100644
@@ -232,7 +232,11 @@ 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;
+
+	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
#6 lore raw
Quoted 6 lines · Maciej Fijalkowski
Quoted 5 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 conditions.

Quoted 9 lines
Quoted 3 lines

Though it would be worth spelling out something in the commit msg about additional check you're adding (frags flag can't go without dev bound)

Ok, I'll add to the commit message the below:

Frags are allowed only if program is dev-bound-only, but not if it is requesting bpf offload.

Quoted 25 lines
Quoted 25 lines
---
 kernel/bpf/offload.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/bpf/offload.c +5 -1
index ee35f33a96d1..43aded96c79b 100644
@@ -232,7 +232,11 @@ 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;
+
+	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