Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

Commit 601fd0f

Browse files
bluesheep1337zhenyw
authored andcommitted
drm/i915/gvt: fix double free bug in split_2MB_gtt_entry
If intel_gvt_dma_map_guest_page failed, it will call ppgtt_invalidate_spt, which will finally free the spt. But the caller function ppgtt_populate_spt_by_guest_entry does not notice that, it will free spt again in its error path. Fix this by canceling the mapping of DMA address and freeing sub_spt. Besides, leave the handle of spt destroy to caller function instead of callee function when error occurs. Fixes: b901b25 ("drm/i915/gvt: Add 2M huge gtt support") Signed-off-by: Zheng Wang <[email protected]> Reviewed-by: Zhenyu Wang <[email protected]> Signed-off-by: Zhenyu Wang <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 5229566 commit 601fd0f

File tree

1 file changed

+13
-4
lines changed
  • drivers/gpu/drm/i915/gvt

1 file changed

+13
-4
lines changed

drivers/gpu/drm/i915/gvt/gtt.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,10 +1209,8 @@ static int split_2MB_gtt_entry(struct intel_vgpu *vgpu,
12091209
for_each_shadow_entry(sub_spt, &sub_se, sub_index) {
12101210
ret = intel_gvt_dma_map_guest_page(vgpu, start_gfn + sub_index,
12111211
PAGE_SIZE, &dma_addr);
1212-
if (ret) {
1213-
ppgtt_invalidate_spt(spt);
1214-
return ret;
1215-
}
1212+
if (ret)
1213+
goto err;
12161214
sub_se.val64 = se->val64;
12171215

12181216
/* Copy the PAT field from PDE. */
@@ -1231,6 +1229,17 @@ static int split_2MB_gtt_entry(struct intel_vgpu *vgpu,
12311229
ops->set_pfn(se, sub_spt->shadow_page.mfn);
12321230
ppgtt_set_shadow_entry(spt, se, index);
12331231
return 0;
1232+
err:
1233+
/* Cancel the existing addess mappings of DMA addr. */
1234+
for_each_present_shadow_entry(sub_spt, &sub_se, sub_index) {
1235+
gvt_vdbg_mm("invalidate 4K entry\n");
1236+
ppgtt_invalidate_pte(sub_spt, &sub_se);
1237+
}
1238+
/* Release the new allocated spt. */
1239+
trace_spt_change(sub_spt->vgpu->id, "release", sub_spt,
1240+
sub_spt->guest_page.gfn, sub_spt->shadow_page.type);
1241+
ppgtt_free_spt(sub_spt);
1242+
return ret;
12341243
}
12351244

12361245
static int split_64KB_gtt_entry(struct intel_vgpu *vgpu,

0 commit comments

Comments
 (0)