From patchwork Thu Sep 22 12:13:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Franciosi X-Patchwork-Id: 9345163 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4C51C6077A for ; Thu, 22 Sep 2016 12:14:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3560C2AA50 for ; Thu, 22 Sep 2016 12:14:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 293332AA54; Thu, 22 Sep 2016 12:14:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7EFAE2AA50 for ; Thu, 22 Sep 2016 12:14:39 +0000 (UTC) Received: from localhost ([::1]:42988 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn2th-0007pQ-VO for patchwork-qemu-devel@patchwork.kernel.org; Thu, 22 Sep 2016 08:14:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52682) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn2tM-0007o9-HV for qemu-devel@nongnu.org; Thu, 22 Sep 2016 08:14:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bn2tH-0005wy-GC for qemu-devel@nongnu.org; Thu, 22 Sep 2016 08:14:15 -0400 Received: from [62.254.189.133] (port=50278 helo=centos.localdomain) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn2tH-0005oM-5i for qemu-devel@nongnu.org; Thu, 22 Sep 2016 08:14:11 -0400 Received: by centos.localdomain (Postfix, from userid 500) id 198BD9FBDC; Thu, 22 Sep 2016 13:13:53 +0100 (BST) From: Felipe Franciosi To: "Michael S. Tsirkin" , Marc-Andre Lureau Date: Thu, 22 Sep 2016 13:13:41 +0100 Message-Id: <1474546421-8613-1-git-send-email-felipe@nutanix.com> X-Mailer: git-send-email 1.9.5 X-detected-operating-system: by eggs.gnu.org: Mac OS X [generic] X-Received-From: 62.254.189.133 Subject: [Qemu-devel] [PATCH v2] Avoid additional GET_FEATURES call on vhost-user X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Felipe Franciosi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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. 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. Signed-off-by: Felipe Franciosi --- v2. Rebase on d1b4259f hw/virtio/vhost-backend.c | 27 ++++++++++++++++++--------- hw/virtio/vhost-user.c | 1 + hw/virtio/vhost.c | 9 --------- 3 files changed, 19 insertions(+), 18 deletions(-) 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, unsigned long int request, return ioctl(fd, request, arg); } -static int vhost_kernel_init(struct vhost_dev *dev, void *opaque) -{ - assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_KERNEL); - - dev->opaque = opaque; - - return 0; -} - static int vhost_kernel_cleanup(struct vhost_dev *dev) { int fd = (uintptr_t) dev->opaque; @@ -185,6 +176,24 @@ static int vhost_kernel_vsock_set_running(struct vhost_dev *dev, int start) } #endif /* CONFIG_VHOST_VSOCK */ +static int vhost_kernel_init(struct vhost_dev *dev, void *opaque) +{ + uint64_t features; + int r; + + assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_KERNEL); + + dev->opaque = opaque; + + r = vhost_kernel_get_features(dev, &features); + if (r < 0) { + return r; + } + dev->features = features; + + return 0; +} + static const VhostOps kernel_ops = { .backend_type = VHOST_BACKEND_TYPE_KERNEL, .vhost_backend_init = 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, void *opaque) if (err < 0) { return err; } + dev->features = features; if (virtio_has_feature(features, VHOST_USER_F_PROTOCOL_FEATURES)) { dev->backend_features |= 1ULL << VHOST_USER_F_PROTOCOL_FEATURES; 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_virtqueue *vq) int vhost_dev_init(struct vhost_dev *hdev, void *opaque, VhostBackendType backend_type, uint32_t busyloop_timeout) { - uint64_t features; int i, r, n_initialized_vqs = 0; hdev->migration_blocker = NULL; @@ -1077,12 +1076,6 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque, goto fail; } - r = hdev->vhost_ops->vhost_get_features(hdev, &features); - if (r < 0) { - VHOST_OPS_DEBUG("vhost_get_features failed"); - goto fail; - } - for (i = 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) { r = 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 *opaque, } } - hdev->features = features; - hdev->memory_listener = (MemoryListener) { .begin = vhost_begin, .commit = vhost_commit,