From: Hemanth Selam <hemanth.selam@gmail.com>
To: seanjc@google.com, pbonzini@redhat.com, shuah@kernel.org
Cc: kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 0/2] KVM: selftests: Actually test PV_UNHALT
Date: Wed, 26 Aug 2026 17:29:13 +0530 [thread overview]
Message-ID: <20260826115915.2882221-1-hemanth.selam@gmail.com> (raw)
test_pv_unhalt() only checks that KVM clears KVM_FEATURE_PV_UNHALT from
guest CPUID when HLT-exiting is disabled; the feature itself has never
been exercised, hence the FIXME. Patch 2 tests it by halting one vCPU
with interrupts disabled and kicking it from another, so that reaching the
instruction after HLT is proof that KVM_HC_KICK_CPU was delivered.
Patch 1 adds the helper that patch 2 needs to learn a vCPU's APIC ID from
the host, rather than open coding KVM_GET_LAPIC as a few tests already do.
Changes in v2:
- Pass the APIC ID to kick in a1, not a0. KVM reads it from a1, as the
in-kernel guest does in kvm_kick_cpu(), so v1 asked KVM to kick APIC ID
0 and only passed because the halting vCPU happened to be vCPU 0.
Spotted by the Sashiko AI reviewer.
- Halt on a vCPU with a non-zero APIC ID, so that a kick sent to the wrong
vCPU can no longer pass by accident, and enable that vCPU's APIC, as a
guest using PV spinlocks would: KVM only routes the kick once the vCPU
is in the APIC map, which is also why xapic_ipi_test enables it.
- Move the APIC ID helper into apic.h instead of keeping it private to
the test (new patch 1).
- Report the return value of pthread_create()/pthread_join() rather than
errno; they return the error directly and do not set errno.
Built and run on x86_64 (AMD). Untested on Intel, though the kick is
handled in common code and delivered through the generic LAPIC path.
- On kvm-x86/next, the whole selftest suite builds warning-free and
kvm_pv_test passed 10 of 10 runs.
- Also run inside a VM booted on a kernel built from kvm-x86/next, i.e.
against the KVM this targets rather than the host's.
- Whole x86 suite with the series applied: 61 passed, 24 skipped, and
set_sregs_test failed with "KVM allowed invalid efer bit (0x100)". That
one fails identically without the series, i.e. it is the host kernel.
The test was checked against four deliberate breakages, to make sure it
can only pass when the kick really works:
- pass the APIC ID in a0, i.e. the v1 bug: the kick goes to the wrong
vCPU and the test times out, so this version does catch it;
- drop the KVM_HC_KICK_CPU call: the halted vCPU is never resumed and the
test times out;
- clear PV_UNHALT from the kicking vCPU's CPUID while enforcement is on:
the hypercall returns -KVM_ENOSYS and the test fails with
0xfffffffffffffc18 != 0x0 (kvm_hypercall(KVM_HC_KICK_CPU, ...) != 0)
- remove the halt: the bounded wait trips and the test fails with
"vCPU never halted" rather than hanging.
Hemanth Selam (2):
KVM: selftests: Add a helper to read a vCPU's APIC ID
KVM: selftests: Test the PV_UNHALT feature, not just its CPUID bit
tools/testing/selftests/kvm/include/x86/apic.h | 9 ++
tools/testing/selftests/kvm/x86/kvm_pv_test.c | 97 +++++++++++++++++++++-
2 files changed, 105 insertions(+), 1 deletion(-)
--
2.43.7
next reply other threads:[~2026-08-26 11:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 11:59 Hemanth Selam [this message]
2026-08-26 11:59 ` [PATCH v2 1/2] KVM: selftests: Add a helper to read a vCPU's APIC ID Hemanth Selam
2026-08-26 11:59 ` [PATCH v2 2/2] KVM: selftests: Test the PV_UNHALT feature, not just its CPUID bit Hemanth Selam
2026-08-27 4:48 ` [PATCH v2 1/2] KVM: selftests: Add a helper to read a vCPU's APIC ID Hemanth Selam
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=20260826115915.2882221-1-hemanth.selam@gmail.com \
--to=hemanth.selam@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
/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