cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-spapr-Improve-handling-of-memory-unplug-with-old-gue.patch

8fced6
From f94b3a4eb9d709f1f6a14ad9ad6ebcc1b67b6923 Mon Sep 17 00:00:00 2001
8fced6
From: Greg Kurz <gkurz@redhat.com>
8fced6
Date: Tue, 19 Jan 2021 15:09:54 -0500
8fced6
Subject: [PATCH 6/9] spapr: Improve handling of memory unplug with old guests
8fced6
8fced6
RH-Author: Greg Kurz <gkurz@redhat.com>
8fced6
Message-id: <20210119150954.1017058-7-gkurz@redhat.com>
8fced6
Patchwork-id: 100684
8fced6
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH v2 6/6] spapr: Improve handling of memory unplug with old guests
8fced6
Bugzilla: 1901837
8fced6
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
8fced6
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
8fced6
RH-Acked-by: David Gibson <dgibson@redhat.com>
8fced6
8fced6
From: Greg Kurz <groug@kaod.org>
8fced6
8fced6
Since commit 1e8b5b1aa16b ("spapr: Allow memory unplug to always succeed")
8fced6
trying to unplug memory from a guest that doesn't support it (eg. rhel6)
8fced6
no longer generates an error like it used to. Instead, it leaves the
8fced6
memory around : only a subsequent reboot or manual use of drmgr within
8fced6
the guest can complete the hot-unplug sequence. A flag was added to
8fced6
SpaprMachineClass so that this new behavior only applies to the default
8fced6
machine type.
8fced6
8fced6
We can do better. CAS processes all pending hot-unplug requests. This
8fced6
means that we don't really care about what the guest supports if
8fced6
the hot-unplug request happens before CAS.
8fced6
8fced6
All guests that we care for, even old ones, set enough bits in OV5
8fced6
that lead to a non-empty bitmap in spapr->ov5_cas. Use that as a
8fced6
heuristic to decide if CAS has already occured or not.
8fced6
8fced6
Always accept unplug requests that happen before CAS since CAS will
8fced6
process them. Restore the previous behavior of rejecting them after
8fced6
CAS when we know that the guest doesn't support memory hot-unplug.
8fced6
8fced6
This behavior is suitable for all machine types : this allows to
8fced6
drop the pre_6_0_memory_unplug flag.
8fced6
8fced6
Fixes: 1e8b5b1aa16b ("spapr: Allow memory unplug to always succeed")
8fced6
Signed-off-by: Greg Kurz <groug@kaod.org>
8fced6
Message-Id: <161012708715.801107.11418801796987916516.stgit@bahia.lan>
8fced6
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
8fced6
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
8fced6
(cherry picked from commit 73598c75df0585e039825e642adede21912dabc7)
8fced6
Signed-off-by: Greg Kurz <gkurz@redhat.com>
8fced6
8fced6
Conflicts:
8fced6
	hw/ppc/spapr.c
8fced6
	include/hw/ppc/spapr.h
8fced6
8fced6
Contextual conflicts around the removal of pre_6_0_memory_unplug,
8fced6
which was only partially backported from upstream 1e8b5b1aa16b, and
8fced6
the addition of spapr_memory_hot_unplug_supported().
8fced6
8fced6
Signed-off-by: Jon Maloy <jmaloy.redhat.com>
8fced6
---
8fced6
 hw/ppc/spapr.c              | 21 +++++++++++++--------
8fced6
 hw/ppc/spapr_events.c       |  3 +--
8fced6
 hw/ppc/spapr_ovec.c         |  7 +++++++
8fced6
 include/hw/ppc/spapr.h      |  2 +-
8fced6
 include/hw/ppc/spapr_ovec.h |  1 +
8fced6
 5 files changed, 23 insertions(+), 11 deletions(-)
8fced6
8fced6
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
8fced6
index f8de33e3e5..00b1ef075e 100644
8fced6
--- a/hw/ppc/spapr.c
8fced6
+++ b/hw/ppc/spapr.c
8fced6
@@ -3993,6 +3993,18 @@ static void spapr_machine_device_unplug(HotplugHandler *hotplug_dev,
8fced6
     }
8fced6
 }
8fced6
 
8fced6
+bool spapr_memory_hot_unplug_supported(SpaprMachineState *spapr)
8fced6
+{
8fced6
+    return spapr_ovec_test(spapr->ov5_cas, OV5_HP_EVT) ||
8fced6
+        /*
8fced6
+         * CAS will process all pending unplug requests.
8fced6
+         *
8fced6
+         * HACK: a guest could theoretically have cleared all bits in OV5,
8fced6
+         * but none of the guests we care for do.
8fced6
+         */
8fced6
+        spapr_ovec_empty(spapr->ov5_cas);
8fced6
+}
8fced6
+
8fced6
 static void spapr_machine_device_unplug_request(HotplugHandler *hotplug_dev,
8fced6
                                                 DeviceState *dev, Error **errp)
8fced6
 {
8fced6
@@ -4001,16 +4013,9 @@ static void spapr_machine_device_unplug_request(HotplugHandler *hotplug_dev,
8fced6
     SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
8fced6
 
8fced6
     if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
8fced6
-        if (!smc->pre_6_0_memory_unplug ||
8fced6
-            spapr_ovec_test(sms->ov5_cas, OV5_HP_EVT)) {
8fced6
+        if (spapr_memory_hot_unplug_supported(sms)) {
8fced6
             spapr_memory_unplug_request(hotplug_dev, dev, errp);
8fced6
         } else {
8fced6
-            /* NOTE: this means there is a window after guest reset, prior to
8fced6
-             * CAS negotiation, where unplug requests will fail due to the
8fced6
-             * capability not being detected yet. This is a bit different than
8fced6
-             * the case with PCI unplug, where the events will be queued and
8fced6
-             * eventually handled by the guest after boot
8fced6
-             */
8fced6
             error_setg(errp, "Memory hot unplug not supported for this guest");
8fced6
         }
8fced6
     } else if (object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_CPU_CORE)) {
8fced6
diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c
8fced6
index 6e284aa4bc..08168acd65 100644
8fced6
--- a/hw/ppc/spapr_events.c
8fced6
+++ b/hw/ppc/spapr_events.c
8fced6
@@ -547,8 +547,7 @@ static void spapr_hotplug_req_event(uint8_t hp_id, uint8_t hp_action,
8fced6
         /* we should not be using count_indexed value unless the guest
8fced6
          * supports dedicated hotplug event source
8fced6
          */
8fced6
-        g_assert(!SPAPR_MACHINE_GET_CLASS(spapr)->pre_6_0_memory_unplug ||
8fced6
-                 spapr_ovec_test(spapr->ov5_cas, OV5_HP_EVT));
8fced6
+        g_assert(spapr_memory_hot_unplug_supported(spapr));
8fced6
         hp->drc_id.count_indexed.count =
8fced6
             cpu_to_be32(drc_id->count_indexed.count);
8fced6
         hp->drc_id.count_indexed.index =
8fced6
diff --git a/hw/ppc/spapr_ovec.c b/hw/ppc/spapr_ovec.c
8fced6
index 811fadf143..f858afc7d5 100644
8fced6
--- a/hw/ppc/spapr_ovec.c
8fced6
+++ b/hw/ppc/spapr_ovec.c
8fced6
@@ -135,6 +135,13 @@ bool spapr_ovec_test(SpaprOptionVector *ov, long bitnr)
8fced6
     return test_bit(bitnr, ov->bitmap) ? true : false;
8fced6
 }
8fced6
 
8fced6
+bool spapr_ovec_empty(SpaprOptionVector *ov)
8fced6
+{
8fced6
+    g_assert(ov);
8fced6
+
8fced6
+    return bitmap_empty(ov->bitmap, OV_MAXBITS);
8fced6
+}
8fced6
+
8fced6
 static void guest_byte_to_bitmap(uint8_t entry, unsigned long *bitmap,
8fced6
                                  long bitmap_offset)
8fced6
 {
8fced6
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
8fced6
index ac6961ed16..7aaf5d9996 100644
8fced6
--- a/include/hw/ppc/spapr.h
8fced6
+++ b/include/hw/ppc/spapr.h
8fced6
@@ -124,7 +124,6 @@ struct SpaprMachineClass {
8fced6
     bool pre_4_1_migration; /* don't migrate hpt-max-page-size */
8fced6
     bool linux_pci_probe;
8fced6
     bool smp_threads_vsmt; /* set VSMT to smp_threads by default */
8fced6
-    bool pre_6_0_memory_unplug;
8fced6
 
8fced6
     bool has_power9_support;
8fced6
     void (*phb_placement)(SpaprMachineState *spapr, uint32_t index,
8fced6
@@ -894,4 +893,5 @@ void spapr_check_pagesize(SpaprMachineState *spapr, hwaddr pagesize,
8fced6
 #define SPAPR_OV5_XIVE_BOTH     0x80 /* Only to advertise on the platform */
8fced6
 
8fced6
 void spapr_set_all_lpcrs(target_ulong value, target_ulong mask);
8fced6
+bool spapr_memory_hot_unplug_supported(SpaprMachineState *spapr);
8fced6
 #endif /* HW_SPAPR_H */
8fced6
diff --git a/include/hw/ppc/spapr_ovec.h b/include/hw/ppc/spapr_ovec.h
8fced6
index 7891e9caac..98c73bf601 100644
8fced6
--- a/include/hw/ppc/spapr_ovec.h
8fced6
+++ b/include/hw/ppc/spapr_ovec.h
8fced6
@@ -73,6 +73,7 @@ void spapr_ovec_cleanup(SpaprOptionVector *ov);
8fced6
 void spapr_ovec_set(SpaprOptionVector *ov, long bitnr);
8fced6
 void spapr_ovec_clear(SpaprOptionVector *ov, long bitnr);
8fced6
 bool spapr_ovec_test(SpaprOptionVector *ov, long bitnr);
8fced6
+bool spapr_ovec_empty(SpaprOptionVector *ov);
8fced6
 SpaprOptionVector *spapr_ovec_parse_vector(target_ulong table_addr, int vector);
8fced6
 int spapr_ovec_populate_dt(void *fdt, int fdt_offset,
8fced6
                            SpaprOptionVector *ov, const char *name);
8fced6
-- 
8fced6
2.18.2
8fced6