Skip to content

Commit 6f45ab3

Browse files
danielj-mellanoxPaolo Abeni
authored and
Paolo Abeni
committed
virtio_net: Add a lock for the command VQ.
The command VQ will no longer be protected by the RTNL lock. Use a mutex to protect the control buffer header and the VQ. Signed-off-by: Daniel Jurgens <danielj@nvidia.com> Reviewed-by: Jiri Pirko <jiri@nvidia.com> Reviewed-by: Heng Qi <hengqi@linux.alibaba.com> Tested-by: Heng Qi <hengqi@linux.alibaba.com> Acked-by: Jason Wang <jasowang@redhat.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent ff7c7d9 commit 6f45ab3

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

drivers/net/virtio_net.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ struct virtnet_info {
411411
/* Has control virtqueue */
412412
bool has_cvq;
413413

414+
/* Lock to protect the control VQ */
415+
struct mutex cvq_lock;
416+
414417
/* Host can handle any s/g split between our header and packet data */
415418
bool any_header_sg;
416419

@@ -2675,6 +2678,7 @@ static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd
26752678
/* Caller should know better */
26762679
BUG_ON(!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ));
26772680

2681+
mutex_lock(&vi->cvq_lock);
26782682
vi->ctrl->status = ~0;
26792683
vi->ctrl->hdr.class = class;
26802684
vi->ctrl->hdr.cmd = cmd;
@@ -2697,11 +2701,12 @@ static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd
26972701
if (ret < 0) {
26982702
dev_warn(&vi->vdev->dev,
26992703
"Failed to add sgs for command vq: %d\n.", ret);
2704+
mutex_unlock(&vi->cvq_lock);
27002705
return false;
27012706
}
27022707

27032708
if (unlikely(!virtqueue_kick(vi->cvq)))
2704-
return vi->ctrl->status == VIRTIO_NET_OK;
2709+
goto unlock;
27052710

27062711
/* Spin for a response, the kick causes an ioport write, trapping
27072712
* into the hypervisor, so the request should be handled immediately.
@@ -2712,6 +2717,8 @@ static bool virtnet_send_command_reply(struct virtnet_info *vi, u8 class, u8 cmd
27122717
cpu_relax();
27132718
}
27142719

2720+
unlock:
2721+
mutex_unlock(&vi->cvq_lock);
27152722
return vi->ctrl->status == VIRTIO_NET_OK;
27162723
}
27172724

@@ -5736,6 +5743,8 @@ static int virtnet_probe(struct virtio_device *vdev)
57365743
if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ))
57375744
vi->has_cvq = true;
57385745

5746+
mutex_init(&vi->cvq_lock);
5747+
57395748
if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
57405749
mtu = virtio_cread16(vdev,
57415750
offsetof(struct virtio_net_config,

0 commit comments

Comments
 (0)