From: bot+bpf-ci@kernel.org
To: arighi@nvidia.com,ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,eddyz87@gmail.com,memxor@gmail.com
Cc: martin.lau@linux.dev,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,ihor.solodrai@linux.dev,john.fastabend@gmail.com,tj@kernel.org,void@manifault.com,changwoo@igalia.com,joshdon@google.com,vineethrp@google.com,yepeilin@google.com,zhiw@nvidia.com,ltrager@nvidia.com,balbirs@nvidia.com,skolothumtho@nvidia.com,himadrics@protonmail.com,royfru44@gmail.com,bpf@vger.kernel.org,sched-ext@lists.linux.dev,linux-kernel@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH 2/3] bpf: Allow importing device-dax pages into an arena
Date: Tue, 17 Nov 2026 11:02:25 +0000 (UTC) [thread overview]
Message-ID: <0e602faa04ade005445a5dba3c1cebb690e5daefa30f24b07a12a3bbcff6ab61@mail.kernel.org> (raw)
In-Reply-To: <20261117103028.4105609-3-arighi@nvidia.com>
[-- Attachment #1: Type: text/plain, Size: 3563 bytes --]
> 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
next prev parent reply other threads:[~2026-11-17 11:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 10:28 [PATCH v2 bpf-next 0/3] bpf: Import external " Andrea Righi
2026-11-17 10:28 ` [PATCH 1/3] bpf: Allow importing memfd " Andrea Righi
2026-11-17 11:14 ` bot+bpf-ci
2026-11-17 10:28 ` [PATCH 2/3] bpf: Allow importing device-dax " Andrea Righi
2026-11-17 11:02 ` bot+bpf-ci [this message]
2026-11-17 10:28 ` [PATCH 3/3] selftests/bpf: Test importing " Andrea Righi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0e602faa04ade005445a5dba3c1cebb690e5daefa30f24b07a12a3bbcff6ab61@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=andrii@kernel.org \
--cc=arighi@nvidia.com \
--cc=ast@kernel.org \
--cc=balbirs@nvidia.com \
--cc=bpf@vger.kernel.org \
--cc=changwoo@igalia.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=himadrics@protonmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=joshdon@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ltrager@nvidia.com \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=mason@kernel.org \
--cc=memxor@gmail.com \
--cc=royfru44@gmail.com \
--cc=sched-ext@lists.linux.dev \
--cc=skolothumtho@nvidia.com \
--cc=song@kernel.org \
--cc=tj@kernel.org \
--cc=vineethrp@google.com \
--cc=void@manifault.com \
--cc=yepeilin@google.com \
--cc=yonghong.song@linux.dev \
--cc=zhiw@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®