yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-spapr-Fix-handling-of-unplugged-devices-during-CAS-a.patch

c687bc
From 9ebed8090b88282f9b7432258df9182b9d3944ee Mon Sep 17 00:00:00 2001
c687bc
From: Greg Kurz <gkurz@redhat.com>
c687bc
Date: Tue, 19 Jan 2021 15:09:52 -0500
c687bc
Subject: [PATCH 4/9] spapr: Fix handling of unplugged devices during CAS and
c687bc
 migration
c687bc
c687bc
RH-Author: Greg Kurz <gkurz@redhat.com>
c687bc
Message-id: <20210119150954.1017058-5-gkurz@redhat.com>
c687bc
Patchwork-id: 100685
c687bc
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH v2 4/6] spapr: Fix handling of unplugged devices during CAS and migration
c687bc
Bugzilla: 1901837
c687bc
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
c687bc
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
c687bc
RH-Acked-by: David Gibson <dgibson@redhat.com>
c687bc
c687bc
From: Greg Kurz <groug@kaod.org>
c687bc
c687bc
We already detect if a device is being hot plugged before CAS to trigger
c687bc
a CAS reboot and during migration to migrate the state of the associated
c687bc
DRC. But hot unplugging a device is also an asynchronous operation that
c687bc
requires the guest to take action. This means that if the guest is migrated
c687bc
after the hot unplug event was sent but before it could release the device
c687bc
with RTAS, the destination QEMU doesn't know about the pending unplug
c687bc
operation and doesn't actually remove the device when the guest finally
c687bc
releases it.
c687bc
c687bc
Similarly, if the unplug request is fired before CAS, the guest isn't
c687bc
notified of the change, just like with hotplug. It ends up booting with
c687bc
the device still present in the DT and configures it, just like it was
c687bc
never removed. Even weirder, since the event is still queued, it will
c687bc
be eventually processed when some other unrelated event is posted to
c687bc
the guest.
c687bc
c687bc
Enhance spapr_drc_transient() to also return true if an unplug request is
c687bc
pending. This fixes the issue at CAS with a CAS reboot request and
c687bc
causes the DRC state to be migrated. Some extra care is still needed to
c687bc
inform the destination that an unplug request is pending : migrate the
c687bc
unplug_requested field of the DRC in an optional subsection. This might
c687bc
break backwards migration, but this is still better than ending with
c687bc
an inconsistent guest.
c687bc
c687bc
Signed-off-by: Greg Kurz <groug@kaod.org>
c687bc
Message-Id: <158169248798.3465937.1108351365840514270.stgit@bahia.lan>
c687bc
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
c687bc
(cherry picked from commit ab8584349c476f9818dc6403359c85f9ab0ad5eb)
c687bc
Signed-off-by: Greg Kurz <gkurz@redhat.com>
c687bc
Signed-off-by: Jon Maloy <jmaloy.redhat.com>
c687bc
---
c687bc
 hw/ppc/spapr_drc.c | 25 +++++++++++++++++++++++--
c687bc
 1 file changed, 23 insertions(+), 2 deletions(-)
c687bc
c687bc
diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c
c687bc
index 9b498d429e..897bb7aae0 100644
c687bc
--- a/hw/ppc/spapr_drc.c
c687bc
+++ b/hw/ppc/spapr_drc.c
c687bc
@@ -455,6 +455,22 @@ void spapr_drc_reset(SpaprDrc *drc)
c687bc
     }
c687bc
 }
c687bc
 
c687bc
+static bool spapr_drc_unplug_requested_needed(void *opaque)
c687bc
+{
c687bc
+    return spapr_drc_unplug_requested(opaque);
c687bc
+}
c687bc
+
c687bc
+static const VMStateDescription vmstate_spapr_drc_unplug_requested = {
c687bc
+    .name = "spapr_drc/unplug_requested",
c687bc
+    .version_id = 1,
c687bc
+    .minimum_version_id = 1,
c687bc
+    .needed = spapr_drc_unplug_requested_needed,
c687bc
+    .fields  = (VMStateField []) {
c687bc
+        VMSTATE_BOOL(unplug_requested, SpaprDrc),
c687bc
+        VMSTATE_END_OF_LIST()
c687bc
+    }
c687bc
+};
c687bc
+
c687bc
 bool spapr_drc_transient(SpaprDrc *drc)
c687bc
 {
c687bc
     SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
c687bc
@@ -470,9 +486,10 @@ bool spapr_drc_transient(SpaprDrc *drc)
c687bc
     /*
c687bc
      * We need to reset the DRC at CAS or to migrate the DRC state if it's
c687bc
      * not equal to the expected long-term state, which is the same as the
c687bc
-     * coldplugged initial state.
c687bc
+     * coldplugged initial state, or if an unplug request is pending.
c687bc
      */
c687bc
-    return (drc->state != drck->ready_state);
c687bc
+    return drc->state != drck->ready_state ||
c687bc
+        spapr_drc_unplug_requested(drc);
c687bc
 }
c687bc
 
c687bc
 static bool spapr_drc_needed(void *opaque)
c687bc
@@ -488,6 +505,10 @@ static const VMStateDescription vmstate_spapr_drc = {
c687bc
     .fields  = (VMStateField []) {
c687bc
         VMSTATE_UINT32(state, SpaprDrc),
c687bc
         VMSTATE_END_OF_LIST()
c687bc
+    },
c687bc
+    .subsections = (const VMStateDescription * []) {
c687bc
+        &vmstate_spapr_drc_unplug_requested,
c687bc
+        NULL
c687bc
     }
c687bc
 };
c687bc
 
c687bc
-- 
c687bc
2.18.2
c687bc