Skip to content

Commit 0777061

Browse files
Arseniy Krasnovdavem330
authored andcommitted
virtio/vsock: don't use skbuff state to account credit
'skb->len' can vary when we partially read the data, this complicates the calculation of credit to be updated in 'virtio_transport_inc_rx_pkt()/ virtio_transport_dec_rx_pkt()'. Also in 'virtio_transport_dec_rx_pkt()' we were miscalculating the credit since 'skb->len' was redundant. For these reasons, let's replace the use of skbuff state to calculate new 'rx_bytes'/'fwd_cnt' values with explicit value as input argument. This makes code more simple, because it is not needed to change skbuff state before each call to update 'rx_bytes'/'fwd_cnt'. Fixes: 71dc9ec ("virtio/vsock: replace virtio_vsock_pkt with sk_buff") Signed-off-by: Arseniy Krasnov <[email protected]> Reviewed-by: Stefano Garzarella <[email protected]> Acked-by: Bobby Eshleman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cd35601 commit 0777061

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

net/vmw_vsock/virtio_transport_common.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,21 +241,18 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk,
241241
}
242242

243243
static bool virtio_transport_inc_rx_pkt(struct virtio_vsock_sock *vvs,
244-
struct sk_buff *skb)
244+
u32 len)
245245
{
246-
if (vvs->rx_bytes + skb->len > vvs->buf_alloc)
246+
if (vvs->rx_bytes + len > vvs->buf_alloc)
247247
return false;
248248

249-
vvs->rx_bytes += skb->len;
249+
vvs->rx_bytes += len;
250250
return true;
251251
}
252252

253253
static void virtio_transport_dec_rx_pkt(struct virtio_vsock_sock *vvs,
254-
struct sk_buff *skb)
254+
u32 len)
255255
{
256-
int len;
257-
258-
len = skb_headroom(skb) - sizeof(struct virtio_vsock_hdr) - skb->len;
259256
vvs->rx_bytes -= len;
260257
vvs->fwd_cnt += len;
261258
}
@@ -388,7 +385,9 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk,
388385
skb_pull(skb, bytes);
389386

390387
if (skb->len == 0) {
391-
virtio_transport_dec_rx_pkt(vvs, skb);
388+
u32 pkt_len = le32_to_cpu(virtio_vsock_hdr(skb)->len);
389+
390+
virtio_transport_dec_rx_pkt(vvs, pkt_len);
392391
consume_skb(skb);
393392
} else {
394393
__skb_queue_head(&vvs->rx_queue, skb);
@@ -437,17 +436,17 @@ static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk,
437436

438437
while (!msg_ready) {
439438
struct virtio_vsock_hdr *hdr;
439+
size_t pkt_len;
440440

441441
skb = __skb_dequeue(&vvs->rx_queue);
442442
if (!skb)
443443
break;
444444
hdr = virtio_vsock_hdr(skb);
445+
pkt_len = (size_t)le32_to_cpu(hdr->len);
445446

446447
if (dequeued_len >= 0) {
447-
size_t pkt_len;
448448
size_t bytes_to_copy;
449449

450-
pkt_len = (size_t)le32_to_cpu(hdr->len);
451450
bytes_to_copy = min(user_buf_len, pkt_len);
452451

453452
if (bytes_to_copy) {
@@ -484,7 +483,7 @@ static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk,
484483
msg->msg_flags |= MSG_EOR;
485484
}
486485

487-
virtio_transport_dec_rx_pkt(vvs, skb);
486+
virtio_transport_dec_rx_pkt(vvs, pkt_len);
488487
kfree_skb(skb);
489488
}
490489

@@ -1040,7 +1039,7 @@ virtio_transport_recv_enqueue(struct vsock_sock *vsk,
10401039

10411040
spin_lock_bh(&vvs->rx_lock);
10421041

1043-
can_enqueue = virtio_transport_inc_rx_pkt(vvs, skb);
1042+
can_enqueue = virtio_transport_inc_rx_pkt(vvs, len);
10441043
if (!can_enqueue) {
10451044
free_pkt = true;
10461045
goto out;

0 commit comments

Comments
 (0)