From befb917f7ace75c78b42b811f51d4e948f471903 Mon Sep 17 00:00:00 2001 From: Ying Fang Date: Fri, 22 May 2020 19:10:08 +0800 Subject: [PATCH 1/6] spec: Update release version increase release version by one Signed-off-by: Ying Fang --- qemu.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qemu.spec b/qemu.spec index 94280a1b..1a9cb337 100644 --- a/qemu.spec +++ b/qemu.spec @@ -1,6 +1,6 @@ Name: qemu Version: 4.1.0 -Release: 8 +Release: 9 Epoch: 2 Summary: QEMU is a generic and open source machine emulator and virtualizer License: GPLv2 and BSD and MIT and CC-BY -- Gitee From 3591ff8735bac4f69ebac86765e6c38cfc7e87ec Mon Sep 17 00:00:00 2001 From: Ying Fang Date: Wed, 27 May 2020 11:35:14 +0800 Subject: [PATCH 2/6] Revert: "vtimer: compat cross version migration from v4.0.1" This reverts commit patch: vtimer-compat-cross-version-migration-from-v4.0.1.patch Signed-off-by: Ying Fang --- ...mpat-cross-version-migration-from-v4.patch | 37 +++++++++++++++++++ qemu.spec | 4 ++ 2 files changed, 41 insertions(+) create mode 100644 Revert-vtimer-compat-cross-version-migration-from-v4.patch diff --git a/Revert-vtimer-compat-cross-version-migration-from-v4.patch b/Revert-vtimer-compat-cross-version-migration-from-v4.patch new file mode 100644 index 00000000..082f1763 --- /dev/null +++ b/Revert-vtimer-compat-cross-version-migration-from-v4.patch @@ -0,0 +1,37 @@ +From ced290d644a00e18e70046194d042bcaa2703b65 Mon Sep 17 00:00:00 2001 +From: Ying Fang +Date: Wed, 27 May 2020 11:16:53 +0800 +Subject: [PATCH] Revert: "vtimer: compat cross version migration from v4.0.1" + +This reverts commit patch: +vtimer-compat-cross-version-migration-from-v4.0.1.patch + +Signed-off-by: Ying Fang + +diff --git a/target/arm/cpu.h b/target/arm/cpu.h +index 2609113d..86eb79cd 100644 +--- a/target/arm/cpu.h ++++ b/target/arm/cpu.h +@@ -261,7 +261,6 @@ typedef struct CPUARMState { + uint64_t elr_el[4]; /* AArch64 exception link regs */ + uint64_t sp_el[4]; /* AArch64 banked stack pointers */ + +- uint64_t vtimer; /* Timer tick when vcpu is stopped */ + + /* System control coprocessor (cp15) */ + struct { +diff --git a/target/arm/machine.c b/target/arm/machine.c +index ec28b839..ee3c59a6 100644 +--- a/target/arm/machine.c ++++ b/target/arm/machine.c +@@ -814,7 +814,6 @@ const VMStateDescription vmstate_arm_cpu = { + VMSTATE_UINT32(env.exception.syndrome, ARMCPU), + VMSTATE_UINT32(env.exception.fsr, ARMCPU), + VMSTATE_UINT64(env.exception.vaddress, ARMCPU), +- VMSTATE_UINT64(env.vtimer, ARMCPU), + VMSTATE_TIMER_PTR(gt_timer[GTIMER_PHYS], ARMCPU), + VMSTATE_TIMER_PTR(gt_timer[GTIMER_VIRT], ARMCPU), + { +-- +2.23.0 + diff --git a/qemu.spec b/qemu.spec index 1a9cb337..ebaf85b7 100644 --- a/qemu.spec +++ b/qemu.spec @@ -168,6 +168,7 @@ Patch0155: slirp-tftp-restrict-relative-path-access.patch Patch0156: ip_reass-Fix-use-after-free.patch Patch0157: bt-use-size_t-type-for-length-parameters-instead-of-.patch Patch0158: log-Add-some-logs-on-VM-runtime-path.patch +Patch0159: Revert-vtimer-compat-cross-version-migration-from-v4.patch BuildRequires: flex BuildRequires: bison @@ -513,6 +514,9 @@ getent passwd qemu >/dev/null || \ %endif %changelog +* Wed May 27 2020 Huawei Technologies Co., Ltd. +- Revert: "vtimer: compat cross version migration from v4.0.1" + * Fri May 22 2020 Huawei Technologies Co., Ltd. - ip_reass: Fix use after free - bt: use size_t type for length parameters instead of int -- Gitee From 8aa99fcf689ba4ac20eb2dcfe16263a9664c81f1 Mon Sep 17 00:00:00 2001 From: Ying Fang Date: Wed, 27 May 2020 11:37:33 +0800 Subject: [PATCH 3/6] vtimer: introduce the vtimer first used in v4.0.1 To support cross version migration, we had to add the vtimer back which was introduced in openEuler qemu-4.0.1. Signed-off-by: Ying Fang --- ...cord-vtimer-tick-when-cpu-is-stopped.patch | 134 ++++++++++++++++++ qemu.spec | 2 + 2 files changed, 136 insertions(+) create mode 100644 ARM64-record-vtimer-tick-when-cpu-is-stopped.patch diff --git a/ARM64-record-vtimer-tick-when-cpu-is-stopped.patch b/ARM64-record-vtimer-tick-when-cpu-is-stopped.patch new file mode 100644 index 00000000..4681e9f3 --- /dev/null +++ b/ARM64-record-vtimer-tick-when-cpu-is-stopped.patch @@ -0,0 +1,134 @@ +From 4646a24045cf53f2cc5e0ef1974da88ef50ef676 Mon Sep 17 00:00:00 2001 +From: Ying Fang +Date: Wed, 27 May 2020 11:54:31 +0800 +Subject: [PATCH] ARM64: record vtimer tick when cpu is stopped + +The vtimer kick still increases even if the vcpu is stopped when VM has +save/restore or suspend/resume operation. This will cause guest watchdog +soft-lockup if the VM has lots of memory in use. + +Signed-off-by: Hao Hong +Signed-off-by: Haibin Wang +Signed-off-by: Ying Fang +--- + cpus.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ + target/arm/cpu.h | 2 ++ + target/arm/machine.c | 1 + + 3 files changed, 61 insertions(+) + +diff --git a/cpus.c b/cpus.c +index 927a00aa..b9aa51f8 100644 +--- a/cpus.c ++++ b/cpus.c +@@ -1066,6 +1066,28 @@ void cpu_synchronize_all_pre_loadvm(void) + } + } + ++#ifdef __aarch64__ ++static void get_vcpu_timer_tick(CPUState *cs) ++{ ++ CPUARMState *env = &ARM_CPU(cs)->env; ++ int err; ++ struct kvm_one_reg reg; ++ uint64_t timer_tick; ++ ++ reg.id = KVM_REG_ARM_TIMER_CNT; ++ reg.addr = (uintptr_t) &timer_tick; ++ ++ err = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®); ++ if (err < 0) { ++ error_report("get vcpu tick failed, ret = %d", err); ++ env->vtimer = 0; ++ return; ++ } ++ env->vtimer = timer_tick; ++ return; ++} ++#endif ++ + static int do_vm_stop(RunState state, bool send_stop) + { + int ret = 0; +@@ -1073,6 +1095,11 @@ static int do_vm_stop(RunState state, bool send_stop) + if (runstate_is_running()) { + cpu_disable_ticks(); + pause_all_vcpus(); ++#ifdef __aarch64__ ++ if (first_cpu) { ++ get_vcpu_timer_tick(first_cpu); ++ } ++#endif + runstate_set(state); + vm_state_notify(0, state); + if (send_stop) { +@@ -1918,11 +1945,42 @@ void cpu_resume(CPUState *cpu) + qemu_cpu_kick(cpu); + } + ++#ifdef __aarch64__ ++static void set_vcpu_timer_tick(CPUState *cs) ++{ ++ CPUARMState *env = &ARM_CPU(cs)->env; ++ ++ if (env->vtimer == 0) { ++ return; ++ } ++ ++ int err; ++ struct kvm_one_reg reg; ++ uint64_t timer_tick = env->vtimer; ++ env->vtimer = 0; ++ ++ reg.id = KVM_REG_ARM_TIMER_CNT; ++ reg.addr = (uintptr_t) &timer_tick; ++ ++ err = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®); ++ if (err < 0) { ++ error_report("Set vcpu tick failed, ret = %d", err); ++ return; ++ } ++ return; ++} ++#endif ++ + void resume_all_vcpus(void) + { + CPUState *cpu; + + qemu_clock_enable(QEMU_CLOCK_VIRTUAL, true); ++#ifdef __aarch64__ ++ if (first_cpu) { ++ set_vcpu_timer_tick(first_cpu); ++ } ++#endif + CPU_FOREACH(cpu) { + cpu_resume(cpu); + } +diff --git a/target/arm/cpu.h b/target/arm/cpu.h +index 86eb79cd..aec6a214 100644 +--- a/target/arm/cpu.h ++++ b/target/arm/cpu.h +@@ -262,6 +262,8 @@ typedef struct CPUARMState { + uint64_t sp_el[4]; /* AArch64 banked stack pointers */ + + ++ uint64_t vtimer; /* Timer tick when vcpu stop */ ++ + /* System control coprocessor (cp15) */ + struct { + uint32_t c0_cpuid; +diff --git a/target/arm/machine.c b/target/arm/machine.c +index ee3c59a6..ec28b839 100644 +--- a/target/arm/machine.c ++++ b/target/arm/machine.c +@@ -814,6 +814,7 @@ const VMStateDescription vmstate_arm_cpu = { + VMSTATE_UINT32(env.exception.syndrome, ARMCPU), + VMSTATE_UINT32(env.exception.fsr, ARMCPU), + VMSTATE_UINT64(env.exception.vaddress, ARMCPU), ++ VMSTATE_UINT64(env.vtimer, ARMCPU), + VMSTATE_TIMER_PTR(gt_timer[GTIMER_PHYS], ARMCPU), + VMSTATE_TIMER_PTR(gt_timer[GTIMER_VIRT], ARMCPU), + { +-- +2.23.0 + diff --git a/qemu.spec b/qemu.spec index ebaf85b7..3c8bfef7 100644 --- a/qemu.spec +++ b/qemu.spec @@ -169,6 +169,7 @@ Patch0156: ip_reass-Fix-use-after-free.patch Patch0157: bt-use-size_t-type-for-length-parameters-instead-of-.patch Patch0158: log-Add-some-logs-on-VM-runtime-path.patch Patch0159: Revert-vtimer-compat-cross-version-migration-from-v4.patch +Patch0160: ARM64-record-vtimer-tick-when-cpu-is-stopped.patch BuildRequires: flex BuildRequires: bison @@ -516,6 +517,7 @@ getent passwd qemu >/dev/null || \ %changelog * Wed May 27 2020 Huawei Technologies Co., Ltd. - Revert: "vtimer: compat cross version migration from v4.0.1" +- ARM64: record vtimer tick when cpu is stopped * Fri May 22 2020 Huawei Technologies Co., Ltd. - ip_reass: Fix use after free -- Gitee From a30721ae20156ceb9e79766119773d2eb220a08e Mon Sep 17 00:00:00 2001 From: Ying Fang Date: Wed, 27 May 2020 11:41:47 +0800 Subject: [PATCH 4/6] hw/arm/virt: add missing compat for kvm-no-adjvtime Machine compatibility for kvm-no-adjvtime is missed, let's add it for virt machine 4.0, thus kvm-no-adjvtime is supported in v4.1.0. Signed-off-by: Ying Fang --- ...d-missing-compat-for-kvm-no-adjvtime.patch | 25 +++++++++++++++++++ qemu.spec | 2 ++ 2 files changed, 27 insertions(+) create mode 100644 hw-arm-virt-add-missing-compat-for-kvm-no-adjvtime.patch diff --git a/hw-arm-virt-add-missing-compat-for-kvm-no-adjvtime.patch b/hw-arm-virt-add-missing-compat-for-kvm-no-adjvtime.patch new file mode 100644 index 00000000..3d711678 --- /dev/null +++ b/hw-arm-virt-add-missing-compat-for-kvm-no-adjvtime.patch @@ -0,0 +1,25 @@ +From fbcb4ffa8648d0aa5be01c11816423a483f245ae Mon Sep 17 00:00:00 2001 +From: Ying Fang +Date: Tue, 26 May 2020 22:39:23 +0800 +Subject: [PATCH] hw/arm/virt: add missing compat for kvm-no-adjvtime + +Machine compatibility for kvm-no-adjvtime is missed, +let's add it for virt machine 4.0 + +Signed-off-by: Ying Fang + +diff --git a/hw/arm/virt.c b/hw/arm/virt.c +index 4c727939..133d36a4 100644 +--- a/hw/arm/virt.c ++++ b/hw/arm/virt.c +@@ -2492,6 +2492,7 @@ static void virt_machine_4_0_options(MachineClass *mc) + compat_props_add(mc->compat_props, hw_compat_4_0, hw_compat_4_0_len); + vmc->no_ged = true; + mc->auto_enable_numa_with_memhp = false; ++ vmc->kvm_no_adjvtime = true; + } + DEFINE_VIRT_MACHINE(4, 0) + +-- +2.23.0 + diff --git a/qemu.spec b/qemu.spec index 3c8bfef7..1de0ed2e 100644 --- a/qemu.spec +++ b/qemu.spec @@ -170,6 +170,7 @@ Patch0157: bt-use-size_t-type-for-length-parameters-instead-of-.patch Patch0158: log-Add-some-logs-on-VM-runtime-path.patch Patch0159: Revert-vtimer-compat-cross-version-migration-from-v4.patch Patch0160: ARM64-record-vtimer-tick-when-cpu-is-stopped.patch +Patch0161: hw-arm-virt-add-missing-compat-for-kvm-no-adjvtime.patch BuildRequires: flex BuildRequires: bison @@ -518,6 +519,7 @@ getent passwd qemu >/dev/null || \ * Wed May 27 2020 Huawei Technologies Co., Ltd. - Revert: "vtimer: compat cross version migration from v4.0.1" - ARM64: record vtimer tick when cpu is stopped +- hw/arm/virt: add missing compat for kvm-no-adjvtime * Fri May 22 2020 Huawei Technologies Co., Ltd. - ip_reass: Fix use after free -- Gitee From 3f2b0b10b80471ef4abdf6443a3c0bf1357811e7 Mon Sep 17 00:00:00 2001 From: Ying Fang Date: Wed, 27 May 2020 11:45:35 +0800 Subject: [PATCH 5/6] migration: Compat virtual timer adjust for v4.0.1 and v4.1.0 Vtimer adjust is used in openEuler qemu-4.0.1, however kvm_adjvtime is introduced in openEuler qemu-4.1.0. To maintain the compatibility and enable cross version migration, let's enable vtimer adjust only if kvm_adjvtime is not enabled, otherwise there may be conflicts between vtimer adjust and kvm_adjvtime. After this modification: 1: openEuler qemu-4.0.1 use vtimer as the default virtual timer 2: openEuler qemu-4.1.0 use kvm_adjvtime as the defaut virtual timer Migration from openEuler qemu-4.0.1 to openEuler qemu-4.1.0 will be ok, but migration path from upstream qemu-4.0.1 to openEuler qemu-4..0.1 will be broken. Since openEuler qemu-4.1.0, kvm_adjvtime is used as the default virtual timer. So please upgrade to openEuler qemu-4.1.0 and use the virt-4.1 machine. Signed-off-by: Ying Fang --- ...-virtual-timer-adjust-for-v4.0.1-and.patch | 80 +++++++++++++++++++ qemu.spec | 2 + 2 files changed, 82 insertions(+) create mode 100644 migration-Compat-virtual-timer-adjust-for-v4.0.1-and.patch diff --git a/migration-Compat-virtual-timer-adjust-for-v4.0.1-and.patch b/migration-Compat-virtual-timer-adjust-for-v4.0.1-and.patch new file mode 100644 index 00000000..79548949 --- /dev/null +++ b/migration-Compat-virtual-timer-adjust-for-v4.0.1-and.patch @@ -0,0 +1,80 @@ +From 79d722679731233ccb1aa775d896a4bf21e13d44 Mon Sep 17 00:00:00 2001 +From: Ying Fang +Date: Wed, 27 May 2020 10:02:06 +0800 +Subject: [PATCH] migration: Compat virtual timer adjust for v4.0.1 and v4.1.0 + +Vtimer adjust is used in openEuler qemu-4.0.1, however kvm_adjvtime +is introduced in openEuler qemu-4.1.0. To maintain the compatibility +and enable cross version migration, let's enable vtimer adjust only +if kvm_adjvtime is not enabled, otherwise there may be conflicts +between vtimer adjust and kvm_adjvtime. + +After this modification: +1: openEuler qemu-4.0.1 use vtimer as the default virtual timer +2: openEuler qemu-4.1.0 use kvm_adjvtime as the defaut virtual timer + +Migration from openEuler qemu-4.0.1 to openEuler qemu-4.1.0 will +be ok, but migration path from upstream qemu-4.0.1 to openEuler +qemu-4..0.1 will be broken. + +Since openEuler qemu-4.1.0, kvm_adjvtime is used as the default +virtual timer. So please upgrade to openEuler qemu-4.1.0 and +use the virt-4.1 machine. + +Signed-off-by: Ying Fang + +diff --git a/cpus.c b/cpus.c +index b9aa51f8..6a28bdef 100644 +--- a/cpus.c ++++ b/cpus.c +@@ -1067,6 +1067,12 @@ void cpu_synchronize_all_pre_loadvm(void) + } + + #ifdef __aarch64__ ++static bool kvm_adjvtime_enabled(CPUState *cs) ++{ ++ ARMCPU *cpu = ARM_CPU(cs); ++ return cpu->kvm_adjvtime == true; ++} ++ + static void get_vcpu_timer_tick(CPUState *cs) + { + CPUARMState *env = &ARM_CPU(cs)->env; +@@ -1096,7 +1102,13 @@ static int do_vm_stop(RunState state, bool send_stop) + cpu_disable_ticks(); + pause_all_vcpus(); + #ifdef __aarch64__ +- if (first_cpu) { ++ /* vtimer adjust is used in openEuler qemu-4.0.1, however kvm_adjvtime ++ * is introduced in openEuler qemu-4.1.0. To maintain the compatibility ++ * and enable cross version migration, let's enable vtimer adjust only ++ * if kvm_adjvtime is not enabled, otherwise there may be conflicts ++ * between vtimer adjust and kvm_adjvtime. ++ */ ++ if (first_cpu && !kvm_adjvtime_enabled(first_cpu)) { + get_vcpu_timer_tick(first_cpu); + } + #endif +@@ -1946,6 +1958,7 @@ void cpu_resume(CPUState *cpu) + } + + #ifdef __aarch64__ ++ + static void set_vcpu_timer_tick(CPUState *cs) + { + CPUARMState *env = &ARM_CPU(cs)->env; +@@ -1977,7 +1990,10 @@ void resume_all_vcpus(void) + + qemu_clock_enable(QEMU_CLOCK_VIRTUAL, true); + #ifdef __aarch64__ +- if (first_cpu) { ++ /* Enable vtimer adjust only if kvm_adjvtime is not enabled, otherwise ++ * there may be conflicts between vtimer adjust and kvm_adjvtime. ++ */ ++ if (first_cpu && !kvm_adjvtime_enabled(first_cpu)) { + set_vcpu_timer_tick(first_cpu); + } + #endif +-- +2.23.0 + diff --git a/qemu.spec b/qemu.spec index 1de0ed2e..f2ee54a4 100644 --- a/qemu.spec +++ b/qemu.spec @@ -171,6 +171,7 @@ Patch0158: log-Add-some-logs-on-VM-runtime-path.patch Patch0159: Revert-vtimer-compat-cross-version-migration-from-v4.patch Patch0160: ARM64-record-vtimer-tick-when-cpu-is-stopped.patch Patch0161: hw-arm-virt-add-missing-compat-for-kvm-no-adjvtime.patch +Patch0162: migration-Compat-virtual-timer-adjust-for-v4.0.1-and.patch BuildRequires: flex BuildRequires: bison @@ -520,6 +521,7 @@ getent passwd qemu >/dev/null || \ - Revert: "vtimer: compat cross version migration from v4.0.1" - ARM64: record vtimer tick when cpu is stopped - hw/arm/virt: add missing compat for kvm-no-adjvtime +- migration: Compat virtual timer adjust for v4.0.1 and v4.1.0 * Fri May 22 2020 Huawei Technologies Co., Ltd. - ip_reass: Fix use after free -- Gitee From 6c8a3d8f78e22b2dfba14682f61e4ed8124da716 Mon Sep 17 00:00:00 2001 From: Ying Fang Date: Wed, 27 May 2020 11:46:52 +0800 Subject: [PATCH 6/6] spec: Update release version increase release version by one Signed-off-by: Ying Fang --- qemu.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qemu.spec b/qemu.spec index f2ee54a4..b4e3a7ae 100644 --- a/qemu.spec +++ b/qemu.spec @@ -1,6 +1,6 @@ Name: qemu Version: 4.1.0 -Release: 9 +Release: 10 Epoch: 2 Summary: QEMU is a generic and open source machine emulator and virtualizer License: GPLv2 and BSD and MIT and CC-BY -- Gitee