get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 128180,
    "url": "http://patchwork.dpdk.org/api/patches/128180/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/20230606081852.71003-16-maxime.coquelin@redhat.com/",
    "project": {
        "id": 1,
        "url": "http://patchwork.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": "<20230606081852.71003-16-maxime.coquelin@redhat.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20230606081852.71003-16-maxime.coquelin@redhat.com",
    "date": "2023-06-06T08:18:41",
    "name": "[v5,15/26] vhost: add control virtqueue support",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "6b47b25c719b540a5de4a3afcfd4eea55ef1f08f",
    "submitter": {
        "id": 512,
        "url": "http://patchwork.dpdk.org/api/people/512/?format=api",
        "name": "Maxime Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "delegate": {
        "id": 2642,
        "url": "http://patchwork.dpdk.org/api/users/2642/?format=api",
        "username": "mcoquelin",
        "first_name": "Maxime",
        "last_name": "Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/20230606081852.71003-16-maxime.coquelin@redhat.com/mbox/",
    "series": [
        {
            "id": 28365,
            "url": "http://patchwork.dpdk.org/api/series/28365/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=28365",
            "date": "2023-06-06T08:18:26",
            "name": "Add VDUSE support to Vhost library",
            "version": 5,
            "mbox": "http://patchwork.dpdk.org/series/28365/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/128180/comments/",
    "check": "warning",
    "checks": "http://patchwork.dpdk.org/api/patches/128180/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 911AD42C3E;\n\tTue,  6 Jun 2023 10:20:41 +0200 (CEST)",
            "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id BD3C542D85;\n\tTue,  6 Jun 2023 10:19:46 +0200 (CEST)",
            "from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by mails.dpdk.org (Postfix) with ESMTP id 69EA842D56\n for <dev@dpdk.org>; Tue,  6 Jun 2023 10:19:45 +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-155-hsdVi_GmP3y7aueGXhFQuw-1; Tue, 06 Jun 2023 04:19:42 -0400",
            "from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com\n [10.11.54.1])\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 73642801182;\n Tue,  6 Jun 2023 08:19:41 +0000 (UTC)",
            "from max-t490s.redhat.com (unknown [10.39.208.25])\n by smtp.corp.redhat.com (Postfix) with ESMTP id ECF2140CF8F6;\n Tue,  6 Jun 2023 08:19:38 +0000 (UTC)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1686039585;\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=YPQYGUKXd3T5G0nzSO7UYxof2jO85vBggzbd+oY0ZrI=;\n b=In4UD6wxCkzkPN8CiaYpoaXwpjoMjI6bK9czYfby42bQ/ScHMOZEqgCZaVrkK8lJgMZFY1\n TlCmIPUsnJVhywqWdKgRCZ2Klwf2Um3pXTkSjhoE8Vt2O1TUwScqN8tHOckpSfqs589MfT\n iLHcOQ6mrioOrp3mOQW4LnFGabt3yps=",
        "X-MC-Unique": "hsdVi_GmP3y7aueGXhFQuw-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 v5 15/26] vhost: add control virtqueue support",
        "Date": "Tue,  6 Jun 2023 10:18:41 +0200",
        "Message-Id": "<20230606081852.71003-16-maxime.coquelin@redhat.com>",
        "In-Reply-To": "<20230606081852.71003-1-maxime.coquelin@redhat.com>",
        "References": "<20230606081852.71003-1-maxime.coquelin@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 3.1 on 10.11.54.1",
        "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": "In order to support multi-queue with VDUSE, having\ncontrol queue support is required.\n\nThis patch adds control queue implementation, it will be\nused later when adding VDUSE support. Only split ring\nlayout is supported for now, packed ring support will be\nadded later.\n\nSigned-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>\nReviewed-by: Chenbo Xia <chenbo.xia@intel.com>\n---\n lib/vhost/meson.build       |   1 +\n lib/vhost/vhost.h           |   2 +\n lib/vhost/virtio_net_ctrl.c | 286 ++++++++++++++++++++++++++++++++++++\n lib/vhost/virtio_net_ctrl.h |  10 ++\n 4 files changed, 299 insertions(+)\n create mode 100644 lib/vhost/virtio_net_ctrl.c\n create mode 100644 lib/vhost/virtio_net_ctrl.h",
    "diff": "diff --git a/lib/vhost/meson.build b/lib/vhost/meson.build\nindex 05679447db..d211a0bd37 100644\n--- a/lib/vhost/meson.build\n+++ b/lib/vhost/meson.build\n@@ -27,6 +27,7 @@ sources = files(\n         'vhost_crypto.c',\n         'vhost_user.c',\n         'virtio_net.c',\n+        'virtio_net_ctrl.c',\n )\n headers = files(\n         'rte_vdpa.h',\ndiff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h\nindex ea2798b0bf..04267a3ac5 100644\n--- a/lib/vhost/vhost.h\n+++ b/lib/vhost/vhost.h\n@@ -527,6 +527,8 @@ struct virtio_net {\n \tint\t\t\tpostcopy_ufd;\n \tint\t\t\tpostcopy_listening;\n \n+\tstruct vhost_virtqueue\t*cvq;\n+\n \tstruct rte_vdpa_device *vdpa_dev;\n \n \t/* context data for the external message handlers */\ndiff --git a/lib/vhost/virtio_net_ctrl.c b/lib/vhost/virtio_net_ctrl.c\nnew file mode 100644\nindex 0000000000..6b583a0ce6\n--- /dev/null\n+++ b/lib/vhost/virtio_net_ctrl.c\n@@ -0,0 +1,286 @@\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+\n+#include \"iotlb.h\"\n+#include \"vhost.h\"\n+#include \"virtio_net_ctrl.h\"\n+\n+struct virtio_net_ctrl {\n+\tuint8_t class;\n+\tuint8_t command;\n+\tuint8_t command_data[];\n+};\n+\n+struct virtio_net_ctrl_elem {\n+\tstruct virtio_net_ctrl *ctrl_req;\n+\tuint16_t head_idx;\n+\tuint16_t n_descs;\n+\tuint8_t *desc_ack;\n+};\n+\n+static int\n+virtio_net_ctrl_pop(struct virtio_net *dev, struct vhost_virtqueue *cvq,\n+\t\tstruct virtio_net_ctrl_elem *ctrl_elem)\n+\t__rte_shared_locks_required(&cvq->iotlb_lock)\n+{\n+\tuint16_t avail_idx, desc_idx, n_descs = 0;\n+\tuint64_t desc_len, desc_addr, desc_iova, data_len = 0;\n+\tuint8_t *ctrl_req;\n+\tstruct vring_desc *descs;\n+\n+\tavail_idx = __atomic_load_n(&cvq->avail->idx, __ATOMIC_ACQUIRE);\n+\tif (avail_idx == cvq->last_avail_idx) {\n+\t\tVHOST_LOG_CONFIG(dev->ifname, DEBUG, \"Control queue empty\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tdesc_idx = cvq->avail->ring[cvq->last_avail_idx];\n+\tif (desc_idx >= cvq->size) {\n+\t\tVHOST_LOG_CONFIG(dev->ifname, ERR, \"Out of range desc index, dropping\\n\");\n+\t\tgoto err;\n+\t}\n+\n+\tctrl_elem->head_idx = desc_idx;\n+\n+\tif (cvq->desc[desc_idx].flags & VRING_DESC_F_INDIRECT) {\n+\t\tdesc_len = cvq->desc[desc_idx].len;\n+\t\tdesc_iova = cvq->desc[desc_idx].addr;\n+\n+\t\tdescs = (struct vring_desc *)(uintptr_t)vhost_iova_to_vva(dev, cvq,\n+\t\t\t\t\tdesc_iova, &desc_len, VHOST_ACCESS_RO);\n+\t\tif (!descs || desc_len != cvq->desc[desc_idx].len) {\n+\t\t\tVHOST_LOG_CONFIG(dev->ifname, ERR, \"Failed to map ctrl indirect descs\\n\");\n+\t\t\tgoto err;\n+\t\t}\n+\n+\t\tdesc_idx = 0;\n+\t} else {\n+\t\tdescs = cvq->desc;\n+\t}\n+\n+\twhile (1) {\n+\t\tdesc_len = descs[desc_idx].len;\n+\t\tdesc_iova = descs[desc_idx].addr;\n+\n+\t\tn_descs++;\n+\n+\t\tif (descs[desc_idx].flags & VRING_DESC_F_WRITE) {\n+\t\t\tif (ctrl_elem->desc_ack) {\n+\t\t\t\tVHOST_LOG_CONFIG(dev->ifname, ERR,\n+\t\t\t\t\t\t\"Unexpected ctrl chain layout\\n\");\n+\t\t\t\tgoto err;\n+\t\t\t}\n+\n+\t\t\tif (desc_len != sizeof(uint8_t)) {\n+\t\t\t\tVHOST_LOG_CONFIG(dev->ifname, ERR,\n+\t\t\t\t\t\t\"Invalid ack size for ctrl req, dropping\\n\");\n+\t\t\t\tgoto err;\n+\t\t\t}\n+\n+\t\t\tctrl_elem->desc_ack = (uint8_t *)(uintptr_t)vhost_iova_to_vva(dev, cvq,\n+\t\t\t\t\tdesc_iova, &desc_len, VHOST_ACCESS_WO);\n+\t\t\tif (!ctrl_elem->desc_ack || desc_len != sizeof(uint8_t)) {\n+\t\t\t\tVHOST_LOG_CONFIG(dev->ifname, ERR,\n+\t\t\t\t\t\t\"Failed to map ctrl ack descriptor\\n\");\n+\t\t\t\tgoto err;\n+\t\t\t}\n+\t\t} else {\n+\t\t\tif (ctrl_elem->desc_ack) {\n+\t\t\t\tVHOST_LOG_CONFIG(dev->ifname, ERR,\n+\t\t\t\t\t\t\"Unexpected ctrl chain layout\\n\");\n+\t\t\t\tgoto err;\n+\t\t\t}\n+\n+\t\t\tdata_len += desc_len;\n+\t\t}\n+\n+\t\tif (!(descs[desc_idx].flags & VRING_DESC_F_NEXT))\n+\t\t\tbreak;\n+\n+\t\tdesc_idx = descs[desc_idx].next;\n+\t}\n+\n+\tdesc_idx = ctrl_elem->head_idx;\n+\n+\tif (cvq->desc[desc_idx].flags & VRING_DESC_F_INDIRECT)\n+\t\tctrl_elem->n_descs = 1;\n+\telse\n+\t\tctrl_elem->n_descs = n_descs;\n+\n+\tif (!ctrl_elem->desc_ack) {\n+\t\tVHOST_LOG_CONFIG(dev->ifname, ERR, \"Missing ctrl ack descriptor\\n\");\n+\t\tgoto err;\n+\t}\n+\n+\tif (data_len < sizeof(ctrl_elem->ctrl_req->class) + sizeof(ctrl_elem->ctrl_req->command)) {\n+\t\tVHOST_LOG_CONFIG(dev->ifname, ERR, \"Invalid control header size\\n\");\n+\t\tgoto err;\n+\t}\n+\n+\tctrl_elem->ctrl_req = malloc(data_len);\n+\tif (!ctrl_elem->ctrl_req) {\n+\t\tVHOST_LOG_CONFIG(dev->ifname, ERR, \"Failed to alloc ctrl request\\n\");\n+\t\tgoto err;\n+\t}\n+\n+\tctrl_req = (uint8_t *)ctrl_elem->ctrl_req;\n+\n+\tif (cvq->desc[desc_idx].flags & VRING_DESC_F_INDIRECT) {\n+\t\tdesc_len = cvq->desc[desc_idx].len;\n+\t\tdesc_iova = cvq->desc[desc_idx].addr;\n+\n+\t\tdescs = (struct vring_desc *)(uintptr_t)vhost_iova_to_vva(dev, cvq,\n+\t\t\t\t\tdesc_iova, &desc_len, VHOST_ACCESS_RO);\n+\t\tif (!descs || desc_len != cvq->desc[desc_idx].len) {\n+\t\t\tVHOST_LOG_CONFIG(dev->ifname, ERR, \"Failed to map ctrl indirect descs\\n\");\n+\t\t\tgoto free_err;\n+\t\t}\n+\n+\t\tdesc_idx = 0;\n+\t} else {\n+\t\tdescs = cvq->desc;\n+\t}\n+\n+\twhile (!(descs[desc_idx].flags & VRING_DESC_F_WRITE)) {\n+\t\tdesc_len = descs[desc_idx].len;\n+\t\tdesc_iova = descs[desc_idx].addr;\n+\n+\t\tdesc_addr = vhost_iova_to_vva(dev, cvq, desc_iova, &desc_len, VHOST_ACCESS_RO);\n+\t\tif (!desc_addr || desc_len < descs[desc_idx].len) {\n+\t\t\tVHOST_LOG_CONFIG(dev->ifname, ERR, \"Failed to map ctrl descriptor\\n\");\n+\t\t\tgoto free_err;\n+\t\t}\n+\n+\t\tmemcpy(ctrl_req, (void *)(uintptr_t)desc_addr, desc_len);\n+\t\tctrl_req += desc_len;\n+\n+\t\tif (!(descs[desc_idx].flags & VRING_DESC_F_NEXT))\n+\t\t\tbreak;\n+\n+\t\tdesc_idx = descs[desc_idx].next;\n+\t}\n+\n+\tcvq->last_avail_idx++;\n+\tif (cvq->last_avail_idx >= cvq->size)\n+\t\tcvq->last_avail_idx -= cvq->size;\n+\n+\tif (dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX))\n+\t\tvhost_avail_event(cvq) = cvq->last_avail_idx;\n+\n+\treturn 1;\n+\n+free_err:\n+\tfree(ctrl_elem->ctrl_req);\n+err:\n+\tcvq->last_avail_idx++;\n+\tif (cvq->last_avail_idx >= cvq->size)\n+\t\tcvq->last_avail_idx -= cvq->size;\n+\n+\tif (dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX))\n+\t\tvhost_avail_event(cvq) = cvq->last_avail_idx;\n+\n+\treturn -1;\n+}\n+\n+static uint8_t\n+virtio_net_ctrl_handle_req(struct virtio_net *dev, struct virtio_net_ctrl *ctrl_req)\n+{\n+\tuint8_t ret = VIRTIO_NET_ERR;\n+\n+\tif (ctrl_req->class == VIRTIO_NET_CTRL_MQ &&\n+\t\t\tctrl_req->command == VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) {\n+\t\tuint16_t queue_pairs;\n+\t\tuint32_t i;\n+\n+\t\tqueue_pairs = *(uint16_t *)(uintptr_t)ctrl_req->command_data;\n+\t\tVHOST_LOG_CONFIG(dev->ifname, INFO, \"Ctrl req: MQ %u queue pairs\\n\", queue_pairs);\n+\t\tret = VIRTIO_NET_OK;\n+\n+\t\tfor (i = 0; i < dev->nr_vring; i++) {\n+\t\t\tstruct vhost_virtqueue *vq = dev->virtqueue[i];\n+\t\t\tbool enable;\n+\n+\t\t\tif (vq == dev->cvq)\n+\t\t\t\tcontinue;\n+\n+\t\t\tif (i < queue_pairs * 2)\n+\t\t\t\tenable = true;\n+\t\t\telse\n+\t\t\t\tenable = false;\n+\n+\t\t\tvq->enabled = enable;\n+\t\t\tif (dev->notify_ops->vring_state_changed)\n+\t\t\t\tdev->notify_ops->vring_state_changed(dev->vid, i, enable);\n+\t\t}\n+\t}\n+\n+\treturn ret;\n+}\n+\n+static int\n+virtio_net_ctrl_push(struct virtio_net *dev, struct virtio_net_ctrl_elem *ctrl_elem)\n+{\n+\tstruct vhost_virtqueue *cvq = dev->cvq;\n+\tstruct vring_used_elem *used_elem;\n+\n+\tused_elem = &cvq->used->ring[cvq->last_used_idx];\n+\tused_elem->id = ctrl_elem->head_idx;\n+\tused_elem->len = ctrl_elem->n_descs;\n+\n+\tcvq->last_used_idx++;\n+\tif (cvq->last_used_idx >= cvq->size)\n+\t\tcvq->last_used_idx -= cvq->size;\n+\n+\t__atomic_store_n(&cvq->used->idx, cvq->last_used_idx, __ATOMIC_RELEASE);\n+\n+\tvhost_vring_call_split(dev, dev->cvq);\n+\n+\tfree(ctrl_elem->ctrl_req);\n+\n+\treturn 0;\n+}\n+\n+int\n+virtio_net_ctrl_handle(struct virtio_net *dev)\n+{\n+\tint ret = 0;\n+\n+\tif (dev->features & (1ULL << VIRTIO_F_RING_PACKED)) {\n+\t\tVHOST_LOG_CONFIG(dev->ifname, ERR, \"Packed ring not supported yet\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\tif (!dev->cvq) {\n+\t\tVHOST_LOG_CONFIG(dev->ifname, ERR, \"missing control queue\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\trte_rwlock_read_lock(&dev->cvq->access_lock);\n+\tvhost_user_iotlb_rd_lock(dev->cvq);\n+\n+\twhile (1) {\n+\t\tstruct virtio_net_ctrl_elem ctrl_elem;\n+\n+\t\tmemset(&ctrl_elem, 0, sizeof(struct virtio_net_ctrl_elem));\n+\n+\t\tret = virtio_net_ctrl_pop(dev, dev->cvq, &ctrl_elem);\n+\t\tif (ret <= 0)\n+\t\t\tbreak;\n+\n+\t\t*ctrl_elem.desc_ack = virtio_net_ctrl_handle_req(dev, ctrl_elem.ctrl_req);\n+\n+\t\tret = virtio_net_ctrl_push(dev, &ctrl_elem);\n+\t\tif (ret < 0)\n+\t\t\tbreak;\n+\t}\n+\n+\tvhost_user_iotlb_rd_unlock(dev->cvq);\n+\trte_rwlock_read_unlock(&dev->cvq->access_lock);\n+\n+\treturn ret;\n+}\ndiff --git a/lib/vhost/virtio_net_ctrl.h b/lib/vhost/virtio_net_ctrl.h\nnew file mode 100644\nindex 0000000000..9a90f4b9da\n--- /dev/null\n+++ b/lib/vhost/virtio_net_ctrl.h\n@@ -0,0 +1,10 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright (c) 2023 Red Hat, Inc.\n+ */\n+\n+#ifndef _VIRTIO_NET_CTRL_H\n+#define _VIRTIO_NET_CTRL_H\n+\n+int virtio_net_ctrl_handle(struct virtio_net *dev);\n+\n+#endif\n",
    "prefixes": [
        "v5",
        "15/26"
    ]
}