Skip to contentSkip to conversation

drm/amdgpu: report GUILTY/INNOCENT reset from amdgpu_ctx_query()

PATCH In review Jesse Zhang 2 participants 2 messages Jun 11

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

PATCH v2 1/1 drm/amdgpu: report GUILTY/INNOCENT reset from amdgpu_ctx_query()

drm/amdgpu: report guilty/innocent context reset status in ctx query

amdgpu_ctx_query() currently reports AMDGPU_CTX_UNKNOWN_RESET whenever the device reset counter changes, even if the context can be identified as guilty or unaffected.

Use amdgpu_ctx_guilty() in the ctx query path and return:
- AMDGPU_CTX_GUILTY_RESET for guilty contexts,
- AMDGPU_CTX_INNOCENT_RESET for non-guilty contexts after a reset,
- AMDGPU_CTX_NO_RESET only when no reset occurred and context is not guilty.

This provides accurate per-context reset attribution to userspace instead of collapsing all reset cases into UNKNOWN.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +8 -3
index d54cec3e4a53..a88443e0254c 100644
@@ -542,6 +542,8 @@ static int amdgpu_ctx_free(struct amdgpu_fpriv *fpriv, uint32_t id)
 	return ctx ? 0 : -EINVAL;
 }
 
+static bool amdgpu_ctx_guilty(struct amdgpu_ctx *ctx);
+
 static int amdgpu_ctx_query(struct amdgpu_device *adev,
 			    struct amdgpu_fpriv *fpriv, uint32_t id,
 			    union drm_amdgpu_ctx_out *out)
@@ -549,6 +551,7 @@ static int amdgpu_ctx_query(struct amdgpu_device *adev,
 	struct amdgpu_ctx *ctx;
 	struct amdgpu_ctx_mgr *mgr;
 	unsigned reset_counter;
+	bool guilty;
 
 	if (!fpriv)
 		return -EINVAL;
@@ -567,11 +570,13 @@ static int amdgpu_ctx_query(struct amdgpu_device *adev,
 
 	/* determine if a GPU reset has occured since the last call */
 	reset_counter = atomic_read(&adev->gpu_reset_counter);
-	/* TODO: this should ideally return NO, GUILTY, or INNOCENT. */
-	if (ctx->reset_counter_query == reset_counter)
+	guilty = amdgpu_ctx_guilty(ctx);
+	if (ctx->reset_counter_query == reset_counter && !guilty)
 		out->state.reset_status = AMDGPU_CTX_NO_RESET;
+	else if (guilty)
+		out->state.reset_status = AMDGPU_CTX_GUILTY_RESET;
 	else
-		out->state.reset_status = AMDGPU_CTX_UNKNOWN_RESET;
+		out->state.reset_status = AMDGPU_CTX_INNOCENT_RESET;
 	ctx->reset_counter_query = reset_counter;
 
 	mutex_unlock(&mgr->lock);
Signature · 1 line
2.49.0
maintainer
#1 lore raw
Quoted 6 lines · Jesse Zhang

drm/amdgpu: report guilty/innocent context reset status in ctx query

amdgpu_ctx_query() currently reports AMDGPU_CTX_UNKNOWN_RESET whenever the device reset counter changes, even if the context can be identified as guilty or unaffected.

Quoted 7 lines

Use amdgpu_ctx_guilty() in the ctx query path and return:
- AMDGPU_CTX_GUILTY_RESET for guilty contexts,
- AMDGPU_CTX_INNOCENT_RESET for non-guilty contexts after a reset,
- AMDGPU_CTX_NO_RESET only when no reset occurred and context is not guilty.

This provides accurate per-context reset attribution to userspace instead of collapsing all reset cases into UNKNOWN.

I think I have to reject that.

The amdgpu_ctx_query() function is deprecated and replaced by the amdgpu_ctx_query2() function exactly because we couldn't extend the interface with such information.

IIRC the last time we tried to change it something broke in userspace and we had to revert that.

Just using the amdgpu_ctx_query2() should work as well.

Regards,
Christian.

Quoted 43 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +8 -3
index d54cec3e4a53..a88443e0254c 100644
@@ -542,6 +542,8 @@ static int amdgpu_ctx_free(struct amdgpu_fpriv *fpriv, uint32_t id)
 	return ctx ? 0 : -EINVAL;
 }
 
+static bool amdgpu_ctx_guilty(struct amdgpu_ctx *ctx);
+
 static int amdgpu_ctx_query(struct amdgpu_device *adev,
 			    struct amdgpu_fpriv *fpriv, uint32_t id,
 			    union drm_amdgpu_ctx_out *out)
@@ -549,6 +551,7 @@ static int amdgpu_ctx_query(struct amdgpu_device *adev,
 	struct amdgpu_ctx *ctx;
 	struct amdgpu_ctx_mgr *mgr;
 	unsigned reset_counter;
+	bool guilty;
 
 	if (!fpriv)
 		return -EINVAL;
@@ -567,11 +570,13 @@ static int amdgpu_ctx_query(struct amdgpu_device *adev,
 
 	/* determine if a GPU reset has occured since the last call */
 	reset_counter = atomic_read(&adev->gpu_reset_counter);
-	/* TODO: this should ideally return NO, GUILTY, or INNOCENT. */
-	if (ctx->reset_counter_query == reset_counter)
+	guilty = amdgpu_ctx_guilty(ctx);
+	if (ctx->reset_counter_query == reset_counter && !guilty)
 		out->state.reset_status = AMDGPU_CTX_NO_RESET;
+	else if (guilty)
+		out->state.reset_status = AMDGPU_CTX_GUILTY_RESET;
 	else
-		out->state.reset_status = AMDGPU_CTX_UNKNOWN_RESET;
+		out->state.reset_status = AMDGPU_CTX_INNOCENT_RESET;
 	ctx->reset_counter_query = reset_counter;
 
 	mutex_unlock(&mgr->lock);