* [PATCH v2] vdpa: Return -EINVAL if device ack is VIRTIO_NET_ERR
@ 2023-06-27 14:35 Hawkins Jiawei
2023-06-28 4:09 ` Jason Wang
0 siblings, 1 reply; 2+ messages in thread
From: Hawkins Jiawei @ 2023-06-27 14:35 UTC (permalink / raw)
To: jasowang, mst, eperezma; +Cc: qemu-stable, qemu-devel, yin31149, 18801353760
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_x() 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 -EINVAL when the device's
ack is not VIRTIO_NET_OK.
Fixes: f73c0c43ac ("vdpa: extract vhost_vdpa_net_load_mac from vhost_vdpa_net_load")
Fixes: f64c7cda69 ("vdpa: Add vhost_vdpa_net_load_mq")
Fixes: 0b58d3686a ("vdpa: Add vhost_vdpa_net_load_offloads()")
Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
---
v2:
- fix the same bug in vhost_vdpa_net_load_offloads()
v1: https://lore.kernel.org/all/cover.1686746406.git.yin31149@gmail.com/
net/vhost-vdpa.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index e19ab063fa..6f6a5c6df6 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -646,8 +646,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 -EINVAL;
+ }
}
return 0;
@@ -670,8 +671,11 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s,
if (unlikely(dev_written < 0)) {
return dev_written;
}
+ if (*s->status != VIRTIO_NET_OK) {
+ return -EINVAL;
+ }
- return *s->status != VIRTIO_NET_OK;
+ return 0;
}
static int vhost_vdpa_net_load_offloads(VhostVDPAState *s,
@@ -708,8 +712,11 @@ static int vhost_vdpa_net_load_offloads(VhostVDPAState *s,
if (unlikely(dev_written < 0)) {
return dev_written;
}
+ if (*s->status != VIRTIO_NET_OK) {
+ return -EINVAL;
+ }
- return *s->status != VIRTIO_NET_OK;
+ return 0;
}
static int vhost_vdpa_net_load(NetClientState *nc)
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] vdpa: Return -EINVAL if device ack is VIRTIO_NET_ERR
2023-06-27 14:35 [PATCH v2] vdpa: Return -EINVAL if device ack is VIRTIO_NET_ERR Hawkins Jiawei
@ 2023-06-28 4:09 ` Jason Wang
0 siblings, 0 replies; 2+ messages in thread
From: Jason Wang @ 2023-06-28 4:09 UTC (permalink / raw)
To: Hawkins Jiawei; +Cc: mst, eperezma, qemu-stable, qemu-devel, 18801353760
On Tue, Jun 27, 2023 at 10:36 PM Hawkins Jiawei <yin31149@gmail.com> wrote:
>
> 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_x() 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 -EINVAL when the device's
> ack is not VIRTIO_NET_OK.
>
> Fixes: f73c0c43ac ("vdpa: extract vhost_vdpa_net_load_mac from vhost_vdpa_net_load")
> Fixes: f64c7cda69 ("vdpa: Add vhost_vdpa_net_load_mq")
> Fixes: 0b58d3686a ("vdpa: Add vhost_vdpa_net_load_offloads()")
> Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Thanks
> ---
> v2:
> - fix the same bug in vhost_vdpa_net_load_offloads()
>
> v1: https://lore.kernel.org/all/cover.1686746406.git.yin31149@gmail.com/
>
> net/vhost-vdpa.c | 15 +++++++++++----
> 1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> index e19ab063fa..6f6a5c6df6 100644
> --- a/net/vhost-vdpa.c
> +++ b/net/vhost-vdpa.c
> @@ -646,8 +646,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 -EINVAL;
> + }
> }
>
> return 0;
> @@ -670,8 +671,11 @@ static int vhost_vdpa_net_load_mq(VhostVDPAState *s,
> if (unlikely(dev_written < 0)) {
> return dev_written;
> }
> + if (*s->status != VIRTIO_NET_OK) {
> + return -EINVAL;
> + }
>
> - return *s->status != VIRTIO_NET_OK;
> + return 0;
> }
>
> static int vhost_vdpa_net_load_offloads(VhostVDPAState *s,
> @@ -708,8 +712,11 @@ static int vhost_vdpa_net_load_offloads(VhostVDPAState *s,
> if (unlikely(dev_written < 0)) {
> return dev_written;
> }
> + if (*s->status != VIRTIO_NET_OK) {
> + return -EINVAL;
> + }
>
> - return *s->status != VIRTIO_NET_OK;
> + return 0;
> }
>
> static int vhost_vdpa_net_load(NetClientState *nc)
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-06-28 4:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-27 14:35 [PATCH v2] vdpa: Return -EINVAL if device ack is VIRTIO_NET_ERR Hawkins Jiawei
2023-06-28 4:09 ` Jason Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).