#include "test_util.h"
struct xapic_vcpu {
- uint32_t id;
+ struct kvm_vcpu *vcpu;
bool is_x2apic;
};
} while (1);
}
-static void ____test_icr(struct kvm_vm *vm, struct xapic_vcpu *vcpu, uint64_t val)
+static void ____test_icr(struct kvm_vm *vm, struct xapic_vcpu *x, uint64_t val)
{
+ struct kvm_vcpu *vcpu = x->vcpu;
struct kvm_lapic_state xapic;
struct ucall uc;
uint64_t icr;
vcpu_ioctl(vm, vcpu->id, KVM_GET_LAPIC, &xapic);
icr = (u64)(*((u32 *)&xapic.regs[APIC_ICR])) |
(u64)(*((u32 *)&xapic.regs[APIC_ICR2])) << 32;
- if (!vcpu->is_x2apic)
+ if (!x->is_x2apic)
val &= (-1u | (0xffull << (32 + 24)));
ASSERT_EQ(icr, val & ~APIC_ICR_BUSY);
}
-static void __test_icr(struct kvm_vm *vm, struct xapic_vcpu *vcpu, uint64_t val)
+static void __test_icr(struct kvm_vm *vm, struct xapic_vcpu *x, uint64_t val)
{
- ____test_icr(vm, vcpu, val | APIC_ICR_BUSY);
- ____test_icr(vm, vcpu, val & ~(u64)APIC_ICR_BUSY);
+ ____test_icr(vm, x, val | APIC_ICR_BUSY);
+ ____test_icr(vm, x, val & ~(u64)APIC_ICR_BUSY);
}
-static void test_icr(struct kvm_vm *vm, struct xapic_vcpu *vcpu)
+static void test_icr(struct kvm_vm *vm, struct xapic_vcpu *x)
{
+ struct kvm_vcpu *vcpu = x->vcpu;
uint64_t icr, i, j;
icr = APIC_DEST_SELF | APIC_INT_ASSERT | APIC_DM_FIXED;
for (i = 0; i <= 0xff; i++)
- __test_icr(vm, vcpu, icr | i);
+ __test_icr(vm, x, icr | i);
icr = APIC_INT_ASSERT | APIC_DM_FIXED;
for (i = 0; i <= 0xff; i++)
- __test_icr(vm, vcpu, icr | i);
+ __test_icr(vm, x, icr | i);
/*
* Send all flavors of IPIs to non-existent vCPUs. TODO: use number of
icr = APIC_INT_ASSERT | 0xff;
for (i = vcpu->id + 1; i < 0xff; i++) {
for (j = 0; j < 8; j++)
- __test_icr(vm, vcpu, i << (32 + 24) | APIC_INT_ASSERT | (j << 8));
+ __test_icr(vm, x, i << (32 + 24) | APIC_INT_ASSERT | (j << 8));
}
/* And again with a shorthand destination for all types of IPIs. */
icr = APIC_DEST_ALLBUT | APIC_INT_ASSERT;
for (i = 0; i < 8; i++)
- __test_icr(vm, vcpu, icr | (i << 8));
+ __test_icr(vm, x, icr | (i << 8));
/* And a few garbage value, just make sure it's an IRQ (blocked). */
- __test_icr(vm, vcpu, 0xa5a5a5a5a5a5a5a5 & ~APIC_DM_FIXED_MASK);
- __test_icr(vm, vcpu, 0x5a5a5a5a5a5a5a5a & ~APIC_DM_FIXED_MASK);
- __test_icr(vm, vcpu, -1ull & ~APIC_DM_FIXED_MASK);
+ __test_icr(vm, x, 0xa5a5a5a5a5a5a5a5 & ~APIC_DM_FIXED_MASK);
+ __test_icr(vm, x, 0x5a5a5a5a5a5a5a5a & ~APIC_DM_FIXED_MASK);
+ __test_icr(vm, x, -1ull & ~APIC_DM_FIXED_MASK);
}
int main(int argc, char *argv[])
{
- struct xapic_vcpu vcpu = {
- .id = 0,
+ struct xapic_vcpu x = {
+ .vcpu = NULL,
.is_x2apic = true,
};
struct kvm_cpuid2 *cpuid;
struct kvm_vm *vm;
int i;
- vm = vm_create_default(vcpu.id, 0, x2apic_guest_code);
- test_icr(vm, &vcpu);
+ vm = vm_create_with_one_vcpu(&x.vcpu, x2apic_guest_code);
+ test_icr(vm, &x);
kvm_vm_free(vm);
/*
* the guest in order to test AVIC. KVM disallows changing CPUID after
* KVM_RUN and AVIC is disabled if _any_ vCPU is allowed to use x2APIC.
*/
- vm = vm_create_default(vcpu.id, 0, xapic_guest_code);
- vcpu.is_x2apic = false;
+ vm = vm_create_with_one_vcpu(&x.vcpu, xapic_guest_code);
+ x.is_x2apic = false;
- cpuid = vcpu_get_cpuid(vm, vcpu.id);
+ cpuid = vcpu_get_cpuid(vm, x.vcpu->id);
for (i = 0; i < cpuid->nent; i++) {
if (cpuid->entries[i].function == 1)
break;
}
cpuid->entries[i].ecx &= ~BIT(21);
- vcpu_set_cpuid(vm, vcpu.id, cpuid);
+ vcpu_set_cpuid(vm, x.vcpu->id, cpuid);
virt_pg_map(vm, APIC_DEFAULT_GPA, APIC_DEFAULT_GPA);
- test_icr(vm, &vcpu);
+ test_icr(vm, &x);
kvm_vm_free(vm);
}