Re: [PATCH 2/3] bpf: Allow importing device-dax pages into an arena

From: bot+bpf-ci

Date: Tue Nov 17 2026 - 06:02:36 EST


> bpf: Allow importing device-dax pages into an arena

TL;DR:
- Possible ABBA deadlock: get_online_mems() then mmap_read_lock() inverts the
order nouveau/dmirror use, so a hang looks possible
- Minor: tagged user pointers are not untagged before vma_lookup()

> diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c
> --- a/kernel/bpf/arena.c
> +++ b/kernel/bpf/arena.c

[ ... ]

> +static int arena_import_dax(struct bpf_arena *arena, long uaddr, u32 page_cnt, u64 src)
> +{

[ ... ]

> + /* A sleepable callback, like a bpf_wq one, may run without an address space */
> + if (!mm || (src & ~PAGE_MASK))
> + return -EINVAL;

[ ... ]

> + /*
> + * A pin doesn't keep the memmap of device pages: an unbind can free it
> + * until a dev_pagemap reference is held, but only under mem_hotplug_lock,
> + * which nests outside of mmap_lock
> + */
> + get_online_mems();
> + mmap_read_lock(mm);

Is the lock order stated in this comment correct? The tree also has paths
that take mem_hotplug_lock for write while holding a user mmap_read_lock:

nouveau_svmm_bind() mmap_read_lock(mm)
nouveau_dmem_migrate_vma() -> nouveau_dmem_migrate_chunk() ->
nouveau_dmem_migrate_copy_one() -> nouveau_dmem_page_alloc_locked() ->
nouveau_dmem_chunk_alloc() -> memremap_pages() -> pagemap_range() ->
mem_hotplug_begin() -> percpu_down_write(&mem_hotplug_lock)

dmirror_migrate_to_device() mmap_read_lock(mm)
dmirror_migrate_alloc_and_copy() -> dmirror_devmem_alloc_page() ->
dmirror_allocate_chunk() -> memremap_pages()

That is the opposite order from get_online_mems() followed by
mmap_read_lock(mm) here, so lockdep should report an ABBA cycle once both
chains are seen.

A hang with a single mm looks possible with three threads. T1 holds
mmap_read_lock and waits in percpu_down_write() for T2. T2, in this kfunc,
holds mem_hotplug_lock for read and calls mmap_read_lock(mm). T3 waits in
mmap_write_lock() on T1's read hold, and once it sets the rwsem handoff flag
T2 can no longer take the read lock and queues behind T3. No thread can
make progress.

The x86 ptdump debugfs path already uses the same order as this patch, so
the inversion is not new, but this kfunc makes it reachable from a much more
common path.

Could the dev_pagemap reference be taken without holding mem_hotplug_lock
across mmap_lock, for example by taking the dev_dax pgmap from the VMA's
file before pinning?

> + vma = vma_lookup(mm, src);

A subsystem pattern flags this as potentially concerning: src is a
user-supplied u64 that goes to vma_lookup() and to the vma->vm_end - src
range check without untagged_addr(), and the only earlier test is
(src & ~PAGE_MASK). A tagged pointer (arm64 TBI/MTE, x86 LAM) is above every
VMA, so vma_lookup() returns NULL and the import fails with -EINVAL, while
pin_user_pages() would have accepted the same address because
__get_user_pages() untags it.

This fails closed, so the checked VMA and the pinned range cannot diverge,
and addresses returned by mmap() of /dev/daxX.Y are untagged. Should this
use untagged_addr(src) on a copy before vma_lookup() and the range check, or
should the kdoc say that @src must be untagged?

> + if (!vma || !vma_is_devdax(vma) ||
> + ((unsigned long)page_cnt << PAGE_SHIFT) > vma->vm_end - src)
> + goto out_unlock;

[ ... ]


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/44067070819