Skip to content

Commit

Permalink
vsock/virtio: use GFP_ATOMIC under RCU read lock
Browse files Browse the repository at this point in the history
virtio_transport_send_pkt in now called on transport fast path,
under RCU read lock. In that case, we have a bug: virtio_add_sgs
is called with GFP_KERNEL, and might sleep.

Pass the gfp flags as an argument, and use GFP_ATOMIC on
the fast path.

Link: https://lore.kernel.org/all/hfcr2aget2zojmqpr4uhlzvnep4vgskblx5b6xf2ddosbsrke7@nt34bxgp7j2x
Fixes: efcd71a ("vsock/virtio: avoid queuing packets when intermediate queue is empty")
Reported-by: Christian Brauner <[email protected]>
Cc: Stefano Garzarella <[email protected]>
Cc: Luigi Leonardi <[email protected]>
Message-ID: <3fbfb6e871f625f89eb578c7228e127437b1975a.1727876449.git.mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Reviewed-by: Pankaj Gupta <[email protected]>
Reviewed-by: Christian Brauner <[email protected]>
Reviewed-by: Luigi Leonardi <[email protected]>
Reviewed-by: Stefano Garzarella <[email protected]>
  • Loading branch information
mstsirkin committed Oct 7, 2024
1 parent b9efbe2 commit a194c98
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions net/vmw_vsock/virtio_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static u32 virtio_transport_get_local_cid(void)

/* Caller need to hold vsock->tx_lock on vq */
static int virtio_transport_send_skb(struct sk_buff *skb, struct virtqueue *vq,
struct virtio_vsock *vsock)
struct virtio_vsock *vsock, gfp_t gfp)
{
int ret, in_sg = 0, out_sg = 0;
struct scatterlist **sgs;
Expand Down Expand Up @@ -140,7 +140,7 @@ static int virtio_transport_send_skb(struct sk_buff *skb, struct virtqueue *vq,
}
}

ret = virtqueue_add_sgs(vq, sgs, out_sg, in_sg, skb, GFP_KERNEL);
ret = virtqueue_add_sgs(vq, sgs, out_sg, in_sg, skb, gfp);
/* Usually this means that there is no more space available in
* the vq
*/
Expand Down Expand Up @@ -178,7 +178,7 @@ virtio_transport_send_pkt_work(struct work_struct *work)

reply = virtio_vsock_skb_reply(skb);

ret = virtio_transport_send_skb(skb, vq, vsock);
ret = virtio_transport_send_skb(skb, vq, vsock, GFP_KERNEL);
if (ret < 0) {
virtio_vsock_skb_queue_head(&vsock->send_pkt_queue, skb);
break;
Expand Down Expand Up @@ -221,7 +221,7 @@ static int virtio_transport_send_skb_fast_path(struct virtio_vsock *vsock, struc
if (unlikely(ret == 0))
return -EBUSY;

ret = virtio_transport_send_skb(skb, vq, vsock);
ret = virtio_transport_send_skb(skb, vq, vsock, GFP_ATOMIC);
if (ret == 0)
virtqueue_kick(vq);

Expand Down

0 comments on commit a194c98

Please sign in to comment.