Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/xe/devcoredump: Use scope-based cleanup

Use scope-based cleanup for forcewake and runtime PM in the devcoredump
code. This eliminates some goto-based error handling and slightly
simplifies other functions.

v2:
- Move the forcewake acquisition slightly higher in
devcoredump_snapshot() so that we maintain an easy-to-understand LIFO
cleanup order. (Gustavo)

Cc: Gustavo Sousa <gustavo.sousa@intel.com>
Reviewed-by: Gustavo Sousa <gustavo.sousa@intel.com>
Link: https://patch.msgid.link/20251118164338.3572146-41-matthew.d.roper@intel.com
Signed-off-by: Matt Roper <matthew.d.roper@intel.com>

+12 -18
+12 -18
drivers/gpu/drm/xe/xe_devcoredump.c
··· 276 276 struct xe_devcoredump_snapshot *ss = container_of(work, typeof(*ss), work); 277 277 struct xe_devcoredump *coredump = container_of(ss, typeof(*coredump), snapshot); 278 278 struct xe_device *xe = coredump_to_xe(coredump); 279 - unsigned int fw_ref; 280 279 281 280 /* 282 281 * NB: Despite passing a GFP_ flags parameter here, more allocations are done ··· 286 287 xe_devcoredump_read, xe_devcoredump_free, 287 288 XE_COREDUMP_TIMEOUT_JIFFIES); 288 289 289 - xe_pm_runtime_get(xe); 290 + guard(xe_pm_runtime)(xe); 290 291 291 292 /* keep going if fw fails as we still want to save the memory and SW data */ 292 - fw_ref = xe_force_wake_get(gt_to_fw(ss->gt), XE_FORCEWAKE_ALL); 293 - if (!xe_force_wake_ref_has_domain(fw_ref, XE_FORCEWAKE_ALL)) 294 - xe_gt_info(ss->gt, "failed to get forcewake for coredump capture\n"); 295 - xe_vm_snapshot_capture_delayed(ss->vm); 296 - xe_guc_exec_queue_snapshot_capture_delayed(ss->ge); 297 - xe_force_wake_put(gt_to_fw(ss->gt), fw_ref); 293 + xe_with_force_wake(fw_ref, gt_to_fw(ss->gt), XE_FORCEWAKE_ALL) { 294 + if (!xe_force_wake_ref_has_domain(fw_ref.domains, XE_FORCEWAKE_ALL)) 295 + xe_gt_info(ss->gt, "failed to get forcewake for coredump capture\n"); 296 + xe_vm_snapshot_capture_delayed(ss->vm); 297 + xe_guc_exec_queue_snapshot_capture_delayed(ss->ge); 298 + } 298 299 299 300 ss->read.chunk_position = 0; 300 301 ··· 305 306 ss->read.buffer = kvmalloc(XE_DEVCOREDUMP_CHUNK_MAX, 306 307 GFP_USER); 307 308 if (!ss->read.buffer) 308 - goto put_pm; 309 + return; 309 310 310 311 __xe_devcoredump_read(ss->read.buffer, 311 312 XE_DEVCOREDUMP_CHUNK_MAX, ··· 313 314 } else { 314 315 ss->read.buffer = kvmalloc(ss->read.size, GFP_USER); 315 316 if (!ss->read.buffer) 316 - goto put_pm; 317 + return; 317 318 318 319 __xe_devcoredump_read(ss->read.buffer, ss->read.size, 0, 319 320 coredump); 320 321 xe_devcoredump_snapshot_free(ss); 321 322 } 322 - 323 - put_pm: 324 - xe_pm_runtime_put(xe); 325 323 } 326 324 327 325 static void devcoredump_snapshot(struct xe_devcoredump *coredump, ··· 328 332 struct xe_devcoredump_snapshot *ss = &coredump->snapshot; 329 333 struct xe_guc *guc = exec_queue_to_guc(q); 330 334 const char *process_name = "no process"; 331 - unsigned int fw_ref; 332 335 bool cookie; 333 336 334 337 ss->snapshot_time = ktime_get_real(); ··· 343 348 ss->gt = q->gt; 344 349 INIT_WORK(&ss->work, xe_devcoredump_deferred_snap_work); 345 350 346 - cookie = dma_fence_begin_signalling(); 347 - 348 351 /* keep going if fw fails as we still want to save the memory and SW data */ 349 - fw_ref = xe_force_wake_get(gt_to_fw(q->gt), XE_FORCEWAKE_ALL); 352 + CLASS(xe_force_wake, fw_ref)(gt_to_fw(q->gt), XE_FORCEWAKE_ALL); 353 + 354 + cookie = dma_fence_begin_signalling(); 350 355 351 356 ss->guc.log = xe_guc_log_snapshot_capture(&guc->log, true); 352 357 ss->guc.ct = xe_guc_ct_snapshot_capture(&guc->ct); ··· 359 364 360 365 queue_work(system_unbound_wq, &ss->work); 361 366 362 - xe_force_wake_put(gt_to_fw(q->gt), fw_ref); 363 367 dma_fence_end_signalling(cookie); 364 368 } 365 369