Skip to content

Commit cfbdab9

Browse files
Jason Wangmstsirkin
authored andcommitted
vhost-net: check the support of mergeable buffer outside the receive loop
No need to check the support of mergeable buffer inside the recevie loop as the whole handle_rx()_xx is in the read critical region. So this patch move it ahead of the receiving loop. Signed-off-by: Jason Wang <jasowang@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent fcc042a commit cfbdab9

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎drivers/vhost/net.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ static void handle_rx_mergeable(struct vhost_net *net)
411411
.hdr.gso_type = VIRTIO_NET_HDR_GSO_NONE
412412
};
413413
size_t total_len = 0;
414-
int err, headcount;
414+
int err, headcount, mergeable;
415415
size_t vhost_hlen, sock_hlen;
416416
size_t vhost_len, sock_len;
417417
/* TODO: check that we are running from vhost_worker? */
@@ -427,6 +427,7 @@ static void handle_rx_mergeable(struct vhost_net *net)
427427

428428
vq_log = unlikely(vhost_has_feature(&net->dev, VHOST_F_LOG_ALL)) ?
429429
vq->log : NULL;
430+
mergeable = vhost_has_feature(&net->dev, VIRTIO_NET_F_MRG_RXBUF);
430431

431432
while ((sock_len = peek_head_len(sock->sk))) {
432433
sock_len += sock_hlen;
@@ -476,7 +477,7 @@ static void handle_rx_mergeable(struct vhost_net *net)
476477
break;
477478
}
478479
/* TODO: Should check and handle checksum. */
479-
if (vhost_has_feature(&net->dev, VIRTIO_NET_F_MRG_RXBUF) &&
480+
if (likely(mergeable) &&
480481
memcpy_toiovecend(vq->hdr, (unsigned char *)&headcount,
481482
offsetof(typeof(hdr), num_buffers),
482483
sizeof hdr.num_buffers)) {

0 commit comments

Comments
 (0)