[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 08/15] KVM: Split out common memory invalidation code
From: |
Chao Peng |
Subject: |
[PATCH v3 08/15] KVM: Split out common memory invalidation code |
Date: |
Tue, 21 Dec 2021 23:11:18 +0800 |
When fd-based memory is enabled, there will be two types of memory
invalidation:
- memory invalidation from native MMU through mmu_notifier callback
for hva-based memory, and,
- memory invalidation from memfd through memfd_notifier callback for
fd-based memory.
Some code can be shared between these two types of memory invalidation.
This patch moves these shared code into one place so that it can be
used for CONFIG_MMU_NOTIFIER as well as CONFIG_MEMFD_NOTIFIER.
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 | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 0f2d1002f6a7..59f01e68337b 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -454,22 +454,6 @@ void kvm_vcpu_destroy(struct kvm_vcpu *vcpu)
EXPORT_SYMBOL_GPL(kvm_vcpu_destroy);
#if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
-static inline struct kvm *mmu_notifier_to_kvm(struct mmu_notifier *mn)
-{
- return container_of(mn, struct kvm, mmu_notifier);
-}
-
-static void kvm_mmu_notifier_invalidate_range(struct mmu_notifier *mn,
- struct mm_struct *mm,
- unsigned long start, unsigned
long end)
-{
- struct kvm *kvm = mmu_notifier_to_kvm(mn);
- int idx;
-
- idx = srcu_read_lock(&kvm->srcu);
- kvm_arch_mmu_notifier_invalidate_range(kvm, start, end);
- srcu_read_unlock(&kvm->srcu, idx);
-}
typedef bool (*gfn_handler_t)(struct kvm *kvm, struct kvm_gfn_range *range);
@@ -580,6 +564,25 @@ static __always_inline int
__kvm_handle_useraddr_range(struct kvm *kvm,
/* The notifiers are averse to booleans. :-( */
return (int)ret;
}
+#endif
+
+#if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
+static inline struct kvm *mmu_notifier_to_kvm(struct mmu_notifier *mn)
+{
+ return container_of(mn, struct kvm, mmu_notifier);
+}
+
+static void kvm_mmu_notifier_invalidate_range(struct mmu_notifier *mn,
+ struct mm_struct *mm,
+ unsigned long start, unsigned
long end)
+{
+ struct kvm *kvm = mmu_notifier_to_kvm(mn);
+ int idx;
+
+ idx = srcu_read_lock(&kvm->srcu);
+ kvm_arch_mmu_notifier_invalidate_range(kvm, start, end);
+ srcu_read_unlock(&kvm->srcu, idx);
+}
static __always_inline int kvm_handle_hva_range(struct mmu_notifier *mn,
unsigned long start,
--
2.17.1
- [PATCH v3 00/15] KVM: mm: fd-based approach for supporting KVM guest private memory, Chao Peng, 2021/12/21
- [PATCH v3 01/15] mm/shmem: Introduce F_SEAL_INACCESSIBLE, Chao Peng, 2021/12/21
- [PATCH v3 02/15] mm/memfd: Introduce MFD_INACCESSIBLE flag, Chao Peng, 2021/12/21
- [PATCH v3 03/15] mm/memfd: Introduce MEMFD_OPS, Chao Peng, 2021/12/21
- [PATCH v3 04/15] KVM: Extend the memslot to support fd-based private memory, Chao Peng, 2021/12/21
- [PATCH v3 05/15] KVM: Implement fd-based memory using MEMFD_OPS interfaces, Chao Peng, 2021/12/21
- [PATCH v3 06/15] KVM: Refactor hva based memory invalidation code, Chao Peng, 2021/12/21
- [PATCH v3 07/15] KVM: Special handling for fd-based memory invalidation, Chao Peng, 2021/12/21
- [PATCH v3 08/15] KVM: Split out common memory invalidation code,
Chao Peng <=
- [PATCH v3 09/15] KVM: Implement fd-based memory invalidation, Chao Peng, 2021/12/21
- [PATCH v3 12/15] KVM: Add KVM_EXIT_MEMORY_ERROR exit, Chao Peng, 2021/12/21
- [PATCH v3 13/15] KVM: Handle page fault for private memory, Chao Peng, 2021/12/21
- [PATCH v3 14/15] KVM: Use kvm_userspace_memory_region_ext, Chao Peng, 2021/12/21
- [PATCH v3 10/15] KVM: Add kvm_map_gfn_range, Chao Peng, 2021/12/21
- [PATCH v3 15/15] KVM: Register/unregister private memory slot to memfd, Chao Peng, 2021/12/21
- [PATCH v3 11/15] KVM: Implement fd-based memory fallocation, Chao Peng, 2021/12/21
- Re: [PATCH v3 00/15] KVM: mm: fd-based approach for supporting KVM guest private memory, Sean Christopherson, 2021/12/21