Skip to content

Commit 17229bd

Browse files
rananta468Marc Zyngier
authored andcommitted
KVM: arm64: selftests: Add guest support to get the vcpuid
At times, such as when in the interrupt handler, the guest wants to get the vcpuid that it's running on to pull the per-cpu private data. As a result, introduce guest_get_vcpuid() that returns the vcpuid of the calling vcpu. The interface is architecture independent, but defined only for arm64 as of now. Suggested-by: Reiji Watanabe <[email protected]> Signed-off-by: Raghavendra Rao Ananta <[email protected]> Reviewed-by: Ricardo Koller <[email protected]> Reviewed-by: Reiji Watanabe <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0226cd5 commit 17229bd

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

tools/testing/selftests/kvm/include/kvm_util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,6 @@ uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc);
400400
int vm_get_stats_fd(struct kvm_vm *vm);
401401
int vcpu_get_stats_fd(struct kvm_vm *vm, uint32_t vcpuid);
402402

403+
uint32_t guest_get_vcpuid(void);
404+
403405
#endif /* SELFTEST_KVM_UTIL_H */

tools/testing/selftests/kvm/lib/aarch64/processor.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ void aarch64_vcpu_setup(struct kvm_vm *vm, uint32_t vcpuid, struct kvm_vcpu_init
277277
set_reg(vm, vcpuid, KVM_ARM64_SYS_REG(SYS_TCR_EL1), tcr_el1);
278278
set_reg(vm, vcpuid, KVM_ARM64_SYS_REG(SYS_MAIR_EL1), DEFAULT_MAIR_EL1);
279279
set_reg(vm, vcpuid, KVM_ARM64_SYS_REG(SYS_TTBR0_EL1), vm->pgd);
280+
set_reg(vm, vcpuid, KVM_ARM64_SYS_REG(SYS_TPIDR_EL1), vcpuid);
280281
}
281282

282283
void vcpu_dump(FILE *stream, struct kvm_vm *vm, uint32_t vcpuid, uint8_t indent)
@@ -426,3 +427,8 @@ void vm_install_exception_handler(struct kvm_vm *vm, int vector,
426427
assert(vector < VECTOR_NUM);
427428
handlers->exception_handlers[vector][0] = handler;
428429
}
430+
431+
uint32_t guest_get_vcpuid(void)
432+
{
433+
return read_sysreg(tpidr_el1);
434+
}

0 commit comments

Comments
 (0)