From: sashiko-bot@kernel.org
To: "Natalie Vock" <nat@pixelcluster.dev>
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 05/10] drm/amdgpu: Track dirty bo_va structures in update ctx
Date: Tue, 17 Nov 2026 14:28:16 +0000 [thread overview]
Message-ID: <sashiko-outbox-218965@kernel.org> (raw)
In-Reply-To: <20261117-prt-explicit-sync-v2-5-bb3851cb6a0c@pixelcluster.dev>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/amdgpu: UAF on bo_va in amdgpu_vm_update_ctx_fini() after
amdgpu_vm_bo_del()
- [High] drm/amdgpu: skipped delete in
amdgpu_vm_update_ctx_add_freed_mapping()
- [Low] drm/amdgpu: update_link placed under wrong lock comment in
amdgpu_bo_va
--
commit 3f1753904c640653510160bf642992a7a55fbc3d
Author: Natalie Vock <nat@pixelcluster.dev>
drm/amdgpu: Track dirty bo_va structures in update ctx
This commit adds an update_link list head to struct amdgpu_bo_va and tracks
modified bo_va structures in a dirty_bo_vas list on struct amdgpu_vm_update_ctx.
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> index e0090dc10682f..068c57ed537fd 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> @@ -80,6 +80,8 @@ struct amdgpu_bo_va {
> /* protected by bo being reserved */
> unsigned ref_count;
>
> + struct list_head update_link;
> +
> /* all other members protected by the VM PD being reserved */
> struct dma_fence *last_pt_update;
>
[Severity: Low]
Should update_link be placed below the "all other members protected by the VM
PD being reserved" comment? It is modified by the update_ctx helpers while
only the VM PD reservation lock is held, including when the individual BO is
NULL (such as fpriv->prt_va) or not reserved (when clearing overlapping
mappings of other BOs in the VM).
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 1e2d45979efdb..330c288053352 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
[ ... ]
> @@ -1733,8 +1735,10 @@ static void
> amdgpu_vm_update_ctx_add_freed_mapping(struct amdgpu_vm_update_ctx *ctx,
> struct amdgpu_bo_va_mapping *mapping)
> {
> - WARN_ON(!list_empty(&mapping->pending_list));
> - list_add(&mapping->pending_list, &ctx->deleted);
> + if (list_empty(&mapping->bo_va->update_link))
> + list_add(&mapping->bo_va->update_link, &ctx->dirty_bo_vas);
> + if (list_empty(&mapping->pending_list))
> + list_add(&mapping->pending_list, &ctx->deleted);
> }
[Severity: High]
Can skipping list_add(&mapping->pending_list, &ctx->deleted) when
mapping->pending_list is non-empty leave freed mappings in vm->va?
Within one update_ctx, amdgpu_vm_bo_clear_mappings() and
amdgpu_vm_bo_replace_map() put overlapping mappings onto ctx->cleared via
mapping->pending_list; if amdgpu_vm_bo_unmap() is then called on that mapping
in the same context, amdgpu_vm_update_ctx_add_freed_mapping() leaves it on
ctx->cleared instead of moving it to ctx->deleted, so
amdgpu_vm_update_ctx_execute_replace() re-inserts any non-cleared remainder.
Furthermore, if an update_ctx is aborted before
amdgpu_vm_update_ctx_execute_replace() finishes processing ctx->cleared (for
example, if amdgpu_vm_bo_replace_map() fails in
amdgpu_vm_update_ctx_add_new_mapping()), neither amdgpu_vm_update_ctx_fini()
here nor amdgpu_vm_update_ctx_rollback() in commit "drm/amdgpu: Add function to
roll back a VM update ctx" unlinks entries from ctx->cleared. When the BO is
later removed in amdgpu_vm_bo_del(), amdgpu_vm_update_ctx_add_freed_mapping()
silently skips adding the mapping to update_ctx.deleted and kfree(bo_va) frees
bo_va while the mapping remains in vm->va with a dangling mapping->bo_va
pointer, causing a use-after-free on subsequent vm->va traversals.
> int amdgpu_vm_update_ctx_execute_replace(struct amdgpu_vm_update_ctx *ctx)
[ ... ]
> @@ -1878,10 +1883,16 @@ void amdgpu_vm_update_ctx_init(struct amdgpu_vm_update_ctx *ctx,
> void amdgpu_vm_update_ctx_fini(struct amdgpu_vm_update_ctx *ctx)
> {
> struct interval_tree_node *node, *next_node;
> + struct amdgpu_bo_va *bo_va, *next_bo_va;
>
> list_splice(&ctx->freed, &ctx->vm->delayed_freed);
> amdgpu_sync_free(&ctx->sync);
>
> + list_for_each_entry_safe(bo_va, next_bo_va, &ctx->dirty_bo_vas,
> + update_link) {
> + list_del_init(&bo_va->update_link);
> + }
[Severity: High]
Does this cause a use-after-free on bo_va when a caller unmaps and deletes a
bo_va before finalizing update_ctx?
In amdgpu_unmap_static_csa(), amdgpu_vm_bo_unmap() adds bo_va->update_link to
update_ctx.dirty_bo_vas, and amdgpu_vm_bo_del() then frees bo_va before
amdgpu_vm_update_ctx_fini() runs:
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c:amdgpu_unmap_static_csa() {
...
r = amdgpu_vm_bo_unmap(&update_ctx, bo_va, csa_addr);
if (r) {
drm_err(adev_to_drm(adev),
"failed to do bo_unmap on static CSA, err=%d\n", r);
goto error_ctx;
}
amdgpu_vm_update_ctx_commit(&update_ctx);
amdgpu_vm_bo_del(adev, bo_va);
error_ctx:
amdgpu_vm_update_ctx_fini(&update_ctx);
...
}
Because amdgpu_vm_bo_del() calls kfree(bo_va) without unlinking
bo_va->update_link from the outer update_ctx.dirty_bo_vas,
amdgpu_vm_update_ctx_fini() executes list_del_init(&bo_va->update_link) on the
freed bo_va. Unlinking bo_va->update_link in amdgpu_vm_bo_del() before
kfree(bo_va) would avoid this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-prt-explicit-sync-v2-0-bb3851cb6a0c@pixelcluster.dev?part=5
next prev parent reply other threads:[~2026-11-17 14:28 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 12:50 [PATCH v2 00/10] drm/amdgpu: Rework VM update ops for batching and explicit sync Natalie Vock
2026-11-17 12:50 ` [PATCH v2 01/10] drm/amdgpu: Remove unused parameter from amdgpu_vm_pte_fragment Natalie Vock
2026-11-17 12:50 ` [PATCH v2 02/10] drm/amdgpu: Add and use vm_update_ctx struct Natalie Vock
2026-11-17 13:26 ` sashiko-bot
2026-11-17 12:50 ` [PATCH v2 03/10] drm/amdgpu: Make VM maps pending per update context Natalie Vock
2026-11-17 13:43 ` sashiko-bot
2026-11-17 12:50 ` [PATCH v2 04/10] drm/amdgpu: Make removed/cleared mappings " Natalie Vock
2026-11-17 14:05 ` sashiko-bot
2026-11-17 12:50 ` [PATCH v2 05/10] drm/amdgpu: Track dirty bo_va structures in update ctx Natalie Vock
2026-11-17 14:28 ` sashiko-bot [this message]
2026-11-17 12:50 ` [PATCH v2 06/10] drm/amdgpu: Add function to roll back a VM " Natalie Vock
2026-11-17 14:40 ` sashiko-bot
2026-11-17 12:50 ` [PATCH v2 07/10] drm/amdgpu: Move some VA op validation to a helper Natalie Vock
2026-11-17 12:50 ` [PATCH v2 08/10] drm/amdgpu: Only reject conflicting mappings if they are not cleared Natalie Vock
2026-11-17 15:06 ` sashiko-bot
2026-11-17 12:50 ` [PATCH v2 09/10] drm/amdgpu: Add new AMDGPU_GEM_VA2 ioctl Natalie Vock
2026-11-17 15:34 ` sashiko-bot
2026-11-17 22:46 ` Dave Airlie
2026-11-17 12:50 ` [PATCH v2 10/10] drm/amdgpu: Bump minor version Natalie Vock
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-218965@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=amd-gfx@lists.freedesktop.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=nat@pixelcluster.dev \
--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