From: sashiko-bot@kernel.org
To: "Arvind Yadav" <arvind.yadav@intel.com>,
dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v2 2/2] drm/gpusvm: Clear inline DMA mapping state on unmap
Date: Fri, 04 Dec 2026 07:39:51 +0000 [thread overview]
Message-ID: <sashiko-outbox-249332@kernel.org> (raw)
In-Reply-To: <20261204065318.1785149-3-arvind.yadav@intel.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/gpusvm: data race in drm_gpusvm_get_pages() against inline
unmap clear
- [Low] drm/gpusvm: stale inline-mapping comment in
drm_gpusvm_get_pages()
--
commit bab5781b359a68d1d19fa3199ce1021cc07be6b6
Author: Arvind Yadav <arvind.yadav@intel.com>
drm/gpusvm: Clear inline DMA mapping state on unmap
This commit clears inline_addr and flags.inline_dma_mapping in
__drm_gpusvm_unmap_pages(), and updates the drm_gpusvm_pages_first_dma()
documentation to require holding the notifier lock when resolving and
copying an inline entry.
> diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c
> index de2fa2684e846..1a61b13384a01 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;
[Severity: High]
Can clearing svm_pages->inline_addr here race with the unlocked dma_addr
allocation loop in drm_gpusvm_get_pages()?
When ctx->devmem_fn is set (for example, from Xe's prefetch_ranges()),
drm_gpusvm_get_pages() bypasses the fast path even with a valid inline
mapping and inspects and updates the union before taking
gpusvm->notifier_lock:
drivers/gpu/drm/drm_gpusvm.c:drm_gpusvm_get_pages() {
...
if (map_dma) {
for (p = 0; p < num_pages; ++p) {
if (drm_gpusvm_pages_first_dma(&svm_pages[p], NULL))
continue;
svm_pages[p].dma_addr =
kvzalloc_objs(*svm_pages[p].dma_addr, npages);
...
drm_gpusvm_notifier_lock(gpusvm);
...
}
__drm_gpusvm_unmap_pages() runs from MMU notifiers under
gpusvm->notifier_lock without the driver lock, so the two paths share no
locks here. Because svm_pages->inline_addr and svm_pages->flags.__flags
are separate fields with no compiler or release barrier between the plain
16-byte clear and WRITE_ONCE(), the flag update can become visible first:
CPU0 (drm_gpusvm_get_pages) CPU1 (MMU notifier)
--------------------------- -------------------
down_write(&gpusvm->notifier_lock)
__drm_gpusvm_unmap_pages()
WRITE_ONCE(flags, ...) /* reordered */
drm_gpusvm_pages_first_dma()
sees inline_dma_mapping == 0
sees dma_addr == NULL
svm_pages[p].dma_addr =
kvzalloc_objs(...)
svm_pages->inline_addr = {}
<-- clobbers dma_addr with NULL
up_write(&gpusvm->notifier_lock)
drm_gpusvm_notifier_lock()
If inline_addr.addr was 0 (such as VRAM DPA 0) or the 16-byte clear is
torn, the delayed zeroing can overwrite the newly allocated dma_addr
pointer with NULL, permanently leaking the buffer, or tear the pointer
and corrupt memory on a later kvfree(). Reading
drm_gpusvm_pages_first_dma() outside notifier_lock also violates the
updated locking contract documented by this patch.
Since gpusvm->notifier_lock cannot wrap GFP_KERNEL allocations, could
drm_gpusvm_get_pages() allocate into a temporary buffer outside the lock
and inspect and install svm_pages[p].dma_addr under notifier_lock, freeing
any unused buffer after unlocking?
[Severity: Low]
Does the comment above drm_gpusvm_pages_valid_unlocked() in
drm_gpusvm_get_pages() now need an update?
drivers/gpu/drm/drm_gpusvm.c:drm_gpusvm_get_pages() {
...
/*
* drm_gpusvm_pages_valid_unlocked() also resets any instance whose
* mapping was invalidated, so it must run on the map_dma path even when
* devmem_fn suppresses the fast path; otherwise a stale inline mapping
* is later mistaken for a dma_addr array by drm_gpusvm_dma_map_pages().
*/
...
}
With __drm_gpusvm_unmap_pages() clearing inline_addr and
flags.inline_dma_mapping on invalidation, invalidated entries no longer
retain a stale inline mapping when drm_gpusvm_get_pages() runs.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204065318.1785149-1-arvind.yadav@intel.com?part=2
next prev parent reply other threads:[~2026-12-04 7:40 UTC|newest]
Thread overview: 7+ 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 7:21 ` sashiko-bot
2026-12-04 6:53 ` [PATCH v2 2/2] drm/gpusvm: Clear inline DMA mapping state on unmap Arvind Yadav
2026-12-04 7:39 ` sashiko-bot [this message]
2026-12-04 7:30 ` ✓ CI.KUnit: success for Fix invalidated inline DMA mappings in GPUSVM Patchwork
2026-12-04 8:04 ` ✓ Xe.CI.BAT: " Patchwork
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=sashiko-outbox-249332@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=arvind.yadav@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
/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