Skip to content

Commit 301b498

Browse files
chentao-kernelintel-lab-lkp
authored andcommitted
bpf/selftests: Check errno when percpu map value size exceeds
This test case checks the errno message when percpu map value size exceeds PCPU_MIN_UNIT_SIZE. root@debian:~# ./test_progs -t map_init torvalds#160/1 map_init/pcpu_map_init:OK torvalds#160/2 map_init/pcpu_lru_map_init:OK torvalds#160/3 map_init/pcpu map value size:OK torvalds#160 map_init:OK Summary: 1/3 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Tao Chen <[email protected]> Signed-off-by: jinke han <[email protected]>
1 parent 7f50b19 commit 301b498

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#define TEST_VALUE 0x1234
88
#define FILL_VALUE 0xdeadbeef
9+
#define PCPU_MIN_UNIT_SIZE 32768
910

1011
static int nr_cpus;
1112
static int duration;
@@ -118,6 +119,35 @@ static int check_values_one_cpu(pcpu_map_value_t *value, map_value_t expected)
118119

119120
return 0;
120121
}
122+
/*
123+
* percpu map value size is bound by PCPU_MIN_UNIT_SIZE
124+
* check the errno when the value exceed PCPU_MIN_UNIT_SIZE
125+
*/
126+
static void test_pcpu_map_value_size(void)
127+
{
128+
struct test_map_init *skel;
129+
int err;
130+
int value_sz = PCPU_MIN_UNIT_SIZE + 1;
131+
enum bpf_map_type map_types[] = { BPF_MAP_TYPE_PERCPU_ARRAY,
132+
BPF_MAP_TYPE_PERCPU_HASH,
133+
BPF_MAP_TYPE_LRU_PERCPU_HASH };
134+
for (int i = 0; i < ARRAY_SIZE(map_types); i++) {
135+
skel = test_map_init__open();
136+
if (!ASSERT_OK_PTR(skel, "skel_open"))
137+
return;
138+
err = bpf_map__set_type(skel->maps.hashmap2, map_types[i]);
139+
if (!ASSERT_OK(err, "bpf_map__set_type"))
140+
goto error;
141+
err = bpf_map__set_value_size(skel->maps.hashmap2, value_sz);
142+
if (!ASSERT_OK(err, "bpf_map__set_value_size"))
143+
goto error;
144+
145+
err = test_map_init__load(skel);
146+
ASSERT_EQ(err, -E2BIG, "skel_load");
147+
error:
148+
test_map_init__destroy(skel);
149+
}
150+
}
121151

122152
/* Add key=1 elem with values set for all CPUs
123153
* Delete elem key=1
@@ -211,4 +241,6 @@ void test_map_init(void)
211241
test_pcpu_map_init();
212242
if (test__start_subtest("pcpu_lru_map_init"))
213243
test_pcpu_lru_map_init();
244+
if (test__start_subtest("pcpu map value size"))
245+
test_pcpu_map_value_size();
214246
}

tools/testing/selftests/bpf/progs/test_map_init.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ struct {
1515
__type(value, __u64);
1616
} hashmap1 SEC(".maps");
1717

18+
struct {
19+
__uint(type, BPF_MAP_TYPE_HASH);
20+
__uint(max_entries, 1);
21+
__type(key, __u32);
22+
__type(value, __u64);
23+
} hashmap2 SEC(".maps");
1824

1925
SEC("tp/syscalls/sys_enter_getpgid")
2026
int sysenter_getpgid(const void *ctx)

0 commit comments

Comments
 (0)