Skip to contentSkip to conversation

RFC: pcie: parital fix for missing unplug events

PATCH In review Maxim Levitsky 3 participants 7 messages Jul 22, 2020 – Jul 30, 2020

lore
Share & tools
lore
#0 lore raw

cover RFC: pcie: parital fix for missing unplug events

As described in bugzilla #1854264 it is possible to plug a pcie device and then unplug it before the guest notices (has time to process the attention button press)

To partially fix this issue, detect and refuse the hotunplug event.

There are other ways to fix this, which is why I am sending this as RFC:

1. Queue/remember the unplug event and fire it (press the attention button again), when the guest clears its pending status.
According to the spec this should cancel the hotplug event in the guest if done within 5 seconds (and I think that guest actually should wait 5 seconds after attention button is pressed before plugging in the device too to be strictly up to the spec)

2. Detect that device isn't yet powered on by the guest (for example checking the bus master bit) or check that attention button is still pressed and in this case just unplug the device immediately.

Best regards,
Maxim Levitsky

Maxim Levitsky (1):
pci/pcie: refuse another hotplug/unplug event if attention button is
pending

 hw/pci/pcie.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/1 pci/pcie: refuse another hotplug/unplug event if attention button is pending

Curently it is possible to hotplug a device and then immediatly hotunplug it before the OS notices, and that will result
in missed unplug event since we can only send one attention button event.

Moreover the device will stuck in unplugging state forever.

Error out in such cases and rely on the caller (e.g libvirt) to retry the unplug a bit later

---
 hw/pci/pcie.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
hw/pci/pcie.c +11 -0
index 5b48bae0f6..9e836cf2f4 100644
@@ -402,6 +402,17 @@ static void pcie_cap_slot_plug_common(PCIDevice *hotplug_dev, DeviceState *dev,
          */
         error_setg_errno(errp, EBUSY, "slot is electromechanically locked");
     }
+
+    if (sltsta & PCI_EXP_SLTSTA_ABP) {
+        /*
+         * Attention button is pressed, thus we can't send another
+         * hotpplug event
+         */
+        error_setg_errno(errp, EBUSY,
+                         "attention button is already pressed, can't "
+                         "send another hotplug event");
+    }
+
 }
 
 void pcie_cap_slot_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
Signature · 1 line
2.26.2
#2 lore raw

Re: [PATCH 1/1] pci/pcie: refuse another hotplug/unplug event if attention button is pending

Quoted 19 lines · Maxim Levitsky

Curently it is possible to hotplug a device and then immediatly hotunplug it before the OS notices, and that will result
in missed unplug event since we can only send one attention button event.

Moreover the device will stuck in unplugging state forever.

Error out in such cases and rely on the caller (e.g libvirt) to retry the unplug a bit later

---
 hw/pci/pcie.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
hw/pci/pcie.c +0 -0
index 5b48bae0f6..9e836cf2f4 100644

hw/pci/pcie.c static void pcie_cap_slot_plug_common(PCIDevice *hotplug_dev, DeviceState *dev, · line 409

Quoted 8 lines
hw/pci/pcie.c +5 -0
@@ -402,6 +402,17 @@ static void pcie_cap_slot_plug_common(PCIDevice *hotplug_dev, DeviceState *dev,
          */
         error_setg_errno(errp, EBUSY, "slot is electromechanically locked");
     }
+
+    if (sltsta & PCI_EXP_SLTSTA_ABP) {
+        /*
+         * Attention button is pressed, thus we can't send another
+         * hotpplug event

Typo here, forgot to refresh the commit.

Quoted 9 lines
hw/pci/pcie.c +6 -0
+         */
+        error_setg_errno(errp, EBUSY,
+                         "attention button is already pressed, can't "
+                         "send another hotplug event");
+    }
+
 }
 
 void pcie_cap_slot_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
#3 lore raw

Re: [PATCH 1/1] pci/pcie: refuse another hotplug/unplug event if attention button is pending

Quoted 15 lines · Maxim Levitsky
Quoted 14 lines · Maxim Levitsky

Curently it is possible to hotplug a device and then immediatly hotunplug it before the OS notices, and that will result
in missed unplug event since we can only send one attention button event.

Moreover the device will stuck in unplugging state forever.

Error out in such cases and rely on the caller (e.g libvirt) to retry the unplug a bit later

---
 hw/pci/pcie.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
Quoted 23 lines

hw/pci/pcie.c static void pcie_cap_slot_plug_common(PCIDevice *hotplug_dev, DeviceState *dev, · line 409

Quoted 13 lines
hw/pci/pcie.c +5 -0
index 5b48bae0f6..9e836cf2f4 100644
@@ -402,6 +402,17 @@ static void pcie_cap_slot_plug_common(PCIDevice *hotplug_dev, DeviceState *dev,
          */
         error_setg_errno(errp, EBUSY, "slot is electromechanically locked");
     }
+
+    if (sltsta & PCI_EXP_SLTSTA_ABP) {
+        /*
+         * Attention button is pressed, thus we can't send another
+         * hotpplug event

Typo here, forgot to refresh the commit.

Quoted 9 lines
hw/pci/pcie.c +6 -0
+         */
+        error_setg_errno(errp, EBUSY,
+                         "attention button is already pressed, can't "
+                         "send another hotplug event");
+    }
+
 }
 
 void pcie_cap_slot_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,

ping.

Best regards,
Maxim Levitsky

#4 lore raw

Re: [PATCH 1/1] pci/pcie: refuse another hotplug/unplug event if attention button is pending

Quoted 38 lines · On Wed, 29 Jul 2020 08:09:37 +0300 Maxim Levitsky <[email protected]> wrote:
Quoted 37 lines · Maxim Levitsky
Quoted 19 lines · Maxim Levitsky

Curently it is possible to hotplug a device and then immediatly hotunplug it before the OS notices, and that will result
in missed unplug event since we can only send one attention button event.

Moreover the device will stuck in unplugging state forever.

Error out in such cases and rely on the caller (e.g libvirt) to retry the unplug a bit later

---
 hw/pci/pcie.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
hw/pci/pcie.c +0 -0
index 5b48bae0f6..9e836cf2f4 100644

hw/pci/pcie.c static void pcie_cap_slot_plug_common(PCIDevice *hotplug_dev, DeviceState *dev, · line 409

Quoted 8 lines
hw/pci/pcie.c +5 -0
@@ -402,6 +402,17 @@ static void pcie_cap_slot_plug_common(PCIDevice *hotplug_dev, DeviceState *dev,
          */
         error_setg_errno(errp, EBUSY, "slot is electromechanically locked");
     }
+
+    if (sltsta & PCI_EXP_SLTSTA_ABP) {
+        /*
+         * Attention button is pressed, thus we can't send another
+         * hotpplug event  

Typo here, forgot to refresh the commit.

Quoted 8 lines
hw/pci/pcie.c +6 -0
+         */
+        error_setg_errno(errp, EBUSY,
+                         "attention button is already pressed, can't "
+                         "send another hotplug event");
+    }
+
 }
 
Quoted 2 lines
Quoted 1 line

hw/pci/pcie.c static void pcie_cap_slot_plug_common(PCIDevice *hotplug_dev, DeviceState *dev, · line 418

Quoted 1 line
hw/pci/pcie.c +0 -0
 void pcie_cap_slot_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,  

ping.

CCing Julia since she was looking into PCI hotplug/unplug code recently.

Quoted 5 lines

Best regards,
Maxim Levitsky

#5 lore raw

Re: [PATCH 1/1] pci/pcie: refuse another hotplug/unplug event if attention button is pending

In reply to Maxim Levitsky
Quoted 19 lines · Maxim Levitsky

Curently it is possible to hotplug a device and then immediatly hotunplug it before the OS notices, and that will result
in missed unplug event since we can only send one attention button event.

Moreover the device will stuck in unplugging state forever.

Error out in such cases and rely on the caller (e.g libvirt) to retry the unplug a bit later

---
 hw/pci/pcie.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
hw/pci/pcie.c +0 -0
index 5b48bae0f6..9e836cf2f4 100644

hw/pci/pcie.c static void pcie_cap_slot_plug_common(PCIDevice *hotplug_dev, DeviceState *dev, · line 409

Quoted 8 lines
hw/pci/pcie.c +5 -0
@@ -402,6 +402,17 @@ static void pcie_cap_slot_plug_common(PCIDevice *hotplug_dev, DeviceState *dev,
          */
         error_setg_errno(errp, EBUSY, "slot is electromechanically locked");
     }
+
+    if (sltsta & PCI_EXP_SLTSTA_ABP) {
+        /*
+         * Attention button is pressed, thus we can't send another
+         * hotpplug event

typo

hw/pci/pcie.c static void pcie_cap_slot_plug_common(PCIDevice *hotplug_dev, DeviceState *dev, · line 416

Quoted 7 lines
hw/pci/pcie.c +6 -0
+         */
+        error_setg_errno(errp, EBUSY,
+                         "attention button is already pressed, can't "
+                         "send another hotplug event");
+    }
+
 }

It would be neater if we could queue the event up in qemu. Alternatively - can we clean up the unhandled event so guest does not even notice the device briefly appeared?

Quoted 4 lines
hw/pci/pcie.c +0 -0
 void pcie_cap_slot_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
Signature · 1 line
2.26.2
#6 lore raw
In reply to Maxim Levitsky
Quoted 15 lines · Maxim Levitsky

As described in bugzilla #1854264 it is possible to plug a pcie device and then unplug it before the guest notices (has time to process the attention button press)

To partially fix this issue, detect and refuse the hotunplug event.

There are other ways to fix this, which is why I am sending this as RFC:

1. Queue/remember the unplug event and fire it (press the attention button again), when the guest clears its pending status.
According to the spec this should cancel the hotplug event in the guest if done within 5 seconds (and I think that guest actually should wait 5 seconds after attention button is pressed before plugging in the device too to be strictly up to the spec)

Quoted 3 lines

2. Detect that device isn't yet powered on by the guest (for example checking the bus master bit) or check that attention button is still pressed and in this case just unplug the device immediately.

I think 2 or failing that 1 would be preferable.

Quoted 13 lines

Best regards,
Maxim Levitsky

Maxim Levitsky (1):
pci/pcie: refuse another hotplug/unplug event if attention button is
pending

 hw/pci/pcie.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
Signature · 1 line
2.26.2