Skip to contentSkip to conversation

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

PATCH Applied Suchit Karunakaran 4 participants 5 messages May 24 – May 29

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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

Changes since v1:
- Removed unused variable node

---
 tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +3 -8
index 1a3233a275c7..8107f5934d2d 100644
@@ -196,18 +196,13 @@ fq_flows_remove_front(struct bpf_list_head *head, struct bpf_spin_lock *lock,
 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 1 potential issue(s) to consider: - [Low] The patch introduces a call to `bpf_list_empty()`, which is an undeclared function, resulting in a…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The patch introduces a call to bpf_list_empty(), which is an undeclared function, resulting in a build failure. --

commit 9fb6024323da084c2713bff3f8a0e6018dc6bd72
Author: Suchit Karunakaran <[email protected]>

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

This commit simplifies fq_flows_is_empty() by replacing a pop/push check with a direct call to bpf_list_empty(). The intention is to avoid unnecessary list mutation and simplify the code.

Quoted 9 lines
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +0 -1
index 1a3233a275c7e..8107f5934d2d7 100644
@@ -196,18 +196,13 @@ fq_flows_remove_front(struct bpf_list_head *head, struct bpf_spin_lock *lock,
 static bool
 fq_flows_is_empty(struct bpf_list_head *head, struct bpf_spin_lock *lock)
 {
-	struct bpf_list_node *node;

tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c fq_flows_remove_front(struct bpf_list_head *head, struct bpf_spin_lock *lock, · line 202

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? A search of the codebase doesn't show this function being defined as a BPF helper, kfunc, or macro anywhere in the kernel source or BPF headers.

Since BPF list structures are opaque, their access must be mediated by verifier-recognized kfuncs. Will this cause a build failure due to an implicit declaration?

Could the existing bpf_list_front() kfunc be used instead to check list emptiness without mutation?

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
Quoted 46 lines · On Sun, 24 May 2026 at 09:00, <[email protected]> wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The patch introduces a call to bpf_list_empty(), which is an undeclared function, resulting in a build failure. --

commit 9fb6024323da084c2713bff3f8a0e6018dc6bd72
Author: Suchit Karunakaran <[email protected]>

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

This commit simplifies fq_flows_is_empty() by replacing a pop/push check with a direct call to bpf_list_empty(). The intention is to avoid unnecessary list mutation and simplify the code.

Quoted 9 lines
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +0 -1
index 1a3233a275c7e..8107f5934d2d7 100644
@@ -196,18 +196,13 @@ fq_flows_remove_front(struct bpf_list_head *head, struct bpf_spin_lock *lock,
 static bool
 fq_flows_is_empty(struct bpf_list_head *head, struct bpf_spin_lock *lock)
 {
-     struct bpf_list_node *node;

tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c fq_flows_remove_front(struct bpf_list_head *head, struct bpf_spin_lock *lock, · line 202

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? A search of the codebase doesn't show this function being defined as a BPF helper, kfunc, or macro anywhere in the kernel source or BPF headers.

Since BPF list structures are opaque, their access must be mediated by verifier-recognized kfuncs. Will this cause a build failure due to an implicit declaration?

Could the existing bpf_list_front() kfunc be used instead to check list emptiness without mutation?

Quoted 8 lines

tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c fq_flows_remove_front(struct bpf_list_head *head, struct bpf_spin_lock *lock, · line 206

Quoted 5 lines
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +1 -1
      bpf_spin_unlock(lock);
 
-     return true;
+     return empty;
 }

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1

bpf_list_empty() is available in the current bpf-next and linux-next trees, which is what this patch was based on. It has not yet been merged into mainline or the current rc tree.

reviewer Reviewed-by on v2 1/1
#3 lore raw
In reply to Suchit Karunakaran
Quoted 9 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.

Changes since v1:
- Removed unused variable node

Saw v1 before v2:

Quoted 30 lines
---
 tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
tools/testing/selftests/bpf/progs/bpf_qdisc_fq.c +3 -8
index 1a3233a275c7..8107f5934d2d 100644
@@ -196,18 +196,13 @@ fq_flows_remove_front(struct bpf_list_head *head, struct bpf_spin_lock *lock,
 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)
#4 lore raw
In reply to Suchit Karunakaran
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

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

Quoted 8 lines · On Sun, 24 May 2026 08:28:53 +0530 you wrote:

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.

[...]

Here is the summary with links:
- [v2] bpf: replace pop/push emptiness check with bpf_list_empty()

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

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html