Skip to contentSkip to conversation

pSeries: revert CPU unplug timeout

PATCH Applied Daniel Henrique Barboza 2 participants 6 messages Apr 1, 2021 – Apr 20, 2021

lore
Share & tools
lore
#0 lore raw

cover pSeries: revert CPU unplug timeout

Hi,

This series reverts the CPU hotunplug timeout mechanism that was added during the 6.0.0 cycle. See patch 1 for the reasoning behind this decision.

Patch 2 is a re-post of a patch that allows CPU hotunplug events to be re-send to the guest [1], regardless of any existing hotunplug pending state present in QEMU. This will give users a way to retry hotunplugging CPUs without relying on unplug timeouts.

[1] https://lists.gnu.org/archive/html/qemu-devel/2021-01/msg04399.html

Daniel Henrique Barboza (2):
spapr: rollback 'unplug timeout' for CPU hotunplugs spapr.c: always pulse guest IRQ in spapr_core_unplug_request()

 hw/ppc/spapr.c             | 15 +++++++----
 hw/ppc/spapr_drc.c         | 52 --------------------------------------
 include/hw/ppc/spapr_drc.h |  5 ----
 include/qemu/timer.h       |  8 ------
 util/qemu-timer.c          | 13 ----------
 5 files changed, 10 insertions(+), 83 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/2 spapr: rollback 'unplug timeout' for CPU hotunplugs

The pseries machines introduced the concept of 'unplug timeout' for CPU hotunplugs. The idea was to circunvent a deficiency in the pSeries specification (PAPR), that currently does not define a proper way for the hotunplug to fail. If the guest refuses to release the CPU (see [1] for an example) there is no way for QEMU to detect the failure.

Further discussions about how to send a QAPI event to inform about the hotunplug timeout [2] exposed problems that weren't predicted back when the idea was developed. Other QEMU machines don't have any type of hotunplug timeout mechanism for any device, e.g. ACPI based machines have a way to make hotunplug errors visible to the hypervisor. This would make this timeout mechanism exclusive to pSeries, which is not ideal.

The real problem is that a QAPI event that reports hotunplug timeouts puts the management layer (namely Libvirt) in a weird spot. We're not telling that the hotunplug failed, because we can't be 100% sure of that, and yet we're resetting the unplug state back, preventing any DEVICE_DEL events to reach out in case the guest decides to release the device. Libvirt would need to inspect the guest itself to see if the device was released or not, otherwise the internal domain states will be inconsistent. Moreover, Libvirt already has an 'unplug timeout' concept, and a QEMU side timeout would need to be juggled together with the existing Libvirt timeout.

All this considered, this solution ended up creating more trouble than it solved. This patch reverts the 3 commits that introduced the timeout mechanism for CPU hotplugs in pSeries machines.

This reverts commit 4515a5f786024fabf0bef4cf3d28adf5647e6e82 "qemu_timer.c: add timer_deadline_ms() helper"

This reverts commit d1c2e3ce3d5a5424651967bce1cf1f4caa0c6d91 "spapr_drc.c: add hotunplug timeout for CPUs"

This reverts commit 51254ffb320183a4636635840c23ee0e3a1efffa "spapr_drc.c: introduce unplug_timeout_timer"

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1911414
[2] https://lists.gnu.org/archive/html/qemu-devel/2021-03/msg04682.html

---

Paolo, I'm CCing you in this patch because I reverted a change in qemu_timer.c that added the timer_deadline_ms() helper that was used only by pseries code that I'm removing with this patch. Figured that a helper that is not used anywhere wouldn't do too much good.

 hw/ppc/spapr.c             |  4 ---
 hw/ppc/spapr_drc.c         | 52 --------------------------------------
 include/hw/ppc/spapr_drc.h |  5 ----
 include/qemu/timer.h       |  8 ------
 util/qemu-timer.c          | 13 ----------
 5 files changed, 82 deletions(-)
hw/ppc/spapr.c +0 -4
index 73a06df3b1..05a765fab4 100644
@@ -3778,10 +3778,6 @@ void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev,
     if (!spapr_drc_unplug_requested(drc)) {
         spapr_drc_unplug_request(drc);
         spapr_hotplug_req_remove_by_index(drc);
-    } else {
-        error_setg(errp, "core-id %d unplug is still pending, %d seconds "
-                   "timeout remaining",
-                   cc->core_id, spapr_drc_unplug_timeout_remaining_sec(drc));
     }
 }
 
hw/ppc/spapr_drc.c +0 -52

111 lines not on this page · raw message

include/hw/ppc/spapr_drc.h +0 -5
index 26599c385a..02a63b3666 100644
@@ -187,8 +187,6 @@ typedef struct SpaprDrc {
     bool unplug_requested;
     void *fdt;
     int fdt_start_offset;
-
-    QEMUTimer *unplug_timeout_timer;
 } SpaprDrc;
 
 struct SpaprMachineState;
@@ -211,8 +209,6 @@ typedef struct SpaprDrcClass {
 
     int (*dt_populate)(SpaprDrc *drc, struct SpaprMachineState *spapr,
                        void *fdt, int *fdt_start_offset, Error **errp);
-
-    int unplug_timeout_seconds;
 } SpaprDrcClass;
 
 typedef struct SpaprDrcPhysical {
@@ -248,7 +244,6 @@ int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_mask);
  */
 void spapr_drc_attach(SpaprDrc *drc, DeviceState *d);
 void spapr_drc_unplug_request(SpaprDrc *drc);
-int spapr_drc_unplug_timeout_remaining_sec(SpaprDrc *drc);
 
 /*
  * Reset all DRCs, causing pending hot-plug/unplug requests to complete.
include/qemu/timer.h +0 -8
index 301fa47b42..88ef114689 100644
@@ -797,14 +797,6 @@ static inline int64_t get_max_clock_jump(void)
     return 60 * NANOSECONDS_PER_SECOND;
 }
 
-/**
- * timer_deadline_ms:
- *
- * Returns the remaining miliseconds for @timer to expire, or zero
- * if the timer is no longer pending.
- */
-int64_t timer_deadline_ms(QEMUTimer *timer);
-
 /*
  * Low level clock functions
  */
util/qemu-timer.c +0 -13
index be529c1f65..f36c75e594 100644
@@ -242,19 +242,6 @@ int64_t timerlist_deadline_ns(QEMUTimerList *timer_list)
     return delta;
 }
 
-/*
- * Returns the time remaining for the deadline, in ms.
- */
-int64_t timer_deadline_ms(QEMUTimer *timer)
-{
-    if (timer_pending(timer)) {
-        return qemu_timeout_ns_to_ms(timer->expire_time) -
-               qemu_clock_get_ms(timer->timer_list->clock->type);
-    }
-
-    return 0;
-}
-
 /* Calculate the soonest deadline across all timerlists attached
  * to the clock. This is used for the icount timeout so we
  * ignore whether or not the clock should be used in deadline
Signature · 1 line
2.30.2
#2 lore raw

PATCH 2/2 spapr.c: always pulse guest IRQ in spapr_core_unplug_request()

In reply to Daniel Henrique Barboza

Commit 47c8c915b162 fixed a problem where multiple spapr_drc_detach() requests were breaking QEMU. The solution was to just spapr_drc_detach() once, and use spapr_drc_unplug_requested() to filter whether we already detached it or not. The commit also tied the hotplug request to the guest in the same condition.

Turns out that there is a reliable way for a CPU hotunplug to fail. If a guest with one CPU hotplugs a CPU1, then offline CPU0s via 'echo 0 > /sys/devices/system/cpu/cpu0/online', then attempts to hotunplug CPU1, the kernel will refuse it because it's the last online CPU of the system. Given that we're pulsing the IRQ only in the first try, in a failed attempt, all other CPU1 hotunplug attempts will fail, regardless of the online state of CPU1 in the kernel, because we're simply not letting the guest know that we want to hotunplug the device.

Let's move spapr_hotplug_req_remove_by_index() back out of the "if (!spapr_drc_unplug_requested(drc))" conditional, allowing for multiple 'device_del' requests to the same CPU core to reach the guest, in case the CPU core didn't fully hotunplugged previously.

---
 hw/ppc/spapr.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +10 -1
index 05a765fab4..e4be00b732 100644
@@ -3777,8 +3777,17 @@ void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev,
 
     if (!spapr_drc_unplug_requested(drc)) {
         spapr_drc_unplug_request(drc);
-        spapr_hotplug_req_remove_by_index(drc);
     }
+
+    /*
+     * spapr_hotplug_req_remove_by_index is left unguarded, out of the
+     * "!spapr_drc_unplug_requested" check, to allow for multiple IRQ
+     * pulses removing the same CPU. Otherwise, in an failed hotunplug
+     * attempt (e.g. the kernel will refuse to remove the last online
+     * CPU), we will never attempt it again because unplug_requested
+     * will still be 'true' in that case.
+     */
+    spapr_hotplug_req_remove_by_index(drc);
 }
 
 int spapr_core_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr,
Signature · 1 line
2.30.2
Applied
#3 lore raw

Re: [PATCH 2/2] spapr.c: always pulse guest IRQ in spapr_core_unplug_request()

Quoted 15 lines · Daniel Henrique Barboza

Commit 47c8c915b162 fixed a problem where multiple spapr_drc_detach() requests were breaking QEMU. The solution was to just spapr_drc_detach() once, and use spapr_drc_unplug_requested() to filter whether we already detached it or not. The commit also tied the hotplug request to the guest in the same condition.

Turns out that there is a reliable way for a CPU hotunplug to fail. If a guest with one CPU hotplugs a CPU1, then offline CPU0s via 'echo 0 > /sys/devices/system/cpu/cpu0/online', then attempts to hotunplug CPU1, the kernel will refuse it because it's the last online CPU of the system. Given that we're pulsing the IRQ only in the first try, in a failed attempt, all other CPU1 hotunplug attempts will fail, regardless of the online state of CPU1 in the kernel, because we're simply not letting the guest know that we want to hotunplug the device.

Quoted 6 lines

Let's move spapr_hotplug_req_remove_by_index() back out of the "if (!spapr_drc_unplug_requested(drc))" conditional, allowing for multiple 'device_del' requests to the same CPU core to reach the guest, in case the CPU core didn't fully hotunplugged previously.

I've applied these to ppc-for-6.0, but..

Quoted 14 lines
---
 hw/ppc/spapr.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +0 -1
index 05a765fab4..e4be00b732 100644
@@ -3777,8 +3777,17 @@ void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev,
 
     if (!spapr_drc_unplug_requested(drc)) {
         spapr_drc_unplug_request(drc);
-        spapr_hotplug_req_remove_by_index(drc);
     }

hw/ppc/spapr.c void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev, · line 3790

Quoted 10 lines
hw/ppc/spapr.c +10 -0
+
+    /*
+     * spapr_hotplug_req_remove_by_index is left unguarded, out of the
+     * "!spapr_drc_unplug_requested" check, to allow for multiple IRQ
+     * pulses removing the same CPU. Otherwise, in an failed hotunplug
+     * attempt (e.g. the kernel will refuse to remove the last online
+     * CPU), we will never attempt it again because unplug_requested
+     * will still be 'true' in that case.
+     */
+    spapr_hotplug_req_remove_by_index(drc);

I think we need similar changes for all the other unplug types (LMB, PCI, PHB) - basically retries should always be allowed, and at worst be a no-op, rather than generating an error like they do now.

Quoted 3 lines
hw/ppc/spapr.c +0 -0
 }
 
 int spapr_core_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr,
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
#4 lore raw

Re: [PATCH 2/2] spapr.c: always pulse guest IRQ in spapr_core_unplug_request()

Quoted 45 lines · David Gibson
Quoted 15 lines · Daniel Henrique Barboza

Commit 47c8c915b162 fixed a problem where multiple spapr_drc_detach() requests were breaking QEMU. The solution was to just spapr_drc_detach() once, and use spapr_drc_unplug_requested() to filter whether we already detached it or not. The commit also tied the hotplug request to the guest in the same condition.

Turns out that there is a reliable way for a CPU hotunplug to fail. If a guest with one CPU hotplugs a CPU1, then offline CPU0s via 'echo 0 > /sys/devices/system/cpu/cpu0/online', then attempts to hotunplug CPU1, the kernel will refuse it because it's the last online CPU of the system. Given that we're pulsing the IRQ only in the first try, in a failed attempt, all other CPU1 hotunplug attempts will fail, regardless of the online state of CPU1 in the kernel, because we're simply not letting the guest know that we want to hotunplug the device.

Quoted 6 lines

Let's move spapr_hotplug_req_remove_by_index() back out of the "if (!spapr_drc_unplug_requested(drc))" conditional, allowing for multiple 'device_del' requests to the same CPU core to reach the guest, in case the CPU core didn't fully hotunplugged previously.

I've applied these to ppc-for-6.0, but..

Quoted 20 lines
---
  hw/ppc/spapr.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +6 -1
index 05a765fab4..e4be00b732 100644
@@ -3777,8 +3777,17 @@ void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev,
 
      if (!spapr_drc_unplug_requested(drc)) {
          spapr_drc_unplug_request(drc);
-        spapr_hotplug_req_remove_by_index(drc);
      }
+
+    /*
+     * spapr_hotplug_req_remove_by_index is left unguarded, out of the
+     * "!spapr_drc_unplug_requested" check, to allow for multiple IRQ
+     * pulses removing the same CPU. Otherwise, in an failed hotunplug
+     * attempt (e.g. the kernel will refuse to remove the last online
Quoted 8 lines

hw/ppc/spapr.c void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev, · line 3790

Quoted 4 lines
hw/ppc/spapr.c +4 -0
+     * CPU), we will never attempt it again because unplug_requested
+     * will still be 'true' in that case.
+     */
+    spapr_hotplug_req_remove_by_index(drc);

I think we need similar changes for all the other unplug types (LMB, PCI, PHB) - basically retries should always be allowed, and at worst be a no-op, rather than generating an error like they do now.

For PHBs should be straightforward. Not so sure about PCI because there is all the PCI function logic around the hotunplug of function 0.

As for LMBs, we block further attempts because there is no way we can tell if the hotunplug is being executed but it is taking some time (it is not uncommon for a DIMM unplug to take 20-30 seconds to complete), versus an error scenario. What we do ATM is check is the pending DIMM unplug state exists, and if it does, assume that a hotunplug is pending. I have no idea what would happen if an unplug request for a LMB DRC reaches the kernel in the middle of an error rollback (when the kernel reconnects all the LMBs again) and the same DRC that was rolled back is disconnected again.

We would need to check not only if the pending dimm unplug state exists, but also if partially exists. In other words, if there are DRCs of that DIMM that were unplugged already. That way we can prevent to issue a removal while the unplug is still running.

Thanks,

DHB

Quoted 5 lines
Quoted 4 lines
hw/ppc/spapr.c +0 -0
  }
 
  int spapr_core_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr,
#5 lore raw

Re: [PATCH 2/2] spapr.c: always pulse guest IRQ in spapr_core_unplug_request()

Quoted 57 lines · Daniel Henrique Barboza
Quoted 44 lines · David Gibson
Quoted 15 lines · Daniel Henrique Barboza

Commit 47c8c915b162 fixed a problem where multiple spapr_drc_detach() requests were breaking QEMU. The solution was to just spapr_drc_detach() once, and use spapr_drc_unplug_requested() to filter whether we already detached it or not. The commit also tied the hotplug request to the guest in the same condition.

Turns out that there is a reliable way for a CPU hotunplug to fail. If a guest with one CPU hotplugs a CPU1, then offline CPU0s via 'echo 0 > /sys/devices/system/cpu/cpu0/online', then attempts to hotunplug CPU1, the kernel will refuse it because it's the last online CPU of the system. Given that we're pulsing the IRQ only in the first try, in a failed attempt, all other CPU1 hotunplug attempts will fail, regardless of the online state of CPU1 in the kernel, because we're simply not letting the guest know that we want to hotunplug the device.

Quoted 6 lines

Let's move spapr_hotplug_req_remove_by_index() back out of the "if (!spapr_drc_unplug_requested(drc))" conditional, allowing for multiple 'device_del' requests to the same CPU core to reach the guest, in case the CPU core didn't fully hotunplugged previously.

I've applied these to ppc-for-6.0, but..

Quoted 19 lines
---
  hw/ppc/spapr.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +6 -1
index 05a765fab4..e4be00b732 100644
@@ -3777,8 +3777,17 @@ void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev,
      if (!spapr_drc_unplug_requested(drc)) {
          spapr_drc_unplug_request(drc);
-        spapr_hotplug_req_remove_by_index(drc);
      }
+
+    /*
+     * spapr_hotplug_req_remove_by_index is left unguarded, out of the
+     * "!spapr_drc_unplug_requested" check, to allow for multiple IRQ
+     * pulses removing the same CPU. Otherwise, in an failed hotunplug
+     * attempt (e.g. the kernel will refuse to remove the last online
Quoted 8 lines

hw/ppc/spapr.c void spapr_core_unplug_request(HotplugHandler *hotplug_dev, DeviceState *dev, · line 3790

Quoted 4 lines
hw/ppc/spapr.c +4 -0
+     * CPU), we will never attempt it again because unplug_requested
+     * will still be 'true' in that case.
+     */
+    spapr_hotplug_req_remove_by_index(drc);

I think we need similar changes for all the other unplug types (LMB, PCI, PHB) - basically retries should always be allowed, and at worst be a no-op, rather than generating an error like they do now.

Quoted 7 lines

For PHBs should be straightforward. Not so sure about PCI because there is all the PCI function logic around the hotunplug of function 0.

As for LMBs, we block further attempts because there is no way we can tell if the hotunplug is being executed but it is taking some time (it is not uncommon for a DIMM unplug to take 20-30 seconds to complete), versus an error scenario.

I don't see why that prevents retries. Can't you reissue the index+size unplug request anyway? The code you already have to fail unplugs on a reconfigure should work for both the original request and the retry, shouldn't it?

Quoted 23 lines

What we do ATM is check is the pending DIMM unplug
state exists, and if it does, assume that a hotunplug is pending. I have no idea what would happen if an unplug request for a LMB DRC reaches the kernel in the middle of an error rollback (when the kernel reconnects all the LMBs again) and the same DRC that was rolled back is disconnected again.

We would need to check not only if the pending dimm unplug state exists, but also if partially exists. In other words, if there are DRCs of that DIMM that were unplugged already. That way we can prevent to issue a removal while the unplug is still running.

Thanks,

DHB

Quoted 4 lines
Quoted 3 lines
hw/ppc/spapr.c +0 -0
  }
  int spapr_core_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr,
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