8fced6
From 1fc9b693c54c93736c6f902f3df8b94440e8cc5d Mon Sep 17 00:00:00 2001
8fced6
From: Greg Kurz <gkurz@redhat.com>
8fced6
Date: Tue, 19 Jan 2021 15:09:53 -0500
8fced6
Subject: [PATCH 5/9] spapr: Allow memory unplug to always succeed
8fced6
8fced6
RH-Author: Greg Kurz <gkurz@redhat.com>
8fced6
Message-id: <20210119150954.1017058-6-gkurz@redhat.com>
8fced6
Patchwork-id: 100686
8fced6
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH v2 5/6] spapr: Allow memory unplug to always succeed
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
It is currently impossible to hot-unplug a memory device between
8fced6
machine reset and CAS.
8fced6
8fced6
(qemu) device_del dimm1
8fced6
Error: Memory hot unplug not supported for this guest
8fced6
8fced6
This limitation was introduced in order to provide an explicit
8fced6
error path for older guests that didn't support hot-plug event
8fced6
sources (and thus memory hot-unplug).
8fced6
8fced6
The linux kernel has been supporting these since 4.11. All recent
8fced6
enough guests are thus capable of handling the removal of a memory
8fced6
device at all time, including during early boot.
8fced6
8fced6
Lift the limitation for the latest machine type. This means that
8fced6
trying to unplug memory from a guest that doesn't support it will
8fced6
likely just do nothing and the memory will only get removed at
8fced6
next reboot. Such older guests can still get the existing behavior
8fced6
by using an older machine type.
8fced6
8fced6
Signed-off-by: Greg Kurz <groug@kaod.org>
8fced6
Message-Id: <160794035064.23292.17560963281911312439.stgit@bahia.lan>
8fced6
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
8fced6
(cherry picked from commit 1e8b5b1aa16b7d73ba8ba52c95d0b52329d5c9d0)
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
Conflicts around the addition of pre_6_0_memory_unplug. Ignore the
8fced6
change that sets pre_6_0_memory_unplug for older machine types.
8fced6
This is ok because pre_6_0_memory_unplug is removed in a subsequent
8fced6
patch anyway.
8fced6
8fced6
Signed-off-by: Jon Maloy <jmaloy.redhat.com>
8fced6
---
8fced6
 hw/ppc/spapr.c         | 3 ++-
8fced6
 hw/ppc/spapr_events.c  | 3 ++-
8fced6
 include/hw/ppc/spapr.h | 1 +
8fced6
 3 files changed, 5 insertions(+), 2 deletions(-)
8fced6
8fced6
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
8fced6
index 992bd08aaa..f8de33e3e5 100644
8fced6
--- a/hw/ppc/spapr.c
8fced6
+++ b/hw/ppc/spapr.c
8fced6
@@ -4001,7 +4001,8 @@ 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 (spapr_ovec_test(sms->ov5_cas, OV5_HP_EVT)) {
8fced6
+        if (!smc->pre_6_0_memory_unplug ||
8fced6
+            spapr_ovec_test(sms->ov5_cas, OV5_HP_EVT)) {
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
diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c
8fced6
index 15b92b63ad..6e284aa4bc 100644
8fced6
--- a/hw/ppc/spapr_events.c
8fced6
+++ b/hw/ppc/spapr_events.c
8fced6
@@ -547,7 +547,8 @@ 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_ovec_test(spapr->ov5_cas, OV5_HP_EVT));
8fced6
+        g_assert(!SPAPR_MACHINE_GET_CLASS(spapr)->pre_6_0_memory_unplug ||
8fced6
+                 spapr_ovec_test(spapr->ov5_cas, OV5_HP_EVT));
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/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
8fced6
index e5e2a99046..ac6961ed16 100644
8fced6
--- a/include/hw/ppc/spapr.h
8fced6
+++ b/include/hw/ppc/spapr.h
8fced6
@@ -124,6 +124,7 @@ 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
-- 
8fced6
2.18.2
8fced6