FAILED: patch "[PATCH] drm/gpusvm: publish dpagemap early to avoid device mapping" failed to apply to 6.18-stable tree
Subsystems (4)
[email protected]
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x 7f708f51e3955bda0d77a0b67ab9bea6c97fea99
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026072912-heritage-womb-d38a@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 7f708f51e3955bda0d77a0b67ab9bea6c97fea99 Mon Sep 17 00:00:00 2001
From: Honglei Huang <[email protected]>
Date: Wed, 1 Jul 2026 14:28:00 +0800
Subject: [PATCH] drm/gpusvm: publish dpagemap early to avoid device mapping
leak on error
drm_gpusvm_get_pages() only stored the local dpagemap into svm_pages->dpagemap on the success path. If a later page failed (e.g. -EOPNOTSUPP when ctx->allow_mixed is false) and jumped to err_unmap, svm_pages->dpagemap was still NULL, so __drm_gpusvm_unmap_pages() skipped device_unmap() and leaked the device mappings already created.
Assign svm_pages->dpagemap when the first device page is mapped so the err_unmap path can device_unmap() those mappings.
This issue was found by Sashiko AI review.
drivers/gpu/drm/drm_gpusvm.c +11 -5
@@ -1544,6 +1544,16 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm, err = -EAGAIN ; goto err_unmap; } + +/* +* Set the dpagemap as soon as the first +* device page is mapped so the err_unmap path +* can device_unmap() the device mappings that +* have already been created. +*/ +drm_pagemap_get (dpagemap); +drm_pagemap_put (svm_pages->dpagemap); + svm_pages->dpagemap = dpagemap; } svm_pages->dma_addr[j] = dpagemap->ops->device_map(dpagemap,
@@ -1611,12 +1621,8 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm, goto err_unmap; } -if (pagemap) { +if (pagemap) flags.has_devmem_pages = true; -drm_pagemap_get (dpagemap); -drm_pagemap_put (svm_pages->dpagemap); - svm_pages->dpagemap = dpagemap; - }/* WRITE_ONCE pairs with READ_ONCE for opportunistic checks */ WRITE_ONCE (svm_pages->flags.__flags, flags.__flags);
Honglei Huang
reviewerPATCH 1/1 drm/gpusvm: publish dpagemap early to avoid device mapping leak on error
drm_gpusvm_get_pages() only stored the local dpagemap into svm_pages->dpagemap on the success path. If a later page failed (e.g. -EOPNOTSUPP when ctx->allow_mixed is false) and jumped to err_unmap, svm_pages->dpagemap was still NULL, so __drm_gpusvm_unmap_pages() skipped device_unmap() and leaked the device mappings already created.
Assign svm_pages->dpagemap when the first device page is mapped so the err_unmap path can device_unmap() those mappings.
This issue was found by Sashiko AI review.
[ Adjusted for 6.18.y: drop drm_pagemap_get()/drm_pagemap_put() around the
svm_pages->dpagemap assignment; that reference counting is not present in 6.18 where the field is not refcounted (unmap path only clears it). ]
--- drivers/gpu/drm/drm_gpusvm.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_gpusvm.c +9 -3
@@ -1390,6 +1390,14 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm, err = -EAGAIN ; goto err_unmap; } + +/* +* Set the dpagemap as soon as the first +* device page is mapped so the err_unmap path +* can device_unmap() the device mappings that +* have already been created. +*/ + svm_pages->dpagemap = dpagemap; } svm_pages->dma_addr[j] = dpagemap->ops->device_map(dpagemap,
@@ -1432,10 +1440,8 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm, flags.has_dma_mapping = true; } -if (pagemap) { +if (pagemap) flags.has_devmem_pages = true; - svm_pages->dpagemap = dpagemap; - }/* WRITE_ONCE pairs with READ_ONCE for opportunistic checks */ WRITE_ONCE (svm_pages->flags.__flags, flags.__flags);
Signature · 1 line
2.34.1
Re: [PATCH 6.18.y] drm/gpusvm: publish dpagemap early to avoid device mapping leak on error
Quoted 3 lines · Honglei Huang
[ Adjusted for 6.18.y: drop drm_pagemap_get()/drm_pagemap_put() around the
svm_pages->dpagemapassignment; that reference counting is not present in 6.18 where the field is not refcounted (unmap path only clears it). ]
Queued for 6.18, thanks.
Signature · 2 lines
Thanks, Sasha