|
43 | 43 | #include <linux/dma-fence-array.h> |
44 | 44 | #include <linux/pci-p2pdma.h> |
45 | 45 |
|
| 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 | + |
46 | 69 | /** |
47 | 70 | * amdgpu_dma_buf_attach - &dma_buf_ops.attach implementation |
48 | 71 | * |
|
54 | 77 | static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf, |
55 | 78 | struct dma_buf_attachment *attach) |
56 | 79 | { |
| 80 | + struct amdgpu_device *attach_adev = dma_buf_attach_adev(attach); |
57 | 81 | struct drm_gem_object *obj = dmabuf->priv; |
58 | 82 | struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj); |
59 | 83 | struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev); |
60 | 84 |
|
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) |
62 | 87 | attach->peer2peer = false; |
63 | 88 |
|
64 | 89 | amdgpu_vm_bo_update_shared(bo); |
@@ -480,6 +505,9 @@ bool amdgpu_dmabuf_is_xgmi_accessible(struct amdgpu_device *adev, |
480 | 505 | struct drm_gem_object *obj = &bo->tbo.base; |
481 | 506 | struct drm_gem_object *gobj; |
482 | 507 |
|
| 508 | + if (!adev) |
| 509 | + return false; |
| 510 | + |
483 | 511 | if (obj->import_attach) { |
484 | 512 | struct dma_buf *dma_buf = obj->import_attach->dmabuf; |
485 | 513 |
|
|
0 commit comments