@@ -596,6 +596,8 @@ struct kvm_memory_slot {
pgoff_t pgoff;
} gmem;
#endif
+
+ struct kvm *kvm;
};
static inline bool kvm_slot_can_be_private(const struct kvm_memory_slot *slot)
@@ -1769,6 +1769,7 @@ static void kvm_copy_memslot(struct kvm_memory_slot *dest,
dest->flags = src->flags;
dest->id = src->id;
dest->as_id = src->as_id;
+ dest->kvm = src->kvm;
}
static void kvm_invalidate_memslot(struct kvm *kvm,
@@ -2078,6 +2079,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
new->npages = npages;
new->flags = mem->flags;
new->userspace_addr = mem->userspace_addr;
+ new->kvm = kvm;
if (mem->flags & KVM_MEM_GUEST_MEMFD) {
r = kvm_gmem_bind(kvm, new, mem->guest_memfd, mem->guest_memfd_offset);
if (r)
Because a gfn having userfault enabled is tied to a struct kvm, we need a pointer to it. We could pass the kvm pointer around in the routines we need it, but that is a lot of churn, and there isn't much of a downside to simply storing the pointer in the memslot. Signed-off-by: James Houghton <jthoughton@google.com> --- include/linux/kvm_host.h | 2 ++ virt/kvm/kvm_main.c | 2 ++ 2 files changed, 4 insertions(+)