[dpdk-dev] [PATCH v2 41/44] net/virtio: move Vhost-kernel data to its backend

Maxime Coquelin maxime.coquelin at redhat.com
Mon Jan 25 15:59:16 CET 2021



On 1/22/21 9:55 AM, Xia, Chenbo wrote:
> Hi Maxime,
> 
>> -----Original Message-----
>> From: Maxime Coquelin <maxime.coquelin at redhat.com>
>> Sent: Wednesday, January 20, 2021 5:25 AM
>> To: dev at dpdk.org; Xia, Chenbo <chenbo.xia at intel.com>; olivier.matz at 6wind.com;
>> amorenoz at redhat.com; david.marchand at redhat.com
>> Cc: Maxime Coquelin <maxime.coquelin at redhat.com>
>> Subject: [PATCH v2 41/44] net/virtio: move Vhost-kernel data to its backend
>>
>> As done earlier for Vhost-user, this patch moves the
>> Vhost-Kernel specific data to its backend file.
>>
>> Signed-off-by: Maxime Coquelin <maxime.coquelin at redhat.com>
>> ---
>>  drivers/net/virtio/virtio_user/vhost_kernel.c | 106 +++++++++++++++---
>>  .../net/virtio/virtio_user/virtio_user_dev.c  |  43 ++-----
>>  .../net/virtio/virtio_user/virtio_user_dev.h  |   7 +-
>>  3 files changed, 98 insertions(+), 58 deletions(-)
>>
>> diff --git a/drivers/net/virtio/virtio_user/vhost_kernel.c
>> b/drivers/net/virtio/virtio_user/vhost_kernel.c
>> index aa1f9ece5e..bc4b3461e1 100644
>> --- a/drivers/net/virtio/virtio_user/vhost_kernel.c
>> +++ b/drivers/net/virtio/virtio_user/vhost_kernel.c
>> @@ -14,6 +14,11 @@
>>  #include "virtio_user_dev.h"
>>  #include "vhost_kernel_tap.h"
>>
>> +struct vhost_kernel_data {
>> +	int *vhostfds;
>> +	int *tapfds;
>> +};
>> +
>>  struct vhost_memory_kernel {
>>  	uint32_t nregions;
>>  	uint32_t padding;
>> @@ -96,7 +101,9 @@ vhost_kernel_ioctl(int fd, uint64_t request, void *arg)
>>  static int
>>  vhost_kernel_set_owner(struct virtio_user_dev *dev)
>>  {
>> -	return vhost_kernel_ioctl(dev->vhostfds[0], VHOST_SET_OWNER, NULL);
>> +	struct vhost_kernel_data *data = dev->backend_data;
>> +
>> +	return vhost_kernel_ioctl(data->vhostfds[0], VHOST_SET_OWNER, NULL);
>>  }
>>
>>  static int
>> @@ -104,8 +111,9 @@ vhost_kernel_get_features(struct virtio_user_dev *dev,
>> uint64_t *features)
>>  {
>>  	int ret;
>>  	unsigned int tap_features;
>> +	struct vhost_kernel_data *data = dev->backend_data;
>>
>> -	ret = vhost_kernel_ioctl(dev->vhostfds[0], VHOST_GET_FEATURES, features);
>> +	ret = vhost_kernel_ioctl(data->vhostfds[0], VHOST_GET_FEATURES,
>> features);
>>  	if (ret < 0) {
>>  		PMD_DRV_LOG(ERR, "Failed to get features");
>>  		return -1;
>> @@ -138,6 +146,8 @@ vhost_kernel_get_features(struct virtio_user_dev *dev,
>> uint64_t *features)
>>  static int
>>  vhost_kernel_set_features(struct virtio_user_dev *dev, uint64_t features)
>>  {
>> +	struct vhost_kernel_data *data = dev->backend_data;
>> +
>>  	/* We don't need memory protection here */
>>  	features &= ~(1ULL << VIRTIO_F_IOMMU_PLATFORM);
>>  	/* VHOST kernel does not know about below flags */
>> @@ -145,7 +155,7 @@ vhost_kernel_set_features(struct virtio_user_dev *dev,
>> uint64_t features)
>>  	features &= ~VHOST_KERNEL_HOST_OFFLOADS_MASK;
>>  	features &= ~(1ULL << VIRTIO_NET_F_MQ);
>>
>> -	return vhost_kernel_ioctl(dev->vhostfds[0], VHOST_SET_FEATURES,
>> &features);
>> +	return vhost_kernel_ioctl(data->vhostfds[0], VHOST_SET_FEATURES,
>> &features);
>>  }
>>
>>  static int
>> @@ -185,6 +195,7 @@ add_memseg_list(const struct rte_memseg_list *msl, void
>> *arg)
>>  static int
>>  vhost_kernel_set_memory_table(struct virtio_user_dev *dev)
>>  {
>> +	struct vhost_kernel_data *data = dev->backend_data;
>>  	struct vhost_memory_kernel *vm;
>>  	int ret;
>>
>> @@ -205,7 +216,7 @@ vhost_kernel_set_memory_table(struct virtio_user_dev *dev)
>>  	if (ret < 0)
>>  		goto err_free;
>>
>> -	ret = vhost_kernel_ioctl(dev->vhostfds[0], VHOST_SET_MEM_TABLE, vm);
>> +	ret = vhost_kernel_ioctl(data->vhostfds[0], VHOST_SET_MEM_TABLE, vm);
>>  	if (ret < 0)
>>  		goto err_free;
>>
>> @@ -224,9 +235,10 @@ vhost_kernel_set_vring(struct virtio_user_dev *dev,
>> uint64_t req, struct vhost_v
>>  {
>>  	int ret, fd;
>>  	unsigned int index = state->index;
>> +	struct vhost_kernel_data *data = dev->backend_data;
>>
>>  	/* Convert from queue index to queue-pair & offset */
>> -	fd = dev->vhostfds[state->index / 2];
>> +	fd = data->vhostfds[state->index / 2];
>>  	state->index %= 2;
>>
>>  	ret = vhost_kernel_ioctl(fd, req, state);
>> @@ -265,9 +277,10 @@ vhost_kernel_set_vring_file(struct virtio_user_dev *dev,
>> uint64_t req,
>>  {
>>  	int ret, fd;
>>  	unsigned int index = file->index;
>> +	struct vhost_kernel_data *data = dev->backend_data;
>>
>>  	/* Convert from queue index to queue-pair & offset */
>> -	fd = dev->vhostfds[file->index / 2];
>> +	fd = data->vhostfds[file->index / 2];
>>  	file->index %= 2;
>>
>>  	ret = vhost_kernel_ioctl(fd, req, file);
>> @@ -299,9 +312,10 @@ vhost_kernel_set_vring_addr(struct virtio_user_dev *dev,
>> struct vhost_vring_addr
>>  {
>>  	int ret, fd;
>>  	unsigned int index = addr->index;
>> +	struct vhost_kernel_data *data = dev->backend_data;
>>
>>  	/* Convert from queue index to queue-pair & offset */
>> -	fd = dev->vhostfds[addr->index / 2];
>> +	fd = data->vhostfds[addr->index / 2];
>>  	addr->index %= 2;
>>
>>  	ret = vhost_kernel_ioctl(fd, VHOST_SET_VRING_ADDR, addr);
>> @@ -339,27 +353,82 @@ static int
>>  vhost_kernel_setup(struct virtio_user_dev *dev)
>>  {
>>  	int vhostfd;
>> -	uint32_t i;
>> +	uint32_t q, i;
>> +	struct vhost_kernel_data *data;
>> +
>> +	data = malloc(sizeof(*data));
>> +	if (!data) {
>> +		PMD_INIT_LOG(ERR, "(%s) Failed to allocate Vhost-kernel data",
>> dev->path);
>> +		return -1;
>> +	}
>> +
>> +	data->vhostfds = malloc(dev->max_queue_pairs * sizeof(int));
>> +	if (!data->vhostfds) {
>> +		PMD_INIT_LOG(ERR, "(%s) Failed to allocate Vhost FDs", dev->path);
>> +		goto err_data;
>> +	}
>> +	data->tapfds = malloc(dev->max_queue_pairs * sizeof(int));
>> +	if (!data->tapfds) {
>> +		PMD_INIT_LOG(ERR, "(%s) Failed to allocate FDs", dev->path);
> 
> 'allocate tap FDs'?

Done.

> With this fixed:
> 
> Reviewed-by: Chenbo Xia <chenbo.xia at intel.com>

Thanks,
Maxime



More information about the dev mailing list