get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 108934,
    "url": "https://patches.dpdk.org/api/patches/108934/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/20220328121758.26632-6-david.marchand@redhat.com/",
    "project": {
        "id": 1,
        "url": "https://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": "<20220328121758.26632-6-david.marchand@redhat.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20220328121758.26632-6-david.marchand@redhat.com",
    "date": "2022-03-28T12:17:58",
    "name": "[RFC,5/5] vhost: annotate IOTLB locks",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "113aefc0f93abb64a812a39a4f5e9adf9afdd32e",
    "submitter": {
        "id": 1173,
        "url": "https://patches.dpdk.org/api/people/1173/?format=api",
        "name": "David Marchand",
        "email": "david.marchand@redhat.com"
    },
    "delegate": {
        "id": 2642,
        "url": "https://patches.dpdk.org/api/users/2642/?format=api",
        "username": "mcoquelin",
        "first_name": "Maxime",
        "last_name": "Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/20220328121758.26632-6-david.marchand@redhat.com/mbox/",
    "series": [
        {
            "id": 22266,
            "url": "https://patches.dpdk.org/api/series/22266/?format=api",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=22266",
            "date": "2022-03-28T12:17:53",
            "name": "vhost lock annotations",
            "version": 1,
            "mbox": "https://patches.dpdk.org/series/22266/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/108934/comments/",
    "check": "success",
    "checks": "https://patches.dpdk.org/api/patches/108934/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 D5A92A0501;\n\tMon, 28 Mar 2022 14:19:01 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 8CC4742884;\n\tMon, 28 Mar 2022 14:19:00 +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 1CD18427F8\n for <dev@dpdk.org>; Mon, 28 Mar 2022 14:18:59 +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-223-uqq-3VaLOEaribxOpwR0UQ-1; Mon, 28 Mar 2022 08:18:55 -0400",
            "from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com\n [10.11.54.8])\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 2B782803D42;\n Mon, 28 Mar 2022 12:18:55 +0000 (UTC)",
            "from dmarchan.remote.csb (unknown [10.40.195.27])\n by smtp.corp.redhat.com (Postfix) with ESMTP id 28C72C07F50;\n Mon, 28 Mar 2022 12:18:54 +0000 (UTC)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1648469938;\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=GPgHRqfKB43mibrcRaSetlatDxGXfwcaAlNWGJJVbHA=;\n b=Lmwzz5/RUL2YW3kWqOOwsbOZizJqdougHM1v42CkmGfnsk4EQ3XIY5iHbZNdP0LlHC5qY+\n ZsC1avMPuVZJf3cMK4rWSvBELjSYfbMQslXBYNYBQFIV43eT/9rGr9N4CWvnnOGbcTD3Zg\n iViW5I/ewOts3ijNRywHEO4RPykI1OY=",
        "X-MC-Unique": "uqq-3VaLOEaribxOpwR0UQ-1",
        "From": "David Marchand <david.marchand@redhat.com>",
        "To": "dev@dpdk.org",
        "Cc": "maxime.coquelin@redhat.com,\n\tchenbo.xia@intel.com",
        "Subject": "[RFC PATCH 5/5] vhost: annotate IOTLB locks",
        "Date": "Mon, 28 Mar 2022 14:17:58 +0200",
        "Message-Id": "<20220328121758.26632-6-david.marchand@redhat.com>",
        "In-Reply-To": "<20220328121758.26632-1-david.marchand@redhat.com>",
        "References": "<20220328121758.26632-1-david.marchand@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 2.85 on 10.11.54.8",
        "Authentication-Results": "relay.mimecast.com;\n auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david.marchand@redhat.com",
        "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": "The IOTLB code uses r/w locks.\n\nIntroduce a wrapper around this type of locks and annotate iotlb_lock\nand iotlb_pending_lock.\n\nclang does not support conditionally held locks, so always take iotlb\nlocks regardless of VIRTIO_F_IOMMU_PLATFORM feature.\n\nvdpa and vhost_crypto code are annotated though they end up not taking\na IOTLB lock and have been marked with a FIXME.\n\nSigned-off-by: David Marchand <david.marchand@redhat.com>\n---\n lib/vhost/iotlb.c        | 36 +++++++--------\n lib/vhost/iotlb.h        | 24 ----------\n lib/vhost/vdpa.c         |  1 +\n lib/vhost/vhost.c        | 16 +++----\n lib/vhost/vhost.h        | 94 +++++++++++++++++++++++++++++++++++-----\n lib/vhost/vhost_crypto.c |  7 +++\n lib/vhost/vhost_user.c   | 16 +++++--\n lib/vhost/virtio_net.c   | 49 ++++++++++++++++-----\n 8 files changed, 164 insertions(+), 79 deletions(-)",
    "diff": "diff --git a/lib/vhost/iotlb.c b/lib/vhost/iotlb.c\nindex 5a5ba8b82a..e5367d3af9 100644\n--- a/lib/vhost/iotlb.c\n+++ b/lib/vhost/iotlb.c\n@@ -30,14 +30,14 @@ vhost_user_iotlb_pending_remove_all(struct vhost_virtqueue *vq)\n {\n \tstruct vhost_iotlb_entry *node, *temp_node;\n \n-\trte_rwlock_write_lock(&vq->iotlb_pending_lock);\n+\tvhost_rwlock_write_lock(&vq->iotlb_pending_lock);\n \n \tRTE_TAILQ_FOREACH_SAFE(node, &vq->iotlb_pending_list, next, temp_node) {\n \t\tTAILQ_REMOVE(&vq->iotlb_pending_list, node, next);\n \t\trte_mempool_put(vq->iotlb_pool, node);\n \t}\n \n-\trte_rwlock_write_unlock(&vq->iotlb_pending_lock);\n+\tvhost_rwlock_write_unlock(&vq->iotlb_pending_lock);\n }\n \n bool\n@@ -47,7 +47,7 @@ vhost_user_iotlb_pending_miss(struct vhost_virtqueue *vq, uint64_t iova,\n \tstruct vhost_iotlb_entry *node;\n \tbool found = false;\n \n-\trte_rwlock_read_lock(&vq->iotlb_pending_lock);\n+\tvhost_rwlock_read_lock(&vq->iotlb_pending_lock);\n \n \tTAILQ_FOREACH(node, &vq->iotlb_pending_list, next) {\n \t\tif ((node->iova == iova) && (node->perm == perm)) {\n@@ -56,7 +56,7 @@ vhost_user_iotlb_pending_miss(struct vhost_virtqueue *vq, uint64_t iova,\n \t\t}\n \t}\n \n-\trte_rwlock_read_unlock(&vq->iotlb_pending_lock);\n+\tvhost_rwlock_read_unlock(&vq->iotlb_pending_lock);\n \n \treturn found;\n }\n@@ -89,11 +89,11 @@ vhost_user_iotlb_pending_insert(struct virtio_net *dev, struct vhost_virtqueue *\n \tnode->iova = iova;\n \tnode->perm = perm;\n \n-\trte_rwlock_write_lock(&vq->iotlb_pending_lock);\n+\tvhost_rwlock_write_lock(&vq->iotlb_pending_lock);\n \n \tTAILQ_INSERT_TAIL(&vq->iotlb_pending_list, node, next);\n \n-\trte_rwlock_write_unlock(&vq->iotlb_pending_lock);\n+\tvhost_rwlock_write_unlock(&vq->iotlb_pending_lock);\n }\n \n void\n@@ -102,7 +102,7 @@ vhost_user_iotlb_pending_remove(struct vhost_virtqueue *vq,\n {\n \tstruct vhost_iotlb_entry *node, *temp_node;\n \n-\trte_rwlock_write_lock(&vq->iotlb_pending_lock);\n+\tvhost_rwlock_write_lock(&vq->iotlb_pending_lock);\n \n \tRTE_TAILQ_FOREACH_SAFE(node, &vq->iotlb_pending_list, next,\n \t\t\t\ttemp_node) {\n@@ -116,7 +116,7 @@ vhost_user_iotlb_pending_remove(struct vhost_virtqueue *vq,\n \t\trte_mempool_put(vq->iotlb_pool, node);\n \t}\n \n-\trte_rwlock_write_unlock(&vq->iotlb_pending_lock);\n+\tvhost_rwlock_write_unlock(&vq->iotlb_pending_lock);\n }\n \n static void\n@@ -124,7 +124,7 @@ vhost_user_iotlb_cache_remove_all(struct vhost_virtqueue *vq)\n {\n \tstruct vhost_iotlb_entry *node, *temp_node;\n \n-\trte_rwlock_write_lock(&vq->iotlb_lock);\n+\tvhost_rwlock_write_lock(&vq->iotlb_lock);\n \n \tRTE_TAILQ_FOREACH_SAFE(node, &vq->iotlb_list, next, temp_node) {\n \t\tTAILQ_REMOVE(&vq->iotlb_list, node, next);\n@@ -133,7 +133,7 @@ vhost_user_iotlb_cache_remove_all(struct vhost_virtqueue *vq)\n \n \tvq->iotlb_cache_nr = 0;\n \n-\trte_rwlock_write_unlock(&vq->iotlb_lock);\n+\tvhost_rwlock_write_unlock(&vq->iotlb_lock);\n }\n \n static void\n@@ -142,7 +142,7 @@ vhost_user_iotlb_cache_random_evict(struct vhost_virtqueue *vq)\n \tstruct vhost_iotlb_entry *node, *temp_node;\n \tint entry_idx;\n \n-\trte_rwlock_write_lock(&vq->iotlb_lock);\n+\tvhost_rwlock_write_lock(&vq->iotlb_lock);\n \n \tentry_idx = rte_rand() % vq->iotlb_cache_nr;\n \n@@ -156,7 +156,7 @@ vhost_user_iotlb_cache_random_evict(struct vhost_virtqueue *vq)\n \t\tentry_idx--;\n \t}\n \n-\trte_rwlock_write_unlock(&vq->iotlb_lock);\n+\tvhost_rwlock_write_unlock(&vq->iotlb_lock);\n }\n \n void\n@@ -190,7 +190,7 @@ vhost_user_iotlb_cache_insert(struct virtio_net *dev, struct vhost_virtqueue *vq\n \tnew_node->size = size;\n \tnew_node->perm = perm;\n \n-\trte_rwlock_write_lock(&vq->iotlb_lock);\n+\tvhost_rwlock_write_lock(&vq->iotlb_lock);\n \n \tTAILQ_FOREACH(node, &vq->iotlb_list, next) {\n \t\t/*\n@@ -213,7 +213,7 @@ vhost_user_iotlb_cache_insert(struct virtio_net *dev, struct vhost_virtqueue *vq\n unlock:\n \tvhost_user_iotlb_pending_remove(vq, iova, size, perm);\n \n-\trte_rwlock_write_unlock(&vq->iotlb_lock);\n+\tvhost_rwlock_write_unlock(&vq->iotlb_lock);\n \n }\n \n@@ -226,7 +226,7 @@ vhost_user_iotlb_cache_remove(struct vhost_virtqueue *vq,\n \tif (unlikely(!size))\n \t\treturn;\n \n-\trte_rwlock_write_lock(&vq->iotlb_lock);\n+\tvhost_rwlock_write_lock(&vq->iotlb_lock);\n \n \tRTE_TAILQ_FOREACH_SAFE(node, &vq->iotlb_list, next, temp_node) {\n \t\t/* Sorted list */\n@@ -240,7 +240,7 @@ vhost_user_iotlb_cache_remove(struct vhost_virtqueue *vq,\n \t\t}\n \t}\n \n-\trte_rwlock_write_unlock(&vq->iotlb_lock);\n+\tvhost_rwlock_write_unlock(&vq->iotlb_lock);\n }\n \n uint64_t\n@@ -312,8 +312,8 @@ vhost_user_iotlb_init(struct virtio_net *dev, int vq_index)\n \t\tsocket = 0;\n #endif\n \n-\trte_rwlock_init(&vq->iotlb_lock);\n-\trte_rwlock_init(&vq->iotlb_pending_lock);\n+\tvhost_rwlock_init(&vq->iotlb_lock);\n+\tvhost_rwlock_init(&vq->iotlb_pending_lock);\n \n \tTAILQ_INIT(&vq->iotlb_list);\n \tTAILQ_INIT(&vq->iotlb_pending_list);\ndiff --git a/lib/vhost/iotlb.h b/lib/vhost/iotlb.h\nindex 8d0ff7473b..96ec4d608f 100644\n--- a/lib/vhost/iotlb.h\n+++ b/lib/vhost/iotlb.h\n@@ -9,30 +9,6 @@\n \n #include \"vhost.h\"\n \n-static __rte_always_inline void\n-vhost_user_iotlb_rd_lock(struct vhost_virtqueue *vq)\n-{\n-\trte_rwlock_read_lock(&vq->iotlb_lock);\n-}\n-\n-static __rte_always_inline void\n-vhost_user_iotlb_rd_unlock(struct vhost_virtqueue *vq)\n-{\n-\trte_rwlock_read_unlock(&vq->iotlb_lock);\n-}\n-\n-static __rte_always_inline void\n-vhost_user_iotlb_wr_lock(struct vhost_virtqueue *vq)\n-{\n-\trte_rwlock_write_lock(&vq->iotlb_lock);\n-}\n-\n-static __rte_always_inline void\n-vhost_user_iotlb_wr_unlock(struct vhost_virtqueue *vq)\n-{\n-\trte_rwlock_write_unlock(&vq->iotlb_lock);\n-}\n-\n void vhost_user_iotlb_cache_insert(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \t\t\t\t\tuint64_t iova, uint64_t uaddr,\n \t\t\t\t\tuint64_t size, uint8_t perm);\ndiff --git a/lib/vhost/vdpa.c b/lib/vhost/vdpa.c\nindex 8fa2153023..406f13288b 100644\n--- a/lib/vhost/vdpa.c\n+++ b/lib/vhost/vdpa.c\n@@ -130,6 +130,7 @@ rte_vdpa_unregister_device(struct rte_vdpa_device *dev)\n \n int\n rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m)\n+\tVHOST_NO_THREAD_SAFETY_ANALYSIS /* FIXME: requires iotlb_lock? */\n {\n \tstruct virtio_net *dev = get_device(vid);\n \tuint16_t idx, idx_m, desc_id;\ndiff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c\nindex ea28323367..466a24dabe 100644\n--- a/lib/vhost/vhost.c\n+++ b/lib/vhost/vhost.c\n@@ -50,7 +50,7 @@ __vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \t\t * which could cause a deadlock with QEMU if an IOTLB update\n \t\t * is being handled. We can safely unlock here to avoid it.\n \t\t */\n-\t\tvhost_user_iotlb_rd_unlock(vq);\n+\t\tvhost_rwlock_read_unlock(&vq->iotlb_lock);\n \n \t\tvhost_user_iotlb_pending_insert(dev, vq, iova, perm);\n \t\tif (vhost_user_iotlb_miss(dev, iova, perm)) {\n@@ -59,7 +59,7 @@ __vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \t\t\tvhost_user_iotlb_pending_remove(vq, iova, 1, perm);\n \t\t}\n \n-\t\tvhost_user_iotlb_rd_lock(vq);\n+\t\tvhost_rwlock_read_lock(&vq->iotlb_lock);\n \t}\n \n \treturn 0;\n@@ -383,6 +383,7 @@ free_device(struct virtio_net *dev)\n \n static __rte_always_inline int\n log_translate(struct virtio_net *dev, struct vhost_virtqueue *vq)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tif (likely(!(vq->ring_addrs.flags & (1 << VHOST_VRING_F_LOG))))\n \t\treturn 0;\n@@ -434,6 +435,7 @@ translate_log_addr(struct virtio_net *dev, struct vhost_virtqueue *vq,\n /* Caller should have iotlb_lock read-locked */\n static int\n vring_translate_split(struct virtio_net *dev, struct vhost_virtqueue *vq)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tuint64_t req_size, size;\n \n@@ -473,6 +475,7 @@ vring_translate_split(struct virtio_net *dev, struct vhost_virtqueue *vq)\n /* Caller should have iotlb_lock read-locked */\n static int\n vring_translate_packed(struct virtio_net *dev, struct vhost_virtqueue *vq)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tuint64_t req_size, size;\n \n@@ -506,7 +509,6 @@ vring_translate_packed(struct virtio_net *dev, struct vhost_virtqueue *vq)\n int\n vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq)\n {\n-\n \tif (!(dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)))\n \t\treturn -1;\n \n@@ -527,19 +529,13 @@ vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq)\n }\n \n void\n-vring_invalidate(struct virtio_net *dev, struct vhost_virtqueue *vq)\n+vring_invalidate(struct virtio_net *dev __rte_unused, struct vhost_virtqueue *vq)\n {\n-\tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))\n-\t\tvhost_user_iotlb_wr_lock(vq);\n-\n \tvq->access_ok = false;\n \tvq->desc = NULL;\n \tvq->avail = NULL;\n \tvq->used = NULL;\n \tvq->log_guest_addr = 0;\n-\n-\tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))\n-\t\tvhost_user_iotlb_wr_unlock(vq);\n }\n \n static void\ndiff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h\nindex 4b301ec152..08ace9994a 100644\n--- a/lib/vhost/vhost.h\n+++ b/lib/vhost/vhost.h\n@@ -108,6 +108,19 @@\n #define VHOST_SPINLOCK_RELEASES(...) \\\n \t__attribute__((unlock_function(__VA_ARGS__)))\n \n+#define VHOST_RDLOCK_REQUIRES(...) \\\n+\t__attribute__((shared_locks_required(__VA_ARGS__)))\n+#define VHOST_RDLOCK_ACQUIRES(...) \\\n+\t__attribute__((shared_lock_function(__VA_ARGS__)))\n+#define VHOST_RDLOCK_RELEASES(...) \\\n+\t__attribute__((unlock_function(__VA_ARGS__)))\n+#define VHOST_WRLOCK_REQUIRES(...) \\\n+\t__attribute__((exclusive_locks_required(__VA_ARGS__)))\n+#define VHOST_WRLOCK_ACQUIRES(...) \\\n+\t__attribute__((exclusive_lock_function(__VA_ARGS__)))\n+#define VHOST_WRLOCK_RELEASES(...) \\\n+\t__attribute__((unlock_function(__VA_ARGS__)))\n+\n #else\n #define VHOST_NO_THREAD_SAFETY_ANALYSIS\n #define VHOST_LOCKABLE\n@@ -117,6 +130,13 @@\n #define VHOST_SPINLOCK_ACQUIRES(...)\n #define VHOST_SPINLOCK_TRYLOCK(...)\n #define VHOST_SPINLOCK_RELEASES(...)\n+\n+#define VHOST_RDLOCK_ACQUIRES(...)\n+#define VHOST_RDLOCK_REQUIRES(...)\n+#define VHOST_RDLOCK_RELEASES(...)\n+#define VHOST_WRLOCK_REQUIRES(...)\n+#define VHOST_WRLOCK_ACQUIRES(...)\n+#define VHOST_WRLOCK_RELEASES(...)\n #endif\n \n typedef struct VHOST_LOCKABLE {\n@@ -153,6 +173,48 @@ vhost_spinlock_unlock(vhost_spinlock_t *l)\n \trte_spinlock_unlock(&l->l);\n }\n \n+typedef struct VHOST_LOCKABLE {\n+\trte_rwlock_t l;\n+} vhost_rwlock_t;\n+\n+static __rte_always_inline void\n+vhost_rwlock_init(vhost_rwlock_t *l)\n+{\n+\trte_rwlock_init(&l->l);\n+}\n+\n+static __rte_always_inline void\n+vhost_rwlock_read_lock(vhost_rwlock_t *l)\n+\tVHOST_RDLOCK_ACQUIRES(l)\n+\tVHOST_NO_THREAD_SAFETY_ANALYSIS\n+{\n+\trte_rwlock_read_lock(&l->l);\n+}\n+\n+static __rte_always_inline void\n+vhost_rwlock_read_unlock(vhost_rwlock_t *l)\n+\tVHOST_RDLOCK_RELEASES(l)\n+\tVHOST_NO_THREAD_SAFETY_ANALYSIS\n+{\n+\trte_rwlock_read_unlock(&l->l);\n+}\n+\n+static __rte_always_inline void\n+vhost_rwlock_write_lock(vhost_rwlock_t *l)\n+\tVHOST_WRLOCK_ACQUIRES(l)\n+\tVHOST_NO_THREAD_SAFETY_ANALYSIS\n+{\n+\trte_rwlock_write_lock(&l->l);\n+}\n+\n+static __rte_always_inline void\n+vhost_rwlock_write_unlock(vhost_rwlock_t *l)\n+\tVHOST_WRLOCK_RELEASES(l)\n+\tVHOST_NO_THREAD_SAFETY_ANALYSIS\n+{\n+\trte_rwlock_write_unlock(&l->l);\n+}\n+\n /**\n  * Structure contains buffer address, length and descriptor index\n  * from vring to do scatter RX.\n@@ -346,8 +408,8 @@ struct vhost_virtqueue {\n \tuint64_t\t\tlog_guest_addr;\n \tstruct log_cache_entry\t*log_cache;\n \n-\trte_rwlock_t\tiotlb_lock;\n-\trte_rwlock_t\tiotlb_pending_lock;\n+\tvhost_rwlock_t\tiotlb_lock;\n+\tvhost_rwlock_t\tiotlb_pending_lock;\n \tstruct rte_mempool *iotlb_pool;\n \tTAILQ_HEAD(, vhost_iotlb_entry) iotlb_list;\n \tTAILQ_HEAD(, vhost_iotlb_entry) iotlb_pending_list;\n@@ -592,12 +654,15 @@ void __vhost_log_cache_write(struct virtio_net *dev,\n \t\tuint64_t addr, uint64_t len);\n void __vhost_log_cache_write_iova(struct virtio_net *dev,\n \t\tstruct vhost_virtqueue *vq,\n-\t\tuint64_t iova, uint64_t len);\n+\t\tuint64_t iova, uint64_t len)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock);\n void __vhost_log_cache_sync(struct virtio_net *dev,\n \t\tstruct vhost_virtqueue *vq);\n+\n void __vhost_log_write(struct virtio_net *dev, uint64_t addr, uint64_t len);\n void __vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,\n-\t\t\t    uint64_t iova, uint64_t len);\n+\t\tuint64_t iova, uint64_t len)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock);\n \n static __rte_always_inline void\n vhost_log_write(struct virtio_net *dev, uint64_t addr, uint64_t len)\n@@ -647,6 +712,7 @@ vhost_log_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,\n static __rte_always_inline void\n vhost_log_cache_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \t\t\t   uint64_t iova, uint64_t len)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tif (likely(!(dev->features & (1ULL << VHOST_F_LOG_ALL))))\n \t\treturn;\n@@ -660,6 +726,7 @@ vhost_log_cache_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,\n static __rte_always_inline void\n vhost_log_write_iova(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \t\t\t   uint64_t iova, uint64_t len)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tif (likely(!(dev->features & (1ULL << VHOST_F_LOG_ALL))))\n \t\treturn;\n@@ -863,18 +930,23 @@ struct rte_vhost_device_ops const *vhost_driver_callback_get(const char *path);\n void vhost_backend_cleanup(struct virtio_net *dev);\n \n uint64_t __vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,\n-\t\t\tuint64_t iova, uint64_t *len, uint8_t perm);\n-void *vhost_alloc_copy_ind_table(struct virtio_net *dev,\n-\t\t\tstruct vhost_virtqueue *vq,\n-\t\t\tuint64_t desc_addr, uint64_t desc_len);\n-int vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq);\n+\t\tuint64_t iova, uint64_t *len, uint8_t perm)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock);\n+void *vhost_alloc_copy_ind_table(struct virtio_net *dev, struct vhost_virtqueue *vq,\n+\t\tuint64_t desc_addr, uint64_t desc_len)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock);\n+int vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock);\n uint64_t translate_log_addr(struct virtio_net *dev, struct vhost_virtqueue *vq,\n-\t\tuint64_t log_addr);\n-void vring_invalidate(struct virtio_net *dev, struct vhost_virtqueue *vq);\n+\t\tuint64_t log_addr)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock);\n+void vring_invalidate(struct virtio_net *dev, struct vhost_virtqueue *vq)\n+\tVHOST_WRLOCK_REQUIRES(vq->iotlb_lock);\n \n static __rte_always_inline uint64_t\n vhost_iova_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \t\t\tuint64_t iova, uint64_t *len, uint8_t perm)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tif (!(dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)))\n \t\treturn rte_vhost_va_from_guest_pa(dev->mem, iova, len);\ndiff --git a/lib/vhost/vhost_crypto.c b/lib/vhost/vhost_crypto.c\nindex b1c0eb6a0f..2d0a1250fb 100644\n--- a/lib/vhost/vhost_crypto.c\n+++ b/lib/vhost/vhost_crypto.c\n@@ -506,6 +506,7 @@ static __rte_always_inline struct virtio_crypto_inhdr *\n reach_inhdr(struct vhost_crypto_data_req *vc_req,\n \t\tstruct vhost_crypto_desc *head,\n \t\tuint32_t max_n_descs)\n+\tVHOST_RDLOCK_REQUIRES(vc_req->vq->iotlb_lock)\n {\n \tstruct virtio_crypto_inhdr *inhdr;\n \tstruct vhost_crypto_desc *last = head + (max_n_descs - 1);\n@@ -552,6 +553,7 @@ static __rte_always_inline void *\n get_data_ptr(struct vhost_crypto_data_req *vc_req,\n \t\tstruct vhost_crypto_desc *cur_desc,\n \t\tuint8_t perm)\n+\tVHOST_RDLOCK_REQUIRES(vc_req->vq->iotlb_lock)\n {\n \tvoid *data;\n \tuint64_t dlen = cur_desc->len;\n@@ -570,6 +572,7 @@ copy_data(void *dst_data, struct vhost_crypto_data_req *vc_req,\n \t\tstruct vhost_crypto_desc *head,\n \t\tstruct vhost_crypto_desc **cur_desc,\n \t\tuint32_t size, uint32_t max_n_descs)\n+\tVHOST_RDLOCK_REQUIRES(vc_req->vq->iotlb_lock)\n {\n \tstruct vhost_crypto_desc *desc = *cur_desc;\n \tuint64_t remain, addr, dlen, len;\n@@ -718,6 +721,7 @@ prepare_write_back_data(struct vhost_crypto_data_req *vc_req,\n \t\tuint32_t offset,\n \t\tuint64_t write_back_len,\n \t\tuint32_t max_n_descs)\n+\tVHOST_RDLOCK_REQUIRES(vc_req->vq->iotlb_lock)\n {\n \tstruct vhost_crypto_writeback_data *wb_data, *head;\n \tstruct vhost_crypto_desc *desc = *cur_desc;\n@@ -838,6 +842,7 @@ prepare_sym_cipher_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op,\n \t\tstruct virtio_crypto_cipher_data_req *cipher,\n \t\tstruct vhost_crypto_desc *head,\n \t\tuint32_t max_n_descs)\n+\tVHOST_RDLOCK_REQUIRES(vc_req->vq->iotlb_lock)\n {\n \tstruct vhost_crypto_desc *desc = head;\n \tstruct vhost_crypto_writeback_data *ewb = NULL;\n@@ -990,6 +995,7 @@ prepare_sym_chain_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op,\n \t\tstruct virtio_crypto_alg_chain_data_req *chain,\n \t\tstruct vhost_crypto_desc *head,\n \t\tuint32_t max_n_descs)\n+\tVHOST_RDLOCK_REQUIRES(vc_req->vq->iotlb_lock)\n {\n \tstruct vhost_crypto_desc *desc = head, *digest_desc;\n \tstruct vhost_crypto_writeback_data *ewb = NULL, *ewb2 = NULL;\n@@ -1172,6 +1178,7 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto,\n \t\tstruct vhost_virtqueue *vq, struct rte_crypto_op *op,\n \t\tstruct vring_desc *head, struct vhost_crypto_desc *descs,\n \t\tuint16_t desc_idx)\n+\tVHOST_NO_THREAD_SAFETY_ANALYSIS /* FIXME: requires iotlb_lock? */\n {\n \tstruct vhost_crypto_data_req *vc_req = rte_mbuf_to_priv(op->sym->m_src);\n \tstruct rte_cryptodev_sym_session *session;\ndiff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c\nindex 35f1e23995..0482c00801 100644\n--- a/lib/vhost/vhost_user.c\n+++ b/lib/vhost/vhost_user.c\n@@ -754,10 +754,10 @@ ring_addr_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)) {\n \t\tuint64_t vva;\n \n-\t\tvhost_user_iotlb_rd_lock(vq);\n+\t\tvhost_rwlock_read_lock(&vq->iotlb_lock);\n \t\tvva = vhost_iova_to_vva(dev, vq, ra,\n \t\t\t\t\tsize, VHOST_ACCESS_RW);\n-\t\tvhost_user_iotlb_rd_unlock(vq);\n+\t\tvhost_rwlock_read_unlock(&vq->iotlb_lock);\n \n \t\treturn vva;\n \t}\n@@ -770,9 +770,9 @@ log_addr_to_gpa(struct virtio_net *dev, struct vhost_virtqueue *vq)\n {\n \tuint64_t log_gpa;\n \n-\tvhost_user_iotlb_rd_lock(vq);\n+\tvhost_rwlock_read_lock(&vq->iotlb_lock);\n \tlog_gpa = translate_log_addr(dev, vq, vq->ring_addrs.log_guest_addr);\n-\tvhost_user_iotlb_rd_unlock(vq);\n+\tvhost_rwlock_read_unlock(&vq->iotlb_lock);\n \n \treturn log_gpa;\n }\n@@ -927,7 +927,9 @@ vhost_user_set_vring_addr(struct virtio_net **pdev,\n \t */\n \tmemcpy(&vq->ring_addrs, addr, sizeof(*addr));\n \n+\tvhost_rwlock_write_lock(&vq->iotlb_lock);\n \tvring_invalidate(dev, vq);\n+\tvhost_rwlock_write_unlock(&vq->iotlb_lock);\n \n \tif ((vq->enabled && (dev->features &\n \t\t\t\t(1ULL << VHOST_USER_F_PROTOCOL_FEATURES))) ||\n@@ -1437,7 +1439,9 @@ vhost_user_set_mem_table(struct virtio_net **pdev,\n \t\t\t * need to be translated again as virtual addresses have\n \t\t\t * changed.\n \t\t\t */\n+\t\t\tvhost_rwlock_write_lock(&vq->iotlb_lock);\n \t\t\tvring_invalidate(dev, vq);\n+\t\t\tvhost_rwlock_write_unlock(&vq->iotlb_lock);\n \n \t\t\tdev = translate_ring_addresses(dev, i);\n \t\t\tif (!dev) {\n@@ -2186,7 +2190,9 @@ vhost_user_get_vring_base(struct virtio_net **pdev,\n \n \tvhost_user_iotlb_flush_all(vq);\n \n+\tvhost_rwlock_write_lock(&vq->iotlb_lock);\n \tvring_invalidate(dev, vq);\n+\tvhost_rwlock_write_unlock(&vq->iotlb_lock);\n \n \treturn RTE_VHOST_MSG_RESULT_REPLY;\n }\n@@ -2591,7 +2597,9 @@ vhost_user_iotlb_msg(struct virtio_net **pdev,\n \n \t\t\tif (is_vring_iotlb(dev, vq, imsg)) {\n \t\t\t\tvhost_spinlock_lock(&vq->access_lock);\n+\t\t\t\tvhost_rwlock_write_lock(&vq->iotlb_lock);\n \t\t\t\tvring_invalidate(dev, vq);\n+\t\t\t\tvhost_rwlock_write_unlock(&vq->iotlb_lock);\n \t\t\t\tvhost_spinlock_unlock(&vq->access_lock);\n \t\t\t}\n \t\t}\ndiff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c\nindex 9bdba992dd..ec342e772d 100644\n--- a/lib/vhost/virtio_net.c\n+++ b/lib/vhost/virtio_net.c\n@@ -180,6 +180,7 @@ vhost_async_dma_check_completed(struct virtio_net *dev, int16_t dma_id, uint16_t\n \n static inline void\n do_data_copy_enqueue(struct virtio_net *dev, struct vhost_virtqueue *vq)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tstruct batch_copy_elem *elem = vq->batch_copy_elems;\n \tuint16_t count = vq->batch_copy_nb_elems;\n@@ -526,6 +527,7 @@ vhost_shadow_enqueue_single_packed(struct virtio_net *dev,\n \t\t\t\t   uint16_t *id,\n \t\t\t\t   uint16_t *count,\n \t\t\t\t   uint16_t num_buffers)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tvhost_shadow_enqueue_packed(vq, len, id, count, num_buffers);\n \n@@ -607,6 +609,7 @@ static __rte_always_inline int\n map_one_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \t\tstruct buf_vector *buf_vec, uint16_t *vec_idx,\n \t\tuint64_t desc_iova, uint64_t desc_len, uint8_t perm)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tuint16_t vec_id = *vec_idx;\n \n@@ -644,6 +647,7 @@ fill_vec_buf_split(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \t\t\t uint32_t avail_idx, uint16_t *vec_idx,\n \t\t\t struct buf_vector *buf_vec, uint16_t *desc_chain_head,\n \t\t\t uint32_t *desc_chain_len, uint8_t perm)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tuint16_t idx = vq->avail->ring[avail_idx & (vq->size - 1)];\n \tuint16_t vec_id = *vec_idx;\n@@ -727,6 +731,7 @@ reserve_avail_buf_split(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \t\t\t\tuint32_t size, struct buf_vector *buf_vec,\n \t\t\t\tuint16_t *num_buffers, uint16_t avail_head,\n \t\t\t\tuint16_t *nr_vec)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tuint16_t cur_idx;\n \tuint16_t vec_idx = 0;\n@@ -777,6 +782,7 @@ fill_vec_buf_packed_indirect(struct virtio_net *dev,\n \t\t\tstruct vhost_virtqueue *vq,\n \t\t\tstruct vring_packed_desc *desc, uint16_t *vec_idx,\n \t\t\tstruct buf_vector *buf_vec, uint32_t *len, uint8_t perm)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tuint16_t i;\n \tuint32_t nr_descs;\n@@ -835,6 +841,7 @@ fill_vec_buf_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \t\t\t\tuint16_t avail_idx, uint16_t *desc_count,\n \t\t\t\tstruct buf_vector *buf_vec, uint16_t *vec_idx,\n \t\t\t\tuint16_t *buf_id, uint32_t *len, uint8_t perm)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tbool wrap_counter = vq->avail_wrap_counter;\n \tstruct vring_packed_desc *descs = vq->desc_packed;\n@@ -900,6 +907,7 @@ static __rte_noinline void\n copy_vnet_hdr_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \t\tstruct buf_vector *buf_vec,\n \t\tstruct virtio_net_hdr_mrg_rxbuf *hdr)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tuint64_t len;\n \tuint64_t remain = dev->vhost_hlen;\n@@ -1036,6 +1044,7 @@ static __rte_always_inline void\n sync_mbuf_to_desc_seg(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \t\tstruct rte_mbuf *m, uint32_t mbuf_offset,\n \t\tuint64_t buf_addr, uint64_t buf_iova, uint32_t cpy_len)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tstruct batch_copy_elem *batch_copy = vq->batch_copy_elems;\n \n@@ -1061,6 +1070,7 @@ mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \t\tstruct rte_mbuf *m, struct buf_vector *buf_vec,\n \t\tuint16_t nr_vec, uint16_t num_buffers, bool is_async)\n \tVHOST_SPINLOCK_REQUIRES(vq->access_lock)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tuint32_t vec_idx = 0;\n \tuint32_t mbuf_offset, mbuf_avail;\n@@ -1191,6 +1201,7 @@ vhost_enqueue_single_packed(struct virtio_net *dev,\n \t\t\t    struct buf_vector *buf_vec,\n \t\t\t    uint16_t *nr_descs)\n \tVHOST_SPINLOCK_REQUIRES(vq->access_lock)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tuint16_t nr_vec = 0;\n \tuint16_t avail_idx = vq->last_avail_idx;\n@@ -1252,6 +1263,7 @@ static __rte_noinline uint32_t\n virtio_dev_rx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \tstruct rte_mbuf **pkts, uint32_t count)\n \tVHOST_SPINLOCK_REQUIRES(vq->access_lock)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tuint32_t pkt_idx = 0;\n \tuint16_t num_buffers;\n@@ -1309,6 +1321,7 @@ virtio_dev_rx_sync_batch_check(struct virtio_net *dev,\n \t\t\t   struct rte_mbuf **pkts,\n \t\t\t   uint64_t *desc_addrs,\n \t\t\t   uint64_t *lens)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tbool wrap_counter = vq->avail_wrap_counter;\n \tstruct vring_packed_desc *descs = vq->desc_packed;\n@@ -1360,6 +1373,7 @@ virtio_dev_rx_batch_packed_copy(struct virtio_net *dev,\n \t\t\t   struct rte_mbuf **pkts,\n \t\t\t   uint64_t *desc_addrs,\n \t\t\t   uint64_t *lens)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tuint32_t buf_offset = sizeof(struct virtio_net_hdr_mrg_rxbuf);\n \tstruct virtio_net_hdr_mrg_rxbuf *hdrs[PACKED_BATCH_SIZE];\n@@ -1401,6 +1415,7 @@ static __rte_always_inline int\n virtio_dev_rx_sync_batch_packed(struct virtio_net *dev,\n \t\t\t   struct vhost_virtqueue *vq,\n \t\t\t   struct rte_mbuf **pkts)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tuint64_t desc_addrs[PACKED_BATCH_SIZE];\n \tuint64_t lens[PACKED_BATCH_SIZE];\n@@ -1423,6 +1438,7 @@ virtio_dev_rx_single_packed(struct virtio_net *dev,\n \t\t\t    struct vhost_virtqueue *vq,\n \t\t\t    struct rte_mbuf *pkt)\n \tVHOST_SPINLOCK_REQUIRES(vq->access_lock)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tstruct buf_vector buf_vec[BUF_VECTOR_MAX];\n \tuint16_t nr_descs = 0;\n@@ -1449,6 +1465,7 @@ virtio_dev_rx_packed(struct virtio_net *dev,\n \t\t     struct rte_mbuf **__rte_restrict pkts,\n \t\t     uint32_t count)\n \tVHOST_SPINLOCK_REQUIRES(vq->access_lock)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tuint32_t pkt_idx = 0;\n \n@@ -1501,8 +1518,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,\n \tif (unlikely(!vq->enabled))\n \t\tgoto out_access_unlock;\n \n-\tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))\n-\t\tvhost_user_iotlb_rd_lock(vq);\n+\tvhost_rwlock_read_lock(&vq->iotlb_lock);\n \n \tif (unlikely(!vq->access_ok))\n \t\tif (unlikely(vring_translate(dev, vq) < 0))\n@@ -1518,8 +1534,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,\n \t\tnb_tx = virtio_dev_rx_split(dev, vq, pkts, count);\n \n out:\n-\tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))\n-\t\tvhost_user_iotlb_rd_unlock(vq);\n+\tvhost_rwlock_read_unlock(&vq->iotlb_lock);\n \n out_access_unlock:\n \tvhost_spinlock_unlock(&vq->access_lock);\n@@ -1595,6 +1610,7 @@ virtio_dev_rx_async_submit_split(struct virtio_net *dev, struct vhost_virtqueue\n \t\tuint16_t queue_id, struct rte_mbuf **pkts, uint32_t count,\n \t\tint16_t dma_id, uint16_t vchan_id)\n \tVHOST_SPINLOCK_REQUIRES(vq->access_lock)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tstruct buf_vector buf_vec[BUF_VECTOR_MAX];\n \tuint32_t pkt_idx = 0;\n@@ -1700,6 +1716,7 @@ vhost_enqueue_async_packed(struct virtio_net *dev,\n \t\t\t    uint16_t *nr_descs,\n \t\t\t    uint16_t *nr_buffers)\n \tVHOST_SPINLOCK_REQUIRES(vq->access_lock)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tuint16_t nr_vec = 0;\n \tuint16_t avail_idx = vq->last_avail_idx;\n@@ -1758,6 +1775,7 @@ static __rte_always_inline int16_t\n virtio_dev_rx_async_packed(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \t\t\t    struct rte_mbuf *pkt, uint16_t *nr_descs, uint16_t *nr_buffers)\n \tVHOST_SPINLOCK_REQUIRES(vq->access_lock)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tstruct buf_vector buf_vec[BUF_VECTOR_MAX];\n \n@@ -1805,6 +1823,7 @@ virtio_dev_rx_async_submit_packed(struct virtio_net *dev, struct vhost_virtqueue\n \t\tuint16_t queue_id, struct rte_mbuf **pkts, uint32_t count,\n \t\tint16_t dma_id, uint16_t vchan_id)\n \tVHOST_SPINLOCK_REQUIRES(vq->access_lock)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tuint32_t pkt_idx = 0;\n \tuint32_t remained = count;\n@@ -2154,8 +2173,7 @@ virtio_dev_rx_async_submit(struct virtio_net *dev, uint16_t queue_id,\n \tif (unlikely(!vq->enabled || !vq->async))\n \t\tgoto out_access_unlock;\n \n-\tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))\n-\t\tvhost_user_iotlb_rd_lock(vq);\n+\tvhost_rwlock_read_lock(&vq->iotlb_lock);\n \n \tif (unlikely(!vq->access_ok))\n \t\tif (unlikely(vring_translate(dev, vq) < 0))\n@@ -2173,8 +2191,7 @@ virtio_dev_rx_async_submit(struct virtio_net *dev, uint16_t queue_id,\n \t\t\t\tpkts, count, dma_id, vchan_id);\n \n out:\n-\tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))\n-\t\tvhost_user_iotlb_rd_unlock(vq);\n+\tvhost_rwlock_read_unlock(&vq->iotlb_lock);\n \n out_access_unlock:\n \tvhost_spinlock_unlock(&vq->access_lock);\n@@ -2697,6 +2714,7 @@ virtio_dev_tx_split(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \tstruct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count,\n \tbool legacy_ol_flags)\n \tVHOST_SPINLOCK_REQUIRES(vq->access_lock)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tuint16_t i;\n \tuint16_t free_entries;\n@@ -2793,6 +2811,7 @@ virtio_dev_tx_split_legacy(struct virtio_net *dev,\n \tstruct vhost_virtqueue *vq, struct rte_mempool *mbuf_pool,\n \tstruct rte_mbuf **pkts, uint16_t count)\n \tVHOST_SPINLOCK_REQUIRES(vq->access_lock)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \treturn virtio_dev_tx_split(dev, vq, mbuf_pool, pkts, count, true);\n }\n@@ -2803,6 +2822,7 @@ virtio_dev_tx_split_compliant(struct virtio_net *dev,\n \tstruct vhost_virtqueue *vq, struct rte_mempool *mbuf_pool,\n \tstruct rte_mbuf **pkts, uint16_t count)\n \tVHOST_SPINLOCK_REQUIRES(vq->access_lock)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \treturn virtio_dev_tx_split(dev, vq, mbuf_pool, pkts, count, false);\n }\n@@ -2814,6 +2834,7 @@ vhost_reserve_avail_batch_packed(struct virtio_net *dev,\n \t\t\t\t uint16_t avail_idx,\n \t\t\t\t uintptr_t *desc_addrs,\n \t\t\t\t uint16_t *ids)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tbool wrap = vq->avail_wrap_counter;\n \tstruct vring_packed_desc *descs = vq->desc_packed;\n@@ -2883,6 +2904,7 @@ virtio_dev_tx_batch_packed(struct virtio_net *dev,\n \t\t\t   struct vhost_virtqueue *vq,\n \t\t\t   struct rte_mbuf **pkts,\n \t\t\t   bool legacy_ol_flags)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tuint16_t avail_idx = vq->last_avail_idx;\n \tuint32_t buf_offset = sizeof(struct virtio_net_hdr_mrg_rxbuf);\n@@ -2929,6 +2951,7 @@ vhost_dequeue_single_packed(struct virtio_net *dev,\n \t\t\t    uint16_t *buf_id,\n \t\t\t    uint16_t *desc_count,\n \t\t\t    bool legacy_ol_flags)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tstruct buf_vector buf_vec[BUF_VECTOR_MAX];\n \tuint32_t buf_len;\n@@ -2972,6 +2995,7 @@ virtio_dev_tx_single_packed(struct virtio_net *dev,\n \t\t\t    struct rte_mempool *mbuf_pool,\n \t\t\t    struct rte_mbuf *pkts,\n \t\t\t    bool legacy_ol_flags)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \n \tuint16_t buf_id, desc_count = 0;\n@@ -3003,6 +3027,7 @@ virtio_dev_tx_packed(struct virtio_net *dev,\n \t\t     uint32_t count,\n \t\t     bool legacy_ol_flags)\n \tVHOST_SPINLOCK_REQUIRES(vq->access_lock)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \tuint32_t pkt_idx = 0;\n \n@@ -3047,6 +3072,7 @@ virtio_dev_tx_packed_legacy(struct virtio_net *dev,\n \tstruct vhost_virtqueue *__rte_restrict vq, struct rte_mempool *mbuf_pool,\n \tstruct rte_mbuf **__rte_restrict pkts, uint32_t count)\n \tVHOST_SPINLOCK_REQUIRES(vq->access_lock)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \treturn virtio_dev_tx_packed(dev, vq, mbuf_pool, pkts, count, true);\n }\n@@ -3057,6 +3083,7 @@ virtio_dev_tx_packed_compliant(struct virtio_net *dev,\n \tstruct vhost_virtqueue *__rte_restrict vq, struct rte_mempool *mbuf_pool,\n \tstruct rte_mbuf **__rte_restrict pkts, uint32_t count)\n \tVHOST_SPINLOCK_REQUIRES(vq->access_lock)\n+\tVHOST_RDLOCK_REQUIRES(vq->iotlb_lock)\n {\n \treturn virtio_dev_tx_packed(dev, vq, mbuf_pool, pkts, count, false);\n }\n@@ -3096,8 +3123,7 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id,\n \t\tgoto out_access_unlock;\n \t}\n \n-\tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))\n-\t\tvhost_user_iotlb_rd_lock(vq);\n+\tvhost_rwlock_read_lock(&vq->iotlb_lock);\n \n \tif (unlikely(!vq->access_ok))\n \t\tif (unlikely(vring_translate(dev, vq) < 0)) {\n@@ -3153,8 +3179,7 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id,\n \t}\n \n out:\n-\tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))\n-\t\tvhost_user_iotlb_rd_unlock(vq);\n+\tvhost_rwlock_read_unlock(&vq->iotlb_lock);\n \n out_access_unlock:\n \tvhost_spinlock_unlock(&vq->access_lock);\n",
    "prefixes": [
        "RFC",
        "5/5"
    ]
}