Skip to content

Commit ac3d9dd

Browse files
Eric Dumazetdavem330
Eric Dumazet
authored andcommitted
netpoll: make ndo_poll_controller() optional
As diagnosed by Song Liu, ndo_poll_controller() can be very dangerous on loaded hosts, since the cpu calling ndo_poll_controller() might steal all NAPI contexts (for all RX/TX queues of the NIC). This capture can last for unlimited amount of time, since one cpu is generally not able to drain all the queues under load. It seems that all networking drivers that do use NAPI for their TX completions, should not provide a ndo_poll_controller(). NAPI drivers have netpoll support already handled in core networking stack, since netpoll_poll_dev() uses poll_napi(dev) to iterate through registered NAPI contexts for a device. This patch allows netpoll_poll_dev() to process NAPI contexts even for drivers not providing ndo_poll_controller(), allowing for following patches in NAPI drivers. Also we export netpoll_poll_dev() so that it can be called by bonding/team drivers in following patches. Reported-by: Song Liu <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Tested-by: Song Liu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 16fdf8b commit ac3d9dd

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

include/linux/netpoll.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ struct netpoll_info {
4949
};
5050

5151
#ifdef CONFIG_NETPOLL
52-
extern void netpoll_poll_disable(struct net_device *dev);
53-
extern void netpoll_poll_enable(struct net_device *dev);
52+
void netpoll_poll_dev(struct net_device *dev);
53+
void netpoll_poll_disable(struct net_device *dev);
54+
void netpoll_poll_enable(struct net_device *dev);
5455
#else
5556
static inline void netpoll_poll_disable(struct net_device *dev) { return; }
5657
static inline void netpoll_poll_enable(struct net_device *dev) { return; }

net/core/netpoll.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,16 @@ static void poll_napi(struct net_device *dev)
187187
}
188188
}
189189

190-
static void netpoll_poll_dev(struct net_device *dev)
190+
void netpoll_poll_dev(struct net_device *dev)
191191
{
192-
const struct net_device_ops *ops;
193192
struct netpoll_info *ni = rcu_dereference_bh(dev->npinfo);
193+
const struct net_device_ops *ops;
194194

195195
/* Don't do any rx activity if the dev_lock mutex is held
196196
* the dev_open/close paths use this to block netpoll activity
197197
* while changing device state
198198
*/
199-
if (down_trylock(&ni->dev_lock))
199+
if (!ni || down_trylock(&ni->dev_lock))
200200
return;
201201

202202
if (!netif_running(dev)) {
@@ -205,20 +205,16 @@ static void netpoll_poll_dev(struct net_device *dev)
205205
}
206206

207207
ops = dev->netdev_ops;
208-
if (!ops->ndo_poll_controller) {
209-
up(&ni->dev_lock);
210-
return;
211-
}
212-
213-
/* Process pending work on NIC */
214-
ops->ndo_poll_controller(dev);
208+
if (ops->ndo_poll_controller)
209+
ops->ndo_poll_controller(dev);
215210

216211
poll_napi(dev);
217212

218213
up(&ni->dev_lock);
219214

220215
zap_completion_queue();
221216
}
217+
EXPORT_SYMBOL(netpoll_poll_dev);
222218

223219
void netpoll_poll_disable(struct net_device *dev)
224220
{
@@ -613,8 +609,7 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
613609
strlcpy(np->dev_name, ndev->name, IFNAMSIZ);
614610
INIT_WORK(&np->cleanup_work, netpoll_async_cleanup);
615611

616-
if ((ndev->priv_flags & IFF_DISABLE_NETPOLL) ||
617-
!ndev->netdev_ops->ndo_poll_controller) {
612+
if (ndev->priv_flags & IFF_DISABLE_NETPOLL) {
618613
np_err(np, "%s doesn't support polling, aborting\n",
619614
np->dev_name);
620615
err = -ENOTSUPP;

0 commit comments

Comments
 (0)