Skip to content

Commit 495b883

Browse files
Yonghong SongKernel Patches Daemon
authored andcommitted
selftests/bpf: Fix task_local_data failure with 64K page
On arm64 systems with 64K pages, the selftest task_local_data has the following failures: ... test_task_local_data_basic:PASS:tld_create_key 0 nsec test_task_local_data_basic:FAIL:tld_create_key unexpected tld_create_key: actual 0 != expected -28 ... test_task_local_data_basic_thread:PASS:run task_main 0 nsec test_task_local_data_basic_thread:FAIL:task_main retval unexpected error: 2 (errno 0) test_task_local_data_basic_thread:FAIL:tld_get_data value0 unexpected tld_get_data value0: actual 0 != expected 6268 ... #447/1 task_local_data/task_local_data_basic:FAIL ... #447/2 task_local_data/task_local_data_race:FAIL #447 task_local_data:FAIL When TLD_DYN_DATA_SIZE is 64K page size, for struct tld_meta_u { _Atomic __u8 cnt; __u16 size; struct tld_metadata metadata[]; }; field 'cnt' would overflow. For example, for 4K page, 'cnt' will be 4096/64 = 64. But for 64K page, 'cnt' will be 65536/64 = 1024 and 'cnt' is not enough for 1024. To accommodate 64K page, '_Atomic __u8 cnt' becomes '_Atomic __u16 cnt'. A few other places are adjusted accordingly. In test_task_local_data.c, the value for TLD_DYN_DATA_SIZE is changed from 4096 to (getpagesize() - 8) since the maximum buffer size for TLD_DYN_DATA_SIZE is (getpagesize() - 8). Reviewed-by: Alan Maguire <alan.maguire@oracle.com> Tested-by: Alan Maguire <alan.maguire@oracle.com> Cc: Amery Hung <ameryhung@gmail.com> Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
1 parent 403c46b commit 495b883

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

tools/testing/selftests/bpf/prog_tests/task_local_data.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct tld_metadata {
9494
};
9595

9696
struct tld_meta_u {
97-
_Atomic __u8 cnt;
97+
_Atomic __u16 cnt;
9898
__u16 size;
9999
struct tld_metadata metadata[];
100100
};
@@ -217,7 +217,7 @@ static int __tld_init_data_p(int map_fd)
217217
static tld_key_t __tld_create_key(const char *name, size_t size, bool dyn_data)
218218
{
219219
int err, i, sz, off = 0;
220-
__u8 cnt;
220+
__u16 cnt;
221221

222222
if (!TLD_READ_ONCE(tld_meta_p)) {
223223
err = __tld_init_meta_p();

tools/testing/selftests/bpf/prog_tests/test_task_local_data.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <test_progs.h>
55

66
#define TLD_FREE_DATA_ON_THREAD_EXIT
7-
#define TLD_DYN_DATA_SIZE 4096
7+
#define TLD_DYN_DATA_SIZE (getpagesize() - 8)
88
#include "task_local_data.h"
99

1010
struct test_tld_struct {

tools/testing/selftests/bpf/progs/task_local_data.bpf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct tld_metadata {
8080
};
8181

8282
struct tld_meta_u {
83-
__u8 cnt;
83+
__u16 cnt;
8484
__u16 size;
8585
struct tld_metadata metadata[TLD_MAX_DATA_CNT];
8686
};

0 commit comments

Comments
 (0)