Skip to content

Commit

Permalink
selftests/bpf: Add a selftest with > 512-byte percpu allocation size
Browse files Browse the repository at this point in the history
Add a selftest to capture the verification failure when the allocation
size is greater than 512.

Acked-by: Hou Tao <houtao1@huawei.com>
Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20231222031812.1293190-1-yonghong.song@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Yonghong Song authored and Alexei Starovoitov committed Jan 4, 2024
1 parent 21f5a80 commit adc8c45
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tools/testing/selftests/bpf/progs/percpu_alloc_fail.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ struct val_with_rb_root_t {
struct bpf_spin_lock lock;
};

struct val_600b_t {
char b[600];
};

struct elem {
long sum;
struct val_t __percpu_kptr *pc;
Expand Down Expand Up @@ -161,4 +165,18 @@ int BPF_PROG(test_array_map_7)
return 0;
}

SEC("?fentry.s/bpf_fentry_test1")
__failure __msg("bpf_percpu_obj_new type size (600) is greater than 512")
int BPF_PROG(test_array_map_8)
{
struct val_600b_t __percpu_kptr *p;

p = bpf_percpu_obj_new(struct val_600b_t);
if (!p)
return 0;

bpf_percpu_obj_drop(p);
return 0;
}

char _license[] SEC("license") = "GPL";

0 comments on commit adc8c45

Please sign in to comment.