kvmgt: Hold struct kvm reference
Subsystems (5)
PATCH 1/1 kvmgt: Hold struct kvm reference
The kvmgt code keeps a pointer to the struct kvm associated with the device, but doesn't actually hold a reference to it. If we do unclean shutdown testing (ie. killing the user process), then we can see the kvm association to the device unset, which causes kvmgt to trigger a device release via a work queue. Naturally we cannot guarantee that the cached struct kvm pointer is still valid at this point without holding a reference. The observed failure in this case is a stuck cpu trying to acquire the spinlock from the invalid reference, but other failure modes are clearly possible. Hold a reference to avoid this.
--- drivers/gpu/drm/i915/gvt/kvmgt.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/i915/gvt/kvmgt.c +2 -0
@@ -1324,6 +1324,7 @@ static int kvmgt_guest_init(struct mdev_device *mdev) vgpu->handle = (unsigned long )info; info->vgpu = vgpu; info->kvm = kvm; +kvm_get_kvm (info->kvm);kvmgt_protect_table_init (info);gvt_cache_init (vgpu);
@@ -1343,6 +1344,7 @@ static bool kvmgt_guest_exit(struct kvmgt_guest_info *info) }kvm_page_track_unregister_notifier (info->kvm, &info->track_node); +kvm_put_kvm (info->kvm);kvmgt_protect_table_destroy (info);gvt_cache_destroy (info->vgpu);vfree (info);
Quoted 11 lines · Alex Williamson
The kvmgt code keeps a pointer to the struct kvm associated with the device, but doesn't actually hold a reference to it. If we do unclean shutdown testing (ie. killing the user process), then we can see the kvm association to the device unset, which causes kvmgt to trigger a device release via a work queue. Naturally we cannot guarantee that the cached struct kvm pointer is still valid at this point without holding a reference. The observed failure in this case is a stuck cpu trying to acquire the spinlock from the invalid reference, but other failure modes are clearly possible. Hold a reference to avoid this.
Quoted 7 lines
Signed-off-by Alex Williamson <[email protected]>Cc [email protected] #v4.10Cc Jike Song <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Zhenyu Wang <[email protected]>Cc Zhi Wang <[email protected]>---
Thanks for the fix!
--
Thanks,
Jike
Quoted 24 lines
drivers/gpu/drm/i915/gvt/kvmgt.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpu/drm/i915/gvt/kvmgt.c +2
-0@@ -1324,6 +1324,7 @@ static int kvmgt_guest_init(struct mdev_device *mdev) vgpu->handle = (unsigned long )info; info->vgpu = vgpu; info->kvm = kvm; +kvm_get_kvm (info->kvm);kvmgt_protect_table_init (info);gvt_cache_init (vgpu);@@ -1343,6 +1344,7 @@ static bool kvmgt_guest_exit(struct kvmgt_guest_info *info) }kvm_page_track_unregister_notifier (info->kvm, &info->track_node); +kvm_put_kvm (info->kvm);kvmgt_protect_table_destroy (info);gvt_cache_destroy (info->vgpu);vfree (info);
Zhenyu Wang
AppliedQuoted 20 lines · Jike Song
Quoted 11 lines · Alex Williamson
The kvmgt code keeps a pointer to the struct kvm associated with the device, but doesn't actually hold a reference to it. If we do unclean shutdown testing (ie. killing the user process), then we can see the kvm association to the device unset, which causes kvmgt to trigger a device release via a work queue. Naturally we cannot guarantee that the cached struct kvm pointer is still valid at this point without holding a reference. The observed failure in this case is a stuck cpu trying to acquire the spinlock from the invalid reference, but other failure modes are clearly possible. Hold a reference to avoid this.
Quoted 7 lines
Signed-off-by Alex Williamson <[email protected]>Cc [email protected] #v4.10Cc Jike Song <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Zhenyu Wang <[email protected]>Cc Zhi Wang <[email protected]>---
Quoted 4 lines
Reviewed-by Jike Song <[email protected]>Thanks for the fix!
queued in fixes tree, thanks!
Quoted 25 lines
Quoted 25 lines
drivers/gpu/drm/i915/gvt/kvmgt.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpu/drm/i915/gvt/kvmgt.c +2
-0@@ -1324,6 +1324,7 @@ static int kvmgt_guest_init(struct mdev_device *mdev) vgpu->handle = (unsigned long )info; info->vgpu = vgpu; info->kvm = kvm; +kvm_get_kvm (info->kvm);kvmgt_protect_table_init (info);gvt_cache_init (vgpu);@@ -1343,6 +1344,7 @@ static bool kvmgt_guest_exit(struct kvmgt_guest_info *info) }kvm_page_track_unregister_notifier (info->kvm, &info->track_node); +kvm_put_kvm (info->kvm);kvmgt_protect_table_destroy (info);gvt_cache_destroy (info->vgpu);vfree (info);
Signature · 3 lines
Open Source Technology Center, Intel ltd. $gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827