* [PATCH RFC 0/1] Return -EINVAL if device's ack is VIRTIO_NET_ERR
@ 2023-06-14 13:01 Hawkins Jiawei
2023-06-14 13:01 ` [PATCH RFC 1/1] vdpa: " Hawkins Jiawei
0 siblings, 1 reply; 6+ messages in thread
From: Hawkins Jiawei @ 2023-06-14 13:01 UTC (permalink / raw)
To: jasowang, mst, eperezma; +Cc: qemu-devel, qemu-stable, yin31149, 18801353760
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(-)
--
2.25.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH RFC 1/1] vdpa: Return -EINVAL if device's ack is VIRTIO_NET_ERR
2023-06-14 13:01 [PATCH RFC 0/1] Return -EINVAL if device's ack is VIRTIO_NET_ERR Hawkins Jiawei
@ 2023-06-14 13:01 ` Hawkins Jiawei
2023-07-03 16:38 ` Eugenio Perez Martin
2023-07-03 16:52 ` Michael S. Tsirkin
0 siblings, 2 replies; 6+ messages in thread
From: Hawkins Jiawei @ 2023-06-14 13:01 UTC (permalink / raw)
To: jasowang, mst, eperezma; +Cc: qemu-devel, qemu-stable, 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")
Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
---
net/vhost-vdpa.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index 37cdc84562..630c9bf71e 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH RFC 1/1] vdpa: Return -EINVAL if device's ack is VIRTIO_NET_ERR
2023-06-14 13:01 ` [PATCH RFC 1/1] vdpa: " Hawkins Jiawei
@ 2023-07-03 16:38 ` Eugenio Perez Martin
2023-07-04 1:28 ` Hawkins Jiawei
2023-07-03 16:52 ` Michael S. Tsirkin
1 sibling, 1 reply; 6+ messages in thread
From: Eugenio Perez Martin @ 2023-07-03 16:38 UTC (permalink / raw)
To: Hawkins Jiawei; +Cc: jasowang, mst, qemu-devel, qemu-stable, 18801353760
On Wed, Jun 14, 2023 at 3:02 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")
> Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
Maybe we could split the fixes? Either way:
Acked-by: Eugenio Pérez <eperezma@redhat.com>
Thanks!
> ---
> net/vhost-vdpa.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> index 37cdc84562..630c9bf71e 100644
> --- a/net/vhost-vdpa.c
> +++ b/net/vhost-vdpa.c
> @@ -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
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH RFC 1/1] vdpa: Return -EINVAL if device's ack is VIRTIO_NET_ERR
2023-06-14 13:01 ` [PATCH RFC 1/1] vdpa: " Hawkins Jiawei
2023-07-03 16:38 ` Eugenio Perez Martin
@ 2023-07-03 16:52 ` Michael S. Tsirkin
2023-07-04 1:33 ` Hawkins Jiawei
1 sibling, 1 reply; 6+ messages in thread
From: Michael S. Tsirkin @ 2023-07-03 16:52 UTC (permalink / raw)
To: Hawkins Jiawei; +Cc: jasowang, eperezma, qemu-devel, qemu-stable, 18801353760
On Wed, Jun 14, 2023 at 09:01:47PM +0800, Hawkins Jiawei 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")
> Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
> ---
> net/vhost-vdpa.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> index 37cdc84562..630c9bf71e 100644
> --- a/net/vhost-vdpa.c
> +++ b/net/vhost-vdpa.c
> @@ -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;
> }
I think EIO would be better, we have too many EINVAL cases,
making things hard to debug.
>
> static int vhost_vdpa_net_load(NetClientState *nc)
> --
> 2.25.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH RFC 1/1] vdpa: Return -EINVAL if device's ack is VIRTIO_NET_ERR
2023-07-03 16:38 ` Eugenio Perez Martin
@ 2023-07-04 1:28 ` Hawkins Jiawei
0 siblings, 0 replies; 6+ messages in thread
From: Hawkins Jiawei @ 2023-07-04 1:28 UTC (permalink / raw)
To: Eugenio Perez Martin; +Cc: jasowang, mst, qemu-devel, qemu-stable, 18801353760
On 2023/7/4 0:38, Eugenio Perez Martin wrote:
> On Wed, Jun 14, 2023 at 3:02 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")
>> Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
>
> Maybe we could split the fixes? Either way:
OK, I will split these fixes according to your suggestion.
Thanks!
>
> Acked-by: Eugenio Pérez <eperezma@redhat.com>
>
> Thanks!
>
>> ---
>> net/vhost-vdpa.c | 10 +++++++---
>> 1 file changed, 7 insertions(+), 3 deletions(-)
>>
>> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
>> index 37cdc84562..630c9bf71e 100644
>> --- a/net/vhost-vdpa.c
>> +++ b/net/vhost-vdpa.c
>> @@ -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
>>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH RFC 1/1] vdpa: Return -EINVAL if device's ack is VIRTIO_NET_ERR
2023-07-03 16:52 ` Michael S. Tsirkin
@ 2023-07-04 1:33 ` Hawkins Jiawei
0 siblings, 0 replies; 6+ messages in thread
From: Hawkins Jiawei @ 2023-07-04 1:33 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: jasowang, eperezma, qemu-devel, qemu-stable, 18801353760
On 2023/7/4 0:52, Michael S. Tsirkin wrote:
> On Wed, Jun 14, 2023 at 09:01:47PM +0800, Hawkins Jiawei 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")
>> Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
>> ---
>> net/vhost-vdpa.c | 10 +++++++---
>> 1 file changed, 7 insertions(+), 3 deletions(-)
>>
>> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
>> index 37cdc84562..630c9bf71e 100644
>> --- a/net/vhost-vdpa.c
>> +++ b/net/vhost-vdpa.c
>> @@ -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;
>> }
>
> 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!
>
>
>>
>> static int vhost_vdpa_net_load(NetClientState *nc)
>> --
>> 2.25.1
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-07-04 1:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-14 13:01 [PATCH RFC 0/1] Return -EINVAL if device's ack is VIRTIO_NET_ERR Hawkins Jiawei
2023-06-14 13:01 ` [PATCH RFC 1/1] vdpa: " Hawkins Jiawei
2023-07-03 16:38 ` Eugenio Perez Martin
2023-07-04 1:28 ` Hawkins Jiawei
2023-07-03 16:52 ` Michael S. Tsirkin
2023-07-04 1:33 ` Hawkins Jiawei
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.