drm/amdgpu: Add lock to serialize sriov command execution

Add lock to serialize sriov command execution.

Signed-off-by: YiPeng Chai <YiPeng.Chai@amd.com>
Reviewed-by: Hawking Zhang <Hawking.Zhang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
This commit is contained in:
YiPeng Chai 2025-07-21 15:22:27 +08:00 committed by Alex Deucher
parent c0e870407b
commit 2b198d459f
3 changed files with 15 additions and 5 deletions

View File

@ -917,6 +917,7 @@ static void amdgpu_virt_init_ras(struct amdgpu_device *adev)
RATELIMIT_MSG_ON_RELEASE);
mutex_init(&adev->virt.ras.ras_telemetry_mutex);
mutex_init(&adev->virt.access_req_mutex);
adev->virt.ras.cper_rptr = 0;
}

View File

@ -325,6 +325,8 @@ struct amdgpu_virt {
/* Spinlock to protect access to the RLCG register interface */
spinlock_t rlcg_reg_lock;
struct mutex access_req_mutex;
union amd_sriov_ras_caps ras_en_caps;
union amd_sriov_ras_caps ras_telemetry_en_caps;
struct amdgpu_virt_ras ras;

View File

@ -173,13 +173,17 @@ static void xgpu_nv_mailbox_trans_msg (struct amdgpu_device *adev,
static int xgpu_nv_send_access_requests_with_param(struct amdgpu_device *adev,
enum idh_request req, u32 data1, u32 data2, u32 data3)
{
int r, retry = 1;
struct amdgpu_virt *virt = &adev->virt;
int r = 0, retry = 1;
enum idh_event event = -1;
mutex_lock(&virt->access_req_mutex);
send_request:
if (amdgpu_ras_is_rma(adev))
return -ENODEV;
if (amdgpu_ras_is_rma(adev)) {
r = -ENODEV;
goto out;
}
xgpu_nv_mailbox_trans_msg(adev, req, data1, data2, data3);
@ -217,7 +221,7 @@ static int xgpu_nv_send_access_requests_with_param(struct amdgpu_device *adev,
if (req != IDH_REQ_GPU_INIT_DATA) {
dev_err(adev->dev, "Doesn't get msg:%d from pf, error=%d\n", event, r);
return r;
goto out;
} else /* host doesn't support REQ_GPU_INIT_DATA handshake */
adev->virt.req_init_data_ver = 0;
} else {
@ -246,7 +250,10 @@ static int xgpu_nv_send_access_requests_with_param(struct amdgpu_device *adev,
}
}
return 0;
out:
mutex_unlock(&virt->access_req_mutex);
return r;
}
static int xgpu_nv_send_access_requests(struct amdgpu_device *adev,