Skip to content

Commit f5e7fab

Browse files
ChristianKoenigAMDalexdeucher
authored andcommitted
drm/amdgpu: allow pinning DMA-bufs into VRAM if all importers can do P2P
Try pinning into VRAM to allow P2P with RDMA NICs without ODP support if all attachments can do P2P. If any attachment can't do P2P just pin into GTT instead. Acked-by: Simona Vetter <[email protected]> Signed-off-by: Christian König <[email protected]> Signed-off-by: Felix Kuehling <[email protected]> Reviewed-by: Felix Kuehling <[email protected]> Tested-by: Pak Nin Lui <[email protected]> Cc: Simona Vetter <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 1b5447d commit f5e7fab

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,25 @@ static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf,
7575
*/
7676
static int amdgpu_dma_buf_pin(struct dma_buf_attachment *attach)
7777
{
78-
struct drm_gem_object *obj = attach->dmabuf->priv;
79-
struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
78+
struct dma_buf *dmabuf = attach->dmabuf;
79+
struct amdgpu_bo *bo = gem_to_amdgpu_bo(dmabuf->priv);
80+
u32 domains = bo->preferred_domains;
8081

81-
/* pin buffer into GTT */
82-
return amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT);
82+
dma_resv_assert_held(dmabuf->resv);
83+
84+
/*
85+
* Try pinning into VRAM to allow P2P with RDMA NICs without ODP
86+
* support if all attachments can do P2P. If any attachment can't do
87+
* P2P just pin into GTT instead.
88+
*/
89+
list_for_each_entry(attach, &dmabuf->attachments, node)
90+
if (!attach->peer2peer)
91+
domains &= ~AMDGPU_GEM_DOMAIN_VRAM;
92+
93+
if (domains & AMDGPU_GEM_DOMAIN_VRAM)
94+
bo->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
95+
96+
return amdgpu_bo_pin(bo, domains);
8397
}
8498

8599
/**
@@ -134,9 +148,6 @@ static struct sg_table *amdgpu_dma_buf_map(struct dma_buf_attachment *attach,
134148
r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
135149
if (r)
136150
return ERR_PTR(r);
137-
138-
} else if (bo->tbo.resource->mem_type != TTM_PL_TT) {
139-
return ERR_PTR(-EBUSY);
140151
}
141152

142153
switch (bo->tbo.resource->mem_type) {

0 commit comments

Comments
 (0)