From: Tianrui Zhao <zhaotianrui@xxxxxxxxxxx> Implement kvm_arch_handle_exit for loongarch. In this function, the KVM_EXIT_LOONGARCH_IOCSR is handled, we read or write the iocsr address space by the addr, length and is_write argument in kvm_run. Cc: "Michael S. Tsirkin" <mst@xxxxxxxxxx> Cc: Cornelia Huck <cohuck@xxxxxxxxxx> Cc: Paolo Bonzini <pbonzini@xxxxxxxxxx> Cc: "Marc-André Lureau" <marcandre.lureau@xxxxxxxxxx> Cc: "Daniel P. Berrangé" <berrange@xxxxxxxxxx> Cc: Thomas Huth <thuth@xxxxxxxxxx> Cc: "Philippe Mathieu-Daudé" <philmd@xxxxxxxxxx> Cc: Richard Henderson <richard.henderson@xxxxxxxxxx> Cc: Peter Maydell <peter.maydell@xxxxxxxxxx> Cc: Bibo Mao <maobibo@xxxxxxxxxxx> Cc: Song Gao <gaosong@xxxxxxxxxxx> Cc: Xiaojuan Yang <yangxiaojuan@xxxxxxxxxxx> Cc: Tianrui Zhao <zhaotianrui@xxxxxxxxxxx> Signed-off-by: Tianrui Zhao <zhaotianrui@xxxxxxxxxxx> Reviewed-by: Richard Henderson <richard.henderson@xxxxxxxxxx> Signed-off-by: xianglai li <lixianglai@xxxxxxxxxxx> --- target/loongarch/kvm.c | 24 +++++++++++++++++++++++- target/loongarch/trace-events | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/target/loongarch/kvm.c b/target/loongarch/kvm.c index 9754478e34..0fe52434ed 100644 --- a/target/loongarch/kvm.c +++ b/target/loongarch/kvm.c @@ -549,7 +549,29 @@ bool kvm_arch_cpu_check_are_resettable(void) int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) { - return 0; + int ret = 0; + LoongArchCPU *cpu = LOONGARCH_CPU(cs); + CPULoongArchState *env = &cpu->env; + MemTxAttrs attrs = {}; + + attrs.requester_id = env_cpu(env)->cpu_index; + + trace_kvm_arch_handle_exit(run->exit_reason); + switch (run->exit_reason) { + case KVM_EXIT_LOONGARCH_IOCSR: + address_space_rw(&env->address_space_iocsr, + run->iocsr_io.phys_addr, + attrs, + run->iocsr_io.data, + run->iocsr_io.len, + run->iocsr_io.is_write); + break; + default: + ret = -1; + warn_report("KVM: unknown exit reason %d", run->exit_reason); + break; + } + return ret; } void kvm_arch_accel_class_init(ObjectClass *oc) diff --git a/target/loongarch/trace-events b/target/loongarch/trace-events index f801ad7c76..6cce653b20 100644 --- a/target/loongarch/trace-events +++ b/target/loongarch/trace-events @@ -13,3 +13,4 @@ kvm_failed_get_counter(const char *msg) "Failed to get counter from KVM: %s" kvm_failed_put_counter(const char *msg) "Failed to put counter into KVM: %s" kvm_failed_get_cpucfg(const char *msg) "Failed to get cpucfg from KVM: %s" kvm_failed_put_cpucfg(const char *msg) "Failed to put cpucfg into KVM: %s" +kvm_arch_handle_exit(int num) "kvm arch handle exit, the reason number: %d" -- 2.39.1