On 28/02/23 7:01 am, Yuan Yao wrote:
On Sat, Feb 25, 2023 at 08:47:59PM +0000, Shivam Kumar wrote:
Call update_dirty_quota whenever a page is marked dirty with
appropriate arch-specific page size. Process the KVM request
KVM_REQ_DIRTY_QUOTA_EXIT (raised by update_dirty_quota) to exit to
userspace with exit reason KVM_EXIT_DIRTY_QUOTA_EXHAUSTED.
Suggested-by: Shaju Abraham <shaju.abraham@xxxxxxxxxxx>
Suggested-by: Manish Mishra <manish.mishra@xxxxxxxxxxx>
Co-developed-by: Anurag Madnawat <anurag.madnawat@xxxxxxxxxxx>
Signed-off-by: Anurag Madnawat <anurag.madnawat@xxxxxxxxxxx>
Signed-off-by: Shivam Kumar <shivam.kumar1@xxxxxxxxxxx>
---
arch/x86/kvm/Kconfig | 1 +
arch/x86/kvm/mmu/mmu.c | 8 +++++++-
arch/x86/kvm/mmu/spte.c | 3 +++
arch/x86/kvm/mmu/tdp_mmu.c | 3 +++
arch/x86/kvm/vmx/vmx.c | 5 +++++
arch/x86/kvm/x86.c | 16 ++++++++++++++++
arch/x86/kvm/xen.c | 12 +++++++++++-
7 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig
index 8e578311ca9d..8621a9512572 100644
--- a/arch/x86/kvm/Kconfig
+++ b/arch/x86/kvm/Kconfig
@@ -48,6 +48,7 @@ config KVM
select KVM_VFIO
select SRCU
select INTERVAL_TREE
+ select HAVE_KVM_DIRTY_QUOTA
select HAVE_KVM_PM_NOTIFIER if PM
select KVM_GENERIC_HARDWARE_ENABLING
help
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index c8ebe542c565..e0c8348ecdf1 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -3323,8 +3323,14 @@ fast_pf_fix_direct_spte(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault,
if (!try_cmpxchg64(sptep, &old_spte, new_spte))
return false;
- if (is_writable_pte(new_spte) && !is_writable_pte(old_spte))
+ if (is_writable_pte(new_spte) && !is_writable_pte(old_spte)) {
+#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA
+ struct kvm_mmu_page *sp = sptep_to_sp(sptep);
+
+ update_dirty_quota(vcpu->kvm, (1L << SPTE_LEVEL_SHIFT(sp->role.level)));
+#endif
mark_page_dirty_in_slot(vcpu->kvm, fault->slot, fault->gfn);
Possible to call update_dirty_quota() from mark_page_dirty_in_slot() ?
Then other Architectures can be covered yet.
As Marc commented on the first patch of this patchset,
mark_page_dirty_in_slot can be called multiple times for the same page,
e.g. in the case of PML for nested guests. If bitmap-based dirty
tracking is not enabled, we might not be able to handle those cases
without adding an extra param (which can tell us whether a dirty quota
update is required or not) in mark_page_dirty_in_slot. Thanks.
Thanks,
Shivam