This hypercall allows the guest to communicate with the host via the new exit type. It will be used in future patches to communicate guest-triggered change of memory sharing status with the host/vmm (kvmtool). Signed-off-by: Fuad Tabba <tabba@xxxxxxxxxx> --- arm/aarch32/include/kvm/kvm-arch.h | 1 + arm/aarch64/include/kvm/kvm-arch.h | 1 + arm/aarch64/kvm.c | 23 +++++++++++++++++++++++ arm/kvm-cpu.c | 10 ++++++++++ arm/kvm.c | 1 + 5 files changed, 36 insertions(+) diff --git a/arm/aarch32/include/kvm/kvm-arch.h b/arm/aarch32/include/kvm/kvm-arch.h index 467fb09..5666f2f 100644 --- a/arm/aarch32/include/kvm/kvm-arch.h +++ b/arm/aarch32/include/kvm/kvm-arch.h @@ -7,6 +7,7 @@ struct kvm; static inline void kvm__arch_enable_mte(struct kvm *kvm) {} +static inline void kvm__arch_enable_exit_hypcall(struct kvm *kvm) {} #define MAX_PAGE_SIZE SZ_4K diff --git a/arm/aarch64/include/kvm/kvm-arch.h b/arm/aarch64/include/kvm/kvm-arch.h index 02d09a4..9af002b 100644 --- a/arm/aarch64/include/kvm/kvm-arch.h +++ b/arm/aarch64/include/kvm/kvm-arch.h @@ -7,6 +7,7 @@ struct kvm; unsigned long long kvm__arch_get_kern_offset(struct kvm *kvm, int fd); int kvm__arch_get_ipa_limit(struct kvm *kvm); void kvm__arch_enable_mte(struct kvm *kvm); +void kvm__arch_enable_exit_hypcall(struct kvm *kvm); #define MAX_PAGE_SIZE SZ_64K diff --git a/arm/aarch64/kvm.c b/arm/aarch64/kvm.c index f65c9c1..604a5e8 100644 --- a/arm/aarch64/kvm.c +++ b/arm/aarch64/kvm.c @@ -163,3 +163,26 @@ void kvm__arch_enable_mte(struct kvm *kvm) pr_debug("MTE capability enabled"); } + +void kvm__arch_enable_exit_hypcall(struct kvm *kvm) +{ + struct kvm_enable_cap cap = { + .cap = KVM_CAP_EXIT_HYPERCALL, + .args[0] = KVM_EXIT_HYPERCALL_VALID_MASK, + }; + + if (kvm->cfg.arch.aarch32_guest) { + pr_debug("EXIT HYPERCALL is incompatible with AArch32"); + return; + } + + if (!kvm__supports_extension(kvm, KVM_CAP_EXIT_HYPERCALL)) { + pr_debug("EXIT HYPERCALL capability not available"); + return; + } + + if (ioctl(kvm->vm_fd, KVM_ENABLE_CAP, &cap)) + die_perror("KVM_ENABLE_CAP(KVM_CAP_EXIT_HYPERCALL)"); + + pr_debug("EXIT capability enabled"); +} diff --git a/arm/kvm-cpu.c b/arm/kvm-cpu.c index 98bc5fd..cb5a92a 100644 --- a/arm/kvm-cpu.c +++ b/arm/kvm-cpu.c @@ -146,6 +146,16 @@ void kvm_cpu__delete(struct kvm_cpu *vcpu) bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu) { + switch (vcpu->kvm_run->exit_reason) { + case KVM_EXIT_HYPERCALL: + pr_warning("Unhandled exit hypercall: 0x%llx, 0x%llx, 0x%llx, 0x%llx", + vcpu->kvm_run->hypercall.nr, + vcpu->kvm_run->hypercall.ret, + vcpu->kvm_run->hypercall.args[0], + vcpu->kvm_run->hypercall.args[1]); + return true; + } + return false; } diff --git a/arm/kvm.c b/arm/kvm.c index 094fbe4..f4b0247 100644 --- a/arm/kvm.c +++ b/arm/kvm.c @@ -84,6 +84,7 @@ void kvm__arch_init(struct kvm *kvm) die("Failed to create virtual GIC"); kvm__arch_enable_mte(kvm); + kvm__arch_enable_exit_hypcall(kvm); } #define FDT_ALIGN SZ_2M -- 2.39.0.rc0.267.gcb52ba06e7-goog