lkml.org 
[lkml]   [2018]   [Dec]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[RFC][PATCH v2 14/21] kvm: register in mm_struct
VM is associated with an address space and not a specific thread.

>From Documentation/virtual/kvm/api.txt:
Only run VM ioctls from the same process (address space) that was used
to create the VM.

CC: Nikita Leshenko <nikita.leshchenko@oracle.com>
CC: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
---
include/linux/mm_types.h | 11 +++++++++++
virt/kvm/kvm_main.c | 3 +++
2 files changed, 14 insertions(+)

--- linux.orig/include/linux/mm_types.h 2018-12-23 19:58:06.993417137 +0800
+++ linux/include/linux/mm_types.h 2018-12-23 19:58:06.993417137 +0800
@@ -27,6 +27,7 @@ typedef int vm_fault_t;
struct address_space;
struct mem_cgroup;
struct hmm;
+struct kvm;

/*
* Each physical page in the system has a struct page associated with
@@ -496,6 +497,10 @@ struct mm_struct {
/* HMM needs to track a few things per mm */
struct hmm *hmm;
#endif
+
+#if IS_ENABLED(CONFIG_KVM)
+ struct kvm *kvm;
+#endif
} __randomize_layout;

/*
@@ -507,6 +512,12 @@ struct mm_struct {

extern struct mm_struct init_mm;

+#if IS_ENABLED(CONFIG_KVM)
+static inline struct kvm *mm_kvm(struct mm_struct *mm) { return mm->kvm; }
+#else
+static inline struct kvm *mm_kvm(struct mm_struct *mm) { return NULL; }
+#endif
+
/* Pointer magic because the dynamic array size confuses some compilers. */
static inline void mm_init_cpumask(struct mm_struct *mm)
{
--- linux.orig/virt/kvm/kvm_main.c 2018-12-23 19:58:06.993417137 +0800
+++ linux/virt/kvm/kvm_main.c 2018-12-23 19:58:06.993417137 +0800
@@ -727,6 +727,7 @@ static void kvm_destroy_vm(struct kvm *k
struct mm_struct *mm = kvm->mm;

kvm_uevent_notify_change(KVM_EVENT_DESTROY_VM, kvm);
+ mm->kvm = NULL;
kvm_destroy_vm_debugfs(kvm);
kvm_arch_sync_events(kvm);
spin_lock(&kvm_lock);
@@ -3224,6 +3225,8 @@ static int kvm_dev_ioctl_create_vm(unsig
fput(file);
return -ENOMEM;
}
+
+ kvm->mm->kvm = kvm;
kvm_uevent_notify_change(KVM_EVENT_CREATE_VM, kvm);

fd_install(r, file);

\
 
 \ /
  Last update: 2018-12-26 14:37    [W:0.283 / U:7.072 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site