dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* Re: [RFC PATCH] drm/gpusvm: reject device pages not owned by the caller
       [not found] <20261205064202.2527445-1-praneethb2002@gmail.com>
@ 2026-12-05  7:03 ` sashiko-bot
  0 siblings, 0 replies; only message in thread
From: sashiko-bot @ 2026-12-05  7:03 UTC (permalink / raw)
  To: Praneeth Balasubramanian; +Cc: dri-devel

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 <praneethb2002@gmail.com>

> 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 <praneethb2002@gmail.com>

[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 Memory")

> 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_gpusvm *gpusvm,
>  		order = 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 =
> -				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 !=
> +			    ctx->device_private_page_owner) {
> +				err = -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 = 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 == -EOPNOTSUPP || err == -EFAULT || err == -EPERM) {
		ctx.timeslice_ms <<= 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.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205064202.2527445-1-praneethb2002@gmail.com?part=1

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-05  7:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261205064202.2527445-1-praneethb2002@gmail.com>
2026-12-05  7:03 ` [RFC PATCH] drm/gpusvm: reject device pages not owned by the caller sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox