Return -EINVAL if device's ack is VIRTIO_NET_ERR
RFC PATCH 1/1 vdpa: Return -EINVAL if device's ack is VIRTIO_NET_ERR
In reply to Hawkins JiaweiAccording 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.
--- net/vhost-vdpa.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
net/vhost-vdpa.c +7 -3
@@ -651,8 +651,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 ;
@@ -676,8 +677,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 (NetClientState *nc)
Signature · 1 line
2.25.1
cover Return -EINVAL if device's ack is VIRTIO_NET_ERR
This patch fixes the problem that vhost_net_start_one() doesn't cancel the device startup and returns 0 even if the device's ack is VIRTIO_NET_ERR in net->nc->info->load().
Note that this problem also exists in
patch "vdpa: Add vhost_vdpa_net_load_offloads()" at [1]. Because this patch has not been merged yet, so I will submit the v2 patch to fix the problem in that patch once the pending patch
has been successfully merged.
[1]. https://lists.nongnu.org/archive/html/qemu-devel/2023-06/msg00504.html
Hawkins Jiawei (1):
vdpa: Return -EINVAL if device's ack is VIRTIO_NET_ERR
net/vhost-vdpa.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
Re: [PATCH RFC 1/1] vdpa: Return -EINVAL if device's ack is VIRTIO_NET_ERR
In reply to Hawkins JiaweiQuoted 19 lines · Hawkins Jiawei
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 notVIRTIO_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_OKwhen the device's ack isVIRTIO_NET_ERR. As a result,net->nc->info->load()also returns 1, this makesvhost_net_start_one()incorrectly assume the device state is successfully loaded byvhost_vdpa_net_load()and return 0, instead of gotofaillabel to cancel the device startup, asvhost_net_start_one()only cancels the device startup whennet->nc->info->load()returns a negative value.
Quoted 6 lines
This patch fixes this problem by returning
-EINVALwhen the device's ack is notVIRTIO_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")Signed-off-by Hawkins Jiawei <[email protected]>
Maybe we could split the fixes? Either way:
Thanks!
Quoted 36 lines
--- net/vhost-vdpa.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)net/vhost-vdpa.c +7
-4@@ -651,8 +651,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 ;@@ -676,8 +677,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 (NetClientState *nc) --2.25.1
Re: [PATCH RFC 1/1] vdpa: Return -EINVAL if device's ack is VIRTIO_NET_ERR
In reply to Hawkins JiaweiQuoted 45 lines · Hawkins Jiawei
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 notVIRTIO_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_OKwhen the device's ack isVIRTIO_NET_ERR. As a result,net->nc->info->load()also returns 1, this makesvhost_net_start_one()incorrectly assume the device state is successfully loaded byvhost_vdpa_net_load()and return 0, instead of gotofaillabel to cancel the device startup, asvhost_net_start_one()only cancels the device startup whennet->nc->info->load()returns a negative value.This patch fixes this problem by returning
-EINVALwhen the device's ack is notVIRTIO_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")Signed-off-by Hawkins Jiawei <[email protected]>--- net/vhost-vdpa.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)net/vhost-vdpa.c +3
-2@@ -651,8 +651,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 ;
net/vhost-vdpa.c static int vhost_vdpa_net_load_mq(VhostVDPAState *s, · line 685
Quoted 10 lines
net/vhost-vdpa.c +4
-1@@ -676,8 +677,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 ; }
I think EIO would be better, we have too many EINVAL cases, making things hard to debug.
Quoted 4 lines
net/vhost-vdpa.c +0
-0static int vhost_vdpa_net_load (NetClientState *nc)Signature · 1 line
2.25.1
Re: [PATCH RFC 1/1] vdpa: Return -EINVAL if device's ack is VIRTIO_NET_ERR
In reply to Eugenio Perez MartinQuoted 20 lines · Eugenio Perez Martin
Quoted 19 lines · Hawkins Jiawei
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 notVIRTIO_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_OKwhen the device's ack isVIRTIO_NET_ERR. As a result,net->nc->info->load()also returns 1, this makesvhost_net_start_one()incorrectly assume the device state is successfully loaded byvhost_vdpa_net_load()and return 0, instead of gotofaillabel to cancel the device startup, asvhost_net_start_one()only cancels the device startup whennet->nc->info->load()returns a negative value.
Quoted 8 lines
Quoted 6 lines
This patch fixes this problem by returning
-EINVALwhen the device's ack is notVIRTIO_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")Signed-off-by Hawkins Jiawei <[email protected]>Maybe we could split the fixes? Either way:
OK, I will split these fixes according to your suggestion.
Thanks!
Quoted 42 lines
Acked-by Eugenio Pérez <[email protected]>Thanks!
Quoted 36 lines
--- net/vhost-vdpa.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)net/vhost-vdpa.c +7
-4@@ -651,8 +651,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 ;@@ -676,8 +677,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 (NetClientState *nc) --2.25.1
Re: [PATCH RFC 1/1] vdpa: Return -EINVAL if device's ack is VIRTIO_NET_ERR
In reply to Michael S. TsirkinQuoted 53 lines · Michael S. Tsirkin
Quoted 52 lines · Hawkins Jiawei
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 notVIRTIO_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_OKwhen the device's ack isVIRTIO_NET_ERR. As a result,net->nc->info->load()also returns 1, this makesvhost_net_start_one()incorrectly assume the device state is successfully loaded byvhost_vdpa_net_load()and return 0, instead of gotofaillabel to cancel the device startup, asvhost_net_start_one()only cancels the device startup whennet->nc->info->load()returns a negative value.This patch fixes this problem by returning
-EINVALwhen the device's ack is notVIRTIO_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")Signed-off-by Hawkins Jiawei <[email protected]>--- net/vhost-vdpa.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)net/vhost-vdpa.c +6
-2@@ -651,8 +651,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 ;@@ -676,8 +677,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 ; + }
Quoted 6 lines
net/vhost-vdpa.c static int vhost_vdpa_net_load_mq(VhostVDPAState *s, · line 685
Quoted 3 lines
net/vhost-vdpa.c +1
-1-return *s->status !=VIRTIO_NET_OK ; +return 0 ; }I think EIO would be better, we have too many EINVAL cases, making things hard to debug.
I will refactor this patch to return -EIO according to your suggestion.
Thanks!
Quoted 8 lines
Quoted 7 lines
net/vhost-vdpa.c +0
-1static int vhost_vdpa_net_load (NetClientState *nc) --2.25.1