[PATCH v2 00/23] Fix xe_force_wake_get() failure handling
Himal Prasad Ghimiray
himal.prasad.ghimiray at intel.com
Thu Sep 12 19:15:40 UTC 2024
In case of xe_force_wake_get() call the refcount for domains
are incremented irrespective of failure or success, which can lead to
undefined behaviour:
[1] subsequent forcewake call by callee function assumes domains are
already awake, which might not be true. This shows perfectly balanced
xe_force_wake_get/_put can also cause problem.
[2] The functions are using xe_force_wake_get() and return on failures.
In this scenario only the first caller returns and other functions will
always assume domains to be awake.
[1] func_a() {
XE_WARN(xe_force_wake_get()) <---> fails but increments refcount
func_b();
XE_WARN(xe_force_wake_put());<---> decrements refcounts
}
func_b() {
if(xe_force_wake_get()) <---> succeeds due to refcount of caller
return;
does mmio_operations(); <---> Domain might not be awake
xe_force_wake_put(); <---> decrement refcount
}
[2] func_a() {
int err = xe_force_wake_get(); <---> returns if fails, inc refcount
if (err)
return;
mmio_operations();
xe_force_wake_put();
}
func_b() {
if (xe_force_wake_get()) <---> succeeds due to refcnt of func_a()
return;
mmio_operations(); <---> Invalid accesses
xe_force_wake_put(); <---> decrements refcount for func_b
}
This series ensures refcount is not incremented in case of
xe_force_wake_get() failure and return mask of successfully refcount
incremented domains.
For single domains (except XE_FORCEWAKE_ALL), the return value will be
0 on failure and doesn't need call to xe_force_wake_put()(if called,
call will return with check since input mask will be 0).
For XE_FORCEWAKE_ALL caller need to compare the returned mask with
XE_FORCEWAKE_ALL to confirm the success of call and need to explicitly
call xe_force_wake_put() with returned mask to put awaken domains to
sleep.
-v2 (Rodrigo, Badal)
- Dont put successfully awaken domains to sleep. Instead rely on _put to
do that.
- Modified xe_force_wake_get() to return the refcount-incremented domain
mask and xe_force_wake_put() uses this returned mask.
Cc: Badal Nilawar <badal.nilawar at intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi at intel.com>
Cc: Lucas De Marchi <lucas.demarchi at intel.com>
Cc: Nirmoy Das <nirmoy.das at intel.com>
Cc: Matthew Brost <matthew.brost at intel.com>
Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio at intel.com>
Cc: Ashutosh Dixit <ashutosh.dixit at intel.com>
Himal Prasad Ghimiray (23):
drm/xe: Error handling in xe_force_wake_get()
drm/xe: Modify xe_force_wake_put to handle _get returned mask
drm/xe/device: Update handling of xe_force_wake_get return
drm/xe/hdcp: Update handling of xe_force_wake_get return
drm/xe/gsc: Update handling of xe_force_wake_get return
drm/xe/gt: Update handling of xe_force_wake_get return
drm/xe/xe_gt_idle: Update handling of xe_force_wake_get return
drm/xe/devcoredump: Update handling of xe_force_wake_get return
drm/xe/tests/mocs: Update xe_force_wake_get() return handling
drm/xe/mocs: Update handling of xe_force_wake_get return
drm/xe/xe_drm_client: Update handling of xe_force_wake_get return
drm/xe/xe_gt_debugfs: Update handling of xe_force_wake_get return
drm/xe/guc: Update handling of xe_force_wake_get return
drm/xe/huc: Update handling of xe_force_wake_get return
drm/xe/oa: Handle force_wake_get failure in xe_oa_stream_init()
drm/xe/pat: Update handling of xe_force_wake_get return
drm/xe/gt_tlb_invalidation_ggtt: Update handling of xe_force_wake_get
return
drm/xe/xe_reg_sr: Update handling of xe_force_wake_get return
drm/xe/query: Update handling of xe_force_wake_get return
drm/xe/vram: Update handling of xe_force_wake_get return
drm/xe: forcewake debugfs open fails on xe_forcewake_get failure
drm/xe: Ensure __must_check for xe_force_wake_get() return
drm/xe: Change return type to void for xe_force_wake_put
drivers/gpu/drm/xe/display/xe_hdcp_gsc.c | 6 +-
drivers/gpu/drm/xe/tests/xe_mocs.c | 16 +--
drivers/gpu/drm/xe/xe_debugfs.c | 29 ++++-
drivers/gpu/drm/xe/xe_devcoredump.c | 13 ++-
drivers/gpu/drm/xe/xe_device.c | 25 +++--
drivers/gpu/drm/xe/xe_drm_client.c | 8 +-
drivers/gpu/drm/xe/xe_force_wake.c | 69 +++++++++---
drivers/gpu/drm/xe/xe_force_wake.h | 8 +-
drivers/gpu/drm/xe/xe_gsc.c | 21 ++--
drivers/gpu/drm/xe/xe_gsc_proxy.c | 9 +-
drivers/gpu/drm/xe/xe_gt.c | 113 +++++++++++---------
drivers/gpu/drm/xe/xe_gt_debugfs.c | 13 ++-
drivers/gpu/drm/xe/xe_gt_idle.c | 29 ++---
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c | 6 +-
drivers/gpu/drm/xe/xe_guc.c | 14 +--
drivers/gpu/drm/xe/xe_guc_pc.c | 54 ++++++----
drivers/gpu/drm/xe/xe_huc.c | 8 +-
drivers/gpu/drm/xe/xe_mocs.c | 10 +-
drivers/gpu/drm/xe/xe_oa.c | 12 ++-
drivers/gpu/drm/xe/xe_pat.c | 50 ++++-----
drivers/gpu/drm/xe/xe_query.c | 8 +-
drivers/gpu/drm/xe/xe_reg_sr.c | 24 ++---
drivers/gpu/drm/xe/xe_vram.c | 11 +-
23 files changed, 335 insertions(+), 221 deletions(-)
--
2.34.1
More information about the Intel-xe
mailing list