From: sashiko-bot@kernel.org
To: "Qiliang Yuan" <qiliang.yuan@linux.dev>
Cc: dri-devel@lists.freedesktop.org, media-ci@linuxtv.org
Subject: Re: [PATCH v4 2/3] udmabuf: map huge page backed ranges with PMDs
Date: Sat, 05 Dec 2026 15:37:07 +0000 [thread overview]
Message-ID: <sashiko-outbox-251704@kernel.org> (raw)
In-Reply-To: <20261205-feat-udmabuf-huge-pfnmap-v4-2-c1e1a1d22e27@linux.dev>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] udmabuf: race between udmabuf_vm_huge_fault() and
udmabuf_vm_fault()
- [Low] udmabuf: unsigned wraparound in udmabuf_vm_fault() skips
pre-faulting
--
commit 39a38238540cdafe30119c4f3ab3970a3e452b5b
Author: Qiliang Yuan <qiliang.yuan@linux.dev>
udmabuf: map huge page backed ranges with PMDs
This commit adds a ->huge_fault() handler to udmabuf to map aligned,
contiguous PMD-sized PFN ranges with PMDs, and limits pre-faulting in
udmabuf_vm_fault() to the faulting PMD range.
> diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
> index 018937435356e..60b16f8cd266f 100644
> --- a/drivers/dma-buf/udmabuf.c
> +++ b/drivers/dma-buf/udmabuf.c
[ ... ]
> +static vm_fault_t udmabuf_vm_huge_fault(struct vm_fault *vmf,
> + unsigned int order)
> +{
> + unsigned long pfn;
> +
> + if (order != PMD_ORDER ||
> + !udmabuf_pmd_mappable(vmf->vma, vmf->address & PMD_MASK, &pfn))
> + return VM_FAULT_FALLBACK;
> +
> + return vmf_insert_pfn_pmd(vmf, pfn, vmf->flags & FAULT_FLAG_WRITE);
> +}
> +#endif
[Severity: High]
Can udmabuf_vm_huge_fault() race with udmabuf_vm_fault() on the same PMD
entry in this tree?
The prerequisite mm series ("mm: fix races between huge and non-huge faults
in PFN mappings") is not present in this tree, and udmabuf does not
serialize huge faults against PTE faults. create_huge_pmd() calls
udmabuf_vm_huge_fault() under FAULT_FLAG_VMA_LOCK without calling
vmf_can_call_fault(), while prctl_set_thp_disable() only takes
mmap_write_lock without vma_start_write():
CPU0 CPU1
handle_mm_fault() [VMA read lock]
create_huge_pmd()
udmabuf_vm_huge_fault()
udmabuf_pmd_mappable()
prctl_set_thp_disable()
set MMF_DISABLE_THP_COMPLETELY
handle_mm_fault()
udmabuf_vm_fault()
vmf_insert_pfn_pmd()
insert_pmd() [installs PMD]
vmf_insert_pfn()
walk_to_pmd() <-- VM_BUG_ON
If udmabuf_vm_huge_fault() installs the huge PMD first, udmabuf_vm_fault()
-> insert_pfn() -> walk_to_pmd() hits VM_BUG_ON(pmd_trans_huge(*pmd)) when
CONFIG_DEBUG_VM is enabled, or __pte_offset_map() returns NULL and
insert_pfn() returns a spurious VM_FAULT_OOM when CONFIG_DEBUG_VM is
disabled.
If udmabuf_vm_fault() installs a PTE page table first during a write fault,
insert_pmd() sees !pmd_none(*pmd) without checking pmd_trans_huge(*pmd),
triggers WARN_ON_ONCE(!is_huge_zero_pmd(*pmd)), and returns VM_FAULT_NOPAGE
instead of VM_FAULT_FALLBACK.
Merging this patch ahead of the prerequisite mm series exposes these
crashes and warnings unless the mm fixes land first or udmabuf serializes
huge and PTE faults.
[ ... ]
> @@ -61,11 +113,17 @@ static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf)
> if (ret & VM_FAULT_ERROR)
> return ret;
>
> - /* pre fault */
> - pgoff = vma->vm_pgoff;
> - addr = vma->vm_start;
> + /*
> + * Pre-fault the rest of the PMD-sized range of the fault. Staying
> + * within its page table keeps the walk off the ranges that
> + * udmabuf_vm_huge_fault() maps with a PMD.
> + */
> + addr = vmf->address & PMD_MASK;
> + end = min(vma->vm_end, addr + PMD_SIZE);
> + addr = max(vma->vm_start, addr);
> + pgoff = linear_page_index(vma, addr);
>
> - for (; addr < vma->vm_end; pgoff++, addr += PAGE_SIZE) {
> + for (; addr < end; pgoff++, addr += PAGE_SIZE) {
[Severity: Low]
Can addr + PMD_SIZE wrap around to 0 when the faulting address is in the
topmost PMD slot?
On architectures where user TASK_SIZE extends into the final PMD window
(such as 64-bit s390 with TASK_SIZE_MAX = -PAGE_SIZE or 32-bit PA-RISC),
a fault in [PMD_MASK, TASK_SIZE) sets addr to PMD_MASK, so addr + PMD_SIZE
overflows to 0. end then evaluates to 0 and the pre-fault loop runs zero
iterations, silently skipping pre-faulting for that PMD range.
Using end = addr + min(vma->vm_end - addr, PMD_SIZE) avoids the wraparound.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-feat-udmabuf-huge-pfnmap-v4-0-c1e1a1d22e27@linux.dev?part=2
next prev parent reply other threads:[~2026-12-05 15:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 15:16 [PATCH v4 0/3] udmabuf: speed up mmap() of huge page backed buffers Qiliang Yuan
2026-12-05 15:16 ` [PATCH v4 1/3] dma-buf: align large mappings to PMD boundaries Qiliang Yuan
2026-12-05 15:16 ` [PATCH v4 2/3] udmabuf: map huge page backed ranges with PMDs Qiliang Yuan
2026-12-05 15:37 ` sashiko-bot [this message]
2026-12-05 15:16 ` [PATCH v4 3/3] selftests/udmabuf: test mapping a huge page backed udmabuf Qiliang Yuan
2026-12-05 15:35 ` sashiko-bot
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=sashiko-outbox-251704@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=media-ci@linuxtv.org \
--cc=qiliang.yuan@linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/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