Blame SOURCES/kvm-spapr-Don-t-hijack-current_machine-boot_order.patch

a83cc2
From b859b919acc83ea12c5c5b2991afac47e9532660 Mon Sep 17 00:00:00 2001
a83cc2
From: Greg Kurz <gkurz@redhat.com>
a83cc2
Date: Thu, 3 Jun 2021 13:29:40 -0400
a83cc2
Subject: [PATCH 06/21] spapr: Don't hijack current_machine->boot_order
a83cc2
MIME-Version: 1.0
a83cc2
Content-Type: text/plain; charset=UTF-8
a83cc2
Content-Transfer-Encoding: 8bit
a83cc2
a83cc2
RH-Author: Miroslav Rezanina <mrezanin@redhat.com>
a83cc2
RH-MergeRequest: 8: Synchronize with RHEL-AV 8.5 release 19 to RHEL 9
a83cc2
RH-Commit: [5/8] 04822ea86e438f013915cd46e09a33627a640a47 (mrezanin/centos-src-qemu-kvm)
a83cc2
RH-Bugzilla: 1957194
a83cc2
RH-Acked-by: Daniel P. Berrangé <berrange@redhat.com>
a83cc2
RH-Acked-by: Greg Kurz <gkurz@redhat.com>
a83cc2
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
a83cc2
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
a83cc2
a83cc2
From: Greg Kurz <groug@kaod.org>
a83cc2
a83cc2
QEMU 6.0 moved all the -boot variables to the machine. Especially, the
a83cc2
removal of the boot_order static changed the handling of '-boot once'
a83cc2
from:
a83cc2
a83cc2
    if (boot_once) {
a83cc2
        qemu_boot_set(boot_once, &error_fatal);
a83cc2
        qemu_register_reset(restore_boot_order, g_strdup(boot_order));
a83cc2
    }
a83cc2
a83cc2
to
a83cc2
a83cc2
    if (current_machine->boot_once) {
a83cc2
        qemu_boot_set(current_machine->boot_once, &error_fatal);
a83cc2
        qemu_register_reset(restore_boot_order,
a83cc2
                            g_strdup(current_machine->boot_order));
a83cc2
    }
a83cc2
a83cc2
This means that we now register as subsequent boot order a copy
a83cc2
of current_machine->boot_once that was just set with the previous
a83cc2
call to qemu_boot_set(), i.e. we never transition away from the
a83cc2
once boot order.
a83cc2
a83cc2
It is certainly fragile^Wwrong for the spapr code to hijack a
a83cc2
field of the base machine type object like that. The boot order
a83cc2
rework simply turned this software boundary violation into an
a83cc2
actual bug.
a83cc2
a83cc2
Have the spapr code to handle that with its own field in
a83cc2
SpaprMachineState. Also kfree() the initial boot device
a83cc2
string when "once" was used.
a83cc2
a83cc2
Fixes: 4b7acd2ac821 ("vl: clean up -boot variables")
a83cc2
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1960119
a83cc2
Cc: pbonzini@redhat.com
a83cc2
Signed-off-by: Greg Kurz <groug@kaod.org>
a83cc2
Message-Id: <20210521160735.1901914-1-groug@kaod.org>
a83cc2
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
a83cc2
(cherry picked from commit 3bf0844f3be77b24cc8f56fc8df9ff199f8324cb)
a83cc2
Signed-off-by: Greg Kurz <gkurz@redhat.com>
a83cc2
a83cc2
Conflicts:
a83cc2
	include/hw/ppc/spapr.h
a83cc2
a83cc2
Trivial context conflict because downstream has experimental support
a83cc2
for secure guests (f23e4b5090ba).
a83cc2
a83cc2
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
a83cc2
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
a83cc2
---
a83cc2
 hw/ppc/spapr.c         | 8 +++++---
a83cc2
 include/hw/ppc/spapr.h | 3 +++
a83cc2
 2 files changed, 8 insertions(+), 3 deletions(-)
a83cc2
a83cc2
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
a83cc2
index 653574ba91..11db32c537 100644
a83cc2
--- a/hw/ppc/spapr.c
a83cc2
+++ b/hw/ppc/spapr.c
a83cc2
@@ -1006,7 +1006,7 @@ static void spapr_dt_chosen(SpaprMachineState *spapr, void *fdt, bool reset)
a83cc2
     _FDT(chosen = fdt_add_subnode(fdt, 0, "chosen"));
a83cc2
 
a83cc2
     if (reset) {
a83cc2
-        const char *boot_device = machine->boot_order;
a83cc2
+        const char *boot_device = spapr->boot_device;
a83cc2
         char *stdout_path = spapr_vio_stdout_path(spapr->vio_bus);
a83cc2
         size_t cb = 0;
a83cc2
         char *bootlist = get_boot_devices_list(&cb;;
a83cc2
@@ -2364,8 +2364,10 @@ static SaveVMHandlers savevm_htab_handlers = {
a83cc2
 static void spapr_boot_set(void *opaque, const char *boot_device,
a83cc2
                            Error **errp)
a83cc2
 {
a83cc2
-    MachineState *machine = MACHINE(opaque);
a83cc2
-    machine->boot_order = g_strdup(boot_device);
a83cc2
+    SpaprMachineState *spapr = SPAPR_MACHINE(opaque);
a83cc2
+
a83cc2
+    g_free(spapr->boot_device);
a83cc2
+    spapr->boot_device = g_strdup(boot_device);
a83cc2
 }
a83cc2
 
a83cc2
 static void spapr_create_lmb_dr_connectors(SpaprMachineState *spapr)
a83cc2
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
a83cc2
index 54cdde8980..6d15066bc3 100644
a83cc2
--- a/include/hw/ppc/spapr.h
a83cc2
+++ b/include/hw/ppc/spapr.h
a83cc2
@@ -227,6 +227,9 @@ struct SpaprMachineState {
a83cc2
     /* Secure Guest support via x-svm-allowed */
a83cc2
     bool svm_allowed;
a83cc2
 
a83cc2
+    /* Set by -boot */
a83cc2
+    char *boot_device;
a83cc2
+
a83cc2
     /*< public >*/
a83cc2
     char *kvm_type;
a83cc2
     char *host_model;
a83cc2
-- 
a83cc2
2.27.0
a83cc2