From: Hao Zhang <hao_zhang_kdev@163.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>, kvm@vger.kernel.org
Subject: [PATCH 2/2] KVM: Return dirty ring reset errors if no entries were reset
Date: Fri, 28 Aug 2026 17:19:14 +0800 [thread overview]
Message-ID: <apFSkpRoxhDMJwRr@192.168.1.215> (raw)
In-Reply-To: <apFQtIs9SLEobo04@192.168.1.215>
From: Hao Zhang <zhanghao1@kylinos.cn>
KVM_RESET_DIRTY_RINGS returns the number of entries that were reset.
Commit 530a8ba71b4c ("KVM: Bound the number of dirty ring entries in a
single reset at INT_MAX") converted kvm_dirty_ring_reset() to return a
standard 0/-errno, and commit 49005a2a3d2a ("KVM: Bail from the dirty
ring reset flow if a signal is pending") introduced an actual -EINTR path
by bailing out when a signal is pending.
kvm_vm_ioctl_reset_dirty_pages() currently breaks out of the vCPU loop on
error, but always returns the number of entries that were reset. As a
result, KVM reports success with a return value of 0 if a signal is
already pending before any entries are reset.
Preserve the existing partial-success behavior by returning the number of
reset entries after forward progress, but propagate the error if no
entries were reset.
Fixes: 49005a2a3d2a ("KVM: Bail from the dirty ring reset flow if a signal is pending")
Signed-off-by: Hao Zhang <zhanghao1@kylinos.cn>
---
virt/kvm/kvm_main.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 65eb26a0520d..ad472c577a7a 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -4999,7 +4999,7 @@ static int kvm_vm_ioctl_reset_dirty_pages(struct kvm *kvm)
{
unsigned long i;
struct kvm_vcpu *vcpu;
- int cleared = 0, r;
+ int cleared = 0, r = 0;
if (!kvm->dirty_ring_size)
return -EINVAL;
@@ -5017,7 +5017,12 @@ static int kvm_vm_ioctl_reset_dirty_pages(struct kvm *kvm)
if (cleared)
kvm_flush_remote_tlbs(kvm);
- return cleared;
+ /*
+ * Preserve partial-success semantics if KVM made forward progress, but
+ * don't squash errors when nothing was reset, e.g. if a signal was
+ * already pending.
+ */
+ return cleared ? cleared : r;
}
int __attribute__((weak)) kvm_vm_ioctl_enable_cap(struct kvm *kvm,
--
2.15.0
prev parent reply other threads:[~2026-08-28 9:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 9:11 [PATCH 1/2] KVM: Flush dirty ring resets before handling signals Hao Zhang
2026-08-28 9:19 ` Hao Zhang [this message]
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=apFSkpRoxhDMJwRr@192.168.1.215 \
--to=hao_zhang_kdev@163.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.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