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 610DFA0471 for ; Wed, 19 Jun 2019 22:14:22 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 245001D03C; Wed, 19 Jun 2019 22:14:21 +0200 (CEST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id D1B4C1D039 for ; Wed, 19 Jun 2019 22:14:18 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 00A667E426; Wed, 19 Jun 2019 20:14:18 +0000 (UTC) Received: from dhcp-25.97.bos.redhat.com (ovpn-124-68.rdu2.redhat.com [10.10.124.68]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B2FD1001B12; Wed, 19 Jun 2019 20:14:10 +0000 (UTC) From: Aaron Conole To: Nikos Dragazis 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> Date: Wed, 19 Jun 2019 16:14:09 -0400 In-Reply-To: <1560957293-17294-2-git-send-email-ndragazis@arrikto.com> (Nikos Dragazis's message of "Wed, 19 Jun 2019 18:14:26 +0300") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 19 Jun 2019 20:14:18 +0000 (UTC) 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" 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'] > 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