linux/tools/testing/selftests/kvm/arm64/idreg-idst.c
David Matlack 26f8453288 KVM: selftests: Use u64 instead of uint64_t
Use u64 instead of uint64_t to make the KVM selftests code more concise
and more similar to the kernel (since selftests are primarily developed
by kernel developers).

This commit was generated with the following command:

  git ls-files tools/testing/selftests/kvm | xargs sed -i 's/uint64_t/u64/g'

Then by manually adjusting whitespace to make checkpatch.pl happy.

Include <linux/types.h> in include/kvm_util_types.h, iinclude/test_util.h,
and include/x86/pmu.h to pick up the tools-defined u64.  Arguably, all
headers (especially kvm_util_types.h) should have already been including
stdint.h to get uint64_t from the libc headers, but the missing dependency
only rears its head once KVM uses u64 instead of uint64_t.

No functional change intended.

Signed-off-by: David Matlack <dmatlack@google.com>
[sean: rename pread_uint64() => pread_u64, expand on types.h include]
Link: https://patch.msgid.link/20260420212004.3938325-5-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-04-20 14:54:16 -07:00

118 lines
2.2 KiB
C

// SPDX-License-Identifier: GPL-2.0
/*
* Access all FEAT_IDST-handled registers that depend on more than
* just FEAT_AA64, and fail if we don't get an a trap with an 0x18 EC.
*/
#include <test_util.h>
#include <kvm_util.h>
#include <processor.h>
static volatile bool sys64, undef;
#define __check_sr_read(r) \
({ \
u64 val; \
\
sys64 = false; \
undef = false; \
dsb(sy); \
val = read_sysreg_s(SYS_ ## r); \
val; \
})
/* Fatal checks */
#define check_sr_read(r) \
do { \
__check_sr_read(r); \
__GUEST_ASSERT(!undef, #r " unexpected UNDEF"); \
__GUEST_ASSERT(sys64, #r " didn't trap"); \
} while(0)
static void guest_code(void)
{
check_sr_read(CCSIDR2_EL1);
check_sr_read(SMIDR_EL1);
check_sr_read(GMID_EL1);
GUEST_DONE();
}
static void guest_sys64_handler(struct ex_regs *regs)
{
sys64 = true;
undef = false;
regs->pc += 4;
}
static void guest_undef_handler(struct ex_regs *regs)
{
sys64 = false;
undef = true;
regs->pc += 4;
}
static void test_run_vcpu(struct kvm_vcpu *vcpu)
{
struct ucall uc;
do {
vcpu_run(vcpu);
switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT:
REPORT_GUEST_ASSERT(uc);
break;
case UCALL_PRINTF:
printf("%s", uc.buffer);
break;
case UCALL_DONE:
break;
default:
TEST_FAIL("Unknown ucall %lu", uc.cmd);
}
} while (uc.cmd != UCALL_DONE);
}
static void test_guest_feat_idst(void)
{
struct kvm_vcpu *vcpu;
struct kvm_vm *vm;
/* This VM has no MTE, no SME, no CCIDX */
vm = vm_create_with_one_vcpu(&vcpu, guest_code);
vm_init_descriptor_tables(vm);
vcpu_init_descriptor_tables(vcpu);
vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT,
ESR_ELx_EC_SYS64, guest_sys64_handler);
vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT,
ESR_ELx_EC_UNKNOWN, guest_undef_handler);
test_run_vcpu(vcpu);
kvm_vm_free(vm);
}
int main(int argc, char *argv[])
{
struct kvm_vcpu *vcpu;
struct kvm_vm *vm;
u64 mmfr2;
test_disable_default_vgic();
vm = vm_create_with_one_vcpu(&vcpu, NULL);
mmfr2 = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64MMFR2_EL1));
__TEST_REQUIRE(FIELD_GET(ID_AA64MMFR2_EL1_IDS, mmfr2) > 0,
"FEAT_IDST not supported");
kvm_vm_free(vm);
test_guest_feat_idst();
return 0;
}