Skip to contentSkip to conversation

drm/amdgpu: Resend full access request on timeout for AI mailbox

PATCH New Yunxiang Li 1 participant 1 message Oct 20

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: Resend full access request on timeout for AI mailbox

When a VF requests full GPU access, the host may need a whole GPU reset before it can answer. That reset can take longer than the 6 s READY_TO_ACCESS_GPU wait. The guest then gives up, sets no_hw_access, and the VF stays unusable until the driver is reloaded.

The NV mailbox resends the request after a timeout since commit 124e8b1990ac ("drm/amdgpu: Extend full access wait time in guest"), so a request lost to a host reset is answered once the host is back. Make xgpu_ai_send_access_requests() and xgpu_ai_poll_msg() follow the NV
versions: map the request to its reply event in a switch, resend up to 5 times, report the failure once after the last attempt, and use a ktime based deadline in the poll.

---
 drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c | 56 +++++++++++++++++----------
 drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h |  1 +
 2 files changed, 37 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c +36 -20
index fec08f235b92..cfddbb3225d2 100644
@@ -100,18 +100,25 @@ static int xgpu_ai_poll_ack(struct amdgpu_device *adev)
 
 static int xgpu_ai_poll_msg(struct amdgpu_device *adev, enum idh_event event)
 {
-	int r, timeout = AI_MAILBOX_POLL_MSG_TIMEDOUT;
+	int r;
+	uint64_t timeout, now;
+
+	now = (uint64_t)ktime_to_ms(ktime_get());
+	timeout = now + AI_MAILBOX_POLL_MSG_TIMEDOUT;
 
 	do {
 		r = xgpu_ai_mailbox_rcv_msg(adev, event);
-		if (!r)
+		if (!r) {
+			dev_dbg(adev->dev, "rcv_msg 0x%x after %llu ms\n",
+					event, AI_MAILBOX_POLL_MSG_TIMEDOUT - timeout + now);
 			return 0;
+		}
 
 		msleep(10);
-		timeout -= 10;
-	} while (timeout > 1);
+		now = (uint64_t)ktime_to_ms(ktime_get());
+	} while (timeout > now);
 
-	dev_err(adev->dev, "Doesn't get msg:%d from pf, error=%d\n", event, r);
+	dev_dbg(adev->dev, "ai_poll_msg timed out\n");
 
 	return -ETIME;
 }
@@ -163,33 +170,42 @@ static void xgpu_ai_mailbox_trans_msg (struct amdgpu_device *adev,
 static int xgpu_ai_send_access_requests(struct amdgpu_device *adev,
 					enum idh_request req)
 {
-	int r;
+	int r, retry = 1;
+	enum idh_event event = -1;
 
+send_request:
 	xgpu_ai_mailbox_trans_msg(adev, req, 0, 0, 0);
 
-	/* start to check msg if request is idh_req_gpu_init_access */
-	if (req == IDH_REQ_GPU_INIT_ACCESS ||
-		req == IDH_REQ_GPU_FINI_ACCESS ||
-		req == IDH_REQ_GPU_RESET_ACCESS) {
-		r = xgpu_ai_poll_msg(adev, IDH_READY_TO_ACCESS_GPU);
+	switch (req) {
+	case IDH_REQ_GPU_INIT_ACCESS:
+	case IDH_REQ_GPU_FINI_ACCESS:
+	case IDH_REQ_GPU_RESET_ACCESS:
+		event = IDH_READY_TO_ACCESS_GPU;
+		break;
+	case IDH_REQ_GPU_INIT_DATA:
+		event = IDH_REQ_GPU_INIT_DATA_READY;
+		adev->virt.req_init_data_ver = GPU_CRIT_REGION_V1;
+		break;
+	default:
+		break;
+	}
+
+	if (event != -1) {
+		r = xgpu_ai_poll_msg(adev, event);
 		if (r) {
-			dev_err(adev->dev, "Doesn't get READY_TO_ACCESS_GPU from pf, give up\n");
+			if (retry++ < AI_MAILBOX_REQ_RETRY_MAX)
+				goto send_request;
+
+			dev_err(adev->dev, "Doesn't get msg:%d from pf, error=%d\n", event, r);
 			return r;
 		}
+
 		/* Retrieve checksum from mailbox2 */
 		if (req == IDH_REQ_GPU_INIT_ACCESS || req == IDH_REQ_GPU_RESET_ACCESS) {
 			adev->virt.fw_reserve.checksum_key =
 				RREG32_NO_KIQ(SOC15_REG_OFFSET(NBIO, 0,
 					mmBIF_BX_PF0_MAILBOX_MSGBUF_RCV_DW2));
 		}
-	} else if (req == IDH_REQ_GPU_INIT_DATA){
-		/* Dummy REQ_GPU_INIT_DATA handling */
-		r = xgpu_ai_poll_msg(adev, IDH_REQ_GPU_INIT_DATA_READY);
-		/*
-		 * AI uses the GPU_CRIT_REGION_V1 layout in practice, so fix the
-		 * dummy version value to match the actual init-data format.
-		 */
-		adev->virt.req_init_data_ver = GPU_CRIT_REGION_V1;
 	}
 
 	return 0;
drivers/gpu/drm/amd/amdgpu/mxgpu_ai.h +1 -0
index 874b9f8f9804..af4ef0fbdb86 100644
@@ -28,6 +28,7 @@
 #define AI_MAILBOX_POLL_MSG_TIMEDOUT	6000
 #define AI_MAILBOX_POLL_FLR_TIMEDOUT	10000
 #define AI_MAILBOX_POLL_MSG_REP_MAX	11
+#define AI_MAILBOX_REQ_RETRY_MAX	5
 
 enum idh_request {
 	IDH_REQ_GPU_INIT_ACCESS = 1,
Signature · 1 line
2.54.0