`qdev_free` when unplug a pci device
PATCH 1/1 `qdev_free` when unplug a pci device
qdev_free when unplug a pci device
It resolves a bug when detaching/attaching a network device
# virsh detach-interface dom0 network --mac 52:54:00:f6:84:ba Interface detached successfully
# virsh attach-interface dom0 network default --mac 52:54:00:f6:84:ba error: Failed to attach interface error: internal error unable to execute QEMU command 'device_add': Duplicate ID 'net0' for device
A detached pci device was not freed of the list qemu_device_opts
--- hw/pci.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
hw/pci.c +4 -1
@@ -1671,13 +1671,16 @@ static int pci_unplug_device(DeviceState *qdev) {PCIDevice *dev =DO_UPCAST (PCIDevice, qdev, qdev);PCIDeviceInfo *info =container_of (qdev->info, PCIDeviceInfo, qdev); +int unplug;if (info->no_hotplug) {qerror_report (QERR_DEVICE_NO_HOTPLUG , info->qdev.name);return -1 ; } -return dev->bus->hotplug (dev->bus->hotplug_qdev, dev, + unplug = dev->bus->hotplug (dev->bus->hotplug_qdev, dev,PCI_HOTPLUG_DISABLED ); +qdev_free (qdev); +return unplug; }void pci_qdev_register (PCIDeviceInfo *info)
Signature · 1 line
William
Quoted 23 lines · William Dauchy
qdev_freewhen unplug a pci device
It resolves a bug when detaching/attaching a network device# virsh detach-interface dom0 network --mac 52:54:00:f6:84:ba Interface detached successfully# virsh attach-interface dom0 network default --mac 52:54:00:f6:84:ba error: Failed to attach interface error: internal error unable to execute QEMU command 'device_add': Duplicate ID 'net0' for deviceA detached pci device was not freed of the list
qemu_device_opts--- hw/pci.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)hw/pci.c +0
-0@@ -1671,13 +1671,16 @@ static int pci_unplug_device(DeviceState *qdev) {PCIDevice *dev =DO_UPCAST (PCIDevice, qdev, qdev);PCIDeviceInfo *info =container_of (qdev->info, PCIDeviceInfo, qdev);
hw/pci.c static int pci_unplug_device(DeviceState *qdev) · line 1682
Quoted 10 lines
hw/pci.c +3
-1+int unplug;if (info->no_hotplug) {qerror_report (QERR_DEVICE_NO_HOTPLUG , info->qdev.name);return -1 ; } -return dev->bus->hotplug (dev->bus->hotplug_qdev, dev, + unplug = dev->bus->hotplug (dev->bus->hotplug_qdev, dev,PCI_HOTPLUG_DISABLED ); +qdev_free (qdev);
Good catch.qdev_free() should be called only when unplug had succeeded. Although piix4 unplug always successes, pcie unplug may fail.
Quoted 8 lines
hw/pci.c +1
-0+return unplug; }void pci_qdev_register (PCIDeviceInfo *info)Signature · 1 line
William
Signature · 1 line
yamahata
Quoted 26 lines · Isaku Yamahata
Quoted 25 lines · William Dauchy
qdev_freewhen unplug a pci device
It resolves a bug when detaching/attaching a network device# virsh detach-interface dom0 network --mac 52:54:00:f6:84:ba Interface detached successfully# virsh attach-interface dom0 network default --mac 52:54:00:f6:84:ba error: Failed to attach interface error: internal error unable to execute QEMU command 'device_add': Duplicate ID 'net0' for deviceA detached pci device was not freed of the list
qemu_device_opts--- hw/pci.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)hw/pci.c +1
-0@@ -1671,13 +1671,16 @@ static int pci_unplug_device(DeviceState *qdev) {PCIDevice *dev =DO_UPCAST (PCIDevice, qdev, qdev);PCIDeviceInfo *info =container_of (qdev->info, PCIDeviceInfo, qdev); +int unplug;
Quoted 17 lines
hw/pci.c static int pci_unplug_device(DeviceState *qdev) · line 1682
Quoted 8 lines
hw/pci.c +2
-1if (info->no_hotplug) {qerror_report (QERR_DEVICE_NO_HOTPLUG , info->qdev.name);return -1 ; } -return dev->bus->hotplug (dev->bus->hotplug_qdev, dev, + unplug = dev->bus->hotplug (dev->bus->hotplug_qdev, dev,PCI_HOTPLUG_DISABLED ); +qdev_free (qdev);Good catch.
qdev_free()should be called only when unplug had succeeded. Although piix4 unplug always successes, pcie unplug may fail.Quoted 4 lines
hw/pci.c +1
-0+return unplug; }void pci_qdev_register (PCIDeviceInfo *info)
I don't think this patch is correct. Let me explain.
Device hot unplug is *not* guaranteed to succeed.
For some buses, such as USB, it always succeeds immediately, i.e. when the device_del monitor command finishes, the device is gone. Live is good.
But for PCI, device_del merely initiates the ACPI unplug rain dance. It doesn't wait for the dance to complete. Why? The dance can take an unpredictable amount of time, including forever.
Problem: Subsequent device_add can fail if it reuses the qdev ID or PCI slot, and the unplug has not yet completed (race condition), or it failed. Yes, Virginia, PCI hotplug *can* fail.
When unplug succeeds, the qdev is automatically destroyed. pciej_write() does that for PIIX4. Looks like pcie_cap_slot_event() does it for PCIE.
Your patch adds a *second* qdev_free(). No good.
Hi Markus,
Quoted 16 lines · Markus Armbruster
I don't think this patch is correct. Let me explain.
Device hot unplug is *not* guaranteed to succeed.
For some buses, such as USB, it always succeeds immediately, i.e. when the
device_delmonitor command finishes, the device is gone. Live is good.But for PCI,
device_delmerely initiates the ACPI unplug rain dance. It doesn't wait for the dance to complete. Why? The dance can take an unpredictable amount of time, including forever.Problem: Subsequent
device_addcan fail if it reuses the qdev ID or PCI slot, and the unplug has not yet completed (race condition), or it failed. Yes, Virginia, PCI hotplug *can* fail.
Quoted 5 lines
When unplug succeeds, the qdev is automatically destroyed.
pciej_write()does that for PIIX4. Looks likepcie_cap_slot_event()does it for PCIE.Your patch adds a *second*
qdev_free(). No good.
Thanks for the complete explanation. I now understand my mistake and find out why it wasn't working as expected.
On a Linux virtual machine I forgot to load the acpiphp module which makes the pci device disappear when doing a detach. I thought that, even without this module the detach should have freed the corresponding device on qemu side, regardless if the virtual machine was supporting or not acpi signals.
Please ignore my patch.
Regards,
Signature · 1 line
William
Hi Markus Armbruster
At 02/23/2011 04:30 PM, Markus Armbruster Write:
Quoted 2 lines
Isaku Yamahata <[email protected]> writes:
<snip>
Quoted 13 lines
I don't think this patch is correct. Let me explain.
Device hot unplug is *not* guaranteed to succeed.
For some buses, such as USB, it always succeeds immediately, i.e. when the
device_delmonitor command finishes, the device is gone. Live is good.But for PCI,
device_delmerely initiates the ACPI unplug rain dance. It doesn't wait for the dance to complete. Why? The dance can take an unpredictable amount of time, including forever.
Quoted 7 lines
Problem: Subsequent
device_addcan fail if it reuses the qdev ID or PCI slot, and the unplug has not yet completed (race condition), or it failed. Yes, Virginia, PCI hotplug *can* fail.When unplug succeeds, the qdev is automatically destroyed.
pciej_write()does that for PIIX4. Looks likepcie_cap_slot_event()does it for PCIE.
I got a similar problem. When I unplug a pci device by hand, it works as expected, and I can hotplug it again. But when I use a srcipt to do the same thing, sometimes it failed. I think I may find another bug.
Steps to reproduce this bug:
1. cat ./test-e1000.sh # RHEL6RC is domain name #! /bin/bash
while true; do
virsh attach-interface RHEL6RC network default --mac 52:54:00:1f:db:c7 --model e1000
if [[ $? -ne 0 ]]; then
break
fi
virsh detach-interface RHEL6RC network --mac 52:54:00:1f:db:c7
if [[ $? -ne 0 ]]; then
break
fi
sleep 5
done2. ./test-e1000.sh
Interface attached successfully
Interface detached successfully
Interface attached successfully
Interface detached successfully
error: Failed to attach interface
error: operation failed: adding e1000,netdev=hostnet1,id=net1,mac=52:54:00:1f:db:c7,bus=pci.0,addr=0x8 device failed: Duplicate ID 'net1' for device
I use ftrace to trace whether sci interrupt is passed to guest OS, here is log:
# cat trace | grep 'irq=9'
<idle>-0 [000] 118342.634772: irq_handler_entry: irq=9 name=acpi
<idle>-0 [000] 118342.634831: irq_handler_exit: irq=9 ret=handled
<idle>-0 [000] 118342.693216: irq_handler_entry: irq=9 name=acpi
<idle>-0 [000] 118342.693254: irq_handler_exit: irq=9 ret=handled
<idle>-0 [000] 118347.737689: irq_handler_entry: irq=9 name=acpi
<idle>-0 [000] 118347.737738: irq_handler_exit: irq=9 ret=handled
According to the log, we only receive 3 sci interrupt, and one is lost.I enable piix4's debug and 1 line printf into piix4_device_hotplug:
printf("slot: %d, up: %d, down: %d, state: %d\n", slot, s->pci0_status.up, s->pci0_status.down, state);here is the log:
========
PM: mapping to 0xb000
PM readw port=0x0004 val=0x0000
...
gpe write afe2 <== 0
gpe write afe0 <== 255
gpe write afe3 <== 0
gpe write afe1 <== 255
PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0000
gpe read afe0 == 0
gpe read afe2 == 0
gpe read afe1 == 0
gpe read afe3 == 0
PM writew port=0x0000 val=0x0020
PM readw port=0x0002 val=0x0000
PM writew port=0x0002 val=0x0020
PM readw port=0x0002 val=0x0020
gpe write afe2 <== 255
gpe write afe3 <== 255
...
slot: 6, up: 0, down: 0, state: 1 <==== we attach interface the first time
PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 40
pcihotplug read ae04 == 0
...
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 6, up: 64, down: 0, state: 0 <===== we detach interface the first time PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 0
pcihotplug read ae04 == 40
...
pciej write ae08 <== 64 <=== we will call qdev_free()
pciej write ae08 <== 64
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 7, up: 0, down: 64, state: 1 <=== we attach interface the second time. PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
slot: 7, up: 128, down: 0, state: 0 <=== we detach interface the second time
gpe write afe0 <== 2 <=== write 2 to afe0 will cause sci interupt to be lost
gpe write afe2 <== 255
===========
Here is short log, and show the different between the first time and second time:
===========
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 6, up: 64, down: 0, state: 0 <===== we detach interface the first time
....
slot: 7, up: 128, down: 0, state: 0 <=== we detach interface the second time
gpe write afe0 <== 2 <=== write 2 to afe0 will cause sci interupt to be lost
gpe write afe2 <== 255
===========
Does this behavior is a normal behavior?
The following patch can fix this problem.
Quoted 1 line
From
3c149575b52261b8da9a73d5c4ebdfedce9866c1Mon Sep 17 00:00:00 2001
From: Wen Congyang <[email protected]>
Date: Mon, 28 Feb 2011 10:33:45 +0800
Subject: [PATCH] pend hotplug event until last event is handled by guest OS
--- hw/acpi_piix4.c | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 44 insertions(+), 7 deletions(-)
hw/acpi_piix4.c +44 -7
@@ -74,6 +74,7 @@ typedef struct PIIX4PMState {/* for pci hotplug */ struct gpe_regs gpe;struct pci_status pci0_status; +struct pci_status pci0_status_pending;uint32_t pci0_hotplug_enable; } PIIX4PMState;
@@ -518,6 +519,19 @@ static void gpe_reset_val(uint16_t *cur, int addr, uint32_t val) *cur = (*cur & (0xff << (8 - shift))) | (x1 << shift); } +static void raise_pending_hotplug (PIIX4PMState *s) +{ +if (s->pci0_status_pending.up || s->pci0_status_pending.down) { + s->gpe.sts |=PIIX4_PCI_HOTPLUG_STATUS ; + s->pci0_status.up = s->pci0_status_pending.up; + s->pci0_status.down = s->pci0_status_pending.down; + s->pci0_status_pending.up =0 ; + s->pci0_status_pending.down =0 ; + +pm_update_sci (s); + } +} +static void gpe_writeb (void *opaque,uint32_t addr,uint32_t val) {PIIX4PMState *s = opaque;
@@ -539,6 +553,11 @@ static void gpe_writeb(void *opaque, uint32_t addr, uint32_t val)pm_update_sci (s);PIIX4_DPRINTF ("gpe write %x <== %d\n" , addr, val); + +if (!(g->sts &PIIX4_PCI_HOTPLUG_STATUS ) && g->en &PIIX4_PCI_HOTPLUG_STATUS ) { +/* check and reraise the pending hotplug event */ +raise_pending_hotplug (s); + } }static uint32_t pcihotplug_read (void *opaque,uint32_t addr)
@@ -639,12 +658,22 @@ static void enable_device(PIIX4PMState *s, int slot) s->pci0_status.up |= (1 << slot); } +static void pend_enable_device (PIIX4PMState *s,int slot) +{ + s->pci0_status_pending.up |= (1 << slot); +} +static void disable_device (PIIX4PMState *s,int slot) { s->gpe.sts |=PIIX4_PCI_HOTPLUG_STATUS ; s->pci0_status.down |= (1 << slot); } +static void pend_disable_device (PIIX4PMState *s,int slot) +{ + s->pci0_status_pending.down |= (1 << slot); +} +static int piix4_device_hotplug (DeviceState *qdev,PCIDevice *dev,PCIHotplugState state) {
@@ -659,15 +688,23 @@ static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,return 0 ; } - s->pci0_status.up =0 ; - s->pci0_status.down =0 ; -if (state ==PCI_HOTPLUG_ENABLED ) { -enable_device (s, slot); +if (s->gpe.sts &PIIX4_PCI_HOTPLUG_STATUS ) { +if (state ==PCI_HOTPLUG_ENABLED ) { +pend_enable_device (s, slot); + }else { +pend_disable_device (s, slot); + } }else { -disable_device (s, slot); - } + s->pci0_status.up =0 ; + s->pci0_status.down =0 ; +if (state ==PCI_HOTPLUG_ENABLED ) { +enable_device (s, slot); + }else { +disable_device (s, slot); + } -pm_update_sci (s); +pm_update_sci (s); + }return 0 ; }
Signature · 1 line
1.7.1
Quoted 4 lines
Your patch adds a *second*
qdev_free(). No good.
Hi.
I don't suppose that just introducing pending bits solve the issue. Your test only use single hot plug/unplug. How about mixing of multiple hot plug/unplug with different slots.
Zeroing up/down on piix4_device_hotplug() is the culprit.
State machine of (up, down) would be needed. (up, down) of each slots should be changed following something like
- on power-on (0, 0)
- on hot plug (0, 0) -> (1, 0)
if other combination -> error
- on hot unpug (1, 0) or (0, 0) -> (0, 1) (0, 0) is for cold plugged devices. (1, 0) is for hot plugged devices. if other combination -> error
- on pciej_write(write on PCI_EJ_BASE)
(0, 1) -> (0, 0) and qdev_free()
if other combination -> ignoreWhen enabling sci, those bits are checked and raise sci if necessary.
Any comments on this?
Anyway the current pci hotplug-related commands are somewhat broken, and needs clean up with multifunction hotplug support which is on my todo list.
thanks
Quoted 334 lines · Wen Congyang
Hi Markus Armbruster
At 02/23/2011 04:30 PM, Markus Armbruster Write:
Quoted 2 lines
Isaku Yamahata <[email protected]> writes:
<snip>
Quoted 13 lines
I don't think this patch is correct. Let me explain.
Device hot unplug is *not* guaranteed to succeed.
For some buses, such as USB, it always succeeds immediately, i.e. when the
device_delmonitor command finishes, the device is gone. Live is good.But for PCI,
device_delmerely initiates the ACPI unplug rain dance. It doesn't wait for the dance to complete. Why? The dance can take an unpredictable amount of time, including forever.Quoted 7 lines
Problem: Subsequent
device_addcan fail if it reuses the qdev ID or PCI slot, and the unplug has not yet completed (race condition), or it failed. Yes, Virginia, PCI hotplug *can* fail.When unplug succeeds, the qdev is automatically destroyed.
pciej_write()does that for PIIX4. Looks likepcie_cap_slot_event()does it for PCIE.I got a similar problem. When I unplug a pci device by hand, it works as expected, and I can hotplug it again. But when I use a srcipt to do the same thing, sometimes it failed. I think I may find another bug.
Steps to reproduce this bug:
1. cat ./test-e1000.sh # RHEL6RC is domain name #!/bin/bashwhile true; do virsh attach-interface RHEL6RC network default --mac 52:54:00:1f:db:c7 --model e1000 if [[ $? -ne 0 ]]; then break fi virsh detach-interface RHEL6RC network --mac 52:54:00:1f:db:c7 if [[ $? -ne 0 ]]; then break fi sleep 5 done2. ./test-e1000.sh
Interface attached successfullyInterface detached successfully
Interface attached successfully
Interface detached successfully
error: Failed to attach interface
error: operation failed: adding e1000,netdev=hostnet1,id=net1,mac=52:54:00:1f:db:c7,bus=pci.0,addr=0x8 device failed: Duplicate ID 'net1' for deviceI use ftrace to trace whether sci interrupt is passed to guest OS, here is log:
# cat trace | grep 'irq=9' <idle>-0 [000] 118342.634772: irq_handler_entry: irq=9 name=acpi <idle>-0 [000] 118342.634831: irq_handler_exit: irq=9 ret=handled <idle>-0 [000] 118342.693216: irq_handler_entry: irq=9 name=acpi <idle>-0 [000] 118342.693254: irq_handler_exit: irq=9 ret=handled <idle>-0 [000] 118347.737689: irq_handler_entry: irq=9 name=acpi <idle>-0 [000] 118347.737738: irq_handler_exit: irq=9 ret=handled According to the log, we only receive 3 sci interrupt, and one is lost.I enable piix4's debug and 1 line printf into
piix4_device_hotplug:printf("slot: %d, up: %d, down: %d, state: %d\n", slot, s->pci0_status.up, s->pci0_status.down, state);here is the log:
========
PM: mapping to0xb000
PM readw port=0x0004 val=0x0000
...
gpe write afe2 <== 0
gpe write afe0 <== 255
gpe write afe3 <== 0
gpe write afe1 <== 255
PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0000
gpe read afe0 == 0
gpe read afe2 == 0
gpe read afe1 == 0
gpe read afe3 == 0
PM writew port=0x0000 val=0x0020
PM readw port=0x0002 val=0x0000
PM writew port=0x0002 val=0x0020
PM readw port=0x0002 val=0x0020
gpe write afe2 <== 255
gpe write afe3 <== 255
...
slot: 6, up: 0, down: 0, state: 1 <==== we attach interface the first time
PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 40
pcihotplug read ae04 == 0
...
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 6, up: 64, down: 0, state: 0 <===== we detach interface the first time PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 0
pcihotplug read ae04 == 40
...
pciej write ae08 <== 64 <=== we will callqdev_free()
pciej write ae08 <== 64
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 7, up: 0, down: 64, state: 1 <=== we attach interface the second time. PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
slot: 7, up: 128, down: 0, state: 0 <=== we detach interface the second time
gpe write afe0 <== 2 <=== write 2 to afe0 will cause sci interupt to be lost
gpe write afe2 <== 255
===========Here is short log, and show the different between the first time and second time:
===========
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 6, up: 64, down: 0, state: 0 <===== we detach interface the first time
....
slot: 7, up: 128, down: 0, state: 0 <=== we detach interface the second time
gpe write afe0 <== 2 <=== write 2 to afe0 will cause sci interupt to be lost
gpe write afe2 <== 255===========
Does this behavior is a normal behavior?
The following patch can fix this problem.
From
3c149575b52261b8da9a73d5c4ebdfedce9866c1Mon Sep 17 00:00:00 2001
From: Wen Congyang <[email protected]>
Date: Mon, 28 Feb 2011 10:33:45 +0800
Subject: [PATCH] pend hotplug event until last event is handled by guest OS--- hw/acpi_piix4.c | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 44 insertions(+), 7 deletions(-)hw/acpi_piix4.c +44
-7@@ -74,6 +74,7 @@ typedef struct PIIX4PMState {/* for pci hotplug */ struct gpe_regs gpe;struct pci_status pci0_status; +struct pci_status pci0_status_pending;uint32_t pci0_hotplug_enable; } PIIX4PMState;@@ -518,6 +519,19 @@ static void gpe_reset_val(uint16_t *cur, int addr, uint32_t val) *cur = (*cur & (0xff << (8 - shift))) | (x1 << shift); } +static void raise_pending_hotplug (PIIX4PMState *s) +{ +if (s->pci0_status_pending.up || s->pci0_status_pending.down) { + s->gpe.sts |=PIIX4_PCI_HOTPLUG_STATUS ; + s->pci0_status.up = s->pci0_status_pending.up; + s->pci0_status.down = s->pci0_status_pending.down; + s->pci0_status_pending.up =0 ; + s->pci0_status_pending.down =0 ; + +pm_update_sci (s); + } +} +static void gpe_writeb (void *opaque,uint32_t addr,uint32_t val) {PIIX4PMState *s = opaque;@@ -539,6 +553,11 @@ static void gpe_writeb(void *opaque, uint32_t addr, uint32_t val)pm_update_sci (s);PIIX4_DPRINTF ("gpe write %x <== %d\n" , addr, val); + +if (!(g->sts &PIIX4_PCI_HOTPLUG_STATUS ) && g->en &PIIX4_PCI_HOTPLUG_STATUS ) { +/* check and reraise the pending hotplug event */ +raise_pending_hotplug (s); + } }static uint32_t pcihotplug_read (void *opaque,uint32_t addr)@@ -639,12 +658,22 @@ static void enable_device(PIIX4PMState *s, int slot) s->pci0_status.up |= (1 << slot); } +static void pend_enable_device (PIIX4PMState *s,int slot) +{ + s->pci0_status_pending.up |= (1 << slot); +} +static void disable_device (PIIX4PMState *s,int slot) { s->gpe.sts |=PIIX4_PCI_HOTPLUG_STATUS ; s->pci0_status.down |= (1 << slot); } +static void pend_disable_device (PIIX4PMState *s,int slot) +{ + s->pci0_status_pending.down |= (1 << slot); +} +static int piix4_device_hotplug (DeviceState *qdev,PCIDevice *dev,PCIHotplugState state) {@@ -659,15 +688,23 @@ static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,return 0 ; } - s->pci0_status.up =0 ; - s->pci0_status.down =0 ; -if (state ==PCI_HOTPLUG_ENABLED ) { -enable_device (s, slot); +if (s->gpe.sts &PIIX4_PCI_HOTPLUG_STATUS ) { +if (state ==PCI_HOTPLUG_ENABLED ) { +pend_enable_device (s, slot); + }else { +pend_disable_device (s, slot); + } }else { -disable_device (s, slot); - } + s->pci0_status.up =0 ; + s->pci0_status.down =0 ; +if (state ==PCI_HOTPLUG_ENABLED ) { +enable_device (s, slot); + }else { +disable_device (s, slot); + } -pm_update_sci (s); +pm_update_sci (s); + }return 0 ; }Signature · 1 line
1.7.1Quoted 4 lines
Your patch adds a *second*
qdev_free(). No good.
Signature · 1 line
yamahata
At 03/01/2011 12:11 PM, Isaku Yamahata Write:
Quoted 5 lines
Hi.
I don't suppose that just introducing pending bits solve the issue. Your test only use single hot plug/unplug. How about mixing of multiple hot plug/unplug with different slots.
The qemu uses the same thread to deal with monitor command and I/O request from guest OS. So I think mixing of multiple hot plug/unplug with different slots can also work fine.
Quoted 5 lines
Zeroing up/down on
piix4_device_hotplug()is the culprit.State machine of (up, down) would be needed. (up, down) of each slots should be changed following something like
Why we need this feature? We access s->pci0_status only in main thread and do not accesss it when we deal with signal, so there is no competition to access it.
Quoted 357 lines
- on power-on (0, 0)
- on hot plug (0, 0) -> (1, 0)if other combination -> error- on hot unpug (1, 0) or (0, 0) -> (0, 1) (0, 0) is for cold plugged devices. (1, 0) is for hot plugged devices. if other combination -> error
- onpciej_write(write on PCI_EJ_BASE)(0, 1) -> (0, 0) and qdev_free() if other combination -> ignoreWhen enabling sci, those bits are checked and raise sci if necessary.
Any comments on this?
Anyway the current pci hotplug-related commands are somewhat broken, and needs clean up with multifunction hotplug support which is on my todo list.thanks
Quoted 334 lines · Wen Congyang
Hi Markus Armbruster
At 02/23/2011 04:30 PM, Markus Armbruster Write:
Quoted 2 lines
Isaku Yamahata <[email protected]> writes:
<snip>
Quoted 13 lines
I don't think this patch is correct. Let me explain.
Device hot unplug is *not* guaranteed to succeed.
For some buses, such as USB, it always succeeds immediately, i.e. when the
device_delmonitor command finishes, the device is gone. Live is good.But for PCI,
device_delmerely initiates the ACPI unplug rain dance. It doesn't wait for the dance to complete. Why? The dance can take an unpredictable amount of time, including forever.Quoted 7 lines
Problem: Subsequent
device_addcan fail if it reuses the qdev ID or PCI slot, and the unplug has not yet completed (race condition), or it failed. Yes, Virginia, PCI hotplug *can* fail.When unplug succeeds, the qdev is automatically destroyed.
pciej_write()does that for PIIX4. Looks likepcie_cap_slot_event()does it for PCIE.I got a similar problem. When I unplug a pci device by hand, it works as expected, and I can hotplug it again. But when I use a srcipt to do the same thing, sometimes it failed. I think I may find another bug.
Steps to reproduce this bug:
1. cat ./test-e1000.sh # RHEL6RC is domain name #!/bin/bashwhile true; do virsh attach-interface RHEL6RC network default --mac 52:54:00:1f:db:c7 --model e1000 if [[ $? -ne 0 ]]; then break fi virsh detach-interface RHEL6RC network --mac 52:54:00:1f:db:c7 if [[ $? -ne 0 ]]; then break fi sleep 5 done2. ./test-e1000.sh
Interface attached successfullyInterface detached successfully
Interface attached successfully
Interface detached successfully
error: Failed to attach interface
error: operation failed: adding e1000,netdev=hostnet1,id=net1,mac=52:54:00:1f:db:c7,bus=pci.0,addr=0x8 device failed: Duplicate ID 'net1' for deviceI use ftrace to trace whether sci interrupt is passed to guest OS, here is log:
# cat trace | grep 'irq=9' <idle>-0 [000] 118342.634772: irq_handler_entry: irq=9 name=acpi <idle>-0 [000] 118342.634831: irq_handler_exit: irq=9 ret=handled <idle>-0 [000] 118342.693216: irq_handler_entry: irq=9 name=acpi <idle>-0 [000] 118342.693254: irq_handler_exit: irq=9 ret=handled <idle>-0 [000] 118347.737689: irq_handler_entry: irq=9 name=acpi <idle>-0 [000] 118347.737738: irq_handler_exit: irq=9 ret=handled According to the log, we only receive 3 sci interrupt, and one is lost.I enable piix4's debug and 1 line printf into
piix4_device_hotplug:printf("slot: %d, up: %d, down: %d, state: %d\n", slot, s->pci0_status.up, s->pci0_status.down, state);here is the log:
========
PM: mapping to0xb000
PM readw port=0x0004 val=0x0000
...
gpe write afe2 <== 0
gpe write afe0 <== 255
gpe write afe3 <== 0
gpe write afe1 <== 255
PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0000
gpe read afe0 == 0
gpe read afe2 == 0
gpe read afe1 == 0
gpe read afe3 == 0
PM writew port=0x0000 val=0x0020
PM readw port=0x0002 val=0x0000
PM writew port=0x0002 val=0x0020
PM readw port=0x0002 val=0x0020
gpe write afe2 <== 255
gpe write afe3 <== 255
...
slot: 6, up: 0, down: 0, state: 1 <==== we attach interface the first time
PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 40
pcihotplug read ae04 == 0
...
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 6, up: 64, down: 0, state: 0 <===== we detach interface the first time PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 0
pcihotplug read ae04 == 40
...
pciej write ae08 <== 64 <=== we will callqdev_free()
pciej write ae08 <== 64
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 7, up: 0, down: 64, state: 1 <=== we attach interface the second time. PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
slot: 7, up: 128, down: 0, state: 0 <=== we detach interface the second time
gpe write afe0 <== 2 <=== write 2 to afe0 will cause sci interupt to be lost
gpe write afe2 <== 255
===========Here is short log, and show the different between the first time and second time:
===========
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 6, up: 64, down: 0, state: 0 <===== we detach interface the first time
....
slot: 7, up: 128, down: 0, state: 0 <=== we detach interface the second time
gpe write afe0 <== 2 <=== write 2 to afe0 will cause sci interupt to be lost
gpe write afe2 <== 255===========
Does this behavior is a normal behavior?
The following patch can fix this problem.
From
3c149575b52261b8da9a73d5c4ebdfedce9866c1Mon Sep 17 00:00:00 2001
From: Wen Congyang <[email protected]>
Date: Mon, 28 Feb 2011 10:33:45 +0800
Subject: [PATCH] pend hotplug event until last event is handled by guest OS--- hw/acpi_piix4.c | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 44 insertions(+), 7 deletions(-)hw/acpi_piix4.c +44
-7@@ -74,6 +74,7 @@ typedef struct PIIX4PMState {/* for pci hotplug */ struct gpe_regs gpe;struct pci_status pci0_status; +struct pci_status pci0_status_pending;uint32_t pci0_hotplug_enable; } PIIX4PMState;@@ -518,6 +519,19 @@ static void gpe_reset_val(uint16_t *cur, int addr, uint32_t val) *cur = (*cur & (0xff << (8 - shift))) | (x1 << shift); } +static void raise_pending_hotplug (PIIX4PMState *s) +{ +if (s->pci0_status_pending.up || s->pci0_status_pending.down) { + s->gpe.sts |=PIIX4_PCI_HOTPLUG_STATUS ; + s->pci0_status.up = s->pci0_status_pending.up; + s->pci0_status.down = s->pci0_status_pending.down; + s->pci0_status_pending.up =0 ; + s->pci0_status_pending.down =0 ; + +pm_update_sci (s); + } +} +static void gpe_writeb (void *opaque,uint32_t addr,uint32_t val) {PIIX4PMState *s = opaque;@@ -539,6 +553,11 @@ static void gpe_writeb(void *opaque, uint32_t addr, uint32_t val)pm_update_sci (s);PIIX4_DPRINTF ("gpe write %x <== %d\n" , addr, val); + +if (!(g->sts &PIIX4_PCI_HOTPLUG_STATUS ) && g->en &PIIX4_PCI_HOTPLUG_STATUS ) { +/* check and reraise the pending hotplug event */ +raise_pending_hotplug (s); + } }static uint32_t pcihotplug_read (void *opaque,uint32_t addr)@@ -639,12 +658,22 @@ static void enable_device(PIIX4PMState *s, int slot) s->pci0_status.up |= (1 << slot); } +static void pend_enable_device (PIIX4PMState *s,int slot) +{ + s->pci0_status_pending.up |= (1 << slot); +} +static void disable_device (PIIX4PMState *s,int slot) { s->gpe.sts |=PIIX4_PCI_HOTPLUG_STATUS ; s->pci0_status.down |= (1 << slot); } +static void pend_disable_device (PIIX4PMState *s,int slot) +{ + s->pci0_status_pending.down |= (1 << slot); +} +static int piix4_device_hotplug (DeviceState *qdev,PCIDevice *dev,PCIHotplugState state) {@@ -659,15 +688,23 @@ static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,return 0 ; } - s->pci0_status.up =0 ; - s->pci0_status.down =0 ; -if (state ==PCI_HOTPLUG_ENABLED ) { -enable_device (s, slot); +if (s->gpe.sts &PIIX4_PCI_HOTPLUG_STATUS ) { +if (state ==PCI_HOTPLUG_ENABLED ) { +pend_enable_device (s, slot); + }else { +pend_disable_device (s, slot); + } }else { -disable_device (s, slot); - } + s->pci0_status.up =0 ; + s->pci0_status.down =0 ; +if (state ==PCI_HOTPLUG_ENABLED ) { +enable_device (s, slot); + }else { +disable_device (s, slot); + } -pm_update_sci (s); +pm_update_sci (s); + }return 0 ; }Signature · 1 line
1.7.1Quoted 4 lines
Your patch adds a *second*
qdev_free(). No good.
Quoted 13 lines · Wen Congyang
At 03/01/2011 12:11 PM, Isaku Yamahata Write:
Quoted 5 lines
Hi.
I don't suppose that just introducing pending bits solve the issue. Your test only use single hot plug/unplug. How about mixing of multiple hot plug/unplug with different slots.
The qemu uses the same thread to deal with monitor command and I/O request from guest OS. So I think mixing of multiple hot plug/unplug with different slots can also work fine.
Quoted 2 lines
Zeroing up/down on
piix4_device_hotplug()is the culprit.
Quoted 7 lines
Quoted 3 lines
State machine of (up, down) would be needed. (up, down) of each slots should be changed following something like
Why we need this feature? We access
s->pci0_statusonly in main thread and do not accesss it when we deal with signal, so there is no competition to access it.
We are talking about losing interrupt and events, aren't we?
Not race caused by threads.
The issue is, Qemu injected sci interrupt into guest,
but before the guest completes to handled it,
users/qemu can start to inject the next sci event triggered by hot plug/unplug. Thus qemu loses sci interrupt and up/down status.
thanks
Quoted 359 lines
Quoted 358 lines
- on power-on (0, 0)
- on hot plug (0, 0) -> (1, 0)if other combination -> error- on hot unpug (1, 0) or (0, 0) -> (0, 1) (0, 0) is for cold plugged devices. (1, 0) is for hot plugged devices. if other combination -> error
- onpciej_write(write on PCI_EJ_BASE)(0, 1) -> (0, 0) and qdev_free() if other combination -> ignoreWhen enabling sci, those bits are checked and raise sci if necessary.
Any comments on this?
Anyway the current pci hotplug-related commands are somewhat broken, and needs clean up with multifunction hotplug support which is on my todo list.thanks
Quoted 334 lines · Wen Congyang
Hi Markus Armbruster
At 02/23/2011 04:30 PM, Markus Armbruster Write:
Quoted 2 lines
Isaku Yamahata <[email protected]> writes:
<snip>
Quoted 13 lines
I don't think this patch is correct. Let me explain.
Device hot unplug is *not* guaranteed to succeed.
For some buses, such as USB, it always succeeds immediately, i.e. when the
device_delmonitor command finishes, the device is gone. Live is good.But for PCI,
device_delmerely initiates the ACPI unplug rain dance. It doesn't wait for the dance to complete. Why? The dance can take an unpredictable amount of time, including forever.Quoted 7 lines
Problem: Subsequent
device_addcan fail if it reuses the qdev ID or PCI slot, and the unplug has not yet completed (race condition), or it failed. Yes, Virginia, PCI hotplug *can* fail.When unplug succeeds, the qdev is automatically destroyed.
pciej_write()does that for PIIX4. Looks likepcie_cap_slot_event()does it for PCIE.I got a similar problem. When I unplug a pci device by hand, it works as expected, and I can hotplug it again. But when I use a srcipt to do the same thing, sometimes it failed. I think I may find another bug.
Steps to reproduce this bug:
1. cat ./test-e1000.sh # RHEL6RC is domain name #!/bin/bashwhile true; do virsh attach-interface RHEL6RC network default --mac 52:54:00:1f:db:c7 --model e1000 if [[ $? -ne 0 ]]; then break fi virsh detach-interface RHEL6RC network --mac 52:54:00:1f:db:c7 if [[ $? -ne 0 ]]; then break fi sleep 5 done2. ./test-e1000.sh
Interface attached successfullyInterface detached successfully
Interface attached successfully
Interface detached successfully
error: Failed to attach interface
error: operation failed: adding e1000,netdev=hostnet1,id=net1,mac=52:54:00:1f:db:c7,bus=pci.0,addr=0x8 device failed: Duplicate ID 'net1' for deviceI use ftrace to trace whether sci interrupt is passed to guest OS, here is log:
# cat trace | grep 'irq=9' <idle>-0 [000] 118342.634772: irq_handler_entry: irq=9 name=acpi <idle>-0 [000] 118342.634831: irq_handler_exit: irq=9 ret=handled <idle>-0 [000] 118342.693216: irq_handler_entry: irq=9 name=acpi <idle>-0 [000] 118342.693254: irq_handler_exit: irq=9 ret=handled <idle>-0 [000] 118347.737689: irq_handler_entry: irq=9 name=acpi <idle>-0 [000] 118347.737738: irq_handler_exit: irq=9 ret=handled According to the log, we only receive 3 sci interrupt, and one is lost.I enable piix4's debug and 1 line printf into
piix4_device_hotplug:printf("slot: %d, up: %d, down: %d, state: %d\n", slot, s->pci0_status.up, s->pci0_status.down, state);here is the log:
========
PM: mapping to0xb000
PM readw port=0x0004 val=0x0000
...
gpe write afe2 <== 0
gpe write afe0 <== 255
gpe write afe3 <== 0
gpe write afe1 <== 255
PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0000
gpe read afe0 == 0
gpe read afe2 == 0
gpe read afe1 == 0
gpe read afe3 == 0
PM writew port=0x0000 val=0x0020
PM readw port=0x0002 val=0x0000
PM writew port=0x0002 val=0x0020
PM readw port=0x0002 val=0x0020
gpe write afe2 <== 255
gpe write afe3 <== 255
...
slot: 6, up: 0, down: 0, state: 1 <==== we attach interface the first time
PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 40
pcihotplug read ae04 == 0
...
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 6, up: 64, down: 0, state: 0 <===== we detach interface the first time PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 0
pcihotplug read ae04 == 40
...
pciej write ae08 <== 64 <=== we will callqdev_free()
pciej write ae08 <== 64
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 7, up: 0, down: 64, state: 1 <=== we attach interface the second time. PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
slot: 7, up: 128, down: 0, state: 0 <=== we detach interface the second time
gpe write afe0 <== 2 <=== write 2 to afe0 will cause sci interupt to be lost
gpe write afe2 <== 255
===========Here is short log, and show the different between the first time and second time:
===========
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 6, up: 64, down: 0, state: 0 <===== we detach interface the first time
....
slot: 7, up: 128, down: 0, state: 0 <=== we detach interface the second time
gpe write afe0 <== 2 <=== write 2 to afe0 will cause sci interupt to be lost
gpe write afe2 <== 255===========
Does this behavior is a normal behavior?
The following patch can fix this problem.
From
3c149575b52261b8da9a73d5c4ebdfedce9866c1Mon Sep 17 00:00:00 2001
From: Wen Congyang <[email protected]>
Date: Mon, 28 Feb 2011 10:33:45 +0800
Subject: [PATCH] pend hotplug event until last event is handled by guest OS--- hw/acpi_piix4.c | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 44 insertions(+), 7 deletions(-)hw/acpi_piix4.c +44
-7@@ -74,6 +74,7 @@ typedef struct PIIX4PMState {/* for pci hotplug */ struct gpe_regs gpe;struct pci_status pci0_status; +struct pci_status pci0_status_pending;uint32_t pci0_hotplug_enable; } PIIX4PMState;@@ -518,6 +519,19 @@ static void gpe_reset_val(uint16_t *cur, int addr, uint32_t val) *cur = (*cur & (0xff << (8 - shift))) | (x1 << shift); } +static void raise_pending_hotplug (PIIX4PMState *s) +{ +if (s->pci0_status_pending.up || s->pci0_status_pending.down) { + s->gpe.sts |=PIIX4_PCI_HOTPLUG_STATUS ; + s->pci0_status.up = s->pci0_status_pending.up; + s->pci0_status.down = s->pci0_status_pending.down; + s->pci0_status_pending.up =0 ; + s->pci0_status_pending.down =0 ; + +pm_update_sci (s); + } +} +static void gpe_writeb (void *opaque,uint32_t addr,uint32_t val) {PIIX4PMState *s = opaque;@@ -539,6 +553,11 @@ static void gpe_writeb(void *opaque, uint32_t addr, uint32_t val)pm_update_sci (s);PIIX4_DPRINTF ("gpe write %x <== %d\n" , addr, val); + +if (!(g->sts &PIIX4_PCI_HOTPLUG_STATUS ) && g->en &PIIX4_PCI_HOTPLUG_STATUS ) { +/* check and reraise the pending hotplug event */ +raise_pending_hotplug (s); + } }static uint32_t pcihotplug_read (void *opaque,uint32_t addr)@@ -639,12 +658,22 @@ static void enable_device(PIIX4PMState *s, int slot) s->pci0_status.up |= (1 << slot); } +static void pend_enable_device (PIIX4PMState *s,int slot) +{ + s->pci0_status_pending.up |= (1 << slot); +} +static void disable_device (PIIX4PMState *s,int slot) { s->gpe.sts |=PIIX4_PCI_HOTPLUG_STATUS ; s->pci0_status.down |= (1 << slot); } +static void pend_disable_device (PIIX4PMState *s,int slot) +{ + s->pci0_status_pending.down |= (1 << slot); +} +static int piix4_device_hotplug (DeviceState *qdev,PCIDevice *dev,PCIHotplugState state) {@@ -659,15 +688,23 @@ static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,return 0 ; } - s->pci0_status.up =0 ; - s->pci0_status.down =0 ; -if (state ==PCI_HOTPLUG_ENABLED ) { -enable_device (s, slot); +if (s->gpe.sts &PIIX4_PCI_HOTPLUG_STATUS ) { +if (state ==PCI_HOTPLUG_ENABLED ) { +pend_enable_device (s, slot); + }else { +pend_disable_device (s, slot); + } }else { -disable_device (s, slot); - } + s->pci0_status.up =0 ; + s->pci0_status.down =0 ; +if (state ==PCI_HOTPLUG_ENABLED ) { +enable_device (s, slot); + }else { +disable_device (s, slot); + } -pm_update_sci (s); +pm_update_sci (s); + }return 0 ; }Signature · 1 line
1.7.1Quoted 4 lines
Your patch adds a *second*
qdev_free(). No good.
Signature · 1 line
yamahata
At 03/01/2011 03:13 PM, Isaku Yamahata Write:
Quoted 18 lines · Wen Congyang
Quoted 17 lines
At 03/01/2011 12:11 PM, Isaku Yamahata Write:
Quoted 5 lines
Hi.
I don't suppose that just introducing pending bits solve the issue. Your test only use single hot plug/unplug. How about mixing of multiple hot plug/unplug with different slots.
The qemu uses the same thread to deal with monitor command and I/O request from guest OS. So I think mixing of multiple hot plug/unplug with different slots can also work fine.
Quoted 5 lines
Zeroing up/down on
piix4_device_hotplug()is the culprit.State machine of (up, down) would be needed. (up, down) of each slots should be changed following something like
Quoted 6 lines
Quoted 3 lines
Why we need this feature? We access
s->pci0_statusonly in main thread and do not accesss it when we deal with signal, so there is no competition to access it.We are talking about losing interrupt and events, aren't we? Not race caused by threads.
I am sorry, I do not understand what you are talk about.
Quoted 4 lines
The issue is, Qemu injected sci interrupt into guest,
but before the guest completes to handled it,
users/qemu can start to inject the next sci event triggered by hot plug/unplug. Thus qemu loses sci interrupt and up/down status.
Yes, you are right. But I still do not understand why introducing pending bits can not solve the issue?
Thanks
Wen Congyang
Quoted 362 lines
thanks
Quoted 359 lines
Quoted 358 lines
- on power-on (0, 0)
- on hot plug (0, 0) -> (1, 0)if other combination -> error- on hot unpug (1, 0) or (0, 0) -> (0, 1) (0, 0) is for cold plugged devices. (1, 0) is for hot plugged devices. if other combination -> error
- onpciej_write(write on PCI_EJ_BASE)(0, 1) -> (0, 0) and qdev_free() if other combination -> ignoreWhen enabling sci, those bits are checked and raise sci if necessary.
Any comments on this?
Anyway the current pci hotplug-related commands are somewhat broken, and needs clean up with multifunction hotplug support which is on my todo list.thanks
Quoted 334 lines · Wen Congyang
Hi Markus Armbruster
At 02/23/2011 04:30 PM, Markus Armbruster Write:
Quoted 2 lines
Isaku Yamahata <[email protected]> writes:
<snip>
Quoted 13 lines
I don't think this patch is correct. Let me explain.
Device hot unplug is *not* guaranteed to succeed.
For some buses, such as USB, it always succeeds immediately, i.e. when the
device_delmonitor command finishes, the device is gone. Live is good.But for PCI,
device_delmerely initiates the ACPI unplug rain dance. It doesn't wait for the dance to complete. Why? The dance can take an unpredictable amount of time, including forever.Quoted 7 lines
Problem: Subsequent
device_addcan fail if it reuses the qdev ID or PCI slot, and the unplug has not yet completed (race condition), or it failed. Yes, Virginia, PCI hotplug *can* fail.When unplug succeeds, the qdev is automatically destroyed.
pciej_write()does that for PIIX4. Looks likepcie_cap_slot_event()does it for PCIE.I got a similar problem. When I unplug a pci device by hand, it works as expected, and I can hotplug it again. But when I use a srcipt to do the same thing, sometimes it failed. I think I may find another bug.
Steps to reproduce this bug:
1. cat ./test-e1000.sh # RHEL6RC is domain name #!/bin/bashwhile true; do virsh attach-interface RHEL6RC network default --mac 52:54:00:1f:db:c7 --model e1000 if [[ $? -ne 0 ]]; then break fi virsh detach-interface RHEL6RC network --mac 52:54:00:1f:db:c7 if [[ $? -ne 0 ]]; then break fi sleep 5 done2. ./test-e1000.sh
Interface attached successfullyInterface detached successfully
Interface attached successfully
Interface detached successfully
error: Failed to attach interface
error: operation failed: adding e1000,netdev=hostnet1,id=net1,mac=52:54:00:1f:db:c7,bus=pci.0,addr=0x8 device failed: Duplicate ID 'net1' for deviceI use ftrace to trace whether sci interrupt is passed to guest OS, here is log:
# cat trace | grep 'irq=9' <idle>-0 [000] 118342.634772: irq_handler_entry: irq=9 name=acpi <idle>-0 [000] 118342.634831: irq_handler_exit: irq=9 ret=handled <idle>-0 [000] 118342.693216: irq_handler_entry: irq=9 name=acpi <idle>-0 [000] 118342.693254: irq_handler_exit: irq=9 ret=handled <idle>-0 [000] 118347.737689: irq_handler_entry: irq=9 name=acpi <idle>-0 [000] 118347.737738: irq_handler_exit: irq=9 ret=handled According to the log, we only receive 3 sci interrupt, and one is lost.I enable piix4's debug and 1 line printf into
piix4_device_hotplug:printf("slot: %d, up: %d, down: %d, state: %d\n", slot, s->pci0_status.up, s->pci0_status.down, state);here is the log:
========
PM: mapping to0xb000
PM readw port=0x0004 val=0x0000
...
gpe write afe2 <== 0
gpe write afe0 <== 255
gpe write afe3 <== 0
gpe write afe1 <== 255
PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0000
gpe read afe0 == 0
gpe read afe2 == 0
gpe read afe1 == 0
gpe read afe3 == 0
PM writew port=0x0000 val=0x0020
PM readw port=0x0002 val=0x0000
PM writew port=0x0002 val=0x0020
PM readw port=0x0002 val=0x0020
gpe write afe2 <== 255
gpe write afe3 <== 255
...
slot: 6, up: 0, down: 0, state: 1 <==== we attach interface the first time
PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 40
pcihotplug read ae04 == 0
...
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 6, up: 64, down: 0, state: 0 <===== we detach interface the first time PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 0
pcihotplug read ae04 == 40
...
pciej write ae08 <== 64 <=== we will callqdev_free()
pciej write ae08 <== 64
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 7, up: 0, down: 64, state: 1 <=== we attach interface the second time. PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
slot: 7, up: 128, down: 0, state: 0 <=== we detach interface the second time
gpe write afe0 <== 2 <=== write 2 to afe0 will cause sci interupt to be lost
gpe write afe2 <== 255
===========Here is short log, and show the different between the first time and second time:
===========
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 6, up: 64, down: 0, state: 0 <===== we detach interface the first time
....
slot: 7, up: 128, down: 0, state: 0 <=== we detach interface the second time
gpe write afe0 <== 2 <=== write 2 to afe0 will cause sci interupt to be lost
gpe write afe2 <== 255===========
Does this behavior is a normal behavior?
The following patch can fix this problem.
From
3c149575b52261b8da9a73d5c4ebdfedce9866c1Mon Sep 17 00:00:00 2001
From: Wen Congyang <[email protected]>
Date: Mon, 28 Feb 2011 10:33:45 +0800
Subject: [PATCH] pend hotplug event until last event is handled by guest OS--- hw/acpi_piix4.c | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 44 insertions(+), 7 deletions(-)hw/acpi_piix4.c +44
-7@@ -74,6 +74,7 @@ typedef struct PIIX4PMState {/* for pci hotplug */ struct gpe_regs gpe;struct pci_status pci0_status; +struct pci_status pci0_status_pending;uint32_t pci0_hotplug_enable; } PIIX4PMState;@@ -518,6 +519,19 @@ static void gpe_reset_val(uint16_t *cur, int addr, uint32_t val) *cur = (*cur & (0xff << (8 - shift))) | (x1 << shift); } +static void raise_pending_hotplug (PIIX4PMState *s) +{ +if (s->pci0_status_pending.up || s->pci0_status_pending.down) { + s->gpe.sts |=PIIX4_PCI_HOTPLUG_STATUS ; + s->pci0_status.up = s->pci0_status_pending.up; + s->pci0_status.down = s->pci0_status_pending.down; + s->pci0_status_pending.up =0 ; + s->pci0_status_pending.down =0 ; + +pm_update_sci (s); + } +} +static void gpe_writeb (void *opaque,uint32_t addr,uint32_t val) {PIIX4PMState *s = opaque;@@ -539,6 +553,11 @@ static void gpe_writeb(void *opaque, uint32_t addr, uint32_t val)pm_update_sci (s);PIIX4_DPRINTF ("gpe write %x <== %d\n" , addr, val); + +if (!(g->sts &PIIX4_PCI_HOTPLUG_STATUS ) && g->en &PIIX4_PCI_HOTPLUG_STATUS ) { +/* check and reraise the pending hotplug event */ +raise_pending_hotplug (s); + } }static uint32_t pcihotplug_read (void *opaque,uint32_t addr)@@ -639,12 +658,22 @@ static void enable_device(PIIX4PMState *s, int slot) s->pci0_status.up |= (1 << slot); } +static void pend_enable_device (PIIX4PMState *s,int slot) +{ + s->pci0_status_pending.up |= (1 << slot); +} +static void disable_device (PIIX4PMState *s,int slot) { s->gpe.sts |=PIIX4_PCI_HOTPLUG_STATUS ; s->pci0_status.down |= (1 << slot); } +static void pend_disable_device (PIIX4PMState *s,int slot) +{ + s->pci0_status_pending.down |= (1 << slot); +} +static int piix4_device_hotplug (DeviceState *qdev,PCIDevice *dev,PCIHotplugState state) {@@ -659,15 +688,23 @@ static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,return 0 ; } - s->pci0_status.up =0 ; - s->pci0_status.down =0 ; -if (state ==PCI_HOTPLUG_ENABLED ) { -enable_device (s, slot); +if (s->gpe.sts &PIIX4_PCI_HOTPLUG_STATUS ) { +if (state ==PCI_HOTPLUG_ENABLED ) { +pend_enable_device (s, slot); + }else { +pend_disable_device (s, slot); + } }else { -disable_device (s, slot); - } + s->pci0_status.up =0 ; + s->pci0_status.down =0 ; +if (state ==PCI_HOTPLUG_ENABLED ) { +enable_device (s, slot); + }else { +disable_device (s, slot); + } -pm_update_sci (s); +pm_update_sci (s); + }return 0 ; }Signature · 1 line
1.7.1Quoted 4 lines
Your patch adds a *second*
qdev_free(). No good.
Quoted 7 lines · Wen Congyang
Quoted 4 lines
The issue is, Qemu injected sci interrupt into guest,
but before the guest completes to handled it,
users/qemu can start to inject the next sci event triggered by hot plug/unplug. Thus qemu loses sci interrupt and up/down status.Yes, you are right. But I still do not understand why introducing pending bits can not solve the issue?
Maybe your patch works.
The difference is to introduce new variables or new state machine.
Anyway I suppose that the eventual solution is to switch to express native hotplug which is much more reliable and doesn't rely on ACPI. (note: I'm very biased here.)
thanks
Quoted 367 lines
Thanks
Wen CongyangQuoted 362 lines
thanks
Quoted 359 lines
Quoted 358 lines
- on power-on (0, 0)
- on hot plug (0, 0) -> (1, 0)if other combination -> error- on hot unpug (1, 0) or (0, 0) -> (0, 1) (0, 0) is for cold plugged devices. (1, 0) is for hot plugged devices. if other combination -> error
- onpciej_write(write on PCI_EJ_BASE)(0, 1) -> (0, 0) and qdev_free() if other combination -> ignoreWhen enabling sci, those bits are checked and raise sci if necessary.
Any comments on this?
Anyway the current pci hotplug-related commands are somewhat broken, and needs clean up with multifunction hotplug support which is on my todo list.thanks
Quoted 334 lines · Wen Congyang
Hi Markus Armbruster
At 02/23/2011 04:30 PM, Markus Armbruster Write:
Quoted 2 lines
Isaku Yamahata <[email protected]> writes:
<snip>
Quoted 13 lines
I don't think this patch is correct. Let me explain.
Device hot unplug is *not* guaranteed to succeed.
For some buses, such as USB, it always succeeds immediately, i.e. when the
device_delmonitor command finishes, the device is gone. Live is good.But for PCI,
device_delmerely initiates the ACPI unplug rain dance. It doesn't wait for the dance to complete. Why? The dance can take an unpredictable amount of time, including forever.Quoted 7 lines
Problem: Subsequent
device_addcan fail if it reuses the qdev ID or PCI slot, and the unplug has not yet completed (race condition), or it failed. Yes, Virginia, PCI hotplug *can* fail.When unplug succeeds, the qdev is automatically destroyed.
pciej_write()does that for PIIX4. Looks likepcie_cap_slot_event()does it for PCIE.I got a similar problem. When I unplug a pci device by hand, it works as expected, and I can hotplug it again. But when I use a srcipt to do the same thing, sometimes it failed. I think I may find another bug.
Steps to reproduce this bug:
1. cat ./test-e1000.sh # RHEL6RC is domain name #!/bin/bashwhile true; do virsh attach-interface RHEL6RC network default --mac 52:54:00:1f:db:c7 --model e1000 if [[ $? -ne 0 ]]; then break fi virsh detach-interface RHEL6RC network --mac 52:54:00:1f:db:c7 if [[ $? -ne 0 ]]; then break fi sleep 5 done2. ./test-e1000.sh
Interface attached successfullyInterface detached successfully
Interface attached successfully
Interface detached successfully
error: Failed to attach interface
error: operation failed: adding e1000,netdev=hostnet1,id=net1,mac=52:54:00:1f:db:c7,bus=pci.0,addr=0x8 device failed: Duplicate ID 'net1' for deviceI use ftrace to trace whether sci interrupt is passed to guest OS, here is log:
# cat trace | grep 'irq=9' <idle>-0 [000] 118342.634772: irq_handler_entry: irq=9 name=acpi <idle>-0 [000] 118342.634831: irq_handler_exit: irq=9 ret=handled <idle>-0 [000] 118342.693216: irq_handler_entry: irq=9 name=acpi <idle>-0 [000] 118342.693254: irq_handler_exit: irq=9 ret=handled <idle>-0 [000] 118347.737689: irq_handler_entry: irq=9 name=acpi <idle>-0 [000] 118347.737738: irq_handler_exit: irq=9 ret=handled According to the log, we only receive 3 sci interrupt, and one is lost.I enable piix4's debug and 1 line printf into
piix4_device_hotplug:printf("slot: %d, up: %d, down: %d, state: %d\n", slot, s->pci0_status.up, s->pci0_status.down, state);here is the log:
========
PM: mapping to0xb000
PM readw port=0x0004 val=0x0000
...
gpe write afe2 <== 0
gpe write afe0 <== 255
gpe write afe3 <== 0
gpe write afe1 <== 255
PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0000
gpe read afe0 == 0
gpe read afe2 == 0
gpe read afe1 == 0
gpe read afe3 == 0
PM writew port=0x0000 val=0x0020
PM readw port=0x0002 val=0x0000
PM writew port=0x0002 val=0x0020
PM readw port=0x0002 val=0x0020
gpe write afe2 <== 255
gpe write afe3 <== 255
...
slot: 6, up: 0, down: 0, state: 1 <==== we attach interface the first time
PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 40
pcihotplug read ae04 == 0
...
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 6, up: 64, down: 0, state: 0 <===== we detach interface the first time PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 0
pcihotplug read ae04 == 40
...
pciej write ae08 <== 64 <=== we will callqdev_free()
pciej write ae08 <== 64
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 7, up: 0, down: 64, state: 1 <=== we attach interface the second time. PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
slot: 7, up: 128, down: 0, state: 0 <=== we detach interface the second time
gpe write afe0 <== 2 <=== write 2 to afe0 will cause sci interupt to be lost
gpe write afe2 <== 255
===========Here is short log, and show the different between the first time and second time:
===========
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 6, up: 64, down: 0, state: 0 <===== we detach interface the first time
....
slot: 7, up: 128, down: 0, state: 0 <=== we detach interface the second time
gpe write afe0 <== 2 <=== write 2 to afe0 will cause sci interupt to be lost
gpe write afe2 <== 255===========
Does this behavior is a normal behavior?
The following patch can fix this problem.
From
3c149575b52261b8da9a73d5c4ebdfedce9866c1Mon Sep 17 00:00:00 2001
From: Wen Congyang <[email protected]>
Date: Mon, 28 Feb 2011 10:33:45 +0800
Subject: [PATCH] pend hotplug event until last event is handled by guest OS--- hw/acpi_piix4.c | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 44 insertions(+), 7 deletions(-)hw/acpi_piix4.c +44
-7@@ -74,6 +74,7 @@ typedef struct PIIX4PMState {/* for pci hotplug */ struct gpe_regs gpe;struct pci_status pci0_status; +struct pci_status pci0_status_pending;uint32_t pci0_hotplug_enable; } PIIX4PMState;@@ -518,6 +519,19 @@ static void gpe_reset_val(uint16_t *cur, int addr, uint32_t val) *cur = (*cur & (0xff << (8 - shift))) | (x1 << shift); } +static void raise_pending_hotplug (PIIX4PMState *s) +{ +if (s->pci0_status_pending.up || s->pci0_status_pending.down) { + s->gpe.sts |=PIIX4_PCI_HOTPLUG_STATUS ; + s->pci0_status.up = s->pci0_status_pending.up; + s->pci0_status.down = s->pci0_status_pending.down; + s->pci0_status_pending.up =0 ; + s->pci0_status_pending.down =0 ; + +pm_update_sci (s); + } +} +static void gpe_writeb (void *opaque,uint32_t addr,uint32_t val) {PIIX4PMState *s = opaque;@@ -539,6 +553,11 @@ static void gpe_writeb(void *opaque, uint32_t addr, uint32_t val)pm_update_sci (s);PIIX4_DPRINTF ("gpe write %x <== %d\n" , addr, val); + +if (!(g->sts &PIIX4_PCI_HOTPLUG_STATUS ) && g->en &PIIX4_PCI_HOTPLUG_STATUS ) { +/* check and reraise the pending hotplug event */ +raise_pending_hotplug (s); + } }static uint32_t pcihotplug_read (void *opaque,uint32_t addr)@@ -639,12 +658,22 @@ static void enable_device(PIIX4PMState *s, int slot) s->pci0_status.up |= (1 << slot); } +static void pend_enable_device (PIIX4PMState *s,int slot) +{ + s->pci0_status_pending.up |= (1 << slot); +} +static void disable_device (PIIX4PMState *s,int slot) { s->gpe.sts |=PIIX4_PCI_HOTPLUG_STATUS ; s->pci0_status.down |= (1 << slot); } +static void pend_disable_device (PIIX4PMState *s,int slot) +{ + s->pci0_status_pending.down |= (1 << slot); +} +static int piix4_device_hotplug (DeviceState *qdev,PCIDevice *dev,PCIHotplugState state) {@@ -659,15 +688,23 @@ static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,return 0 ; } - s->pci0_status.up =0 ; - s->pci0_status.down =0 ; -if (state ==PCI_HOTPLUG_ENABLED ) { -enable_device (s, slot); +if (s->gpe.sts &PIIX4_PCI_HOTPLUG_STATUS ) { +if (state ==PCI_HOTPLUG_ENABLED ) { +pend_enable_device (s, slot); + }else { +pend_disable_device (s, slot); + } }else { -disable_device (s, slot); - } + s->pci0_status.up =0 ; + s->pci0_status.down =0 ; +if (state ==PCI_HOTPLUG_ENABLED ) { +enable_device (s, slot); + }else { +disable_device (s, slot); + } -pm_update_sci (s); +pm_update_sci (s); + }return 0 ; }Signature · 1 line
1.7.1Quoted 4 lines
Your patch adds a *second*
qdev_free(). No good.
Signature · 1 line
yamahata
Quoted 37 lines · Wen Congyang
Hi Markus Armbruster
At 02/23/2011 04:30 PM, Markus Armbruster Write:
Quoted 2 lines
Isaku Yamahata <[email protected]> writes:
<snip>
Quoted 13 lines
I don't think this patch is correct. Let me explain.
Device hot unplug is *not* guaranteed to succeed.
For some buses, such as USB, it always succeeds immediately, i.e. when the
device_delmonitor command finishes, the device is gone. Live is good.But for PCI,
device_delmerely initiates the ACPI unplug rain dance. It doesn't wait for the dance to complete. Why? The dance can take an unpredictable amount of time, including forever.Quoted 7 lines
Problem: Subsequent
device_addcan fail if it reuses the qdev ID or PCI slot, and the unplug has not yet completed (race condition), or it failed. Yes, Virginia, PCI hotplug *can* fail.When unplug succeeds, the qdev is automatically destroyed.
pciej_write()does that for PIIX4. Looks likepcie_cap_slot_event()does it for PCIE.I got a similar problem. When I unplug a pci device by hand, it works as expected, and I can hotplug it again. But when I use a srcipt to do the same thing, sometimes it failed. I think I may find another bug.
Steps to reproduce this bug:
1. cat ./test-e1000.sh # RHEL6RC is domain name #!/bin/bash
Quoted 10 lines
while true; do
virsh attach-interface RHEL6RC network default --mac 52:54:00:1f:db:c7 --model e1000
if [[ $? -ne 0 ]]; then
break
fi
virsh detach-interface RHEL6RC network --mac 52:54:00:1f:db:c7
if [[ $? -ne 0 ]]; then
break
fi
sleep 5How do you know that the guest has responded at this point before you attempt to attach again at the top of the loop. Any attach/detach requires the guest to respond to the request and it may not respond at all.
Quoted 286 lines
done
2. ./test-e1000.sh
Interface attached successfullyInterface detached successfully
Interface attached successfully
Interface detached successfully
error: Failed to attach interface
error: operation failed: adding e1000,netdev=hostnet1,id=net1,mac=52:54:00:1f:db:c7,bus=pci.0,addr=0x8 device failed: Duplicate ID 'net1' for deviceI use ftrace to trace whether sci interrupt is passed to guest OS, here is log:
# cat trace | grep 'irq=9' <idle>-0 [000] 118342.634772: irq_handler_entry: irq=9 name=acpi <idle>-0 [000] 118342.634831: irq_handler_exit: irq=9 ret=handled <idle>-0 [000] 118342.693216: irq_handler_entry: irq=9 name=acpi <idle>-0 [000] 118342.693254: irq_handler_exit: irq=9 ret=handled <idle>-0 [000] 118347.737689: irq_handler_entry: irq=9 name=acpi <idle>-0 [000] 118347.737738: irq_handler_exit: irq=9 ret=handled According to the log, we only receive 3 sci interrupt, and one is lost.I enable piix4's debug and 1 line printf into
piix4_device_hotplug:printf("slot: %d, up: %d, down: %d, state: %d\n", slot, s->pci0_status.up, s->pci0_status.down, state);here is the log:
========
PM: mapping to0xb000
PM readw port=0x0004 val=0x0000
...
gpe write afe2 <== 0
gpe write afe0 <== 255
gpe write afe3 <== 0
gpe write afe1 <== 255
PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0000
gpe read afe0 == 0
gpe read afe2 == 0
gpe read afe1 == 0
gpe read afe3 == 0
PM writew port=0x0000 val=0x0020
PM readw port=0x0002 val=0x0000
PM writew port=0x0002 val=0x0020
PM readw port=0x0002 val=0x0020
gpe write afe2 <== 255
gpe write afe3 <== 255
...
slot: 6, up: 0, down: 0, state: 1 <==== we attach interface the first time
PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 40
pcihotplug read ae04 == 0
...
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 6, up: 64, down: 0, state: 0 <===== we detach interface the first time PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 0
pcihotplug read ae04 == 40
...
pciej write ae08 <== 64 <=== we will callqdev_free()
pciej write ae08 <== 64
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 7, up: 0, down: 64, state: 1 <=== we attach interface the second time. PM readw port=0x0000 val=0x0001
PM readw port=0x0002 val=0x0120
gpe read afe0 == 2
gpe read afe2 == ff
gpe read afe2 == ff
gpe write afe2 <== 253
gpe read afe1 == 0
gpe read afe3 == ff
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
pcihotplug read ae00 == 80
pcihotplug read ae04 == 0
slot: 7, up: 128, down: 0, state: 0 <=== we detach interface the second time
gpe write afe0 <== 2 <=== write 2 to afe0 will cause sci interupt to be lost
gpe write afe2 <== 255
===========Here is short log, and show the different between the first time and second time:
===========
gpe write afe0 <== 2
gpe write afe2 <== 255
slot: 6, up: 64, down: 0, state: 0 <===== we detach interface the first time
....
slot: 7, up: 128, down: 0, state: 0 <=== we detach interface the second time
gpe write afe0 <== 2 <=== write 2 to afe0 will cause sci interupt to be lost
gpe write afe2 <== 255===========
Does this behavior is a normal behavior?
The following patch can fix this problem.
Quoted 1 line
From
3c149575b52261b8da9a73d5c4ebdfedce9866c1Mon Sep 17 00:00:00 2001From: Wen Congyang <[email protected]>
Date: Mon, 28 Feb 2011 10:33:45 +0800
Subject: [PATCH] pend hotplug event until last event is handled by guest OS--- hw/acpi_piix4.c | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 44 insertions(+), 7 deletions(-)hw/acpi_piix4.c +44
-7@@ -74,6 +74,7 @@ typedef struct PIIX4PMState {/* for pci hotplug */ struct gpe_regs gpe;struct pci_status pci0_status; +struct pci_status pci0_status_pending;uint32_t pci0_hotplug_enable; } PIIX4PMState;@@ -518,6 +519,19 @@ static void gpe_reset_val(uint16_t *cur, int addr, uint32_t val) *cur = (*cur & (0xff << (8 - shift))) | (x1 << shift); } +static void raise_pending_hotplug (PIIX4PMState *s) +{ +if (s->pci0_status_pending.up || s->pci0_status_pending.down) { + s->gpe.sts |=PIIX4_PCI_HOTPLUG_STATUS ; + s->pci0_status.up = s->pci0_status_pending.up; + s->pci0_status.down = s->pci0_status_pending.down; + s->pci0_status_pending.up =0 ; + s->pci0_status_pending.down =0 ; + +pm_update_sci (s); + } +} +static void gpe_writeb (void *opaque,uint32_t addr,uint32_t val) {PIIX4PMState *s = opaque;@@ -539,6 +553,11 @@ static void gpe_writeb(void *opaque, uint32_t addr, uint32_t val)pm_update_sci (s);PIIX4_DPRINTF ("gpe write %x <== %d\n" , addr, val); + +if (!(g->sts &PIIX4_PCI_HOTPLUG_STATUS ) && g->en &PIIX4_PCI_HOTPLUG_STATUS ) { +/* check and reraise the pending hotplug event */ +raise_pending_hotplug (s); + } }static uint32_t pcihotplug_read (void *opaque,uint32_t addr)@@ -639,12 +658,22 @@ static void enable_device(PIIX4PMState *s, int slot) s->pci0_status.up |= (1 << slot); } +static void pend_enable_device (PIIX4PMState *s,int slot) +{ + s->pci0_status_pending.up |= (1 << slot); +} +static void disable_device (PIIX4PMState *s,int slot) { s->gpe.sts |=PIIX4_PCI_HOTPLUG_STATUS ; s->pci0_status.down |= (1 << slot); } +static void pend_disable_device (PIIX4PMState *s,int slot) +{ + s->pci0_status_pending.down |= (1 << slot); +} +static int piix4_device_hotplug (DeviceState *qdev,PCIDevice *dev,PCIHotplugState state) {@@ -659,15 +688,23 @@ static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,return 0 ; } - s->pci0_status.up =0 ; - s->pci0_status.down =0 ; -if (state ==PCI_HOTPLUG_ENABLED ) { -enable_device (s, slot); +if (s->gpe.sts &PIIX4_PCI_HOTPLUG_STATUS ) { +if (state ==PCI_HOTPLUG_ENABLED ) { +pend_enable_device (s, slot); + }else { +pend_disable_device (s, slot); + } }else { -disable_device (s, slot); - } + s->pci0_status.up =0 ; + s->pci0_status.down =0 ; +if (state ==PCI_HOTPLUG_ENABLED ) { +enable_device (s, slot); + }else { +disable_device (s, slot); + } -pm_update_sci (s); +pm_update_sci (s); + }return 0 ; }Signature · 1 line
1.7.1Quoted 4 lines
Your patch adds a *second*
qdev_free(). No good.
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
At 03/09/2011 12:08 PM, Ryan Harper Write:
Quoted 49 lines · Wen Congyang
Quoted 37 lines
Hi Markus Armbruster
At 02/23/2011 04:30 PM, Markus Armbruster Write:
Quoted 2 lines
Isaku Yamahata <[email protected]> writes:
<snip>
Quoted 13 lines
I don't think this patch is correct. Let me explain.
Device hot unplug is *not* guaranteed to succeed.
For some buses, such as USB, it always succeeds immediately, i.e. when the
device_delmonitor command finishes, the device is gone. Live is good.But for PCI,
device_delmerely initiates the ACPI unplug rain dance. It doesn't wait for the dance to complete. Why? The dance can take an unpredictable amount of time, including forever.Quoted 7 lines
Problem: Subsequent
device_addcan fail if it reuses the qdev ID or PCI slot, and the unplug has not yet completed (race condition), or it failed. Yes, Virginia, PCI hotplug *can* fail.When unplug succeeds, the qdev is automatically destroyed.
pciej_write()does that for PIIX4. Looks likepcie_cap_slot_event()does it for PCIE.I got a similar problem. When I unplug a pci device by hand, it works as expected, and I can hotplug it again. But when I use a srcipt to do the same thing, sometimes it failed. I think I may find another bug.
Steps to reproduce this bug:
1. cat ./test-e1000.sh # RHEL6RC is domain name
#!/bin/bashQuoted 10 lines
while true; do virsh attach-interface RHEL6RC network default --mac 52:54:00:1f:db:c7 --model e1000 if [[ $? -ne 0 ]]; then break fi virsh detach-interface RHEL6RC network --mac 52:54:00:1f:db:c7 if [[ $? -ne 0 ]]; then break fi sleep 5
Quoted 4 lines
How do you know that the guest has responded at this point before you attempt to attach again at the top of the loop. Any attach/detach requires the guest to respond to the request and it may not respond at all.
When I attach/detach interface by hand, it works fine: I can see the new interface when I attach it, and it disapears when I detached it.
Quoted 2 lines
Quoted 50 lines · Wen Congyang
At 03/09/2011 12:08 PM, Ryan Harper Write:
Quoted 49 lines · Wen Congyang
Quoted 47 lines
Hi Markus Armbruster
At 02/23/2011 04:30 PM, Markus Armbruster Write:
Quoted 2 lines
Isaku Yamahata <[email protected]> writes:
<snip>
Quoted 13 lines
I don't think this patch is correct. Let me explain.
Device hot unplug is *not* guaranteed to succeed.
For some buses, such as USB, it always succeeds immediately, i.e. when the
device_delmonitor command finishes, the device is gone. Live is good.But for PCI,
device_delmerely initiates the ACPI unplug rain dance. It doesn't wait for the dance to complete. Why? The dance can take an unpredictable amount of time, including forever.Quoted 7 lines
Problem: Subsequent
device_addcan fail if it reuses the qdev ID or PCI slot, and the unplug has not yet completed (race condition), or it failed. Yes, Virginia, PCI hotplug *can* fail.When unplug succeeds, the qdev is automatically destroyed.
pciej_write()does that for PIIX4. Looks likepcie_cap_slot_event()does it for PCIE.I got a similar problem. When I unplug a pci device by hand, it works as expected, and I can hotplug it again. But when I use a srcipt to do the same thing, sometimes it failed. I think I may find another bug.
Steps to reproduce this bug:
1. cat ./test-e1000.sh # RHEL6RC is domain name
#!/bin/bashwhile true; do virsh attach-interface RHEL6RC network default --mac 52:54:00:1f:db:c7 --model e1000 if [[ $? -ne 0 ]]; then break fi virsh detach-interface RHEL6RC network --mac 52:54:00:1f:db:c7 if [[ $? -ne 0 ]]; then break fi sleep 5
Quoted 7 lines
Quoted 4 lines
How do you know that the guest has responded at this point before you attempt to attach again at the top of the loop. Any attach/detach requires the guest to respond to the request and it may not respond at all.
When I attach/detach interface by hand, it works fine: I can see the new interface when I attach it, and it disapears when I detached it.
The point is that since the attach and detach require guest participation, this interface isn't reliable. You have a sleep 5 in your loop, hoping to wait long enough for the guest to respond, but after a number of iterations in your loop it fails, you can bump the sleep to to 3600 seconds and the guest *still* might not respond...
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
At 03/09/2011 02:12 PM, Ryan Harper Write:
Quoted 56 lines · Wen Congyang
Quoted 55 lines
At 03/09/2011 12:08 PM, Ryan Harper Write:
Quoted 53 lines · Wen Congyang
Quoted 37 lines
Hi Markus Armbruster
At 02/23/2011 04:30 PM, Markus Armbruster Write:
Quoted 2 lines
Isaku Yamahata <[email protected]> writes:
<snip>
Quoted 13 lines
I don't think this patch is correct. Let me explain.
Device hot unplug is *not* guaranteed to succeed.
For some buses, such as USB, it always succeeds immediately, i.e. when the
device_delmonitor command finishes, the device is gone. Live is good.But for PCI,
device_delmerely initiates the ACPI unplug rain dance. It doesn't wait for the dance to complete. Why? The dance can take an unpredictable amount of time, including forever.Quoted 7 lines
Problem: Subsequent
device_addcan fail if it reuses the qdev ID or PCI slot, and the unplug has not yet completed (race condition), or it failed. Yes, Virginia, PCI hotplug *can* fail.When unplug succeeds, the qdev is automatically destroyed.
pciej_write()does that for PIIX4. Looks likepcie_cap_slot_event()does it for PCIE.I got a similar problem. When I unplug a pci device by hand, it works as expected, and I can hotplug it again. But when I use a srcipt to do the same thing, sometimes it failed. I think I may find another bug.
Steps to reproduce this bug:
1. cat ./test-e1000.sh # RHEL6RC is domain name
#!/bin/bashQuoted 10 lines
while true; do virsh attach-interface RHEL6RC network default --mac 52:54:00:1f:db:c7 --model e1000 if [[ $? -ne 0 ]]; then break fi virsh detach-interface RHEL6RC network --mac 52:54:00:1f:db:c7 if [[ $? -ne 0 ]]; then break fi sleep 5How do you know that the guest has responded at this point before you attempt to attach again at the top of the loop. Any attach/detach requires the guest to respond to the request and it may not respond at all.
Quoted 8 lines
Quoted 2 lines
When I attach/detach interface by hand, it works fine: I can see the new interface when I attach it, and it disapears when I detached it.
The point is that since the attach and detach require guest participation, this interface isn't reliable. You have a sleep 5 in your loop, hoping to wait long enough for the guest to respond, but after a number of iterations in your loop it fails, you can bump the sleep to to 3600 seconds and the guest *still* might not respond...
We use sci interrupt to tell the guest that a device has been attached/detached. But the sci interrupt is *lost* in qemu, so the guest does not know a device has been attached/detached, and does not respond it.
If the sci interrupt is not lost, the guest can respond it.
Quoted 2 lines
Quoted 66 lines · Wen Congyang
At 03/09/2011 02:12 PM, Ryan Harper Write:
Quoted 56 lines · Wen Congyang
Quoted 55 lines
At 03/09/2011 12:08 PM, Ryan Harper Write:
Quoted 53 lines · Wen Congyang
Quoted 37 lines
Hi Markus Armbruster
At 02/23/2011 04:30 PM, Markus Armbruster Write:
Quoted 2 lines
Isaku Yamahata <[email protected]> writes:
<snip>
Quoted 13 lines
I don't think this patch is correct. Let me explain.
Device hot unplug is *not* guaranteed to succeed.
For some buses, such as USB, it always succeeds immediately, i.e. when the
device_delmonitor command finishes, the device is gone. Live is good.But for PCI,
device_delmerely initiates the ACPI unplug rain dance. It doesn't wait for the dance to complete. Why? The dance can take an unpredictable amount of time, including forever.Quoted 7 lines
Problem: Subsequent
device_addcan fail if it reuses the qdev ID or PCI slot, and the unplug has not yet completed (race condition), or it failed. Yes, Virginia, PCI hotplug *can* fail.When unplug succeeds, the qdev is automatically destroyed.
pciej_write()does that for PIIX4. Looks likepcie_cap_slot_event()does it for PCIE.I got a similar problem. When I unplug a pci device by hand, it works as expected, and I can hotplug it again. But when I use a srcipt to do the same thing, sometimes it failed. I think I may find another bug.
Steps to reproduce this bug:
1. cat ./test-e1000.sh # RHEL6RC is domain name
#!/bin/bashQuoted 10 lines
while true; do virsh attach-interface RHEL6RC network default --mac 52:54:00:1f:db:c7 --model e1000 if [[ $? -ne 0 ]]; then break fi virsh detach-interface RHEL6RC network --mac 52:54:00:1f:db:c7 if [[ $? -ne 0 ]]; then break fi sleep 5How do you know that the guest has responded at this point before you attempt to attach again at the top of the loop. Any attach/detach requires the guest to respond to the request and it may not respond at all.
Quoted 8 lines
Quoted 2 lines
When I attach/detach interface by hand, it works fine: I can see the new interface when I attach it, and it disapears when I detached it.
The point is that since the attach and detach require guest participation, this interface isn't reliable. You have a sleep 5 in your loop, hoping to wait long enough for the guest to respond, but after a number of iterations in your loop it fails, you can bump the sleep to to 3600 seconds and the guest *still* might not respond...
Quoted 5 lines
We use sci interrupt to tell the guest that a device has been attached/detached. But the sci interrupt is *lost* in qemu, so the guest does not know a device has been attached/detached, and does not respond it.
If the sci interrupt is not lost, the guest can respond it.
*can* is the important word. Even if the interrupt isn;t lost, you have no way to guarantee that the guest will respond at all. That's not to say there isn't a bug around the lost interrupt; but rather a more general point about hotplug's current architecture.
Quoted 3 lines
Quoted 3 lines
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
At 03/10/2011 12:31 PM, Ryan Harper Write:
Quoted 71 lines · Wen Congyang
Quoted 70 lines
At 03/09/2011 02:12 PM, Ryan Harper Write:
Quoted 56 lines · Wen Congyang
Quoted 55 lines
At 03/09/2011 12:08 PM, Ryan Harper Write:
Quoted 53 lines · Wen Congyang
Quoted 37 lines
Hi Markus Armbruster
At 02/23/2011 04:30 PM, Markus Armbruster Write:
Quoted 2 lines
Isaku Yamahata <[email protected]> writes:
<snip>
Quoted 13 lines
I don't think this patch is correct. Let me explain.
Device hot unplug is *not* guaranteed to succeed.
For some buses, such as USB, it always succeeds immediately, i.e. when the
device_delmonitor command finishes, the device is gone. Live is good.But for PCI,
device_delmerely initiates the ACPI unplug rain dance. It doesn't wait for the dance to complete. Why? The dance can take an unpredictable amount of time, including forever.Quoted 7 lines
Problem: Subsequent
device_addcan fail if it reuses the qdev ID or PCI slot, and the unplug has not yet completed (race condition), or it failed. Yes, Virginia, PCI hotplug *can* fail.When unplug succeeds, the qdev is automatically destroyed.
pciej_write()does that for PIIX4. Looks likepcie_cap_slot_event()does it for PCIE.I got a similar problem. When I unplug a pci device by hand, it works as expected, and I can hotplug it again. But when I use a srcipt to do the same thing, sometimes it failed. I think I may find another bug.
Steps to reproduce this bug:
1. cat ./test-e1000.sh # RHEL6RC is domain name
#!/bin/bashQuoted 10 lines
while true; do virsh attach-interface RHEL6RC network default --mac 52:54:00:1f:db:c7 --model e1000 if [[ $? -ne 0 ]]; then break fi virsh detach-interface RHEL6RC network --mac 52:54:00:1f:db:c7 if [[ $? -ne 0 ]]; then break fi sleep 5How do you know that the guest has responded at this point before you attempt to attach again at the top of the loop. Any attach/detach requires the guest to respond to the request and it may not respond at all.
Quoted 8 lines
Quoted 2 lines
When I attach/detach interface by hand, it works fine: I can see the new interface when I attach it, and it disapears when I detached it.
The point is that since the attach and detach require guest participation, this interface isn't reliable. You have a sleep 5 in your loop, hoping to wait long enough for the guest to respond, but after a number of iterations in your loop it fails, you can bump the sleep to to 3600 seconds and the guest *still* might not respond...
We use sci interrupt to tell the guest that a device has been attached/detached. But the sci interrupt is *lost* in qemu, so the guest does not know a device has been attached/detached, and does not respond it.
Quoted 6 lines
Quoted 1 line
If the sci interrupt is not lost, the guest can respond it.
*can* is the important word. Even if the interrupt isn;t lost, you have no way to guarantee that the guest will respond at all. That's not to say there isn't a bug around the lost interrupt; but rather a more general point about hotplug's current architecture.
I don't know whether a real hardware has the same behavior. Should we make sure the sci interrupt not lost?
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines