[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 1/4] vhost: Re-enable vrings after setting features
From: |
German Maglione |
Subject: |
Re: [PATCH 1/4] vhost: Re-enable vrings after setting features |
Date: |
Wed, 12 Apr 2023 12:55:18 +0200 |
On Tue, Apr 11, 2023 at 5:05 PM Hanna Czenczek <hreitz@redhat.com> wrote:
>
> If the back-end supports the VHOST_USER_F_PROTOCOL_FEATURES feature,
> setting the vhost features will set this feature, too. Doing so
> disables all vrings, which may not be intended.
>
> For example, enabling or disabling logging during migration requires
> setting those features (to set or unset VHOST_F_LOG_ALL), which will
> automatically disable all vrings. In either case, the VM is running
> (disabling logging is done after a failed or cancelled migration, and
> only once the VM is running again, see comment in
> memory_global_dirty_log_stop()), so the vrings should really be enabled.
> As a result, the back-end seems to hang.
>
> To fix this, we must remember whether the vrings are supposed to be
> enabled, and, if so, re-enable them after a SET_FEATURES call that set
> VHOST_USER_F_PROTOCOL_FEATURES.
>
> It seems less than ideal that there is a short period in which the VM is
> running but the vrings will be stopped (between SET_FEATURES and
> SET_VRING_ENABLE). To fix this, we would need to change the protocol,
> e.g. by introducing a new flag or vhost-user protocol feature to disable
> disabling vrings whenever VHOST_USER_F_PROTOCOL_FEATURES is set, or add
> new functions for setting/clearing singular feature bits (so that
> F_LOG_ALL can be set/cleared without touching F_PROTOCOL_FEATURES).
>
Could be the other way around?, I mean before commit
02b61f38d3574900fb4cc4c450b17c75956a6a04
so until v7.2rc0 we didn't have this problem with
VHOST_USER_F_PROTOCOL_FEATURES,
so "it seems" it's fine to start with the vrings enabled, could be
possible to go back to that
behavior (reflecting that in the spec) and add a new flag to start
with vrings disabled?
> Even with such a potential addition to the protocol, we still need this
> fix here, because we cannot expect that back-ends will implement this
> addition.
>
> Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
> ---
> include/hw/virtio/vhost.h | 10 ++++++++++
> hw/virtio/vhost.c | 13 +++++++++++++
> 2 files changed, 23 insertions(+)
>
> diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
> index a52f273347..2fe02ed5d4 100644
> --- a/include/hw/virtio/vhost.h
> +++ b/include/hw/virtio/vhost.h
> @@ -90,6 +90,16 @@ struct vhost_dev {
> int vq_index_end;
> /* if non-zero, minimum required value for max_queues */
> int num_queues;
> +
> + /*
> + * Whether the virtqueues are supposed to be enabled (via
> + * SET_VRING_ENABLE). Setting the features (e.g. for
> + * enabling/disabling logging) will disable all virtqueues if
> + * VHOST_USER_F_PROTOCOL_FEATURES is set, so then we need to
> + * re-enable them if this field is set.
> + */
> + bool enable_vqs;
> +
> /**
> * vhost feature handling requires matching the feature set
> * offered by a backend which may be a subset of the total
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index a266396576..cbff589efa 100644
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -50,6 +50,8 @@ static unsigned int used_memslots;
> static QLIST_HEAD(, vhost_dev) vhost_devices =
> QLIST_HEAD_INITIALIZER(vhost_devices);
>
> +static int vhost_dev_set_vring_enable(struct vhost_dev *hdev, int enable);
> +
> bool vhost_has_free_slot(void)
> {
> unsigned int slots_limit = ~0U;
> @@ -899,6 +901,15 @@ static int vhost_dev_set_features(struct vhost_dev *dev,
> }
> }
>
> + if (dev->enable_vqs) {
> + /*
> + * Setting VHOST_USER_F_PROTOCOL_FEATURES would have disabled all
> + * virtqueues, even if that was not intended; re-enable them if
> + * necessary.
> + */
> + vhost_dev_set_vring_enable(dev, true);
> + }
> +
> out:
> return r;
> }
> @@ -1896,6 +1907,8 @@ int vhost_dev_get_inflight(struct vhost_dev *dev,
> uint16_t queue_size,
>
> static int vhost_dev_set_vring_enable(struct vhost_dev *hdev, int enable)
> {
> + hdev->enable_vqs = enable;
> +
> if (!hdev->vhost_ops->vhost_set_vring_enable) {
> return 0;
> }
> --
> 2.39.1
>
--
German
- [PATCH 0/4] vhost-user-fs: Internal migration, Hanna Czenczek, 2023/04/11
- [PATCH 1/4] vhost: Re-enable vrings after setting features, Hanna Czenczek, 2023/04/11
- Re: [PATCH 1/4] vhost: Re-enable vrings after setting features,
German Maglione <=
- Re: [PATCH 1/4] vhost: Re-enable vrings after setting features, Stefan Hajnoczi, 2023/04/12
- Re: [PATCH 1/4] vhost: Re-enable vrings after setting features, Maxime Coquelin, 2023/04/13
- Re: [PATCH 1/4] vhost: Re-enable vrings after setting features, Hanna Czenczek, 2023/04/13
- Re: [PATCH 1/4] vhost: Re-enable vrings after setting features, Stefan Hajnoczi, 2023/04/13
- Re: [PATCH 1/4] vhost: Re-enable vrings after setting features, Anton Kuchin, 2023/04/13
- Re: [PATCH 1/4] vhost: Re-enable vrings after setting features, Michael S. Tsirkin, 2023/04/13
Re: [PATCH 1/4] vhost: Re-enable vrings after setting features, Stefan Hajnoczi, 2023/04/13
Re: [PATCH 1/4] vhost: Re-enable vrings after setting features, Michael S. Tsirkin, 2023/04/13