152 lines
4.4 KiB
Diff
152 lines
4.4 KiB
Diff
|
|
From 8febab6bcb01e3e10ca4ac0021bae2a812a4452b Mon Sep 17 00:00:00 2001
|
||
|
|
From: Bibo Mao <maobibo@loongson.cn>
|
||
|
|
Date: Mon, 30 Sep 2024 14:40:40 +0800
|
||
|
|
Subject: [PATCH 61/78] target/loongarch: Add steal time support on migration
|
||
|
|
|
||
|
|
With pv steal time supported, VM machine needs get physical address
|
||
|
|
of each vcpu and notify new host during migration. Here two
|
||
|
|
functions kvm_get_stealtime/kvm_set_stealtime, and guest steal time
|
||
|
|
physical address is only updated on KVM_PUT_FULL_STATE stage.
|
||
|
|
|
||
|
|
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
|
||
|
|
Reviewed-by: Song Gao <gaosong@loongson.cn>
|
||
|
|
Message-ID: <20240930064040.753929-1-maobibo@loongson.cn>
|
||
|
|
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
|
||
|
|
---
|
||
|
|
target/loongarch/cpu.h | 3 ++
|
||
|
|
target/loongarch/kvm/kvm.c | 65 ++++++++++++++++++++++++++++++++++++++
|
||
|
|
target/loongarch/machine.c | 6 ++--
|
||
|
|
3 files changed, 72 insertions(+), 2 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
|
||
|
|
index 8ff00d17e1..4c90cf9ef3 100644
|
||
|
|
--- a/target/loongarch/cpu.h
|
||
|
|
+++ b/target/loongarch/cpu.h
|
||
|
|
@@ -369,6 +369,9 @@ typedef struct CPUArchState {
|
||
|
|
uint64_t CSR_DBG;
|
||
|
|
uint64_t CSR_DERA;
|
||
|
|
uint64_t CSR_DSAVE;
|
||
|
|
+ struct {
|
||
|
|
+ uint64_t guest_addr;
|
||
|
|
+ } stealtime;
|
||
|
|
|
||
|
|
#ifdef CONFIG_TCG
|
||
|
|
float_status fp_status;
|
||
|
|
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
|
||
|
|
index 8b0f86a201..550f14269e 100644
|
||
|
|
--- a/target/loongarch/kvm/kvm.c
|
||
|
|
+++ b/target/loongarch/kvm/kvm.c
|
||
|
|
@@ -35,6 +35,55 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
|
||
|
|
KVM_CAP_LAST_INFO
|
||
|
|
};
|
||
|
|
|
||
|
|
+static int kvm_get_stealtime(CPUState *cs)
|
||
|
|
+{
|
||
|
|
+ CPULoongArchState *env = cpu_env(cs);
|
||
|
|
+ int err;
|
||
|
|
+ struct kvm_device_attr attr = {
|
||
|
|
+ .group = KVM_LOONGARCH_VCPU_PVTIME_CTRL,
|
||
|
|
+ .attr = KVM_LOONGARCH_VCPU_PVTIME_GPA,
|
||
|
|
+ .addr = (uint64_t)&env->stealtime.guest_addr,
|
||
|
|
+ };
|
||
|
|
+
|
||
|
|
+ err = kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, attr);
|
||
|
|
+ if (err) {
|
||
|
|
+ return 0;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ err = kvm_vcpu_ioctl(cs, KVM_GET_DEVICE_ATTR, attr);
|
||
|
|
+ if (err) {
|
||
|
|
+ error_report("PVTIME: KVM_GET_DEVICE_ATTR: %s", strerror(errno));
|
||
|
|
+ return err;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ return 0;
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
+static int kvm_set_stealtime(CPUState *cs)
|
||
|
|
+{
|
||
|
|
+ CPULoongArchState *env = cpu_env(cs);
|
||
|
|
+ int err;
|
||
|
|
+ struct kvm_device_attr attr = {
|
||
|
|
+ .group = KVM_LOONGARCH_VCPU_PVTIME_CTRL,
|
||
|
|
+ .attr = KVM_LOONGARCH_VCPU_PVTIME_GPA,
|
||
|
|
+ .addr = (uint64_t)&env->stealtime.guest_addr,
|
||
|
|
+ };
|
||
|
|
+
|
||
|
|
+ err = kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, attr);
|
||
|
|
+ if (err) {
|
||
|
|
+ return 0;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ err = kvm_vcpu_ioctl(cs, KVM_SET_DEVICE_ATTR, attr);
|
||
|
|
+ if (err) {
|
||
|
|
+ error_report("PVTIME: KVM_SET_DEVICE_ATTR %s with gpa "TARGET_FMT_lx,
|
||
|
|
+ strerror(errno), env->stealtime.guest_addr);
|
||
|
|
+ return err;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ return 0;
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
static int kvm_loongarch_get_regs_core(CPUState *cs)
|
||
|
|
{
|
||
|
|
int ret = 0;
|
||
|
|
@@ -790,6 +839,11 @@ int kvm_arch_get_registers(CPUState *cs)
|
||
|
|
return ret;
|
||
|
|
}
|
||
|
|
|
||
|
|
+ ret = kvm_get_stealtime(cs);
|
||
|
|
+ if (ret) {
|
||
|
|
+ return ret;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
ret = kvm_loongarch_get_mpstate(cs);
|
||
|
|
return ret;
|
||
|
|
}
|
||
|
|
@@ -823,6 +877,17 @@ int kvm_arch_put_registers(CPUState *cs, int level)
|
||
|
|
return ret;
|
||
|
|
}
|
||
|
|
|
||
|
|
+ if (level >= KVM_PUT_FULL_STATE) {
|
||
|
|
+ /*
|
||
|
|
+ * only KVM_PUT_FULL_STATE is required, kvm kernel will clear
|
||
|
|
+ * guest_addr for KVM_PUT_RESET_STATE
|
||
|
|
+ */
|
||
|
|
+ ret = kvm_set_stealtime(cs);
|
||
|
|
+ if (ret) {
|
||
|
|
+ return ret;
|
||
|
|
+ }
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
ret = kvm_loongarch_put_mpstate(cs);
|
||
|
|
return ret;
|
||
|
|
}
|
||
|
|
diff --git a/target/loongarch/machine.c b/target/loongarch/machine.c
|
||
|
|
index 5d62aabd51..fd69ea05dc 100644
|
||
|
|
--- a/target/loongarch/machine.c
|
||
|
|
+++ b/target/loongarch/machine.c
|
||
|
|
@@ -188,8 +188,8 @@ static const VMStateDescription vmstate_tlb = {
|
||
|
|
/* LoongArch CPU state */
|
||
|
|
const VMStateDescription vmstate_loongarch_cpu = {
|
||
|
|
.name = "cpu",
|
||
|
|
- .version_id = 2,
|
||
|
|
- .minimum_version_id = 2,
|
||
|
|
+ .version_id = 3,
|
||
|
|
+ .minimum_version_id = 3,
|
||
|
|
.post_load = cpu_post_load,
|
||
|
|
.pre_save = cpu_pre_save,
|
||
|
|
.fields = (const VMStateField[]) {
|
||
|
|
@@ -257,6 +257,8 @@ const VMStateDescription vmstate_loongarch_cpu = {
|
||
|
|
VMSTATE_UINT64(env.CSR_DSAVE, LoongArchCPU),
|
||
|
|
|
||
|
|
VMSTATE_UINT64(kvm_state_counter, LoongArchCPU),
|
||
|
|
+ /* PV steal time */
|
||
|
|
+ VMSTATE_UINT64(env.stealtime.guest_addr, LoongArchCPU),
|
||
|
|
|
||
|
|
VMSTATE_END_OF_LIST()
|
||
|
|
},
|
||
|
|
--
|
||
|
|
2.39.1
|
||
|
|
|