From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 693FEA052A; Mon, 25 Jan 2021 15:59:27 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 533D9140F6D; Mon, 25 Jan 2021 15:59:27 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id 840BE140F64 for ; Mon, 25 Jan 2021 15:59:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611586765; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OdINhfKzd6IvIKXdEdloRaoRhIwVjoINTa2+snEf92c=; b=LS+S2VKEB4NsY7Age1D6eWUaZ01fCvDz4ISlpTe7YSDgQGxGoG8XxZMFl3winAK1mQlTF6 ltxHEWLMkc5e5SkR9jva4vSC+yV3KP/cB7JwvPMXSKbKvfmKXwT6W9oogoTN40sOvfxOSA krrjUTzGJbU0iG1/qtlnO1vMe9iwum8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-359-nW4rVvMTPzi2nawx361BzQ-1; Mon, 25 Jan 2021 09:59:24 -0500 X-MC-Unique: nW4rVvMTPzi2nawx361BzQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D7C6A8145E0; Mon, 25 Jan 2021 14:59:22 +0000 (UTC) Received: from [10.36.110.31] (unknown [10.36.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1DE255D71D; Mon, 25 Jan 2021 14:59:17 +0000 (UTC) To: "Xia, Chenbo" , "dev@dpdk.org" , "olivier.matz@6wind.com" , "amorenoz@redhat.com" , "david.marchand@redhat.com" References: <20210119212507.1043636-1-maxime.coquelin@redhat.com> <20210119212507.1043636-42-maxime.coquelin@redhat.com> From: Maxime Coquelin Message-ID: <674833d7-f17e-b16c-518c-ce9767d37aa9@redhat.com> Date: Mon, 25 Jan 2021 15:59:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v2 41/44] net/virtio: move Vhost-kernel data to its backend X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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 1/22/21 9:55 AM, Xia, Chenbo wrote: > Hi Maxime, > >> -----Original Message----- >> From: Maxime Coquelin >> Sent: Wednesday, January 20, 2021 5:25 AM >> To: dev@dpdk.org; Xia, Chenbo ; olivier.matz@6wind.com; >> amorenoz@redhat.com; david.marchand@redhat.com >> Cc: Maxime Coquelin >> 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 >> --- >> 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 Thanks, Maxime