Skip to content

Commit 87dbae5

Browse files
willdeaconmstsirkin
authored andcommitted
vsock/virtio: Move length check to callers of virtio_vsock_skb_rx_put()
virtio_vsock_skb_rx_put() only calls skb_put() if the length in the packet header is not zero even though skb_put() handles this case gracefully. Remove the functionally redundant check from virtio_vsock_skb_rx_put() and, on the assumption that this is a worthwhile optimisation for handling credit messages, augment the existing length checks in virtio_transport_rx_work() to elide the call for zero-length payloads. Since the callers all have the length, extend virtio_vsock_skb_rx_put() to take it as an additional parameter rather than fish it back out of the packet header. Note that the vhost code already has similar logic in vhost_vsock_alloc_skb(). Reviewed-by: Stefano Garzarella <[email protected]> Signed-off-by: Will Deacon <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 0dab924 commit 87dbae5

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

drivers/vhost/vsock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ vhost_vsock_alloc_skb(struct vhost_virtqueue *vq,
375375
return NULL;
376376
}
377377

378-
virtio_vsock_skb_rx_put(skb);
378+
virtio_vsock_skb_rx_put(skb, payload_len);
379379

380380
nbytes = copy_from_iter(skb->data, payload_len, &iov_iter);
381381
if (nbytes != payload_len) {

include/linux/virtio_vsock.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,9 @@ static inline void virtio_vsock_skb_clear_tap_delivered(struct sk_buff *skb)
4747
VIRTIO_VSOCK_SKB_CB(skb)->tap_delivered = false;
4848
}
4949

50-
static inline void virtio_vsock_skb_rx_put(struct sk_buff *skb)
50+
static inline void virtio_vsock_skb_rx_put(struct sk_buff *skb, u32 len)
5151
{
52-
u32 len;
53-
54-
len = le32_to_cpu(virtio_vsock_hdr(skb)->len);
55-
56-
if (len > 0)
57-
skb_put(skb, len);
52+
skb_put(skb, len);
5853
}
5954

6055
static inline struct sk_buff *virtio_vsock_alloc_skb(unsigned int size, gfp_t mask)

net/vmw_vsock/virtio_transport.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,9 @@ static void virtio_transport_rx_work(struct work_struct *work)
656656
continue;
657657
}
658658

659-
virtio_vsock_skb_rx_put(skb);
659+
if (payload_len)
660+
virtio_vsock_skb_rx_put(skb, payload_len);
661+
660662
virtio_transport_deliver_tap_pkt(skb);
661663
virtio_transport_recv_pkt(&virtio_transport, skb);
662664
}

0 commit comments

Comments
 (0)