Skip to content

Commit 4c29bac

Browse files
bluesheep1337ngboonkhai
authored andcommitted
drm/i915/gvt: fix double free bug in split_2MB_gtt_entry
[ Upstream commit 4a61648 ] 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] Signed-off-by: Sasha Levin <[email protected]>
1 parent 5866a6d commit 4c29bac

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
@@ -1214,10 +1214,8 @@ static int split_2MB_gtt_entry(struct intel_vgpu *vgpu,
12141214
for_each_shadow_entry(sub_spt, &sub_se, sub_index) {
12151215
ret = intel_gvt_dma_map_guest_page(vgpu, start_gfn + sub_index,
12161216
PAGE_SIZE, &dma_addr);
1217-
if (ret) {
1218-
ppgtt_invalidate_spt(spt);
1219-
return ret;
1220-
}
1217+
if (ret)
1218+
goto err;
12211219
sub_se.val64 = se->val64;
12221220

12231221
/* Copy the PAT field from PDE. */
@@ -1236,6 +1234,17 @@ static int split_2MB_gtt_entry(struct intel_vgpu *vgpu,
12361234
ops->set_pfn(se, sub_spt->shadow_page.mfn);
12371235
ppgtt_set_shadow_entry(spt, se, index);
12381236
return 0;
1237+
err:
1238+
/* Cancel the existing addess mappings of DMA addr. */
1239+
for_each_present_shadow_entry(sub_spt, &sub_se, sub_index) {
1240+
gvt_vdbg_mm("invalidate 4K entry\n");
1241+
ppgtt_invalidate_pte(sub_spt, &sub_se);
1242+
}
1243+
/* Release the new allocated spt. */
1244+
trace_spt_change(sub_spt->vgpu->id, "release", sub_spt,
1245+
sub_spt->guest_page.gfn, sub_spt->shadow_page.type);
1246+
ppgtt_free_spt(sub_spt);
1247+
return ret;
12391248
}
12401249

12411250
static int split_64KB_gtt_entry(struct intel_vgpu *vgpu,

0 commit comments

Comments
 (0)