Skip to content

Commit 7df4e81

Browse files
sean-jcpull[bot]
authored andcommitted
drm/i915/gvt: Get reference to KVM iff attachment to VM is successful
Get a reference to KVM if and only if a vGPU is successfully attached to the VM to avoid leaking a reference if there's no available vGPU. On open_device() failure, vfio_device_open() doesn't invoke close_device(). Fixes: 421cfe6 ("vfio: remove VFIO_GROUP_NOTIFY_SET_KVM") Cc: stable@vger.kernel.org Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Zhenyu Wang <zhenyuw@linux.intel.com> Link: http://patchwork.freedesktop.org/patch/msgid/20221111002225.2418386-2-seanjc@google.com
1 parent 7306260 commit 7df4e81

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,6 @@ static int intel_vgpu_open_device(struct vfio_device *vfio_dev)
664664
return -ESRCH;
665665
}
666666

667-
kvm_get_kvm(vgpu->vfio_device.kvm);
668-
669667
if (__kvmgt_vgpu_exist(vgpu))
670668
return -EEXIST;
671669

@@ -676,6 +674,7 @@ static int intel_vgpu_open_device(struct vfio_device *vfio_dev)
676674

677675
vgpu->track_node.track_write = kvmgt_page_track_write;
678676
vgpu->track_node.track_flush_slot = kvmgt_page_track_flush_slot;
677+
kvm_get_kvm(vgpu->vfio_device.kvm);
679678
kvm_page_track_register_notifier(vgpu->vfio_device.kvm,
680679
&vgpu->track_node);
681680

0 commit comments

Comments
 (0)