mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>,
	Paul Durrant <paul@xen.org>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	Fred Griffoul <fgriffo@amazon.co.uk>,
	David Woodhouse <dwmw@amazon.co.uk>
Subject: [PATCH v4 01/12] KVM: x86/xen: Don't block memslot updates while halted in SCHEDOP_poll
Date: Mon, 19 Oct 2026 17:24:32 +0100	[thread overview]
Message-ID: <20261019162445.37219-2-dwmw2@infradead.org> (raw)
In-Reply-To: <20261019162445.37219-1-dwmw2@infradead.org>

From: David Woodhouse <dwmw@amazon.co.uk>

kvm_xen_schedop_poll() halts the vCPU from within vcpu_run's exit
handling, without dropping the vCPU's kvm->srcu read section as
vcpu_block() is careful to do around every other halt. The poll wakes
only on delivery of a polled event channel, its poll timer, a signal,
or KVM_REQ_UNBLOCK — and a memslot update raises none of those. With a
zero timeout and a port which nobody is going to signal, the vCPU
sleeps at the guest's pleasure, holding the read section the whole
time.

A memslot update then hangs, unkillably, in kvm_swap_active_memslots()'s
synchronize_srcu() waiting for that reader to quiesce. Any guest with
SCHEDOP_poll available can thus park its VMM's memslot ioctls more or
less indefinitely.

Drop the srcu read section across the halt. A hypercall is only ever
processed from vcpu_run's exit handling, so the vCPU's own read lock
accounting is always the live section here, and nothing between the
unlock and the relock touches memslot-derived state: the pending-event
check which precedes it takes its own read section, and the timer
cleanup which follows does not need one.

Found by Sashiko review while testing the series which lets Xen
attribute ioctls wait out memslot updates — those waits joined the
same queue, with rather more visibility.

Fixes: 1a65105a5aba ("KVM: x86/xen: handle PV spinlocks slowpath")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
 arch/x86/kvm/xen.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c
index 6aa00f746cba..2a0477ad0c91 100644
--- a/arch/x86/kvm/xen.c
+++ b/arch/x86/kvm/xen.c
@@ -1594,7 +1594,15 @@ static bool kvm_xen_schedop_poll(struct kvm_vcpu *vcpu, bool is_64bit,
 			mod_timer(&vcpu->arch.xen.poll_timer,
 				  jiffies + nsecs_to_jiffies(sched_poll.timeout));
 
+		/*
+		 * Drop the vCPU's kvm->srcu read section across the halt, as
+		 * vcpu_block() does: the halt is unbounded (with a zero
+		 * timeout, entirely at the guest's pleasure), and a memslot
+		 * update cannot complete until this read section quiesces.
+		 */
+		kvm_vcpu_srcu_read_unlock(vcpu);
 		kvm_vcpu_halt(vcpu);
+		kvm_vcpu_srcu_read_lock(vcpu);
 
 		if (sched_poll.timeout)
 			timer_delete(&vcpu->arch.xen.poll_timer);
-- 
2.43.0


  reply	other threads:[~2026-10-19 16:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-19 16:24 [PATCH v4 00/12] KVM: x86/xen: Don't drop event deliveries which race memslot updates David Woodhouse
2026-10-19 16:24 ` David Woodhouse [this message]
2026-10-19 16:24 ` [PATCH v4 02/12] KVM: pfncache: Return -EAGAIN for a lookup which hits an invalid memslot David Woodhouse
2026-10-19 16:24 ` [PATCH v4 03/12] KVM: pfncache: Add a 'wait' argument to the refresh and activate functions David Woodhouse
2026-10-19 16:24 ` [PATCH v4 04/12] KVM: x86/xen: Wait out memslot updates in the Xen attribute ioctls David Woodhouse
2026-10-19 16:24 ` [PATCH v4 05/12] KVM: x86/xen: Don't lose the timer event when delivery fails transiently David Woodhouse
2026-10-19 16:24 ` [PATCH v4 06/12] KVM: x86/xen: Retry event channel delivery which races a memslot update David Woodhouse
2026-10-19 16:24 ` [PATCH v4 07/12] KVM: x86/xen: Extract delivery of event to vCPU into a separate helper David Woodhouse
2026-10-19 16:24 ` [PATCH v4 08/12] KVM: x86/xen: Explicitly tag "shared info" page as never being dirty tracked David Woodhouse
2026-10-19 16:24 ` [PATCH v4 09/12] KVM: x86/xen: Don't dirty track "vCPU info" page David Woodhouse
2026-10-19 16:24 ` [PATCH v4 10/12] KVM: x86: Request the guest TLB flush from record_steal_time() David Woodhouse
2026-10-19 16:24 ` [PATCH v4 11/12] KVM: selftests: Add Xen evtchn vs memslot-update race test David Woodhouse
2026-10-19 16:24 ` [PATCH v4 12/12] KVM: selftests: Fix unreachable timer recovery in xen_shinfo_test David Woodhouse
2026-11-03 22:46 ` [PATCH v4 00/12] KVM: x86/xen: Don't drop event deliveries which race memslot updates David Woodhouse
2026-11-04 19:55   ` Sean Christopherson
2026-11-05  0:42     ` David Woodhouse
2026-11-04 19:53 ` 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=20261019162445.37219-2-dwmw2@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=dwmw@amazon.co.uk \
    --cc=fgriffo@amazon.co.uk \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=paul@xen.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.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

all inboxes | Powered by JetHome®