From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9AFFC606A322 for ; Sat, 5 Dec 2026 15:37:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PVkq+8PA Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F300910E878; Sat, 5 Dec 2026 15:37:15 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 055B610E878 for ; Sat, 5 Dec 2026 15:37:10 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id F2B38601EB; Sat, 5 Dec 2026 15:37:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 908711F0092B; Sat, 5 Dec 2026 15:37:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796485028; bh=i/XQHAFVSK81rxe33pvBYbHyECoC5i0+uL3pZ9TMRB4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=PVkq+8PAmXptH91fBIQ+GtXp9QN5CV+gTDoa2Tst95Js1xo1XRFYHdbT16o/K5U0i G3G8qcvvtb3vfmkUV/5ZOLInpovQAc6a5Ok/Qy+PgB3M3yLKouHZoa2NW1zZgIY51D hK81JskezZqD0N1gj3qpp3e4wS8m9zQZ22B9mmI+D3bLRfEZ4dVaLANn8XoG9on3C9 wYDlUAGniW9d61cdb0HYT3CFiPyixANgPKpFKTVe2DT0AWqqvLK5yCJ7Qqr85TZcLN rEf9LsEC9uwtPuR9ufEAft5GrdsYVwv/BdCskIElrSvp4seeP2kKfQuas96cAJ8jdB 1ccPPJ4ssRXeQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 2/3] udmabuf: map huge page backed ranges with PMDs To: "Qiliang Yuan" Cc: dri-devel@lists.freedesktop.org, media-ci@linuxtv.org In-Reply-To: <20261205-feat-udmabuf-huge-pfnmap-v4-2-c1e1a1d22e27@linux.dev> References: <20261205-feat-udmabuf-huge-pfnmap-v4-0-c1e1a1d22e27@linux.dev> <20261205-feat-udmabuf-huge-pfnmap-v4-2-c1e1a1d22e27@linux.dev> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 15:37:07 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "dri-devel" X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: 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 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 !=3D 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; > =20 > - /* pre fault */ > - pgoff =3D vma->vm_pgoff; > - addr =3D 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 =3D vmf->address & PMD_MASK; > + end =3D min(vma->vm_end, addr + PMD_SIZE); > + addr =3D max(vma->vm_start, addr); > + pgoff =3D linear_page_index(vma, addr); > =20 > - for (; addr < vma->vm_end; pgoff++, addr +=3D PAGE_SIZE) { > + for (; addr < end; pgoff++, addr +=3D 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 =3D -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 =3D addr + min(vma->vm_end - addr, PMD_SIZE) avoids the wraparoun= d. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205-feat-udmab= uf-huge-pfnmap-v4-0-c1e1a1d22e27@linux.dev?part=3D2