RE: [PATCH v2] drm/amdgpu: bind imported BOs before mapping them into a VM

"Zhang, Yifan" <[email protected]>
Newsgroups org.freedesktop.lists.amd-gfx
Message-ID <CY5PR12MB636936558E2C3AB838F05C91C1DC2@CY5PR12MB6369.namprd12.prod.outlook.com>
AMD General

Hi Christian,

v3 moves the validation into amdgpu_gem_object_open() as you suggested,so imports are bound once at open time and graphics and compute VMs follow the same rule.

I couldn't find the earlier patches you mentioned on the list, so this is a fresh implementation. Please let me know if I missed them.

Best Regards,
Yifan

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, August 11, 2026 8:28 PM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Yuan, Perry <[email protected]>; Ghosh, Prerona <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: bind imported BOs before mapping them into a VM

On 8/11/26 10:07, Yifan Zhang wrote:
> From: Prerona Ghosh <[email protected]>
>
> An imported dma-buf with a dynamic attachment is not bound to GTT
> until it is validated. In a VM that is not a KFD compute context
> nothing does
> that: amdgpu_gem_object_open() only validates and fences imports for
> compute VMs, and clients submitting through HW queues never go through
> amdgpu_cs, so amdgpu_vm_validate() does not run either.

Well that is a good catch, but clear NAK to this hacky workaround.

I suggested a long time ago already to change this behavior and validate inside amdgpu_gem_object_open(), IIRC we even had patches for that on the mailing list.

Did we accidentally dropped those?

Regards,
Christian.

>
> AMDGPU_GEM_VA then maps the BO while its resource is still
> TTM_PL_SYSTEM. amdgpu_ttm_tt_pde_flags() drops AMDGPU_PTE_VALID and
> AMDGPU_PTE_SYSTEM for that memory type, so the range is programmed
> with PTE flags 0x60 (readable and writeable only) and the first GPU
> access to it faults:
>
>  amdgpu 0000:26:00.0: [gfxhub0] retry page fault (src_id:0 ring:0 vmid:3 pasid:46)
>  amdgpu 0000:26:00.0:   in page starting at address 0x00007f142d6d8000 from IH client 0x1b (UTCL2)
>  amdgpu 0000:26:00.0: VM_L2_PROTECTION_FAULT_STATUS:0x00301011
>  amdgpu 0000:26:00.0:      Faulty UTCL2 client ID: TCP (0x8)
>  amdgpu 0000:26:00.0:      PERMISSION_FAULTS: 0x1
>
> Validate imported BOs into their allowed domains before MAP and
> REPLACE so that the mapping is always created from a bound resource.
>
> Signed-off-by: Yifan Zhang <[email protected]>
> Assisted-by: Claude:opus-5
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 29
> +++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> index f754a4a3a1c2..214ae2a95da2 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> @@ -747,6 +747,27 @@ int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
>       return r;
>  }
>
> +/**
> + * amdgpu_gem_va_make_resident - bind an imported BO before it gets
> +mapped
> + *
> + * @bo: the BO about to be mapped into a VM
> + *
> + * Imported dma-bufs with a dynamic attachment stay unbound until
> +they are
> + * validated. Mapping one while it is still in TTM_PL_SYSTEM would
> +program
> + * PTEs without AMDGPU_PTE_VALID and any GPU access to them faults.
> + */
> +static int amdgpu_gem_va_make_resident(struct amdgpu_bo *bo) {
> +     struct ttm_operation_ctx ctx = { true, false };
> +
> +     if (bo->tbo.resource &&
> +         bo->tbo.resource->mem_type != TTM_PL_SYSTEM)
> +             return 0;
> +
> +     amdgpu_bo_placement_from_domain(bo, bo->allowed_domains);
> +     return ttm_bo_validate(&bo->tbo, &bo->placement, &ctx); }
> +
>  /**
>   * amdgpu_gem_va_update_vm -update the bo_va in its VM
>   *
> @@ -962,6 +983,14 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
>       if (r)
>               goto error;
>
> +     if (abo && drm_gem_is_imported(&abo->tbo.base) &&
> +         (args->operation == AMDGPU_VA_OP_MAP ||
> +          args->operation == AMDGPU_VA_OP_REPLACE)) {
> +             r = amdgpu_gem_va_make_resident(abo);
> +             if (r)
> +                     goto error;
> +     }
> +
>       switch (args->operation) {
>       case AMDGPU_VA_OP_MAP:
>               r = amdgpu_vm_bo_map(adev, bo_va, args->va_address,
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.