]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
bpf: Plumb get_unmapped_area() callback into bpf_map_ops
authorAlexei Starovoitov <ast@kernel.org>
Thu, 7 Mar 2024 03:12:25 +0000 (19:12 -0800)
committerMartin KaFai Lau <martin.lau@kernel.org>
Thu, 7 Mar 2024 22:58:48 +0000 (14:58 -0800)
Subsequent patches introduce bpf_arena that imposes special alignment
requirements on address selection.

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

index 785660810e6a7aeb3dec146b7e76698d2316d186..95e07673cdc1a07ed177b718341765646d162dd1 100644 (file)
@@ -139,6 +139,9 @@ struct bpf_map_ops {
        int (*map_mmap)(struct bpf_map *map, struct vm_area_struct *vma);
        __poll_t (*map_poll)(struct bpf_map *map, struct file *filp,
                             struct poll_table_struct *pts);
+       unsigned long (*map_get_unmapped_area)(struct file *filep, unsigned long addr,
+                                              unsigned long len, unsigned long pgoff,
+                                              unsigned long flags);
 
        /* Functions called by bpf_local_storage maps */
        int (*map_local_storage_charge)(struct bpf_local_storage_map *smap,
index b2750b79ac8050c448533a23aed14a9c2aa1939b..f63f4da4db5ea15e830fb8c56fb7ddb134a10251 100644 (file)
@@ -937,6 +937,21 @@ static __poll_t bpf_map_poll(struct file *filp, struct poll_table_struct *pts)
        return EPOLLERR;
 }
 
+static unsigned long bpf_get_unmapped_area(struct file *filp, unsigned long addr,
+                                          unsigned long len, unsigned long pgoff,
+                                          unsigned long flags)
+{
+       struct bpf_map *map = filp->private_data;
+
+       if (map->ops->map_get_unmapped_area)
+               return map->ops->map_get_unmapped_area(filp, addr, len, pgoff, flags);
+#ifdef CONFIG_MMU
+       return current->mm->get_unmapped_area(filp, addr, len, pgoff, flags);
+#else
+       return addr;
+#endif
+}
+
 const struct file_operations bpf_map_fops = {
 #ifdef CONFIG_PROC_FS
        .show_fdinfo    = bpf_map_show_fdinfo,
@@ -946,6 +961,7 @@ const struct file_operations bpf_map_fops = {
        .write          = bpf_dummy_write,
        .mmap           = bpf_map_mmap,
        .poll           = bpf_map_poll,
+       .get_unmapped_area = bpf_get_unmapped_area,
 };
 
 int bpf_map_new_fd(struct bpf_map *map, int flags)