Commit 47315329 authored by John Fastabend's avatar John Fastabend Committed by David S. Miller

virtio_net: wrap rtnl_lock in test for calling with lock already held

For XDP use case and to allow ethtool reset tests it is useful to be
able to use reset paths from contexts where rtnl lock is already
held.

This requries updating virtnet_set_queues and free_receive_bufs the
two places where rtnl_lock is taken in virtio_net. To do this we
use the following pattern,

	_foo(...) { do stuff }
	foo(...) { rtnl_lock(); _foo(...); rtnl_unlock()};

this allows us to use freeze()/restore() flow from both contexts.
Signed-off-by: default avatarJohn Fastabend <john.r.fastabend@intel.com>
Acked-by: default avatarJason Wang <jasowang@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 152bff37
...@@ -1305,7 +1305,7 @@ static void virtnet_ack_link_announce(struct virtnet_info *vi) ...@@ -1305,7 +1305,7 @@ static void virtnet_ack_link_announce(struct virtnet_info *vi)
rtnl_unlock(); rtnl_unlock();
} }
static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs) static int _virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
{ {
struct scatterlist sg; struct scatterlist sg;
struct net_device *dev = vi->dev; struct net_device *dev = vi->dev;
...@@ -1331,6 +1331,16 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs) ...@@ -1331,6 +1331,16 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
return 0; return 0;
} }
static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
{
int err;
rtnl_lock();
err = _virtnet_set_queues(vi, queue_pairs);
rtnl_unlock();
return err;
}
static int virtnet_close(struct net_device *dev) static int virtnet_close(struct net_device *dev)
{ {
struct virtnet_info *vi = netdev_priv(dev); struct virtnet_info *vi = netdev_priv(dev);
...@@ -1583,7 +1593,7 @@ static int virtnet_set_channels(struct net_device *dev, ...@@ -1583,7 +1593,7 @@ static int virtnet_set_channels(struct net_device *dev,
return -EINVAL; return -EINVAL;
get_online_cpus(); get_online_cpus();
err = virtnet_set_queues(vi, queue_pairs); err = _virtnet_set_queues(vi, queue_pairs);
if (!err) { if (!err) {
netif_set_real_num_tx_queues(dev, queue_pairs); netif_set_real_num_tx_queues(dev, queue_pairs);
netif_set_real_num_rx_queues(dev, queue_pairs); netif_set_real_num_rx_queues(dev, queue_pairs);
...@@ -1715,7 +1725,7 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog) ...@@ -1715,7 +1725,7 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog)
return -ENOMEM; return -ENOMEM;
} }
err = virtnet_set_queues(vi, curr_qp + xdp_qp); err = _virtnet_set_queues(vi, curr_qp + xdp_qp);
if (err) { if (err) {
dev_warn(&dev->dev, "XDP Device queue allocation failure.\n"); dev_warn(&dev->dev, "XDP Device queue allocation failure.\n");
return err; return err;
...@@ -1724,7 +1734,7 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog) ...@@ -1724,7 +1734,7 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog)
if (prog) { if (prog) {
prog = bpf_prog_add(prog, vi->max_queue_pairs - 1); prog = bpf_prog_add(prog, vi->max_queue_pairs - 1);
if (IS_ERR(prog)) { if (IS_ERR(prog)) {
virtnet_set_queues(vi, curr_qp); _virtnet_set_queues(vi, curr_qp);
return PTR_ERR(prog); return PTR_ERR(prog);
} }
} }
...@@ -1840,12 +1850,11 @@ static void virtnet_free_queues(struct virtnet_info *vi) ...@@ -1840,12 +1850,11 @@ static void virtnet_free_queues(struct virtnet_info *vi)
kfree(vi->sq); kfree(vi->sq);
} }
static void free_receive_bufs(struct virtnet_info *vi) static void _free_receive_bufs(struct virtnet_info *vi)
{ {
struct bpf_prog *old_prog; struct bpf_prog *old_prog;
int i; int i;
rtnl_lock();
for (i = 0; i < vi->max_queue_pairs; i++) { for (i = 0; i < vi->max_queue_pairs; i++) {
while (vi->rq[i].pages) while (vi->rq[i].pages)
__free_pages(get_a_page(&vi->rq[i], GFP_KERNEL), 0); __free_pages(get_a_page(&vi->rq[i], GFP_KERNEL), 0);
...@@ -1855,6 +1864,12 @@ static void free_receive_bufs(struct virtnet_info *vi) ...@@ -1855,6 +1864,12 @@ static void free_receive_bufs(struct virtnet_info *vi)
if (old_prog) if (old_prog)
bpf_prog_put(old_prog); bpf_prog_put(old_prog);
} }
}
static void free_receive_bufs(struct virtnet_info *vi)
{
rtnl_lock();
_free_receive_bufs(vi);
rtnl_unlock(); rtnl_unlock();
} }
...@@ -2293,9 +2308,7 @@ static int virtnet_probe(struct virtio_device *vdev) ...@@ -2293,9 +2308,7 @@ static int virtnet_probe(struct virtio_device *vdev)
goto free_unregister_netdev; goto free_unregister_netdev;
} }
rtnl_lock();
virtnet_set_queues(vi, vi->curr_queue_pairs); virtnet_set_queues(vi, vi->curr_queue_pairs);
rtnl_unlock();
/* Assume link up if device can't report link status, /* Assume link up if device can't report link status,
otherwise get link status from config. */ otherwise get link status from config. */
...@@ -2404,9 +2417,7 @@ static int virtnet_restore(struct virtio_device *vdev) ...@@ -2404,9 +2417,7 @@ static int virtnet_restore(struct virtio_device *vdev)
netif_device_attach(vi->dev); netif_device_attach(vi->dev);
rtnl_lock();
virtnet_set_queues(vi, vi->curr_queue_pairs); virtnet_set_queues(vi, vi->curr_queue_pairs);
rtnl_unlock();
err = virtnet_cpu_notif_add(vi); err = virtnet_cpu_notif_add(vi);
if (err) if (err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment