Skip to contentSkip to conversation

selftests/bpf: Fix kmem_cache iterator draining

PATCH Applied T.J. Mercier 4 participants 5 messages Apr 28, 2025 – Apr 29, 2025

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

PATCH 1/1 selftests/bpf: Fix kmem_cache iterator draining

The closing parentheses around the read syscall is misplaced, causing single byte reads from the iterator instead of buf sized reads. While the end result is the same, many more read calls than necessary are performed.

$ tools/testing/selftests/bpf/vmtest.sh  "./test_progs -t kmem_cache_iter"
145/1   kmem_cache_iter/check_task_struct:OK
145/2   kmem_cache_iter/check_slabinfo:OK
145/3   kmem_cache_iter/open_coded_iter:OK
145     kmem_cache_iter:OK
Summary: 1/3 PASSED, 0 SKIPPED, 0 FAILED
Fixes a496d0cdc84d ("selftests/bpf: Add a test for kmem_cache_iter")
---
 tools/testing/selftests/bpf/prog_tests/kmem_cache_iter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/kmem_cache_iter.c +1 -1
index 8e13a3416a21..1de14b111931 100644
@@ -104,7 +104,7 @@ void test_kmem_cache_iter(void)
 		goto destroy;
 
 	memset(buf, 0, sizeof(buf));
-	while (read(iter_fd, buf, sizeof(buf) > 0)) {
+	while (read(iter_fd, buf, sizeof(buf)) > 0) {
 		/* Read out all contents */
 		printf("%s", buf);
 	}

base-commit: b4432656b36e5cc1d50a1f2dc15357543add530e

Signature · 1 line
2.49.0.906.g1f30a19c02-goog
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 13 lines · T.J. Mercier

The closing parentheses around the read syscall is misplaced, causing single byte reads from the iterator instead of buf sized reads. While the end result is the same, many more read calls than necessary are performed.

$ tools/testing/selftests/bpf/vmtest.sh  "./test_progs -t kmem_cache_iter"
145/1   kmem_cache_iter/check_task_struct:OK
145/2   kmem_cache_iter/check_slabinfo:OK
145/3   kmem_cache_iter/open_coded_iter:OK
145     kmem_cache_iter:OK
Summary: 1/3 PASSED, 0 SKIPPED, 0 FAILED
Quoted 2 lines
Fixes a496d0cdc84d ("selftests/bpf: Add a test for kmem_cache_iter")
Acked-by on v1 1/1
#2 lore raw
In reply to T.J. Mercier

Hello,

Quoted 12 lines · T.J. Mercier

The closing parentheses around the read syscall is misplaced, causing single byte reads from the iterator instead of buf sized reads. While the end result is the same, many more read calls than necessary are performed.

$ tools/testing/selftests/bpf/vmtest.sh  "./test_progs -t kmem_cache_iter"
145/1   kmem_cache_iter/check_task_struct:OK
145/2   kmem_cache_iter/check_slabinfo:OK
145/3   kmem_cache_iter/open_coded_iter:OK
145     kmem_cache_iter:OK
Summary: 1/3 PASSED, 0 SKIPPED, 0 FAILED
Quoted 2 lines
Fixes a496d0cdc84d ("selftests/bpf: Add a test for kmem_cache_iter")

Oops, thanks for fixing this.

Thanks,
Namhyung

Quoted 22 lines
---
 tools/testing/selftests/bpf/prog_tests/kmem_cache_iter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/kmem_cache_iter.c +1 -1
index 8e13a3416a21..1de14b111931 100644
@@ -104,7 +104,7 @@ void test_kmem_cache_iter(void)
 		goto destroy;
 
 	memset(buf, 0, sizeof(buf));
-	while (read(iter_fd, buf, sizeof(buf) > 0)) {
+	while (read(iter_fd, buf, sizeof(buf)) > 0) {
 		/* Read out all contents */
 		printf("%s", buf);
 	}

base-commit: b4432656b36e5cc1d50a1f2dc15357543add530e

Signature · 1 line
2.49.0.906.g1f30a19c02-goog
#3 lore raw
Quoted 19 lines · Namhyung Kim

Hello,

Quoted 12 lines · T.J. Mercier

The closing parentheses around the read syscall is misplaced, causing single byte reads from the iterator instead of buf sized reads. While the end result is the same, many more read calls than necessary are performed.

$ tools/testing/selftests/bpf/vmtest.sh  "./test_progs -t kmem_cache_iter"
145/1   kmem_cache_iter/check_task_struct:OK
145/2   kmem_cache_iter/check_slabinfo:OK
145/3   kmem_cache_iter/open_coded_iter:OK
145     kmem_cache_iter:OK
Summary: 1/3 PASSED, 0 SKIPPED, 0 FAILED
Quoted 2 lines
Fixes a496d0cdc84d ("selftests/bpf: Add a test for kmem_cache_iter")
Quoted 6 lines

Oops, thanks for fixing this.

Thanks,
Namhyung

No worries, thanks! It's been helpful reading through this code.

Quoted 22 lines
Quoted 22 lines
---
 tools/testing/selftests/bpf/prog_tests/kmem_cache_iter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/kmem_cache_iter.c +1 -1
index 8e13a3416a21..1de14b111931 100644
@@ -104,7 +104,7 @@ void test_kmem_cache_iter(void)
              goto destroy;
 
      memset(buf, 0, sizeof(buf));
-     while (read(iter_fd, buf, sizeof(buf) > 0)) {
+     while (read(iter_fd, buf, sizeof(buf)) > 0) {
              /* Read out all contents */
              printf("%s", buf);
      }

base-commit: b4432656b36e5cc1d50a1f2dc15357543add530e --
2.49.0.906.g1f30a19c02-goog

#4 lore raw
In reply to T.J. Mercier
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 5 lines · On Mon, 28 Apr 2025 18:02:54 +0000 you wrote:

The closing parentheses around the read syscall is misplaced, causing single byte reads from the iterator instead of buf sized reads. While the end result is the same, many more read calls than necessary are performed.

Quoted 8 lines
$ tools/testing/selftests/bpf/vmtest.sh  "./test_progs -t kmem_cache_iter"
145/1   kmem_cache_iter/check_task_struct:OK
145/2   kmem_cache_iter/check_slabinfo:OK
145/3   kmem_cache_iter/open_coded_iter:OK
145     kmem_cache_iter:OK
Summary: 1/3 PASSED, 0 SKIPPED, 0 FAILED

[...]

Here is the summary with links:
- selftests/bpf: Fix kmem_cache iterator draining

    https://git.kernel.org/bpf/bpf-next/c/38d976c32d85

You are awesome, thank you!

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