From patchwork Wed Jun 19 15:14:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikos Dragazis X-Patchwork-Id: 54955 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BCCAE1C38B; Wed, 19 Jun 2019 17:15:39 +0200 (CEST) Received: from mx0.arrikto.com (mx0.arrikto.com [212.71.252.59]) by dpdk.org (Postfix) with ESMTP id 270F82BEA for ; Wed, 19 Jun 2019 17:15:36 +0200 (CEST) Received: from troi.prod.arr (mail.arr [10.99.0.5]) by mx0.arrikto.com (Postfix) with ESMTP id C0AFF182005; Wed, 19 Jun 2019 18:15:35 +0300 (EEST) Received: from localhost.localdomain (unknown [10.89.50.133]) by troi.prod.arr (Postfix) with ESMTPSA id 36DAE32C; Wed, 19 Jun 2019 18:15:35 +0300 (EEST) From: Nikos Dragazis To: dev@dpdk.org Cc: Maxime Coquelin , Tiwei Bie , Zhihong Wang , Stefan Hajnoczi , Wei Wang , Stojaczyk Dariusz , Vangelis Koukis Date: Wed, 19 Jun 2019 18:14:26 +0300 Message-Id: <1560957293-17294-2-git-send-email-ndragazis@arrikto.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560957293-17294-1-git-send-email-ndragazis@arrikto.com> References: <1560957293-17294-1-git-send-email-ndragazis@arrikto.com> Subject: [dpdk-dev] [PATCH 01/28] vhost: introduce vhost transport operations structure X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This is the first of a series of patches, whose purpose is to add support for the virtio-vhost-user transport. This is a vhost-user transport implementation that is different from the default AF_UNIX transport. It uses the virtio-vhost-user PCI device in order to tunnel vhost-user protocol messages over virtio. This lets guests act as vhost device backends for other guests. File descriptor passing is specific to the AF_UNIX vhost-user protocol transport. In order to add support for additional transports, it is necessary to extract transport-specific code from the main vhost-user code. This patch introduces struct vhost_transport_ops and associates each device with a transport. Core vhost-user code calls into vhost_transport_ops to perform transport-specific operations. Notifying callfd is a transport-specific operation, so it belongs to trans_af_unix.c. Several more patches follow this one to complete the task of moving AF_UNIX transport code out of core vhost-user code. Signed-off-by: Nikos Dragazis Signed-off-by: Stefan Hajnoczi --- lib/librte_vhost/Makefile | 2 +- lib/librte_vhost/trans_af_unix.c | 20 ++++++++++++++++++++ lib/librte_vhost/vhost.c | 1 + lib/librte_vhost/vhost.h | 34 +++++++++++++++++++++++++++++----- 4 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 lib/librte_vhost/trans_af_unix.c diff --git a/lib/librte_vhost/Makefile b/lib/librte_vhost/Makefile index 8623e91..5ff5fb2 100644 --- a/lib/librte_vhost/Makefile +++ b/lib/librte_vhost/Makefile @@ -23,7 +23,7 @@ LDLIBS += -lrte_eal -lrte_mempool -lrte_mbuf -lrte_ethdev -lrte_net # all source are stored in SRCS-y SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := fd_man.c iotlb.c socket.c vhost.c \ - vhost_user.c virtio_net.c vdpa.c + vhost_user.c virtio_net.c vdpa.c trans_af_unix.c # install includes SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h rte_vdpa.h diff --git a/lib/librte_vhost/trans_af_unix.c b/lib/librte_vhost/trans_af_unix.c new file mode 100644 index 0000000..3f0c308 --- /dev/null +++ b/lib/librte_vhost/trans_af_unix.c @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2018 Intel Corporation + * Copyright(c) 2017 Red Hat, Inc. + * Copyright(c) 2019 Arrikto Inc. + */ + +#include "vhost.h" + +static int +af_unix_vring_call(struct virtio_net *dev __rte_unused, + struct vhost_virtqueue *vq) +{ + if (vq->callfd >= 0) + eventfd_write(vq->callfd, (eventfd_t)1); + return 0; +} + +const struct vhost_transport_ops af_unix_trans_ops = { + .vring_call = af_unix_vring_call, +}; diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index 981837b..a36bc01 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -507,6 +507,7 @@ vhost_new_device(void) dev->vid = i; dev->flags = VIRTIO_DEV_BUILTIN_VIRTIO_NET; dev->slave_req_fd = -1; + dev->trans_ops = &af_unix_trans_ops; dev->vdpa_dev_id = -1; dev->postcopy_ufd = -1; rte_spinlock_init(&dev->slave_req_lock); diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index 884befa..077f213 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -286,6 +286,30 @@ struct guest_page { uint64_t size; }; +struct virtio_net; + +/** + * A structure containing function pointers for transport-specific operations. + */ +struct vhost_transport_ops { + /** + * Notify the guest that used descriptors have been added to the vring. + * The VRING_AVAIL_F_NO_INTERRUPT flag and event idx have already been checked + * so this function just needs to perform the notification. + * + * @param dev + * vhost device + * @param vq + * vhost virtqueue + * @return + * 0 on success, -1 on failure + */ + int (*vring_call)(struct virtio_net *dev, struct vhost_virtqueue *vq); +}; + +/** The traditional AF_UNIX vhost-user protocol transport. */ +extern const struct vhost_transport_ops af_unix_trans_ops; + /** * Device structure contains all configuration information relating * to the device. @@ -312,6 +336,7 @@ struct virtio_net { uint16_t mtu; struct vhost_device_ops const *notify_ops; + struct vhost_transport_ops const *trans_ops; uint32_t nr_guest_pages; uint32_t max_guest_pages; @@ -544,12 +569,11 @@ vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq) if ((vhost_need_event(vhost_used_event(vq), new, old) && (vq->callfd >= 0)) || unlikely(!signalled_used_valid)) - eventfd_write(vq->callfd, (eventfd_t) 1); + dev->trans_ops->vring_call(dev, vq); } else { /* Kick the guest if necessary. */ - if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT) - && (vq->callfd >= 0)) - eventfd_write(vq->callfd, (eventfd_t)1); + if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)) + dev->trans_ops->vring_call(dev, vq); } } @@ -601,7 +625,7 @@ vhost_vring_call_packed(struct virtio_net *dev, struct vhost_virtqueue *vq) kick = true; kick: if (kick) - eventfd_write(vq->callfd, (eventfd_t)1); + dev->trans_ops->vring_call(dev, vq); } static __rte_always_inline void