From: Sean Christopherson <seanjc@google.com>
To: Shivam Kumar <shivam.kumar1@nutanix.com>
Cc: pbonzini@redhat.com, maz@kernel.org, james.morse@arm.com,
borntraeger@linux.ibm.com, david@redhat.com, kvm@vger.kernel.org,
Shaju Abraham <shaju.abraham@nutanix.com>,
Manish Mishra <manish.mishra@nutanix.com>,
Anurag Madnawat <anurag.madnawat@nutanix.com>
Subject: Re: [PATCH v6 1/5] KVM: Implement dirty quota-based throttling of vcpus
Date: Fri, 7 Oct 2022 19:08:52 +0000 [thread overview]
Message-ID: <Y0B5RFI25TotwWHT@google.com> (raw)
In-Reply-To: <20220915101049.187325-2-shivam.kumar1@nutanix.com>
On Thu, Sep 15, 2022, Shivam Kumar wrote:
> @@ -542,6 +545,21 @@ static inline int kvm_vcpu_exiting_guest_mode(struct kvm_vcpu *vcpu)
> return cmpxchg(&vcpu->mode, IN_GUEST_MODE, EXITING_GUEST_MODE);
> }
>
> +static inline int kvm_vcpu_check_dirty_quota(struct kvm_vcpu *vcpu)
> +{
> + struct kvm_run *run = vcpu->run;
> + u64 dirty_quota = READ_ONCE(run->dirty_quota);
> + u64 pages_dirtied = vcpu->stat.generic.pages_dirtied;
> +
> + if (!dirty_quota || (pages_dirtied < dirty_quota))
> + return 1;
> +
> + run->exit_reason = KVM_EXIT_DIRTY_QUOTA_EXHAUSTED;
> + run->dirty_quota_exit.count = pages_dirtied;
> + run->dirty_quota_exit.quota = dirty_quota;
> + return 0;
Dead code.
> +}
...
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 584a5bab3af3..f315af50037d 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -3298,18 +3298,36 @@ int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len)
> }
> EXPORT_SYMBOL_GPL(kvm_clear_guest);
>
> +static void kvm_vcpu_is_dirty_quota_exhausted(struct kvm_vcpu *vcpu)
Ouch, sorry. I suspect you got this name from me[*]. That was a goof on my end,
I'm 99% certain I copy-pasted stale code, i.e. didn't intended to suggest a
rename.
Let's keep kvm_vcpu_check_dirty_quota(), IMO that's still the least awful name.
[*] https://lore.kernel.org/all/Yo+82LjHSOdyxKzT@google.com
> +{
> + u64 dirty_quota = READ_ONCE(vcpu->run->dirty_quota);
> +
> + if (!dirty_quota || (vcpu->stat.generic.pages_dirtied < dirty_quota))
> + return;
> +
> + /*
> + * Snapshot the quota to report it to userspace. The dirty count will be
> + * captured when the request is processed.
> + */
> + vcpu->dirty_quota = dirty_quota;
> + kvm_make_request(KVM_REQ_DIRTY_QUOTA_EXIT, vcpu);
Making the request needs to be guarded with an arch opt-in. Pending requests
prevent KVM from entering the guest, and so making a request that an arch isn't
aware of will effectively hang the vCPU. Obviously userspace would be shooting
itself in the foot by setting run->dirty_quota in this case, but KVM shouldn't
hand userspace a loaded gun and help them aim.
My suggestion from v1[*] about not forcing architectures to opt-in was in the
context of a request-less implementation where dirty_quota was a nop until the
arch took action.
And regardless of arch opt-in, I think this needs a capability so that userspace
can detect KVM support.
I don't see any reason to wrap the request or vcpu_run field, e.g. something like
this should suffice:
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index ea5847d22aff..93362441215b 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -3298,8 +3298,9 @@ int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len)
}
EXPORT_SYMBOL_GPL(kvm_clear_guest);
-static void kvm_vcpu_is_dirty_quota_exhausted(struct kvm_vcpu *vcpu)
+static void kvm_vcpu_check_dirty_quota(struct kvm_vcpu *vcpu)
{
+#ifdef CONFIG_HAVE_KVM_DIRTY_QUOTA
u64 dirty_quota = READ_ONCE(vcpu->run->dirty_quota);
if (!dirty_quota || (vcpu->stat.generic.pages_dirtied < dirty_quota))
@@ -3311,6 +3312,7 @@ static void kvm_vcpu_is_dirty_quota_exhausted(struct kvm_vcpu *vcpu)
*/
vcpu->dirty_quota = dirty_quota;
kvm_make_request(KVM_REQ_DIRTY_QUOTA_EXIT, vcpu);
+#endif
}
void mark_page_dirty_in_slot(struct kvm *kvm,
@@ -4507,6 +4509,8 @@ static long kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg)
case KVM_CAP_BINARY_STATS_FD:
case KVM_CAP_SYSTEM_EVENT_DATA:
return 1;
+ case KVM_CAP_DIRTY_QUOTA:
+ return !!IS_ENABLED(CONFIG_HAVE_KVM_DIRTY_QUOTA);
default:
break;
}
[*] https://lore.kernel.org/all/YZaUENi0ZyQi%2F9M0@google.com
next prev parent reply other threads:[~2022-10-07 19:09 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-15 10:10 [PATCH v6 0/5] KVM: Dirty quota-based throttling Shivam Kumar
2022-09-15 10:10 ` [PATCH v6 1/5] KVM: Implement dirty quota-based throttling of vcpus Shivam Kumar
2022-09-15 13:21 ` Christian Borntraeger
2022-09-15 14:34 ` Christian Borntraeger
2022-10-07 18:18 ` Sean Christopherson
2022-10-09 18:36 ` Shivam Kumar
2022-10-10 6:12 ` Christian Borntraeger
2022-10-07 19:08 ` Sean Christopherson [this message]
2022-10-07 19:20 ` Sean Christopherson
2022-10-09 18:49 ` Shivam Kumar
2022-10-10 16:09 ` Sean Christopherson
2022-10-09 19:30 ` Shivam Kumar
2022-10-10 5:41 ` Shivam Kumar
2022-10-17 5:28 ` Shivam Kumar
2022-10-19 16:01 ` Sean Christopherson
2022-09-15 10:10 ` [PATCH v6 2/5] KVM: x86: Dirty " Shivam Kumar
2022-10-07 19:30 ` Sean Christopherson
2022-10-09 19:05 ` Shivam Kumar
2022-10-18 17:43 ` Shivam Kumar
2022-10-19 15:42 ` Sean Christopherson
2022-10-09 19:17 ` Shivam Kumar
2022-09-15 10:10 ` [PATCH v6 3/5] KVM: arm64: " Shivam Kumar
2022-09-15 10:10 ` [PATCH v6 4/5] KVM: s390x: " Shivam Kumar
2022-09-15 13:24 ` Christian Borntraeger
2022-09-15 10:10 ` [PATCH v6 5/5] KVM: selftests: Add selftests for dirty quota throttling Shivam Kumar
2022-10-07 18:29 ` Sean Christopherson
2022-10-09 19:26 ` Shivam Kumar
2022-10-10 15:47 ` Sean Christopherson
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=Y0B5RFI25TotwWHT@google.com \
--to=seanjc@google.com \
--cc=anurag.madnawat@nutanix.com \
--cc=borntraeger@linux.ibm.com \
--cc=david@redhat.com \
--cc=james.morse@arm.com \
--cc=kvm@vger.kernel.org \
--cc=manish.mishra@nutanix.com \
--cc=maz@kernel.org \
--cc=pbonzini@redhat.com \
--cc=shaju.abraham@nutanix.com \
--cc=shivam.kumar1@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.