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 D8B72A0A05; Tue, 19 Jan 2021 22:31:31 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 68E09140FE7; Tue, 19 Jan 2021 22:28:42 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id B2901140E88 for ; Tue, 19 Jan 2021 22:28:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611091720; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DOAdm89fOWBY3Z+gBT1rDP5t0Pqp2Qf6Hafus56Obco=; b=PSdBGEz4REAya5IE5DwLAkSsNS4IoT6bpZaWvpxGF88Adbl7wsrmPuDIV3lNHGkFz/sU+3 oUId3YPyacanJ5kHtasBvOIqmg7FNpNQVwQIFvQAvmvRRBXWYcwppR+6wcuJbOm7dRBkQc Hj/934Cxa1k0vqTk+0Xfh9eOR+cU9Es= 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-10-R1O4gmG_OKK-qrP2KZ16ag-1; Tue, 19 Jan 2021 16:28:38 -0500 X-MC-Unique: R1O4gmG_OKK-qrP2KZ16ag-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AE92210054FF; Tue, 19 Jan 2021 21:28:37 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.36.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44D0A5D9DD; Tue, 19 Jan 2021 21:28:36 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, olivier.matz@6wind.com, amorenoz@redhat.com, david.marchand@redhat.com Cc: Maxime Coquelin Date: Tue, 19 Jan 2021 22:25:05 +0100 Message-Id: <20210119212507.1043636-43-maxime.coquelin@redhat.com> In-Reply-To: <20210119212507.1043636-1-maxime.coquelin@redhat.com> References: <20210119212507.1043636-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-dev] [PATCH v2 42/44] net/virtio: move Vhost-vDPA 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" As done earlier for Vhost-user and Vhost-kernel, this patch moves the Vhost-vDPA specific data to its backend file. Signed-off-by: Maxime Coquelin --- drivers/net/virtio/virtio_user/vhost_vdpa.c | 120 +++++++++++++----- .../net/virtio/virtio_user/virtio_user_dev.h | 4 - 2 files changed, 89 insertions(+), 35 deletions(-) diff --git a/drivers/net/virtio/virtio_user/vhost_vdpa.c b/drivers/net/virtio/virtio_user/vhost_vdpa.c index 5e3778b682..e2d6d3504d 100644 --- a/drivers/net/virtio/virtio_user/vhost_vdpa.c +++ b/drivers/net/virtio/virtio_user/vhost_vdpa.c @@ -13,6 +13,11 @@ #include "vhost.h" #include "virtio_user_dev.h" +struct vhost_vdpa_data { + int vhostfd; + uint64_t protocol_features; +}; + #define VHOST_VDPA_SUPPORTED_BACKEND_FEATURES \ (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2 | \ 1ULL << VHOST_BACKEND_F_IOTLB_BATCH) @@ -88,27 +93,34 @@ vhost_vdpa_ioctl(int fd, uint64_t request, void *arg) static int vhost_vdpa_set_owner(struct virtio_user_dev *dev) { - return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_OWNER, NULL); + struct vhost_vdpa_data *data = dev->backend_data; + + return vhost_vdpa_ioctl(data->vhostfd, VHOST_SET_OWNER, NULL); } static int vhost_vdpa_get_protocol_features(struct virtio_user_dev *dev, uint64_t *features) { - return vhost_vdpa_ioctl(dev->vhostfd, VHOST_GET_BACKEND_FEATURES, features); + struct vhost_vdpa_data *data = dev->backend_data; + + return vhost_vdpa_ioctl(data->vhostfd, VHOST_GET_BACKEND_FEATURES, features); } static int vhost_vdpa_set_protocol_features(struct virtio_user_dev *dev, uint64_t features) { - return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_BACKEND_FEATURES, &features); + struct vhost_vdpa_data *data = dev->backend_data; + + return vhost_vdpa_ioctl(data->vhostfd, VHOST_SET_BACKEND_FEATURES, &features); } static int vhost_vdpa_get_features(struct virtio_user_dev *dev, uint64_t *features) { + struct vhost_vdpa_data *data = dev->backend_data; int ret; - ret = vhost_vdpa_ioctl(dev->vhostfd, VHOST_GET_FEATURES, features); + ret = vhost_vdpa_ioctl(data->vhostfd, VHOST_GET_FEATURES, features); if (ret) { PMD_DRV_LOG(ERR, "Failed to get features"); return -1; @@ -118,15 +130,15 @@ vhost_vdpa_get_features(struct virtio_user_dev *dev, uint64_t *features) *features &= ~(1ULL << VIRTIO_NET_F_MQ); /* Negotiated vDPA backend features */ - ret = vhost_vdpa_get_protocol_features(dev, &dev->protocol_features); + ret = vhost_vdpa_get_protocol_features(dev, &data->protocol_features); if (ret < 0) { PMD_DRV_LOG(ERR, "Failed to get backend features"); return -1; } - dev->protocol_features &= VHOST_VDPA_SUPPORTED_BACKEND_FEATURES; + data->protocol_features &= VHOST_VDPA_SUPPORTED_BACKEND_FEATURES; - ret = vhost_vdpa_set_protocol_features(dev, dev->protocol_features); + ret = vhost_vdpa_set_protocol_features(dev, data->protocol_features); if (ret < 0) { PMD_DRV_LOG(ERR, "Failed to set backend features"); return -1; @@ -138,21 +150,24 @@ vhost_vdpa_get_features(struct virtio_user_dev *dev, uint64_t *features) static int vhost_vdpa_set_features(struct virtio_user_dev *dev, uint64_t features) { + struct vhost_vdpa_data *data = dev->backend_data; + /* WORKAROUND */ features |= 1ULL << VIRTIO_F_IOMMU_PLATFORM; - return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_FEATURES, &features); + return vhost_vdpa_ioctl(data->vhostfd, VHOST_SET_FEATURES, &features); } static int vhost_vdpa_iotlb_batch_begin(struct virtio_user_dev *dev) { + struct vhost_vdpa_data *data = dev->backend_data; struct vhost_msg msg = {}; - if (!(dev->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_BATCH))) + if (!(data->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_BATCH))) return 0; - if (!(dev->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2))) { + if (!(data->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2))) { PMD_DRV_LOG(ERR, "IOTLB_MSG_V2 not supported by the backend."); return -1; } @@ -160,7 +175,7 @@ vhost_vdpa_iotlb_batch_begin(struct virtio_user_dev *dev) msg.type = VHOST_IOTLB_MSG_V2; msg.iotlb.type = VHOST_IOTLB_BATCH_BEGIN; - if (write(dev->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) { + if (write(data->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) { PMD_DRV_LOG(ERR, "Failed to send IOTLB batch begin (%s)", strerror(errno)); return -1; @@ -172,12 +187,13 @@ vhost_vdpa_iotlb_batch_begin(struct virtio_user_dev *dev) static int vhost_vdpa_iotlb_batch_end(struct virtio_user_dev *dev) { + struct vhost_vdpa_data *data = dev->backend_data; struct vhost_msg msg = {}; - if (!(dev->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_BATCH))) + if (!(data->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_BATCH))) return 0; - if (!(dev->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2))) { + if (!(data->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2))) { PMD_DRV_LOG(ERR, "IOTLB_MSG_V2 not supported by the backend."); return -1; } @@ -185,7 +201,7 @@ vhost_vdpa_iotlb_batch_end(struct virtio_user_dev *dev) msg.type = VHOST_IOTLB_MSG_V2; msg.iotlb.type = VHOST_IOTLB_BATCH_END; - if (write(dev->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) { + if (write(data->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) { PMD_DRV_LOG(ERR, "Failed to send IOTLB batch end (%s)", strerror(errno)); return -1; @@ -198,9 +214,10 @@ static int vhost_vdpa_dma_map(struct virtio_user_dev *dev, void *addr, uint64_t iova, size_t len) { + struct vhost_vdpa_data *data = dev->backend_data; struct vhost_msg msg = {}; - if (!(dev->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2))) { + if (!(data->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2))) { PMD_DRV_LOG(ERR, "IOTLB_MSG_V2 not supported by the backend."); return -1; } @@ -215,7 +232,7 @@ vhost_vdpa_dma_map(struct virtio_user_dev *dev, void *addr, PMD_DRV_LOG(DEBUG, "%s: iova: 0x%" PRIx64 ", addr: %p, len: 0x%zx", __func__, iova, addr, len); - if (write(dev->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) { + if (write(data->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) { PMD_DRV_LOG(ERR, "Failed to send IOTLB update (%s)", strerror(errno)); return -1; @@ -228,9 +245,10 @@ static int vhost_vdpa_dma_unmap(struct virtio_user_dev *dev, __rte_unused void *addr, uint64_t iova, size_t len) { + struct vhost_vdpa_data *data = dev->backend_data; struct vhost_msg msg = {}; - if (!(dev->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2))) { + if (!(data->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2))) { PMD_DRV_LOG(ERR, "IOTLB_MSG_V2 not supported by the backend."); return -1; } @@ -243,7 +261,7 @@ vhost_vdpa_dma_unmap(struct virtio_user_dev *dev, __rte_unused void *addr, PMD_DRV_LOG(DEBUG, "%s: iova: 0x%" PRIx64 ", len: 0x%zx", __func__, iova, len); - if (write(dev->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) { + if (write(data->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) { PMD_DRV_LOG(ERR, "Failed to send IOTLB invalidate (%s)", strerror(errno)); return -1; @@ -353,55 +371,73 @@ vhost_vdpa_set_memory_table(struct virtio_user_dev *dev) static int vhost_vdpa_set_vring_enable(struct virtio_user_dev *dev, struct vhost_vring_state *state) { - return vhost_vdpa_ioctl(dev->vhostfd, VHOST_VDPA_SET_VRING_ENABLE, state); + struct vhost_vdpa_data *data = dev->backend_data; + + return vhost_vdpa_ioctl(data->vhostfd, VHOST_VDPA_SET_VRING_ENABLE, state); } static int vhost_vdpa_set_vring_num(struct virtio_user_dev *dev, struct vhost_vring_state *state) { - return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_VRING_NUM, state); + struct vhost_vdpa_data *data = dev->backend_data; + + return vhost_vdpa_ioctl(data->vhostfd, VHOST_SET_VRING_NUM, state); } static int vhost_vdpa_set_vring_base(struct virtio_user_dev *dev, struct vhost_vring_state *state) { - return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_VRING_BASE, state); + struct vhost_vdpa_data *data = dev->backend_data; + + return vhost_vdpa_ioctl(data->vhostfd, VHOST_SET_VRING_BASE, state); } static int vhost_vdpa_get_vring_base(struct virtio_user_dev *dev, struct vhost_vring_state *state) { - return vhost_vdpa_ioctl(dev->vhostfd, VHOST_GET_VRING_BASE, state); + struct vhost_vdpa_data *data = dev->backend_data; + + return vhost_vdpa_ioctl(data->vhostfd, VHOST_GET_VRING_BASE, state); } static int vhost_vdpa_set_vring_call(struct virtio_user_dev *dev, struct vhost_vring_file *file) { - return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_VRING_CALL, file); + struct vhost_vdpa_data *data = dev->backend_data; + + return vhost_vdpa_ioctl(data->vhostfd, VHOST_SET_VRING_CALL, file); } static int vhost_vdpa_set_vring_kick(struct virtio_user_dev *dev, struct vhost_vring_file *file) { - return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_VRING_KICK, file); + struct vhost_vdpa_data *data = dev->backend_data; + + return vhost_vdpa_ioctl(data->vhostfd, VHOST_SET_VRING_KICK, file); } static int vhost_vdpa_set_vring_addr(struct virtio_user_dev *dev, struct vhost_vring_addr *addr) { - return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_VRING_ADDR, addr); + struct vhost_vdpa_data *data = dev->backend_data; + + return vhost_vdpa_ioctl(data->vhostfd, VHOST_SET_VRING_ADDR, addr); } static int vhost_vdpa_get_status(struct virtio_user_dev *dev, uint8_t *status) { - return vhost_vdpa_ioctl(dev->vhostfd, VHOST_VDPA_GET_STATUS, status); + struct vhost_vdpa_data *data = dev->backend_data; + + return vhost_vdpa_ioctl(data->vhostfd, VHOST_VDPA_GET_STATUS, status); } static int vhost_vdpa_set_status(struct virtio_user_dev *dev, uint8_t status) { - return vhost_vdpa_ioctl(dev->vhostfd, VHOST_VDPA_SET_STATUS, &status); + struct vhost_vdpa_data *data = dev->backend_data; + + return vhost_vdpa_ioctl(data->vhostfd, VHOST_VDPA_SET_STATUS, &status); } /** @@ -414,27 +450,49 @@ vhost_vdpa_set_status(struct virtio_user_dev *dev, uint8_t status) static int vhost_vdpa_setup(struct virtio_user_dev *dev) { + struct vhost_vdpa_data *data; uint32_t did = (uint32_t)-1; - dev->vhostfd = open(dev->path, O_RDWR); - if (dev->vhostfd < 0) { + data = malloc(sizeof(*data)); + if (!data) { + PMD_DRV_LOG(ERR, "(%s) Faidle to allocate backend data", dev->path); + return -1; + } + + data->vhostfd = open(dev->path, O_RDWR); + if (data->vhostfd < 0) { PMD_DRV_LOG(ERR, "Failed to open %s: %s\n", dev->path, strerror(errno)); + free(data); return -1; } - if (ioctl(dev->vhostfd, VHOST_VDPA_GET_DEVICE_ID, &did) < 0 || + if (ioctl(data->vhostfd, VHOST_VDPA_GET_DEVICE_ID, &did) < 0 || did != VIRTIO_ID_NETWORK) { PMD_DRV_LOG(ERR, "Invalid vdpa device ID: %u\n", did); + close(data->vhostfd); + free(data); return -1; } + dev->backend_data = data; + return 0; } static int -vhost_vdpa_destroy(struct virtio_user_dev *dev __rte_unused) +vhost_vdpa_destroy(struct virtio_user_dev *dev) { + struct vhost_vdpa_data *data = dev->backend_data; + + if (!data) + return 0; + + close(data->vhostfd); + + free(data); + dev->backend_data = NULL; + return 0; } diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h index 36a9cadcad..9a6723da24 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h @@ -29,9 +29,6 @@ struct virtio_user_dev { enum virtio_user_backend_type backend_type; bool is_server; /* server or client mode */ - /* for vhost_vdpa backend */ - int vhostfd; - /* for both vhost_user and vhost_kernel */ int callfds[VIRTIO_MAX_VIRTQUEUES]; int kickfds[VIRTIO_MAX_VIRTQUEUES]; @@ -45,7 +42,6 @@ struct virtio_user_dev { uint64_t device_features; /* supported features by device */ uint64_t frontend_features; /* enabled frontend features */ uint64_t unsupported_features; /* unsupported features mask */ - uint64_t protocol_features; /* negotiated protocol features */ uint8_t status; uint16_t net_status; uint16_t port_id; -- 2.29.2