[dpdk-dev] [PATCH 01/28] vhost: introduce vhost transport operations structure
Nikos Dragazis
ndragazis at arrikto.com
Thu Jun 20 20:19:37 CEST 2019
On 19/6/19 11:14 μ.μ., Aaron Conole wrote:
> Nikos Dragazis <ndragazis at arrikto.com> 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 <ndragazis at arrikto.com>
>> Signed-off-by: Stefan Hajnoczi <stefanha at redhat.com>
>> ---
> 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
More information about the dev
mailing list