Skip to content

Commit 6c0a15e

Browse files
hghimirarodrigovivi
authored andcommitted
drm/xe: forcewake debugfs open fails on xe_forcewake_get failure
A failure in xe_force_wake_get() no longer increments the domain's refcount. Therefore, if xe_force_wake_get() fails during forcewake debugfs open, return an error. This ensures there are no valid file descriptors to close via forcewake debugfs, preventing refcount mismanagement. v3 - return xe_wakeref_t instead of int in xe_force_wake_get() v5 - return unsigned int from xe_force_wake_get() v6 - Use helper xe_force_wake_ref_has_domain() to determine the status of the call. Cc: Badal Nilawar <[email protected]> Cc: Rodrigo Vivi <[email protected]> Cc: Lucas De Marchi <[email protected]> Signed-off-by: Himal Prasad Ghimiray <[email protected]> Reviewed-by: Badal Nilawar <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Rodrigo Vivi <[email protected]>
1 parent bd1aad7 commit 6c0a15e

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

drivers/gpu/drm/xe/xe_debugfs.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,32 @@ static int forcewake_open(struct inode *inode, struct file *file)
9090
{
9191
struct xe_device *xe = inode->i_private;
9292
struct xe_gt *gt;
93-
u8 id;
93+
u8 id, last_gt;
94+
unsigned int fw_ref;
9495

9596
xe_pm_runtime_get(xe);
96-
for_each_gt(gt, xe, id)
97-
XE_WARN_ON(xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL));
97+
for_each_gt(gt, xe, id) {
98+
last_gt = id;
99+
100+
fw_ref = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL);
101+
if (!xe_force_wake_ref_has_domain(fw_ref, XE_FORCEWAKE_ALL))
102+
goto err_fw_get;
103+
}
98104

99105
return 0;
106+
107+
err_fw_get:
108+
for_each_gt(gt, xe, id) {
109+
if (id < last_gt)
110+
xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL);
111+
else if (id == last_gt)
112+
xe_force_wake_put(gt_to_fw(gt), fw_ref);
113+
else
114+
break;
115+
}
116+
117+
xe_pm_runtime_put(xe);
118+
return -ETIMEDOUT;
100119
}
101120

102121
static int forcewake_release(struct inode *inode, struct file *file)
@@ -106,7 +125,7 @@ static int forcewake_release(struct inode *inode, struct file *file)
106125
u8 id;
107126

108127
for_each_gt(gt, xe, id)
109-
XE_WARN_ON(xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL));
128+
xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL);
110129
xe_pm_runtime_put(xe);
111130

112131
return 0;

0 commit comments

Comments
 (0)