Skip to content

Commit 304b93b

Browse files
bibo-maochenhuacai
authored andcommitted
KVM: selftests: Add ucall test support for LoongArch
Add ucall test support for LoongArch, ucall method on LoongArch uses undefined mmio area. It will cause vCPU exiting to hypervisor so that hypervisor can communicate with vCPU. Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 2ebf31d commit 304b93b

File tree

2 files changed

+58
-0
lines changed
  • tools/testing/selftests/kvm

2 files changed

+58
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
#ifndef SELFTEST_KVM_UCALL_H
3+
#define SELFTEST_KVM_UCALL_H
4+
5+
#include "kvm_util.h"
6+
7+
#define UCALL_EXIT_REASON KVM_EXIT_MMIO
8+
9+
/*
10+
* ucall_exit_mmio_addr holds per-VM values (global data is duplicated by each
11+
* VM), it must not be accessed from host code.
12+
*/
13+
extern vm_vaddr_t *ucall_exit_mmio_addr;
14+
15+
static inline void ucall_arch_do_ucall(vm_vaddr_t uc)
16+
{
17+
WRITE_ONCE(*ucall_exit_mmio_addr, uc);
18+
}
19+
20+
#endif
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* ucall support. A ucall is a "hypercall to userspace".
4+
*
5+
*/
6+
#include "kvm_util.h"
7+
8+
/*
9+
* ucall_exit_mmio_addr holds per-VM values (global data is duplicated by each
10+
* VM), it must not be accessed from host code.
11+
*/
12+
vm_vaddr_t *ucall_exit_mmio_addr;
13+
14+
void ucall_arch_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa)
15+
{
16+
vm_vaddr_t mmio_gva = vm_vaddr_unused_gap(vm, vm->page_size, KVM_UTIL_MIN_VADDR);
17+
18+
virt_map(vm, mmio_gva, mmio_gpa, 1);
19+
20+
vm->ucall_mmio_addr = mmio_gpa;
21+
22+
write_guest_global(vm, ucall_exit_mmio_addr, (vm_vaddr_t *)mmio_gva);
23+
}
24+
25+
void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu)
26+
{
27+
struct kvm_run *run = vcpu->run;
28+
29+
if (run->exit_reason == KVM_EXIT_MMIO &&
30+
run->mmio.phys_addr == vcpu->vm->ucall_mmio_addr) {
31+
TEST_ASSERT(run->mmio.is_write && run->mmio.len == sizeof(uint64_t),
32+
"Unexpected ucall exit mmio address access");
33+
34+
return (void *)(*((uint64_t *)run->mmio.data));
35+
}
36+
37+
return NULL;
38+
}

0 commit comments

Comments
 (0)