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

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