All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: Yifan Zhang <yifan1.zhang@amd.com>, amd-gfx@lists.freedesktop.org
Cc: Alexander.Deucher@amd.com, Perry.Yuan@amd.com,
	Prerona Ghosh <Prerona.Ghosh@amd.com>
Subject: Re: [PATCH v2] drm/amdgpu: bind imported BOs before mapping them into a VM
Date: Tue, 11 Aug 2026 14:27:58 +0200	[thread overview]
Message-ID: <d2d08abf-989d-4e88-a69e-a8ab1ffd4cb1@amd.com> (raw)
In-Reply-To: <20260811080717.547510-1-yifan1.zhang@amd.com>

On 8/11/26 10:07, Yifan Zhang wrote:
> From: Prerona Ghosh <Prerona.Ghosh@amd.com>
> 
> 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 <yifan1.zhang@amd.com>
> 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,


  reply	other threads:[~2026-08-11 12:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-11  8:07 [PATCH v2] drm/amdgpu: bind imported BOs before mapping them into a VM Yifan Zhang
2026-08-11 12:27 ` Christian König [this message]
2026-08-12  7:16   ` Zhang, Yifan

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=d2d08abf-989d-4e88-a69e-a8ab1ffd4cb1@amd.com \
    --to=christian.koenig@amd.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Perry.Yuan@amd.com \
    --cc=Prerona.Ghosh@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=yifan1.zhang@amd.com \
    /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.