From: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
To: mtosatti@redhat.com
Cc: gleb@redhat.com, avi.kivity@gmail.com,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Subject: [PATCH v3 05/15] KVM: MMU: allow per-rmap operations
Date: Tue, 16 Apr 2013 14:32:43 +0800 [thread overview]
Message-ID: <1366093973-2617-6-git-send-email-xiaoguangrong@linux.vnet.ibm.com> (raw)
In-Reply-To: <1366093973-2617-1-git-send-email-xiaoguangrong@linux.vnet.ibm.com>
Introduce rmap_operations to allow rmap having different operations,
then, we are able to handle invalid rmap specially
Signed-off-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
---
arch/x86/include/asm/kvm_host.h | 1 +
arch/x86/kvm/mmu.c | 31 ++++++++++++++++++++++++-------
arch/x86/kvm/mmu.h | 16 ++++++++++++++++
arch/x86/kvm/x86.c | 1 +
4 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 4e1f7cb..5fd6ed1 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -511,6 +511,7 @@ struct kvm_lpage_info {
};
struct kvm_arch_memory_slot {
+ struct rmap_operations *ops;
unsigned long *rmap[KVM_NR_PAGE_SIZES];
struct kvm_lpage_info *lpage_info[KVM_NR_PAGE_SIZES - 1];
};
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 514f5b1..99ad2a4 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -1055,13 +1055,13 @@ static int slot_rmap_add(struct kvm_memory_slot *slot,
struct kvm_vcpu *vcpu, unsigned long *rmapp,
u64 *spte)
{
- return pte_list_add(vcpu, spte, rmapp);
+ return slot->arch.ops->rmap_add(vcpu, spte, rmapp);
}
static void slot_rmap_remove(struct kvm_memory_slot *slot,
unsigned long *rmapp, u64 *spte)
{
- pte_list_remove(spte, rmapp);
+ slot->arch.ops->rmap_remove(spte, rmapp);
}
static int rmap_add(struct kvm_vcpu *vcpu, u64 *spte, gfn_t gfn)
@@ -1238,7 +1238,7 @@ static bool slot_rmap_write_protect(struct kvm_memory_slot *slot,
struct kvm *kvm, unsigned long *rmapp,
bool pt_protect)
{
- return __rmap_write_protect(kvm, rmapp, pt_protect);
+ return slot->arch.ops->rmap_write_protect(kvm, rmapp, pt_protect);
}
/**
@@ -1306,7 +1306,7 @@ static int kvm_unmap_rmapp(struct kvm *kvm, unsigned long *rmapp)
static int slot_rmap_unmap(struct kvm *kvm, unsigned long *rmapp,
struct kvm_memory_slot *slot, unsigned long data)
{
- return kvm_unmap_rmapp(kvm, rmapp);
+ return slot->arch.ops->rmap_unmap(kvm, rmapp);
}
static int kvm_set_pte_rmapp(struct kvm *kvm, unsigned long *rmapp,
@@ -1353,7 +1353,7 @@ static int kvm_set_pte_rmapp(struct kvm *kvm, unsigned long *rmapp,
static int slot_rmap_set_pte(struct kvm *kvm, unsigned long *rmapp,
struct kvm_memory_slot *slot, unsigned long data)
{
- return kvm_set_pte_rmapp(kvm, rmapp, (pte_t *)data);
+ return slot->arch.ops->rmap_set_pte(kvm, rmapp, (pte_t *)data);
}
static int kvm_handle_hva_range(struct kvm *kvm,
@@ -1470,7 +1470,7 @@ out:
static int slot_rmap_age(struct kvm *kvm, unsigned long *rmapp,
struct kvm_memory_slot *slot, unsigned long data)
{
- int young = kvm_age_rmapp(kvm, rmapp);
+ int young = slot->arch.ops->rmap_age(kvm, rmapp);
/* @data has hva passed to kvm_age_hva(). */
trace_kvm_age_page(data, slot, young);
@@ -1508,7 +1508,7 @@ static int slot_rmap_test_age(struct kvm *kvm, unsigned long *rmapp,
struct kvm_memory_slot *slot,
unsigned long data)
{
- return kvm_test_age_rmapp(kvm, rmapp);
+ return slot->arch.ops->rmap_test_age(kvm, rmapp);
}
#define RMAP_RECYCLE_THRESHOLD 1000
@@ -1537,6 +1537,23 @@ int kvm_test_age_hva(struct kvm *kvm, unsigned long hva)
return kvm_handle_hva(kvm, hva, 0, slot_rmap_test_age);
}
+static struct rmap_operations normal_rmap_ops = {
+ .rmap_add = pte_list_add,
+ .rmap_remove = pte_list_remove,
+
+ .rmap_write_protect = __rmap_write_protect,
+
+ .rmap_set_pte = kvm_set_pte_rmapp,
+ .rmap_age = kvm_age_rmapp,
+ .rmap_test_age = kvm_test_age_rmapp,
+ .rmap_unmap = kvm_unmap_rmapp
+};
+
+void init_memslot_rmap_ops(struct kvm_memory_slot *slot)
+{
+ slot->arch.ops = &normal_rmap_ops;
+}
+
#ifdef MMU_DEBUG
static int is_empty_shadow_page(u64 *spt)
{
diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
index ffd40d1..bb2b22e 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -114,4 +114,20 @@ static inline bool permission_fault(struct kvm_mmu *mmu, unsigned pte_access,
return (mmu->permissions[pfec >> 1] >> pte_access) & 1;
}
+struct rmap_operations {
+ int (*rmap_add)(struct kvm_vcpu *vcpu, u64 *spte,
+ unsigned long *rmap);
+ void (*rmap_remove)(u64 *spte, unsigned long *rmap);
+
+ bool (*rmap_write_protect)(struct kvm *kvm, unsigned long *rmap,
+ bool pt_protect);
+
+ int (*rmap_set_pte)(struct kvm *kvm, unsigned long *rmap,
+ pte_t *ptep);
+ int (*rmap_age)(struct kvm *kvm, unsigned long *rmap);
+ int (*rmap_test_age)(struct kvm *kvm, unsigned long *rmap);
+ int (*rmap_unmap)(struct kvm *kvm, unsigned long *rmapp);
+};
+
+void init_memslot_rmap_ops(struct kvm_memory_slot *slot);
#endif
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 839e666..bec83cd 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -6919,6 +6919,7 @@ static int kvm_arch_create_memslot(struct kvm_memory_slot *slot)
}
}
+ init_memslot_rmap_ops(slot);
return 0;
out_free:
--
1.7.7.6
next prev parent reply other threads:[~2013-04-16 6:33 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-16 6:32 [PATCH v3 00/15] KVM: MMU: fast zap all shadow pages Xiao Guangrong
2013-04-16 6:32 ` [PATCH v3 01/15] KVM: x86: clean up and optimize for kvm_arch_free_memslot Xiao Guangrong
2013-04-16 6:32 ` [PATCH v3 02/15] KVM: fold kvm_arch_create_memslot into kvm_arch_prepare_memory_region Xiao Guangrong
2013-04-16 6:32 ` [PATCH v3 03/15] KVM: x86: do not reuse rmap when memslot is moved Xiao Guangrong
2013-04-16 6:32 ` [PATCH v3 04/15] KVM: MMU: abstract memslot rmap related operations Xiao Guangrong
2013-04-16 6:32 ` Xiao Guangrong [this message]
2013-04-16 6:32 ` [PATCH v3 06/15] KVM: MMU: allow concurrently clearing spte on remove-only pte-list Xiao Guangrong
2013-04-16 6:32 ` [PATCH v3 07/15] KVM: MMU: introduce invalid rmap handlers Xiao Guangrong
2013-04-17 23:38 ` Marcelo Tosatti
2013-04-18 3:15 ` Xiao Guangrong
2013-04-16 6:32 ` [PATCH v3 08/15] KVM: MMU: allow unmap invalid rmap out of mmu-lock Xiao Guangrong
2013-04-18 11:00 ` Gleb Natapov
2013-04-18 11:22 ` Xiao Guangrong
2013-04-18 11:38 ` Gleb Natapov
2013-04-18 12:10 ` Xiao Guangrong
2013-04-16 6:32 ` [PATCH v3 09/15] KVM: MMU: introduce free_meslot_rmap_desc_nolock Xiao Guangrong
2013-04-16 6:32 ` [PATCH v3 10/15] KVM: x86: introduce memslot_set_lpage_disallowed Xiao Guangrong
2013-04-16 6:32 ` [PATCH v3 11/15] KVM: MMU: introduce kvm_clear_all_lpage_info Xiao Guangrong
2013-04-16 6:32 ` [PATCH v3 12/15] KVM: MMU: fast invalid all shadow pages Xiao Guangrong
2013-04-18 0:05 ` Marcelo Tosatti
2013-04-18 4:00 ` Xiao Guangrong
2013-04-18 13:03 ` Marcelo Tosatti
2013-04-18 13:29 ` Marcelo Tosatti
2013-04-18 15:20 ` Xiao Guangrong
2013-04-16 6:32 ` [PATCH v3 13/15] KVM: x86: use the fast way to invalid all pages Xiao Guangrong
2013-04-16 6:32 ` [PATCH v3 14/15] KVM: move srcu_read_lock/srcu_read_unlock to arch-specified code Xiao Guangrong
2013-04-16 6:32 ` [PATCH v3 15/15] KVM: MMU: replace kvm_zap_all with kvm_mmu_invalid_all_pages Xiao Guangrong
2013-04-18 0:08 ` Marcelo Tosatti
2013-04-18 4:03 ` Xiao Guangrong
2013-04-20 17:18 ` Marcelo Tosatti
2013-04-21 6:59 ` Xiao Guangrong
2013-04-21 13:03 ` [PATCH v3 00/15] KVM: MMU: fast zap all shadow pages Gleb Natapov
2013-04-21 14:09 ` Xiao Guangrong
2013-04-21 15:24 ` Marcelo Tosatti
2013-04-22 2:50 ` Xiao Guangrong
2013-04-22 9:21 ` Gleb Natapov
2013-04-23 0:19 ` Xiao Guangrong
2013-04-23 6:28 ` Gleb Natapov
2013-04-23 7:20 ` Xiao Guangrong
2013-04-23 7:33 ` Gleb Natapov
2013-04-21 15:27 ` Marcelo Tosatti
2013-04-21 15:35 ` Marcelo Tosatti
2013-04-22 12:39 ` Gleb Natapov
2013-04-22 13:45 ` Takuya Yoshikawa
2013-04-22 23:02 ` Marcelo Tosatti
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1366093973-2617-6-git-send-email-xiaoguangrong@linux.vnet.ibm.com \
--to=xiaoguangrong@linux.vnet.ibm.com \
--cc=avi.kivity@gmail.com \
--cc=gleb@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®