diff mbox series

qdev-monitor: Forbid repeated device_del

Message ID 20200220165556.39388-1-jusual@redhat.com (mailing list archive)
State New, archived
Headers show
Series qdev-monitor: Forbid repeated device_del | expand

Commit Message

Julia Suvorova Feb. 20, 2020, 4:55 p.m. UTC
Device unplug can be done asynchronously. Thus, sending the second
device_del before the previous unplug is complete may lead to
unexpected results. On PCIe devices, this cancels the hot-unplug
process.

Signed-off-by: Julia Suvorova <jusual@redhat.com>
---
 qdev-monitor.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Stefan Hajnoczi Feb. 21, 2020, 1:53 p.m. UTC | #1
On Thu, Feb 20, 2020 at 05:55:56PM +0100, Julia Suvorova wrote:
> Device unplug can be done asynchronously. Thus, sending the second
> device_del before the previous unplug is complete may lead to
> unexpected results. On PCIe devices, this cancels the hot-unplug
> process.
> 
> Signed-off-by: Julia Suvorova <jusual@redhat.com>
> ---
>  qdev-monitor.c | 6 ++++++
>  1 file changed, 6 insertions(+)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Paolo Bonzini Feb. 21, 2020, 1:58 p.m. UTC | #2
On 21/02/20 14:53, Stefan Hajnoczi wrote:
> On Thu, Feb 20, 2020 at 05:55:56PM +0100, Julia Suvorova wrote:
>> Device unplug can be done asynchronously. Thus, sending the second
>> device_del before the previous unplug is complete may lead to
>> unexpected results. On PCIe devices, this cancels the hot-unplug
>> process.
>>
>> Signed-off-by: Julia Suvorova <jusual@redhat.com>
>> ---
>>  qdev-monitor.c | 6 ++++++
>>  1 file changed, 6 insertions(+)
> 
> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> 

Queued, thanks.

Paolo
diff mbox series

Patch

diff --git a/qdev-monitor.c b/qdev-monitor.c
index 8ce71a206b..8a2a9538cd 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -887,6 +887,12 @@  void qmp_device_del(const char *id, Error **errp)
 {
     DeviceState *dev = find_device_state(id, errp);
     if (dev != NULL) {
+        if (dev->pending_deleted_event) {
+            error_setg(errp, "Device %s is already in the "
+                             "process of unplug", id);
+            return;
+        }
+
         qdev_unplug(dev, errp);
     }
 }