Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] drm/amdgpu: 64-bit PFN truncation in
  amdgpu_vm_update_ctx_add_new_mapping()
- [Low] drm/amdgpu: duplicate interval check in
  amdgpu_vm_update_ctx_add_new_mapping()
- [Low] drm/amdgpu: fix pending_maps kernel-doc in struct
  amdgpu_vm_update_ctx
--

commit 471887082bbdcd3f5636c1bb4feae875d96ebdb8
Author: Natalie Vock <[email protected]>

drm/amdgpu: Make VM maps pending per update context

This commit stages new VM mappings in struct amdgpu_vm_update_ctx and
inserts them into the VM bookkeeping structures when
amdgpu_vm_update_ctx_commit() is called.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 90f27feb84257..97cf04da6a025 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -1589,6 +1589,73 @@ static void amdgpu_vm_prt_fini(struct amdgpu_device 
> *adev, struct amdgpu_vm *vm)

[ ... ]

> +static int
> +amdgpu_vm_update_ctx_add_new_mapping(struct amdgpu_vm_update_ctx *ctx,
> +                                  struct amdgpu_bo_va *bo_va,
> +                                  struct amdgpu_bo_va_mapping *mapping)
> +{
> +     struct interval_tree_node *pending;
> +
> +     if (interval_tree_iter_first(&ctx->pending_maps, mapping->start,
> +                                  mapping->last))
> +             return -EINVAL;
> +
> +     pending = kzalloc_obj(*pending);
> +     if (!pending)
> +             return -ENOMEM;
> +
> +     if (interval_tree_iter_first(&ctx->pending_maps, mapping->start,
> +                                  mapping->last))
> +             return -EINVAL;

[Severity: Low]
Is this second interval_tree_iter_first() check redundant, and would it
leak pending if ever taken?  ctx->pending_maps is not modified since the
identical check before kzalloc_obj(), and returning -EINVAL here skips
kfree(pending).

> +
> +     pending->start = mapping->start;
> +     pending->last = mapping->last;
> +     interval_tree_insert(pending, &ctx->pending_maps);

[Severity: Medium]
Can using struct interval_tree_node here truncate 64-bit GPU page frame
numbers on 32-bit architectures?

mapping->start and mapping->last are uint64_t PFNs (which is why amdgpu_vm.c
defines amdgpu_vm_it with uint64_t via INTERVAL_TREE_DEFINE), whereas
struct interval_tree_node and interval_tree_iter_first() use unsigned long.
On 32-bit builds, GPU virtual addresses at or above 16 TiB (PFN >= 1ULL << 32)
have their upper 32 bits truncated when querying and inserting into
ctx->pending_maps, which can cause false -EINVAL conflicts, missed overlaps,
or inverted intervals where pending->start > pending->last.

While a mapping is pending on ctx->new prior to amdgpu_vm_bo_commit_insert(),
its embedded rb and uint64_t start/last/__subtree_last fields are unused, so
inserting mapping directly into ctx->pending_maps via the amdgpu_vm_it
helpers would also avoid allocating pending.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
> index 8445599d9539a..d35494440cb5a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
> @@ -279,6 +279,16 @@ struct amdgpu_vm_update_ctx {
>        */
>       struct amdgpu_vm *vm;
>  
> +     /**
> +      * @mapped_intervals: Interval tree of VA ranges mapped by this update 
> operation.
> +      */
> +     struct rb_root_cached pending_maps;

[Severity: Low]
The kernel-doc tag @mapped_intervals does not match the struct member name
pending_maps, which triggers a scripts/kernel-doc warning.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=3

Reply via email to