[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH RFC v1 06/10] target/loongarch: Implement kvm_arch_init_vcpu
From: |
Tianrui Zhao |
Subject: |
[PATCH RFC v1 06/10] target/loongarch: Implement kvm_arch_init_vcpu |
Date: |
Thu, 20 Apr 2023 17:36:02 +0800 |
Implement kvm_arch_init_vcpu interface for loongarch,
in this function, we register VM change state handler.
And when VM state changes to running, the counter value
should be put into kvm to keep consistent with kvm,
and when state change to stop, counter value should be
refreshed from kvm.
Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
---
target/loongarch/cpu.h | 1 +
target/loongarch/kvm.c | 23 +++++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
index 86b9f26d60..473d9986f3 100644
--- a/target/loongarch/cpu.h
+++ b/target/loongarch/cpu.h
@@ -350,6 +350,7 @@ struct ArchCPU {
/* 'compatible' string for this CPU for Linux device trees */
const char *dtb_compatible;
+ uint64_t counter_value;
};
#define TYPE_LOONGARCH_CPU "loongarch-cpu"
diff --git a/target/loongarch/kvm.c b/target/loongarch/kvm.c
index 53f495a588..f8772bbb27 100644
--- a/target/loongarch/kvm.c
+++ b/target/loongarch/kvm.c
@@ -397,8 +397,31 @@ int kvm_arch_put_registers(CPUState *cs, int level)
return ret;
}
+static void kvm_loongarch_vm_stage_change(void *opaque, bool running,
+ RunState state)
+{
+ int ret;
+ CPUState *cs = opaque;
+ LoongArchCPU *cpu = LOONGARCH_CPU(cs);
+
+ if (running) {
+ ret = kvm_larch_putq(cs, KVM_REG_LOONGARCH_COUNTER,
+ &cpu->counter_value);
+ if (ret < 0) {
+ printf("%s: Failed to put counter_value (%d)\n", __func__, ret);
+ }
+ } else {
+ ret = kvm_larch_getq(cs, KVM_REG_LOONGARCH_COUNTER,
+ &cpu->counter_value);
+ if (ret < 0) {
+ printf("%s: Failed to get counter_value (%d)\n", __func__, ret);
+ }
+ }
+}
+
int kvm_arch_init_vcpu(CPUState *cs)
{
+ qemu_add_vm_change_state_handler(kvm_loongarch_vm_stage_change, cs);
return 0;
}
--
2.31.1
- [PATCH RFC v1 00/10] Add loongarch kvm accel support, Tianrui Zhao, 2023/04/20
- [PATCH RFC v1 03/10] target/loongarch: Supplement vcpu env initial when vcpu reset, Tianrui Zhao, 2023/04/20
- [PATCH RFC v1 02/10] target/loongarch: Define some kvm_arch interfaces, Tianrui Zhao, 2023/04/20
- [PATCH RFC v1 05/10] target/loongarch: Implement kvm_arch_init function, Tianrui Zhao, 2023/04/20
- [PATCH RFC v1 10/10] target/loongarch: Add kvm file into meson build, Tianrui Zhao, 2023/04/20
- [PATCH RFC v1 04/10] target/loongarch: Implement kvm get/set registers, Tianrui Zhao, 2023/04/20
- [PATCH RFC v1 09/10] target/loongarch: Add kvm-stub.c, Tianrui Zhao, 2023/04/20
- [PATCH RFC v1 08/10] target/loongarch: Implement set vcpu intr for kvm, Tianrui Zhao, 2023/04/20
- [PATCH RFC v1 06/10] target/loongarch: Implement kvm_arch_init_vcpu,
Tianrui Zhao <=
- [PATCH RFC v1 01/10] linux-headers: Add KVM headers for loongarch, Tianrui Zhao, 2023/04/20
- [PATCH RFC v1 07/10] target/loongarch: Implement kvm_arch_handle_exit, Tianrui Zhao, 2023/04/20