Skip to content

Commit e364544

Browse files
committed
KVM: selftests: Add CPUID tests for Hyper-V features that need in-kernel APIC
Add testcases to x86's Hyper-V CPUID test to verify that KVM advertises support for features that require an in-kernel local APIC appropriately, i.e. that KVM hides support from the vCPU-scoped ioctl if the VM doesn't have an in-kernel local APIC. Cc: Vitaly Kuznetsov <vkuznets@redhat.com> Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com> Link: https://lore.kernel.org/r/20250118003454.2619573-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent cd5a0c2 commit e364544

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

tools/testing/selftests/kvm/x86/hyperv_cpuid.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static bool smt_possible(void)
4343

4444
static void test_hv_cpuid(struct kvm_vcpu *vcpu, bool evmcs_expected)
4545
{
46+
const bool has_irqchip = !vcpu || vcpu->vm->has_irqchip;
4647
const struct kvm_cpuid2 *hv_cpuid_entries;
4748
int i;
4849
int nent_expected = 10;
@@ -85,12 +86,19 @@ static void test_hv_cpuid(struct kvm_vcpu *vcpu, bool evmcs_expected)
8586
entry->eax, evmcs_expected
8687
);
8788
break;
89+
case 0x40000003:
90+
TEST_ASSERT(has_irqchip || !(entry->edx & BIT(19)),
91+
"\"Direct\" Synthetic Timers should require in-kernel APIC");
92+
break;
8893
case 0x40000004:
8994
test_val = entry->eax & (1UL << 18);
9095

9196
TEST_ASSERT(!!test_val == !smt_possible(),
9297
"NoNonArchitecturalCoreSharing bit"
9398
" doesn't reflect SMT setting");
99+
100+
TEST_ASSERT(has_irqchip || !(entry->eax & BIT(10)),
101+
"Cluster IPI (i.e. SEND_IPI) should require in-kernel APIC");
94102
break;
95103
case 0x4000000A:
96104
TEST_ASSERT(entry->eax & (1UL << 19),
@@ -145,9 +153,14 @@ int main(int argc, char *argv[])
145153

146154
TEST_REQUIRE(kvm_has_cap(KVM_CAP_HYPERV_CPUID));
147155

148-
vm = vm_create_with_one_vcpu(&vcpu, guest_code);
156+
/* Test the vCPU ioctl without an in-kernel local APIC. */
157+
vm = vm_create_barebones();
158+
vcpu = __vm_vcpu_add(vm, 0);
159+
test_hv_cpuid(vcpu, false);
160+
kvm_vm_free(vm);
149161

150162
/* Test vCPU ioctl version */
163+
vm = vm_create_with_one_vcpu(&vcpu, guest_code);
151164
test_hv_cpuid_e2big(vm, vcpu);
152165
test_hv_cpuid(vcpu, false);
153166

0 commit comments

Comments
 (0)