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 5616C606A322 for ; Sat, 5 Dec 2026 07:03: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=dL5tk4zG Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AAEE810E7DC; Sat, 5 Dec 2026 07:03:39 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 62B2510E7DC for ; Sat, 5 Dec 2026 07:03: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 A1FA8601F8; Sat, 5 Dec 2026 07:03:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4827B1F0092B; Sat, 5 Dec 2026 07:03:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796454212; bh=8VRs68ZOJq+kdCOBngvcNbKCaQqwJnFhHS5PulDU+WQ=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=dL5tk4zGhK4P1NT5R0JUQhWxVhaWom8IVeERC7cdfcChx55Gjj09lRoEG2aoxPM/P W+9yPVBV5m7cvXvL8LRO6lfryXgJU8TLYqcOKrqdRqQss6xmWbC2GcMjTZryOFhjzJ 2RqhKYr2BpRKOLjH+G+SzpE5kH6rCwJHEjBV/Sk7SDza/NL3xX17ty1C5lWuDJaH48 5IAWKG0qurVKKVXBUo818mYtTIPlm0LNwV4u4zU7Nmb0x49f0CtgWGYeMZG0ZLldhP SVvxGIcZI1hkOvHClAzrhXZJi+DV230mUo4T+76vEXTXlvcqpAu4vwNlxz8R4/tege F0+qzlo5I/lHg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH] drm/gpusvm: reject device pages not owned by the caller To: "Praneeth Balasubramanian" Cc: dri-devel@lists.freedesktop.org In-Reply-To: <20261205064202.2527445-1-praneethb2002@gmail.com> References: <20261205064202.2527445-1-praneethb2002@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 07:03: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=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,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] drm/gpusvm: -EOPNOTSUPP on foreign coherent pages livelocks Xe pagefaults - [Low] drm/gpusvm: missing Fixes trailer for commit 99624bdff867 -- commit 662bc69b632b0f40716e04f89aa496467afcd5ff Author: Praneeth Balasubramanian > drm/gpusvm: reject device pages not owned by the caller > > drm_gpusvm_dma_map_pages() treats every device private and device > coherent page returned by hmm_range_fault() as populated from a > drm_pagemap. It calls drm_pagemap_page_to_dpagemap(), which reads > zone_device_data as a struct drm_pagemap_zdd and dereferences > zdd->devmem_allocation->dpagemap. > > That assumption does not hold for foreign pages. hmm_range_fault() > filters non-present device private entries by owner. But a present > device coherent page is reported as valid regardless of owner. A > coherent VRAM page migrated by amdkfd SVM holds a struct svm_range_bo > in zone_device_data, not a drm_pagemap_zdd. When such a page reaches > drm_gpusvm_dma_map_pages() through drm_gpusvm_get_pages(), for > example from the Xe userptr path which sets allow_mixed, > drm_pagemap_page_to_dpagemap() misreads the object type and follows a > bogus dpagemap pointer into drm_pagemap_get() and > dpagemap->ops->device_map(). > > Compare page_pgmap(page)->owner against > ctx->device_private_page_owner before interpreting zone_device_data. > Fail with -EOPNOTSUPP on mismatch, the same error already used for > unsupported page mixes. Device private pages keep working unchanged > since hmm_range_fault() already filters them by that owner. > > This was found by an LLM-based audit that checks code against the rules > stated in kernel comments. > > Signed-off-by: Praneeth Balasubramanian [Severity: Low] This fixes a type-confusion bug introduced when GPU SVM support was added. Should this include: Fixes: 99624bdff867 ("drm/gpusvm: Add support for GPU Shared Virtual Memo= ry") > diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c > index de2fa2684e846..a5fcf4de55497 100644 > --- a/drivers/gpu/drm/drm_gpusvm.c > +++ b/drivers/gpu/drm/drm_gpusvm.c > @@ -1614,8 +1614,20 @@ static int drm_gpusvm_dma_map_pages(struct drm_gpu= svm *gpusvm, > order =3D drm_gpusvm_hmm_pfn_to_order(pfns[i], i, npages); > if (is_device_private_page(page) || > is_device_coherent_page(page)) { > - struct drm_pagemap_zdd *__zdd =3D > - drm_pagemap_page_zone_device_data(page); > + struct drm_pagemap_zdd *__zdd; > + > + /* > + * hmm_range_fault() reports present device coherent > + * pages of any owner. Only pages of our owner come > + * from a drm_pagemap and carry a drm_pagemap_zdd. > + */ > + if (page_pgmap(page)->owner !=3D > + ctx->device_private_page_owner) { > + err =3D -EOPNOTSUPP; > + goto err_unmap; > + } [Severity: High] Can returning -EOPNOTSUPP here livelock Xe GPU page fault handling on foreign device coherent pages? On a normal Xe GPU page fault (!ctx.devmem_only) hitting an SVM VMA with a present foreign device coherent page, xe_pagefault_service() holds down_read(&vm->lock) and calls xe_svm_handle_pagefault() -> __xe_svm_handle_pagefault() -> xe_svm_range_get_pages(). xe_svm_range_get_pages() treats -EOPNOTSUPP as a transient condition and calls drm_gpusvm_range_evict(), which invokes hmm_range_fault() with dev_private_owner =3D NULL. In hmm_vma_handle_pte(), owner-mismatch faulting only runs for non-present PTEs, so present device coherent pages stay mapped and drm_gpusvm_range_evict() is a no-op. __xe_svm_handle_pagefault() then loops back to retry without bound whenever !ctx.devmem_only: drivers/gpu/drm/xe/xe_svm.c:__xe_svm_handle_pagefault() { ... if (err =3D=3D -EOPNOTSUPP || err =3D=3D -EFAULT || err =3D=3D -EPERM) { ctx.timeslice_ms <<=3D 1; /* Double timeslice if we have to retry */ if (migrate_try_count > 0 || !ctx.devmem_only) { ... goto retry; } ... } This spins the pagefault worker forever while holding down_read(&vm->lock), wedging pagefault servicing and permanently starving down_write(&vm->lock) waiters such as VM bind and teardown. Returning a distinct terminal error code for non-evictable foreign pages (or mapping them as system memory where supported) would avoid the infinite retry loop. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205064202.2527= 445-1-praneethb2002@gmail.com?part=3D1