[PATCH 58/95] drm/amdgpu: Handle local GPUs in UALink import
Alex Deucher <[email protected]>
| Newsgroups | org.freedesktop.lists.amd-gfx |
|---|---|
| Message-ID | <[email protected]> |
From: Mukul Joshi <[email protected]> When the remote GPU is part of the local_accels array (same physical pod), bypass the HELLO/NPA-REQ messaging protocol and directly look up the exported BO in the peer's exporter xarray. Export it as a DMA-buf and return the fd to user-space without creating an importer xarray entry. Signed-off-by: Mukul Joshi <[email protected]> Reviewed-by: Felix Kuehling <[email protected]> Signed-off-by: Alex Deucher <[email protected]> --- drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c index 57332243ea027..cd9ee0484f9c2 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c @@ -28,6 +28,7 @@ #include "amdgpu.h" #include "amdgpu_ualink.h" #include "amdgpu_xgmi.h" +#include "amdgpu_dma_buf.h" #include <linux/sysfs.h> #include <linux/string.h> @@ -610,6 +611,22 @@ static struct amdgpu_device *find_peer_adev(unsigned int accel_id) return NULL; } +static bool amdgpu_ualink_is_local_accel(struct amdgpu_device *adev, + u32 accel_id) +{ + struct amdgpu_ualink_info *info = adev->ualink.info; + unsigned int i; + + if (!info) + return false; + + for (i = 0; i < info->n_local_accels; i++) { + if (info->local_accels[i] == accel_id) + return true; + } + return false; +} + static bool check_local_vpod_integrity(struct amdgpu_device *adev) { struct amdgpu_ualink_info *info = adev->ualink.info; @@ -3055,6 +3072,55 @@ static int amdgpu_ualink_do_import_handle(struct amdgpu_device *adev, return r; } +static int amdgpu_ualink_local_import(struct amdgpu_device *adev, + u32 remote_acc_id, + struct amdgpu_ualink_handle *handle, + int *fd_out) +{ + struct amdgpu_ualink_exp_xa_node *exp_xa_node; + struct amdgpu_device *peer_adev; + int fd; + + mutex_lock(&mgpu_info.mutex); + peer_adev = find_peer_adev(remote_acc_id); + mutex_unlock(&mgpu_info.mutex); + if (!peer_adev) { + dev_err(adev->dev, + "IMPORT LOCAL: peer adev not found for AccId:%u\n", + remote_acc_id); + return -ENODEV; + } + + xa_lock(&peer_adev->ualink.exp_xa); + exp_xa_node = xa_load(&peer_adev->ualink.exp_xa, handle->handle_lo); + if (!exp_xa_node || + exp_xa_node->handle.handle_hi != handle->handle_hi || + !amdgpu_ualink_exp_xa_entry_get(exp_xa_node)) { + xa_unlock(&peer_adev->ualink.exp_xa); + dev_err(adev->dev, + "IMPORT LOCAL: handle:%llx:%llx not found in peer exp_xa\n", + handle->handle_hi, handle->handle_lo); + return -EINVAL; + } + xa_unlock(&peer_adev->ualink.exp_xa); + + get_dma_buf(exp_xa_node->dmabuf); + /* Get a new fd for the DMABuf */ + fd = dma_buf_fd(exp_xa_node->dmabuf, O_CLOEXEC | O_RDWR); + if (fd < 0) { + dev_err(adev->dev, + "IMPORT LOCAL: dma-buf fd failed handle:%llx:%llx\n", + handle->handle_hi, handle->handle_lo); + dma_buf_put(exp_xa_node->dmabuf); + amdgpu_ualink_exp_xa_entry_put(exp_xa_node); + return fd; + } + + amdgpu_ualink_exp_xa_entry_put(exp_xa_node); + *fd_out = fd; + return 0; +} + int amdgpu_ualink_import_handle(struct drm_device *dev, const struct amdgpu_ualink_handle *ualink_handle, int *fd_out) @@ -3074,6 +3140,10 @@ int amdgpu_ualink_import_handle(struct drm_device *dev, return -EINVAL; } + if (amdgpu_ualink_is_local_accel(adev, remote_acc_id)) + return amdgpu_ualink_local_import(adev, remote_acc_id, + &handle, fd_out); + xa_lock(&adev->ualink.imp_xa); imp_xa_node = xa_load(&adev->ualink.imp_xa, handle.handle_lo); -- 2.55.0