Skip to contentSkip to conversation

bpf: replace pop/push emptiness check with bpf_list_empty()

PATCH Superseded Suchit Karunakaran 4 participants 4 messages May 23 – May 25

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: replace pop/push emptiness check with bpf_list_empty()

Simplify fq_flows_is_empty() by replacing the pop/push based emptiness check with a direct call to bpf_list_empty().
This avoids unnecessary list mutation and simplifies the code while preserving correctness.

---
 tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +3 -7
index 1a3233a275c7..3b05ac1d7c77 100644
@@ -197,17 +197,13 @@ static bool
 fq_flows_is_empty(struct bpf_list_head *head, struct bpf_spin_lock *lock)
 {
 	struct bpf_list_node *node;
+	bool empty;
 
 	bpf_spin_lock(lock);
-	node = bpf_list_pop_front(head);
-	if (node) {
-		bpf_list_push_front(head, node);
-		bpf_spin_unlock(lock);
-		return false;
-	}
+	empty = bpf_list_empty(head);
 	bpf_spin_unlock(lock);
 
-	return true;
+	return empty;
 }
 
 /* flow->age is used to denote the state of the flow (not-detached, detached, throttled)
Signature · 1 line
2.54.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Low] The patch introduces a call to `bpf_list_empty()`, which does not exist in the BPF API. - [Low] The…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] The patch introduces a call to bpf_list_empty(), which does not exist in the BPF API.
- [Low] The local variable node is declared but never used.
--

commit 0412c8130cf7d0d205c2cc937b2838067c31fb8b
Author: Suchit Karunakaran <[email protected]>

bpf: replace pop/push emptiness check with bpf_list_empty()

This commit attempts to simplify fq_flows_is_empty() by replacing the pop/push based emptiness check with a direct call to bpf_list_empty(). This is intended to avoid unnecessary list mutations.

tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c static bool · line 199

Quoted 8 lines
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +0 -0
index 1a3233a275c7e..3b05ac1d7c776 100644
@@ -197,17 +197,13 @@ static bool
 fq_flows_is_empty(struct bpf_list_head *head, struct bpf_spin_lock *lock)
 {
 	struct bpf_list_node *node;

[Severity: Low]
Since the pop and push logic was removed, is the node variable still used anywhere? Leaving this declaration here might trigger an unused-variable compiler warning and break the selftests build.

tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c static bool · line 203

Quoted 10 lines
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +2 -6
+	bool empty;
 
 	bpf_spin_lock(lock);
-	node = bpf_list_pop_front(head);
-	if (node) {
-		bpf_list_push_front(head, node);
-		bpf_spin_unlock(lock);
-		return false;
-	}
+	empty = bpf_list_empty(head);

[Severity: Low]
Does bpf_list_empty() exist in the BPF API?

The BPF linked list API does not appear to define a bpf_list_empty() kfunc, helper function, or macro. Could this lead to an implicit declaration compilation error?

Quoted 5 lines
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +1 -1
 	bpf_spin_unlock(lock);
 
-	return true;
+	return empty;
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Suchit Karunakaran
The variable 'node' is no longer used after removing the pop/push logic. Will this trigger an unused-variable compiler warning and break the selftests build?

tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c static bool · line 199

Quoted 8 lines
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +0 -0
index 1a3233a275c7..3b05ac1d7c77 100644
@@ -197,17 +197,13 @@ static bool
 fq_flows_is_empty(struct bpf_list_head *head, struct bpf_spin_lock *lock)
 {
 	struct bpf_list_node *node;
                              ^^^^

The variable 'node' is no longer used after removing the pop/push logic. Will this trigger an unused-variable compiler warning and break the selftests build?

Quoted 5 lines
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +0 -2
 +	bool empty;
 
 	bpf_spin_lock(lock);
-	node = bpf_list_pop_front(head);
-	if (node) {

tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c static bool · line 207

Quoted 10 lines
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +2 -5
-		bpf_list_push_front(head, node);
-		bpf_spin_unlock(lock);
-		return false;
-	}
+	empty = bpf_list_empty(head);
 	bpf_spin_unlock(lock);
 
-	return true;
+	return empty;
 }

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/26340856238

reviewer Reviewed-by on v1 1/1
#3 lore raw
In reply to Suchit Karunakaran
Quoted 6 lines · Suchit Karunakaran

Simplify fq_flows_is_empty() by replacing the pop/push based emptiness check with a direct call to bpf_list_empty().
This avoids unnecessary list mutation and simplifies the code while preserving correctness.

Imo the new code is way nicer, so even if this is a selftest the change is worth it. After addressing the AI feedback feel free to add:

Quoted 29 lines
---
 tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +3 -7
index 1a3233a275c7..3b05ac1d7c77 100644
@@ -197,17 +197,13 @@ static bool
 fq_flows_is_empty(struct bpf_list_head *head, struct bpf_spin_lock *lock)
 {
 	struct bpf_list_node *node;
+	bool empty;
 
 	bpf_spin_lock(lock);
-	node = bpf_list_pop_front(head);
-	if (node) {
-		bpf_list_push_front(head, node);
-		bpf_spin_unlock(lock);
-		return false;
-	}
+	empty = bpf_list_empty(head);
 	bpf_spin_unlock(lock);
 
-	return true;
+	return empty;
 }
 
 /* flow->age is used to denote the state of the flow (not-detached, detached, throttled)