Merge ~sergiodj/ubuntu/+source/qemu:lp2064914-windows-hangs-tsc-jammy into ubuntu/+source/qemu:ubuntu/jammy-devel

Proposed by Sergio Durigan Junior
Status: Approved
Approved by: git-ubuntu bot
Approved revision: not available
Proposed branch: ~sergiodj/ubuntu/+source/qemu:lp2064914-windows-hangs-tsc-jammy
Merge into: ubuntu/+source/qemu:ubuntu/jammy-devel
Diff against target: 104 lines (+82/-0)
3 files modified
debian/changelog (+7/-0)
debian/patches/series (+1/-0)
debian/patches/ubuntu/lp-2064914-properly-reset-tsc-on-reset.patch (+74/-0)
Reviewer Review Type Date Requested Status
git-ubuntu bot Approve
Bryce Harrington (community) Approve
Canonical Server Reporter Pending
Review via email: mp+465879@code.launchpad.net

Description of the change

This MP fixes bug #2064914.

The bug affects Windows, so I am relying on the reporter to verify the fix. Meanwhile, I'm building the package here:

PPA: https://launchpad.net/~sergiodj/+archive/ubuntu/qemu

I'll run dep8 tests and the regular migration test soon.

To post a comment you must log in.
Revision history for this message
Sergio Durigan Junior (sergiodj) wrote :

dep8 tests are going to take a long time to run. I will upload the package anyway and check the test results after the SRU has been accepted.

Revision history for this message
Sergio Durigan Junior (sergiodj) wrote :

Package uploaded.

Revision history for this message
Bryce Harrington (bryce) wrote :

Autopkgtests vs. the PPA look ok:
  - qemu/1:6.2+dfsg-2ubuntu6.20~ppa1
    + ✅ qemu on jammy for amd64 @ 17.05.24 16:21:04 Log️ 🗒️
    + ✅ qemu on jammy for arm64 @ 12.05.24 22:39:07 Log️ 🗒️
    + ✅ qemu on jammy for armhf @ 10.05.24 02:46:05 Log️ 🗒️
    + ✅ qemu on jammy for ppc64el @ 15.05.24 20:22:17 Log️ 🗒️
    + ✅ qemu on jammy for s390x @ 14.05.24 16:41:06 Log️ 🗒️

The patch itself looks ok. Could there be any ABI concerns for tsc moving around in the struct? I'm assuming since qemu is not a library it isn't.

The SRU template needs filling out, but that's known already.

mfo has some review suggestions on the bug report worth considering prior to uploading.

review: Approve
Revision history for this message
git-ubuntu bot (git-ubuntu-bot) wrote :

Approvers: sergiodj, bryce
Uploaders: sergiodj, bryce
MP auto-approved

review: Approve

Unmerged commits

7f39799... by Sergio Durigan Junior

changelog for 1:6.2+dfsg-2ubuntu6.20

a824885... by Sergio Durigan Junior

  * d/p/u/lp-2064914-properly-reset-tsc-on-reset.patch: Properly reset
    TSC on reset, fixing Windows hang after reboot. (LP: #2064914).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index ab23ca0..41ab654 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,10 @@
6+qemu (1:6.2+dfsg-2ubuntu6.20) jammy; urgency=medium
7+
8+ * d/p/u/lp-2064914-properly-reset-tsc-on-reset.patch: Properly reset
9+ TSC on reset, fixing Windows hang after reboot. (LP: #2064914).
10+
11+ -- Sergio Durigan Junior <sergio.durigan@canonical.com> Thu, 09 May 2024 14:30:38 -0400
12+
13 qemu (1:6.2+dfsg-2ubuntu6.19) jammy; urgency=medium
14
15 * d/p/u/lp2012763-maxcpus-too-low.patch: Bump max_cpus to 1024 on
16diff --git a/debian/patches/series b/debian/patches/series
17index ba7a4ad..732e144 100644
18--- a/debian/patches/series
19+++ b/debian/patches/series
20@@ -124,3 +124,4 @@ CVE-2021-3611-24.patch
21 ubuntu/lp-2046439-target-s390x-Split-out-gen_ri2.patch
22 ubuntu/lp-2046439-s390x-Fix-emulation-of-C-G-HRL.patch
23 ubuntu/lp2012763-maxcpus-too-low.patch
24+ubuntu/lp-2064914-properly-reset-tsc-on-reset.patch
25diff --git a/debian/patches/ubuntu/lp-2064914-properly-reset-tsc-on-reset.patch b/debian/patches/ubuntu/lp-2064914-properly-reset-tsc-on-reset.patch
26new file mode 100644
27index 0000000..ebfbb0a
28--- /dev/null
29+++ b/debian/patches/ubuntu/lp-2064914-properly-reset-tsc-on-reset.patch
30@@ -0,0 +1,74 @@
31+From: Paolo Bonzini <pbonzini@redhat.com>
32+Date: Thu, 24 Mar 2022 09:21:41 +0100
33+Subject: target/i386: properly reset TSC on reset
34+
35+Some versions of Windows hang on reboot if their TSC value is greater
36+than 2^54. The calibration of the Hyper-V reference time overflows
37+and fails; as a result the processors' clock sources are out of sync.
38+
39+The issue is that the TSC _should_ be reset to 0 on CPU reset and
40+QEMU tries to do that. However, KVM special cases writing 0 to the
41+TSC and thinks that QEMU is trying to hot-plug a CPU, which is
42+correct the first time through but not later. Thwart this valiant
43+effort and reset the TSC to 1 instead, but only if the CPU has been
44+run once.
45+
46+For this to work, env->tsc has to be moved to the part of CPUArchState
47+that is not zeroed at the beginning of x86_cpu_reset.
48+
49+Reported-by: Vadim Rozenfeld <vrozenfe@redhat.com>
50+Supersedes: <20220324082346.72180-1-pbonzini@redhat.com>
51+Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
52+
53+Origin: upstream, https://gitlab.com/qemu-project/qemu/commit/5286c3662294119dc2dd1e9296757337211451f6
54+Bug-RHEL: https://bugzilla.redhat.com/show_bug.cgi?id=1975840
55+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/2064914
56+---
57+ target/i386/cpu.c | 13 +++++++++++++
58+ target/i386/cpu.h | 2 +-
59+ 2 files changed, 14 insertions(+), 1 deletion(-)
60+
61+diff --git a/target/i386/cpu.c b/target/i386/cpu.c
62+index aa9e636..3f08e90 100644
63+--- a/target/i386/cpu.c
64++++ b/target/i386/cpu.c
65+@@ -5863,6 +5863,19 @@ static void x86_cpu_reset(DeviceState *dev)
66+ env->xstate_bv = 0;
67+
68+ env->pat = 0x0007040600070406ULL;
69++
70++ if (kvm_enabled()) {
71++ /*
72++ * KVM handles TSC = 0 specially and thinks we are hot-plugging
73++ * a new CPU, use 1 instead to force a reset.
74++ */
75++ if (env->tsc != 0) {
76++ env->tsc = 1;
77++ }
78++ } else {
79++ env->tsc = 0;
80++ }
81++
82+ env->msr_ia32_misc_enable = MSR_IA32_MISC_ENABLE_DEFAULT;
83+ if (env->features[FEAT_1_ECX] & CPUID_EXT_MONITOR) {
84+ env->msr_ia32_misc_enable |= MSR_IA32_MISC_ENABLE_MWAIT;
85+diff --git a/target/i386/cpu.h b/target/i386/cpu.h
86+index 04f2b79..c6a6c87 100644
87+--- a/target/i386/cpu.h
88++++ b/target/i386/cpu.h
89+@@ -1510,7 +1510,6 @@ typedef struct CPUX86State {
90+ target_ulong kernelgsbase;
91+ #endif
92+
93+- uint64_t tsc;
94+ uint64_t tsc_adjust;
95+ uint64_t tsc_deadline;
96+ uint64_t tsc_aux;
97+@@ -1660,6 +1659,7 @@ typedef struct CPUX86State {
98+ int64_t tsc_khz;
99+ int64_t user_tsc_khz; /* for sanity check only */
100+ uint64_t apic_bus_freq;
101++ uint64_t tsc;
102+ #if defined(CONFIG_KVM) || defined(CONFIG_HVF)
103+ void *xsave_buf;
104+ uint32_t xsave_buf_len;

Subscribers

People subscribed via source and target branches