]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
bpf: Tell bpf programs kernel's PAGE_SIZE
authorAlexei Starovoitov <ast@kernel.org>
Thu, 7 Mar 2024 03:12:28 +0000 (19:12 -0800)
committerMartin KaFai Lau <martin.lau@kernel.org>
Thu, 7 Mar 2024 22:58:48 +0000 (14:58 -0800)
vmlinux BTF includes all kernel enums.
Add __PAGE_SIZE = PAGE_SIZE enum, so that bpf programs
that include vmlinux.h can easily access it.

Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/r/20240307031228.42896-7-alexei.starovoitov@gmail.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
kernel/bpf/core.c

index 9ee4536d0a09c49db90571d29beadd40ed73ba9a..134b7979f5376455e0ebeb14dac0654ef117930e 100644 (file)
@@ -88,13 +88,18 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns
        return NULL;
 }
 
+/* tell bpf programs that include vmlinux.h kernel's PAGE_SIZE */
+enum page_size_enum {
+       __PAGE_SIZE = PAGE_SIZE
+};
+
 struct bpf_prog *bpf_prog_alloc_no_stats(unsigned int size, gfp_t gfp_extra_flags)
 {
        gfp_t gfp_flags = bpf_memcg_flags(GFP_KERNEL | __GFP_ZERO | gfp_extra_flags);
        struct bpf_prog_aux *aux;
        struct bpf_prog *fp;
 
-       size = round_up(size, PAGE_SIZE);
+       size = round_up(size, __PAGE_SIZE);
        fp = __vmalloc(size, gfp_flags);
        if (fp == NULL)
                return NULL;