Skip to content

Commit 0a1b60d

Browse files
committed
drm/i915/gvt: Fix life cycle reference on KVM mm
Handle guest mm access life cycle properly with mmget()/mmput(). As noted by Linus, use_mm() depends on valid live page table but KVM's mmgrab() doesn't guarantee that. As vGPU usage depends on guest VM life cycle, need to make sure to use mmget()/mmput() to guarantee VM address access. v3: fix build v2: v1 caused a weird dependence issue which failed for vfio device release, which result invalid mdev vgpu and kvm state without proper release taken. This trys to put right reference around VM address space access instead. Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Zhi Wang <zhi.a.wang@intel.com> Reviewed-by: Zhi Wang <zhi.a.wang@intel.com> Signed-off-by: Zhenyu Wang <zhenyuw@linux.intel.com>
1 parent 54ff01f commit 0a1b60d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <linux/device.h>
3333
#include <linux/mm.h>
3434
#include <linux/mmu_context.h>
35+
#include <linux/sched/mm.h>
3536
#include <linux/types.h>
3637
#include <linux/list.h>
3738
#include <linux/rbtree.h>
@@ -1792,16 +1793,21 @@ static int kvmgt_rw_gpa(unsigned long handle, unsigned long gpa,
17921793
info = (struct kvmgt_guest_info *)handle;
17931794
kvm = info->kvm;
17941795

1795-
if (kthread)
1796+
if (kthread) {
1797+
if (!mmget_not_zero(kvm->mm))
1798+
return -EFAULT;
17961799
use_mm(kvm->mm);
1800+
}
17971801

17981802
idx = srcu_read_lock(&kvm->srcu);
17991803
ret = write ? kvm_write_guest(kvm, gpa, buf, len) :
18001804
kvm_read_guest(kvm, gpa, buf, len);
18011805
srcu_read_unlock(&kvm->srcu, idx);
18021806

1803-
if (kthread)
1807+
if (kthread) {
18041808
unuse_mm(kvm->mm);
1809+
mmput(kvm->mm);
1810+
}
18051811

18061812
return ret;
18071813
}

0 commit comments

Comments
 (0)