From: Arvind Yadav <arvind.yadav@intel.com>
To: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Cc: matthew.brost@intel.com, thomas.hellstrom@linux.intel.com,
maarten.lankhorst@linux.intel.com, mripard@kernel.org,
tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch,
himal.prasad.ghimiray@intel.com
Subject: [PATCH] drm/gpusvm: Retry invalid inline DMA mappings after HMM faults
Date: Wed, 2 Dec 2026 13:38:17 +0530 [thread overview]
Message-ID: <20261202080817.55658-1-arvind.yadav@intel.com> (raw)
When a devmem callback is present, drm_gpusvm_get_pages() continues
through HMM even if the existing DMA mapping is valid. Invalidation
during this window can unmap the DMA mapping while leaving its inline
storage intact.
HMM refreshes notifier_seq internally, so the later sequence check
can pass. The inline entry causes DMA array allocation to be skipped,
but the mapper then treats the stored DMA address as an array pointer.
This results in:
BUG: KASAN: user-memory-access in drm_gpusvm_get_pages+0xe12/0x1380 [drm_gpusvm_helper]
Write of size 16 at addr 000000027abfd000 by task kworker/u64:71/693678
Workqueue: xe_prefetch_work_queue prefetch_work_func [xe]
Before mapping, check for invalid inline storage under the notifier
lock. Clear it and retry so a DMA array is allocated before the mapper
writes to it. The retry uses the existing timeout.
Fixes: 8d242e452ed7 ("drm/gpusvm: keep a single DMA mapping inline for THP")
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Signed-off-by: Arvind Yadav <arvind.yadav@intel.com>
---
drivers/gpu/drm/drm_gpusvm.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c
index de2fa2684e84..fd071eb85e24 100644
--- a/drivers/gpu/drm/drm_gpusvm.c
+++ b/drivers/gpu/drm/drm_gpusvm.c
@@ -1888,6 +1888,17 @@ int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm,
if (drm_gpusvm_pages_valid(gpusvm, &svm_pages[p]))
continue;
+ /*
+ * HMM may refresh notifier_seq after invalidation, leaving stale
+ * inline storage. Clear it and retry to allocate a DMA array.
+ */
+ if (svm_pages[p].flags.inline_dma_mapping) {
+ __drm_gpusvm_free_pages(gpusvm, &svm_pages[p]);
+ drm_gpusvm_notifier_unlock(gpusvm);
+ kvfree(pfns);
+ goto retry;
+ }
+
err = drm_gpusvm_dma_map_pages(gpusvm, &svm_pages[p], pfns,
npages, ctx, dma_dir);
if (err) {
--
2.43.0
reply other threads:[~2026-12-02 8:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202080817.55658-1-arvind.yadav@intel.com \
--to=arvind.yadav@intel.com \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=himal.prasad.ghimiray@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matthew.brost@intel.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=thomas.hellstrom@linux.intel.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®