public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Binbin Wu <binbin.wu@linux.intel.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Peter Xu <peterx@redhat.com>, Yan Zhao <yan.y.zhao@intel.com>,
	Maxim Levitsky <mlevitsk@redhat.com>
Subject: Re: [PATCH v2 1/5] KVM: Bound the number of dirty ring entries in a single reset at INT_MAX
Date: Tue, 13 May 2025 09:25:39 +0800	[thread overview]
Message-ID: <71228787-1cbc-4287-87a3-cda9aabcca3f@linux.intel.com> (raw)
In-Reply-To: <20250508141012.1411952-2-seanjc@google.com>



On 5/8/2025 10:10 PM, Sean Christopherson wrote:
> Cap the number of ring entries that are reset in a single ioctl to INT_MAX
> to ensure userspace isn't confused by a wrap into negative space, and so
> that, in a truly pathological scenario, KVM doesn't miss a TLB flush due
> to the count wrapping to zero.  While the size of the ring is fixed at
> 0x10000 entries and KVM (currently) supports at most 4096, userspace is
> allowed to harvest entries from the ring while the reset is in-progress,
> i.e. it's possible for the ring to always have harvested entries.
>
> Opportunistically return an actual error code from the helper so that a
> future fix to handle pending signals can gracefully return -EINTR.
>
> Cc: Peter Xu <peterx@redhat.com>
> Cc: Yan Zhao <yan.y.zhao@intel.com>
> Cc: Maxim Levitsky <mlevitsk@redhat.com>
> Fixes: fb04a1eddb1a ("KVM: X86: Implement ring-based dirty memory tracking")
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
>   include/linux/kvm_dirty_ring.h |  8 +++++---
>   virt/kvm/dirty_ring.c          | 10 +++++-----
>   virt/kvm/kvm_main.c            |  9 ++++++---
>   3 files changed, 16 insertions(+), 11 deletions(-)
>
> diff --git a/include/linux/kvm_dirty_ring.h b/include/linux/kvm_dirty_ring.h
> index da4d9b5f58f1..ee61ff6c3fe4 100644
> --- a/include/linux/kvm_dirty_ring.h
> +++ b/include/linux/kvm_dirty_ring.h
> @@ -49,9 +49,10 @@ static inline int kvm_dirty_ring_alloc(struct kvm *kvm, struct kvm_dirty_ring *r
>   }
>   
>   static inline int kvm_dirty_ring_reset(struct kvm *kvm,
> -				       struct kvm_dirty_ring *ring)
> +				       struct kvm_dirty_ring *ring,
> +				       int *nr_entries_reset)
>   {
> -	return 0;
> +	return -ENOENT;
>   }
>   
>   static inline void kvm_dirty_ring_push(struct kvm_vcpu *vcpu,
> @@ -82,7 +83,8 @@ int kvm_dirty_ring_alloc(struct kvm *kvm, struct kvm_dirty_ring *ring,
>    * called with kvm->slots_lock held, returns the number of
>    * processed pages.
>    */
The comment should be updated as well, since the return value is not the
number of processed pages now.


> -int kvm_dirty_ring_reset(struct kvm *kvm, struct kvm_dirty_ring *ring);
> +int kvm_dirty_ring_reset(struct kvm *kvm, struct kvm_dirty_ring *ring,
> +			 int *nr_entries_reset);
>   
[...]

  reply	other threads:[~2025-05-13  1:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-08 14:10 [PATCH v2 0/5] KVM: Dirty ring fixes and cleanups Sean Christopherson
2025-05-08 14:10 ` [PATCH v2 1/5] KVM: Bound the number of dirty ring entries in a single reset at INT_MAX Sean Christopherson
2025-05-13  1:25   ` Binbin Wu [this message]
2025-05-08 14:10 ` [PATCH v2 2/5] KVM: Bail from the dirty ring reset flow if a signal is pending Sean Christopherson
2025-05-08 14:10 ` [PATCH v2 3/5] KVM: Conditionally reschedule when resetting the dirty ring Sean Christopherson
2025-05-12 22:02   ` James Houghton
2025-05-13 14:13     ` Sean Christopherson
2025-05-13 22:27       ` James Houghton
2025-05-14 14:24         ` Sean Christopherson
2025-05-08 14:10 ` [PATCH v2 4/5] KVM: Check for empty mask of harvested dirty ring entries in caller Sean Christopherson
2025-05-13  9:17   ` Binbin Wu
2025-05-13 12:51   ` Gupta, Pankaj
2025-05-08 14:10 ` [PATCH v2 5/5] KVM: Use mask of harvested dirty ring entries to coalesce dirty ring resets Sean Christopherson
2025-05-12 22:33   ` James Houghton
2025-05-13 12:16   ` Gupta, Pankaj

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=71228787-1cbc-4287-87a3-cda9aabcca3f@linux.intel.com \
    --to=binbin.wu@linux.intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mlevitsk@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=seanjc@google.com \
    --cc=yan.y.zhao@intel.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