Skip to content

drm/xe: Guard against NULL return for xe_device_get_gt

Jonathan Cavitt intel-xe 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest7 patches 7 repliesIn review
  2. v25 patches 4 repliesSuperseded
  3. v15 patches 9 repliesSuperseded

Changes in v3 from the cover letter

- Add xe_device_lookup_gt macro (Michal, Rodrigo)
- Modify xe_device_get_gt to assert gt existance (Michal, Rodrigo)
- Use xe_device_get_gt where necessary (jcavitt)
- Add xe_device_get_any_gt for kunit (jcavitt)

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7drm/xe: s/xe_device_get_gt/xe_device_lookup_gtdrivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c drivers/gpu/drm/xe/tests/xe_guc_db_mgr_test.c drivers/gpu/drm/xe/tests/xe_guc_g2g_test.c +10 more+22 -222 replies
2/7drm/xe: Don't call xe_device_lookup_gt twice in xe_hw_engine_lookupdrivers/gpu/drm/xe/xe_hw_engine.c+1 -20 replies
3/7drm/xe/xe_device: Reintroduce xe_device_get_gtdrivers/gpu/drm/xe/xe_device.h+15 -01 reply
4/7drm/xe: Guard against NULL GT in xe_sriov_vf.cdrivers/gpu/drm/xe/xe_sriov_vf.c+1 -12 replies
5/7drm/xe: Guard against NULL GT in xe_pmu.cdrivers/gpu/drm/xe/xe_pmu.c+5 -20 replies
6/7drm/xe: Guard against NULL GT in xe_guc.cdrivers/gpu/drm/xe/xe_guc.c+1 -10 replies
7/7drm/xe/tests: Use any available GT for testingdrivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c drivers/gpu/drm/xe/tests/xe_guc_db_mgr_test.c drivers/gpu/drm/xe/tests/xe_guc_g2g_test.c +3 more+30 -82 replies

Reviews trailers per patch

1 of 7 patches has a Reviewed-by or Acked-by.

PatchMichal WajdeczkoTejas Upadhyay
1/7
2/7R-b R-b
3/7
4/7
5/7
6/7
7/7

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 0/7] drm/xe: Guard against NULL return for xe_device_get_gt

Static analysis reveals the following issue:
xe_device_get_gt is theoretically able to return NULL in some cases, but several use cases don't check the return value before performing a dereference, resulting in a NULL pointer dereference.

Modify xe_device_get_gt to assert a non-NULL return value. This breaks some macros (namely, for_each_gt), so keep the old functionality in xe_device_lookup_gt, and only use xe_device_get_gt in places where it is necessary to assert a non-NULL return value. Finally, add xe_device_get_any_gt, a kunit-only macro that returns the first available GT while asserting at least one exists, for cases where the GT with ID 0 is masked off.

v2:
- Various commit message fixups (Michal)
- Use xe_assert in xe_guc.c (Michal, Matt)
- Add assert to vf_post_migration_recovery (Michal)
- Modify various xe_pmu functions to take an xe_gt pointer (Michal)
- Fix potential memory leak (Michal)

v3:
- Add xe_device_lookup_gt macro (Michal, Rodrigo)
- Modify xe_device_get_gt to assert gt existance (Michal, Rodrigo)
- Use xe_device_get_gt where necessary (jcavitt)
- Add xe_device_get_any_gt for kunit (jcavitt)

Cc Michal Wajdeczko <[email protected]>
Cc Matt Roper <[email protected]>
Cc Rodrigo Vivi <[email protected]>
Cc Tejas Upadhyay <[email protected]>

Jonathan Cavitt (7):
drm/xe: s/xe_device_get_gt/xe_device_lookup_gt
drm/xe: Don't call xe_device_lookup_gt twice in xe_hw_engine_lookup drm/xe/xe_device: Reintroduce xe_device_get_gt
drm/xe: Guard against NULL GT in xe_sriov_vf.c
drm/xe: Guard against NULL GT in xe_pmu.c
drm/xe: Guard against NULL GT in xe_guc.c
drm/xe/tests: Use any available GT for testing

 drivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c   |  2 +-
 drivers/gpu/drm/xe/tests/xe_guc_db_mgr_test.c |  2 +-
 drivers/gpu/drm/xe/tests/xe_guc_g2g_test.c    |  2 +-
 drivers/gpu/drm/xe/tests/xe_guc_relay_test.c  |  8 ++--
 drivers/gpu/drm/xe/xe_device.h                | 41 ++++++++++++++++++-
 drivers/gpu/drm/xe/xe_eu_stall.c              |  2 +-
 drivers/gpu/drm/xe/xe_exec_queue.c            |  2 +-
 drivers/gpu/drm/xe/xe_hw_engine.c             |  5 +--
 drivers/gpu/drm/xe/xe_pmu.c                   | 13 +++---
 drivers/gpu/drm/xe/xe_query.c                 |  2 +-
 10 files changed, 59 insertions(+), 20 deletions(-)
Signature · 1 line
2.43.0