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 B4F26606A31A for ; Tue, 1 Dec 2026 17:34:45 +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=NbguQgz8 Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0BE5D10EA07; Tue, 1 Dec 2026 17:34:40 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6091910FB4A for ; Tue, 1 Dec 2026 17:34:33 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 7C6FB600E4; Tue, 1 Dec 2026 17:34:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92C9B1F00899; Tue, 1 Dec 2026 17:34:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796146471; bh=MQnEWdUtRiuUFE2rRYp5PT7cK0ILV7VC72A3aXz6oqo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=NbguQgz8y5OVgb9flWn6gEyj/+n9w80JrgwMN1XPwKgl6LofFjzSmhDSrcDDhY8Cb ra+UkgJwSR4y3UJXgpSaP8gnOvUurUi+kgYvMEtRWVzYvIxCBDrBrUUqcrqL4KmusV XxK86oLenfB3BElweRzWSchJjrIG4s+VNqnhEqySbwbSsiIOJHMntbBwIokkarL0Ii CmrQgdrhUod2yDKMDwaWUcGuulpTNMkNC3cvz0frcdYGOKXhuUjBmZ+bXoowtU9lzQ m0iGWVG8U94SXm5+LIa6W3vnSnPrVex5koCDwJj8yzF9mncAqCXfWDVTJ4/HSpiwT/ 95ucYGLoBKXWA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 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: <20261201-feat-udmabuf-huge-pfnmap-v3-2-144cc7a48f09@linux.dev> References: <20261201-feat-udmabuf-huge-pfnmap-v3-0-144cc7a48f09@linux.dev> <20261201-feat-udmabuf-huge-pfnmap-v3-2-144cc7a48f09@linux.dev> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 17:34:31 +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=-10.8 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() - [Medium] udmabuf: unclamped pre-fault range via pmd_addr_end() in udmabuf_vm_fault() -- commit ebe4e072f46637cdd8bfd0a954132a421bec39c8 Author: Qiliang Yuan udmabuf: map huge page backed ranges with PMDs This commit adds a ->huge_fault() handler to udmabuf to map PMD-aligned contiguous PFN ranges with PMDs and restricts PTE pre-faulting in udmabuf_vm_fault() to a single PMD-sized range. > diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c > index 018937435356e..dd98d5a1b69fc 100644 > --- a/drivers/dma-buf/udmabuf.c > +++ b/drivers/dma-buf/udmabuf.c > @@ -44,12 +44,67 @@ struct udmabuf { > struct miscdevice *device; > }; > =20 > +#ifdef CONFIG_ARCH_SUPPORTS_HUGE_PFNMAP [ ... ] > +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() and udmabuf_vm_fault() race on the same PMD entry when the prerequisite "mm: fix races between huge and non-huge faults in PFN mappings" series is not present in the tree? Neither fault handler takes a driver lock, and under CONFIG_PER_VMA_LOCK both run under the per-VMA read lock while prctl(PR_SET_THP_DISABLE) sets MMF_DISABLE_THP_COMPLETELY without taking per-VMA write locks: CPU0 CPU1 __handle_mm_fault() create_huge_pmd() udmabuf_vm_huge_fault() udmabuf_pmd_mappable() prctl(PR_SET_THP_DISABLE, 1, ...) __handle_mm_fault() handle_pte_fault() udmabuf_vm_fault() vmf_insert_pfn_pmd() insert_pmd() vmf_insert_pfn() insert_pfn() get_locked_pte() walk_to_pmd() VM_BUG_ON( pmd_trans_huge(*pmd)) When CONFIG_DEBUG_VM is disabled, get_locked_pte() returns NULL on the huge PMD and insert_pfn() returns a spurious VM_FAULT_OOM. If udmabuf_vm_fault() installs a PTE page table first instead, insert_pmd() sees !pmd_none(*pmd) without checking pmd_trans_huge(*pmd); on a write fault it compares pmd_pfn(*pmd) against pfn, hits WARN_ON_ONCE(!is_huge_zero_pmd(*pmd)), and returns VM_FAULT_NOPAGE instead of VM_FAULT_FALLBACK. > static vm_fault_t udmabuf_vm_fault(struct vm_fault *vmf) > { > struct vm_area_struct *vma =3D vmf->vma; > struct udmabuf *ubuf =3D vma->vm_private_data; > pgoff_t pgoff =3D vmf->pgoff; > - unsigned long addr, pfn; > + unsigned long addr, end, pfn; > vm_fault_t ret; > =20 > if (pgoff >=3D ubuf->pagecount) > @@ -61,11 +116,16 @@ 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 max(vma->vm_start, vmf->address & PMD_MASK); > + end =3D pmd_addr_end(vmf->address, vma->vm_end); [Severity: Medium] Does pmd_addr_end(vmf->address, vma->vm_end) fail to clamp end to a single page table on architectures with folded PMDs? When include/asm-generic/pgtable-nopmd.h is used, pmd_addr_end(addr, end) is defined as (end) because it assumes end was already clamped by pgd_addr_end() -> p4d_addr_end() -> pud_addr_end(), while PMD_MASK and PMD_SIZE match PGDIR_MASK and PGDIR_SIZE. As a result, addr is clamped with PMD_MASK, but end stays at vma->vm_end and the loop pre-faults across all remaining page tables to the end of the VMA. Calculating the upper bound explicitly from (vmf->address & PMD_MASK) + PMD_SIZE (as folio_pte_range() does in mm/memory.c) would clamp the range on folded-PMD kernels as well. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201-feat-udmab= uf-huge-pfnmap-v3-0-144cc7a48f09@linux.dev?part=3D2