@@ -38,6 +38,7 @@ struct cfs_rq;
struct fs_struct;
struct futex_pi_state;
struct io_context;
+struct kvm;
struct mempolicy;
struct nameidata;
struct nsproxy;
@@ -1179,6 +1180,9 @@ struct task_struct {
/* Used by LSM modules for access restriction: */
void *security;
#endif
+#if IS_ENABLED(CONFIG_KVM)
+ struct kvm *kvm;
+#endif
/*
* New fields for task_struct should be added above here, so that
@@ -1898,4 +1902,10 @@ static inline void rseq_syscall(struct pt_regs *regs)
#endif
+#if IS_ENABLED(CONFIG_KVM)
+static inline struct kvm *task_kvm(struct task_struct *t) { return t->kvm; }
+#else
+static inline struct kvm *task_kvm(struct task_struct *t) { return NULL; }
+#endif
+
#endif
@@ -3892,6 +3892,7 @@ static void kvm_uevent_notify_change(unsigned int type, struct kvm *kvm)
if (type == KVM_EVENT_CREATE_VM) {
add_uevent_var(env, "EVENT=create");
kvm->userspace_pid = task_pid_nr(current);
+ current->kvm = kvm;
} else if (type == KVM_EVENT_DESTROY_VM) {
add_uevent_var(env, "EVENT=destroy");
}
The added pointer will be used by the /proc/PID/idle_bitmap code to quickly identify QEMU task and walk EPT/NPT accordingly. For virtual machines, the A bits will be set in guest page tables and EPT/NPT, rather than the QEMU task page table. This costs 8 bytes in task_struct which could be wasteful for the majority normal tasks. The alternative is to add a flag only, and let it find the corresponding VM in kvm vm_list. Signed-off-by: Fengguang Wu <fengguang.wu@intel.com> --- include/linux/sched.h | 10 ++++++++++ virt/kvm/kvm_main.c | 1 + 2 files changed, 11 insertions(+)