virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: "Eugenio Pérez" <eperezma@redhat.com>, qemu-devel@nongnu.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	virtualization@lists.linux-foundation.org,
	Eli Cohen <eli@mellanox.com>, Eric Blake <eblake@redhat.com>,
	Parav Pandit <parav@mellanox.com>, Cindy Lu <lulu@redhat.com>,
	"Fangyi \(Eric\)" <eric.fangyi@huawei.com>,
	Markus Armbruster <armbru@redhat.com>,
	yebiaoxiang@huawei.com, Liuxiangdong <liuxiangdong5@huawei.com>,
	Laurent Vivier <lvivier@redhat.com>,
	Eduardo Habkost <ehabkost@redhat.com>,
	Richard Henderson <richard.henderson@linaro.org>,
	Gautam Dawar <gdawar@xilinx.com>,
	Xiao W Wang <xiao.w.wang@intel.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Harpreet Singh Anand <hanand@xilinx.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Lingshan <lingshan.zhu@intel.com>
Subject: Re: [PATCH v2 04/14] vhost: Add vhost_svq_valid_features to shadow vq
Date: Mon, 28 Feb 2022 11:25:28 +0800	[thread overview]
Message-ID: <562b97bc-860e-b2e6-0f45-945a75c25da5@redhat.com> (raw)
In-Reply-To: <20220227134111.3254066-5-eperezma@redhat.com>


在 2022/2/27 下午9:41, Eugenio Pérez 写道:
> This allows SVQ to negotiate features with the guest and the device. For
> the device, SVQ is a driver. While this function bypasses all
> non-transport features, it needs to disable the features that SVQ does
> not support when forwarding buffers. This includes packed vq layout,
> indirect descriptors or event idx.
>
> Future changes can add support to offer more features to the guest,
> since the use of VirtQueue gives this for free. This is left out at the
> moment for simplicity.
>
> Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> ---
>   hw/virtio/vhost-shadow-virtqueue.h |  2 ++
>   hw/virtio/vhost-shadow-virtqueue.c | 39 ++++++++++++++++++++++++++++++
>   hw/virtio/vhost-vdpa.c             | 18 ++++++++++++++
>   3 files changed, 59 insertions(+)
>
> diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-virtqueue.h
> index 1d4c160d0a..84747655ad 100644
> --- a/hw/virtio/vhost-shadow-virtqueue.h
> +++ b/hw/virtio/vhost-shadow-virtqueue.h
> @@ -33,6 +33,8 @@ typedef struct VhostShadowVirtqueue {
>       EventNotifier svq_call;
>   } VhostShadowVirtqueue;
>   
> +bool vhost_svq_valid_features(uint64_t *features);
> +
>   void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd);
>   void vhost_svq_set_guest_call_notifier(VhostShadowVirtqueue *svq, int call_fd);
>   
> diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
> index 54c701a196..34354aea2c 100644
> --- a/hw/virtio/vhost-shadow-virtqueue.c
> +++ b/hw/virtio/vhost-shadow-virtqueue.c
> @@ -14,6 +14,45 @@
>   #include "qemu/main-loop.h"
>   #include "linux-headers/linux/vhost.h"
>   
> +/**
> + * Validate the transport device features that both guests can use with the SVQ
> + * and SVQs can use with the device.
> + *
> + * @dev_features  The features. If success, the acknowledged features. If
> + *                failure, the minimal set from it.
> + *
> + * Returns true if SVQ can go with a subset of these, false otherwise.
> + */
> +bool vhost_svq_valid_features(uint64_t *features)
> +{
> +    bool r = true;
> +
> +    for (uint64_t b = VIRTIO_TRANSPORT_F_START; b <= VIRTIO_TRANSPORT_F_END;
> +         ++b) {
> +        switch (b) {
> +        case VIRTIO_F_ANY_LAYOUT:
> +            continue;
> +
> +        case VIRTIO_F_ACCESS_PLATFORM:
> +            /* SVQ trust in the host's IOMMU to translate addresses */
> +        case VIRTIO_F_VERSION_1:
> +            /* SVQ trust that the guest vring is little endian */
> +            if (!(*features & BIT_ULL(b))) {
> +                set_bit(b, features);
> +                r = false;
> +            }
> +            continue;


It looks to me the *features is only used for logging errors, if this is 
the truth. I suggest to do error_setg in this function instead of 
letting the caller to pass a pointer.


> +
> +        default:
> +            if (*features & BIT_ULL(b)) {
> +                clear_bit(b, features);
> +            }


Do we need to check indirect and event idx here?

Thanks


> +        }
> +    }
> +
> +    return r;
> +}
> +
>   /** Forward guest notifications */
>   static void vhost_handle_guest_kick(EventNotifier *n)
>   {
> diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
> index c73215751d..d614c435f3 100644
> --- a/hw/virtio/vhost-vdpa.c
> +++ b/hw/virtio/vhost-vdpa.c
> @@ -348,11 +348,29 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v,
>                                  Error **errp)
>   {
>       g_autoptr(GPtrArray) shadow_vqs = NULL;
> +    uint64_t dev_features, svq_features;
> +    int r;
> +    bool ok;
>   
>       if (!v->shadow_vqs_enabled) {
>           return 0;
>       }
>   
> +    r = hdev->vhost_ops->vhost_get_features(hdev, &dev_features);
> +    if (r != 0) {
> +        error_setg_errno(errp, -r, "Can't get vdpa device features");
> +        return r;
> +    }
> +
> +    svq_features = dev_features;
> +    ok = vhost_svq_valid_features(&svq_features);
> +    if (unlikely(!ok)) {
> +        error_setg(errp,
> +            "SVQ Invalid device feature flags, offer: 0x%"PRIx64", ok: 0x%"PRIx64,
> +            dev_features, svq_features);
> +        return -1;
> +    }
> +
>       shadow_vqs = g_ptr_array_new_full(hdev->nvqs, vhost_svq_free);
>       for (unsigned n = 0; n < hdev->nvqs; ++n) {
>           g_autoptr(VhostShadowVirtqueue) svq = vhost_svq_new();

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

  parent reply	other threads:[~2022-02-28  3:25 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220227134111.3254066-1-eperezma@redhat.com>
2022-02-28  2:32 ` [PATCH v2 00/14] vDPA shadow virtqueue Jason Wang
     [not found] ` <20220227134111.3254066-3-eperezma@redhat.com>
2022-02-28  2:57   ` [PATCH v2 02/14] vhost: Add Shadow VirtQueue kick forwarding capabilities Jason Wang
     [not found]     ` <CAJaqyWezcrc=iPLe=Y7+g9oBYfUY9pK8OM4=ZUeRgXqr9ZUWkg@mail.gmail.com>
2022-03-03  7:12       ` Jason Wang
     [not found]         ` <CAJaqyWfbkzi19yMAXY7gwCAoj7sakwU_R2hDc1u8+jHPfHLadA@mail.gmail.com>
2022-03-04  1:39           ` Jason Wang
     [not found] ` <20220227134111.3254066-4-eperezma@redhat.com>
2022-02-28  3:18   ` [PATCH v2 03/14] vhost: Add Shadow VirtQueue call " Jason Wang
     [not found] ` <20220227134111.3254066-5-eperezma@redhat.com>
2022-02-28  3:25   ` Jason Wang [this message]
     [not found] ` <20220227134111.3254066-7-eperezma@redhat.com>
2022-02-28  3:59   ` [PATCH v2 06/14] vdpa: adapt vhost_ops callbacks to svq Jason Wang
     [not found] ` <20220227134111.3254066-8-eperezma@redhat.com>
2022-02-28  5:39   ` [PATCH v2 07/14] vhost: Shadow virtqueue buffers forwarding Jason Wang
     [not found]     ` <CAJaqyWe=hGmAvU_Fr34fecbF_7kUYqcm-EOdHJOo47TtddPwLw@mail.gmail.com>
2022-03-03  7:35       ` Jason Wang
     [not found] ` <20220227134111.3254066-9-eperezma@redhat.com>
2022-02-28  6:39   ` [PATCH v2 08/14] util: Add iova_tree_alloc Jason Wang
     [not found]     ` <CAJaqyWdNWqpdBQ-iTWLu7fH0prHPo8Uc1LXkEKvQ4X6cp7_TOA@mail.gmail.com>
2022-03-03  7:16       ` Jason Wang
     [not found] ` <20220227134111.3254066-10-eperezma@redhat.com>
2022-02-28  7:06   ` [PATCH v2 09/14] vhost: Add VhostIOVATree Jason Wang
     [not found]     ` <CAJaqyWchLxXTRBE9zT9ZrF7UT_CnNbD=E5yaK6NrF-gDauhSAg@mail.gmail.com>
2022-03-04  2:04       ` Jason Wang
     [not found]         ` <CAJaqyWcsUv=Kc8up=T103wz8uy8YWd+6gK3Pm5PXwHVVMuLM2Q@mail.gmail.com>
2022-03-07  3:41           ` Jason Wang
     [not found] ` <20220227134111.3254066-11-eperezma@redhat.com>
2022-02-28  7:36   ` [PATCH v2 10/14] vdpa: Add custom IOTLB translations to SVQ Jason Wang
     [not found]     ` <CAJaqyWf9c=OOKt7sB=kMY7FzNGG+YfPF=qNbu6A0UVkhzxmHZA@mail.gmail.com>
2022-03-03  7:33       ` Jason Wang
     [not found]         ` <CAJaqyWfwDjuVsX_ELpad0-8EQJJhK79tz5Yi18Ye1xksM_1snQ@mail.gmail.com>
2022-03-07  4:24           ` Jason Wang
     [not found] ` <20220227134111.3254066-12-eperezma@redhat.com>
2022-02-28  7:38   ` [PATCH v2 11/14] vdpa: Adapt vhost_vdpa_get_vring_base " Jason Wang
2022-02-28  7:41 ` [PATCH v2 00/14] vDPA shadow virtqueue 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=562b97bc-860e-b2e6-0f45-945a75c25da5@redhat.com \
    --to=jasowang@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=eli@mellanox.com \
    --cc=eperezma@redhat.com \
    --cc=eric.fangyi@huawei.com \
    --cc=gdawar@xilinx.com \
    --cc=hanand@xilinx.com \
    --cc=lingshan.zhu@intel.com \
    --cc=liuxiangdong5@huawei.com \
    --cc=lulu@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=mst@redhat.com \
    --cc=parav@mellanox.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=xiao.w.wang@intel.com \
    --cc=yebiaoxiang@huawei.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).