@@ -479,6 +479,7 @@ typedef void (*on_lock_fn_t)(struct kvm *kvm, unsigned long start,
struct kvm_useraddr_range {
unsigned long start;
unsigned long end;
+ struct inode *inode;
pte_t pte;
gfn_handler_t handler;
on_lock_fn_t on_lock;
@@ -520,6 +521,17 @@ static __always_inline int __kvm_handle_useraddr_range(struct kvm *kvm,
kvm_for_each_memslot(slot, slots) {
unsigned long useraddr_start, useraddr_end;
+ /*
+ * Skip the slot if range->inode is not the same as
+ * that in slot->file or slot->priv_file.
+ */
+ if (range->inode &&
+ (!slot->file ||
+ slot->file->f_inode != range->inode) &&
+ (!slot->priv_file ||
+ slot->priv_file->f_inode != range->inode))
+ continue;
+
useraddr_start = max(range->start, slot->userspace_addr);
useraddr_end = min(range->end, slot->userspace_addr +
(slot->npages << PAGE_SHIFT));
@@ -818,6 +830,7 @@ int kvm_memfd_invalidate_range(struct kvm *kvm, struct inode *inode,
const struct kvm_useraddr_range useraddr_range = {
.start = start,
.end = end,
+ .inode = inode,
.pte = __pte(0),
.handler = kvm_unmap_gfn_range,
.on_lock = (void *)kvm_null_fn,