From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>,
Hanna Czenczek <hreitz@redhat.com>
Cc: qemu-devel@nongnu.org, virtio-fs@redhat.com,
"German Maglione" <gmaglione@redhat.com>,
"Anton Kuchin" <antonkuchin@yandex-team.ru>,
"Juan Quintela" <quintela@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
"Stefano Garzarella" <sgarzare@redhat.com>,
"Roman Kagan" <rvkagan@yandex-team.ru>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: Re: [PATCH 1/4] vhost: Re-enable vrings after setting features
Date: Thu, 13 Apr 2023 09:17:16 +0200 [thread overview]
Message-ID: <74a20bbf-860e-ed5b-03fa-6f25ce865652@redhat.com> (raw)
In-Reply-To: <20230412205138.GA2813183@fedora>
On 4/12/23 22:51, Stefan Hajnoczi wrote:
> On Tue, Apr 11, 2023 at 05:05:12PM +0200, Hanna Czenczek 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).
>>
>> 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;
>> }
>
> The vhost-user spec doesn't say that VHOST_F_LOG_ALL needs to be toggled
> at runtime and I don't think VHOST_USER_SET_PROTOCOL_FEATURES is
> intended to be used like that. This issue shows why doing so is a bad
> idea.
>
> VHOST_F_LOG_ALL does not need to be toggled to control logging. Logging
> is controlled at runtime by the presence of the dirty log
> (VHOST_USER_SET_LOG_BASE) and the per-vring logging flag
> (VHOST_VRING_F_LOG).
>
> I suggest permanently enabling VHOST_F_LOG_ALL upon connection when the
> the backend supports it. No spec changes are required.
>
> libvhost-user looks like it will work. I didn't look at DPDK/SPDK, but
> checking that it works there is important too.
>
> I have CCed people who may be interested in this issue. This is the
> first time I've looked at vhost-user logging, so this idea may not work.
In the case of DPDK, we rely on VHOST_F_LOG_ALL to be set to know
whether we should do dirty pages logging or not [0], so setting this
feature at init time will cause performance degradation. The check on
whether the log base address has been set is done afterwards.
Regards,
Maxime
> Stefan
[0]: https://git.dpdk.org/dpdk/tree/lib/vhost/vhost.h#n594
next prev parent reply other threads:[~2023-04-13 7:18 UTC|newest]
Thread overview: 93+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-11 15:05 [PATCH 0/4] vhost-user-fs: Internal migration Hanna Czenczek
2023-04-11 15:05 ` [PATCH 1/4] vhost: Re-enable vrings after setting features Hanna Czenczek
2023-04-12 10:55 ` German Maglione
2023-04-12 12:18 ` Hanna Czenczek
2023-04-12 20:51 ` Stefan Hajnoczi
2023-04-13 7:17 ` Maxime Coquelin [this message]
2023-04-13 8:19 ` Hanna Czenczek
2023-04-13 11:03 ` Stefan Hajnoczi
2023-04-13 14:24 ` Anton Kuchin
2023-04-13 15:48 ` Michael S. Tsirkin
2023-04-13 11:03 ` Stefan Hajnoczi
2023-04-13 17:32 ` Hanna Czenczek
2023-04-13 13:19 ` Michael S. Tsirkin
2023-04-11 15:05 ` [PATCH 2/4] vhost-user: Interface for migration state transfer Hanna Czenczek
2023-04-12 21:06 ` Stefan Hajnoczi
2023-04-13 9:24 ` Hanna Czenczek
2023-04-13 11:38 ` Stefan Hajnoczi
2023-04-13 17:55 ` Hanna Czenczek
2023-04-13 20:42 ` Stefan Hajnoczi
2023-04-14 15:17 ` Eugenio Perez Martin
2023-04-17 15:18 ` Stefan Hajnoczi
2023-04-17 18:55 ` Eugenio Perez Martin
2023-04-17 19:08 ` Stefan Hajnoczi
2023-04-17 19:11 ` Eugenio Perez Martin
2023-04-17 19:46 ` Stefan Hajnoczi
2023-04-18 10:09 ` Eugenio Perez Martin
2023-04-19 10:45 ` Hanna Czenczek
2023-04-19 10:57 ` Stefan Hajnoczi
2023-04-13 10:14 ` Eugenio Perez Martin
2023-04-13 11:07 ` Stefan Hajnoczi
2023-04-13 17:31 ` Hanna Czenczek
2023-04-17 15:12 ` Stefan Hajnoczi
2023-04-19 10:47 ` Hanna Czenczek
2023-04-17 18:37 ` Eugenio Perez Martin
2023-04-17 15:38 ` Stefan Hajnoczi
2023-04-17 19:09 ` Eugenio Perez Martin
2023-04-17 19:33 ` Stefan Hajnoczi
2023-04-18 8:09 ` Eugenio Perez Martin
2023-04-18 17:59 ` Stefan Hajnoczi
2023-04-18 18:31 ` Eugenio Perez Martin
2023-04-18 20:40 ` Stefan Hajnoczi
2023-04-20 13:27 ` Eugenio Pérez
2023-05-08 19:12 ` Stefan Hajnoczi
2023-05-09 6:31 ` Eugenio Perez Martin
2023-05-09 9:01 ` Hanna Czenczek
2023-05-09 15:26 ` Eugenio Perez Martin
2023-04-19 10:57 ` [Virtio-fs] " Hanna Czenczek
2023-04-19 11:10 ` Stefan Hajnoczi
2023-04-19 11:15 ` Hanna Czenczek
2023-04-19 11:24 ` Stefan Hajnoczi
2023-04-17 17:14 ` Stefan Hajnoczi
2023-04-17 19:06 ` Eugenio Perez Martin
2023-04-17 19:20 ` Stefan Hajnoczi
2023-04-18 7:54 ` Eugenio Perez Martin
2023-04-19 11:10 ` Hanna Czenczek
2023-04-19 11:21 ` Stefan Hajnoczi
2023-04-19 11:24 ` Hanna Czenczek
2023-04-20 13:29 ` Eugenio Pérez
2023-05-08 20:10 ` Stefan Hajnoczi
2023-05-09 6:45 ` Eugenio Perez Martin
2023-05-09 15:09 ` Stefan Hajnoczi
2023-05-09 15:35 ` Eugenio Perez Martin
2023-05-09 17:33 ` Stefan Hajnoczi
2023-04-20 10:44 ` Eugenio Pérez
2023-04-13 8:50 ` Eugenio Perez Martin
2023-04-13 9:25 ` Hanna Czenczek
2023-04-11 15:05 ` [PATCH 3/4] vhost: Add high-level state save/load functions Hanna Czenczek
2023-04-12 21:14 ` Stefan Hajnoczi
2023-04-13 9:04 ` Hanna Czenczek
2023-04-13 11:22 ` Stefan Hajnoczi
2023-04-11 15:05 ` [PATCH 4/4] vhost-user-fs: Implement internal migration Hanna Czenczek
2023-04-12 21:00 ` [PATCH 0/4] vhost-user-fs: Internal migration Stefan Hajnoczi
2023-04-13 8:20 ` Hanna Czenczek
2023-04-13 16:11 ` Michael S. Tsirkin
2023-04-13 17:53 ` [Virtio-fs] " Hanna Czenczek
2023-05-04 16:05 ` Hanna Czenczek
2023-05-04 21:14 ` Stefan Hajnoczi
2023-05-05 9:03 ` Hanna Czenczek
2023-05-05 9:51 ` Hanna Czenczek
2023-05-05 14:26 ` Eugenio Perez Martin
2023-05-05 14:37 ` Hanna Czenczek
2023-05-08 17:00 ` Hanna Czenczek
2023-05-08 17:51 ` Eugenio Perez Martin
2023-05-08 19:31 ` Eugenio Perez Martin
2023-05-09 8:59 ` Hanna Czenczek
2023-05-09 15:30 ` Stefan Hajnoczi
2023-05-09 15:43 ` Eugenio Perez Martin
2023-05-05 9:53 ` Eugenio Perez Martin
2023-05-05 12:51 ` Hanna Czenczek
2023-05-08 21:10 ` Stefan Hajnoczi
2023-05-09 8:53 ` Hanna Czenczek
2023-05-09 14:53 ` Stefan Hajnoczi
2023-05-09 15:41 ` Stefan Hajnoczi
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=74a20bbf-860e-ed5b-03fa-6f25ce865652@redhat.com \
--to=maxime.coquelin@redhat.com \
--cc=antonkuchin@yandex-team.ru \
--cc=gmaglione@redhat.com \
--cc=hreitz@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=rvkagan@yandex-team.ru \
--cc=sgarzare@redhat.com \
--cc=stefanha@redhat.com \
--cc=virtio-fs@redhat.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).