watchdog timeout panic in e1000 driver
Subsystems (2)
Hi,
A watchdog timeout panic occurred in e1000 driver (7.2.9-NAPI). If e1000_watchdog is called when processing ioctl from ethtool, the system could stop inside e1000_watchdog interrupt handler for about 16 seconds, and the system panicked as a result of a watchdog timeout.
This problem only occurs on a server using ethernet controller inside 631xESB/632xESB, and NMI watchdog enabled.
Environment:
OS : RHEL4U3(x86_64)
kernel : 2.6.9-34.ELsmp
e1000 : 7.2.9-NAPI
Ethernet controller : Intel Corporation 631x/632xESB DPT LAN Controller
Copper (rev 01)
Watchdog timer should be enabled with a timeout period of less than 16 seconds.
Steps to reproduce:
Please apply the attached patch (ethtool.patch) to ethtool (VERSION 5) source code. Run make, and rename the freshly built ethtool as gsetloop. Put gsetloop and the attached shell script (gloop.sh) in the same directory, and execute gloop.sh. The problem should occur within about 5 minutes.
Cause:
The problem occurs in the following steps.
- ioctl is executed in ethtool.
- e1000_read_phy_reg() is called from ioctl to read the value from phy register.
- e1000_get_hw_eeprom_semaphore() is called from e1000_read_phy_reg() to acquire a semaphore.
- E1000_SWSM_SWESMBI bit that is FW semaphore bit is set in e1000_get_hw_eeprom_semaphore().
- When this bit was set, E1000_SWSM_SMBI bit that is driver's semaphore bit is also set.
- e1000_watchdog() of interrupt handler is executed before the E1000_SWSM_SMBI bit is unset.
- e1000_read_phy_reg() is called from e1000_watchdog() to read the value from phy register.
- e1000_get_software_semaphore() is called from e1000_watchdog to confirm whether interruption handler can acquire a semaphore.
This function confirms whether E1000_SWSM_SMBI bit is being set.
- Therefore the process does loop for "hw->eeprom.word_size + 1" msec in e1000_get_software_semaphore().
The value of "hw->eeprom.word_size + 1" was 16385 on my system. In other words it loops for 16.385 sec in e1000_get_software_semaphore().
If NMI watchdog is enabled, the system will panic by NMI watchdog within this loop.
Fix:
In kernels before 2.6.17, the e1000_watchdog() interrupt handler schedules e1000_watchdog_task(). The semaphore is acquired within this task, after ioctl processing for ethtool is finished, and this problem is avoided.
e1000_watchdog_task() was remove by the following patch.
http://kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=2db10a081c5c1082d58809a1bcf1a6073f4db160
e1000: rework driver hardware reset locking
>After studying the driver mac reset code it was found that there >were multiple race conditions possible to reset the unit twice or >bring it e1000_up() double. This fixes all occurences where the >driver needs to reset the mac.
>
>We also remove irq requesting/releasing into _open and _close so >that while the device is _up we will never touch the irq's. This fixes >the double free irq bug that people saw.
>
>To make sure that the watchdog task doesn't cause another race we let >it run as a non-scheduled task.
I'm not sure whether there was any reason to actively remove e1000_watchdog_task(). I think that removing e1000_watchdog_task() was a mistake, and it should be brought back in.
--
Kenzo Iwami ([email protected])
#!/bin/sh
n=64
i=1
[ $# -ge 1 ] && n=$1
while [ $i -le $n ]
do
./gsetloop eth0 & i=`expr $i + 1`
done
ethtool.c +3 -1
@@ -1576,7 +1576,9 @@ static int do_gset(int fd, struct ifreq ecmd.cmd =ETHTOOL_GSET ; ifr->ifr_data = (caddr_t)&ecmd; - err =ioctl (fd,SIOCETHTOOL , ifr); +for (;;) { + err =ioctl (fd,SIOCETHTOOL , ifr); + }if (err ==0 ) { err =dump_ecmd (&ecmd);if (err)
Quoted 1 line · Kenzo Iwami
A watchdog timeout panic occurred in e1000 driver (7.2.9-NAPI).
where's the panic message ?
Please CC the maintainers of the driver at all times. Our e-mail addresses are widely visible everywhere.
Quoted 7 lines
If
e1000_watchdogis called when processing ioctl from ethtool, the system could stop insidee1000_watchdoginterrupt handler for about 16 secondsand the system panicked as a result of a watchdog timeout.
This problem only occurs on a server using ethernet controller inside 631xESB/632xESB, and NMI watchdog enabled.
why only this system? have you seen/tried it on other machines?
Quoted 62 lines
Environment:
OS :RHEL4U3(x86_64)
kernel : 2.6.9-34.ELsmp
e1000 : 7.2.9-NAPI
Ethernet controller : Intel Corporation 631x/632xESB DPT LAN ControllerCopper (rev 01)Watchdog timer should be enabled with a timeout period of less than 16 seconds.
Steps to reproduce:
Please apply the attached patch (ethtool.patch) to ethtool (VERSION 5) source code. Run make, and rename the freshly built ethtool as gsetloop. Put gsetloop and the attached shell script (gloop.sh) in the same directory, and executegloop.sh. The problem should occur within about 5 minutes.Cause:
The problem occurs in the following steps.
- ioctl is executed in ethtool.
-e1000_read_phy_reg()is called from ioctl to read the value from phy register.
-e1000_get_hw_eeprom_semaphore()is called frome1000_read_phy_reg()to acquire a semaphore.
-E1000_SWSM_SWESMBIbit that is FW semaphore bit is set ine1000_get_hw_eeprom_semaphore().
- When this bit was set,E1000_SWSM_SMBIbit that is driver's semaphore bit is also set.
-e1000_watchdog()of interrupt handler is executed before theE1000_SWSM_SMBIbit is unset.
-e1000_read_phy_reg()is called frome1000_watchdog()to read the value from phy register.
-e1000_get_software_semaphore()is called frome1000_watchdogto confirm whether interruption handler can acquire a semaphore.
This function confirms whetherE1000_SWSM_SMBIbit is being set.
- Therefore the process does loop for "hw->eeprom.word_size+ 1" msec ine1000_get_software_semaphore().
The value of "hw->eeprom.word_size+ 1" was 16385 on my system. In other words it loops for 16.385 sec ine1000_get_software_semaphore().
If NMI watchdog is enabled, the system will panic by NMI watchdog within this loop.Fix:
In kernels before 2.6.17, thee1000_watchdog()interrupt handler schedulese1000_watchdog_task(). The semaphore is acquired within this task, after ioctl processing for ethtool is finished, and this problem is avoided.
e1000_watchdog_task()was remove by the following patch.http://kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=2db10a081c5c1082d58809a1bcf1a6073f4db160
e1000: rework driver hardware reset locking
>After studying the driver mac reset code it was found that there >were multiple race conditions possible to reset the unit twice or >bring ite1000_up()double. This fixes all occurences where the >driver needs to reset the mac.
>
>We also remove irq requesting/releasing into_openand_closeso >that while the device is_upwe will never touch the irq's. This fixes >the double free irq bug that people saw.
>
>To make sure that the watchdog task doesn't cause another race we let >it run as a non-scheduled task.
Quoted 3 lines
I'm not sure whether there was any reason to actively remove
e1000_watchdog_task(). I think that removinge1000_watchdog_task()was a mistake, and it should be brought back in.
Reverting this could would not be a fix, but only a workaround that leaves the problem still in the code, and as such not progress in the right direction.
I find this report extremely edgy, but I'll look into the fact that the driver attempts to sleep for 16384 + 1 msec, which seems overly long :)
As a side note, most other e1000 NIC's use hardcoded word_size numbers, but esb2 systems read it from a register/eeprom. Can you send me the output of ethtool -e ethX ? off-list is OK, it might be large.
Thanks,
Auke
Quoted 27 lines · Kenzo Iwami
Hi,
Thank you for your comment.
Quoted 2 lines
Quoted 1 line
A watchdog timeout panic occurred in e1000 driver (7.2.9-NAPI).
where's the panic message ?
attached the panic message (
e1000_panic).[...]
Quoted 3 lines
Quoted 2 lines
This problem only occurs on a server using ethernet controller inside 631xESB/632xESB, and NMI watchdog enabled.
why only this system? have you seen/tried it on other machines?
This problem is caused by
e1000_get_software_semaphore()being called from within the interrupt handler, while the interrupted code is still holding this semaphore.e1000_get_software_semaphore()is called frome1000_get_hw_eeprom_semaphore()only whenhw->mac_typeise1000_80003es2lan. This condition is true only for MACs inside 631xESB/632xESB.When this problem happens
e1000_get_software_semaphore()will wait for 16 seconds (inside the interrupt handler) before it fails, thus causing the watchdog timeout.I haven't actually tried it on other machines, but theoretically, it will only happen on MAC inside 631xESB/632xESB chip set.
Quoted 8 lines
[...]
Quoted 5 lines
Reverting this could would not be a fix, but only a workaround that leaves the problem still in the code, and as such not progress in the right direction.
I find this report extremely edgy, but I'll look into the fact that the driver attempts to sleep for 16384 + 1 msec, which seems overly long :)
As a side note, most other e1000 NIC's use hardcoded
word_sizenumbers, but esb2 systems read it from a register/eeprom. Can you send me the output ofethtool -e ethX? off-list is OK, it might be large.attached is the output of "ethtool -e ethX" (
eeprom_eth0).
thanks.
This panic report falls in the category "how hard can I break my system as root". Explicitly abusing the system performing restricted calls depletes resources and harasses the sw lock (in this case). The reason that the driver attempts to wait that long is that in the case of ESB2 systems, the SPI interface to the EEPROM can be slow, thus taking a long time to complete certain commands.
We're looking into making this theoretical lock time shorter in the mean time, thanks for reporting this.
Cheers,
Auke
Hi,
Thank you for your comment.
Quoted 5 lines
This panic report falls in the category "how hard can I break my system as root". Explicitly abusing the system performing restricted calls depletes resources and harasses the sw lock (in this case). The reason that the driver attempts to wait that long is that in the case of ESB2 systems, the SPI interface to the EEPROM can be slow, thus taking a long time to complete certain commands.
This problem originally occurred in a very large cluster system using snmp for server management. About two servers panicked each day. The program I sent is to reproduce this problem in a very short time. It does occur under normal load when there is a lot of servers.
Signature · 1 line
Kenzo Iwami ([email protected])
Quoted 10 lines · Kenzo Iwami
Hi,
Thank you for your comment.
Quoted 1 line
This panic report falls in the category "how hard can I break my system as root". Explicitly abusing the system performing restricted calls depletes resources and harasses the sw lock (in this case). The reason that the driver attempts to wait that long is that in the case of ESB2 systems, the SPI interface to the EEPROM can be slow, thus taking a long time to complete certain commands.
This problem originally occurred in a very large cluster system using snmp for server management. About two servers panicked each day. The program I sent is to reproduce this problem in a very short time. It does occur under normal load when there is a lot of servers.
hmm, not good - does your snmp daemon use ethtool excessively? That would certainly be painful to the driver (any driver!).
Anyway as I said in the same e-mail, we're working on reducing the lock timeout to a reasonable time. This will unfortunately take some time, as we need to change some major components in the driver to make sure this doesn't happen.
Cheers,
Auke
Hi,
Quoted 7 lines
Quoted 4 lines
This problem originally occurred in a very large cluster system using snmp for server management. About two servers panicked each day. The program I sent is to reproduce this problem in a very short time. It does occur under normal load when there is a lot of servers.
hmm, not good - does your snmp daemon use ethtool excessively? That would certainly be painful to the driver (any driver!).
I only looked at the panic message after this problem occurred.
I could tell that the snmp daemon caused the panic while trying to process the ethtool's ioctl, but I don't know how often this was called. However, it shouldn't be excessively called because it occurred on a production system while it was idle.
Quoted 3 lines
Anyway as I said in the same e-mail, we're working on reducing the lock timeout to a reasonable time. This will unfortunately take some time, as we need to change some major components in the driver to make sure this doesn't happen.
How about the following approach?
If acquiring semaphore fails inside the interrupt handler, acquiring semaphore is abandoned immediately without waiting for timeout.
However, I don't know whether this method affects other processes.
Signature · 1 line
Kenzo Iwami ([email protected])
Quoted 14 lines · Kenzo Iwami
Hi,
Quoted 5 lines
Quoted 4 lines
This problem originally occurred in a very large cluster system using snmp for server management. About two servers panicked each day. The program I sent is to reproduce this problem in a very short time. It does occur under normal load when there is a lot of servers.
hmm, not good - does your snmp daemon use ethtool excessively? That would certainly be painful to the driver (any driver!).
I only looked at the panic message after this problem occurred.
I could tell that the snmp daemon caused the panic while trying to process the ethtool's ioctl, but I don't know how often this was called. However, it shouldn't be excessively called because it occurred on a production system while it was idle.
Quoted 6 lines
Quoted 1 line
Anyway as I said in the same e-mail, we're working on reducing the lock timeout to a reasonable time. This will unfortunately take some time, as we need to change some major components in the driver to make sure this doesn't happen.
How about the following approach?
If acquiring semaphore fails inside the interrupt handler, acquiring semaphore is abandoned immediately without waiting for timeout.
However, I don't know whether this method affects other processes.
with the current hardware being accessed simultaneously from several users in the kernel, that would lead to large problems - the watchdog task accesses it every 2 seconds as it reads the PHY link status, so when one of those fails the driver would have no choice but to reset the entire device.
Auke
Hi,
Thank you for your comment.
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
Anyway as I said in the same e-mail, we're working on reducing the lock timeout to a reasonable time. This will unfortunately take some time, as we need to change some major components in the driver to make sure this doesn't happen.
How about the following approach?
If acquiring semaphore fails inside the interrupt handler, acquiring semaphore is abandoned immediately without waiting for timeout.
However, I don't know whether this method affects other processes.
Quoted 4 lines
with the current hardware being accessed simultaneously from several users in the kernel, that would lead to large problems - the watchdog task accesses it every 2 seconds as it reads the PHY link status, so when one of those fails the driver would have no choice but to reset the entire device.
This problem occurs because interrupt handler is executed while the interrupted code is still holding the semaphore. Acquiring the semaphore fails regardless of the timeout period.
I think the watchdog task will fail trying to read the PHY link status, even if the lock timeout period has been reduced.
Signature · 1 line
Kenzo Iwami ([email protected])
Quoted 9 lines · Kenzo Iwami
Hi,
Thank you for your comment.
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Anyway as I said in the same e-mail, we're working on reducing the lock timeout to a reasonable time. This will unfortunately take some time, as we need to change some major components in the driver to make sure this doesn't happen.
How about the following approach?
If acquiring semaphore fails inside the interrupt handler, acquiring semaphore is abandoned immediately without waiting for timeout.
However, I don't know whether this method affects other processes.
Quoted 8 lines
Quoted 1 line
with the current hardware being accessed simultaneously from several users in the kernel, that would lead to large problems - the watchdog task accesses it every 2 seconds as it reads the PHY link status, so when one of those fails the driver would have no choice but to reset the entire device.
This problem occurs because interrupt handler is executed while the interrupted code is still holding the semaphore. Acquiring the semaphore fails regardless of the timeout period.
I think the watchdog task will fail trying to read the PHY link status, even if the lock timeout period has been reduced.
correct, we're not looking into reducing the lock timeout but towards reducing the total lock time. Once we have reduced that to something acceptable, we can reduce the timout accordingly.
Cheers,
Auke
Hi,
Thank you for your comment.
Quoted 15 lines
Quoted 15 lines
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
Anyway as I said in the same e-mail, we're working on reducing the lock timeout to a reasonable time. This will unfortunately take some time, as we need to change some major components in the driver to make sure this doesn't happen.
How about the following approach?
If acquiring semaphore fails inside the interrupt handler, acquiring semaphore is abandoned immediately without waiting for timeout.
However, I don't know whether this method affects other processes.with the current hardware being accessed simultaneously from several users in the kernel, that would lead to large problems - the watchdog task accesses it every 2 seconds as it reads the PHY link status, so when one of those fails the driver would have no choice but to reset the entire device.
This problem occurs because interrupt handler is executed while the interrupted code is still holding the semaphore. Acquiring the semaphore fails regardless of the timeout period.
Quoted 6 lines
Quoted 2 lines
I think the watchdog task will fail trying to read the PHY link status, even if the lock timeout period has been reduced.
correct, we're not looking into reducing the lock timeout but towards reducing the total lock time. Once we have reduced that to something acceptable, we can reduce the timout accordingly.
Even if the total lock time can be reduced, it's possible that interrupt handler is executed while the interrupted code is still holding the semaphore. I think your method only decrease the frequency of this problem. Why does reducing the lock time solve this problem?
Signature · 1 line
Kenzo Iwami ([email protected])
Quoted 20 lines · Kenzo Iwami
Hi,
Thank you for your comment.
Quoted 16 lines
Quoted 15 lines
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Anyway as I said in the same e-mail, we're working on reducing the lock timeout to a reasonable time. This will unfortunately take some time, as we need to change some major components in the driver to make sure this doesn't happen.
How about the following approach?
If acquiring semaphore fails inside the interrupt handler, acquiring semaphore is abandoned immediately without waiting for timeout.
However, I don't know whether this method affects other processes.with the current hardware being accessed simultaneously from several users in the kernel, that would lead to large problems - the watchdog task accesses it every 2 seconds as it reads the PHY link status, so when one of those fails the driver would have no choice but to reset the entire device.
This problem occurs because interrupt handler is executed while the interrupted code is still holding the semaphore. Acquiring the semaphore fails regardless of the timeout period.
I think the watchdog task will fail trying to read the PHY link status, even if the lock timeout period has been reduced.
Quoted 6 lines
Quoted 1 line
correct, we're not looking into reducing the lock timeout but towards reducing the total lock time. Once we have reduced that to something acceptable, we can reduce the timout accordingly.
Even if the total lock time can be reduced, it's possible that interrupt handler is executed while the interrupted code is still holding the semaphore. I think your method only decrease the frequency of this problem. Why does reducing the lock time solve this problem?
there are several problems here that need addressing. It's not acceptable for our driver to wait up to 15 seconds, and we can (presumably) reduce it to milliseconds, so that would help a lot. We should in no case at all hold it for any period longer than (give or take) half a second, so working towards that is a very good step in the right direction.
Adding the timer task back may also help, as we are no longer trying to aqcuire the sw_fw_semaphore in interrupt context, but we removed it for a reason, and I need to dig up what reason this exactly was before we can revert it. Jesse might know, so I'll talk to him. But this will not fix the fact that the semaphore is held for a long time :)
so, this needs two fixes. much to do.
Cheers,
Auke
Quoted 12 lines · Auke Kok
Quoted 5 lines
Even if the total lock time can be reduced, it's possible that interrupt handler is executed while the interrupted code is still holding the semaphore.
I think your method only decrease the frequency of this problem. Why does reducing the lock time solve this problem?there are several problems here that need addressing. It's not acceptable for our driver to wait up to 15 seconds, and we can (presumably) reduce it to milliseconds, so that would help a lot. We should in no case at all hold it for any period longer than (give or take) half a second, so working towards that is a very good step in the right direction.
Quoted 5 lines
Adding the timer task back may also help, as we are no longer trying to aqcuire the
sw_fw_semaphorein interrupt context, but we removed it for a reason, and I need to dig up what reason this exactly was before we can revert it. Jesse might know, so I'll talk to him. But this will not fix the fact that the semaphore is held for a long time :)
Timer tasks that reschedule themselves are a pain. The watchdog timer task had a couple of race conditions that were thought to be better fixed by removing it all together. Please, let's not go down that road again!
Check out what you have to say about it, Auke. ;)
http://www.spinics.net/lists/netdev/msg03656.html
Shaw
Hi,
Quoted 17 lines
Quoted 11 lines
Quoted 5 lines
Even if the total lock time can be reduced, it's possible that interrupt handler is executed while the interrupted code is still holding the semaphore.
I think your method only decrease the frequency of this problem. Why does reducing the lock time solve this problem?there are several problems here that need addressing. It's not acceptable for our driver to wait up to 15 seconds, and we can (presumably) reduce it to milliseconds, so that would help a lot. We should in no case at all hold it for any period longer than (give or take) half a second, so working towards that is a very good step in the right direction.
Quoted 5 lines
Adding the timer task back may also help, as we are no longer trying to aqcuire the
sw_fw_semaphorein interrupt context, but we removed it for a reason, and I need to dig up what reason this exactly was before we can revert it. Jesse might know, so I'll talk to him. But this will not fix the fact that the semaphore is held for a long time :)
Quoted 3 lines
Timer tasks that reschedule themselves are a pain. The watchdog timer task had a couple of race conditions that were thought to be better fixed by removing it all together. Please, let's not go down that road again!
I understand that the watchdog_task could cause a race when the timer task and e1000_down runs concurrently, resulting in memory double free.
I think this problem occurs because interrupt handler is executed in same CPU as process that acquires semaphore.
How about disabling interrupt while the process is holding the semaphore? I think this is possible, if the total lock time has been reduced.
Signature · 1 line
Kenzi Iwami ([email protected])
Hi,
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 5 lines
Even if the total lock time can be reduced, it's possible that interrupt handler is executed while the interrupted code is still holding the semaphore.
I think your method only decrease the frequency of this problem. Why does reducing the lock time solve this problem?there are several problems here that need addressing. It's not acceptable for our driver to wait up to 15 seconds, and we can (presumably) reduce it to milliseconds, so that would help a lot. We should in no case at all hold it for any period longer than (give or take) half a second, so working towards that is a very good step in the right direction.
Adding the timer task back may also help, as we are no longer trying to aqcuire the
sw_fw_semaphorein interrupt context, but we removed it for a reason, and I need to dig up what reason this exactly was before we can revert it. Jesse might know, so I'll talk to him. But this will not fix the fact that the semaphore is held for a long time :)
[...]
Quoted 4 lines
I think this problem occurs because interrupt handler is executed in same CPU as process that acquires semaphore.
How about disabling interrupt while the process is holding the semaphore? I think this is possible, if the total lock time has been reduced.
I created the attached patch based on the method described above. This patch disables interrupt while the process is holding the semaphore.
I measured how long interrupts are being disabled 10,000 times using the following method. TSC was read by rdtscll when interrupt was disabled and interrupt was enabled again, then I subtract these two value.
The longest period interrupt was disabled is under 10usec, which seems acceptable. The evaluation environment is;
CPU : Intel Xeon CPU 3.73GHz
kernel : 2.6.19-rc5
I also ran the reproduction TP I sent previously and confirmed that the system didn't panic.
http://marc.theaimsgroup.com/?l=linux-netdev&m=116125332319850&w=2
How about this method?
I welcome any comments.
Signature · 71 lines
Kenzo Iwami ([email protected]) Signed-off-by: Kenzo Iwami <[email protected]> diff -urpN linux-2.6.19-rc5_org/drivers/net/e1000/e1000_hw.c linux-2.6.19-rc5/drivers/net/e1000/e1000_hw.c --- linux-2.6.19-rc5_org/drivers/net/e1000/e1000_hw.c 2006-11-14 17:47:28.000000000 +0900 +++ linux-2.6.19-rc5/drivers/net/e1000/e1000_hw.c 2006-11-15 17:49:39.000000000 +0900 @@ -3379,6 +3379,7 @@ e1000_swfw_sync_acquire(struct e1000_hw uint32_t swmask = mask; uint32_t fwmask = mask << 16; int32_t timeout = 200; + unsigned long flags; DEBUGFUNC("e1000_swfw_sync_acquire"); @@ -3389,8 +3390,11 @@ e1000_swfw_sync_acquire(struct e1000_hw return e1000_get_hw_eeprom_semaphore(hw); while (timeout) { - if (e1000_get_hw_eeprom_semaphore(hw)) + local_irq_save(flags); + if (e1000_get_hw_eeprom_semaphore(hw)) { + local_irq_restore(flags); return -E1000_ERR_SWFW_SYNC; + } swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC); if (!(swfw_sync & (fwmask | swmask))) { @@ -3400,6 +3404,7 @@ e1000_swfw_sync_acquire(struct e1000_hw /* firmware currently using resource (fwmask) */ /* or other software thread currently using resource (swmask) */ e1000_put_hw_eeprom_semaphore(hw); + local_irq_restore(flags); mdelay(5); timeout--; } @@ -3413,6 +3418,7 @@ e1000_swfw_sync_acquire(struct e1000_hw E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync); e1000_put_hw_eeprom_semaphore(hw); + local_irq_restore(flags); return E1000_SUCCESS; } @@ -3421,6 +3427,7 @@ e1000_swfw_sync_release(struct e1000_hw { uint32_t swfw_sync; uint32_t swmask = mask; + unsigned long flags; DEBUGFUNC("e1000_swfw_sync_release"); @@ -3434,6 +3441,7 @@ e1000_swfw_sync_release(struct e1000_hw return; } + local_irq_save(flags); /* if (e1000_get_hw_eeprom_semaphore(hw)) * return -E1000_ERR_SWFW_SYNC; */ while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS); @@ -3444,6 +3452,7 @@ e1000_swfw_sync_release(struct e1000_hw E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync); e1000_put_hw_eeprom_semaphore(hw); + local_irq_restore(flags); } /*****************************************************************************
Quoted 27 lines · Kenzo Iwami
Hi,
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Even if the total lock time can be reduced, it's possible that interrupt handler is executed while the interrupted code is still holding the semaphore. I think your method only decrease the frequency of this problem. Why does reducing the lock time solve this problem?
there are several problems here that need addressing. It's not acceptable for our driver to wait up to 15 seconds, and we can (presumably) reduce it to milliseconds, so that would help a lot. We should in no case at all hold it for any period longer than (give or take) half a second, so working towards that is a very good step in the right direction.
Adding the timer task back may also help, as we are no longer trying to aqcuire the
sw_fw_semaphorein interrupt context, but we removed it for a reason, and I need to dig up what reason this exactly was before we can revert it. Jesse might know, so I'll talk to him. But this will not fix the fact that the semaphore is held for a long time :)[...]
Quoted 4 lines
I think this problem occurs because interrupt handler is executed in same CPU as process that acquires semaphore.
How about disabling interrupt while the process is holding the semaphore? I think this is possible, if the total lock time has been reduced.I created the attached patch based on the method described above. This patch disables interrupt while the process is holding the semaphore.
I measured how long interrupts are being disabled 10,000 times using the following method. TSC was read by rdtscll when interrupt was disabled and interrupt was enabled again, then I subtract these two value.
The longest period interrupt was disabled is under 10usec, which seems acceptable. The evaluation environment is;
CPU : Intel Xeon CPU 3.73GHz
kernel : 2.6.19-rc5
Quoted 5 lines
I also ran the reproduction TP I sent previously and confirmed that the system didn't panic.
http://marc.theaimsgroup.com/?l=linux-netdev&m=116125332319850&w=2How about this method?
I'm not sure why you would have to disable interrupts when freeing the semaphore, but more importantly I don't want to introduce irq code in the swfw handling functions.
Since the major (only) user running this piece of code in intterupt context is the watchdog, we might as well see if we can only disable interrupts for that code path, which would only be once per 2 seconds. We don't need to protect the ethtool path into this code as it doesn't run in irq context.
Would you mind giving attached patch a try and let me know if it works for you? It will disable irqs for a bit longer time than your patch, and it begs for a special check-link-in-watchdog function that doesn't take so damn long :(
Thanks,
Auke
drivers/net/e1000/e1000_main.c +4 -0
@@ -2430,8 +2430,12 @@ e1000_watchdog(unsigned long data)struct e1000_tx_ring *txdr = adapter->tx_ring;uint32_t link, tctl;int32_t ret_val; +unsigned long flags; +local_irq_save (flags); ret_val =e1000_check_for_link (&adapter->hw); +local_irq_restore (flags); +if ((ret_val ==E1000_ERR_PHY ) && (adapter->hw.phy_type == e1000_phy_igp_3) && (E1000_READ_REG (&adapter->hw,CTRL ) &E1000_PHY_CTRL_GBE_DISABLE )) {
Hi,
Thank you for your comment.
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
I think this problem occurs because interrupt handler is executed in same CPU as process that acquires semaphore.
How about disabling interrupt while the process is holding the semaphore? I think this is possible, if the total lock time has been reduced.I created the attached patch based on the method described above. This patch disables interrupt while the process is holding the semaphore.
[...]
Quoted 11 lines
I'm not sure why you would have to disable interrupts when freeing the semaphore, but more importantly I don't want to introduce irq code in the swfw handling functions.
Since the major (only) user running this piece of code in intterupt context is the watchdog, we might as well see if we can only disable interrupts for that code path, which would only be once per 2 seconds. We don't need to protect the ethtool path into this code as it doesn't run in irq context.
Would you mind giving attached patch a try and let me know if it works for you? It will disable irqs for a bit longer time than your patch, and it begs for a special check-link-in-watchdog function that doesn't take so damn long :(
I tried your patch, but the system panicked with the same symptom.
This problem occurs because e1000_watchdog is called from the interrupt handler while ethtool processing is holding the semaphore.
ethtool processing holding semaphore
INTERRUPT
e1000_watchdog waits for semaphore to be released
The semaphore e1000_watchdog is waiting for can only be released when ethtool resumes from interrupt after e1000_watchdog finishes (basically a deadlock)
In order to solve this problem, interrupts has to be disabled on the interrupted side (during ethtool processing) and not during e1000_watchdog within the interrupt handler.
e1000_get_hw_eeprom_semaphore is called from both the interrupt level and the normal level, and needs to be protected by irq code. The reason the patch disables interrupts when freeing the semaphore is because e1000_swfw_sync_release also calls e1000_get_hw_eeprom_semaphore.
--
Kenzo Iwami ([email protected])
Hi,
I created a patch that uses watchdog_task but fixes the race condition that occurred in old the e1000 driver.
I've obtained information about the panic caused by the old e1000 driver using e1000_watchdog_task. According to the crash dump, the panic was caused by a timer_list whose contents were NULLs. Further trace information revealed that the function in the timer list was e1000_watchdog().
This function is registered in timer_list during e1000_watchdog_task. It seems that e1000_watchdog_task could be called after the adapter is removed, and freed memory is registered to timer_list.
By looking at the source code, e1000_watchdog_task will be scheduled if e1000_watchdog is invoked during e1000_remove, after flush_scheduled_work() is called, but before del_timer_sync() is called in e1000_down().
The attached patch adds back the e1000_watchdog_task(), but it will prevent the old race condition from happening by deleting e1000_watchdog from timer_list before flush_scheduled_work() is called.
Please incorporate this patch to e1000 source code. --
Kenzo Iwami ([email protected])
drivers/net/e1000/e1000.h +3 -0
@@ -268,6 +268,7 @@ struct e1000_adapter {uint16_t tx_itr;uint16_t rx_itr; +struct work_struct watchdog_task;struct work_struct reset_task;uint8_t fc_autoneg;
@@ -355,6 +356,8 @@ struct e1000_adapter {boolean_t quad_port_a;unsigned long flags;uint32_t eeprom_wol; +/* Indicates that the adapter is being removed if remove_state==1.*/ +int remove_state; };enum e1000_state_t {
drivers/net/e1000/e1000_main.c +26 -2
@@ -152,6 +152,7 @@ static void e1000_clean_rx_ring(struct estatic void e1000_set_multi (struct net_device *netdev);static void e1000_update_phy_info (unsigned long data);static void e1000_watchdog (unsigned long data); +static void e1000_watchdog_task (struct work_struct *work);static void e1000_82547_tx_fifo_stall (unsigned long data);static int e1000_xmit_frame (struct sk_buff *skb,struct net_device *netdev);static struct net_device_stats *e1000_get_stats (struct net_device *netdev);
@@ -1044,10 +1045,14 @@ e1000_probe(struct pci_dev *pdev, adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall; adapter->tx_fifo_stall_timer.data = (unsigned long ) adapter; + adapter->remove_state =0 ; +init_timer (&adapter->watchdog_timer); adapter->watchdog_timer.function = &e1000_watchdog; adapter->watchdog_timer.data = (unsigned long ) adapter; +INIT_WORK (&adapter->watchdog_task, e1000_watchdog_task); +init_timer (&adapter->phy_info_timer); adapter->phy_info_timer.function = &e1000_update_phy_info; adapter->phy_info_timer.data = (unsigned long ) adapter;
@@ -1219,7 +1224,15 @@ e1000_remove(struct pci_dev *pdev)#ifdef CONFIG_E1000_NAPI int i;#endif - +/* If e1000_watchdog runs between flush_scheduled_work and +* del_timer_sync(in e1000_down), e1000_watchdog_task is +* called after the adapter is removed. This will cause +* freed memory to be registered to timer list and +* result in system panic. Delete e1000_watchdog from +* timer list to prevent this from happening. +*/ + adapter->remove_state =1 ; +del_timer_sync (&adapter->watchdog_timer);flush_scheduled_work ();e1000_release_manageability (adapter);
@@ -2555,6 +2568,16 @@ static void e1000_watchdog(unsigned long data) {struct e1000_adapter *adapter = (struct e1000_adapter *) data; + +/* Do the rest outside of interrupt context */ +schedule_work (&adapter->watchdog_task); +} + +static void +e1000_watchdog_task (struct work_struct *work) +{ +struct e1000_adapter *adapter = + container_of(work, struct e1000_adapter, watchdog_task);struct net_device *netdev = adapter->netdev;struct e1000_tx_ring *txdr = adapter->tx_ring;uint32_t link, tctl;
@@ -2724,7 +2747,8 @@ e1000_watchdog(unsigned long data)e1000_rar_set (&adapter->hw, adapter->hw.mac_addr,0 );/* Reset the timer */ -mod_timer (&adapter->watchdog_timer, jiffies +2 *HZ ); +if (!adapter->remove_state) +mod_timer (&adapter->watchdog_timer, jiffies +2 *HZ ); }enum latency_range {
Quoted 15 lines · Kenzo Iwami
Hi,
I created a patch that uses
watchdog_taskbut fixes the race condition that occurred in old the e1000 driver.I've obtained information about the panic caused by the old e1000 driver using
e1000_watchdog_task. According to the crash dump, the panic was caused by atimer_listwhose contents were NULLs. Further trace information revealed that the function in the timer list wase1000_watchdog().This function is registered in
timer_listduringe1000_watchdog_task. It seems thate1000_watchdog_taskcould be called after the adapter is removed, and freed memory is registered totimer_list.
Quoted 7 lines
By looking at the source code,
e1000_watchdog_taskwill be scheduled ife1000_watchdogis invoked duringe1000_remove, afterflush_scheduled_work()is called, but beforedel_timer_sync()is called ine1000_down().The attached patch adds back the
e1000_watchdog_task(), but it will prevent the old race condition from happening by deletinge1000_watchdogfromtimer_listbeforeflush_scheduled_work()is called.
Kenzo,
this looks a lot better than the previous patch!! However, we already have a state marker for _down_ that we should probably reuse. Can you try the attached patch and see if it works for you? It's basically your patch without the added remove flag and instead using the already available atomic state trackers.
If this works for you then that is great news and I'll push this patch to the upstream kernel maintainers after testing.
Cheers,
Auke
drivers/net/e1000/e1000.h +1 -0
@@ -264,6 +264,7 @@ struct e1000_adapter {uint16_t rx_itr;struct work_struct reset_task; +struct work_struct watchdog_task;uint8_t fc_autoneg;struct timer_list blink_timer;
drivers/net/e1000/e1000_main.c +20 -1
@@ -152,6 +152,7 @@ static void e1000_clean_rx_ring(struct e1000_adapter *adapter,static void e1000_set_multi (struct net_device *netdev);static void e1000_update_phy_info (unsigned long data);static void e1000_watchdog (unsigned long data); +static void e1000_watchdog_task (struct work_struct *work);static void e1000_82547_tx_fifo_stall (unsigned long data);static int e1000_xmit_frame (struct sk_buff *skb,struct net_device *netdev);static struct net_device_stats *e1000_get_stats (struct net_device *netdev);
@@ -1049,6 +1050,7 @@ e1000_probe(struct pci_dev *pdev, adapter->phy_info_timer.data = (unsigned long ) adapter;INIT_WORK (&adapter->reset_task, e1000_reset_task); +INIT_WORK (&adapter->watchdog_task, e1000_watchdog_task);e1000_check_options (adapter);
@@ -1216,6 +1218,11 @@ e1000_remove(struct pci_dev *pdev)int i;#endif +/* flush_scheduled work may reschedule our watchdog task, so +* explicitly disable watchdog tasks from being rescheduled */ +set_bit (__E1000_DOWN, &adapter->flags); +del_timer_sync (&adapter->watchdog_timer); +flush_scheduled_work ();e1000_release_manageability (adapter);
@@ -2551,6 +2558,17 @@ static void e1000_watchdog(unsigned long data) {struct e1000_adapter *adapter = (struct e1000_adapter *) data; + +/* Do the rest outside of interrupt context */ +schedule_work (&adapter->watchdog_task); +} + +static void +e1000_watchdog_task (struct work_struct *work) +{ +struct e1000_adapter *adapter =container_of (work, + struct e1000_adapter, watchdog_task); +struct net_device *netdev = adapter->netdev;struct e1000_tx_ring *txdr = adapter->tx_ring;uint32_t link, tctl;
@@ -2721,7 +2739,8 @@ e1000_watchdog(unsigned long data)e1000_rar_set (&adapter->hw, adapter->hw.mac_addr,0 );/* Reset the timer */ -mod_timer (&adapter->watchdog_timer, jiffies +2 *HZ ); +if (!test_bit (__E1000_DOWN, &adapter->flags)) +mod_timer (&adapter->watchdog_timer, jiffies +2 *HZ ); }enum latency_range {
Hi,
Thank you for your comment.
Quoted 7 lines
this looks a lot better than the previous patch!! However, we already have a state marker for _down_ that we should probably reuse. Can you try the attached patch and see if it works for you? It's basically your patch without the added remove flag and instead using the already available atomic state trackers.
If this works for you then that is great news and I'll push this patch to the upstream kernel maintainers after testing.
I tested your patch and confirmed that the system didn't panic.
Please push the patch to the upstream kernel maintainers. --
Kenzo Iwami ([email protected])