All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kangjie Xu <kangjie.xu@linux.alibaba.com>
To: Jason Wang <jasowang@redhat.com>
Cc: qemu-devel@nongnu.org, mst@redhat.com, hengqi@linux.alibaba.com,
	xuanzhuo@linux.alibaba.com
Subject: Re: [PATCH 09/16] vhost-user: enable/disable a single vring
Date: Wed, 27 Jul 2022 14:44:00 +0800	[thread overview]
Message-ID: <1fcf4956-a28f-ada5-87c8-e3c64fb57eb4@linux.alibaba.com> (raw)
In-Reply-To: <CACGkMEsQ6aW-ihHoiioD5M6acVwQ2vgW97XJ0BoQxVtc3JnNVw@mail.gmail.com>


在 2022/7/27 12:51, Jason Wang 写道:
> On Tue, Jul 26, 2022 at 1:27 PM Kangjie Xu <kangjie.xu@linux.alibaba.com> wrote:
>>
>> 在 2022/7/26 12:07, Jason Wang 写道:
>>> 在 2022/7/18 19:17, Kangjie Xu 写道:
>>>> Implement the vhost_set_single_vring_enable, which is to enable or
>>>> disable a single vring.
>>>>
>>>> The parameter wait_for_reply is added to help for some cases such as
>>>> vq reset.
>>>>
>>>> Meanwhile, vhost_user_set_vring_enable() is refactored.
>>>>
>>>> Signed-off-by: Kangjie Xu <kangjie.xu@linux.alibaba.com>
>>>> Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
>>>> ---
>>>>    hw/virtio/vhost-user.c | 55 ++++++++++++++++++++++++++++++++++++------
>>>>    1 file changed, 48 insertions(+), 7 deletions(-)
>>>>
>>>> diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
>>>> index 75b8df21a4..5a80a415f0 100644
>>>> --- a/hw/virtio/vhost-user.c
>>>> +++ b/hw/virtio/vhost-user.c
>>>> @@ -267,6 +267,8 @@ struct scrub_regions {
>>>>        int fd_idx;
>>>>    };
>>>>    +static int enforce_reply(struct vhost_dev *dev, const VhostUserMsg
>>>> *msg);
>>>> +
>>>>    static bool ioeventfd_enabled(void)
>>>>    {
>>>>        return !kvm_enabled() || kvm_eventfds_enabled();
>>>> @@ -1198,6 +1200,49 @@ static int vhost_user_set_vring_base(struct
>>>> vhost_dev *dev,
>>>>        return vhost_set_vring(dev, VHOST_USER_SET_VRING_BASE, ring);
>>>>    }
>>>>    +
>>>> +static int vhost_user_set_single_vring_enable(struct vhost_dev *dev,
>>>> +                                              int index,
>>>> +                                              int enable,
>>>> +                                              bool wait_for_reply)
>>>> +{
>>>> +    int ret;
>>>> +
>>>> +    if (index < dev->vq_index || index >= dev->vq_index + dev->nvqs) {
>>>> +        return -EINVAL;
>>>> +    }
>>>> +
>>>> +    struct vhost_vring_state state = {
>>>> +        .index = index,
>>>> +        .num   = enable,
>>>> +    };
>>>> +
>>>> +    VhostUserMsg msg = {
>>>> +        .hdr.request = VHOST_USER_SET_VRING_ENABLE,
>>>> +        .hdr.flags = VHOST_USER_VERSION,
>>>> +        .payload.state = state,
>>>> +        .hdr.size = sizeof(msg.payload.state),
>>>> +    };
>>>> +
>>>> +    bool reply_supported = virtio_has_feature(dev->protocol_features,
>>>> + VHOST_USER_PROTOCOL_F_REPLY_ACK);
>>>> +
>>>> +    if (reply_supported && wait_for_reply) {
>>>> +        msg.hdr.flags |= VHOST_USER_NEED_REPLY_MASK;
>>>> +    }
>>>
>>> Do we need to fail if !realy_supported && wait_for_reply?
>>>
>>> Thanks
>>>
>>>
>> I guess you mean "should we fail if VHOST_USER_PROTOCOL_F_REPLY_ACK
>> feature is not supported?".
>>
>> The implementation here is similar to that in vhost_user_set_vring_addr().
>>
>> If this feature is not supported, it will call enforce_reply(), then
>> call vhost_user_get_features() to get a reply.
> Ok, so you meant we can then fallback to VHOST_USER_GET_FEATURES? I
> wonder how robust is this, e.g is the bakcend required to process
> vhost-user request in order?
>
> Thanks
Yes, we rely on VHOST_USER_GET_FEATURES message to ensure that 
VHOST_USER_SET_VRING_ENABLE has been processed.

It's not robust. I reviewed the vhost-user protocol in qemu doc, 
actually it does not specify that the backend should process them in order.

I think adding a new vhost protocol message can fix this issue. The new 
invented message should reset the queue, and have a blocked read to 
ensure the message has been processed.

Thanks

>> Since the messages will be processed sequentailly in DPDK, success of
>> enforce_reply() means the previous message VHOST_USER_SET_VRING_ENABLE
>> has been processed.
>>
>> Thanks
>>
>>>> +
>>>> +    ret = vhost_user_write(dev, &msg, NULL, 0);
>>>> +    if (ret < 0) {
>>>> +        return ret;
>>>> +    }
>>>> +
>>>> +    if (wait_for_reply) {
>>>> +        return enforce_reply(dev, &msg);
>>>> +    }
>>>> +
>>>> +    return ret;
>>>> +}
>>>> +
>>>>    static int vhost_user_set_vring_enable(struct vhost_dev *dev, int
>>>> enable)
>>>>    {
>>>>        int i;
>>>> @@ -1207,13 +1252,8 @@ static int vhost_user_set_vring_enable(struct
>>>> vhost_dev *dev, int enable)
>>>>        }
>>>>          for (i = 0; i < dev->nvqs; ++i) {
>>>> -        int ret;
>>>> -        struct vhost_vring_state state = {
>>>> -            .index = dev->vq_index + i,
>>>> -            .num   = enable,
>>>> -        };
>>>> -
>>>> -        ret = vhost_set_vring(dev, VHOST_USER_SET_VRING_ENABLE,
>>>> &state);
>>>> +        int ret = vhost_user_set_single_vring_enable(dev,
>>>> dev->vq_index + i,
>>>> +                                                     enable, false);
>>>>            if (ret < 0) {
>>>>                /*
>>>>                 * Restoring the previous state is likely infeasible,
>>>> as well as
>>>> @@ -2627,6 +2667,7 @@ const VhostOps user_ops = {
>>>>            .vhost_set_owner = vhost_user_set_owner,
>>>>            .vhost_reset_device = vhost_user_reset_device,
>>>>            .vhost_get_vq_index = vhost_user_get_vq_index,
>>>> +        .vhost_set_single_vring_enable =
>>>> vhost_user_set_single_vring_enable,
>>>>            .vhost_set_vring_enable = vhost_user_set_vring_enable,
>>>>            .vhost_requires_shm_log = vhost_user_requires_shm_log,
>>>>            .vhost_migration_done = vhost_user_migration_done,


  reply	other threads:[~2022-07-27  6:54 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-18 11:16 [PATCH 00/16] Support VIRTIO_F_RING_RESET for virtio-net and vhost-user in virtio pci Kangjie Xu
2022-07-18 11:16 ` [PATCH 01/16] virtio-pci: virtio_pci_common_cfg add queue_notify_data Kangjie Xu
2022-07-26  3:17   ` Jason Wang
2022-07-26  6:16     ` Kangjie Xu
2022-07-18 11:16 ` [PATCH 02/16] virtio: add VIRTIO_F_RING_RESET Kangjie Xu
2022-07-18 11:17 ` [PATCH 03/16] virtio: pci: virtio_pci_common_cfg add queue_reset Kangjie Xu
2022-07-18 11:17 ` [PATCH 04/16] virtio: introduce __virtio_queue_reset() Kangjie Xu
2022-07-26  3:20   ` Jason Wang
2022-07-18 11:17 ` [PATCH 05/16] virtio: introduce virtio_queue_reset() Kangjie Xu
2022-07-26  3:21   ` Jason Wang
2022-07-18 11:17 ` [PATCH 06/16] virtio-pci: support queue reset Kangjie Xu
2022-07-26  3:31   ` Jason Wang
2022-07-18 11:17 ` [PATCH 07/16] virtio-net: " Kangjie Xu
2022-07-26  3:43   ` Jason Wang
2022-07-26  7:01     ` Kangjie Xu
2022-07-27  5:00       ` Jason Wang
2022-07-27  6:23         ` Kangjie Xu
2022-07-27  6:59           ` Jason Wang
2022-07-27  7:12             ` Kangjie Xu
2022-07-18 11:17 ` [PATCH 08/16] vhost: add op to enable or disable a single vring Kangjie Xu
2022-07-26  3:49   ` Jason Wang
2022-07-26  6:39     ` Kangjie Xu
2022-07-27  4:55       ` Jason Wang
2022-07-27  7:05         ` Kangjie Xu
2022-07-28  2:41           ` Jason Wang
2022-07-29  1:51             ` Kangjie Xu
2022-07-18 11:17 ` [PATCH 09/16] vhost-user: enable/disable " Kangjie Xu
2022-07-26  4:07   ` Jason Wang
2022-07-26  5:27     ` Kangjie Xu
2022-07-27  4:51       ` Jason Wang
2022-07-27  6:44         ` Kangjie Xu [this message]
2022-07-18 11:17 ` [PATCH 10/16] vhost: extract the logic of unmapping the vrings and desc Kangjie Xu
2022-07-26  4:07   ` Jason Wang
2022-07-18 11:17 ` [PATCH 11/16] vhost: introduce restart and release for vhost_dev's vqs Kangjie Xu
2022-07-26  4:13   ` Jason Wang
2022-07-26  6:15     ` Kangjie Xu
     [not found]     ` <f28d29ac-f244-a523-ed78-84c438d13340@linux.alibaba.com>
     [not found]       ` <CACGkMEtxXSm8Qc1LpKJJYm9cQ-F+eU5Lqecr62maRPxq1tM5rg@mail.gmail.com>
2022-07-27  8:23         ` Kangjie Xu
2022-07-18 11:17 ` [PATCH 12/16] vhost-net: introduce restart and stop for vhost_net's vqs Kangjie Xu
2022-07-26  4:16   ` Jason Wang
2022-07-26  6:11     ` Kangjie Xu
2022-07-18 11:17 ` [PATCH 13/16] virtio: introduce queue_enable in virtio Kangjie Xu
2022-07-26  4:17   ` Jason Wang
2022-07-26  6:19     ` Kangjie Xu
2022-07-18 11:17 ` [PATCH 14/16] virtio-net: support queue_enable for vhost-user Kangjie Xu
2022-07-26  4:25   ` Jason Wang
2022-07-26  6:54     ` Kangjie Xu
2022-07-27  4:58       ` Jason Wang
2022-07-18 11:17 ` [PATCH 15/16] virtio-net: support queue_reset " Kangjie Xu
2022-07-18 11:17 ` [PATCH 16/16] vhost-net: vq reset feature bit support Kangjie Xu
2022-07-26  4:28   ` Jason Wang
2022-07-26  6:24     ` Kangjie Xu
2022-07-27  4:53       ` Jason Wang
2022-07-27  6:48         ` Kangjie Xu
2022-07-25  2:34 ` [PATCH 00/16] Support VIRTIO_F_RING_RESET for virtio-net and vhost-user in virtio pci Kangjie Xu
2022-07-25  3:29   ` Jason Wang

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=1fcf4956-a28f-ada5-87c8-e3c64fb57eb4@linux.alibaba.com \
    --to=kangjie.xu@linux.alibaba.com \
    --cc=hengqi@linux.alibaba.com \
    --cc=jasowang@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=xuanzhuo@linux.alibaba.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.