From: Shivam Kumar <shivam.kumar1@nutanix.com>
To: pbonzini@redhat.com
Cc: kvm@vger.kernel.org, Shivam Kumar <shivam.kumar1@nutanix.com>,
Anurag Madnawat <anurag.madnawat@nutanix.com>,
Shaju Abraham <shaju.abraham@nutanix.com>,
Manish Mishra <manish.mishra@nutanix.com>
Subject: [PATCH 5/6] Exit to userspace when dirty quota is full.
Date: Sun, 14 Nov 2021 14:57:20 +0000 [thread overview]
Message-ID: <20211114145721.209219-6-shivam.kumar1@nutanix.com> (raw)
In-Reply-To: <20211114145721.209219-1-shivam.kumar1@nutanix.com>
Whenever dirty quota is full (i.e. dirty counter equals dirty quota),
control is passed to the QEMU side, through a KVM exit with the custom exit
reason KVM_EXIT_DIRTY_QUOTA_FULL, to handle the dirty quota full event.
Co-developed-by: Anurag Madnawat <anurag.madnawat@nutanix.com>
Signed-off-by: Anurag Madnawat <anurag.madnawat@nutanix.com>
Signed-off-by: Shivam Kumar <shivam.kumar1@nutanix.com>
Signed-off-by: Shaju Abraham <shaju.abraham@nutanix.com>
Signed-off-by: Manish Mishra <manish.mishra@nutanix.com>
---
arch/x86/kvm/x86.c | 9 +++++++++
include/linux/dirty_quota_migration.h | 6 ++++++
include/uapi/linux/kvm.h | 1 +
virt/kvm/dirty_quota_migration.c | 5 +++++
4 files changed, 21 insertions(+)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index dc7eb5fddfd3..32fc7a6f8b86 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -59,6 +59,7 @@
#include <linux/mem_encrypt.h>
#include <linux/entry-kvm.h>
#include <linux/suspend.h>
+#include <linux/dirty_quota_migration.h>
#include <trace/events/kvm.h>
@@ -10028,6 +10029,14 @@ static int vcpu_run(struct kvm_vcpu *vcpu)
return r;
vcpu->srcu_idx = srcu_read_lock(&kvm->srcu);
}
+
+ /* check for dirty quota migration exit condition if it is enabled */
+ if (vcpu->kvm->dirty_quota_migration_enabled &&
+ is_dirty_quota_full(vcpu->vCPUdqctx)) {
+ vcpu->run->exit_reason = KVM_EXIT_DIRTY_QUOTA_FULL;
+ r = 0;
+ break;
+ }
}
srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);
diff --git a/include/linux/dirty_quota_migration.h b/include/linux/dirty_quota_migration.h
index b6c6f5f896dd..b9b3bedd9682 100644
--- a/include/linux/dirty_quota_migration.h
+++ b/include/linux/dirty_quota_migration.h
@@ -30,11 +30,17 @@ static inline struct page *kvm_dirty_quota_context_get_page(
return NULL;
}
+static inline bool is_dirty_quota_full(struct vCPUDirtyQuotaContext *vCPUdqctx)
+{
+ return true;
+}
+
#else /* KVM_DIRTY_QUOTA_PAGE_OFFSET == 0 */
int kvm_vcpu_dirty_quota_alloc(struct vCPUDirtyQuotaContext **vCPUdqctx);
struct page *kvm_dirty_quota_context_get_page(
struct vCPUDirtyQuotaContext *vCPUdqctx, u32 offset);
+bool is_dirty_quota_full(struct vCPUDirtyQuotaContext *vCPUdqctx);
#endif /* KVM_DIRTY_QUOTA_PAGE_OFFSET == 0 */
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index a6785644bf47..6ba39a6015b0 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -270,6 +270,7 @@ struct kvm_xen_exit {
#define KVM_EXIT_X86_BUS_LOCK 33
#define KVM_EXIT_XEN 34
#define KVM_EXIT_RISCV_SBI 35
+#define KVM_EXIT_DIRTY_QUOTA_FULL 36
/* For KVM_EXIT_INTERNAL_ERROR */
/* Emulate instruction failed. */
diff --git a/virt/kvm/dirty_quota_migration.c b/virt/kvm/dirty_quota_migration.c
index 7e9ace760939..eeef19347af4 100644
--- a/virt/kvm/dirty_quota_migration.c
+++ b/virt/kvm/dirty_quota_migration.c
@@ -18,3 +18,8 @@ struct page *kvm_dirty_quota_context_get_page(
{
return vmalloc_to_page((void *)vCPUdqctx + offset * PAGE_SIZE);
}
+
+bool is_dirty_quota_full(struct vCPUDirtyQuotaContext *vCPUdqctx)
+{
+ return (vCPUdqctx->dirty_counter >= vCPUdqctx->dirty_quota);
+}
--
2.22.3
next prev parent reply other threads:[~2021-11-14 14:58 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-14 14:57 [PATCH 0/6] KVM: Dirty Quota-Based VM Live Migration Auto-Converge Shivam Kumar
2021-11-14 14:57 ` [PATCH 1/6] Define data structures for dirty quota migration Shivam Kumar
2021-11-14 14:57 ` [PATCH 2/6] Init dirty quota flag and allocate memory for vCPUdqctx Shivam Kumar
2021-11-14 14:57 ` [PATCH 3/6] Add KVM_CAP_DIRTY_QUOTA_MIGRATION and handle vCPU page faults Shivam Kumar
2021-11-18 17:57 ` Sean Christopherson
2021-11-19 20:03 ` Shivam Kumar
[not found] ` <02b8fa86-a86b-969e-2137-1953639cb6d2@nutanix.com>
[not found] ` <YZgD0D4536s2DMem@google.com>
2021-11-19 20:21 ` Shivam Kumar
2021-11-25 8:43 ` Shivam Kumar
2021-12-01 17:22 ` Sean Christopherson
2021-11-14 14:57 ` [PATCH 4/6] Increment dirty counter for vmexit due to page write fault Shivam Kumar
2021-11-18 17:48 ` Sean Christopherson
2021-11-19 19:54 ` Shivam Kumar
2021-11-14 14:57 ` Shivam Kumar [this message]
2021-11-14 14:57 ` [PATCH 6/6] Free vCPUdqctx memory on vCPU destroy Shivam Kumar
2021-11-18 17:46 ` [PATCH 0/6] KVM: Dirty Quota-Based VM Live Migration Auto-Converge Sean Christopherson
-- strict thread matches above, loose matches on Subject: below --
2021-10-26 16:35 Shivam Kumar
2021-10-26 16:35 ` [PATCH 5/6] Exit to userspace when dirty quota is full Shivam Kumar
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=20211114145721.209219-6-shivam.kumar1@nutanix.com \
--to=shivam.kumar1@nutanix.com \
--cc=anurag.madnawat@nutanix.com \
--cc=kvm@vger.kernel.org \
--cc=manish.mishra@nutanix.com \
--cc=pbonzini@redhat.com \
--cc=shaju.abraham@nutanix.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;
as well as URLs for NNTP newsgroup(s).