Skip to content

Commit cf2c2e4

Browse files
Alexei StarovoitovMartin KaFai Lau
authored andcommitted
bpf: Plumb get_unmapped_area() callback into bpf_map_ops
Subsequent patches introduce bpf_arena that imposes special alignment requirements on address selection. Acked-by: Kumar Kartikeya Dwivedi <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin KaFai Lau <[email protected]>
1 parent 8d94f13 commit cf2c2e4

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/linux/bpf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ struct bpf_map_ops {
139139
int (*map_mmap)(struct bpf_map *map, struct vm_area_struct *vma);
140140
__poll_t (*map_poll)(struct bpf_map *map, struct file *filp,
141141
struct poll_table_struct *pts);
142+
unsigned long (*map_get_unmapped_area)(struct file *filep, unsigned long addr,
143+
unsigned long len, unsigned long pgoff,
144+
unsigned long flags);
142145

143146
/* Functions called by bpf_local_storage maps */
144147
int (*map_local_storage_charge)(struct bpf_local_storage_map *smap,

kernel/bpf/syscall.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,21 @@ static __poll_t bpf_map_poll(struct file *filp, struct poll_table_struct *pts)
937937
return EPOLLERR;
938938
}
939939

940+
static unsigned long bpf_get_unmapped_area(struct file *filp, unsigned long addr,
941+
unsigned long len, unsigned long pgoff,
942+
unsigned long flags)
943+
{
944+
struct bpf_map *map = filp->private_data;
945+
946+
if (map->ops->map_get_unmapped_area)
947+
return map->ops->map_get_unmapped_area(filp, addr, len, pgoff, flags);
948+
#ifdef CONFIG_MMU
949+
return current->mm->get_unmapped_area(filp, addr, len, pgoff, flags);
950+
#else
951+
return addr;
952+
#endif
953+
}
954+
940955
const struct file_operations bpf_map_fops = {
941956
#ifdef CONFIG_PROC_FS
942957
.show_fdinfo = bpf_map_show_fdinfo,
@@ -946,6 +961,7 @@ const struct file_operations bpf_map_fops = {
946961
.write = bpf_dummy_write,
947962
.mmap = bpf_map_mmap,
948963
.poll = bpf_map_poll,
964+
.get_unmapped_area = bpf_get_unmapped_area,
949965
};
950966

951967
int bpf_map_new_fd(struct bpf_map *map, int flags)

0 commit comments

Comments
 (0)