From: Si-Wei Liu <si-wei.liu@oracle.com>
To: Jason Wang <jasowang@redhat.com>,
08005325@163.com, Eugenio Perez Martin <eperezma@redhat.com>
Cc: Zhu Lingshan <lingshan.zhu@intel.com>,
Michael Qiu <qiudayu@archeros.com>, Cindy Lu <lulu@redhat.com>,
qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [PATCH] vdpa: Avoid reset when stop device
Date: Thu, 24 Mar 2022 23:32:10 -0700 [thread overview]
Message-ID: <df7c9a87-b2bd-7758-a6b6-bd834a7336fe@oracle.com> (raw)
In-Reply-To: <CACGkMEsjQp+gjHV23ntJ2oTBCdt-1TT0GGn-PFDjOvETz6sQ7A@mail.gmail.com>
On 3/23/2022 2:20 AM, Jason Wang wrote:
> Adding Eugenio, and Ling Shan.
>
> On Wed, Mar 23, 2022 at 4:58 PM <08005325@163.com> wrote:
>> From: Michael Qiu <qiudayu@archeros.com>
>>
>> Currently, when VM poweroff, it will trigger vdpa
>> device(such as mlx bluefield2 VF) reset twice, this leads
>> to below issue:
>>
>> vhost VQ 2 ring restore failed: -22: Invalid argument (22)
>>
>> This because in vhost_dev_stop(), qemu tries to stop the device,
>> then stop the queue: vhost_virtqueue_stop().
>> In vhost_dev_stop(), it resets the device, which clear some flags
>> in low level driver, and the driver finds
>> that the VQ is invalied, this is the root cause.
>>
>> Actually, device reset will be called within func release()
>>
>> To solve the issue, vdpa should set vring unready, and
>> remove reset ops in device stop: vhost_dev_start(hdev, false).
> This is an interesting issue. Do you see a real issue except for the
> above warnings.
>
> The reason we "abuse" reset is that we don't have a stop uAPI for
> vhost. We plan to add a status bit to stop the whole device in the
> virtio spec, but considering it may take a while maybe we can first
> introduce a new uAPI/ioctl for that.
Yep. What was missing here is a vdpa specific uAPI for per-virtqueue
stop/suspend rather than spec level amendment to stop the whole device
(including both vq and config space). For now we can have vDPA specific
means to control the vq, something vDPA hardware vendor must support for
live migration, e.g. datapath switching to shadow vq. I believe the spec
amendment may follow to define a bit for virtio feature negotiation
later on if needed (FWIW virtio-vdpa already does set_vq_ready(..., 0)
to stop the vq).
However, there's a flaw in this patch, see below.
>
> Note that the stop doesn't just work for virtqueue but others like,
> e.g config space. But considering we don't have config interrupt
> support right now, we're probably fine.
>
> Checking the driver, it looks to me only the IFCVF's set_vq_ready() is
> problematic, Ling Shan, please have a check. And we probably need a
> workaround for vp_vdpa as well.
>
> Anyhow, this seems to be better than reset. So for 7.1:
>
> Acked-by: Jason Wang <jasowang@redhat.com>
>
>> Signed-off-by: Michael Qiu<qiudayu@archeros.com>
>> ---
>> hw/virtio/vhost-vdpa.c | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
>> index c5ed7a3..d858b4f 100644
>> --- a/hw/virtio/vhost-vdpa.c
>> +++ b/hw/virtio/vhost-vdpa.c
>> @@ -719,14 +719,14 @@ static int vhost_vdpa_get_vq_index(struct vhost_dev *dev, int idx)
>> return idx;
>> }
>>
>> -static int vhost_vdpa_set_vring_ready(struct vhost_dev *dev)
>> +static int vhost_vdpa_set_vring_ready(struct vhost_dev *dev, unsigned int ready)
>> {
>> int i;
>> trace_vhost_vdpa_set_vring_ready(dev);
>> for (i = 0; i < dev->nvqs; ++i) {
>> struct vhost_vring_state state = {
>> .index = dev->vq_index + i,
>> - .num = 1,
>> + .num = ready,
>> };
>> vhost_vdpa_call(dev, VHOST_VDPA_SET_VRING_ENABLE, &state);
>> }
>> @@ -1088,8 +1088,9 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
>> if (unlikely(!ok)) {
>> return -1;
>> }
>> - vhost_vdpa_set_vring_ready(dev);
>> + vhost_vdpa_set_vring_ready(dev, 1);
>> } else {
>> + vhost_vdpa_set_vring_ready(dev, 0);
>> ok = vhost_vdpa_svqs_stop(dev);
>> if (unlikely(!ok)) {
>> return -1;
>> @@ -1105,7 +1106,6 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
>> memory_listener_register(&v->listener, &address_space_memory);
>> return vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
>> } else {
>> - vhost_vdpa_reset_device(dev);
Unfortunately, the reset can't be be removed from here as this code path
usually involves virtio reset or status change for e.g. invoked via
virtio_net_set_status(... , 0). Ideally we should use the
VhostOps.vhost_reset_device() to reset the vhost-vdpa device where
status change is involved after vhost_dev_stop() is done, but this
distinction is not there yet as of today in all of the virtio devices
except vhost_user_scsi.
Alternatively we may be able to do something like below, stop the
virtqueue in vhost_vdpa_get_vring_base() in the vhost_virtqueue_stop()
context. Only until the hardware vq is stopped, svq can stop and unmap
then vhost-vdpa would reset the device status. It kinda works, but not
in a perfect way...
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -564,14 +564,14 @@ static int vhost_vdpa_get_vq_index(struct
vhost_dev *dev, int idx)
return idx;
}
-static int vhost_vdpa_set_vring_ready(struct vhost_dev *dev)
+static int vhost_vdpa_set_vring_ready(struct vhost_dev *dev, int enable)
{
int i;
trace_vhost_vdpa_set_vring_ready(dev);
for (i = 0; i < dev->nvqs; ++i) {
struct vhost_vring_state state = {
.index = dev->vq_index + i,
- .num = 1,
+ .num = enable,
};
vhost_vdpa_call(dev, VHOST_VDPA_SET_VRING_ENABLE, &state);
}
@@ -641,7 +641,7 @@ static int vhost_vdpa_dev_start(struct vhost_dev
*dev, bool started)
if (started) {
vhost_vdpa_host_notifiers_init(dev);
- vhost_vdpa_set_vring_ready(dev);
+ vhost_vdpa_set_vring_ready(dev, 1);
} else {
vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs);
}
@@ -708,6 +708,9 @@ static int vhost_vdpa_get_vring_base(struct
vhost_dev *dev,
{
int ret;
+ /* Deactivate the queue (best effort) */
+ vhost_vdpa_set_vring_ready(dev, 0);
+
ret = vhost_vdpa_call(dev, VHOST_GET_VRING_BASE, ring);
trace_vhost_vdpa_get_vring_base(dev, ring->index, ring->num);
return ret;
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 437347a..2e917d8 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -1832,15 +1832,15 @@ void vhost_dev_stop(struct vhost_dev *hdev,
VirtIODevice *vdev)
/* should only be called after backend is connected */
assert(hdev->vhost_ops);
- if (hdev->vhost_ops->vhost_dev_start) {
- hdev->vhost_ops->vhost_dev_start(hdev, false);
- }
for (i = 0; i < hdev->nvqs; ++i) {
vhost_virtqueue_stop(hdev,
vdev,
hdev->vqs + i,
hdev->vq_index + i);
}
+ if (hdev->vhost_ops->vhost_dev_start) {
+ hdev->vhost_ops->vhost_dev_start(hdev, false);
+ }
if (vhost_dev_has_iommu(hdev)) {
if (hdev->vhost_ops->vhost_set_iotlb_callback) {
Regards,
-Siwei
>> vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE |
>> VIRTIO_CONFIG_S_DRIVER);
>> memory_listener_unregister(&v->listener);
>> --
>> 1.8.3.1
>>
>
next prev parent reply other threads:[~2022-03-25 6:35 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-23 8:42 [PATCH] vdpa: Avoid reset when stop device 08005325
2022-03-23 9:20 ` Jason Wang
2022-03-25 6:32 ` Si-Wei Liu [this message]
[not found] ` <fe13304f-0a18-639e-580d-ce6eb7daecab@archeros.com>
2022-03-25 19:19 ` Si-Wei Liu
[not found] ` <6fbf82a9-39ce-f179-5e4b-384123ca542c@archeros.com>
2022-03-25 19:59 ` Si-Wei Liu
2022-03-30 8:52 ` Jason Wang
2022-03-30 9:53 ` Michael Qiu
2022-03-30 10:02 ` [PATCH v2] vdpa: reset the backend device in stage of stop last vhost device 08005325
2022-03-30 10:52 ` Michael S. Tsirkin
2022-03-31 1:39 ` Michael Qiu
2022-03-31 0:15 ` Si-Wei Liu
2022-03-31 4:01 ` Michael Qiu
2022-03-31 4:02 ` Michael Qiu
2022-03-31 5:19 ` [PATCH v3] vdpa: reset the backend device in the end of vhost_net_stop() 08005325
2022-03-31 8:55 ` Jason Wang
2022-03-31 9:12 ` Maxime Coquelin
2022-03-31 9:22 ` Michael Qiu
2022-04-01 2:55 ` Jason Wang
2022-03-31 9:25 ` [PATCH RESEND " qiudayu
2022-03-31 10:19 ` Michael Qiu
[not found] ` <6245804d.1c69fb81.3c35c.d7efSMTPIN_ADDED_BROKEN@mx.google.com>
2022-03-31 20:32 ` Michael S. Tsirkin
2022-04-01 1:12 ` Si-Wei Liu
2022-04-01 1:45 ` Michael Qiu
2022-04-01 1:31 ` [PATCH v4] " Michael Qiu
2022-04-01 2:53 ` Jason Wang
2022-04-01 3:20 ` Michael Qiu
2022-04-01 23:07 ` Si-Wei Liu
2022-04-02 2:20 ` Jason Wang
2022-04-02 3:53 ` Michael Qiu
2022-04-06 0:56 ` Si-Wei Liu
2022-04-07 7:50 ` Jason Wang
[not found] ` <6247c8f5.1c69fb81.848e0.8b49SMTPIN_ADDED_BROKEN@mx.google.com>
2022-04-07 7:52 ` Jason Wang
[not found] ` <62466fff.1c69fb81.8817a.d813SMTPIN_ADDED_BROKEN@mx.google.com>
2022-04-02 1:48 ` Jason Wang
2022-04-02 3:43 ` Michael Qiu
2022-04-01 11:06 ` [PATCH 0/3] Refactor vhost device reset Michael Qiu
2022-04-01 11:06 ` [PATCH 1/3] vhost: Refactor vhost_reset_device() in VhostOps Michael Qiu
2022-04-02 0:44 ` Si-Wei Liu
2022-04-02 2:08 ` Michael Qiu
2022-04-02 2:38 ` Jason Wang
2022-04-02 5:14 ` Michael Qiu
[not found] ` <6247dc22.1c69fb81.4244.a88bSMTPIN_ADDED_BROKEN@mx.google.com>
2022-04-07 7:35 ` Jason Wang
2022-04-08 8:38 ` Michael Qiu
2022-04-08 17:17 ` Si-Wei Liu
2022-04-11 8:51 ` Jason Wang
2022-04-01 11:06 ` [PATCH 2/3] vhost: add vhost_dev_reset() Michael Qiu
2022-04-02 0:48 ` Si-Wei Liu
2022-04-01 11:06 ` [PATCH 3/3 v5] vdpa: reset the backend device in the end of vhost_net_stop() Michael Qiu
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=df7c9a87-b2bd-7758-a6b6-bd834a7336fe@oracle.com \
--to=si-wei.liu@oracle.com \
--cc=08005325@163.com \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=lingshan.zhu@intel.com \
--cc=lulu@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qiudayu@archeros.com \
/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).