mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 v2 2/2] drm/gpusvm: Clear inline DMA mapping state on unmap
Date: Fri,  4 Dec 2026 12:23:18 +0530	[thread overview]
Message-ID: <20261204065318.1785149-3-arvind.yadav@intel.com> (raw)
In-Reply-To: <20261204065318.1785149-1-arvind.yadav@intel.com>

Unmap clears has_dma_mapping but leaves the inline DMA address and
inline_dma_mapping flag intact.

When a devmem callback is present, get_pages() continues through HMM
even with a valid DMA mapping. Invalidation during HMM can leave stale
inline state while HMM refreshes notifier_seq. The later sequence
check can then pass, but DMA array allocation is skipped. The mapper
treats the stored DMA address as an array pointer.

  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]

Clear the inline address and flag during unmap so the allocation pass
after HMM can allocate a DMA array. Update the helper documentation
to describe the inline entry's lifetime.

v2:
- Clear inline DMA mapping state in __drm_gpusvm_unmap_pages()
  instead of adding a retry in drm_gpusvm_get_pages() (Matt).
- Update the inline DMA helper's lifetime documentation. (Sashiko)

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>
Suggested-by: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: Arvind Yadav <arvind.yadav@intel.com>
---
 drivers/gpu/drm/drm_gpusvm.c |  5 +++++
 include/drm/drm_gpusvm.h     | 14 ++++++++------
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c
index de2fa2684e84..1a61b13384a0 100644
--- a/drivers/gpu/drm/drm_gpusvm.c
+++ b/drivers/gpu/drm/drm_gpusvm.c
@@ -1286,6 +1286,11 @@ static void __drm_gpusvm_unmap_pages(struct drm_gpusvm *gpusvm,
 			i += 1 << addr->order;
 		}
 
+		if (flags.inline_dma_mapping) {
+			svm_pages->inline_addr = (struct drm_pagemap_addr){};
+			flags.inline_dma_mapping = false;
+		}
+
 		/* WRITE_ONCE pairs with READ_ONCE for opportunistic checks */
 		flags.has_devmem_pages = false;
 		flags.has_dma_mapping = false;
diff --git a/include/drm/drm_gpusvm.h b/include/drm/drm_gpusvm.h
index b43432af5637..9d55c34ffbb8 100644
--- a/include/drm/drm_gpusvm.h
+++ b/include/drm/drm_gpusvm.h
@@ -428,12 +428,14 @@ drm_gpusvm_pages_read_retry(struct drm_gpusvm *gpusvm,
  * from the order. The order still states what one PTE may cover: the range
  * length for a huge page, PAGE_SIZE for an IOVA mapped range of single pages.
  *
- * Only get_pages() and the free path switch between the two union members.
- * Both hold the notifier lock for read, so taking that lock does not stop
- * them; callers need the driver lock that does, which every reader of the
- * addresses holds anyway. The notifier never touches the union, so the
- * pointer returned here stays good and can then be used under the notifier
- * lock.
+ * Callers must hold the driver lock that serializes get_pages() and the
+ * free path. Invalidation can clear inline storage under the notifier
+ * lock, so callers must also hold that lock while resolving and copying
+ * an inline entry.
+ *
+ * To use an inline entry after releasing the notifier lock, copy it while
+ * holding the lock and use the copy. The copy does not keep the DMA mapping
+ * valid. Callers must still validate it before committing GPU access.
  *
  * Return: Pointer to the first device address, NULL if none is populated.
  */
-- 
2.43.0


      parent reply	other threads:[~2026-12-04  6:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  6:53 [PATCH v2 0/2] Fix invalidated inline DMA mappings in GPUSVM Arvind Yadav
2026-12-04  6:53 ` [PATCH v2 1/2] drm/xe: Snapshot inline DMA addresses before staging page tables Arvind Yadav
2026-12-04  6:53 ` Arvind Yadav [this message]

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=20261204065318.1785149-3-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®