Skip to content

Commit

Permalink
vdpa: Return -EIO if device ack is VIRTIO_NET_ERR in _load_mac()
Browse files Browse the repository at this point in the history
According to VirtIO standard, "The class, command and
command-specific-data are set by the driver,
and the device sets the ack byte.
There is little it can do except issue a diagnostic
if ack is not VIRTIO_NET_OK."

Therefore, QEMU should stop sending the queued SVQ commands and
cancel the device startup if the device's ack is not VIRTIO_NET_OK.

Yet the problem is that, vhost_vdpa_net_load_mac() returns 1 based on
`*s->status != VIRTIO_NET_OK` when the device's ack is VIRTIO_NET_ERR.
As a result, net->nc->info->load() also returns 1, this makes
vhost_net_start_one() incorrectly assume the device state is
successfully loaded by vhost_vdpa_net_load() and return 0, instead of
goto `fail` label to cancel the device startup, as vhost_net_start_one()
only cancels the device startup when net->nc->info->load() returns a
negative value.

This patch fixes this problem by returning -EIO when the device's
ack is not VIRTIO_NET_OK.

Fixes: f73c0c4 ("vdpa: extract vhost_vdpa_net_load_mac from vhost_vdpa_net_load")
Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Acked-by: Eugenio Pérez <eperezma@redhat.com>
Message-Id: <a21731518644abbd0c495c5b7960527c5911f80d.1688438055.git.yin31149@gmail.com>
Tested-by: Lei Yang <leiyang@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
(cherry picked from commit b479bc3)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
  • Loading branch information
JiaweiHawk authored and Michael Tokarev committed Aug 5, 2023
1 parent 4e9a35d commit 5e67da9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions net/vhost-vdpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,9 @@ static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n)
if (unlikely(dev_written < 0)) {
return dev_written;
}

return *s->status != VIRTIO_NET_OK;
if (*s->status != VIRTIO_NET_OK) {
return -EIO;
}
}

return 0;
Expand Down

0 comments on commit 5e67da9

Please sign in to comment.