[PATCH] drm/xe/oa: Check managed mutex initialization errors

Linmao Li posted 1 patch 1 week, 5 days ago
drivers/gpu/drm/xe/xe_oa.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
[PATCH] drm/xe/oa: Check managed mutex initialization errors
Posted by Linmao Li 1 week, 5 days ago
drmm_mutex_init() can fail while registering its managed cleanup action.
On failure, the reset path destroys the mutex, so continuing OA setup
leaves an unusable lock that later paths may acquire.

Return the error from per-GT OA initialization and abort device-wide OA
initialization if the metrics lock cannot be initialized.

Fixes: a9f905ae7b6f ("drm/xe/oa/uapi: Initialize OA units")
Fixes: cdf02fe1a94a ("drm/xe/oa/uapi: Add/remove OA config perf ops")
Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
---
 drivers/gpu/drm/xe/xe_oa.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_oa.c b/drivers/gpu/drm/xe/xe_oa.c
index 2dce6a47202c..f3a0d5bf7894 100644
--- a/drivers/gpu/drm/xe/xe_oa.c
+++ b/drivers/gpu/drm/xe/xe_oa.c
@@ -2713,9 +2713,7 @@ static int xe_oa_init_gt(struct xe_gt *gt)
 
 	__xe_oa_init_oa_units(gt);
 
-	drmm_mutex_init(&gt_to_xe(gt)->drm, &gt->oa.gt_lock);
-
-	return 0;
+	return drmm_mutex_init(&gt_to_xe(gt)->drm, &gt->oa.gt_lock);
 }
 
 static void xe_oa_print_gt_oa_units(struct xe_gt *gt)
@@ -2855,7 +2853,10 @@ int xe_oa_init(struct xe_device *xe)
 	oa->xe = xe;
 	oa->oa_formats = oa_formats;
 
-	drmm_mutex_init(&oa->xe->drm, &oa->metrics_lock);
+	ret = drmm_mutex_init(&oa->xe->drm, &oa->metrics_lock);
+	if (ret)
+		goto exit;
+
 	idr_init_base(&oa->metrics_idr, 1);
 
 	ret = xe_oa_init_oa_units(oa);
-- 
2.25.1
Re: [PATCH] drm/xe/oa: Check managed mutex initialization errors
Posted by Umesh Nerlige Ramappa 1 week, 4 days ago
On Mon, Jul 13, 2026 at 04:30:53PM +0800, Linmao Li wrote:
>drmm_mutex_init() can fail while registering its managed cleanup action.
>On failure, the reset path destroys the mutex, so continuing OA setup
>leaves an unusable lock that later paths may acquire.
>
>Return the error from per-GT OA initialization and abort device-wide OA
>initialization if the metrics lock cannot be initialized.
>
>Fixes: a9f905ae7b6f ("drm/xe/oa/uapi: Initialize OA units")
>Fixes: cdf02fe1a94a ("drm/xe/oa/uapi: Add/remove OA config perf ops")
>Signed-off-by: Linmao Li <lilinmao@kylinos.cn>

Thanks for addressing this. LGTM, 

Reviewed-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>



>---
> drivers/gpu/drm/xe/xe_oa.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
>diff --git a/drivers/gpu/drm/xe/xe_oa.c b/drivers/gpu/drm/xe/xe_oa.c
>index 2dce6a47202c..f3a0d5bf7894 100644
>--- a/drivers/gpu/drm/xe/xe_oa.c
>+++ b/drivers/gpu/drm/xe/xe_oa.c
>@@ -2713,9 +2713,7 @@ static int xe_oa_init_gt(struct xe_gt *gt)
>
> 	__xe_oa_init_oa_units(gt);
>
>-	drmm_mutex_init(&gt_to_xe(gt)->drm, &gt->oa.gt_lock);
>-
>-	return 0;
>+	return drmm_mutex_init(&gt_to_xe(gt)->drm, &gt->oa.gt_lock);
> }
>
> static void xe_oa_print_gt_oa_units(struct xe_gt *gt)
>@@ -2855,7 +2853,10 @@ int xe_oa_init(struct xe_device *xe)
> 	oa->xe = xe;
> 	oa->oa_formats = oa_formats;
>
>-	drmm_mutex_init(&oa->xe->drm, &oa->metrics_lock);
>+	ret = drmm_mutex_init(&oa->xe->drm, &oa->metrics_lock);
>+	if (ret)
>+		goto exit;
>+
> 	idr_init_base(&oa->metrics_idr, 1);
>
> 	ret = xe_oa_init_oa_units(oa);
>-- 
>2.25.1
>