Received: from eggs.gnu.org ([2001:4830:134:3::10]:41551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btcrF-0001M3-SH for qemu-devel@nongnu.org; Mon, 10 Oct 2016 11:51:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btcr9-00034H-2k for qemu-devel@nongnu.org; Mon, 10 Oct 2016 11:51:16 -0400 Received: from mail-co1nam03on0099.outbound.protection.outlook.com ([104.47.40.99]:44208 helo=NAM03-CO1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btcr8-00033f-J0 for qemu-devel@nongnu.org; Mon, 10 Oct 2016 11:51:10 -0400 From: Felipe Franciosi Date: Mon, 10 Oct 2016 15:17:36 +0000 Message-ID: <6DB45F6B-485F-48BD-B801-3847AA732530@nutanix.com> References: <1474546421-8613-1-git-send-email-felipe@nutanix.com> <20161010013248-mutt-send-email-mst@kernel.org> In-Reply-To: <20161010013248-mutt-send-email-mst@kernel.org> Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-ID: <6487913F74959941B74D1D74784F1F34@namprd02.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH v2] Avoid additional GET_FEATURES call on vhost-user List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: Marc-Andre Lureau , qemu-devel > On 9 Oct 2016, at 23:33, Michael S. Tsirkin wrote: >=20 > On Thu, Sep 22, 2016 at 01:13:41PM +0100, Felipe Franciosi wrote: >> Vhost-user requires an early GET_FEATURES call to determine if the >> slave supports protocol feature negotiation. An extra GET_FEATURES >> call is made after vhost_backend_init() to actually set the device >> features. >>=20 >> This patch moves the actual setting of the device features to both >> implementations (kernel/user) of vhost_backend_init(), therefore >> eliminating the need for a second call. >>=20 >> Signed-off-by: Felipe Franciosi >=20 >=20 > Thanks! > Thinking about this, I think it makes sense to keep > both messages around. > This allow backend to change the feature bitmap > depending on the protocol features negotiated. Hi Michael, Sounds interesting, but I'm struggling a bit to see how that would work. II= UC, the "feature" negotiation should relate to anything between device and = driver. The "protocol feature" should relate to things between backend and = Qemu. The obvious exception is the "protocol feature bit" itself, which is = part of the "feature" since protocol features weren't part of the original = spec. If the protocol or the implementation have deviated from that, we should tr= y to make it consistent and clear to avoid further problems. So on the double message, I guess my questions would be: 1) What features could a backend advertise differently and how that relates= to protocol features? In other words, how would a protocol feature affect = the actual relationship between the backend and the driver? 2) What guarantees would a backend have that Qemu is going to ask again for= the feature bitmap? In other words, if a backend is going to implement som= ething differently (regarding handling the driver) depending on what protoc= ol bits are supported by Qemu, can it count on Qemu asking for it again? 3) If we stick to the double message, should we document it as intentional = and exemplify how it could be used to avoid someone else spotting this and = trying to "fix" it again? Thanks, Felipe >=20 >> --- >> v2. Rebase on d1b4259f >>=20 >> hw/virtio/vhost-backend.c | 27 ++++++++++++++++++--------- >> hw/virtio/vhost-user.c | 1 + >> hw/virtio/vhost.c | 9 --------- >> 3 files changed, 19 insertions(+), 18 deletions(-) >>=20 >> diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c >> index 272a5ec..0ffa4d1 100644 >> --- a/hw/virtio/vhost-backend.c >> +++ b/hw/virtio/vhost-backend.c >> @@ -25,15 +25,6 @@ static int vhost_kernel_call(struct vhost_dev *dev, u= nsigned long int request, >> return ioctl(fd, request, arg); >> } >>=20 >> -static int vhost_kernel_init(struct vhost_dev *dev, void *opaque) >> -{ >> - assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_KERNE= L); >> - >> - dev->opaque =3D opaque; >> - >> - return 0; >> -} >> - >> static int vhost_kernel_cleanup(struct vhost_dev *dev) >> { >> int fd =3D (uintptr_t) dev->opaque; >> @@ -185,6 +176,24 @@ static int vhost_kernel_vsock_set_running(struct vh= ost_dev *dev, int start) >> } >> #endif /* CONFIG_VHOST_VSOCK */ >>=20 >> +static int vhost_kernel_init(struct vhost_dev *dev, void *opaque) >> +{ >> + uint64_t features; >> + int r; >> + >> + assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_KERNE= L); >> + >> + dev->opaque =3D opaque; >> + >> + r =3D vhost_kernel_get_features(dev, &features); >> + if (r < 0) { >> + return r; >> + } >> + dev->features =3D features; >> + >> + return 0; >> +} >> + >> static const VhostOps kernel_ops =3D { >> .backend_type =3D VHOST_BACKEND_TYPE_KERNEL, >> .vhost_backend_init =3D vhost_kernel_init, >> diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c >> index b57454a..684f6d7 100644 >> --- a/hw/virtio/vhost-user.c >> +++ b/hw/virtio/vhost-user.c >> @@ -578,6 +578,7 @@ static int vhost_user_init(struct vhost_dev *dev, vo= id *opaque) >> if (err < 0) { >> return err; >> } >> + dev->features =3D features; >>=20 >> if (virtio_has_feature(features, VHOST_USER_F_PROTOCOL_FEATURES)) { >> dev->backend_features |=3D 1ULL << VHOST_USER_F_PROTOCOL_FEATURE= S; >> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c >> index bd051ab..36fd35f 100644 >> --- a/hw/virtio/vhost.c >> +++ b/hw/virtio/vhost.c >> @@ -1051,7 +1051,6 @@ static void vhost_virtqueue_cleanup(struct vhost_v= irtqueue *vq) >> int vhost_dev_init(struct vhost_dev *hdev, void *opaque, >> VhostBackendType backend_type, uint32_t busyloop_time= out) >> { >> - uint64_t features; >> int i, r, n_initialized_vqs =3D 0; >>=20 >> hdev->migration_blocker =3D NULL; >> @@ -1077,12 +1076,6 @@ int vhost_dev_init(struct vhost_dev *hdev, void *= opaque, >> goto fail; >> } >>=20 >> - r =3D hdev->vhost_ops->vhost_get_features(hdev, &features); >> - if (r < 0) { >> - VHOST_OPS_DEBUG("vhost_get_features failed"); >> - goto fail; >> - } >> - >> for (i =3D 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) { >> r =3D vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index += i); >> if (r < 0) { >> @@ -1100,8 +1093,6 @@ int vhost_dev_init(struct vhost_dev *hdev, void *o= paque, >> } >> } >>=20 >> - hdev->features =3D features; >> - >> hdev->memory_listener =3D (MemoryListener) { >> .begin =3D vhost_begin, >> .commit =3D vhost_commit, >> --=20 >> 1.9.5