BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/5] bpf: Followups for global percpu data series
@ 2026-08-14 17:32 Leon Hwang
  2026-08-14 17:32 ` [PATCH bpf-next 1/5] bpf: Drop duplicate blank line in verifier Leon Hwang
                   ` (6 more replies)
  0 siblings, 7 replies; 11+ messages in thread
From: Leon Hwang @ 2026-08-14 17:32 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
	Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Quentin Monnet, Shuah Khan,
	Leon Hwang, linux-kernel, linux-kselftest

Address some LLM reviews in
"[PATCH bpf-next v12 00/10] bpf: Introduce global percpu data" [1].

[1] https://lore.kernel.org/bpf/20260813152324.97937-1-leon.hwang@linux.dev/

Leon Hwang (5):
  bpf: Drop duplicate blank line in verifier
  libbpf: Avoid unnecessary mmap resize for percpu data maps
  bpftool: Update comments about skel data maps
  selftests/bpf: Avoid flaky resize value test for percpu data
  selftests/bpf: Improve readability in iter test for percpu data

 kernel/bpf/verifier.c                         |  1 -
 tools/bpf/bpftool/gen.c                       |  4 +-
 tools/lib/bpf/libbpf.c                        | 17 ++++----
 .../bpf/prog_tests/global_data_init.c         | 43 ++++++++++---------
 .../bpf/progs/test_global_percpu_data.c       | 14 +++---
 5 files changed, 41 insertions(+), 38 deletions(-)

-- 
2.55.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH bpf-next 1/5] bpf: Drop duplicate blank line in verifier
  2026-08-14 17:32 [PATCH bpf-next 0/5] bpf: Followups for global percpu data series Leon Hwang
@ 2026-08-14 17:32 ` Leon Hwang
  2026-08-14 20:32   ` Andrii Nakryiko
  2026-08-14 17:32 ` [PATCH bpf-next 2/5] libbpf: Avoid unnecessary mmap resize for percpu data maps Leon Hwang
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 11+ messages in thread
From: Leon Hwang @ 2026-08-14 17:32 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
	Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Quentin Monnet, Shuah Khan,
	Leon Hwang, linux-kernel, linux-kselftest

Drop a duplicate blank line in verifier for cleanup.

No functional change intended.

Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
---
 kernel/bpf/verifier.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 6ac1afced20b..81eae8f70acd 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -12113,7 +12113,6 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_call_arg_me
 			ref_tname = btf_name_by_offset(btf, ref_t->name_off);
 		}
 
-
 		if (bpf_register_is_null(reg) && type_may_be_null(kf_arg_type))
 			continue;
 
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH bpf-next 2/5] libbpf: Avoid unnecessary mmap resize for percpu data maps
  2026-08-14 17:32 [PATCH bpf-next 0/5] bpf: Followups for global percpu data series Leon Hwang
  2026-08-14 17:32 ` [PATCH bpf-next 1/5] bpf: Drop duplicate blank line in verifier Leon Hwang
@ 2026-08-14 17:32 ` Leon Hwang
  2026-08-14 17:32 ` [PATCH bpf-next 3/5] bpftool: Update comments about skel " Leon Hwang
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Leon Hwang @ 2026-08-14 17:32 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
	Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Quentin Monnet, Shuah Khan,
	Leon Hwang, linux-kernel, linux-kselftest

Use array_map_mmap_sz() for PERCPU_ARRAY like ARRAY in bpf_map_mmap_sz().
This lets bpf_map__set_value_size() skip mmap(), memcpy(), and munmap()
when the old and new value sizes occupy the same number of pages.

Fix some typos btw:

* mmapble -> mmapable
* satisified -> satisfied
* relocatin -> relocation
* atach_btf_obj_fd -> attach_btf_obj_fd
* len_secnd -> len_second
* precendence -> precedence

Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
---
 tools/lib/bpf/libbpf.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index e574870fb716..b749c01742ee 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1841,9 +1841,8 @@ static size_t bpf_map_mmap_sz(const struct bpf_map *map)
 
 	switch (map->def.type) {
 	case BPF_MAP_TYPE_ARRAY:
-		return array_map_mmap_sz(map->def.value_size, map->def.max_entries);
 	case BPF_MAP_TYPE_PERCPU_ARRAY:
-		return map->def.value_size;
+		return array_map_mmap_sz(map->def.value_size, map->def.max_entries);
 	case BPF_MAP_TYPE_ARENA:
 		return page_sz * map->def.max_entries;
 	default:
@@ -1951,7 +1950,7 @@ static bool map_is_mmapable(struct bpf_object *obj, struct bpf_map *map)
 		return false;
 
 	/*
-	 * The internal PERCPU maps are not mmapble because the underlying
+	 * The internal PERCPU maps are not mmapable because the underlying
 	 * percpu_array maps do not have mmap support.
 	 */
 	if (map->libbpf_type == LIBBPF_MAP_PERCPU)
@@ -2831,7 +2830,7 @@ static size_t adjust_ringbuf_sz(size_t sz)
 		return 0;
 	/* Kernel expects BPF_MAP_TYPE_RINGBUF's max_entries to be
 	 * a power-of-2 multiple of kernel's page size. If user diligently
-	 * satisified these conditions, pass the size through.
+	 * satisfied these conditions, pass the size through.
 	 */
 	if ((sz % page_sz) == 0 && is_pow_of_2(sz / page_sz))
 		return sz;
@@ -6989,7 +6988,7 @@ bpf_object__reloc_code(struct bpf_object *obj, struct bpf_program *main_prog,
  *    +-----------+------+------+
  *
  * At this point, we relocate subA calls, then go one level up and finish with
- * relocatin mainA calls. mainA is done.
+ * relocation mainA calls. mainA is done.
  *
  * For mainB process is similar but results in different order. We start with
  * mainB and skip subA and subB, as mainB never calls them (at least
@@ -7936,7 +7935,7 @@ static int libbpf_prepare_prog_load(struct bpf_program *prog,
 		prog->attach_btf_id = btf_type_id;
 
 		/* but by now libbpf common logic is not utilizing
-		 * prog->atach_btf_obj_fd/prog->attach_btf_id anymore because
+		 * prog->attach_btf_obj_fd/prog->attach_btf_id anymore because
 		 * this callback is called after opts were populated by
 		 * libbpf, so this callback has to update opts explicitly here
 		 */
@@ -14219,7 +14218,7 @@ perf_event_read_simple(void *mmap_mem, size_t mmap_size, size_t page_size,
 		if (((void *)ehdr) + ehdr_size > base + mmap_size) {
 			void *copy_start = ehdr;
 			size_t len_first = base + mmap_size - copy_start;
-			size_t len_secnd = ehdr_size - len_first;
+			size_t len_second = ehdr_size - len_first;
 
 			if (*copy_size < ehdr_size) {
 				free(*copy_mem);
@@ -14233,7 +14232,7 @@ perf_event_read_simple(void *mmap_mem, size_t mmap_size, size_t page_size,
 			}
 
 			memcpy(*copy_mem, copy_start, len_first);
-			memcpy(*copy_mem + len_first, base, len_secnd);
+			memcpy(*copy_mem + len_first, base, len_second);
 			ehdr = *copy_mem;
 		}
 
@@ -14251,7 +14250,7 @@ struct perf_buffer;
 
 struct perf_buffer_params {
 	struct perf_event_attr *attr;
-	/* if event_cb is specified, it takes precendence */
+	/* if event_cb is specified, it takes precedence */
 	perf_buffer_event_fn event_cb;
 	/* sample_cb and lost_cb are higher-level common-case callbacks */
 	perf_buffer_sample_fn sample_cb;
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH bpf-next 3/5] bpftool: Update comments about skel data maps
  2026-08-14 17:32 [PATCH bpf-next 0/5] bpf: Followups for global percpu data series Leon Hwang
  2026-08-14 17:32 ` [PATCH bpf-next 1/5] bpf: Drop duplicate blank line in verifier Leon Hwang
  2026-08-14 17:32 ` [PATCH bpf-next 2/5] libbpf: Avoid unnecessary mmap resize for percpu data maps Leon Hwang
@ 2026-08-14 17:32 ` Leon Hwang
  2026-08-14 20:32   ` Andrii Nakryiko
  2026-08-14 17:32 ` [PATCH bpf-next 4/5] selftests/bpf: Avoid flaky resize value test for percpu data Leon Hwang
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 11+ messages in thread
From: Leon Hwang @ 2026-08-14 17:32 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
	Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Quentin Monnet, Shuah Khan,
	Leon Hwang, linux-kernel, linux-kselftest

Since is_skel_data() includes the non-memory-mapped percpu_array map, the
"memory-mapped maps" in comments are incorrect for percpu data.

Update "memory-mapped internal maps" to "skel data maps" for better
explanation.

Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
---
 tools/bpf/bpftool/gen.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
index a50540ef6521..e5e82255af24 100644
--- a/tools/bpf/bpftool/gen.c
+++ b/tools/bpf/bpftool/gen.c
@@ -303,7 +303,7 @@ static int codegen_datasecs(struct bpf_object *obj, const char *obj_name)
 		return -errno;
 
 	bpf_object__for_each_map(map, obj) {
-		/* only generate definitions for memory-mapped internal maps */
+		/* only generate definitions for skel data maps */
 		if (!is_skel_data(map, map_ident, sizeof(map_ident)))
 			continue;
 
@@ -510,7 +510,7 @@ static size_t bpf_map_mmap_sz(const struct bpf_map *map)
 	return map_sz;
 }
 
-/* Emit type size asserts for all top-level fields in memory-mapped internal maps. */
+/* Emit type size asserts for all top-level fields in skel data maps. */
 static void codegen_asserts(struct bpf_object *obj, const char *obj_name)
 {
 	struct btf *btf = bpf_object__btf(obj);
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH bpf-next 4/5] selftests/bpf: Avoid flaky resize value test for percpu data
  2026-08-14 17:32 [PATCH bpf-next 0/5] bpf: Followups for global percpu data series Leon Hwang
                   ` (2 preceding siblings ...)
  2026-08-14 17:32 ` [PATCH bpf-next 3/5] bpftool: Update comments about skel " Leon Hwang
@ 2026-08-14 17:32 ` Leon Hwang
  2026-08-14 18:24   ` bot+bpf-ci
  2026-08-14 17:32 ` [PATCH bpf-next 5/5] selftests/bpf: Improve readability in iter " Leon Hwang
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 11+ messages in thread
From: Leon Hwang @ 2026-08-14 17:32 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
	Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Quentin Monnet, Shuah Khan,
	Leon Hwang, linux-kernel, linux-kselftest

The bpf_map__set_value_size() test for percpu data relies on the tail
'cpu_id' field in the ".percpu" map. The test would fail, when 'cpu_id' is
not the last field in the map.

To avoid the flaky test, use a dedicated ".percpu.arr" map that only has
one field 'int arr[1]' to ensure that bpf_map__set_value_size() won't
fail.

And, drop 'args' in test_percpu_data_on_cpus(), which isn't used in bpf
prog side.

And, enhance the test to cover 'set' and 'nums[6]' to distinguish a broken
copy.

Fixes: 4c9241bd731a ("selftests/bpf: Add tests to verify global percpu data")
Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
---
 .../bpf/prog_tests/global_data_init.c         | 37 ++++++++++---------
 .../bpf/progs/test_global_percpu_data.c       |  8 ++--
 2 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/global_data_init.c b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
index 7d6bda909295..2f0dbeb88934 100644
--- a/tools/testing/selftests/bpf/prog_tests/global_data_init.c
+++ b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
@@ -68,12 +68,9 @@ static void test_percpu_data_on_cpus(struct bpf_map *map, int map_fd, int prog_f
 {
 	struct test_global_percpu_data__percpu *data = NULL;
 	int i, err, key = 0, num_online, run = 0;
-	__u64 args[2] = {0x1234ULL, 0x5678ULL};
 	size_t data_sz;
 	bool *online;
 	LIBBPF_OPTS(bpf_test_run_opts, topts,
-		    .ctx_in = args,
-		    .ctx_size_in = sizeof(args),
 		    .flags = BPF_F_TEST_RUN_ON_CPU,
 	);
 
@@ -81,7 +78,7 @@ static void test_percpu_data_on_cpus(struct bpf_map *map, int map_fd, int prog_f
 	if (!ASSERT_OK(err, "parse_cpu_mask_file"))
 		return;
 
-	data_sz = map ? bpf_map__value_size(map) : sizeof(*data);
+	data_sz = sizeof(*data);
 	data = calloc(1, data_sz);
 	if (!ASSERT_OK_PTR(data, "calloc percpu data"))
 		goto out;
@@ -109,7 +106,7 @@ static void test_percpu_data_on_cpus(struct bpf_map *map, int map_fd, int prog_f
 			break;
 
 		ASSERT_EQ(*runp, ++run, "run");
-		ASSERT_EQ(data->cpu_id[0], i, "cpu_id");
+		ASSERT_EQ(data->cpu_id, i, "cpu_id");
 		ASSERT_EQ(data->data, 1, "data");
 		ASSERT_TRUE(data->set, "set");
 		ASSERT_EQ(data->nums[6], 0xc0de, "nums[6]");
@@ -126,11 +123,11 @@ static void test_percpu_data_on_cpus(struct bpf_map *map, int map_fd, int prog_f
 static void test_global_percpu_data_init(void)
 {
 	struct test_global_percpu_data__percpu init_value = {};
+	const __u32 desired_sz = sysconf(_SC_PAGE_SIZE) * 2;
 	struct test_global_percpu_data__percpu *init_data;
-	const __u32 desired_sz = sysconf(_SC_PAGE_SIZE);
 	struct test_global_percpu_data *skel = NULL;
+	struct bpf_map *map, *map_percpu_arr;
 	size_t init_data_sz;
-	struct bpf_map *map;
 	int prog_fd, err;
 
 	skel = test_global_percpu_data__open();
@@ -163,9 +160,11 @@ static void test_global_percpu_data_init(void)
 	if (!ASSERT_EQ(bpf_map__type(map), BPF_MAP_TYPE_PERCPU_ARRAY, "bpf_map__type"))
 		goto out;
 
+	init_value.set = 1;
 	init_value.data = 2;
 	init_value.nums[6] = -1;
 	init_value.struct_data.i = 2;
+	init_value.struct_data.set = 1;
 	init_value.struct_data.nums[6] = -1;
 	err = bpf_map__set_initial_value(map, &init_value, sizeof(init_value));
 	if (!ASSERT_OK(err, "bpf_map__set_initial_value"))
@@ -177,33 +176,37 @@ static void test_global_percpu_data_init(void)
 
 	ASSERT_EQ(init_data->data, init_value.data, "init_value data");
 	ASSERT_EQ(init_data->set, init_value.set, "init_value set");
+	ASSERT_EQ(init_data->nums[6], init_value.nums[6], "init_value nums[6]");
 	ASSERT_EQ(init_data->struct_data.i, init_value.struct_data.i, "init_value struct_data.i");
+	ASSERT_EQ(init_data->struct_data.set, init_value.struct_data.set,
+		  "init_value struct_data.set");
 	ASSERT_EQ(init_data->struct_data.nums[6], init_value.struct_data.nums[6],
 		  "init_value struct_data.nums[6]");
 	ASSERT_EQ(init_data_sz, sizeof(init_value), "init_value size");
 	ASSERT_EQ((void *) init_data, (void *) skel->percpu, "skel->percpu eq init_data");
 	ASSERT_EQ(skel->percpu->data, init_value.data, "skel->percpu->data");
 	ASSERT_EQ(skel->percpu->set, init_value.set, "skel->percpu->set");
+	ASSERT_EQ(skel->percpu->nums[6], init_value.nums[6], "skel->percpu->nums[6]");
 	ASSERT_EQ(skel->percpu->struct_data.i, init_value.struct_data.i,
 		  "skel->percpu->struct_data.i");
+	ASSERT_EQ(skel->percpu->struct_data.set, init_value.struct_data.set,
+		  "skel->percpu->struct_data.set");
 	ASSERT_EQ(skel->percpu->struct_data.nums[6], init_value.struct_data.nums[6],
 		  "skel->percpu->struct_data.nums[6]");
 
-	ASSERT_GT(desired_sz, sizeof(init_value), "desired_sz");
-	err = bpf_map__set_value_size(map, desired_sz);
+	skel->percpu_arr->arr[0] = -1;
+	map_percpu_arr = skel->maps.percpu_arr;
+	err = bpf_map__set_value_size(map_percpu_arr, desired_sz);
 	if (!ASSERT_OK(err, "bpf_map__set_value_size"))
 		goto out;
-	if (!ASSERT_EQ(bpf_map__value_size(map), desired_sz, "percpu value size"))
-		goto out;
-	if (!ASSERT_NEQ(bpf_map__btf_value_type_id(map), 0, "percpu BTF value type"))
+	if (!ASSERT_EQ(bpf_map__value_size(map_percpu_arr), desired_sz, "percpu value size"))
 		goto out;
-
-	init_data = bpf_map__initial_value(map, &init_data_sz);
-	if (!ASSERT_OK_PTR(init_data, "resized bpf_map__initial_value"))
+	if (!ASSERT_NEQ(bpf_map__btf_value_type_id(map_percpu_arr), 0, "percpu BTF value type"))
 		goto out;
-	if (!ASSERT_EQ(init_data_sz, desired_sz, "resized initial value size"))
+	skel->percpu_arr = bpf_map__initial_value(map_percpu_arr, &init_data_sz);
+	if (!ASSERT_OK_PTR(skel->percpu_arr, "resized percpu_arr value"))
 		goto out;
-	if (!ASSERT_EQ(init_data->data, init_value.data, "resized initial value data"))
+	if (!ASSERT_EQ(skel->percpu_arr->arr[0], -1, "arr[0]"))
 		goto out;
 
 	err = test_global_percpu_data__load(skel);
diff --git a/tools/testing/selftests/bpf/progs/test_global_percpu_data.c b/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
index 71ff8d1bf49e..12556590b647 100644
--- a/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
+++ b/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
@@ -8,9 +8,11 @@ int loong SEC(".percpu.looooooooong");
 int data3 SEC(".data.percpu");
 int data2 SEC(".percpu.data");
 
+/* Used for testing bpf_map__set_value_size(). */
+int arr[1] SEC(".percpu.arr");
+
 int run;
-/* cpu_id as array to verify map value resizing. */
-int cpu_id[1] SEC(".percpu");
+int cpu_id SEC(".percpu");
 int data SEC(".percpu") = -1;
 int nums[7] SEC(".percpu");
 bool set SEC(".percpu") = false;
@@ -34,7 +36,7 @@ int update_percpu_data(void *ctx)
 	data = 1;
 	run++;
 	set = true;
-	cpu_id[0] = bpf_get_smp_processor_id();
+	cpu_id = bpf_get_smp_processor_id();
 	return 0;
 }
 
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH bpf-next 5/5] selftests/bpf: Improve readability in iter test for percpu data
  2026-08-14 17:32 [PATCH bpf-next 0/5] bpf: Followups for global percpu data series Leon Hwang
                   ` (3 preceding siblings ...)
  2026-08-14 17:32 ` [PATCH bpf-next 4/5] selftests/bpf: Avoid flaky resize value test for percpu data Leon Hwang
@ 2026-08-14 17:32 ` Leon Hwang
  2026-08-14 20:37 ` [PATCH bpf-next 0/5] bpf: Followups for global percpu data series Andrii Nakryiko
  2026-08-14 20:40 ` patchwork-bot+netdevbpf
  6 siblings, 0 replies; 11+ messages in thread
From: Leon Hwang @ 2026-08-14 17:32 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
	Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Quentin Monnet, Shuah Khan,
	Leon Hwang, linux-kernel, linux-kselftest

The original 'offsetof()' + offset is equal to the new 'offsetof()'. Use
the new 'offsetof()' instead.

Rename two variables btw:

* offsetof_num -> num_off
* percpu_data_sum -> sum

Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
---
 tools/testing/selftests/bpf/prog_tests/global_data_init.c   | 6 +++---
 tools/testing/selftests/bpf/progs/test_global_percpu_data.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/global_data_init.c b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
index 2f0dbeb88934..c6d055b9457d 100644
--- a/tools/testing/selftests/bpf/prog_tests/global_data_init.c
+++ b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
@@ -348,8 +348,8 @@ static void test_global_percpu_data_iter(void)
 		return;
 
 	skel->rodata->num_cpus = num_cpus;
-	skel->rodata->offsetof_num = offsetof(struct test_global_percpu_data__percpu, struct_data);
-	skel->rodata->offsetof_num += sizeof(skel->percpu->struct_data) - sizeof(int);
+	skel->rodata->num_off = offsetof(struct test_global_percpu_data__percpu,
+					 struct_data.nums[6]);
 	skel->rodata->elem_sz = roundup(sizeof(struct test_global_percpu_data__percpu), 8);
 	skel->percpu->struct_data.nums[6] = 0xc0de;
 
@@ -372,7 +372,7 @@ static void test_global_percpu_data_iter(void)
 		do { } while (0);
 	ASSERT_EQ(len, 0, "read iter");
 	ASSERT_TRUE(skel->bss->run_iter, "run_iter");
-	ASSERT_EQ(skel->bss->percpu_data_sum, 0xc0de * num_cpus, "percpu_data_sum");
+	ASSERT_EQ(skel->bss->sum, 0xc0de * num_cpus, "sum");
 
 	close(fd);
 out:
diff --git a/tools/testing/selftests/bpf/progs/test_global_percpu_data.c b/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
index 12556590b647..175c44000753 100644
--- a/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
+++ b/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
@@ -64,9 +64,9 @@ int verifier_snprintf(void *ctx)
 }
 
 volatile const __u32 num_cpus = 0;
-volatile const int offsetof_num;
+volatile const int num_off;
 volatile const int elem_sz;
-__u32 percpu_data_sum = 0;
+__u32 sum = 0;
 bool run_iter = false;
 
 SEC("iter/bpf_map_elem")
@@ -82,7 +82,7 @@ int dump_percpu_data(struct bpf_iter__bpf_map_elem *ctx)
 	run_iter = true;
 
 	for (i = 0; i < num_cpus; i++) {
-		percpu_data_sum += *(int *) (pptr + offsetof_num);
+		sum += *(int *) (pptr + num_off);
 		pptr += elem_sz;
 	}
 	return 0;
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH bpf-next 4/5] selftests/bpf: Avoid flaky resize value test for percpu data
  2026-08-14 17:32 ` [PATCH bpf-next 4/5] selftests/bpf: Avoid flaky resize value test for percpu data Leon Hwang
@ 2026-08-14 18:24   ` bot+bpf-ci
  0 siblings, 0 replies; 11+ messages in thread
From: bot+bpf-ci @ 2026-08-14 18:24 UTC (permalink / raw)
  To: leon.hwang, bpf
  Cc: ast, daniel, john.fastabend, andrii, eddyz87, memxor, martin.lau,
	song, yonghong.song, jolsa, emil, ihor.solodrai, qmo, shuah,
	leon.hwang, linux-kernel, linux-kselftest, ast, andrii, daniel,
	martin.lau, eddyz87, yonghong.song, clm, ihor.solodrai

[-- Attachment #1: Type: text/plain, Size: 4421 bytes --]

> diff --git a/tools/testing/selftests/bpf/prog_tests/global_data_init.c b/tools/testing/selftests/bpf/prog_tests/global_data_init.c
> index 7d6bda909295..2f0dbeb88934 100644
> --- a/tools/testing/selftests/bpf/prog_tests/global_data_init.c
> +++ b/tools/testing/selftests/bpf/prog_tests/global_data_init.c

[ ... ]

> @@ -126,11 +123,11 @@ static void test_percpu_data_on_cpus(struct bpf_map *map, int map_fd, int prog_f
>  static void test_global_percpu_data_init(void)
>  {
>  	struct test_global_percpu_data__percpu init_value = {};
> +	const __u32 desired_sz = sysconf(_SC_PAGE_SIZE) * 2;
>  	struct test_global_percpu_data__percpu *init_data;
> -	const __u32 desired_sz = sysconf(_SC_PAGE_SIZE);

Does multiplying by 2 here break the test on 64K page systems?

Per-CPU array value sizes are capped by the kernel:

  /* percpu map value size is bound by PCPU_MIN_UNIT_SIZE */
  if (percpu && round_up(attr->value_size, 8) > PCPU_MIN_UNIT_SIZE)
          return -E2BIG;

in kernel/bpf/arraymap.c:array_map_alloc_check(), where PCPU_MIN_UNIT_SIZE
is defined as:

  #define PCPU_MIN_UNIT_SIZE  PFN_ALIGN(32 << 10)

which equals max(32768, PAGE_SIZE).

The old code was safe by construction: desired_sz == PAGE_SIZE <=
PFN_ALIGN(32768) == PCPU_MIN_UNIT_SIZE. Doubling it breaks that:

  PAGE_SIZE  4096 -> limit 32768, request   8192  OK
  PAGE_SIZE 16384 -> limit 32768, request  32768  OK (exactly at limit)
  PAGE_SIZE 65536 -> limit 65536, request 131072  -E2BIG

On kernels built with 64K pages (arm64 CONFIG_ARM64_64K_PAGES, ppc64)
bpf_map__set_value_size() still succeeds (it is purely userspace
bookkeeping), all four assertions that follow it pass, and then map
creation fails inside test_global_percpu_data__load():

>  	err = test_global_percpu_data__load(skel);
>  	if (!ASSERT_OK(err, "test_global_percpu_data__load"))
>  		goto out;

The "global_percpu_data/init" subtest fails, and test_percpu_data_on_cpus()
is never reached. That is a new failure introduced by this patch (with
desired_sz == PAGE_SIZE the same configuration created a 65536-byte per-CPU
value, which is exactly at the limit and accepted).

Note that the neighbouring resize test in global_map_resize.c deliberately
does not scale a per-CPU map by page size for this reason. At line 46 it
uses:

  new_sz = sizeof(skel->data_percpu_arr->percpu_arr[0]) *
           libbpf_num_possible_cpus();

A size that is independent of PAGE_SIZE would still force the mmap region
to move, which is what the new skel->percpu_arr reassignment and the
arr[0] == -1 check are there to exercise, without hitting the per-CPU
allocator bound.

>  	struct test_global_percpu_data *skel = NULL;
> +	struct bpf_map *map, *map_percpu_arr;
>  	size_t init_data_sz;
> -	struct bpf_map *map;
>  	int prog_fd, err;

[ ... ]

> @@ -177,33 +176,37 @@ static void test_global_percpu_data_init(void)
>
>  	ASSERT_EQ(init_data->data, init_value.data, "init_value data");
>  	ASSERT_EQ(init_data->set, init_value.set, "init_value set");
> +	ASSERT_EQ(init_data->nums[6], init_value.nums[6], "init_value nums[6]");

[ ... ]

> -	ASSERT_GT(desired_sz, sizeof(init_value), "desired_sz");
> -	err = bpf_map__set_value_size(map, desired_sz);
> +	skel->percpu_arr->arr[0] = -1;
> +	map_percpu_arr = skel->maps.percpu_arr;
> +	err = bpf_map__set_value_size(map_percpu_arr, desired_sz);
>  	if (!ASSERT_OK(err, "bpf_map__set_value_size"))
>  		goto out;

[ ... ]

> diff --git a/tools/testing/selftests/bpf/progs/test_global_percpu_data.c b/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
> index 71ff8d1bf49e..12556590b647 100644
> --- a/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
> +++ b/tools/testing/selftests/bpf/progs/test_global_percpu_data.c
> @@ -8,9 +8,11 @@ int loong SEC(".percpu.looooooooong");
>  int data3 SEC(".data.percpu");
>  int data2 SEC(".percpu.data");
>
> +/* Used for testing bpf_map__set_value_size(). */
> +int arr[1] SEC(".percpu.arr");
> +
>  int run;
> -/* cpu_id as array to verify map value resizing. */
> -int cpu_id[1] SEC(".percpu");
> +int cpu_id SEC(".percpu");
>  int data SEC(".percpu") = -1;
>  int nums[7] SEC(".percpu");
>  bool set SEC(".percpu") = false;

[ ... ]


---
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/31826359148

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH bpf-next 1/5] bpf: Drop duplicate blank line in verifier
  2026-08-14 17:32 ` [PATCH bpf-next 1/5] bpf: Drop duplicate blank line in verifier Leon Hwang
@ 2026-08-14 20:32   ` Andrii Nakryiko
  0 siblings, 0 replies; 11+ messages in thread
From: Andrii Nakryiko @ 2026-08-14 20:32 UTC (permalink / raw)
  To: Leon Hwang
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, John Fastabend,
	Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Quentin Monnet, Shuah Khan,
	linux-kernel, linux-kselftest

On Fri, Aug 14, 2026 at 10:32 AM Leon Hwang <leon.hwang@linux.dev> wrote:
>
> Drop a duplicate blank line in verifier for cleanup.
>
> No functional change intended.
>
> Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
> ---
>  kernel/bpf/verifier.c | 1 -
>  1 file changed, 1 deletion(-)
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 6ac1afced20b..81eae8f70acd 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -12113,7 +12113,6 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_call_arg_me
>                         ref_tname = btf_name_by_offset(btf, ref_t->name_off);
>                 }
>
> -

seriously... just because AI tells you to do something, doesn't mean
you have to do it. I'm not applying a patch that's removing a single
empty line.


>                 if (bpf_register_is_null(reg) && type_may_be_null(kf_arg_type))
>                         continue;
>
> --
> 2.55.0
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH bpf-next 3/5] bpftool: Update comments about skel data maps
  2026-08-14 17:32 ` [PATCH bpf-next 3/5] bpftool: Update comments about skel " Leon Hwang
@ 2026-08-14 20:32   ` Andrii Nakryiko
  0 siblings, 0 replies; 11+ messages in thread
From: Andrii Nakryiko @ 2026-08-14 20:32 UTC (permalink / raw)
  To: Leon Hwang
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, John Fastabend,
	Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Quentin Monnet, Shuah Khan,
	linux-kernel, linux-kselftest

On Fri, Aug 14, 2026 at 10:32 AM Leon Hwang <leon.hwang@linux.dev> wrote:
>
> Since is_skel_data() includes the non-memory-mapped percpu_array map, the
> "memory-mapped maps" in comments are incorrect for percpu data.
>
> Update "memory-mapped internal maps" to "skel data maps" for better
> explanation.

What is a "skel data map"? "memory-mapped internal map" is fine as is,
leave it be


>
> Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
> ---
>  tools/bpf/bpftool/gen.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
> index a50540ef6521..e5e82255af24 100644
> --- a/tools/bpf/bpftool/gen.c
> +++ b/tools/bpf/bpftool/gen.c
> @@ -303,7 +303,7 @@ static int codegen_datasecs(struct bpf_object *obj, const char *obj_name)
>                 return -errno;
>
>         bpf_object__for_each_map(map, obj) {
> -               /* only generate definitions for memory-mapped internal maps */
> +               /* only generate definitions for skel data maps */
>                 if (!is_skel_data(map, map_ident, sizeof(map_ident)))
>                         continue;
>
> @@ -510,7 +510,7 @@ static size_t bpf_map_mmap_sz(const struct bpf_map *map)
>         return map_sz;
>  }
>
> -/* Emit type size asserts for all top-level fields in memory-mapped internal maps. */
> +/* Emit type size asserts for all top-level fields in skel data maps. */
>  static void codegen_asserts(struct bpf_object *obj, const char *obj_name)
>  {
>         struct btf *btf = bpf_object__btf(obj);
> --
> 2.55.0
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH bpf-next 0/5] bpf: Followups for global percpu data series
  2026-08-14 17:32 [PATCH bpf-next 0/5] bpf: Followups for global percpu data series Leon Hwang
                   ` (4 preceding siblings ...)
  2026-08-14 17:32 ` [PATCH bpf-next 5/5] selftests/bpf: Improve readability in iter " Leon Hwang
@ 2026-08-14 20:37 ` Andrii Nakryiko
  2026-08-14 20:40 ` patchwork-bot+netdevbpf
  6 siblings, 0 replies; 11+ messages in thread
From: Andrii Nakryiko @ 2026-08-14 20:37 UTC (permalink / raw)
  To: Leon Hwang
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, John Fastabend,
	Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Ihor Solodrai, Quentin Monnet, Shuah Khan,
	linux-kernel, linux-kselftest

On Fri, Aug 14, 2026 at 10:32 AM Leon Hwang <leon.hwang@linux.dev> wrote:
>
> Address some LLM reviews in
> "[PATCH bpf-next v12 00/10] bpf: Introduce global percpu data" [1].
>
> [1] https://lore.kernel.org/bpf/20260813152324.97937-1-leon.hwang@linux.dev/
>
> Leon Hwang (5):
>   bpf: Drop duplicate blank line in verifier
>   libbpf: Avoid unnecessary mmap resize for percpu data maps
>   bpftool: Update comments about skel data maps
>   selftests/bpf: Avoid flaky resize value test for percpu data
>   selftests/bpf: Improve readability in iter test for percpu data
>

applied patches 2 and 5, check AI feedback for 4, don't bother with 1 and 3.

>  kernel/bpf/verifier.c                         |  1 -
>  tools/bpf/bpftool/gen.c                       |  4 +-
>  tools/lib/bpf/libbpf.c                        | 17 ++++----
>  .../bpf/prog_tests/global_data_init.c         | 43 ++++++++++---------
>  .../bpf/progs/test_global_percpu_data.c       | 14 +++---
>  5 files changed, 41 insertions(+), 38 deletions(-)
>
> --
> 2.55.0
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH bpf-next 0/5] bpf: Followups for global percpu data series
  2026-08-14 17:32 [PATCH bpf-next 0/5] bpf: Followups for global percpu data series Leon Hwang
                   ` (5 preceding siblings ...)
  2026-08-14 20:37 ` [PATCH bpf-next 0/5] bpf: Followups for global percpu data series Andrii Nakryiko
@ 2026-08-14 20:40 ` patchwork-bot+netdevbpf
  6 siblings, 0 replies; 11+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-08-14 20:40 UTC (permalink / raw)
  To: Leon Hwang
  Cc: bpf, ast, daniel, john.fastabend, andrii, eddyz87, memxor,
	martin.lau, song, yonghong.song, jolsa, emil, ihor.solodrai, qmo,
	shuah, linux-kernel, linux-kselftest

Hello:

This series was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Sat, 15 Aug 2026 01:32:01 +0800 you wrote:
> Address some LLM reviews in
> "[PATCH bpf-next v12 00/10] bpf: Introduce global percpu data" [1].
> 
> [1] https://lore.kernel.org/bpf/20260813152324.97937-1-leon.hwang@linux.dev/
> 
> Leon Hwang (5):
>   bpf: Drop duplicate blank line in verifier
>   libbpf: Avoid unnecessary mmap resize for percpu data maps
>   bpftool: Update comments about skel data maps
>   selftests/bpf: Avoid flaky resize value test for percpu data
>   selftests/bpf: Improve readability in iter test for percpu data
> 
> [...]

Here is the summary with links:
  - [bpf-next,1/5] bpf: Drop duplicate blank line in verifier
    (no matching commit)
  - [bpf-next,2/5] libbpf: Avoid unnecessary mmap resize for percpu data maps
    https://git.kernel.org/bpf/bpf-next/c/3808171428f5
  - [bpf-next,3/5] bpftool: Update comments about skel data maps
    (no matching commit)
  - [bpf-next,4/5] selftests/bpf: Avoid flaky resize value test for percpu data
    (no matching commit)
  - [bpf-next,5/5] selftests/bpf: Improve readability in iter test for percpu data
    https://git.kernel.org/bpf/bpf-next/c/90bd0329abd4

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-08-14 20:40 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-14 17:32 [PATCH bpf-next 0/5] bpf: Followups for global percpu data series Leon Hwang
2026-08-14 17:32 ` [PATCH bpf-next 1/5] bpf: Drop duplicate blank line in verifier Leon Hwang
2026-08-14 20:32   ` Andrii Nakryiko
2026-08-14 17:32 ` [PATCH bpf-next 2/5] libbpf: Avoid unnecessary mmap resize for percpu data maps Leon Hwang
2026-08-14 17:32 ` [PATCH bpf-next 3/5] bpftool: Update comments about skel " Leon Hwang
2026-08-14 20:32   ` Andrii Nakryiko
2026-08-14 17:32 ` [PATCH bpf-next 4/5] selftests/bpf: Avoid flaky resize value test for percpu data Leon Hwang
2026-08-14 18:24   ` bot+bpf-ci
2026-08-14 17:32 ` [PATCH bpf-next 5/5] selftests/bpf: Improve readability in iter " Leon Hwang
2026-08-14 20:37 ` [PATCH bpf-next 0/5] bpf: Followups for global percpu data series Andrii Nakryiko
2026-08-14 20:40 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox