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 08/10] drm/amdgpu: Only reject conflicting mappings if they are not cleared
Date: Tue, 17 Nov 2026 15:06:29 +0000 [thread overview]
Message-ID: <sashiko-outbox-219018@kernel.org> (raw)
In-Reply-To: <20261117-prt-explicit-sync-v2-8-bb3851cb6a0c@pixelcluster.dev>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Critical] drm/amdgpu: amdgpu_vm_update_ctx_rollback() fails to unlink
ctx->cleared
- [High] drm/amdgpu: missing interval tree iteration in
amdgpu_vm_bo_map()
- [High] drm/amdgpu: amdgpu_vm_bo_map() ignores conflicts on partially
cleared ranges
- [High] drm/amdgpu: amdgpu_vm_update_ctx_rollback() leaks ctx->new
mappings
- [High] drm/amdgpu: missing amdgpu_vm_update_ctx_commit() in
unmap_bo_from_gpuvm()
--
commit 4bdb539ca2c3dc59efa5a70eaf09b4e87c351cb1
Author: Natalie Vock <nat@pixelcluster.dev>
drm/amdgpu: Only reject conflicting mappings if they are not cleared
This commit updates amdgpu_vm_bo_map() to only reject an overlapping
mapping in the VM interval tree when its pending_list is empty.
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index ac4a1ed9b1196..491f4b50f7602 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -2241,7 +2241,7 @@ int amdgpu_vm_bo_map(struct amdgpu_vm_update_ctx *ctx,
> eaddr = saddr + (size - 1) / AMDGPU_GPU_PAGE_SIZE;
>
> tmp = amdgpu_vm_it_iter_first(&vm->va, saddr, eaddr);
> - if (tmp) {
> + if (tmp && list_empty(&tmp->pending_list)) {
> /* bo and tmp overlap, invalid addr */
> dev_err(ctx->adev->dev,
> "bo %p va 0x%010Lx-0x%010Lx conflict with "
[Severity: High]
Can amdgpu_vm_bo_map() miss a conflict when [saddr, eaddr] overlaps more
than one mapping in vm->va?
If the first node returned by amdgpu_vm_it_iter_first() has a non-empty
pending_list (because it was unmapped or cleared earlier in the same
update context) and a subsequent overlapping node in [saddr, eaddr] is
still active with an empty pending_list, amdgpu_vm_bo_map() never walks
the remaining nodes via amdgpu_vm_it_iter_next().
amdgpu_vm_update_ctx_commit() then inserts the new mapping into vm->va on
top of the active mapping.
Should this loop with amdgpu_vm_it_iter_next(tmp, saddr, eaddr) over all
overlapping nodes in [saddr, eaddr] and reject the map if any node has an
empty pending_list?
[Severity: High]
Does checking list_empty(&tmp->pending_list) also allow mapping over the
uncleared portion of a partially cleared mapping?
When amdgpu_vm_bo_clear_mappings() partially clears an existing mapping
tmp, it adds the entire unsplit mapping to ctx->cleared via
tmp->pending_list while recording only the cleared sub-range in
ctx->cleared_ranges:
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:amdgpu_vm_bo_clear_mappings() {
...
tmp = amdgpu_vm_it_iter_first(&ctx->vm->va, saddr, eaddr);
while (tmp) {
amdgpu_vm_update_ctx_add_replaced_mapping(ctx, tmp);
tmp = amdgpu_vm_it_iter_next(tmp, saddr, eaddr);
}
cleared_range->start = saddr;
cleared_range->last = eaddr;
interval_tree_insert(cleared_range, &ctx->cleared_ranges);
...
}
Because list_empty(&tmp->pending_list) is false across all of
[tmp->start, tmp->last], a subsequent amdgpu_vm_bo_map() overlapping the
still-active part of tmp is not rejected here. If a later clear in the
same update context covers that remaining range,
amdgpu_vm_update_ctx_execute_replace() produces no gap mapping to collide
with ctx->pending_maps, so the invalid map succeeds without ever reporting
a conflict.
[Severity: Critical]
What happens to tmp->pending_list when an update context is rolled back
after staging cleared mappings on ctx->cleared?
In commit "drm/amdgpu: Add function to roll back a VM update ctx",
amdgpu_vm_update_ctx_rollback() unlinks ctx->new and ctx->deleted, but
does not unlink ctx->cleared:
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:amdgpu_vm_update_ctx_rollback() {
...
list_for_each_entry_safe(mapping, next, &ctx->new, pending_list)
list_del_init(&mapping->pending_list);
list_for_each_entry_safe(mapping, next, &ctx->deleted, pending_list)
list_del_init(&mapping->pending_list);
...
}
If an operation rolls back after amdgpu_vm_bo_clear_mappings() or
amdgpu_vm_bo_replace_map() has placed a live mapping onto ctx->cleared,
that mapping stays in vm->va with mapping->pending_list pointing into the
expired stack-allocated update_ctx.cleared head. Because
list_empty(&mapping->pending_list) then remains false, this check in
amdgpu_vm_bo_map() treats the live mapping as cleared and allows
conflicting mappings over it. In addition,
amdgpu_vm_update_ctx_add_freed_mapping() skips any mapping whose
pending_list is not empty, so amdgpu_vm_bo_del() frees bo_va while leaving
its mapping in vm->va with a dangling bo_va pointer, leading to a
use-after-free on later VM interval tree walks.
[Severity: High]
Does rolling back a context after amdgpu_vm_bo_map() queues a new mapping
leak the mapping allocation?
amdgpu_vm_bo_map() allocates mapping with kmalloc_obj(*mapping) and
queues it on ctx->new via amdgpu_vm_update_ctx_add_new_mapping(), only
inserting it into vm->va and bo_va->invalids when
amdgpu_vm_update_ctx_commit() runs. When a later step fails (such as
amdgpu_vm_update_ctx_execute_replace() after mapping over a partially
cleared range) or hits lock contention, amdgpu_vm_update_ctx_rollback()
calls list_del_init(&mapping->pending_list) on each entry in ctx->new
without freeing mapping.
[Severity: High]
In commit "drm/amdgpu: Make removed/cleared mappings pending per update
context", does unmap_bo_from_gpuvm() also miss a call to
amdgpu_vm_update_ctx_commit() before clearing freed mappings?
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c:unmap_bo_from_gpuvm() {
...
amdgpu_vm_update_ctx_init(&update_ctx, adev, vm);
(void)amdgpu_vm_bo_unmap(&update_ctx, bo_va, entry->va);
/* VM entity stopped if process killed, don't clear freed pt bo */
if (!amdgpu_vm_ready(vm))
goto out;
(void)amdgpu_vm_clear_freed(&update_ctx, &bo_va->last_pt_update);
(void)amdgpu_sync_fence(sync, bo_va->last_pt_update, GFP_KERNEL);
out:
amdgpu_vm_update_ctx_fini(&update_ctx);
return 0;
}
Because amdgpu_vm_bo_unmap() only stages the mapping on
update_ctx.deleted until amdgpu_vm_update_ctx_commit() moves it to
update_ctx.freed and removes it from vm->va, amdgpu_vm_clear_freed() sees
an empty freed list and amdgpu_vm_update_ctx_fini() rolls the unmap back,
leaving the mapping active in vm->va.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-prt-explicit-sync-v2-0-bb3851cb6a0c@pixelcluster.dev?part=8
next prev parent reply other threads:[~2026-11-17 15:06 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
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 [this message]
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-219018@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