From: Hawkins Jiawei <yin31149@gmail.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: jasowang@redhat.com, eperezma@redhat.com, qemu-devel@nongnu.org,
qemu-stable@nongnu.org, 18801353760@163.com
Subject: Re: [PATCH RFC 1/1] vdpa: Return -EINVAL if device's ack is VIRTIO_NET_ERR
Date: Tue, 4 Jul 2023 09:33:30 +0800 [thread overview]
Message-ID: <CAKrof1O_YcMedVNfXitC=b6yXTTL2s9Uecj4LMr8hWGOkZTC+g@mail.gmail.com> (raw)
In-Reply-To: <20230703125134-mutt-send-email-mst@kernel.org>
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
>
prev parent reply other threads:[~2023-07-04 1:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAKrof1O_YcMedVNfXitC=b6yXTTL2s9Uecj4LMr8hWGOkZTC+g@mail.gmail.com' \
--to=yin31149@gmail.com \
--cc=18801353760@163.com \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).