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 06/10] drm/amdgpu: Add function to roll back a VM update ctx
Date: Tue, 17 Nov 2026 14:40:56 +0000 [thread overview]
Message-ID: <sashiko-outbox-218979@kernel.org> (raw)
In-Reply-To: <20261117-prt-explicit-sync-v2-6-bb3851cb6a0c@pixelcluster.dev>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/amdgpu: leak of ctx->new mappings in
amdgpu_vm_update_ctx_rollback()
- [High] drm/amdgpu: missing ctx->cleared unlink in
amdgpu_vm_update_ctx_rollback()
--
commit b40894c15667a95794d5db4dfea6f22963fb9ec5
Author: Natalie Vock <nat@pixelcluster.dev>
drm/amdgpu: Add function to roll back a VM update ctx
This commit introduces amdgpu_vm_update_ctx_rollback() to discard pending
mapping changes in a VM update context and calls it from
amdgpu_vm_update_ctx_fini().
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 330c288053352..ac4a1ed9b1196 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -1874,37 +1874,48 @@ void amdgpu_vm_update_ctx_init(struct amdgpu_vm_update_ctx *ctx,
> }
>
> /**
> - * amdgpu_vm_update_ctx_fini - finish a VM update operation
> - * @ctx: The context of the update
> + * amdgpu_vm_update_ctx_rollback - clear pending VM updates
> + * @ctx: The context to roll back
> *
> - * Adds any leftover mappings needing to be cleared to the VM's delayed free list,
> - * then frees up resources used by the context.
> + * Cleans up any pending mapping changes, but does not reset
> + * anything else (like attached syncobjs).
> */
> -void amdgpu_vm_update_ctx_fini(struct amdgpu_vm_update_ctx *ctx)
> +void amdgpu_vm_update_ctx_rollback(struct amdgpu_vm_update_ctx *ctx)
> {
> + struct amdgpu_bo_va_mapping *mapping, *next;
> 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(mapping, next, &ctx->new, pending_list)
> + list_del_init(&mapping->pending_list);
[Severity: High]
Does this leak each struct amdgpu_bo_va_mapping on ctx->new?
Unlike mappings on ctx->deleted, newly allocated mappings added by
amdgpu_vm_update_ctx_add_new_mapping() are not inserted into bo_va->invalids
or vm->va until amdgpu_vm_update_ctx_commit() runs. If a rollback or an
error before commit hits this loop, unlinking mapping->pending_list without
calling kfree(mapping) drops the only reference to those allocations.
> + list_for_each_entry_safe(mapping, next, &ctx->deleted, pending_list)
> + list_del_init(&mapping->pending_list);
[Severity: High]
Should amdgpu_vm_update_ctx_rollback() also unlink mappings on
ctx->cleared?
amdgpu_vm_bo_clear_mappings() links overlapping live mappings from vm->va
onto ctx->cleared via mapping->pending_list. If a replace or clear
operation rolls back or fails before amdgpu_vm_update_ctx_execute_replace()
drains ctx->cleared, those mappings stay linked to ctx->cleared while
ctx->cleared_ranges is reset. If the context is then destroyed,
list_empty(&mapping->pending_list) remains false on the live mappings in
vm->va, causing later unmaps and amdgpu_vm_bo_del() to skip removing them
from vm->va before freeing bo_va, which leaves dangling pointers and leads
to a use-after-free.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-prt-explicit-sync-v2-0-bb3851cb6a0c@pixelcluster.dev?part=6
next prev parent reply other threads:[~2026-11-17 14:41 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
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 [this message]
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-218979@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.