Andrii Nakryiko
0b23e4c575
BACKPORT: bpf: Add mmap() support for BPF_MAP_TYPE_ARRAY
...
Add ability to memory-map contents of BPF array map. This is extremely useful
for working with BPF global data from userspace programs. It allows to avoid
typical bpf_map_{lookup,update}_elem operations, improving both performance
and usability.
There had to be special considerations for map freezing, to avoid having
writable memory view into a frozen map. To solve this issue, map freezing and
mmap-ing is happening under mutex now:
- if map is already frozen, no writable mapping is allowed;
- if map has writable memory mappings active (accounted in map->writecnt),
map freezing will keep failing with -EBUSY;
- once number of writable memory mappings drops to zero, map freezing can be
performed again.
Only non-per-CPU plain arrays are supported right now. Maps with spinlocks
can't be memory mapped either.
For BPF_F_MMAPABLE array, memory allocation has to be done through vmalloc()
to be mmap()'able. We also need to make sure that array data memory is
page-sized and page-aligned, so we over-allocate memory in such a way that
struct bpf_array is at the end of a single page of memory with array->value
being aligned with the start of the second page. On deallocation we need to
accomodate this memory arrangement to free vmalloc()'ed memory correctly.
One important consideration regarding how memory-mapping subsystem functions.
Memory-mapping subsystem provides few optional callbacks, among them open()
and close(). close() is called for each memory region that is unmapped, so
that users can decrease their reference counters and free up resources, if
necessary. open() is *almost* symmetrical: it's called for each memory region
that is being mapped, **except** the very first one. So bpf_map_mmap does
initial refcnt bump, while open() will do any extra ones after that. Thus
number of close() calls is equal to number of open() calls plus one more.
Change-Id: Iec61232f89b9cdf29587eb265a61730d6f4925e1
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Song Liu <songliubraving@fb.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Link: https://lore.kernel.org/bpf/20191117172806.2195367-4-andriin@fb.com
2025-12-23 13:35:42 -08:00
..
kasan
Merge android11-5.4.233+ ( 4716ccc) into msm-5.4
2023-05-30 11:16:10 +05:30
backing-dev.c
mm: bdi: initialize bdi_min_ratio when bdi is unregistered
2021-12-14 14:49:00 +01:00
balloon_compaction.c
cleancache.c
cma.c
Merge android11-5.4.265+ ( a34cc1d) into msm-5.4
2024-02-29 15:10:56 +05:30
cma.h
cma_debug.c
compaction.c
Merge tag 'ASB-2024-06-05_11-5.4' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina
2024-06-22 17:58:09 +03:00
debug.c
debug_page_ref.c
dmapool.c
early_ioremap.c
fadvise.c
failslab.c
filemap.c
Merge tag 'ASB-2025-10-06_11-5.4' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina
2025-10-08 15:17:54 +03:00
frame_vector.c
v4l2: don't fall back to follow_pfn() if pin_user_pages_fast() fails
2022-12-08 11:23:06 +01:00
frontswap.c
treewide: Remove uninitialized_var() usage
2023-06-09 10:29:01 +02:00
gup.c
BACKPORT: mm/gup: Remove enfornced COW mechanism
2025-05-18 08:08:42 +00:00
gup_benchmark.c
highmem.c
hmm.c
mm/hmm: move pmd_to_hmm_pfn_flags() to the respective #ifdeffery
2025-08-28 16:21:34 +02:00
huge_memory.c
Merge tag 'ASB-2025-08-05_11-5.4' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina
2025-09-01 13:17:46 +03:00
hugetlb.c
Merge tag 'ASB-2025-12-01_11-5.4' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina
2025-12-04 19:21:35 +02:00
hugetlb_cgroup.c
hwpoison-inject.c
init-mm.c
Revert "mm: protect mm_rb tree with a rwlock"
2025-05-24 05:44:05 +00:00
internal.h
Revert "mm: protect mm_rb tree with a rwlock"
2025-05-24 05:44:05 +00:00
interval_tree.c
Kconfig
Revert "mm: introduce CONFIG_SPECULATIVE_PAGE_FAULT"
2025-05-24 05:44:57 +00:00
Kconfig.debug
khugepaged.c
mm/khugepaged: fix the address passed to notifier on testing young
2025-10-02 13:34:28 +02:00
kmemleak-test.c
kmemleak.c
mm/kmemleak: avoid deadlock by moving pr_warn() outside kmemleak_lock
2025-08-28 16:21:34 +02:00
ksm.c
Merge android11-5.4.249+ ( d57e792) into msm-5.4
2023-09-28 16:45:28 +05:30
list_lru.c
maccess.c
UPSTREAM: uaccess: Add strict non-pagefault kernel-space read function
2025-12-23 13:35:39 -08:00
madvise.c
Merge tag 'ASB-2025-10-06_11-5.4' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina
2025-10-08 15:17:54 +03:00
Makefile
Merge tag 'ASB-2024-05-05_11-5.4' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina
2024-05-07 20:29:15 +03:00
memblock.c
This is the 5.4.232 stable release
2023-02-22 12:30:48 +00:00
memcontrol.c
memcg: always call cond_resched() after fn()
2025-06-04 14:32:35 +02:00
memfd.c
memfd: fix F_SEAL_WRITE after shmem huge page allocated
2022-03-08 19:07:49 +01:00
memory-failure.c
Merge branch 'android11-5.4-lts' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina
2025-10-08 15:23:13 +03:00
memory.c
Revert "mm: prepare for FAULT_FLAG_SPECULATIVE"
2025-05-24 05:44:31 +00:00
memory_hotplug.c
Merge android11-5.4.161+ ( b9d179c) into msm-5.4
2022-02-07 22:29:21 +05:30
mempolicy.c
Revert "mm: protect VMA modifications using VMA sequence count"
2025-05-24 05:44:09 +00:00
mempool.c
memremap.c
memtest.c
memtest: use {READ,WRITE}_ONCE in memory scanning
2024-04-13 12:51:27 +02:00
migrate.c
Merge branch 'android11-5.4-lts' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina
2025-10-08 15:23:13 +03:00
mincore.c
mlock.c
Revert "mm: protect VMA modifications using VMA sequence count"
2025-05-24 05:44:09 +00:00
mm_init.c
mmap.c
This is the 5.4.297 stable release
2025-09-02 10:52:40 +00:00
mmu_context.c
mmu_gather.c
mm/khugepaged: fix GUP-fast interaction by sending IPI
2022-12-14 11:30:42 +01:00
mmu_notifier.c
mmzone.c
arm: remove CONFIG_ARCH_HAS_HOLES_MEMORYMODEL
2022-05-15 19:54:46 +02:00
mprotect.c
Revert "mm: protect VMA modifications using VMA sequence count"
2025-05-24 05:44:09 +00:00
mremap.c
Revert "mm: protect mremap() against SPF hanlder"
2025-05-24 05:44:08 +00:00
msync.c
nommu.c
oom_kill.c
Merge tag 'ASB-2025-05-05_11-5.4' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina
2025-05-18 08:00:20 +00:00
OWNERS
page-writeback.c
mm: fix ratelimit_pages update error in dirty_ratio_handler()
2025-06-27 11:02:52 +01:00
page_alloc.c
Merge branch 'android11-5.4-lts' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina
2025-12-11 01:41:51 -08:00
page_counter.c
page_ext.c
page_idle.c
BACKPORT: mm: don't be stuck to rmap lock on reclaim path
2023-01-13 08:56:32 +00:00
page_io.c
Merge android11-5.4.197+ ( 3970bc6) into msm-5.4
2022-08-16 16:52:01 +05:30
page_isolation.c
page_owner.c
mm: page_owner: Fix -Wstrlcpy-strlcat-size
2025-04-26 21:17:21 +03:00
page_poison.c
page_vma_mapped.c
pagewalk.c
mm: pagewalk: Fix race between unmap and page walker
2022-10-15 07:54:36 +02:00
percpu-internal.h
percpu-km.c
percpu-stats.c
percpu-vm.c
percpu.c
treewide: Remove uninitialized_var() usage
2023-06-09 10:29:01 +02:00
pgsize_migration.c
ANDROID: 16K: Allocate pad vma on the stack
2025-08-22 07:07:13 -07:00
pgtable-generic.c
process_vm_access.c
readahead.c
vfs: fix readahead(2) on block devices
2023-11-20 10:30:08 +01:00
rmap.c
Revert "mm: introduce __page_add_new_anon_rmap()"
2025-05-24 05:44:06 +00:00
rodata_test.c
shmem.c
Merge tag 'ASB-2025-10-06_11-5.4' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina
2025-10-08 15:17:54 +03:00
showmem.c
shuffle.c
shuffle.h
slab.c
slab.h
mm: kmemleak: slob: respect SLAB_NOLEAKTRACE flag
2021-11-26 10:47:21 +01:00
slab_common.c
Merge tag 'ASB-2024-12-05_11-5.4' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina
2024-12-17 03:24:53 +02:00
slob.c
slub.c
Merge tag 'ASB-2025-10-06_11-5.4' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina
2025-10-08 15:17:54 +03:00
sparse-vmemmap.c
sparse.c
swap.c
Revert "mm: introduce __lru_cache_add_active_or_unevictable"
2025-05-24 05:44:06 +00:00
swap_cgroup.c
swap_slots.c
swap_state.c
Revert "mm: protect VMA modifications using VMA sequence count"
2025-05-24 05:44:09 +00:00
swapfile.c
This is the 5.4.285 stable release
2024-11-09 11:29:17 +00:00
truncate.c
usercopy.c
Merge android11-5.4.191+ ( 375c2e2) into msm-5.4
2022-06-09 11:43:23 +05:30
userfaultfd.c
UPSTREAM: mm/shmem: use page_mapping() to detect page cache for uffd continue
2025-05-18 08:08:42 +00:00
util.c
mm: only enforce minimum stack gap size if it's sensible
2024-11-08 16:20:35 +01:00
vmacache.c
vmalloc.c
BACKPORT: bpf: Add mmap() support for BPF_MAP_TYPE_ARRAY
2025-12-23 13:35:42 -08:00
vmpressure.c
vmscan.c
Merge tag 'ASB-2025-06-05_11-5.4' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina
2025-06-30 10:49:17 +03:00
vmstat.c
Revert "mm: add speculative page fault vmstats"
2025-05-24 05:44:04 +00:00
workingset.c
z3fold.c
zbud.c
zpool.c
zsmalloc.c
Merge tag 'ASB-2025-10-06_11-5.4' of https://android.googlesource.com/kernel/common into android13-5.4-lahaina
2025-10-08 15:17:54 +03:00
zswap.c