* [RFC PATCH] drm/gpusvm: reject device pages not owned by the caller
@ 2026-12-05 6:42 Praneeth Balasubramanian
[not found] ` <sashiko-outbox-251184@kernel.org>
0 siblings, 1 reply; 2+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05 6:42 UTC (permalink / raw)
To: Matthew Brost, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter
Cc: Praneeth Balasubramanian, Thomas Hellström,
Himal Prasad Ghimiray, Honglei Huang, dri-devel, linux-kernel
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>
---
Notes:
This was found by an LLM-based audit, part of research at UCSB SecLab.
An LLM turned a kernel comment into a rule, and three LLM votes checked
the code against it. The fix and changelog were drafted with GLM-5.3,
then checked against the source and partly rewritten with Claude Opus
5.5. I reviewed the patch and take responsibility for it.
Testing: builds without new warnings with W=1 (x86_64 allmodconfig),
clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no
reproducer. I do not have this hardware.
RFC: rejecting foreign device coherent pages is one option. Mapping them
as plain system memory may be what you want instead. This needs a system
with both an amdkfd coherent memory device and an Xe device, which I do
not have.
drivers/gpu/drm/drm_gpusvm.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c
index de2fa2684e84..a5fcf4de5549 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;
+ }
+
+ __zdd = drm_pagemap_page_zone_device_data(page);
if (!ctx->allow_mixed &&
zdd != __zdd && i > 0) {
base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [RFC PATCH] drm/gpusvm: reject device pages not owned by the caller
[not found] ` <sashiko-outbox-251184@kernel.org>
@ 2026-12-05 8:21 ` Praneeth Balasubramanian
0 siblings, 0 replies; 2+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05 8:21 UTC (permalink / raw)
To: sashiko-reviews
Cc: Matthew Brost, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter,
Thomas Hellström, Himal Prasad Ghimiray, Honglei Huang,
dri-devel, linux-kernel
On Sat, 05 Dec 2026 07:03:31 +0000, sashiko-bot@kernel.org wrote:
> [Severity: High]
> Can returning -EOPNOTSUPP here livelock Xe GPU page fault handling on
> foreign device coherent pages?
Yes. __xe_svm_handle_pagefault() retries -EOPNOTSUPP, -EFAULT and -EPERM
without a bound when devmem_only is not set, and
drm_gpusvm_range_evict() leaves a present device coherent page where it
is. So v2 returns -EINVAL for a foreign page, which ends the fault. The
userptr path returns it to the caller as before.
> Should this include:
>
> Fixes: 99624bdff867 ("drm/gpusvm: Add support for GPU Shared Virtual Memory")
Yes, that commit already read zone_device_data as a zdd without an
owner check. Added in v2.
For the DRM SVM folks: is failing the mapping what you want here, or
should foreign device coherent pages be mapped like system memory? And
if failing is right, is -EINVAL the code you prefer?
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-05 8:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 6:42 [RFC PATCH] drm/gpusvm: reject device pages not owned by the caller Praneeth Balasubramanian
[not found] ` <sashiko-outbox-251184@kernel.org>
2026-12-05 8:21 ` Praneeth Balasubramanian
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox