[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v2 PATCH 10/13] KVM: Match inode for invalidation of fd-based slot
From: |
Chao Peng |
Subject: |
[RFC v2 PATCH 10/13] KVM: Match inode for invalidation of fd-based slot |
Date: |
Fri, 19 Nov 2021 21:47:36 +0800 |
Different fd/priv_fd can have the same userspace_addr so start/end
is meaningful only when they are used together with fd/priv_fd.
Signed-off-by: Yu Zhang <yu.c.zhang@linux.intel.com>
Signed-off-by: Chao Peng <chao.p.peng@linux.intel.com>
---
virt/kvm/kvm_main.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 090afbadb03f..65055ac460eb 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -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,
--
2.17.1
- Re: [RFC v2 PATCH 04/13] KVM: Add fd-based memslot data structure and utils, (continued)
- [RFC v2 PATCH 05/13] KVM: Implement fd-based memory using new memfd interfaces, Chao Peng, 2021/11/19
- [RFC v2 PATCH 06/13] KVM: Register/unregister memfd backed memslot, Chao Peng, 2021/11/19
- [RFC v2 PATCH 07/13] KVM: Handle page fault for fd based memslot, Chao Peng, 2021/11/19
- [RFC v2 PATCH 08/13] KVM: Rename hva memory invalidation code to cover fd-based offset, Chao Peng, 2021/11/19
- [RFC v2 PATCH 09/13] KVM: Introduce kvm_memfd_invalidate_range, Chao Peng, 2021/11/19
- [RFC v2 PATCH 10/13] KVM: Match inode for invalidation of fd-based slot,
Chao Peng <=
- [RFC v2 PATCH 11/13] KVM: Add kvm_map_gfn_range, Chao Peng, 2021/11/19
- [RFC v2 PATCH 12/13] KVM: Introduce kvm_memfd_fallocate_range, Chao Peng, 2021/11/19
- [RFC v2 PATCH 13/13] KVM: Enable memfd based page invalidation/fallocate, Chao Peng, 2021/11/19
- Re: [RFC v2 PATCH 13/13] KVM: Enable memfd based page invalidation/fallocate, Paolo Bonzini, 2021/11/23