From: Jingyi Sun <1045704958@qq.com>
To: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Mike Rapoport <rppt@kernel.org>, Peter Xu <peterx@redhat.com>
Cc: Dan Williams <djbw@kernel.org>,
Matthew Wilcox <willy@infradead.org>, Jan Kara <jack@suse.cz>,
Alistair Popple <apopple@nvidia.com>,
linux-mm@kvack.org, nvdimm@lists.linux.dev,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [BUG] mm: uffd-wp marker on a DAX file mapping: SIGBUS on write, endless refaults on read
Date: Tue, 17 Nov 2026 20:17:11 +0800 [thread overview]
Message-ID: <tencent_1874C71D4177A1624528043E008DB1A5EF05@qq.com> (raw)
Hi,
On a DAX-mounted file, a uffd-wp PTE marker installed with
UFFD_FEATURE_WP_ASYNC is treated as an already-mapped page when the
page is later faulted in, which makes writes fail with SIGBUS and
reads refault forever.
Path (v7.3-rc2, unchanged in v7.4-rc3 and mm-unstable):
handle_pte_marker()
pte_marker_handle_uffd_wp()
do_pte_missing()
ext4_dax_huge_fault() -> dax_iomap_fault() -> dax_fault_iter()
vmf_insert_page_mkwrite()
insert_page_into_pte_locked()
insert_page_into_pte_locked() only checks !pte_none(pteval) to decide
that something is already mapped. The uffd-wp marker is non-present
but not none, so:
- write fault (mkwrite == true): pte_pfn() is called on the marker,
which does not hold a PFN; the comparison with page_to_pfn(page)
fails, WARN_ON_ONCE(!is_zero_pfn(...)) fires and -EFAULT is
returned, so the task gets SIGBUS;
- read fault (mkwrite == false): -EBUSY is returned, which becomes
VM_FAULT_NOPAGE, the marker is never replaced and the task refaults
on the same address forever (about 3.5 million faults in 20s in our
test). The task stays killable.
vma_can_userfault() allows any memory type when only WP is requested
together with UFFD_FEATURE_WP_ASYNC, so DAX VMAs can get these markers.
Programs using async uffd-wp for dirty tracking (e.g. with
PAGEMAP_SCAN) on DAX files are therefore killed or stuck.
Reproducer (x86_64 in QEMU, v7.3-rc2, memmap=256M!512M as /dev/pmem0,
ext4 mounted with -o dax=always):
1. create and fsync a file on the DAX mount (some pages written, one
page left as a hole by ftruncate);
2. mmap() it MAP_SHARED, PROT_READ|PROT_WRITE, without touching the
pages;
3. userfaultfd with UFFD_FEATURE_WP_ASYNC, UFFDIO_REGISTER with
UFFDIO_REGISTER_MODE_WP over the mapping, then UFFDIO_WRITEPROTECT
(MODE_WP) over the whole range; /proc/self/pagemap now shows
uffd-wp=1, present=0 for the pages;
4. write to a page: WARNING at mm/memory.c:2495 and SIGBUS (3/3 runs,
both for an allocated block and for the hole);
read from a page: the task never returns from the fault (3/3).
Controls behave normally on the same kernel: the same steps on DAX
without userfaultfd, and with userfaultfd on shmem instead of DAX.
As an attribution experiment only, treating a non-present PTE as none
in insert_page_into_pte_locked() makes both symptoms go away, but that
drops the write-protect state, so it is not a proposed fix. A proper
fix probably either installs the page while keeping the uffd-wp bit
(pte_mkuffd_wp()) when replacing a uffd-wp marker in the DAX insert
paths, or refuses uffd-wp on DAX VMAs in vma_can_userfault(). The
same !pte_none() pattern exists in insert_pfn() and in the PMD-level
insert path; those were not tested.
A similar present check was proposed in "mm: compare pfns only if the
entry is present when inserting pfns/pages" (RFC, June 2025), which
described the pte_pfn() on a non-present entry as not expected to cause
harm in practice; that hunk is not in mainline. The reproducer above
shows a user-visible effect. Note that returning -EBUSY for a
non-present entry alone would only turn the SIGBUS into the same
endless refault as in the read case.
Link: https://lore.kernel.org/all/20250617154345.2494405-4-david@redhat.com/
The issue was found with a research static analyzer for
cross-architecture dependency bugs (it flags calls to helpers such as
pte_pfn() that are only defined for present entries) and confirmed
with the QEMU reproducer above. I can share the full reproducer
program.
Thanks,
Jingyi Sun
reply other threads:[~2026-11-17 12:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=tencent_1874C71D4177A1624528043E008DB1A5EF05@qq.com \
--to=1045704958@qq.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=david@kernel.org \
--cc=djbw@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nvdimm@lists.linux.dev \
--cc=peterx@redhat.com \
--cc=rppt@kernel.org \
--cc=willy@infradead.org \
/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®