From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 4D955A0471 for ; Thu, 20 Jun 2019 20:19:40 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A1B101D434; Thu, 20 Jun 2019 20:19:39 +0200 (CEST) Received: from mx0.arrikto.com (mx0.arrikto.com [212.71.252.59]) by dpdk.org (Postfix) with ESMTP id 48D3B1D42B for ; Thu, 20 Jun 2019 20:19:38 +0200 (CEST) Received: from troi.prod.arr (mail.arr [10.99.0.5]) by mx0.arrikto.com (Postfix) with ESMTP id EF793182004; Thu, 20 Jun 2019 21:19:37 +0300 (EEST) Received: from [10.89.50.133] (unknown [10.89.50.133]) by troi.prod.arr (Postfix) with ESMTPSA id 7CCDA2B2; Thu, 20 Jun 2019 21:19:37 +0300 (EEST) To: Aaron Conole Cc: dev@dpdk.org, Maxime Coquelin , Tiwei Bie , Zhihong Wang , Stefan Hajnoczi , Wei Wang , Stojaczyk Dariusz , Vangelis Koukis References: <1560957293-17294-1-git-send-email-ndragazis@arrikto.com> <1560957293-17294-2-git-send-email-ndragazis@arrikto.com> From: Nikos Dragazis Message-ID: Date: Thu, 20 Jun 2019 21:19:37 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US Subject: Re: [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" On 19/6/19 11:14 μ.μ., Aaron Conole wrote: > Nikos Dragazis writes: > >> 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 >> --- > You'll need to also accommodate the meson build - probably with > something like: > > diff --git a/lib/librte_vhost/meson.build b/lib/librte_vhost/meson.build > index 3090bbe08..81b70683b 100644 > --- a/lib/librte_vhost/meson.build > +++ b/lib/librte_vhost/meson.build > @@ -14,6 +14,6 @@ allow_experimental_apis = true > cflags += '-fno-strict-aliasing' > sources = files('fd_man.c', 'iotlb.c', 'socket.c', 'vdpa.c', > 'vhost.c', 'vhost_user.c', > - 'virtio_net.c', 'vhost_crypto.c') > + 'virtio_net.c', 'vhost_crypto.c', 'trans_af_unix.c') > headers = files('rte_vhost.h', 'rte_vdpa.h', 'rte_vhost_crypto.h') > deps += ['ethdev', 'cryptodev', 'hash', 'pci'] Thanks for the pointer. I will incorporate the change in the second version of the patch series along with any other potential comments. > > >> 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