PCI hotplug v.s. suspend
Hi,
I triggered a WARNING while hacking on eeepc-laptop's rfkill-by-pci-hotplug. I saw "Trying to free already-free IRQ" in ath5k_pci_remove(), because the IRQ was already freed by ath5k_pci_suspend(). My changes to eeepc-laptop had allowed the PCI device to be removed while suspended.
Are PCI drivers supposed to handle remove() while suspended?
Thanks
Alan
Quoted 9 lines · Alan Jenkins
Hi,
I triggered a WARNING while hacking on eeepc-laptop's rfkill-by-pci-hotplug. I saw "Trying to free already-free IRQ" in
ath5k_pci_remove(), because the IRQ was already freed byath5k_pci_suspend(). My changes to eeepc-laptop had allowed the PCI device to be removed while suspended.Are PCI drivers supposed to handle
remove()while suspended?
Yes. You found a bug in the driver. However it's not clear (to me at least) whether the bug is that the IRQ is freed in the suspend method or that there's no check for already-freed in the remove method. My guess is the latter.
Alan Stern
Quoted 9 lines · Alan Jenkins
Hi,
I triggered a WARNING while hacking on eeepc-laptop's rfkill-by-pci-hotplug. I saw "Trying to free already-free IRQ" in
ath5k_pci_remove(), because the IRQ was already freed byath5k_pci_suspend(). My changes to eeepc-laptop had allowed the PCI device to be removed while suspended.Are PCI drivers supposed to handle
remove()while suspended?
Yes. You found a bug in the driver. However it's not clear (to me at least) whether the bug is that the IRQ is freed in the suspend method or that there's no check for already-freed in the remove method. My guess is the latter.
Alan Stern
Quoted 14 lines · Alan Stern
Quoted 10 lines · Alan Jenkins
Hi,
I triggered a WARNING while hacking on eeepc-laptop's rfkill-by-pci-hotplug. I saw "Trying to free already-free IRQ" in
ath5k_pci_remove(), because the IRQ was already freed byath5k_pci_suspend(). My changes to eeepc-laptop had allowed the PCI device to be removed while suspended.Are PCI drivers supposed to handle
remove()while suspended?
Quoted 7 lines
Yes. You found a bug in the driver. However it's not clear (to me at least) whether the bug is that the IRQ is freed in the suspend method or that there's no check for already-freed in the remove method. My guess is the latter.
Alan Stern
The example in Documentation/power/pci.txt shows free_irq() being called in suspend (and request_irq() in resume). So the problem is in remove().
Perhaps I will try hacking fakephp to simulate this case, and see if I can find bugs in any other drivers :-).
Thanks!
Alan
Quoted 14 lines · Alan Stern
Quoted 10 lines · Alan Jenkins
Hi,
I triggered a WARNING while hacking on eeepc-laptop's rfkill-by-pci-hotplug. I saw "Trying to free already-free IRQ" in
ath5k_pci_remove(), because the IRQ was already freed byath5k_pci_suspend(). My changes to eeepc-laptop had allowed the PCI device to be removed while suspended.Are PCI drivers supposed to handle
remove()while suspended?
Quoted 7 lines
Yes. You found a bug in the driver. However it's not clear (to me at least) whether the bug is that the IRQ is freed in the suspend method or that there's no check for already-freed in the remove method. My guess is the latter.
Alan Stern
The example in Documentation/power/pci.txt shows free_irq() being called in suspend (and request_irq() in resume). So the problem is in remove().
Perhaps I will try hacking fakephp to simulate this case, and see if I can find bugs in any other drivers :-).
Thanks!
Alan
Quoted 20 lines · Alan Jenkins
Quoted 19 lines · Alan Stern
Quoted 10 lines · Alan Jenkins
Hi,
I triggered a WARNING while hacking on eeepc-laptop's rfkill-by-pci-hotplug. I saw "Trying to free already-free IRQ" in
ath5k_pci_remove(), because the IRQ was already freed byath5k_pci_suspend(). My changes to eeepc-laptop had allowed the PCI device to be removed while suspended.Are PCI drivers supposed to handle
remove()while suspended?Yes. You found a bug in the driver. However it's not clear (to me at least) whether the bug is that the IRQ is freed in the suspend method or that there's no check for already-freed in the remove method. My guess is the latter.
Quoted 5 lines
Quoted 2 lines
Alan Stern
The example in
Documentation/power/pci.txtshowsfree_irq()being called in suspend (andrequest_irq()in resume). So the problem is inremove().
I'm not sure whether the example is trustworthy. There was some discussion quite a while ago regarding whether drivers should free their IRQs during suspend, but I don't remember what the outcome was.
Alan Stern
Quoted 20 lines · Alan Jenkins
Quoted 19 lines · Alan Stern
Quoted 10 lines · Alan Jenkins
Hi,
I triggered a WARNING while hacking on eeepc-laptop's rfkill-by-pci-hotplug. I saw "Trying to free already-free IRQ" in
ath5k_pci_remove(), because the IRQ was already freed byath5k_pci_suspend(). My changes to eeepc-laptop had allowed the PCI device to be removed while suspended.Are PCI drivers supposed to handle
remove()while suspended?Yes. You found a bug in the driver. However it's not clear (to me at least) whether the bug is that the IRQ is freed in the suspend method or that there's no check for already-freed in the remove method. My guess is the latter.
Quoted 5 lines
Quoted 2 lines
Alan Stern
The example in
Documentation/power/pci.txtshowsfree_irq()being called in suspend (andrequest_irq()in resume). So the problem is inremove().
I'm not sure whether the example is trustworthy. There was some discussion quite a while ago regarding whether drivers should free their IRQs during suspend, but I don't remember what the outcome was.
Alan Stern
Quoted 25 lines · Alan Stern
Quoted 23 lines · Alan Jenkins
Quoted 21 lines · Alan Stern
Quoted 10 lines · Alan Jenkins
Hi,
I triggered a WARNING while hacking on eeepc-laptop's rfkill-by-pci-hotplug. I saw "Trying to free already-free IRQ" in
ath5k_pci_remove(), because the IRQ was already freed byath5k_pci_suspend(). My changes to eeepc-laptop had allowed the PCI device to be removed while suspended.Are PCI drivers supposed to handle
remove()while suspended?Yes. You found a bug in the driver. However it's not clear (to me at least) whether the bug is that the IRQ is freed in the suspend method or that there's no check for already-freed in the remove method. My guess is the latter.
Alan Stern
Quoted 6 lines
Quoted 2 lines
The example in
Documentation/power/pci.txtshowsfree_irq()being called in suspend (andrequest_irq()in resume). So the problem is inremove().I'm not sure whether the example is trustworthy. There was some discussion quite a while ago regarding whether drivers should free their IRQs during suspend, but I don't remember what the outcome was.
No, they shouldn't.
That's why we do the entire suspend_device_irqs() thing etc.
Best,
Rafael
Quoted 25 lines · Alan Stern
Quoted 23 lines · Alan Jenkins
Quoted 21 lines · Alan Stern
Quoted 10 lines · Alan Jenkins
Hi,
I triggered a WARNING while hacking on eeepc-laptop's rfkill-by-pci-hotplug. I saw "Trying to free already-free IRQ" in
ath5k_pci_remove(), because the IRQ was already freed byath5k_pci_suspend(). My changes to eeepc-laptop had allowed the PCI device to be removed while suspended.Are PCI drivers supposed to handle
remove()while suspended?Yes. You found a bug in the driver. However it's not clear (to me at least) whether the bug is that the IRQ is freed in the suspend method or that there's no check for already-freed in the remove method. My guess is the latter.
Alan Stern
Quoted 6 lines
Quoted 2 lines
The example in
Documentation/power/pci.txtshowsfree_irq()being called in suspend (andrequest_irq()in resume). So the problem is inremove().I'm not sure whether the example is trustworthy. There was some discussion quite a while ago regarding whether drivers should free their IRQs during suspend, but I don't remember what the outcome was.
No, they shouldn't.
That's why we do the entire suspend_device_irqs() thing etc.
Best,
Rafael
Quoted 7 lines · Rafael J. Wysocki
Quoted 3 lines
I'm not sure whether the example is trustworthy. There was some discussion quite a while ago regarding whether drivers should free their IRQs during suspend, but I don't remember what the outcome was.
No, they shouldn't.
That's why we do the entire
suspend_device_irqs()thing etc.
Looks like the Documentation/power/pci.txt file needs to be updated. No surprise, it hasn't been touched in well over a year and there haven't been any meaningful updates in four years.
Alan Stern
Quoted 7 lines · Rafael J. Wysocki
Quoted 3 lines
I'm not sure whether the example is trustworthy. There was some discussion quite a while ago regarding whether drivers should free their IRQs during suspend, but I don't remember what the outcome was.
No, they shouldn't.
That's why we do the entire
suspend_device_irqs()thing etc.
Looks like the Documentation/power/pci.txt file needs to be updated. No surprise, it hasn't been touched in well over a year and there haven't been any meaningful updates in four years.
Alan Stern
Quoted 6 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines
I'm not sure whether the example is trustworthy. There was some discussion quite a while ago regarding whether drivers should free their IRQs during suspend, but I don't remember what the outcome was.
Quoted 7 lines
Quoted 3 lines
No, they shouldn't.
That's why we do the entire
suspend_device_irqs()thing etc.Looks like the
Documentation/power/pci.txtfile needs to be updated. No surprise, it hasn't been touched in well over a year and there haven't been any meaningful updates in four years.
Sure it does, but PCI PM has been a moving target for quite some time. I hope it's going to settle down now.
Best,
Rafael
Quoted 6 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines
I'm not sure whether the example is trustworthy. There was some discussion quite a while ago regarding whether drivers should free their IRQs during suspend, but I don't remember what the outcome was.
Quoted 7 lines
Quoted 3 lines
No, they shouldn't.
That's why we do the entire
suspend_device_irqs()thing etc.Looks like the
Documentation/power/pci.txtfile needs to be updated. No surprise, it hasn't been touched in well over a year and there haven't been any meaningful updates in four years.
Sure it does, but PCI PM has been a moving target for quite some time. I hope it's going to settle down now.
Best,
Rafael
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Alan Stern
I'm not sure whether the example is trustworthy. There was some discussion quite a while ago regarding whether drivers should free their IRQs during suspend, but I don't remember what the outcome was.
No, they shouldn't.
That's why we do the entire
suspend_device_irqs()thing etc.
So, ath5k needs something like the following?
drivers/net/wireless/ath/ath5k/base.c +0 -11
@@ -665,7 +665,6 @@ ath5k_pci_suspend(struct pci_dev *pdev, pm_message_t state)ath5k_led_off (sc); -free_irq (pdev->irq, sc);pci_save_state (pdev);pci_disable_device (pdev);pci_set_power_state (pdev, PCI_D3hot);
@@ -686,18 +685,8 @@ ath5k_pci_resume(struct pci_dev *pdev)if (err)return err; - err =request_irq (pdev->irq, ath5k_intr,IRQF_SHARED ,"ath" , sc); -if (err) { -ATH5K_ERR (sc,"request_irq failed\n" ); - goto err_no_irq; - } -ath5k_led_enable (sc); return 0; - -err_no_irq: -pci_disable_device (pdev); - return err; }#endif /* CONFIG_PM */
Signature · 1 line
Bob Copeland %% www.bobcopeland.com
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Alan Stern
I'm not sure whether the example is trustworthy. There was some discussion quite a while ago regarding whether drivers should free their IRQs during suspend, but I don't remember what the outcome was.
No, they shouldn't.
That's why we do the entire
suspend_device_irqs()thing etc.
So, ath5k needs something like the following?
drivers/net/wireless/ath/ath5k/base.c +0 -11
@@ -665,7 +665,6 @@ ath5k_pci_suspend(struct pci_dev *pdev, pm_message_t state)ath5k_led_off (sc); -free_irq (pdev->irq, sc);pci_save_state (pdev);pci_disable_device (pdev);pci_set_power_state (pdev, PCI_D3hot);
@@ -686,18 +685,8 @@ ath5k_pci_resume(struct pci_dev *pdev)if (err)return err; - err =request_irq (pdev->irq, ath5k_intr,IRQF_SHARED ,"ath" , sc); -if (err) { -ATH5K_ERR (sc,"request_irq failed\n" ); - goto err_no_irq; - } -ath5k_led_enable (sc); return 0; - -err_no_irq: -pci_disable_device (pdev); - return err; }#endif /* CONFIG_PM */
Signature · 1 line
Bob Copeland %% www.bobcopeland.com
Quoted 37 lines · Bob Copeland
Quoted 10 lines · Rafael J. Wysocki
Quoted 4 lines · Alan Stern
I'm not sure whether the example is trustworthy. There was some discussion quite a while ago regarding whether drivers should free their IRQs during suspend, but I don't remember what the outcome was.
No, they shouldn't.
That's why we do the entire
suspend_device_irqs()thing etc.So, ath5k needs something like the following?
drivers/net/wireless/ath/ath5k/base.c +0
-6@@ -665,7 +665,6 @@ ath5k_pci_suspend(struct pci_dev *pdev, pm_message_t state)ath5k_led_off (sc); -free_irq (pdev->irq, sc);pci_save_state (pdev);pci_disable_device (pdev);pci_set_power_state (pdev, PCI_D3hot);@@ -686,18 +685,8 @@ ath5k_pci_resume(struct pci_dev *pdev)if (err)return err; - err =request_irq (pdev->irq, ath5k_intr,IRQF_SHARED ,"ath" , sc); -if (err) { -ATH5K_ERR (sc,"request_irq failed\n" ); - goto err_no_irq; - }
drivers/net/wireless/ath/ath5k/base.c ath5k_pci_resume(struct pci_dev *pdev) · line 692
Quoted 10 lines
drivers/net/wireless/ath/ath5k/base.c +0
-5-ath5k_led_enable (sc); return 0; - -err_no_irq: -pci_disable_device (pdev); - return err; }#endif /* CONFIG_PM */
Unfortunately this makes it worse. My eeepc-laptop hacks are now in wireless-testing. If I apply the above patch to wireless-testing and "remove" the device while suspended, I get a soft hang on resume. Suspending without removal works fine.
I can see a BUG if I boot with no_console_suspend
Unable to handle kernel NULL pointer dereference IP: klist_put Tainted: G W
Process s2disk
Call trace:
? klist_del
? device_del
? device_unregister
? pci_stop_dev
? pci_stop_bus
? pci_remove_device
? eeepc_rfkill_hotplug [eeepc_laptop]
? eeepc_hotk_resume [eeepc_laptop]
? acpi_device_resume
? device_resume
? hibernation_snapshot
? release_console_sem
? snapshot_ioctl
? snapshot_ioctl
? vfs_ioctl
? do_vfs_ioctl
? n_tty_write
? vfs_write
? sys_ioctl
? syscall_call
Quoted 37 lines · Bob Copeland
Quoted 10 lines · Rafael J. Wysocki
Quoted 4 lines · Alan Stern
I'm not sure whether the example is trustworthy. There was some discussion quite a while ago regarding whether drivers should free their IRQs during suspend, but I don't remember what the outcome was.
No, they shouldn't.
That's why we do the entire
suspend_device_irqs()thing etc.So, ath5k needs something like the following?
drivers/net/wireless/ath/ath5k/base.c +0
-6@@ -665,7 +665,6 @@ ath5k_pci_suspend(struct pci_dev *pdev, pm_message_t state)ath5k_led_off (sc); -free_irq (pdev->irq, sc);pci_save_state (pdev);pci_disable_device (pdev);pci_set_power_state (pdev, PCI_D3hot);@@ -686,18 +685,8 @@ ath5k_pci_resume(struct pci_dev *pdev)if (err)return err; - err =request_irq (pdev->irq, ath5k_intr,IRQF_SHARED ,"ath" , sc); -if (err) { -ATH5K_ERR (sc,"request_irq failed\n" ); - goto err_no_irq; - }
drivers/net/wireless/ath/ath5k/base.c ath5k_pci_resume(struct pci_dev *pdev) · line 692
Quoted 10 lines
drivers/net/wireless/ath/ath5k/base.c +0
-5-ath5k_led_enable (sc); return 0; - -err_no_irq: -pci_disable_device (pdev); - return err; }#endif /* CONFIG_PM */
Unfortunately this makes it worse. My eeepc-laptop hacks are now in wireless-testing. If I apply the above patch to wireless-testing and "remove" the device while suspended, I get a soft hang on resume. Suspending without removal works fine.
I can see a BUG if I boot with no_console_suspend
Unable to handle kernel NULL pointer dereference IP: klist_put Tainted: G W
Process s2disk
Call trace:
? klist_del
? device_del
? device_unregister
? pci_stop_dev
? pci_stop_bus
? pci_remove_device
? eeepc_rfkill_hotplug [eeepc_laptop]
? eeepc_hotk_resume [eeepc_laptop]
? acpi_device_resume
? device_resume
? hibernation_snapshot
? release_console_sem
? snapshot_ioctl
? snapshot_ioctl
? vfs_ioctl
? do_vfs_ioctl
? n_tty_write
? vfs_write
? sys_ioctl
? syscall_call
Quoted 3 lines · Alan Jenkins
Unfortunately this makes it worse. My eeepc-laptop hacks are now in wireless-testing. If I apply the above patch to wireless-testing and "remove" the device while suspended, I get a soft hang on resume.
Is this different from the behavior without the patch? (I don't see how it could be.)
Quoted 10 lines
Suspending without removal works fine.
I can see a BUG if I boot with
no_console_suspendUnable to handle kernel NULL pointer dereference IP: klist_put Tainted: G WProcess s2disk
Call trace:
Quoted 11 lines
?
klist_del
?device_del
?device_unregister
?pci_stop_dev
?pci_stop_bus
?pci_remove_device
?eeepc_rfkill_hotplug[eeepc_laptop]
?eeepc_hotk_resume[eeepc_laptop]
?acpi_device_resume
?device_resume
?hibernation_snapshot
This should be doing more or less the same thing as if you removed the device while the system was running. Or is it not hot-unpluggable?
Alan Stern
Quoted 3 lines · Alan Jenkins
Unfortunately this makes it worse. My eeepc-laptop hacks are now in wireless-testing. If I apply the above patch to wireless-testing and "remove" the device while suspended, I get a soft hang on resume.
Is this different from the behavior without the patch? (I don't see how it could be.)
Quoted 10 lines
Suspending without removal works fine.
I can see a BUG if I boot with
no_console_suspendUnable to handle kernel NULL pointer dereference IP: klist_put Tainted: G WProcess s2disk
Call trace:
Quoted 11 lines
?
klist_del
?device_del
?device_unregister
?pci_stop_dev
?pci_stop_bus
?pci_remove_device
?eeepc_rfkill_hotplug[eeepc_laptop]
?eeepc_hotk_resume[eeepc_laptop]
?acpi_device_resume
?device_resume
?hibernation_snapshot
This should be doing more or less the same thing as if you removed the device while the system was running. Or is it not hot-unpluggable?
Alan Stern
Quoted 11 lines · Alan Stern
Quoted 4 lines · Alan Jenkins
Unfortunately this makes it worse. My eeepc-laptop hacks are now in wireless-testing. If I apply the above patch to wireless-testing and "remove" the device while suspended, I get a soft hang on resume.
Is this different from the behavior without the patch? (I don't see how it could be.)
Ow. No, the free_irq patch doesn't cause this bug. I missed testing this case after adding a workaround for an even more obscure issue :-(.
I have a good idea how eeepc-laptop could cause a double-free error. I suspect we originally got away with trying to call pci_remove_device() twice, but it's not actually legal, and my workaround caused two attempts to happen much closer together.
I'll fix it tomorrow and re-test. With _both_ of my nasty scenarios this time (and the normal ones) - I should really make a checklist :-).
Quoted 23 lines
Quoted 10 lines
Suspending without removal works fine.
I can see a BUG if I boot with
no_console_suspendUnable to handle kernel NULL pointer dereference IP: klist_put Tainted: G WProcess s2disk
Call trace:Quoted 12 lines
?
klist_del
?device_del
?device_unregister
?pci_stop_dev
?pci_stop_bus
?pci_remove_device
?eeepc_rfkill_hotplug[eeepc_laptop]
?eeepc_hotk_resume[eeepc_laptop]
?acpi_device_resume
?device_resume
?hibernation_snapshot
Quoted 5 lines
This should be doing more or less the same thing as if you removed the device while the system was running. Or is it not hot-unpluggable?
Alan Stern
Outside of suspend, I can hot-unplug the device alright. I'm blaming my hotplug driver resume handler.
Thanks
Alan
Quoted 11 lines · Alan Stern
Quoted 4 lines · Alan Jenkins
Unfortunately this makes it worse. My eeepc-laptop hacks are now in wireless-testing. If I apply the above patch to wireless-testing and "remove" the device while suspended, I get a soft hang on resume.
Is this different from the behavior without the patch? (I don't see how it could be.)
Ow. No, the free_irq patch doesn't cause this bug. I missed testing this case after adding a workaround for an even more obscure issue :-(.
I have a good idea how eeepc-laptop could cause a double-free error. I suspect we originally got away with trying to call pci_remove_device() twice, but it's not actually legal, and my workaround caused two attempts to happen much closer together.
I'll fix it tomorrow and re-test. With _both_ of my nasty scenarios this time (and the normal ones) - I should really make a checklist :-).
Quoted 23 lines
Quoted 10 lines
Suspending without removal works fine.
I can see a BUG if I boot with
no_console_suspendUnable to handle kernel NULL pointer dereference IP: klist_put Tainted: G WProcess s2disk
Call trace:Quoted 12 lines
?
klist_del
?device_del
?device_unregister
?pci_stop_dev
?pci_stop_bus
?pci_remove_device
?eeepc_rfkill_hotplug[eeepc_laptop]
?eeepc_hotk_resume[eeepc_laptop]
?acpi_device_resume
?device_resume
?hibernation_snapshot
Quoted 5 lines
This should be doing more or less the same thing as if you removed the device while the system was running. Or is it not hot-unpluggable?
Alan Stern
Outside of suspend, I can hot-unplug the device alright. I'm blaming my hotplug driver resume handler.
Thanks
Alan
Quoted 11 lines · Alan Jenkins
Quoted 9 lines · Alan Stern
Quoted 5 lines · Alan Jenkins
Unfortunately this makes it worse. My eeepc-laptop hacks are now in wireless-testing. If I apply the above patch to wireless-testing and "remove" the device while suspended, I get a soft hang on resume.
Quoted 8 lines
Quoted 4 lines
Is this different from the behavior without the patch? (I don't see how it could be.)
Ow. No, the
free_irqpatch doesn't cause this bug. I missed testing this case after adding a workaround for an even more obscure issue :-(.
I tried an earlier version without the problem workaround. Bob's suggested patch to remove the free_irq() on suspend works fine. It fixes the WARNING when the device is removed during suspend, and it still works if the device is not removed during suspend.
Alan
Quoted 11 lines · Alan Jenkins
Quoted 9 lines · Alan Stern
Quoted 5 lines · Alan Jenkins
Unfortunately this makes it worse. My eeepc-laptop hacks are now in wireless-testing. If I apply the above patch to wireless-testing and "remove" the device while suspended, I get a soft hang on resume.
Quoted 8 lines
Quoted 4 lines
Is this different from the behavior without the patch? (I don't see how it could be.)
Ow. No, the
free_irqpatch doesn't cause this bug. I missed testing this case after adding a workaround for an even more obscure issue :-(.
I tried an earlier version without the problem workaround. Bob's suggested patch to remove the free_irq() on suspend works fine. It fixes the WARNING when the device is removed during suspend, and it still works if the device is not removed during suspend.
Alan
Quoted 4 lines · Alan Jenkins
I tried an earlier version without the problem workaround. Bob's suggested patch to remove the
free_irq()on suspend works fine. It fixes the WARNING when the device is removed during suspend, and it still works if the device is not removed during suspend.
Okay thanks for finding it and testing. I'll send a version with my s-o-b later today.
Signature · 1 line
Bob Copeland %% www.bobcopeland.com
Quoted 4 lines · Alan Jenkins
I tried an earlier version without the problem workaround. Bob's suggested patch to remove the
free_irq()on suspend works fine. It fixes the WARNING when the device is removed during suspend, and it still works if the device is not removed during suspend.
Okay thanks for finding it and testing. I'll send a version with my s-o-b later today.
Signature · 1 line
Bob Copeland %% www.bobcopeland.com