* [PATCH 1/2] drm/amdkfd: Get foreign dma-buf info
@ 2026-10-23 14:48 Xiaogang.Chen
2026-10-23 14:48 ` [PATCH 2/2] drm/amdgpu: Redirect imported dma-buf mmap request to exporter Xiaogang.Chen
2026-10-27 9:02 ` [PATCH 1/2] drm/amdkfd: Get foreign dma-buf info Christian König
0 siblings, 2 replies; 5+ messages in thread
From: Xiaogang.Chen @ 2026-10-23 14:48 UTC (permalink / raw)
To: amd-gfx; +Cc: Xiaogang Chen
From: Xiaogang Chen <xiaogang.chen@amd.com>
When import a dma-buf into kfd driver the dma-buf can be exported from amdgpu
driver or another driver/component(foreign).
Current kfd driver can't handle foreign dma-buf at AMDKFD_IOC_GET_DMABUF_INFO.
When a foreign dma-buf is imported into kfd driver(ex udmabuf) it becomes a
normal kfd buf that can be exported, then imported in same or another amdgpu
device. That requires kfd drive to get new exported dma-buf info before it is
imported.
Extend kfd_ioctl_get_dmabuf_info to handle args->dmabuf_fd that was originally
exported by foreign component.
Signed-off-by: Xiaogang Chen <xiaogang.chen@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 3 ++
.../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 47 +++++++++++++++++++
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 11 ++++-
3 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index e3da382ceb3c..170f0ea0b78a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -347,6 +347,9 @@ int amdgpu_amdkfd_gpuvm_import_dmabuf_fd(struct amdgpu_device *adev, int fd,
uint64_t va, void *drm_priv,
struct kgd_mem **mem, uint64_t *size,
uint64_t *mmap_offset);
+int amdgpu_amdkfd_gpuvm_imported_dmabuf_info(void *kgd_info, int fd,
+ uint64_t *size, uint32_t *flags,
+ uint32_t *gpu_id);
int amdgpu_amdkfd_gpuvm_export_dmabuf(struct kgd_mem *mem,
struct dma_buf **dmabuf);
void amdgpu_amdkfd_debug_mem_fence(struct amdgpu_device *adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index a5d1d83ee5d3..b7fea3a2f5ca 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -2452,6 +2452,53 @@ static int import_obj_create(struct amdgpu_device *adev,
return ret;
}
+int amdgpu_amdkfd_gpuvm_imported_dmabuf_info(void *kgd_info, int fd,
+ uint64_t *size, uint32_t *flags,
+ uint32_t *gpu_id)
+{
+ struct amdkfd_process_info *info = kgd_info;
+ struct dma_buf *dma_buf;
+ struct kgd_mem *mem;
+ int ret = -EINVAL;
+
+ if (!info)
+ return -EINVAL;
+
+ dma_buf = dma_buf_get(fd);
+ if (IS_ERR(dma_buf))
+ return PTR_ERR(dma_buf);
+
+ mutex_lock(&info->lock);
+ list_for_each_entry(mem, &info->kfd_bo_list, validate_list) {
+ struct amdgpu_device *bo_adev;
+ struct kfd_dev *kfd;
+ int8_t xcp_id;
+
+ if (!mem->is_imported || mem->dmabuf != dma_buf)
+ continue;
+
+ if (size)
+ *size = amdgpu_bo_size(mem->bo);
+ if (flags)
+ *flags = mem->alloc_flags;
+ if (gpu_id) {
+ bo_adev = amdgpu_ttm_adev(mem->bo->tbo.bdev);
+ kfd = bo_adev->kfd.dev;
+ xcp_id = mem->bo->xcp_id;
+ if (kfd && xcp_id >= 0 && xcp_id < kfd->num_nodes &&
+ kfd->nodes[xcp_id])
+ *gpu_id = kfd->nodes[xcp_id]->id;
+ else if (kfd && kfd->num_nodes && kfd->nodes[0])
+ *gpu_id = kfd->nodes[0]->id;
+ }
+ ret = 0;
+ break;
+ }
+ mutex_unlock(&info->lock);
+ dma_buf_put(dma_buf);
+ return ret;
+}
+
int amdgpu_amdkfd_gpuvm_import_dmabuf_fd(struct amdgpu_device *adev, int fd,
uint64_t va, void *drm_priv,
struct kgd_mem **mem, uint64_t *size,
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 1d86ddfd6bde..9ca20331e815 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -1595,8 +1595,17 @@ static int kfd_ioctl_get_dmabuf_info(struct file *filep,
&dmabuf_adev, &args->size,
&metadata_buffer, args->metadata_size,
&args->metadata_size, &flags, &xcp_id);
- if (r)
+ if (r) {
+ /* Foreign dma-buf: report it when this process imported it. */
+ r = amdgpu_amdkfd_gpuvm_imported_dmabuf_info(p->kgd_process_info,
+ args->dmabuf_fd,
+ &args->size,
+ &args->flags,
+ &args->gpu_id);
+ if (!r)
+ args->metadata_size = 0;
goto exit;
+ }
if (xcp_id >= 0)
args->gpu_id = dmabuf_adev->kfd.dev->nodes[xcp_id]->id;
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] drm/amdgpu: Redirect imported dma-buf mmap request to exporter
2026-10-23 14:48 [PATCH 1/2] drm/amdkfd: Get foreign dma-buf info Xiaogang.Chen
@ 2026-10-23 14:48 ` Xiaogang.Chen
2026-10-27 9:00 ` Christian König
2026-10-27 9:02 ` [PATCH 1/2] drm/amdkfd: Get foreign dma-buf info Christian König
1 sibling, 1 reply; 5+ messages in thread
From: Xiaogang.Chen @ 2026-10-23 14:48 UTC (permalink / raw)
To: amd-gfx; +Cc: Xiaogang Chen
From: Xiaogang Chen <xiaogang.chen@amd.com>
The imported GEM object with ttm->page_flags TTM_TT_FLAG_EXTERNAL set and
without TTM_TT_FLAG_EXTERNAL_MAPPABLE set,is only a GPU-side handle for memory
that belongs to the exporter. TTM refuses to build a CPU mapping from it
because those page-table entries would point to pages drm driver does not own.
amdgpu_dma_buf_create_obj creates GEM object for foreign exported buf(not
generated by amdgpu driver) belonging to this catagory. The pages, when GPU
needs them, come from dma_buf_map_attachment on the exporter's scatter/gather
table. The exporter can move or revoke that mapping through move_notify.
A CPU page-table entry installed by the importer would keep the old PFN, and
the importer also does not know the exporter's caching mode or whether the
memory is CPU-visible.
This patch redirects foreign imported dma-buf mmap request to exporter. The
CPU mapping is created by dma_buf_mmap, which points the VMA to the exporter's
file and calls dma_buf->ops->mmap. The exporter's fault handler will fill
page table.
Signed-off-by: Xiaogang Chen <xiaogang.chen@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 4e4814caf61a..d872b4bcb5fc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -369,6 +369,26 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj,
static int amdgpu_gem_object_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
{
struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
+ struct dma_buf *dmabuf;
+ int ret;
+
+ /*
+ * A foreign import (udmabuf, for example) does not own the pages.
+ * Point the VMA at the exporter so the later CPU fault uses its
+ * vm_ops. dma_buf_mmap() resets vm_pgoff and holds the dma-buf file.
+ * An amdgpu dma-buf stays on the TTM path below.
+ */
+ dmabuf = obj->import_attach ? obj->import_attach->dmabuf : NULL;
+ if (dmabuf && dmabuf->ops != &amdgpu_dmabuf_ops) {
+ ret = dma_buf_mmap(dmabuf, vma, 0);
+ if (ret)
+ return ret;
+
+ /* Exporter vm_ops will not drop the mapping reference. */
+ drm_gem_object_put(obj);
+ return 0;
+ }
+
if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm))
return -EPERM;
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] drm/amdgpu: Redirect imported dma-buf mmap request to exporter
2026-10-23 14:48 ` [PATCH 2/2] drm/amdgpu: Redirect imported dma-buf mmap request to exporter Xiaogang.Chen
@ 2026-10-27 9:00 ` Christian König
0 siblings, 0 replies; 5+ messages in thread
From: Christian König @ 2026-10-27 9:00 UTC (permalink / raw)
To: Xiaogang.Chen, amd-gfx
On 10/23/26 16:48, Xiaogang.Chen wrote:
> From: Xiaogang Chen <xiaogang.chen@amd.com>
>
> The imported GEM object with ttm->page_flags TTM_TT_FLAG_EXTERNAL set and
> without TTM_TT_FLAG_EXTERNAL_MAPPABLE set,is only a GPU-side handle for memory
> that belongs to the exporter. TTM refuses to build a CPU mapping from it
> because those page-table entries would point to pages drm driver does not own.
>
> amdgpu_dma_buf_create_obj creates GEM object for foreign exported buf(not
> generated by amdgpu driver) belonging to this catagory. The pages, when GPU
> needs them, come from dma_buf_map_attachment on the exporter's scatter/gather
> table. The exporter can move or revoke that mapping through move_notify.
> A CPU page-table entry installed by the importer would keep the old PFN, and
> the importer also does not know the exporter's caching mode or whether the
> memory is CPU-visible.
>
> This patch redirects foreign imported dma-buf mmap request to exporter. The
> CPU mapping is created by dma_buf_mmap, which points the VMA to the exporter's
> file and calls dma_buf->ops->mmap. The exporter's fault handler will fill
> page table.
We had that suggestion many times before and it is only allowed as a backward compatibility hack for a handful of DRM drivers to do this.
If the imported DMA-buf needs to be mmaped() that *must* be done either on the exporter or the DMA-buf file descriptor itself.
So absolutely clear NAK to that!
Regards,
Christian.
>
> Signed-off-by: Xiaogang Chen <xiaogang.chen@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> index 4e4814caf61a..d872b4bcb5fc 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> @@ -369,6 +369,26 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj,
> static int amdgpu_gem_object_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
> {
> struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
> + struct dma_buf *dmabuf;
> + int ret;
> +
> + /*
> + * A foreign import (udmabuf, for example) does not own the pages.
> + * Point the VMA at the exporter so the later CPU fault uses its
> + * vm_ops. dma_buf_mmap() resets vm_pgoff and holds the dma-buf file.
> + * An amdgpu dma-buf stays on the TTM path below.
> + */
> + dmabuf = obj->import_attach ? obj->import_attach->dmabuf : NULL;
> + if (dmabuf && dmabuf->ops != &amdgpu_dmabuf_ops) {
> + ret = dma_buf_mmap(dmabuf, vma, 0);
> + if (ret)
> + return ret;
> +
> + /* Exporter vm_ops will not drop the mapping reference. */
> + drm_gem_object_put(obj);
> + return 0;
> + }
> +
>
> if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm))
> return -EPERM;
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] drm/amdkfd: Get foreign dma-buf info
2026-10-23 14:48 [PATCH 1/2] drm/amdkfd: Get foreign dma-buf info Xiaogang.Chen
2026-10-23 14:48 ` [PATCH 2/2] drm/amdgpu: Redirect imported dma-buf mmap request to exporter Xiaogang.Chen
@ 2026-10-27 9:02 ` Christian König
2026-10-27 16:38 ` Chen, Xiaogang
1 sibling, 1 reply; 5+ messages in thread
From: Christian König @ 2026-10-27 9:02 UTC (permalink / raw)
To: Xiaogang.Chen, amd-gfx
On 10/23/26 16:48, Xiaogang.Chen wrote:
> From: Xiaogang Chen <xiaogang.chen@amd.com>
>
> When import a dma-buf into kfd driver the dma-buf can be exported from amdgpu
> driver or another driver/component(foreign).
>
> Current kfd driver can't handle foreign dma-buf at AMDKFD_IOC_GET_DMABUF_INFO.
> When a foreign dma-buf is imported into kfd driver(ex udmabuf) it becomes a
> normal kfd buf that can be exported, then imported in same or another amdgpu
> device. That requires kfd drive to get new exported dma-buf info before it is
> imported.
Yeah again absolutely clear NAK to that!
Re-exporting the imported DMA-buf this way is *clearly* not allowed!
What you can do is to re-export the original DMA-buf so that you get the same fd you would get from the original exporter.
In other words you can then also ask the original exporter for that information.
Regards,
Christian.
>
> Extend kfd_ioctl_get_dmabuf_info to handle args->dmabuf_fd that was originally
> exported by foreign component.
>
> Signed-off-by: Xiaogang Chen <xiaogang.chen@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 3 ++
> .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 47 +++++++++++++++++++
> drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 11 ++++-
> 3 files changed, 60 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
> index e3da382ceb3c..170f0ea0b78a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
> @@ -347,6 +347,9 @@ int amdgpu_amdkfd_gpuvm_import_dmabuf_fd(struct amdgpu_device *adev, int fd,
> uint64_t va, void *drm_priv,
> struct kgd_mem **mem, uint64_t *size,
> uint64_t *mmap_offset);
> +int amdgpu_amdkfd_gpuvm_imported_dmabuf_info(void *kgd_info, int fd,
> + uint64_t *size, uint32_t *flags,
> + uint32_t *gpu_id);
> int amdgpu_amdkfd_gpuvm_export_dmabuf(struct kgd_mem *mem,
> struct dma_buf **dmabuf);
> void amdgpu_amdkfd_debug_mem_fence(struct amdgpu_device *adev);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index a5d1d83ee5d3..b7fea3a2f5ca 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -2452,6 +2452,53 @@ static int import_obj_create(struct amdgpu_device *adev,
> return ret;
> }
>
> +int amdgpu_amdkfd_gpuvm_imported_dmabuf_info(void *kgd_info, int fd,
> + uint64_t *size, uint32_t *flags,
> + uint32_t *gpu_id)
> +{
> + struct amdkfd_process_info *info = kgd_info;
> + struct dma_buf *dma_buf;
> + struct kgd_mem *mem;
> + int ret = -EINVAL;
> +
> + if (!info)
> + return -EINVAL;
> +
> + dma_buf = dma_buf_get(fd);
> + if (IS_ERR(dma_buf))
> + return PTR_ERR(dma_buf);
> +
> + mutex_lock(&info->lock);
> + list_for_each_entry(mem, &info->kfd_bo_list, validate_list) {
> + struct amdgpu_device *bo_adev;
> + struct kfd_dev *kfd;
> + int8_t xcp_id;
> +
> + if (!mem->is_imported || mem->dmabuf != dma_buf)
> + continue;
> +
> + if (size)
> + *size = amdgpu_bo_size(mem->bo);
> + if (flags)
> + *flags = mem->alloc_flags;
> + if (gpu_id) {
> + bo_adev = amdgpu_ttm_adev(mem->bo->tbo.bdev);
> + kfd = bo_adev->kfd.dev;
> + xcp_id = mem->bo->xcp_id;
> + if (kfd && xcp_id >= 0 && xcp_id < kfd->num_nodes &&
> + kfd->nodes[xcp_id])
> + *gpu_id = kfd->nodes[xcp_id]->id;
> + else if (kfd && kfd->num_nodes && kfd->nodes[0])
> + *gpu_id = kfd->nodes[0]->id;
> + }
> + ret = 0;
> + break;
> + }
> + mutex_unlock(&info->lock);
> + dma_buf_put(dma_buf);
> + return ret;
> +}
> +
> int amdgpu_amdkfd_gpuvm_import_dmabuf_fd(struct amdgpu_device *adev, int fd,
> uint64_t va, void *drm_priv,
> struct kgd_mem **mem, uint64_t *size,
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> index 1d86ddfd6bde..9ca20331e815 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> @@ -1595,8 +1595,17 @@ static int kfd_ioctl_get_dmabuf_info(struct file *filep,
> &dmabuf_adev, &args->size,
> &metadata_buffer, args->metadata_size,
> &args->metadata_size, &flags, &xcp_id);
> - if (r)
> + if (r) {
> + /* Foreign dma-buf: report it when this process imported it. */
> + r = amdgpu_amdkfd_gpuvm_imported_dmabuf_info(p->kgd_process_info,
> + args->dmabuf_fd,
> + &args->size,
> + &args->flags,
> + &args->gpu_id);
> + if (!r)
> + args->metadata_size = 0;
> goto exit;
> + }
>
> if (xcp_id >= 0)
> args->gpu_id = dmabuf_adev->kfd.dev->nodes[xcp_id]->id;
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] drm/amdkfd: Get foreign dma-buf info
2026-10-27 9:02 ` [PATCH 1/2] drm/amdkfd: Get foreign dma-buf info Christian König
@ 2026-10-27 16:38 ` Chen, Xiaogang
0 siblings, 0 replies; 5+ messages in thread
From: Chen, Xiaogang @ 2026-10-27 16:38 UTC (permalink / raw)
To: Christian König, amd-gfx
[-- Attachment #1: Type: text/plain, Size: 5629 bytes --]
On 10/27/2026 4:02 AM, Christian König wrote:
>
> On 10/23/26 16:48, Xiaogang.Chen wrote:
>> From: Xiaogang Chen<xiaogang.chen@amd.com>
>>
>> When import a dma-buf into kfd driver the dma-buf can be exported from amdgpu
>> driver or another driver/component(foreign).
>>
>> Current kfd driver can't handle foreign dma-buf at AMDKFD_IOC_GET_DMABUF_INFO.
>> When a foreign dma-buf is imported into kfd driver(ex udmabuf) it becomes a
>> normal kfd buf that can be exported, then imported in same or another amdgpu
>> device. That requires kfd drive to get new exported dma-buf info before it is
>> imported.
> Yeah again absolutely clear NAK to that!
>
> Re-exporting the imported DMA-buf this way is *clearly* not allowed!
This "Re-exporting" is from driver point view. App exports only once.
The original buf was generated by Thunk using foreign driver/component
exported buf when app allocates buf. Driver sees "exporting the imported
DMA-buf", app does not. App uses same routine to handle it as for normal
kfd buf.
>
> What you can do is to re-export the original DMA-buf so that you get the same fd you would get from the original exporter.
>
> In other words you can then also ask the original exporter for that information.
During the procedure there is only one dma-buf instance which was
generated by foreign driver/component. kfd does not generate new dma-buf
instance. It saves this dma-buf instance. kfd generates a "struct
kgd_mem" to wrap this dma-buf instance and record its metadata. Then
dma-buf info is obtained from this "struct kgd_mem".
Regards
Xiaogang
>
> Regards,
> Christian.
>
>> Extend kfd_ioctl_get_dmabuf_info to handle args->dmabuf_fd that was originally
>> exported by foreign component.
>>
>> Signed-off-by: Xiaogang Chen<xiaogang.chen@amd.com>
>> ---
>> drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 3 ++
>> .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 47 +++++++++++++++++++
>> drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 11 ++++-
>> 3 files changed, 60 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
>> index e3da382ceb3c..170f0ea0b78a 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
>> @@ -347,6 +347,9 @@ int amdgpu_amdkfd_gpuvm_import_dmabuf_fd(struct amdgpu_device *adev, int fd,
>> uint64_t va, void *drm_priv,
>> struct kgd_mem **mem, uint64_t *size,
>> uint64_t *mmap_offset);
>> +int amdgpu_amdkfd_gpuvm_imported_dmabuf_info(void *kgd_info, int fd,
>> + uint64_t *size, uint32_t *flags,
>> + uint32_t *gpu_id);
>> int amdgpu_amdkfd_gpuvm_export_dmabuf(struct kgd_mem *mem,
>> struct dma_buf **dmabuf);
>> void amdgpu_amdkfd_debug_mem_fence(struct amdgpu_device *adev);
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>> index a5d1d83ee5d3..b7fea3a2f5ca 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>> @@ -2452,6 +2452,53 @@ static int import_obj_create(struct amdgpu_device *adev,
>> return ret;
>> }
>>
>> +int amdgpu_amdkfd_gpuvm_imported_dmabuf_info(void *kgd_info, int fd,
>> + uint64_t *size, uint32_t *flags,
>> + uint32_t *gpu_id)
>> +{
>> + struct amdkfd_process_info *info = kgd_info;
>> + struct dma_buf *dma_buf;
>> + struct kgd_mem *mem;
>> + int ret = -EINVAL;
>> +
>> + if (!info)
>> + return -EINVAL;
>> +
>> + dma_buf = dma_buf_get(fd);
>> + if (IS_ERR(dma_buf))
>> + return PTR_ERR(dma_buf);
>> +
>> + mutex_lock(&info->lock);
>> + list_for_each_entry(mem, &info->kfd_bo_list, validate_list) {
>> + struct amdgpu_device *bo_adev;
>> + struct kfd_dev *kfd;
>> + int8_t xcp_id;
>> +
>> + if (!mem->is_imported || mem->dmabuf != dma_buf)
>> + continue;
>> +
>> + if (size)
>> + *size = amdgpu_bo_size(mem->bo);
>> + if (flags)
>> + *flags = mem->alloc_flags;
>> + if (gpu_id) {
>> + bo_adev = amdgpu_ttm_adev(mem->bo->tbo.bdev);
>> + kfd = bo_adev->kfd.dev;
>> + xcp_id = mem->bo->xcp_id;
>> + if (kfd && xcp_id >= 0 && xcp_id < kfd->num_nodes &&
>> + kfd->nodes[xcp_id])
>> + *gpu_id = kfd->nodes[xcp_id]->id;
>> + else if (kfd && kfd->num_nodes && kfd->nodes[0])
>> + *gpu_id = kfd->nodes[0]->id;
>> + }
>> + ret = 0;
>> + break;
>> + }
>> + mutex_unlock(&info->lock);
>> + dma_buf_put(dma_buf);
>> + return ret;
>> +}
>> +
>> int amdgpu_amdkfd_gpuvm_import_dmabuf_fd(struct amdgpu_device *adev, int fd,
>> uint64_t va, void *drm_priv,
>> struct kgd_mem **mem, uint64_t *size,
>> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
>> index 1d86ddfd6bde..9ca20331e815 100644
>> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
>> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
>> @@ -1595,8 +1595,17 @@ static int kfd_ioctl_get_dmabuf_info(struct file *filep,
>> &dmabuf_adev, &args->size,
>> &metadata_buffer, args->metadata_size,
>> &args->metadata_size, &flags, &xcp_id);
>> - if (r)
>> + if (r) {
>> + /* Foreign dma-buf: report it when this process imported it. */
>> + r = amdgpu_amdkfd_gpuvm_imported_dmabuf_info(p->kgd_process_info,
>> + args->dmabuf_fd,
>> + &args->size,
>> + &args->flags,
>> + &args->gpu_id);
>> + if (!r)
>> + args->metadata_size = 0;
>> goto exit;
>> + }
>>
>> if (xcp_id >= 0)
>> args->gpu_id = dmabuf_adev->kfd.dev->nodes[xcp_id]->id;
[-- Attachment #2: Type: text/html, Size: 6844 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-10-27 16:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-23 14:48 [PATCH 1/2] drm/amdkfd: Get foreign dma-buf info Xiaogang.Chen
2026-10-23 14:48 ` [PATCH 2/2] drm/amdgpu: Redirect imported dma-buf mmap request to exporter Xiaogang.Chen
2026-10-27 9:00 ` Christian König
2026-10-27 9:02 ` [PATCH 1/2] drm/amdkfd: Get foreign dma-buf info Christian König
2026-10-27 16:38 ` Chen, Xiaogang
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.