Skip to content

Commit a92741e

Browse files
fxkamdalexdeucher
authored andcommitted
drm/amdgpu: Allow P2P access through XGMI
If peer memory is accessible through XGMI, allow leaving it in VRAM rather than forcing its migration to GTT on DMABuf attachment. Signed-off-by: Felix Kuehling <felix.kuehling@amd.com> Tested-by: Hao (Claire) Zhou <hao.zhou@amd.com> Reviewed-by: Christian König <christian.koenig@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 372c8d7)
1 parent 756c85e commit a92741e

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,29 @@
4343
#include <linux/dma-fence-array.h>
4444
#include <linux/pci-p2pdma.h>
4545

46+
static const struct dma_buf_attach_ops amdgpu_dma_buf_attach_ops;
47+
48+
/**
49+
* dma_buf_attach_adev - Helper to get adev of an attachment
50+
*
51+
* @attach: attachment
52+
*
53+
* Returns:
54+
* A struct amdgpu_device * if the attaching device is an amdgpu device or
55+
* partition, NULL otherwise.
56+
*/
57+
static struct amdgpu_device *dma_buf_attach_adev(struct dma_buf_attachment *attach)
58+
{
59+
if (attach->importer_ops == &amdgpu_dma_buf_attach_ops) {
60+
struct drm_gem_object *obj = attach->importer_priv;
61+
struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
62+
63+
return amdgpu_ttm_adev(bo->tbo.bdev);
64+
}
65+
66+
return NULL;
67+
}
68+
4669
/**
4770
* amdgpu_dma_buf_attach - &dma_buf_ops.attach implementation
4871
*
@@ -54,11 +77,13 @@
5477
static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf,
5578
struct dma_buf_attachment *attach)
5679
{
80+
struct amdgpu_device *attach_adev = dma_buf_attach_adev(attach);
5781
struct drm_gem_object *obj = dmabuf->priv;
5882
struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
5983
struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
6084

61-
if (pci_p2pdma_distance(adev->pdev, attach->dev, false) < 0)
85+
if (!amdgpu_dmabuf_is_xgmi_accessible(attach_adev, bo) &&
86+
pci_p2pdma_distance(adev->pdev, attach->dev, false) < 0)
6287
attach->peer2peer = false;
6388

6489
amdgpu_vm_bo_update_shared(bo);
@@ -480,6 +505,9 @@ bool amdgpu_dmabuf_is_xgmi_accessible(struct amdgpu_device *adev,
480505
struct drm_gem_object *obj = &bo->tbo.base;
481506
struct drm_gem_object *gobj;
482507

508+
if (!adev)
509+
return false;
510+
483511
if (obj->import_attach) {
484512
struct dma_buf *dma_buf = obj->import_attach->dmabuf;
485513

0 commit comments

Comments
 (0)