Skip to content

Commit 537eef3

Browse files
committed
drm/i915/gvt: Explicitly check that vGPU is attached before shadowing
Move the check that a vGPU is attached from is_2MB_gtt_possible() all the way up to shadow_ppgtt_mm() to avoid unnecessary work, and to make it more obvious that a future cleanup of is_2MB_gtt_possible() isn't introducing a bug. is_2MB_gtt_possible() has only one caller, ppgtt_populate_shadow_entry(), and all paths in ppgtt_populate_shadow_entry() eventually check for attachment by way of intel_gvt_dma_map_guest_page(). And of the paths that lead to ppgtt_populate_shadow_entry(), shadow_ppgtt_mm() is the only one that doesn't already check for INTEL_VGPU_STATUS_ACTIVE or INTEL_VGPU_STATUS_ATTACHED. workload_thread() <= pick_next_workload() => INTEL_VGPU_STATUS_ACTIVE | -> dispatch_workload() | |-> prepare_workload() | -> intel_vgpu_sync_oos_pages() | | | |-> ppgtt_set_guest_page_sync() | | | |-> sync_oos_page() | | | |-> ppgtt_populate_shadow_entry() | |-> intel_vgpu_flush_post_shadow() | 1: |-> ppgtt_handle_guest_write_page_table() | |-> ppgtt_handle_guest_entry_add() | 2: | -> ppgtt_populate_spt_by_guest_entry() | | | |-> ppgtt_populate_spt() | | | |-> ppgtt_populate_shadow_entry() | | | |-> ppgtt_populate_spt_by_guest_entry() [see 2] | |-> ppgtt_populate_shadow_entry() kvmgt_page_track_write() <= KVM callback => INTEL_VGPU_STATUS_ATTACHED | |-> intel_vgpu_page_track_handler() | |-> ppgtt_write_protection_handler() | |-> ppgtt_handle_guest_write_page_table_bytes() | |-> ppgtt_handle_guest_write_page_table() [see 1] Reviewed-by: Yan Zhao <yan.y.zhao@intel.com> Tested-by: Yan Zhao <yan.y.zhao@intel.com> Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent f969eca commit 537eef3

File tree

1 file changed

+3
-2
lines changed
  • drivers/gpu/drm/i915/gvt

1 file changed

+3
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,8 +1163,6 @@ static int is_2MB_gtt_possible(struct intel_vgpu *vgpu,
11631163
if (!HAS_PAGE_SIZES(vgpu->gvt->gt->i915, I915_GTT_PAGE_SIZE_2M))
11641164
return 0;
11651165

1166-
if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status))
1167-
return -EINVAL;
11681166
pfn = gfn_to_pfn(vgpu->vfio_device.kvm, ops->get_pfn(entry));
11691167
if (is_error_noslot_pfn(pfn))
11701168
return -EINVAL;
@@ -1827,6 +1825,9 @@ static int shadow_ppgtt_mm(struct intel_vgpu_mm *mm)
18271825
if (mm->ppgtt_mm.shadowed)
18281826
return 0;
18291827

1828+
if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status))
1829+
return -EINVAL;
1830+
18301831
mm->ppgtt_mm.shadowed = true;
18311832

18321833
for (index = 0; index < ARRAY_SIZE(mm->ppgtt_mm.guest_pdps); index++) {

0 commit comments

Comments
 (0)