- disable keyring option - loongarch: Change the UEFI loading mode to loongarch - target/loongarch: Fix qtest test-hmp error when KVM-only build - target/loongarch/kvm: Enable LSX/LASX extension - target/loongarch: Set cpuid CSR register only once with kvm mode - configure: Add linux header compile support for LoongArch - hw/intc/loongarch_extioi: Add vmstate post_load support - hw/intc/loongarch_extioi: Add dynamic cpu number support - hw/loongarch/virt: Set iocsr address space per-board rather than percpu - hw/intc/loongarch_ipi: Use MemTxAttrs interface for ipi ops - target/loongarch: Add loongarch kvm into meson build - target/loongarch: Implement set vcpu intr for kvm - target/loongarch: Restrict TCG-specific code - target/loongarch: Implement kvm_arch_handle_exit - target/loongarch: Implement kvm_arch_init_vcpu - target/loongarch: Implement kvm_arch_init function - target/loongarch: Implement kvm get/set registers - target/loongarch: Supplement vcpu env initial when vcpu reset - target/loongarch: Define some kvm_arch interfaces - linux-headers: Synchronize linux headers from linux v6.7.0-rc8 - linux-headers: Update to Linux v6.7-rc5 - target/loongarch: move translate modules to tcg/ - target/loongarch/meson: move gdbstub.c to loongarch.ss - target/loongarch: Add timer information dump support - hw/loongarch/virt: Align high memory base address with super page size Signed-off-by: Jiabo Feng <fengjiabo1@huawei.com> (cherry picked from commit b2263e41ffa3428f1d9f9ff6e214c8e3a19e06e8)
88 lines
3.2 KiB
Diff
88 lines
3.2 KiB
Diff
From d7d47c044c9854675b75b91ade678d03316d9271 Mon Sep 17 00:00:00 2001
|
|
From: Tianrui Zhao <zhaotianrui@loongson.cn>
|
|
Date: Fri, 5 Jan 2024 15:58:01 +0800
|
|
Subject: [PATCH] target/loongarch: Implement kvm_arch_init_vcpu
|
|
|
|
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>
|
|
Signed-off-by: xianglai li <lixianglai@loongson.cn>
|
|
Reviewed-by: Song Gao <gaosong@loongson.cn>
|
|
Message-Id: <20240105075804.1228596-7-zhaotianrui@loongson.cn>
|
|
Signed-off-by: Song Gao <gaosong@loongson.cn>
|
|
---
|
|
target/loongarch/cpu.h | 2 ++
|
|
target/loongarch/kvm/kvm.c | 23 +++++++++++++++++++++++
|
|
target/loongarch/trace-events | 2 ++
|
|
3 files changed, 27 insertions(+)
|
|
|
|
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
|
|
index f4a89bd626..8ebd6fa1a7 100644
|
|
--- a/target/loongarch/cpu.h
|
|
+++ b/target/loongarch/cpu.h
|
|
@@ -381,6 +381,8 @@ struct ArchCPU {
|
|
|
|
/* 'compatible' string for this CPU for Linux device trees */
|
|
const char *dtb_compatible;
|
|
+ /* used by KVM_REG_LOONGARCH_COUNTER ioctl to access guest time counters */
|
|
+ uint64_t kvm_state_counter;
|
|
};
|
|
|
|
/**
|
|
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
|
|
index 29944b9ef8..85e7aeb083 100644
|
|
--- a/target/loongarch/kvm/kvm.c
|
|
+++ b/target/loongarch/kvm/kvm.c
|
|
@@ -617,8 +617,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_set_one_reg(cs, KVM_REG_LOONGARCH_COUNTER,
|
|
+ &cpu->kvm_state_counter);
|
|
+ if (ret < 0) {
|
|
+ trace_kvm_failed_put_counter(strerror(errno));
|
|
+ }
|
|
+ } else {
|
|
+ ret = kvm_get_one_reg(cs, KVM_REG_LOONGARCH_COUNTER,
|
|
+ &cpu->kvm_state_counter);
|
|
+ if (ret < 0) {
|
|
+ trace_kvm_failed_get_counter(strerror(errno));
|
|
+ }
|
|
+ }
|
|
+}
|
|
+
|
|
int kvm_arch_init_vcpu(CPUState *cs)
|
|
{
|
|
+ qemu_add_vm_change_state_handler(kvm_loongarch_vm_stage_change, cs);
|
|
return 0;
|
|
}
|
|
|
|
diff --git a/target/loongarch/trace-events b/target/loongarch/trace-events
|
|
index 6827ab566a..937c3c7c0c 100644
|
|
--- a/target/loongarch/trace-events
|
|
+++ b/target/loongarch/trace-events
|
|
@@ -7,5 +7,7 @@ kvm_failed_get_fpu(const char *msg) "Failed to get fpu from KVM: %s"
|
|
kvm_failed_put_fpu(const char *msg) "Failed to put fpu into KVM: %s"
|
|
kvm_failed_get_mpstate(const char *msg) "Failed to get mp_state from KVM: %s"
|
|
kvm_failed_put_mpstate(const char *msg) "Failed to put mp_state into KVM: %s"
|
|
+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"
|
|
--
|
|
2.27.0
|
|
|