From: sashiko-bot@kernel.org
To: "David Woodhouse" <dwmw2@infradead.org>, kvm@vger.kernel.org
Subject: Re: [PATCH v4 12/12] KVM: selftests: Fix unreachable timer recovery in xen_shinfo_test
Date: Mon, 19 Oct 2026 16:46:21 +0000 [thread overview]
Message-ID: <sashiko-outbox-177931@kernel.org> (raw)
In-Reply-To: <20261019162445.37219-13-dwmw2@infradead.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] KVM: selftests: wrong fix in guest_code() for juggle_shinfo_state() GFN 0 bug
--
commit 36db2d77eb09cc5d7b05a58f930d6724ba060038
Author: David Woodhouse <dwmw@amazon.co.uk>
KVM: selftests: Fix unreachable timer recovery in xen_shinfo_test
This commit adds a 10ms timeout to the SCHEDOP_poll hypercall in the
TEST_LOCKING_POLL_RACE phase of xen_shinfo_test so the guest does not hang if
the timer event is dropped while blocked in the poll.
> diff --git a/tools/testing/selftests/kvm/x86/xen_shinfo_test.c b/tools/testing/selftests/kvm/x86/xen_shinfo_test.c
> index 3b11d0ee253f5..729c0ba9ab4e8 100644
> --- a/tools/testing/selftests/kvm/x86/xen_shinfo_test.c
> +++ b/tools/testing/selftests/kvm/x86/xen_shinfo_test.c
> @@ -350,7 +350,14 @@ static void guest_code(void)
> p = (struct sched_poll) {
> .ports = ports,
> .nr_ports = 1,
> - .timeout = 0
> + /*
> + * The poll must have a timeout: if the timer event is dropped
> + * while we are already blocked in the poll, nothing else will
> + * ever wake us, and the recovery protocol below could never
> + * run. (As with TEST_POLL_TIMEOUT above, KVM treats the
> + * timeout as relative.)
> + */
> + .timeout = 10000000,
> };
>
> wait_for_timer:
[Severity: Medium]
Is SCHEDOP_poll in TEST_LOCKING_POLL_RACE actually supposed to block waiting
for the timer?
In main(), the host sets bit 0 of evtchn_pending[0] before arming the timer on
EVTCHN_TIMER:
tools/testing/selftests/kvm/x86/xen_shinfo_test.c:main() {
...
case TEST_LOCKING_POLL_RACE:
shinfo->evtchn_pending[0] = 1;
evtchn_irq_expected = true;
tmr.u.timer.expires_ns = rs->state_entry_time +
SHINFO_RACE_TIMEOUT * 1000000000ULL;
vcpu_ioctl(vcpu, KVM_XEN_VCPU_SET_ATTR, &tmr);
break;
}
And in guest_code(), the guest polls on port 0 (ports[0] = 0), not on
EVTCHN_TIMER. In wait_pending_event(), ret defaults to true:
arch/x86/kvm/xen.c:wait_pending_event() {
...
bool ret = true;
int idx, i;
idx = srcu_read_lock(&kvm->srcu);
read_lock_irqsave(&gpc->lock, flags);
if (!kvm_gpc_check(gpc, PAGE_SIZE))
goto out_rcu;
...
}
When shinfo_cache is deactivated, kvm_gpc_check() returns false and
wait_pending_event() returns true immediately. When shinfo_cache is active on
shinfo, bit 0 of evtchn_pending[0] is set, so test_bit() also returns true
without halting the vCPU. Furthermore, if the timer expires while shinfo_cache
is deactivated, xen_timer_callback() sees -EWOULDBLOCK from
kvm_xen_set_evtchn_fast() and unconditionally raises KVM_REQ_UNBLOCK and calls
kvm_vcpu_kick().
Instead, isn't the vCPU blocking in kvm_vcpu_halt() because of a bug in
juggle_shinfo_state()?
tools/testing/selftests/kvm/x86/xen_shinfo_test.c:juggle_shinfo_state() {
...
struct kvm_xen_hvm_attr cache_deactivate_hva = {
.type = KVM_XEN_ATTR_TYPE_SHARED_INFO,
.u.shared_info.hva = 0
};
...
}
Because cache_deactivate_hva uses KVM_XEN_ATTR_TYPE_SHARED_INFO instead of
KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA with hva = 0 (which unions with gfn = 0),
kvm_xen_hvm_set_attr() activates shinfo_cache on guest GFN 0 rather than
deactivating it (since KVM_XEN_ATTR_TYPE_SHARED_INFO checks for
KVM_XEN_INVALID_GFN). At guest GFN 0, evtchn_pending[0] bit 0 is 0, so a
concurrent SCHEDOP_poll sees the port as not pending and blocks in
kvm_vcpu_halt().
Adding a 10ms timeout here causes the guest to sleep in kvm_vcpu_halt() for
10ms whenever SCHEDOP_poll coincides with cache_deactivate_hva, rather than
spinning in the tight hypercall loop to stress gpc->lock contention, while
leaving KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA deactivation untested and continuing
to overwrite guest GFN 0 with wallclock data.
Should this instead fix cache_deactivate_hva.type to
KVM_XEN_ATTR_TYPE_SHARED_INFO_HVA in juggle_shinfo_state(), with:
Fixes: 9397b5334af1 ("KVM: selftests: map Xen's shared_info page using HVA rather than GFN")
?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261019162445.37219-1-dwmw2@infradead.org?part=12
prev parent reply other threads:[~2026-10-19 16:46 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 ` [PATCH v4 01/12] KVM: x86/xen: Don't block memslot updates while halted in SCHEDOP_poll David Woodhouse
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:54 ` sashiko-bot
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:37 ` sashiko-bot
2026-10-20 13:16 ` 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-10-19 16:46 ` sashiko-bot [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=sashiko-outbox-177931@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dwmw2@infradead.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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