Skip to content

Commit

Permalink
vhost/net: Set num_buffers for virtio 1.0
Browse files Browse the repository at this point in the history
The specification says the device MUST set num_buffers to 1 if
VIRTIO_NET_F_MRG_RXBUF has not been negotiated.

Fixes: 41e3e42 ("vhost/net: enable virtio 1.0")
Signed-off-by: Akihiko Odaki <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
  • Loading branch information
akihikodaki authored and mstsirkin committed Jan 27, 2025
1 parent 5abfb22 commit a3b9c05
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/vhost/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,7 @@ static void handle_rx(struct vhost_net *net)
size_t vhost_hlen, sock_hlen;
size_t vhost_len, sock_len;
bool busyloop_intr = false;
bool set_num_buffers;
struct socket *sock;
struct iov_iter fixup;
__virtio16 num_buffers;
Expand All @@ -1129,6 +1130,8 @@ static void handle_rx(struct vhost_net *net)
vq_log = unlikely(vhost_has_feature(vq, VHOST_F_LOG_ALL)) ?
vq->log : NULL;
mergeable = vhost_has_feature(vq, VIRTIO_NET_F_MRG_RXBUF);
set_num_buffers = mergeable ||
vhost_has_feature(vq, VIRTIO_F_VERSION_1);

do {
sock_len = vhost_net_rx_peek_head_len(net, sock->sk,
Expand Down Expand Up @@ -1205,7 +1208,7 @@ static void handle_rx(struct vhost_net *net)
/* TODO: Should check and handle checksum. */

num_buffers = cpu_to_vhost16(vq, headcount);
if (likely(mergeable) &&
if (likely(set_num_buffers) &&
copy_to_iter(&num_buffers, sizeof num_buffers,
&fixup) != sizeof num_buffers) {
vq_err(vq, "Failed num_buffers write");
Expand Down

0 comments on commit a3b9c05

Please sign in to comment.