From: "Zhu, Lingshan" <lingshan.zhu@intel.com>
To: Eugenio Perez Martin <eperezma@redhat.com>
Cc: jasowang@redhat.com, qemu-devel@nongnu.org
Subject: Re: [PATCH] vdpa: dont check vhost_vdpa->suspended when unsupported
Date: Thu, 8 Jun 2023 17:34:01 +0800 [thread overview]
Message-ID: <b3b911b8-3064-21cf-7fa5-adfb597d8cf7@intel.com> (raw)
In-Reply-To: <CAJaqyWfgeN1u97z5W0Z6cCrJYrZBRV1p9je3_DoOv2XghY9XTw@mail.gmail.com>
On 6/8/2023 4:49 PM, Eugenio Perez Martin wrote:
> On Thu, Jun 8, 2023 at 9:07 AM Zhu, Lingshan <lingshan.zhu@intel.com> wrote:
>>
>>
>> On 6/7/2023 9:51 PM, Eugenio Perez Martin wrote:
>>> On Wed, Jun 7, 2023 at 11:09 AM Zhu Lingshan <lingshan.zhu@intel.com> wrote:
>>>> When read the state of a virtqueue, vhost_vdpa need
>>>> to check whether the device is suspended.
>>>>
>>>> This commit verifies whether VHOST_BACKEND_F_SUSPEND is
>>>> negotiated when checking vhost_vdpa->suspended.
>>>>
>>> I'll add: Otherwise, qemu prints XXX error message.
>>>
>>> On second thought, not returning an error prevents the caller
>>> (vhost.c:vhost_virtqueue_stop) from recovering used idx from the
>>> guest.
>>>
>>> I'm not sure about the right fix for this, should we call
>>> virtio_queue_restore_last_avail_idx here? Communicate that the backend
>>> cannot suspend so vhost.c can print a better error message?
>> I agree it is better not to return an error.
>>
>> Instead if neither the device does not support _F_SUSPEND nor failed to
>> suspend,
>> I think vhost_vdpa should try to read the last_avail_idx from
>> the device anyway. We can print an error message here,
>> like: failed to suspend, the value may not reliable.
>>
> We need to drop that value if it is not reliable. If the device keeps
> using descriptors, used_idx may increase beyond avail_idx, so the
> usual is to just restore whatever used_idx value the guest had at
> stop.
This interface is used to read the last_avail_idx, the ideal case
is to fetch it after device has been suspended.
If the device is not suspended, the value may be unreliable
because the device may keep consuming descriptors.
However at that moment, the guest may be freezed as well,
so the guest wouldn't supply more available descriptors to the device.
I think that means the last_avail_idx may not be reliable but still safe,
better than read nothing. Because the last_avail_idx always lags behind
the in-guest avail_idx.
I am not sure we can restore last_avail_idx with last_used_idx, there is
always
a delta between them.
Thanks
> Thanks!
>
>> Thanks
>>> Thanks!
>>>
>>>> Signed-off-by: Zhu Lingshan <lingshan.zhu@intel.com>
>>>> ---
>>>> hw/virtio/vhost-vdpa.c | 2 +-
>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
>>>> index b3094e8a8b..ae176c06dd 100644
>>>> --- a/hw/virtio/vhost-vdpa.c
>>>> +++ b/hw/virtio/vhost-vdpa.c
>>>> @@ -1397,7 +1397,7 @@ static int vhost_vdpa_get_vring_base(struct vhost_dev *dev,
>>>> return 0;
>>>> }
>>>>
>>>> - if (!v->suspended) {
>>>> + if ((dev->backend_cap & BIT_ULL(VHOST_BACKEND_F_SUSPEND)) && (!v->suspended)) {
>>>> /*
>>>> * Cannot trust in value returned by device, let vhost recover used
>>>> * idx from guest.
>>>> --
>>>> 2.39.1
>>>>
next prev parent reply other threads:[~2023-06-08 9:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-07 17:08 [PATCH] vdpa: dont check vhost_vdpa->suspended when unsupported Zhu Lingshan
2023-06-07 13:51 ` Eugenio Perez Martin
2023-06-08 7:07 ` Zhu, Lingshan
2023-06-08 8:49 ` Eugenio Perez Martin
2023-06-08 9:34 ` Zhu, Lingshan [this message]
2023-06-08 10:59 ` Eugenio Perez Martin
2023-06-08 13:19 ` Zhu, Lingshan
2023-06-08 14:38 ` Eugenio Perez Martin
2023-06-09 3:13 ` Jason Wang
2023-06-09 8:49 ` Zhu, Lingshan
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=b3b911b8-3064-21cf-7fa5-adfb597d8cf7@intel.com \
--to=lingshan.zhu@intel.com \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=qemu-devel@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).