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

Proposed by Sergio Durigan Junior
Status: Merged
Approved by: git-ubuntu bot
Approved revision: not available
Merged at revision: 7f39799b39d4b0a47c426b1e18f5f0ef1b099132
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

Preview Diff

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

Subscribers

People subscribed via source and target branches