From: Hawkins Jiawei Date: Tue, 4 Jul 2023 03:34:33 +0000 (+0800) Subject: vdpa: Return -EIO if device ack is VIRTIO_NET_ERR in _load_mac() X-Git-Tag: qemu-xen-4.18.0-rc5~7 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=f43e4e2594195ba86ef8c2415f2e6ad826498104;p=qemu-xen.git vdpa: Return -EIO if device ack is VIRTIO_NET_ERR in _load_mac() 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: f73c0c43ac ("vdpa: extract vhost_vdpa_net_load_mac from vhost_vdpa_net_load") Signed-off-by: Hawkins Jiawei Acked-by: Jason Wang Acked-by: Eugenio Pérez Message-Id: Tested-by: Lei Yang Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin (cherry picked from commit b479bc3c9d5e473553137641fd31069c251f0d6e) Signed-off-by: Michael Tokarev --- diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 7c2c4fb7ea..92c74497b5 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -659,8 +659,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;