From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=203.205.221.153 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794917849; b=H6p4FRKejqQy2HQJ1APVS3SiGwRCxrv4bsyWo4T8vmv+FcBjXbuFbBoFjhy1PNtT4AqH vPfJja6MSEs/uQAvmu3x53hL/nioVIhG0iYDpSDGZD+/BOQneCOpyeEp7AKFTAzGHUnXU 6NvCQOjwx3aHQxWUDs9fuddaj7C89DAUKtGAdyv43sW7zITxHSx3UI8wlvPnIUQNK9X4v fec++Anc1xb66QfaovkimuOztmYLosZNixBSkXHiQaLXDKYMlmu69GpsjB7Oyu+Y32stT dVuXqEHCwFOhrwK74MRYdOxGjVZKQLxRuM+JHcLmqOLWvO8ju8hyBHg9NUD+sXd2YbA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794917849; h=DMARC-Filter:DKIM-Signature:Received:X-QQ-mid:Message-ID: X-QQ-XMAILINFO:X-QQ-XMRINFO:From:To:Cc:Subject:Date:X-OQ-MSGID: X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=AXXxMPEgt9eEKJpgwYhNgOqc1sWnNe7LivV80ncHudk=; b=Iz5+/H56BpZZRz9DJcQwvn3qQuYAmYZV7SE2G4dgeQSv4tbBzn4toxrevodgkaQPauQn GJyIwAwt+m2nKDObxo9mXGdfabvmtNpnpNimaG06NusY9nww3TkkZvB/wi8Z6hsWSDqZK cV9l7iXIucGbP5+tuSOf4k+6wZfsM5rB6Cp+39PDERXVYHdtJxXM03D1XFVExkDQJrEll UuegIaGzINFNsGTNngphjjxbzSQClaCNZWoFkwpk6G6axksp3K3InXWeP6ken3/+WI4ZK GeONyfdeWu24AuSuW2rveVK8/oJuoY74JEgqxoYZaxCI5gMlQNcanzqtFkSA5qXgIlQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=qq.com; spf=pass smtp.mailfrom=qq.com; dkim=pass header.d=qq.com header.i=@qq.com header.a=rsa-sha256 header.s=s201512 header.b=BEJ1Gyie; arc=none smtp.remote-ip=203.205.221.153 Received: from out203-205-221-153.mail.qq.com (out203-205-221-153.mail.qq.com [203.205.221.153]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 552F3606A335; Tue, 17 Nov 2026 12:17:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 552F3606A335 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qq.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.a=rsa-sha256 header.s=s201512 header.b=BEJ1Gyie DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1794917839; bh=AXXxMPEgt9eEKJpgwYhNgOqc1sWnNe7LivV80ncHudk=; h=From:To:Cc:Subject:Date; b=BEJ1Gyieg1w+Ffqka4yDC1j4x+ap2Fe7avg0rYAIIEGN3ZdM/xAXjm2WDNXiukfwt iqdhdaG9ywvkL5FAQWd2VlniDn/VH1iNAWpmQYQdE1WprQhik2RmetyrDsCw+dOUd2 R9X28WQ/gPi2ghHHuruW7rUkJXD991p7DEtAxNg0= Received: from DESKTOP-6LNKCJL.localdomain ([114.245.39.251]) by newxmesmtplogicsvrszb51-1.qq.com (NewEsmtp) with SMTP id 44B0D697; Tue, 17 Nov 2026 20:17:11 +0800 X-QQ-mid: xmsmtpt1794917831tpiumovc5 Message-ID: X-QQ-XMAILINFO: NnYhxYSyuBnLvq4fxmrGrK5xu0mwsez5ZuhTDd2o4ZBNgLhhOOzPQ5wyJ55GxV A8vIc3TP23UGZc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Q== X-QQ-XMRINFO: OWPUhxQsoeAVwkVaQIEGSKwwgKCxK/fD5g== From: Jingyi Sun <1045704958@qq.com> To: Andrew Morton , David Hildenbrand , Mike Rapoport , Peter Xu Cc: Dan Williams , Matthew Wilcox , Jan Kara , Alistair Popple , 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 X-OQ-MSGID: <20261117121711.1088-1-1045704958@qq.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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