drm/i915/gvt: fix refcount leak in intel_vgpu_shadow_mm_pin()
PATCH 1/1 drm/i915/gvt: fix refcount leak in intel_vgpu_shadow_mm_pin()
intel_vgpu_pin_mm() unconditionally increments the mm's pincount at the start. If the subsequent shadow ppgtt creation fails, the function returns an error but leaves the pincount incremented. Callers must therefore always call intel_vgpu_unpin_mm() after intel_vgpu_pin_mm() returns, regardless of success or failure, to balance the reference.
In intel_vgpu_shadow_mm_pin(), when the pinning of the shadow mm fails, the error path returns immediately without unpinning. This leaks the pincount reference that was already taken. All other error paths in the same function correctly unpin on failure, making this an obvious omission.
Add the missing intel_vgpu_unpin_mm() call before returning the error.
--- drivers/gpu/drm/i915/gvt/scheduler.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/i915/gvt/scheduler.c +1 -0
@@ -698,6 +698,7 @@ intel_vgpu_shadow_mm_pin(struct intel_vgpu_workload *workload) ret =intel_vgpu_pin_mm (workload->shadow_mm);if (ret) { +intel_vgpu_unpin_mm (workload->shadow_mm);gvt_vgpu_err ("fail to vgpu pin mm\n" );return ret; }
Signature · 1 line
2.34.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Double-unpin of shared shadow PPGTT memory due to conflict between explicit error handling and…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Double-unpin of shared shadow PPGTT memory due to conflict between explicit error handling and unconditional cleanup. --
commit 4d9fa23878c7d84ea81831549d03a73dfab721d4
Author: Wentao Liang <[email protected]>
drm/i915/gvt: fix refcount leak in intel_vgpu_shadow_mm_pin()
This commit adds an explicit unpin call to the error path of intel_vgpu_shadow_mm_pin() when intel_vgpu_pin_mm() fails. The goal is to balance the pincount increment that unconditionally happens at the start of intel_vgpu_pin_mm().
drivers/gpu/drm/i915/gvt/scheduler.c intel_vgpu_shadow_mm_pin(struct intel_vgpu_workload *workload) · line 701
Quoted 9 lines
drivers/gpu/drm/i915/gvt/scheduler.c +1
-0@@ -698,6 +698,7 @@ intel_vgpu_shadow_mm_pin(struct intel_vgpu_workload *workload) ret =intel_vgpu_pin_mm (workload->shadow_mm);if (ret) { +intel_vgpu_unpin_mm (workload->shadow_mm);
[Severity: High]
Does this explicit unpin introduce a double-unpin of the shadow mm?
Looking at the workload dispatch loop in workload_thread(), if intel_vgpu_shadow_mm_pin() returns an error, the thread jumps to the completion path:
workload_thread()
...
ret = prepare_workload(workload);
if (ret)
goto complete;
...
complete:
complete_current_workload(gvt, engine->id);The cleanup path then unconditionally unpins the shadow mm:
complete_current_workload()
...
intel_vgpu_shadow_mm_unpin(workload);Before this patch, a failure in intel_vgpu_pin_mm() incremented the pincount, and the unconditional cleanup in complete_current_workload() decremented it, maintaining balance.
By adding this explicit unpin in the error path, could the pincount decrement twice and underflow?
Since shadow page tables are shared among workloads for the same vGPU, would an underflow allow the GVT shrinker to prematurely destroy active shadow page tables while another workload is still executing, potentially causing GPU page faults or VM crashes?
Quoted 3 lines
drivers/gpu/drm/i915/gvt/scheduler.c +0
-0gvt_vgpu_err ("fail to vgpu pin mm\n" );return ret; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Patchwork
CI✗ LGCI.VerificationFailed: failure for drm/i915/gvt: fix refcount leak in intel_vgpu_shadow_mm_pin()
In reply to Wentao Liang== Series Details ==
== Series Details ==
Series: drm/i915/gvt: fix refcount leak in intel_vgpu_shadow_mm_pin()
URL : https://patchwork.freedesktop.org/series/168088/
State : failure
== Summary ==
Address '[email protected]' is not on the allowlist, which prevents CI from being triggered for this patch. If you want Intel GFX CI to accept this address, please contact the script maintainers at [email protected]. Exception occurred during validation, bailing out!
Build URL: http://gfx-ci.igk.intel.com:8080/job/CI_PW_kernel/179081/ (on built-in)