get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/127487/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 127487,
    "url": "http://patches.dpdk.org/api/patches/127487/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20230525162551.70359-19-maxime.coquelin@redhat.com/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20230525162551.70359-19-maxime.coquelin@redhat.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20230525162551.70359-19-maxime.coquelin@redhat.com",
    "date": "2023-05-25T16:25:41",
    "name": "[v3,18/28] vhost: add VDUSE device creation and destruction",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "0f15de95771f38763e76f284485072d18100153c",
    "submitter": {
        "id": 512,
        "url": "http://patches.dpdk.org/api/people/512/?format=api",
        "name": "Maxime Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "delegate": {
        "id": 2642,
        "url": "http://patches.dpdk.org/api/users/2642/?format=api",
        "username": "mcoquelin",
        "first_name": "Maxime",
        "last_name": "Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20230525162551.70359-19-maxime.coquelin@redhat.com/mbox/",
    "series": [
        {
            "id": 28187,
            "url": "http://patches.dpdk.org/api/series/28187/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=28187",
            "date": "2023-05-25T16:25:23",
            "name": "Add VDUSE support to Vhost library",
            "version": 3,
            "mbox": "http://patches.dpdk.org/series/28187/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/127487/comments/",
    "check": "warning",
    "checks": "http://patches.dpdk.org/api/patches/127487/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 9EBF742B9D;\n\tThu, 25 May 2023 18:27:55 +0200 (CEST)",
            "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id B284542D93;\n\tThu, 25 May 2023 18:27:12 +0200 (CEST)",
            "from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.133.124])\n by mails.dpdk.org (Postfix) with ESMTP id 8C75142D4B\n for <dev@dpdk.org>; Thu, 25 May 2023 18:27:07 +0200 (CEST)",
            "from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com\n [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id\n us-mta-94-jR30rsDxMM-uwM1jYSRIXA-1; Thu, 25 May 2023 12:27:04 -0400",
            "from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com\n [10.11.54.7])\n (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n (No client certificate requested)\n by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CEF0D858F18;\n Thu, 25 May 2023 16:27:03 +0000 (UTC)",
            "from max-t490s.redhat.com (unknown [10.39.208.23])\n by smtp.corp.redhat.com (Postfix) with ESMTP id 3DC04140E961;\n Thu, 25 May 2023 16:27:01 +0000 (UTC)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1685032027;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=5KxuuND75VeyavOEM34r53sQPcQmaDbybOCq+LZIwV8=;\n b=hUVWv0JR/HvvycYk/ipeMtV9rxZwziPXktpYrwK5cfg+BscNpcjsINfNkTk8uDLbMXf/jU\n fELI003OJFJQsrtb3Q5AjuzAr9M4P3ezMFYCvcl8Q466JUAlJU7CI0ZOYZpQLdkgyvmHJF\n Gadg4BFVTvlFmXPlm5iayZwfHdBz4xM=",
        "X-MC-Unique": "jR30rsDxMM-uwM1jYSRIXA-1",
        "From": "Maxime Coquelin <maxime.coquelin@redhat.com>",
        "To": "dev@dpdk.org, chenbo.xia@intel.com, david.marchand@redhat.com,\n mkp@redhat.com, fbl@redhat.com, jasowang@redhat.com,\n cunming.liang@intel.com, xieyongji@bytedance.com, echaudro@redhat.com,\n eperezma@redhat.com, amorenoz@redhat.com, lulu@redhat.com",
        "Cc": "Maxime Coquelin <maxime.coquelin@redhat.com>",
        "Subject": "[PATCH v3 18/28] vhost: add VDUSE device creation and destruction",
        "Date": "Thu, 25 May 2023 18:25:41 +0200",
        "Message-Id": "<20230525162551.70359-19-maxime.coquelin@redhat.com>",
        "In-Reply-To": "<20230525162551.70359-1-maxime.coquelin@redhat.com>",
        "References": "<20230525162551.70359-1-maxime.coquelin@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 3.1 on 10.11.54.7",
        "X-Mimecast-Spam-Score": "0",
        "X-Mimecast-Originator": "redhat.com",
        "Content-Transfer-Encoding": "8bit",
        "Content-Type": "text/plain; charset=\"US-ASCII\"; x-default=true",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org"
    },
    "content": "This patch adds initial support for VDUSE, which includes\nthe device creation and destruction.\n\nIt does not include the virtqueues configuration, so this is\nnot functionnal at this point.\n\nSigned-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>\nReviewed-by: Chenbo Xia <chenbo.xia@intel.com>\n---\n lib/vhost/meson.build |   4 +\n lib/vhost/socket.c    |  34 ++++---\n lib/vhost/vduse.c     | 201 ++++++++++++++++++++++++++++++++++++++++++\n lib/vhost/vduse.h     |  33 +++++++\n lib/vhost/vhost.h     |   2 +\n 5 files changed, 262 insertions(+), 12 deletions(-)\n create mode 100644 lib/vhost/vduse.c\n create mode 100644 lib/vhost/vduse.h",
    "diff": "diff --git a/lib/vhost/meson.build b/lib/vhost/meson.build\nindex 83c8482c9e..e63072d7a1 100644\n--- a/lib/vhost/meson.build\n+++ b/lib/vhost/meson.build\n@@ -29,6 +29,10 @@ sources = files(\n         'virtio_net.c',\n         'virtio_net_ctrl.c',\n )\n+if cc.has_header('linux/vduse.h')\n+    sources += files('vduse.c')\n+    cflags += '-DVHOST_HAS_VDUSE'\n+endif\n headers = files(\n         'rte_vdpa.h',\n         'rte_vhost.h',\ndiff --git a/lib/vhost/socket.c b/lib/vhost/socket.c\nindex e95c3ffeac..a8a1c4cd2b 100644\n--- a/lib/vhost/socket.c\n+++ b/lib/vhost/socket.c\n@@ -18,6 +18,7 @@\n #include <rte_log.h>\n \n #include \"fd_man.h\"\n+#include \"vduse.h\"\n #include \"vhost.h\"\n #include \"vhost_user.h\"\n \n@@ -35,6 +36,7 @@ struct vhost_user_socket {\n \tint socket_fd;\n \tstruct sockaddr_un un;\n \tbool is_server;\n+\tbool is_vduse;\n \tbool reconnect;\n \tbool iommu_support;\n \tbool use_builtin_virtio_net;\n@@ -992,18 +994,21 @@ rte_vhost_driver_register(const char *path, uint64_t flags)\n #endif\n \t}\n \n-\tif ((flags & RTE_VHOST_USER_CLIENT) != 0) {\n-\t\tvsocket->reconnect = !(flags & RTE_VHOST_USER_NO_RECONNECT);\n-\t\tif (vsocket->reconnect && reconn_tid == 0) {\n-\t\t\tif (vhost_user_reconnect_init() != 0)\n-\t\t\t\tgoto out_mutex;\n-\t\t}\n+\tif (!strncmp(\"/dev/vduse/\", path, strlen(\"/dev/vduse/\"))) {\n+\t\tvsocket->is_vduse = true;\n \t} else {\n-\t\tvsocket->is_server = true;\n-\t}\n-\tret = create_unix_socket(vsocket);\n-\tif (ret < 0) {\n-\t\tgoto out_mutex;\n+\t\tif ((flags & RTE_VHOST_USER_CLIENT) != 0) {\n+\t\t\tvsocket->reconnect = !(flags & RTE_VHOST_USER_NO_RECONNECT);\n+\t\t\tif (vsocket->reconnect && reconn_tid == 0) {\n+\t\t\t\tif (vhost_user_reconnect_init() != 0)\n+\t\t\t\t\tgoto out_mutex;\n+\t\t\t}\n+\t\t} else {\n+\t\t\tvsocket->is_server = true;\n+\t\t}\n+\t\tret = create_unix_socket(vsocket);\n+\t\tif (ret < 0)\n+\t\t\tgoto out_mutex;\n \t}\n \n \tvhost_user.vsockets[vhost_user.vsocket_cnt++] = vsocket;\n@@ -1068,7 +1073,9 @@ rte_vhost_driver_unregister(const char *path)\n \t\tif (strcmp(vsocket->path, path))\n \t\t\tcontinue;\n \n-\t\tif (vsocket->is_server) {\n+\t\tif (vsocket->is_vduse) {\n+\t\t\tvduse_device_destroy(path);\n+\t\t} else if (vsocket->is_server) {\n \t\t\t/*\n \t\t\t * If r/wcb is executing, release vhost_user's\n \t\t\t * mutex lock, and try again since the r/wcb\n@@ -1171,6 +1178,9 @@ rte_vhost_driver_start(const char *path)\n \tif (!vsocket)\n \t\treturn -1;\n \n+\tif (vsocket->is_vduse)\n+\t\treturn vduse_device_create(path);\n+\n \tif (fdset_tid == 0) {\n \t\t/**\n \t\t * create a pipe which will be waited by poll and notified to\ndiff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c\nnew file mode 100644\nindex 0000000000..d67818bfb5\n--- /dev/null\n+++ b/lib/vhost/vduse.c\n@@ -0,0 +1,201 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright (c) 2023 Red Hat, Inc.\n+ */\n+\n+#include <stdint.h>\n+#include <stdio.h>\n+#include <unistd.h>\n+#include <fcntl.h>\n+\n+\n+#include <linux/vduse.h>\n+#include <linux/virtio_net.h>\n+\n+#include <sys/ioctl.h>\n+#include <sys/mman.h>\n+\n+#include <rte_common.h>\n+\n+#include \"vduse.h\"\n+#include \"vhost.h\"\n+\n+#define VHOST_VDUSE_API_VERSION 0\n+#define VDUSE_CTRL_PATH \"/dev/vduse/control\"\n+\n+#define VDUSE_NET_SUPPORTED_FEATURES ((1ULL << VIRTIO_NET_F_MRG_RXBUF) | \\\n+\t\t\t\t(1ULL << VIRTIO_F_ANY_LAYOUT) | \\\n+\t\t\t\t(1ULL << VIRTIO_F_VERSION_1)   | \\\n+\t\t\t\t(1ULL << VIRTIO_NET_F_GSO) | \\\n+\t\t\t\t(1ULL << VIRTIO_NET_F_HOST_TSO4) | \\\n+\t\t\t\t(1ULL << VIRTIO_NET_F_HOST_TSO6) | \\\n+\t\t\t\t(1ULL << VIRTIO_NET_F_HOST_UFO) | \\\n+\t\t\t\t(1ULL << VIRTIO_NET_F_HOST_ECN) | \\\n+\t\t\t\t(1ULL << VIRTIO_NET_F_CSUM)    | \\\n+\t\t\t\t(1ULL << VIRTIO_NET_F_GUEST_CSUM) | \\\n+\t\t\t\t(1ULL << VIRTIO_NET_F_GUEST_TSO4) | \\\n+\t\t\t\t(1ULL << VIRTIO_NET_F_GUEST_TSO6) | \\\n+\t\t\t\t(1ULL << VIRTIO_NET_F_GUEST_UFO) | \\\n+\t\t\t\t(1ULL << VIRTIO_NET_F_GUEST_ECN) | \\\n+\t\t\t\t(1ULL << VIRTIO_RING_F_INDIRECT_DESC) | \\\n+\t\t\t\t(1ULL << VIRTIO_F_IN_ORDER) | \\\n+\t\t\t\t(1ULL << VIRTIO_F_IOMMU_PLATFORM))\n+\n+static struct vhost_backend_ops vduse_backend_ops = {\n+};\n+\n+int\n+vduse_device_create(const char *path)\n+{\n+\tint control_fd, dev_fd, vid, ret;\n+\tuint32_t i;\n+\tstruct virtio_net *dev;\n+\tuint64_t ver = VHOST_VDUSE_API_VERSION;\n+\tstruct vduse_dev_config *dev_config = NULL;\n+\tconst char *name = path + strlen(\"/dev/vduse/\");\n+\n+\tcontrol_fd = open(VDUSE_CTRL_PATH, O_RDWR);\n+\tif (control_fd < 0) {\n+\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to open %s: %s\\n\",\n+\t\t\t\tVDUSE_CTRL_PATH, strerror(errno));\n+\t\treturn -1;\n+\t}\n+\n+\tif (ioctl(control_fd, VDUSE_SET_API_VERSION, &ver)) {\n+\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to set API version: %\" PRIu64 \": %s\\n\",\n+\t\t\t\tver, strerror(errno));\n+\t\tret = -1;\n+\t\tgoto out_ctrl_close;\n+\t}\n+\n+\tdev_config = malloc(offsetof(struct vduse_dev_config, config));\n+\tif (!dev_config) {\n+\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to allocate VDUSE config\\n\");\n+\t\tret = -1;\n+\t\tgoto out_ctrl_close;\n+\t}\n+\n+\tmemset(dev_config, 0, sizeof(struct vduse_dev_config));\n+\n+\tstrncpy(dev_config->name, name, VDUSE_NAME_MAX - 1);\n+\tdev_config->device_id = VIRTIO_ID_NET;\n+\tdev_config->vendor_id = 0;\n+\tdev_config->features = VDUSE_NET_SUPPORTED_FEATURES;\n+\tdev_config->vq_num = 2;\n+\tdev_config->vq_align = sysconf(_SC_PAGE_SIZE);\n+\tdev_config->config_size = 0;\n+\n+\tret = ioctl(control_fd, VDUSE_CREATE_DEV, dev_config);\n+\tif (ret < 0) {\n+\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to create VDUSE device: %s\\n\",\n+\t\t\t\tstrerror(errno));\n+\t\tgoto out_free;\n+\t}\n+\n+\tdev_fd = open(path, O_RDWR);\n+\tif (dev_fd < 0) {\n+\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to open device %s: %s\\n\",\n+\t\t\t\tpath, strerror(errno));\n+\t\tret = -1;\n+\t\tgoto out_dev_close;\n+\t}\n+\n+\tret = fcntl(dev_fd, F_SETFL, O_NONBLOCK);\n+\tif (ret < 0) {\n+\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to set chardev as non-blocking: %s\\n\",\n+\t\t\t\tstrerror(errno));\n+\t\tgoto out_dev_close;\n+\t}\n+\n+\tvid = vhost_new_device(&vduse_backend_ops);\n+\tif (vid < 0) {\n+\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to create new Vhost device\\n\");\n+\t\tret = -1;\n+\t\tgoto out_dev_close;\n+\t}\n+\n+\tdev = get_device(vid);\n+\tif (!dev) {\n+\t\tret = -1;\n+\t\tgoto out_dev_close;\n+\t}\n+\n+\tstrncpy(dev->ifname, path, IF_NAME_SZ - 1);\n+\tdev->vduse_ctrl_fd = control_fd;\n+\tdev->vduse_dev_fd = dev_fd;\n+\tvhost_setup_virtio_net(dev->vid, true, true, true, true);\n+\n+\tfor (i = 0; i < 2; i++) {\n+\t\tstruct vduse_vq_config vq_cfg = { 0 };\n+\n+\t\tret = alloc_vring_queue(dev, i);\n+\t\tif (ret) {\n+\t\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to alloc vring %d metadata\\n\", i);\n+\t\t\tgoto out_dev_destroy;\n+\t\t}\n+\n+\t\tvq_cfg.index = i;\n+\t\tvq_cfg.max_size = 1024;\n+\n+\t\tret = ioctl(dev->vduse_dev_fd, VDUSE_VQ_SETUP, &vq_cfg);\n+\t\tif (ret) {\n+\t\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to set-up VQ %d\\n\", i);\n+\t\t\tgoto out_dev_destroy;\n+\t\t}\n+\t}\n+\n+\tfree(dev_config);\n+\n+\treturn 0;\n+\n+out_dev_destroy:\n+\tvhost_destroy_device(vid);\n+out_dev_close:\n+\tif (dev_fd >= 0)\n+\t\tclose(dev_fd);\n+\tioctl(control_fd, VDUSE_DESTROY_DEV, name);\n+out_free:\n+\tfree(dev_config);\n+out_ctrl_close:\n+\tclose(control_fd);\n+\n+\treturn ret;\n+}\n+\n+int\n+vduse_device_destroy(const char *path)\n+{\n+\tconst char *name = path + strlen(\"/dev/vduse/\");\n+\tstruct virtio_net *dev;\n+\tint vid, ret;\n+\n+\tfor (vid = 0; vid < RTE_MAX_VHOST_DEVICE; vid++) {\n+\t\tdev = vhost_devices[vid];\n+\n+\t\tif (dev == NULL)\n+\t\t\tcontinue;\n+\n+\t\tif (!strcmp(path, dev->ifname))\n+\t\t\tbreak;\n+\t}\n+\n+\tif (vid == RTE_MAX_VHOST_DEVICE)\n+\t\treturn -1;\n+\n+\tif (dev->vduse_dev_fd >= 0) {\n+\t\tclose(dev->vduse_dev_fd);\n+\t\tdev->vduse_dev_fd = -1;\n+\t}\n+\n+\tif (dev->vduse_ctrl_fd >= 0) {\n+\t\tret = ioctl(dev->vduse_ctrl_fd, VDUSE_DESTROY_DEV, name);\n+\t\tif (ret)\n+\t\t\tVHOST_LOG_CONFIG(name, ERR, \"Failed to destroy VDUSE device: %s\\n\",\n+\t\t\t\t\tstrerror(errno));\n+\t\tclose(dev->vduse_ctrl_fd);\n+\t\tdev->vduse_ctrl_fd = -1;\n+\t}\n+\n+\tvhost_destroy_device(vid);\n+\n+\treturn 0;\n+}\ndiff --git a/lib/vhost/vduse.h b/lib/vhost/vduse.h\nnew file mode 100644\nindex 0000000000..a15e5d4c16\n--- /dev/null\n+++ b/lib/vhost/vduse.h\n@@ -0,0 +1,33 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright (c) 2023 Red Hat, Inc.\n+ */\n+\n+#ifndef _VDUSE_H\n+#define _VDUSE_H\n+\n+#include \"vhost.h\"\n+\n+#ifdef VHOST_HAS_VDUSE\n+\n+int vduse_device_create(const char *path);\n+int vduse_device_destroy(const char *path);\n+\n+#else\n+\n+static inline int\n+vduse_device_create(const char *path)\n+{\n+\tVHOST_LOG_CONFIG(path, ERR, \"VDUSE support disabled at build time\\n\");\n+\treturn -1;\n+}\n+\n+static inline int\n+vduse_device_destroy(const char *path)\n+{\n+\tVHOST_LOG_CONFIG(path, ERR, \"VDUSE support disabled at build time\\n\");\n+\treturn -1;\n+}\n+\n+#endif /* VHOST_HAS_VDUSE */\n+\n+#endif /* _VDUSE_H */\ndiff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h\nindex 76663aed24..c8f2a0d43a 100644\n--- a/lib/vhost/vhost.h\n+++ b/lib/vhost/vhost.h\n@@ -524,6 +524,8 @@ struct virtio_net {\n \n \tint\t\t\tpostcopy_ufd;\n \tint\t\t\tpostcopy_listening;\n+\tint\t\t\tvduse_ctrl_fd;\n+\tint\t\t\tvduse_dev_fd;\n \n \tstruct vhost_virtqueue\t*cvq;\n \n",
    "prefixes": [
        "v3",
        "18/28"
    ]
}