Q: what protects dev->napi_list?
Subsystems (2)
Hi,
Sylvain reported a netpoll CPU stall
http://marc.info/?l=linux-netdev&m=134563282530588&w=2
I tried to provide some fix for it:
http://marc.info/?l=linux-netdev&m=134571069921429&w=2
When reviewing that code, I noticed a problem, it seems dev->napi_list is not protected by any lock? What if the device driver calls netif_napi_del() meanwhile we are iterating &dev->napi_list in poll_napi()? It seems netif_napi_del()/netif_napi_add() are usually called with the RTNL lock held during driver init/uninit, but again poll_napi() doesn't have RTNL lock.
Am I missing anything?
Thanks!
Quoted 8 lines · Cong Wang
Hi,
Sylvain reported a netpoll CPU stall
http://marc.info/?l=linux-netdev&m=134563282530588&w=2I tried to provide some fix for it:
http://marc.info/?l=linux-netdev&m=134571069921429&w=2
Quoted 7 lines
When reviewing that code, I noticed a problem, it seems
dev->napi_listis not protected by any lock? What if the device driver callsnetif_napi_del()meanwhile we are iterating&dev->napi_listinpoll_napi()? It seems netif_napi_del()/netif_napi_add() are usually called with the RTNL lock held during driver init/uninit, but againpoll_napi()doesn't have RTNL lock.
Of course poll_napi() cant try to get RTNL (its a mutex by the way)
There are no problems, since :
netif_napi_add() is called at device open time (before napi_poll() can use it)
netif_napi_del() at device dismantle time (after making sure napi_poll() wont use the device again)
Quoted 19 lines · Eric Dumazet
Quoted 8 lines · Cong Wang
Hi,
Sylvain reported a netpoll CPU stall
http://marc.info/?l=linux-netdev&m=134563282530588&w=2I tried to provide some fix for it:
http://marc.info/?l=linux-netdev&m=134571069921429&w=2Quoted 7 lines
When reviewing that code, I noticed a problem, it seems
dev->napi_listis not protected by any lock? What if the device driver callsnetif_napi_del()meanwhile we are iterating&dev->napi_listinpoll_napi()? It seems netif_napi_del()/netif_napi_add() are usually called with the RTNL lock held during driver init/uninit, but againpoll_napi()doesn't have RTNL lock.Of course
poll_napi()cant try to get RTNL (its a mutex by the way)
Quoted 7 lines
There are no problems, since :
netif_napi_add()is called at device open time (beforenapi_poll()can use it)
netif_napi_del()at device dismantle time (after making surenapi_poll()wont use the device again)
Yeah, but bnx2 driver calls it at other time too, for example bnx2_change_ring_size() which in turn could be called by bnx2_set_channels().
Quoted 25 lines · Cong Wang
Quoted 24 lines · Eric Dumazet
Quoted 8 lines · Cong Wang
Hi,
Sylvain reported a netpoll CPU stall
http://marc.info/?l=linux-netdev&m=134563282530588&w=2I tried to provide some fix for it:
http://marc.info/?l=linux-netdev&m=134571069921429&w=2Quoted 7 lines
When reviewing that code, I noticed a problem, it seems
dev->napi_listis not protected by any lock? What if the device driver callsnetif_napi_del()meanwhile we are iterating&dev->napi_listinpoll_napi()? It seems netif_napi_del()/netif_napi_add() are usually called with the RTNL lock held during driver init/uninit, but againpoll_napi()doesn't have RTNL lock.Of course
poll_napi()cant try to get RTNL (its a mutex by the way)There are no problems, since :
netif_napi_add()is called at device open time (beforenapi_poll()can use it)
Quoted 6 lines
Quoted 2 lines
netif_napi_del()at device dismantle time (after making surenapi_poll()wont use the device again)Yeah, but bnx2 driver calls it at other time too, for example
bnx2_change_ring_size()which in turn could be called bybnx2_set_channels().
Then at this point, device is stopped, or should be.
Quoted 8 lines · Eric Dumazet
Quoted 4 lines · Cong Wang
Yeah, but bnx2 driver calls it at other time too, for example
bnx2_change_ring_size()which in turn could be called bybnx2_set_channels().Then at this point, device is stopped, or should be.
But poll_napi() is still iterating the dev->napi_list, could anyone stops it?
IOW, the following race condition may happen:
static void poll_napi(struct net_device *dev)
{
struct napi_struct *napi;
int budget = 16;
WARN_ON_ONCE(!irqs_disabled());
list_for_each_entry(napi, &dev->napi_list, dev_list) {
local_irq_enable();
//<-- Another process may call
//bnx2_change_ring_size() to del
//napi from dev, on other CPU.
local_irq_disable();
}
}Quoted 16 lines · Cong Wang
Quoted 8 lines · Eric Dumazet
Quoted 4 lines · Cong Wang
Yeah, but bnx2 driver calls it at other time too, for example
bnx2_change_ring_size()which in turn could be called bybnx2_set_channels().Then at this point, device is stopped, or should be.
But
poll_napi()is still iterating thedev->napi_list, could anyone stops it?IOW, the following race condition may happen:
static void
poll_napi(struct net_device *dev)
Quoted 18 lines
{
struct napi_struct *napi;
int budget = 16;
WARN_ON_ONCE(!irqs_disabled());
list_for_each_entry(napi, &dev->napi_list, dev_list) {
local_irq_enable();
//<-- Another process may call
//bnx2_change_ring_size() to del
//napi from dev, on other CPU.
local_irq_disable();
}
}Are you trying to say netpoll is buggy ?
Thats the first time I ear that !
Just kidding.
I repeat again : If bnx2_change_ring_size() is called while netconsole is able to enter poll_napi(), then netpoll is buggy and should be fixed.
napi_list is manipulated under a mutex protection, and there is no way netpoll can use a mutex. Same mutex protection for all other netdevice management, so even calling start_xmit() should be forbidden in this state.
Therefore, netpoll must be disabled while a device is reconfigured.