Skip to contentSkip to conversation

send QAPI_EVENT_MEM_UNPLUG_ERROR for ppc64 unplugs

PATCH Applied Daniel Henrique Barboza 3 participants 16 messages Feb 26, 2021 – Mar 2, 2021

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover send QAPI_EVENT_MEM_UNPLUG_ERROR for ppc64 unplugs

Hi,

This series is a follow-up of the existing change in ppc-for-6.0 branch in David's tree, where the pSeries machine is now detecting one case in which the memory hotunplug is rejected by the guest kernel.

Initially I would like to also add a QAPI event to report a CPU unplug error, but we don't have this event available yet. Next time.

Daniel Henrique Barboza (5):
spapr.c: assert first DRC LMB earlier in spapr_memory_unplug_request() spapr.c: check unplug_request flag in spapr_memory_unplug_request() spapr.c: add 'unplug already in progress' message for PHB unplug spapr_pci.c: add 'unplug already in progress' message for PCI unplug spapr.c: send QAPI event when memory hotunplug fails

 hw/ppc/spapr.c         | 37 +++++++++++++++++++++++--------------
 hw/ppc/spapr_drc.c     |  5 ++---
 hw/ppc/spapr_pci.c     |  4 ++++
 include/hw/ppc/spapr.h |  3 +--
 4 files changed, 30 insertions(+), 19 deletions(-)
Signature · 1 line
2.29.2
#1 lore raw

PATCH 1/5 spapr.c: assert first DRC LMB earlier in spapr_memory_unplug_request()

We are asserting the existence of the first DRC LMB after sending unplug requests to all LMBs of the DIMM, where every DRC is being asserted inside the loop. This means that the first DRC is being asserted twice.

We will use the first DRC to simplify the code a bit in the next patch, so instead of removing the duplicated assert, let's do it earlier.

---
 hw/ppc/spapr.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
hw/ppc/spapr.c +7 -5
index 6eaddb12cb..74e046b522 100644
@@ -3664,7 +3664,7 @@ static void spapr_memory_unplug_request(HotplugHandler *hotplug_dev,
     uint32_t nr_lmbs;
     uint64_t size, addr_start, addr;
     int i;
-    SpaprDrc *drc;
+    SpaprDrc *drc, *drc_start;
 
     if (object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM)) {
         error_setg(errp, "nvdimm device hot unplug is not supported yet.");
@@ -3677,6 +3677,10 @@ static void spapr_memory_unplug_request(HotplugHandler *hotplug_dev,
     addr_start = object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP,
                                           &error_abort);
 
+    drc_start = spapr_drc_by_id(TYPE_SPAPR_DRC_LMB,
+                                addr_start / SPAPR_MEMORY_BLOCK_SIZE);
+    g_assert(drc_start);
+
     /*
      * An existing pending dimm state for this DIMM means that there is an
      * unplug operation in progress, waiting for the spapr_lmb_release
@@ -3701,11 +3705,9 @@ static void spapr_memory_unplug_request(HotplugHandler *hotplug_dev,
         addr += SPAPR_MEMORY_BLOCK_SIZE;
     }
 
-    drc = spapr_drc_by_id(TYPE_SPAPR_DRC_LMB,
-                          addr_start / SPAPR_MEMORY_BLOCK_SIZE);
-    g_assert(drc);
     spapr_hotplug_req_remove_by_count_indexed(SPAPR_DR_CONNECTOR_TYPE_LMB,
-                                              nr_lmbs, spapr_drc_index(drc));
+                                              nr_lmbs,
+                                              spapr_drc_index(drc_start));
 }
 
 /* Callback to be called during DRC release. */
Signature · 1 line
2.29.2
#3 lore raw

PATCH 2/5 spapr.c: check unplug_request flag in spapr_memory_unplug_request()

In reply to Daniel Henrique Barboza

Now that we're asserting the first DRC LMB earlier, use it to query if the DRC is already pending unplug and, in this case, issue the same error we already do.

The previous check was introduced in commit 2a129767ebb1 and it works, but it's easier to check the unplug_requested flag instead of looking for the existence of the sPAPRDIMMState. It's also compliant with what is already done in other unplug_request functions for other devices.

---
 hw/ppc/spapr.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
hw/ppc/spapr.c +1 -7
index 74e046b522..149dc2113f 100644
@@ -3681,13 +3681,7 @@ static void spapr_memory_unplug_request(HotplugHandler *hotplug_dev,
                                 addr_start / SPAPR_MEMORY_BLOCK_SIZE);
     g_assert(drc_start);
 
-    /*
-     * An existing pending dimm state for this DIMM means that there is an
-     * unplug operation in progress, waiting for the spapr_lmb_release
-     * callback to complete the job (BQL can't cover that far). In this case,
-     * bail out to avoid detaching DRCs that were already released.
-     */
-    if (spapr_pending_dimm_unplugs_find(spapr, dimm)) {
+    if (spapr_drc_unplug_requested(drc_start)) {
         error_setg(errp, "Memory unplug already in progress for device %s",
                    dev->id);
         return;
Signature · 1 line
2.29.2
#10 lore raw

PATCH 4/5 spapr_pci.c: add 'unplug already in progress' message for PCI unplug

In reply to Daniel Henrique Barboza

Hotunplug for all other devices are warning the user when the hotunplug is already in progress. Do the same for PCI devices in spapr_pci_unplug_request().

---
 hw/ppc/spapr_pci.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/ppc/spapr_pci.c +4 -0
index b00e9609ae..feba18cb12 100644
@@ -1743,6 +1743,10 @@ static void spapr_pci_unplug_request(HotplugHandler *plug_handler,
                 }
             }
         }
+    } else {
+        error_setg(errp,
+                   "PCI device unplug already in progress for device %s",
+                   drc->dev->id);
     }
 }
 
Signature · 1 line
2.29.2
#7 lore raw

PATCH 3/5 spapr.c: add 'unplug already in progress' message for PHB unplug

In reply to Daniel Henrique Barboza

Both CPU hotunplug and PC_DIMM unplug reports an user warning, mentioning that the hotunplug is in progress, if consecutive 'device_del' are issued in quick succession.

Do the same for PHBs in spapr_phb_unplug_request().

---
 hw/ppc/spapr.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/ppc/spapr.c +4 -0
index 149dc2113f..6ef72ee7bd 100644
@@ -4030,6 +4030,10 @@ static void spapr_phb_unplug_request(HotplugHandler *hotplug_dev,
     if (!spapr_drc_unplug_requested(drc)) {
         spapr_drc_unplug_request(drc);
         spapr_hotplug_req_remove_by_index(drc);
+    } else {
+        error_setg(errp,
+                   "PCI Host Bridge unplug already in progress for device %s",
+                   dev->id);
     }
 }
 
Signature · 1 line
2.29.2
#13 lore raw

PATCH 5/5 spapr.c: send QAPI event when memory hotunplug fails

In reply to Daniel Henrique Barboza

Recent changes allowed the pSeries machine to rollback the hotunplug process for the DIMM when the guest kernel signals, via a reconfiguration of the DR connector, that it's not going to release the LMBs.

Let's also warn QAPI listerners about it. One place to do it would be right after the unplug state is cleaned up, spapr_clear_pending_dimm_unplug_state(). This would mean that the function is now doing more than cleaning up the pending dimm state though.

This patch does the following changes in spapr.c:

- send a QAPI event to inform that we experienced a failure in the hotunplug of the DIMM;

- rename spapr_clear_pending_dimm_unplug_state() to spapr_memory_unplug_rollback(). This is a better fit for what the function is now doing, and it makes callers care more about what the function goal is and less about spapr.c internals such as clearing the pending dimm unplug state.

---
 hw/ppc/spapr.c         | 13 +++++++++++--
 hw/ppc/spapr_drc.c     |  5 ++---
 include/hw/ppc/spapr.h |  3 +--
 3 files changed, 14 insertions(+), 7 deletions(-)
hw/ppc/spapr.c +11 -2
index 6ef72ee7bd..cbe5cafb14 100644
@@ -28,6 +28,7 @@
 #include "qemu-common.h"
 #include "qemu/datadir.h"
 #include "qapi/error.h"
+#include "qapi/qapi-events-machine.h"
 #include "qapi/visitor.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/hostmem.h"
@@ -3575,14 +3576,14 @@ static SpaprDimmState *spapr_recover_pending_dimm_state(SpaprMachineState *ms,
     return spapr_pending_dimm_unplugs_add(ms, avail_lmbs, dimm);
 }
 
-void spapr_clear_pending_dimm_unplug_state(SpaprMachineState *spapr,
-                                           DeviceState *dev)
+void spapr_memory_unplug_rollback(SpaprMachineState *spapr, DeviceState *dev)
 {
     SpaprDimmState *ds;
     PCDIMMDevice *dimm;
     SpaprDrc *drc;
     uint32_t nr_lmbs;
     uint64_t size, addr_start, addr;
+    g_autofree char *qapi_error = NULL;
     int i;
 
     if (!dev) {
@@ -3616,6 +3617,14 @@ void spapr_clear_pending_dimm_unplug_state(SpaprMachineState *spapr,
         drc->unplug_requested = false;
         addr += SPAPR_MEMORY_BLOCK_SIZE;
     }
+
+    /*
+     * Tell QAPI that something happened and the memory
+     * hotunplug wasn't successful.
+     */
+    qapi_error = g_strdup_printf("Memory hotunplug failed for device %s",
+                                 dev->id);
+    qapi_event_send_mem_unplug_error(dev->id, qapi_error);
 }
 
 /* Callback to be called during DRC release. */
hw/ppc/spapr_drc.c +2 -3
index 8c4997d795..8faaf9f1dd 100644
@@ -1232,12 +1232,11 @@ static void rtas_ibm_configure_connector(PowerPCCPU *cpu,
 
     /*
      * This indicates that the kernel is reconfiguring a LMB due to
-     * a failed hotunplug. Clear the pending unplug state for the whole
-     * DIMM.
+     * a failed hotunplug. Rollback the DIMM unplug process.
      */
     if (spapr_drc_type(drc) == SPAPR_DR_CONNECTOR_TYPE_LMB &&
         drc->unplug_requested) {
-        spapr_clear_pending_dimm_unplug_state(spapr, drc->dev);
+        spapr_memory_unplug_rollback(spapr, drc->dev);
     }
 
     if (!drc->fdt) {
include/hw/ppc/spapr.h +1 -2
index d6edeaaaff..47cebaf3ac 100644
@@ -847,8 +847,7 @@ int spapr_hpt_shift_for_ramsize(uint64_t ramsize);
 int spapr_reallocate_hpt(SpaprMachineState *spapr, int shift, Error **errp);
 void spapr_clear_pending_events(SpaprMachineState *spapr);
 void spapr_clear_pending_hotplug_events(SpaprMachineState *spapr);
-void spapr_clear_pending_dimm_unplug_state(SpaprMachineState *spapr,
-                                           DeviceState *dev);
+void spapr_memory_unplug_rollback(SpaprMachineState *spapr, DeviceState *dev);
 int spapr_max_server_number(SpaprMachineState *spapr);
 void spapr_store_hpte(PowerPCCPU *cpu, hwaddr ptex,
                       uint64_t pte0, uint64_t pte1);
Signature · 1 line
2.29.2
Reviewed-by on v1 2/5
#4 lore raw

Re: [PATCH 2/5] spapr.c: check unplug_request flag in spapr_memory_unplug_request()

In reply to Daniel Henrique Barboza
Quoted 11 lines · On Fri, 26 Feb 2021 13:32:58 -0300 Daniel Henrique Barboza…

Now that we're asserting the first DRC LMB earlier, use it to query if the DRC is already pending unplug and, in this case, issue the same error we already do.

The previous check was introduced in commit 2a129767ebb1 and it works, but it's easier to check the unplug_requested flag instead of looking for the existence of the sPAPRDIMMState. It's also compliant with what is already done in other unplug_request functions for other devices.

---

Quoted 22 lines
 hw/ppc/spapr.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
hw/ppc/spapr.c +1 -7
index 74e046b522..149dc2113f 100644
@@ -3681,13 +3681,7 @@ static void spapr_memory_unplug_request(HotplugHandler *hotplug_dev,
                                 addr_start / SPAPR_MEMORY_BLOCK_SIZE);
     g_assert(drc_start);
 
-    /*
-     * An existing pending dimm state for this DIMM means that there is an
-     * unplug operation in progress, waiting for the spapr_lmb_release
-     * callback to complete the job (BQL can't cover that far). In this case,
-     * bail out to avoid detaching DRCs that were already released.
-     */
-    if (spapr_pending_dimm_unplugs_find(spapr, dimm)) {
+    if (spapr_drc_unplug_requested(drc_start)) {
         error_setg(errp, "Memory unplug already in progress for device %s",
                    dev->id);
         return;
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] spapr.c: assert first DRC LMB earlier in spapr_memory_unplug_request()

In reply to Daniel Henrique Barboza
Quoted 9 lines · On Fri, 26 Feb 2021 13:32:57 -0300 Daniel Henrique Barboza…

We are asserting the existence of the first DRC LMB after sending unplug requests to all LMBs of the DIMM, where every DRC is being asserted inside the loop. This means that the first DRC is being asserted twice.

We will use the first DRC to simplify the code a bit in the next patch, so instead of removing the duplicated assert, let's do it earlier.

---

Quoted 41 lines
 hw/ppc/spapr.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
hw/ppc/spapr.c +7 -5
index 6eaddb12cb..74e046b522 100644
@@ -3664,7 +3664,7 @@ static void spapr_memory_unplug_request(HotplugHandler *hotplug_dev,
     uint32_t nr_lmbs;
     uint64_t size, addr_start, addr;
     int i;
-    SpaprDrc *drc;
+    SpaprDrc *drc, *drc_start;
 
     if (object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM)) {
         error_setg(errp, "nvdimm device hot unplug is not supported yet.");
@@ -3677,6 +3677,10 @@ static void spapr_memory_unplug_request(HotplugHandler *hotplug_dev,
     addr_start = object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP,
                                           &error_abort);
 
+    drc_start = spapr_drc_by_id(TYPE_SPAPR_DRC_LMB,
+                                addr_start / SPAPR_MEMORY_BLOCK_SIZE);
+    g_assert(drc_start);
+
     /*
      * An existing pending dimm state for this DIMM means that there is an
      * unplug operation in progress, waiting for the spapr_lmb_release
@@ -3701,11 +3705,9 @@ static void spapr_memory_unplug_request(HotplugHandler *hotplug_dev,
         addr += SPAPR_MEMORY_BLOCK_SIZE;
     }
 
-    drc = spapr_drc_by_id(TYPE_SPAPR_DRC_LMB,
-                          addr_start / SPAPR_MEMORY_BLOCK_SIZE);
-    g_assert(drc);
     spapr_hotplug_req_remove_by_count_indexed(SPAPR_DR_CONNECTOR_TYPE_LMB,
-                                              nr_lmbs, spapr_drc_index(drc));
+                                              nr_lmbs,
+                                              spapr_drc_index(drc_start));
 }
 
 /* Callback to be called during DRC release. */
Reviewed-by on v1 3/5
#8 lore raw

Re: [PATCH 3/5] spapr.c: add 'unplug already in progress' message for PHB unplug

In reply to Daniel Henrique Barboza
Quoted 8 lines · On Fri, 26 Feb 2021 13:32:59 -0300 Daniel Henrique Barboza…

Both CPU hotunplug and PC_DIMM unplug reports an user warning, mentioning that the hotunplug is in progress, if consecutive 'device_del' are issued in quick succession.

Do the same for PHBs in spapr_phb_unplug_request().

---

Quoted 18 lines
 hw/ppc/spapr.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/ppc/spapr.c +4 -0
index 149dc2113f..6ef72ee7bd 100644
@@ -4030,6 +4030,10 @@ static void spapr_phb_unplug_request(HotplugHandler *hotplug_dev,
     if (!spapr_drc_unplug_requested(drc)) {
         spapr_drc_unplug_request(drc);
         spapr_hotplug_req_remove_by_index(drc);
+    } else {
+        error_setg(errp,
+                   "PCI Host Bridge unplug already in progress for device %s",
+                   dev->id);
     }
 }
 
Reviewed-by on v1 4/5
#11 lore raw

Re: [PATCH 4/5] spapr_pci.c: add 'unplug already in progress' message for PCI unplug

In reply to Daniel Henrique Barboza
Quoted 6 lines · On Fri, 26 Feb 2021 13:33:00 -0300 Daniel Henrique Barboza…

Hotunplug for all other devices are warning the user when the hotunplug is already in progress. Do the same for PCI devices in spapr_pci_unplug_request().

---

Quoted 18 lines
 hw/ppc/spapr_pci.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/ppc/spapr_pci.c +4 -0
index b00e9609ae..feba18cb12 100644
@@ -1743,6 +1743,10 @@ static void spapr_pci_unplug_request(HotplugHandler *plug_handler,
                 }
             }
         }
+    } else {
+        error_setg(errp,
+                   "PCI device unplug already in progress for device %s",
+                   drc->dev->id);
     }
 }
 
Reviewed-by on v1 5/5
#14 lore raw

Re: [PATCH 5/5] spapr.c: send QAPI event when memory hotunplug fails

In reply to Daniel Henrique Barboza
Quoted 16 lines · On Fri, 26 Feb 2021 13:33:01 -0300 Daniel Henrique Barboza…

Recent changes allowed the pSeries machine to rollback the hotunplug process for the DIMM when the guest kernel signals, via a reconfiguration of the DR connector, that it's not going to release the LMBs.

Let's also warn QAPI listerners about it. One place to do it would be right after the unplug state is cleaned up, spapr_clear_pending_dimm_unplug_state(). This would mean that the function is now doing more than cleaning up the pending dimm state though.

This patch does the following changes in spapr.c:

- send a QAPI event to inform that we experienced a failure in the hotunplug of the DIMM;

Quoted 8 lines

- rename spapr_clear_pending_dimm_unplug_state() to spapr_memory_unplug_rollback(). This is a better fit for what the function is now doing, and it makes callers care more about what the function goal is and less about spapr.c internals such as clearing the pending dimm unplug state.

---

LGTM

Quoted 82 lines
 hw/ppc/spapr.c         | 13 +++++++++++--
 hw/ppc/spapr_drc.c     |  5 ++---
 include/hw/ppc/spapr.h |  3 +--
 3 files changed, 14 insertions(+), 7 deletions(-)
hw/ppc/spapr.c +11 -2
index 6ef72ee7bd..cbe5cafb14 100644
@@ -28,6 +28,7 @@
 #include "qemu-common.h"
 #include "qemu/datadir.h"
 #include "qapi/error.h"
+#include "qapi/qapi-events-machine.h"
 #include "qapi/visitor.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/hostmem.h"
@@ -3575,14 +3576,14 @@ static SpaprDimmState *spapr_recover_pending_dimm_state(SpaprMachineState *ms,
     return spapr_pending_dimm_unplugs_add(ms, avail_lmbs, dimm);
 }
 
-void spapr_clear_pending_dimm_unplug_state(SpaprMachineState *spapr,
-                                           DeviceState *dev)
+void spapr_memory_unplug_rollback(SpaprMachineState *spapr, DeviceState *dev)
 {
     SpaprDimmState *ds;
     PCDIMMDevice *dimm;
     SpaprDrc *drc;
     uint32_t nr_lmbs;
     uint64_t size, addr_start, addr;
+    g_autofree char *qapi_error = NULL;
     int i;
 
     if (!dev) {
@@ -3616,6 +3617,14 @@ void spapr_clear_pending_dimm_unplug_state(SpaprMachineState *spapr,
         drc->unplug_requested = false;
         addr += SPAPR_MEMORY_BLOCK_SIZE;
     }
+
+    /*
+     * Tell QAPI that something happened and the memory
+     * hotunplug wasn't successful.
+     */
+    qapi_error = g_strdup_printf("Memory hotunplug failed for device %s",
+                                 dev->id);
+    qapi_event_send_mem_unplug_error(dev->id, qapi_error);
 }
 
 /* Callback to be called during DRC release. */
hw/ppc/spapr_drc.c +2 -3
index 8c4997d795..8faaf9f1dd 100644
@@ -1232,12 +1232,11 @@ static void rtas_ibm_configure_connector(PowerPCCPU *cpu,
 
     /*
      * This indicates that the kernel is reconfiguring a LMB due to
-     * a failed hotunplug. Clear the pending unplug state for the whole
-     * DIMM.
+     * a failed hotunplug. Rollback the DIMM unplug process.
      */
     if (spapr_drc_type(drc) == SPAPR_DR_CONNECTOR_TYPE_LMB &&
         drc->unplug_requested) {
-        spapr_clear_pending_dimm_unplug_state(spapr, drc->dev);
+        spapr_memory_unplug_rollback(spapr, drc->dev);
     }
 
     if (!drc->fdt) {
include/hw/ppc/spapr.h +1 -2
index d6edeaaaff..47cebaf3ac 100644
@@ -847,8 +847,7 @@ int spapr_hpt_shift_for_ramsize(uint64_t ramsize);
 int spapr_reallocate_hpt(SpaprMachineState *spapr, int shift, Error **errp);
 void spapr_clear_pending_events(SpaprMachineState *spapr);
 void spapr_clear_pending_hotplug_events(SpaprMachineState *spapr);
-void spapr_clear_pending_dimm_unplug_state(SpaprMachineState *spapr,
-                                           DeviceState *dev);
+void spapr_memory_unplug_rollback(SpaprMachineState *spapr, DeviceState *dev);
 int spapr_max_server_number(SpaprMachineState *spapr);
 void spapr_store_hpte(PowerPCCPU *cpu, hwaddr ptex,
                       uint64_t pte0, uint64_t pte1);
Applied
#12 lore raw

Re: [PATCH 4/5] spapr_pci.c: add 'unplug already in progress' message for PCI unplug

In reply to Daniel Henrique Barboza
Quoted 5 lines · Daniel Henrique Barboza

Hotunplug for all other devices are warning the user when the hotunplug is already in progress. Do the same for PCI devices in spapr_pci_unplug_request().

Applied to ppc-for-6.0.

Quoted 19 lines
---
 hw/ppc/spapr_pci.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/ppc/spapr_pci.c +4 -0
index b00e9609ae..feba18cb12 100644
@@ -1743,6 +1743,10 @@ static void spapr_pci_unplug_request(HotplugHandler *plug_handler,
                 }
             }
         }
+    } else {
+        error_setg(errp,
+                   "PCI device unplug already in progress for device %s",
+                   drc->dev->id);
     }
 }
 
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#15 lore raw

Re: [PATCH 5/5] spapr.c: send QAPI event when memory hotunplug fails

In reply to Daniel Henrique Barboza
Quoted 59 lines · Daniel Henrique Barboza

Recent changes allowed the pSeries machine to rollback the hotunplug process for the DIMM when the guest kernel signals, via a reconfiguration of the DR connector, that it's not going to release the LMBs.

Let's also warn QAPI listerners about it. One place to do it would be right after the unplug state is cleaned up, spapr_clear_pending_dimm_unplug_state(). This would mean that the function is now doing more than cleaning up the pending dimm state though.

This patch does the following changes in spapr.c:

- send a QAPI event to inform that we experienced a failure in the hotunplug of the DIMM;

- rename spapr_clear_pending_dimm_unplug_state() to spapr_memory_unplug_rollback(). This is a better fit for what the function is now doing, and it makes callers care more about what the function goal is and less about spapr.c internals such as clearing the pending dimm unplug state.

---
 hw/ppc/spapr.c         | 13 +++++++++++--
 hw/ppc/spapr_drc.c     |  5 ++---
 include/hw/ppc/spapr.h |  3 +--
 3 files changed, 14 insertions(+), 7 deletions(-)
hw/ppc/spapr.c +3 -2
index 6ef72ee7bd..cbe5cafb14 100644
@@ -28,6 +28,7 @@
 #include "qemu-common.h"
 #include "qemu/datadir.h"
 #include "qapi/error.h"
+#include "qapi/qapi-events-machine.h"
 #include "qapi/visitor.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/hostmem.h"
@@ -3575,14 +3576,14 @@ static SpaprDimmState *spapr_recover_pending_dimm_state(SpaprMachineState *ms,
     return spapr_pending_dimm_unplugs_add(ms, avail_lmbs, dimm);
 }
 
-void spapr_clear_pending_dimm_unplug_state(SpaprMachineState *spapr,
-                                           DeviceState *dev)
+void spapr_memory_unplug_rollback(SpaprMachineState *spapr, DeviceState *dev)
 {
     SpaprDimmState *ds;
     PCDIMMDevice *dimm;
     SpaprDrc *drc;
     uint32_t nr_lmbs;
     uint64_t size, addr_start, addr;
+    g_autofree char *qapi_error = NULL;
     int i;
 
     if (!dev) {

hw/ppc/spapr.c void spapr_clear_pending_dimm_unplug_state(SpaprMachineState *spapr, · line 3626

Quoted 10 lines
hw/ppc/spapr.c +7 -0
@@ -3616,6 +3617,14 @@ void spapr_clear_pending_dimm_unplug_state(SpaprMachineState *spapr,
         drc->unplug_requested = false;
         addr += SPAPR_MEMORY_BLOCK_SIZE;
     }
+
+    /*
+     * Tell QAPI that something happened and the memory
+     * hotunplug wasn't successful.
+     */
+    qapi_error = g_strdup_printf("Memory hotunplug failed for device %s",
+                                 dev->id);

Might be worth adjusting the error message to make it clearer that it was the guest which specifically rejected the unplug. Other than that, LGTM.

Quoted 37 lines
hw/ppc/spapr.c +1 -0
+    qapi_event_send_mem_unplug_error(dev->id, qapi_error);
 }
 
 /* Callback to be called during DRC release. */
hw/ppc/spapr_drc.c +2 -3
index 8c4997d795..8faaf9f1dd 100644
@@ -1232,12 +1232,11 @@ static void rtas_ibm_configure_connector(PowerPCCPU *cpu,
 
     /*
      * This indicates that the kernel is reconfiguring a LMB due to
-     * a failed hotunplug. Clear the pending unplug state for the whole
-     * DIMM.
+     * a failed hotunplug. Rollback the DIMM unplug process.
      */
     if (spapr_drc_type(drc) == SPAPR_DR_CONNECTOR_TYPE_LMB &&
         drc->unplug_requested) {
-        spapr_clear_pending_dimm_unplug_state(spapr, drc->dev);
+        spapr_memory_unplug_rollback(spapr, drc->dev);
     }
 
     if (!drc->fdt) {
include/hw/ppc/spapr.h +1 -2
index d6edeaaaff..47cebaf3ac 100644
@@ -847,8 +847,7 @@ int spapr_hpt_shift_for_ramsize(uint64_t ramsize);
 int spapr_reallocate_hpt(SpaprMachineState *spapr, int shift, Error **errp);
 void spapr_clear_pending_events(SpaprMachineState *spapr);
 void spapr_clear_pending_hotplug_events(SpaprMachineState *spapr);
-void spapr_clear_pending_dimm_unplug_state(SpaprMachineState *spapr,
-                                           DeviceState *dev);
+void spapr_memory_unplug_rollback(SpaprMachineState *spapr, DeviceState *dev);
 int spapr_max_server_number(SpaprMachineState *spapr);
 void spapr_store_hpte(PowerPCCPU *cpu, hwaddr ptex,
                       uint64_t pte0, uint64_t pte1);
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#9 lore raw

Re: [PATCH 3/5] spapr.c: add 'unplug already in progress' message for PHB unplug

In reply to Daniel Henrique Barboza
Quoted 7 lines · Daniel Henrique Barboza

Both CPU hotunplug and PC_DIMM unplug reports an user warning, mentioning that the hotunplug is in progress, if consecutive 'device_del' are issued in quick succession.

Do the same for PHBs in spapr_phb_unplug_request().

LGTM, and doesn't have strong dependencies on the other patches, so applied to ppc-for-6.0.

Quoted 19 lines
---
 hw/ppc/spapr.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/ppc/spapr.c +4 -0
index 149dc2113f..6ef72ee7bd 100644
@@ -4030,6 +4030,10 @@ static void spapr_phb_unplug_request(HotplugHandler *hotplug_dev,
     if (!spapr_drc_unplug_requested(drc)) {
         spapr_drc_unplug_request(drc);
         spapr_hotplug_req_remove_by_index(drc);
+    } else {
+        error_setg(errp,
+                   "PCI Host Bridge unplug already in progress for device %s",
+                   dev->id);
     }
 }
 
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#5 lore raw

Re: [PATCH 2/5] spapr.c: check unplug_request flag in spapr_memory_unplug_request()

In reply to Daniel Henrique Barboza
Quoted 10 lines · Daniel Henrique Barboza

Now that we're asserting the first DRC LMB earlier, use it to query if the DRC is already pending unplug and, in this case, issue the same error we already do.

The previous check was introduced in commit 2a129767ebb1 and it works, but it's easier to check the unplug_requested flag instead of looking for the existence of the sPAPRDIMMState. It's also compliant with what is already done in other unplug_request functions for other devices.

I'm having some trouble completely convincing myself this is right.

What about this situation:
1. We initiate a DIMM unplug
- unplug_request is set on all the LMBs
- all the LMBs go on the pending_unplug list
2. The guest encounters no problems, and starts issuing set indicator calls to mark the LMBs unusable, starting from the lowest address
3. On drc_set_unusable() for the first LMB, we see that unplug is requested and call spapr_drc_release()
4. spapr_drc_release() on the first LMB clears unplug_requested
5. At this point, but before this is done on *all* of the DIMM's LMBs, the user attempts another unplug triggering the code below

AFAICT this will now skip the error, since the first LMB is no longer in unplug_requested state, but there *are* still pending unplugs for some of the remaining LMBs, so the old code would have tripped the error.

Quoted 23 lines
---
 hw/ppc/spapr.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
hw/ppc/spapr.c +1 -7
index 74e046b522..149dc2113f 100644
@@ -3681,13 +3681,7 @@ static void spapr_memory_unplug_request(HotplugHandler *hotplug_dev,
                                 addr_start / SPAPR_MEMORY_BLOCK_SIZE);
     g_assert(drc_start);
 
-    /*
-     * An existing pending dimm state for this DIMM means that there is an
-     * unplug operation in progress, waiting for the spapr_lmb_release
-     * callback to complete the job (BQL can't cover that far). In this case,
-     * bail out to avoid detaching DRCs that were already released.
-     */
-    if (spapr_pending_dimm_unplugs_find(spapr, dimm)) {
+    if (spapr_drc_unplug_requested(drc_start)) {
         error_setg(errp, "Memory unplug already in progress for device %s",
                    dev->id);
         return;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#6 lore raw

Re: [PATCH 2/5] spapr.c: check unplug_request flag in spapr_memory_unplug_request()

Quoted 28 lines · David Gibson
Quoted 10 lines · Daniel Henrique Barboza

Now that we're asserting the first DRC LMB earlier, use it to query if the DRC is already pending unplug and, in this case, issue the same error we already do.

The previous check was introduced in commit 2a129767ebb1 and it works, but it's easier to check the unplug_requested flag instead of looking for the existence of the sPAPRDIMMState. It's also compliant with what is already done in other unplug_request functions for other devices.

I'm having some trouble completely convincing myself this is right.

What about this situation:
1. We initiate a DIMM unplug
- unplug_request is set on all the LMBs
- all the LMBs go on the pending_unplug list
2. The guest encounters no problems, and starts issuing set indicator calls to mark the LMBs unusable, starting from the lowest address
3. On drc_set_unusable() for the first LMB, we see that unplug is requested and call spapr_drc_release()
4. spapr_drc_release() on the first LMB clears unplug_requested
5. At this point, but before this is done on *all* of the DIMM's LMBs, the user attempts another unplug triggering the code below

Quoted 4 lines

AFAICT this will now skip the error, since the first LMB is no longer in unplug_requested state, but there *are* still pending unplugs for some of the remaining LMBs, so the old code would have tripped the error.

Good point. Checking the existence of the sPAPRDIMMState struct at this point is the same as checking for drc->unplug_requested for all the DRCs of the DIMM.

I could check for drc->unplug_requested inside the loop where we instantiate each DRC, but there is no gain in doing that instead of what we already have.

I'll drop this patch and change patch 1 to just remove the duplicated assert.

Thanks,

DHB

Quoted 25 lines
Quoted 24 lines
---
  hw/ppc/spapr.c | 8 +-------
  1 file changed, 1 insertion(+), 7 deletions(-)
hw/ppc/spapr.c +1 -7
index 74e046b522..149dc2113f 100644
@@ -3681,13 +3681,7 @@ static void spapr_memory_unplug_request(HotplugHandler *hotplug_dev,
                                  addr_start / SPAPR_MEMORY_BLOCK_SIZE);
      g_assert(drc_start);
 
-    /*
-     * An existing pending dimm state for this DIMM means that there is an
-     * unplug operation in progress, waiting for the spapr_lmb_release
-     * callback to complete the job (BQL can't cover that far). In this case,
-     * bail out to avoid detaching DRCs that were already released.
-     */
-    if (spapr_pending_dimm_unplugs_find(spapr, dimm)) {
+    if (spapr_drc_unplug_requested(drc_start)) {
          error_setg(errp, "Memory unplug already in progress for device %s",
                     dev->id);
          return;