Blame SOURCES/0014-lib-Disable-5-level-page-tables-when-using-cpu-max.patch

b69b2c
From 06cf41cdddfde07871a7f7033ba8c5ccc184a1fb Mon Sep 17 00:00:00 2001
b69b2c
From: "Richard W.M. Jones" <rjones@redhat.com>
b69b2c
Date: Thu, 12 May 2022 08:36:37 +0100
b69b2c
Subject: [PATCH] lib: Disable 5-level page tables when using -cpu max
b69b2c
b69b2c
In https://bugzilla.redhat.com/show_bug.cgi?id=2082806 we've been
b69b2c
tracking an insidious qemu bug which intermittently prevents the
b69b2c
libguestfs appliance from starting.  The symptoms are that SeaBIOS
b69b2c
starts and displays its messages, but the kernel isn't reached.  We
b69b2c
found that the kernel does in fact start, but when it tries to set up
b69b2c
page tables and jump to protected mode it gets a triple fault which
b69b2c
causes the emulated CPU in qemu to reset (qemu exits).
b69b2c
b69b2c
This seems to only affect TCG (not KVM).
b69b2c
b69b2c
Yesterday I found that this is caused by using -cpu max which enables
b69b2c
the "la57" feature (5-level page tables[0]), and that we can make the
b69b2c
problem go away using -cpu max,la57=off.  Note that I still don't
b69b2c
fully understand the qemu bug, so this is only a workaround.
b69b2c
b69b2c
I chose to disable 5-level page tables for both TCG and KVM, partly to
b69b2c
make the patch simpler, and partly because I guess it's not a feature
b69b2c
(ie. 57 bit linear addresses) that is useful for the libguestfs
b69b2c
appliance case, where we have limited physical memory and no need to
b69b2c
run any programs with huge address spaces.
b69b2c
b69b2c
I tested this by running both the direct & libvirt paths overnight.  I
b69b2c
expect that this patch will fail with old qemu/libvirt which doesn't
b69b2c
understand the "la57" feature, but this is only intended as a
b69b2c
temporary workaround.
b69b2c
b69b2c
[0] Article about 5-level page tables as background:
b69b2c
https://lwn.net/Articles/717293/
b69b2c
b69b2c
Thanks: Laszlo Ersek
b69b2c
Fixes: https://answers.launchpad.net/ubuntu/+source/libguestfs/+question/701625
b69b2c
Acked-by: Laszlo Ersek <lersek@redhat.com>
b69b2c
(cherry picked from commit 59d7e6e017b7de79bcb60e1180e15303f1e7dae8)
b69b2c
---
b69b2c
 lib/launch-direct.c  | 15 +++++++++++++--
b69b2c
 lib/launch-libvirt.c |  7 +++++++
b69b2c
 2 files changed, 20 insertions(+), 2 deletions(-)
b69b2c
b69b2c
diff --git a/lib/launch-direct.c b/lib/launch-direct.c
b69b2c
index 4f038f4f0..e7c22fbef 100644
b69b2c
--- a/lib/launch-direct.c
b69b2c
+++ b/lib/launch-direct.c
b69b2c
@@ -554,8 +554,19 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
b69b2c
   } end_list ();
b69b2c
 
b69b2c
   cpu_model = guestfs_int_get_cpu_model (has_kvm && !force_tcg);
b69b2c
-  if (cpu_model)
b69b2c
-    arg ("-cpu", cpu_model);
b69b2c
+  if (cpu_model) {
b69b2c
+#if defined(__x86_64__)
b69b2c
+    /* Temporary workaround for RHBZ#2082806 */
b69b2c
+    if (STREQ (cpu_model, "max")) {
b69b2c
+      start_list ("-cpu") {
b69b2c
+        append_list (cpu_model);
b69b2c
+        append_list ("la57=off");
b69b2c
+      } end_list ();
b69b2c
+    }
b69b2c
+    else
b69b2c
+#endif
b69b2c
+      arg ("-cpu", cpu_model);
b69b2c
+  }
b69b2c
 
b69b2c
   if (g->smp > 1)
b69b2c
     arg_format ("-smp", "%d", g->smp);
b69b2c
diff --git a/lib/launch-libvirt.c b/lib/launch-libvirt.c
b69b2c
index cc714c02e..9e32c94cf 100644
b69b2c
--- a/lib/launch-libvirt.c
b69b2c
+++ b/lib/launch-libvirt.c
b69b2c
@@ -1185,6 +1185,13 @@ construct_libvirt_xml_cpu (guestfs_h *g,
b69b2c
       else if (STREQ (cpu_model, "max")) {
b69b2c
         /* https://bugzilla.redhat.com/show_bug.cgi?id=1935572#c11 */
b69b2c
         attribute ("mode", "maximum");
b69b2c
+#if defined(__x86_64__)
b69b2c
+        /* Temporary workaround for RHBZ#2082806 */
b69b2c
+        start_element ("feature") {
b69b2c
+          attribute ("policy", "disable");
b69b2c
+          attribute ("name", "la57");
b69b2c
+        } end_element ();
b69b2c
+#endif
b69b2c
       }
b69b2c
       else
b69b2c
         single_element ("model", cpu_model);
b69b2c
-- 
b69b2c
2.31.1
b69b2c