History

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.

Eric Dumazet committed 8 years ago

Commit ac3d9dd1 parent 16fdf8b2 files · +10 −14Browse files

Unified · Split

2 files
  1. include/linux/netpoll.h +3 −2
  2. net/core/netpoll.c +7 −12
include/linux/netpoll.h+3−2
@@ -49,8 +49,9 @@ struct netpoll_info { · 48 unmodified lines
49};49};
50 50
51#ifdef CONFIG_NETPOLL51#ifdef CONFIG_NETPOLL
52extern void netpoll_poll_disable(struct net_device *dev);52void netpoll_poll_dev(struct net_device *dev);
53extern void netpoll_poll_enable(struct net_device *dev);53void netpoll_poll_disable(struct net_device *dev);
54void netpoll_poll_enable(struct net_device *dev);
54#else55#else
55static inline void netpoll_poll_disable(struct net_device *dev) { return; }56static inline void netpoll_poll_disable(struct net_device *dev) { return; }
56static inline void netpoll_poll_enable(struct net_device *dev) { return; }57static inline void netpoll_poll_enable(struct net_device *dev) { return; }
net/core/netpoll.c+7−12
@@ -187,16 +187,16 @@ static void poll_napi(struct net_device *dev) · 186 unmodified lines
187 }187 }
188}188}
189 189
190static void netpoll_poll_dev(struct net_device *dev)190void netpoll_poll_dev(struct net_device *dev)
191{191{
192 const struct net_device_ops *ops;
193 struct netpoll_info *ni = rcu_dereference_bh(dev->npinfo);192 struct netpoll_info *ni = rcu_dereference_bh(dev->npinfo);
193 const struct net_device_ops *ops;
194 194
195 /* Don't do any rx activity if the dev_lock mutex is held195 /* Don't do any rx activity if the dev_lock mutex is held
196 * the dev_open/close paths use this to block netpoll activity196 * the dev_open/close paths use this to block netpoll activity
197 * while changing device state197 * while changing device state
198 */198 */
199 if (down_trylock(&ni->dev_lock))199 if (!ni || down_trylock(&ni->dev_lock))
200 return;200 return;
201 201
202 if (!netif_running(dev)) {202 if (!netif_running(dev)) {
@@ -205,13 +205,8 @@ static void netpoll_poll_dev(struct net_device *dev) · 2 unmodified lines
205 }205 }
206 206
207 ops = dev->netdev_ops;207 ops = dev->netdev_ops;
208 if (!ops->ndo_poll_controller) {208 if (ops->ndo_poll_controller)
209 up(&ni->dev_lock);209 ops->ndo_poll_controller(dev);
210 return;
211 }
212
213 /* Process pending work on NIC */
214 ops->ndo_poll_controller(dev);
215 210
216 poll_napi(dev);211 poll_napi(dev);
217 212
@@ -219,6 +214,7 @@ static void netpoll_poll_dev(struct net_device *dev) · 1 unmodified line
219 214
220 zap_completion_queue();215 zap_completion_queue();
221}216}
217EXPORT_SYMBOL(netpoll_poll_dev);
222 218
223void netpoll_poll_disable(struct net_device *dev)219void netpoll_poll_disable(struct net_device *dev)
224{220{
@@ -613,8 +609,7 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev) · 388 unmodified lines
613 strlcpy(np->dev_name, ndev->name, IFNAMSIZ);609 strlcpy(np->dev_name, ndev->name, IFNAMSIZ);
614 INIT_WORK(&np->cleanup_work, netpoll_async_cleanup);610 INIT_WORK(&np->cleanup_work, netpoll_async_cleanup);
615 611
616 if ((ndev->priv_flags & IFF_DISABLE_NETPOLL) ||612 if (ndev->priv_flags & IFF_DISABLE_NETPOLL) {
617 !ndev->netdev_ops->ndo_poll_controller) {
618 np_err(np, "%s doesn't support polling, aborting\n",613 np_err(np, "%s doesn't support polling, aborting\n",
619 np->dev_name);614 np->dev_name);
620 err = -ENOTSUPP;615 err = -ENOTSUPP;