get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 65786,
    "url": "https://patches.dpdk.org/api/patches/65786/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/20200213100458.483410-1-amorenoz@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": "<20200213100458.483410-1-amorenoz@redhat.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20200213100458.483410-1-amorenoz@redhat.com",
    "date": "2020-02-13T10:04:58",
    "name": "vhost: protect log addr translation in iotlb updates",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "bcffb02f897d767d60af96c4b1908f4d8a5f8eb5",
    "submitter": {
        "id": 1397,
        "url": "https://patches.dpdk.org/api/people/1397/?format=api",
        "name": "Adrian Moreno",
        "email": "amorenoz@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/20200213100458.483410-1-amorenoz@redhat.com/mbox/",
    "series": [
        {
            "id": 8524,
            "url": "https://patches.dpdk.org/api/series/8524/?format=api",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=8524",
            "date": "2020-02-13T10:04:58",
            "name": "vhost: protect log addr translation in iotlb updates",
            "version": 1,
            "mbox": "https://patches.dpdk.org/series/8524/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/65786/comments/",
    "check": "fail",
    "checks": "https://patches.dpdk.org/api/patches/65786/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 dpdk.org (dpdk.org [92.243.14.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id E90D8A0542;\n\tThu, 13 Feb 2020 11:05:21 +0100 (CET)",
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id BE60A11A4;\n\tThu, 13 Feb 2020 11:05:21 +0100 (CET)",
            "from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com\n [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id DEA45100C\n for <dev@dpdk.org>; Thu, 13 Feb 2020 11:05:19 +0100 (CET)",
            "from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com\n [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id\n us-mta-354-Yp7RBZBvOeiW5jQwL1xb3g-1; Thu, 13 Feb 2020 05:05:07 -0500",
            "from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com\n [10.5.11.16])\n (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n (No client certificate requested)\n by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9DDEE801E78;\n Thu, 13 Feb 2020 10:05:06 +0000 (UTC)",
            "from amorenoz.users.ipa.redhat.com (unknown [10.36.118.173])\n by smtp.corp.redhat.com (Postfix) with ESMTP id 3057C5C1BB;\n Thu, 13 Feb 2020 10:04:59 +0000 (UTC)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1581588319;\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 bh=LkqvBUv+slmGe/pvM5IbWWLKJr4wOoO15lhjUvYhPMM=;\n b=dA/0wZoOTMJU8Z2BdLIW+x0io+gsfmNulbPbDz07GWa0rCXBczLEwDUiHKHZ0bOOcTbjFv\n QayNiN/+qtHxprzVEKmKYvpa2rsfu5XjSKXXBa5oPOLSvYkIaFe4nVPZglnTzQgj5/wrpJ\n 8jilOFOAazgpekLMKQOjjTEDCRX6Grg=",
        "From": "Adrian Moreno <amorenoz@redhat.com>",
        "To": "dev@dpdk.org",
        "Cc": "maxime.coquelin@redhat.com, Tiwei Bie <tiwei.bie@intel.com>,\n Zhihong Wang <zhihong.wang@intel.com>, Adrian Moreno <amorenoz@redhat.com>,\n stable@dpdk.org",
        "Date": "Thu, 13 Feb 2020 11:04:58 +0100",
        "Message-Id": "<20200213100458.483410-1-amorenoz@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 2.79 on 10.5.11.16",
        "X-MC-Unique": "Yp7RBZBvOeiW5jQwL1xb3g-1",
        "X-Mimecast-Spam-Score": "0",
        "X-Mimecast-Originator": "redhat.com",
        "Content-Type": "text/plain; charset=US-ASCII",
        "Content-Transfer-Encoding": "quoted-printable",
        "Subject": "[dpdk-dev] [PATCH] vhost: protect log addr translation in iotlb\n\tupdates",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "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",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Currently, the log address translation only  happens in the vhost-user's\ntranslate_ring_addresses(). However, the IOTLB update handler is not\nchecking if it was mapped to re-trigger that translation.\n\nSince the log address mapping could fail, check it on iotlb updates.\nAlso, check it on vring_translate() so we do not dirty pages if the\nlogging address is not yet ready.\n\nAdditionally, properly protect the accesses to the iotlb structures.\n\nFixes: 657414f3788a (\"vhost: protect log addr translation in iotlb updates\")\nCc: stable@dpdk.org\n\nSigned-off-by: Adrian Moreno <amorenoz@redhat.com>\n---\n lib/librte_vhost/vhost.c      | 55 +++++++++++++++++++++++++++++++++\n lib/librte_vhost/vhost.h      | 15 +++++++--\n lib/librte_vhost/vhost_user.c | 57 +++++++++++++++--------------------\n 3 files changed, 92 insertions(+), 35 deletions(-)",
    "diff": "diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c\nindex c819a8477..442d896ef 100644\n--- a/lib/librte_vhost/vhost.c\n+++ b/lib/librte_vhost/vhost.c\n@@ -353,6 +353,56 @@ free_device(struct virtio_net *dev)\n \trte_free(dev);\n }\n \n+static __rte_always_inline int\n+log_translate(struct virtio_net *dev, struct vhost_virtqueue *vq)\n+{\n+\tif (likely(!(vq->ring_addrs.flags & (1 << VHOST_VRING_F_LOG))))\n+\t\treturn 0;\n+\n+\tvq->log_guest_addr = translate_log_addr(dev, vq,\n+\t\t\t\t\t\tvq->ring_addrs.log_guest_addr);\n+\tif (vq->log_guest_addr == 0)\n+\t\treturn -1;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Converts vring log address to GPA\n+ * If IOMMU is enabled, the log address is IOVA\n+ * If IOMMU not enabled, the log address is already GPA\n+ *\n+ * Caller should have iotlb_lock read-locked\n+ */\n+uint64_t\n+translate_log_addr(struct virtio_net *dev, struct vhost_virtqueue *vq,\n+\t\tuint64_t log_addr)\n+{\n+\tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)) {\n+\t\tconst uint64_t exp_size = sizeof(uint64_t);\n+\t\tuint64_t hva, gpa;\n+\t\tuint64_t size = exp_size;\n+\n+\t\thva = vhost_iova_to_vva(dev, vq, log_addr,\n+\t\t\t\t\t&size, VHOST_ACCESS_RW);\n+\n+\t\tif (size != exp_size)\n+\t\t\treturn 0;\n+\n+\t\tgpa = hva_to_gpa(dev, hva, exp_size);\n+\t\tif (!gpa) {\n+\t\t\tVHOST_LOG_CONFIG(ERR,\n+\t\t\t\t\"VQ: Failed to find GPA for log_addr: 0x%\" PRIx64 \" hva: 0x%\" PRIx64 \"\\n\",\n+\t\t\t\tlog_addr, hva);\n+\t\t\treturn 0;\n+\t\t}\n+\t\treturn gpa;\n+\n+\t} else\n+\t\treturn log_addr;\n+}\n+\n+/* Caller should have iotlb_lock read-locked */\n static int\n vring_translate_split(struct virtio_net *dev, struct vhost_virtqueue *vq)\n {\n@@ -391,6 +441,7 @@ vring_translate_split(struct virtio_net *dev, struct vhost_virtqueue *vq)\n \treturn 0;\n }\n \n+/* Caller should have iotlb_lock read-locked */\n static int\n vring_translate_packed(struct virtio_net *dev, struct vhost_virtqueue *vq)\n {\n@@ -437,6 +488,10 @@ vring_translate(struct virtio_net *dev, struct vhost_virtqueue *vq)\n \t\tif (vring_translate_split(dev, vq) < 0)\n \t\t\treturn -1;\n \t}\n+\n+\tif (log_translate(dev, vq) < 0)\n+\t\treturn -1;\n+\n \tvq->access_ok = 1;\n \n \treturn 0;\ndiff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h\nindex 686ce42a2..2087d1400 100644\n--- a/lib/librte_vhost/vhost.h\n+++ b/lib/librte_vhost/vhost.h\n@@ -462,14 +462,23 @@ static __rte_always_inline void\n vhost_log_cache_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \t\t\tuint64_t offset, uint64_t len)\n {\n-\tvhost_log_cache_write(dev, vq, vq->log_guest_addr + offset, len);\n+\tif (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL))) {\n+\t\tif (unlikely(vq->log_guest_addr == 0))\n+\t\t\treturn;\n+\t\t__vhost_log_cache_write(dev, vq, vq->log_guest_addr + offset,\n+\t\t\t\t\tlen);\n+\t}\n }\n \n static __rte_always_inline void\n vhost_log_used_vring(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \t\t     uint64_t offset, uint64_t len)\n {\n-\tvhost_log_write(dev, vq->log_guest_addr + offset, len);\n+\tif (unlikely(dev->features & (1ULL << VHOST_F_LOG_ALL))) {\n+\t\tif (unlikely(vq->log_guest_addr == 0))\n+\t\t\treturn;\n+\t\t__vhost_log_write(dev, vq->log_guest_addr + offset, len);\n+\t}\n }\n \n static __rte_always_inline void\n@@ -626,6 +635,8 @@ 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+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 \n static __rte_always_inline uint64_t\ndiff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c\nindex 69b84a882..5db9f148f 100644\n--- a/lib/librte_vhost/vhost_user.c\n+++ b/lib/librte_vhost/vhost_user.c\n@@ -656,13 +656,11 @@ ring_addr_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,\n {\n \tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)) {\n \t\tuint64_t vva;\n-\t\tuint64_t req_size = *size;\n \n-\t\tvva = vhost_user_iotlb_cache_find(vq, ra,\n+\t\tvhost_user_iotlb_rd_lock(vq);\n+\t\tvva = vhost_iova_to_vva(dev, vq, ra,\n \t\t\t\t\tsize, VHOST_ACCESS_RW);\n-\t\tif (req_size != *size)\n-\t\t\tvhost_user_iotlb_miss(dev, (ra + *size),\n-\t\t\t\t\t      VHOST_ACCESS_RW);\n+\t\tvhost_user_iotlb_rd_unlock(vq);\n \n \t\treturn vva;\n \t}\n@@ -670,37 +668,16 @@ ring_addr_to_vva(struct virtio_net *dev, struct vhost_virtqueue *vq,\n \treturn qva_to_vva(dev, ra, size);\n }\n \n-/*\n- * Converts vring log address to GPA\n- * If IOMMU is enabled, the log address is IOVA\n- * If IOMMU not enabled, the log address is already GPA\n- */\n static uint64_t\n-translate_log_addr(struct virtio_net *dev, struct vhost_virtqueue *vq,\n-\t\tuint64_t log_addr)\n+log_addr_to_gpa(struct virtio_net *dev, struct vhost_virtqueue *vq)\n {\n-\tif (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)) {\n-\t\tconst uint64_t exp_size = sizeof(struct vring_used) +\n-\t\t\tsizeof(struct vring_used_elem) * vq->size;\n-\t\tuint64_t hva, gpa;\n-\t\tuint64_t size = exp_size;\n-\n-\t\thva = vhost_iova_to_vva(dev, vq, log_addr,\n-\t\t\t\t\t&size, VHOST_ACCESS_RW);\n-\t\tif (size != exp_size)\n-\t\t\treturn 0;\n+\tuint64_t log_gpa;\n \n-\t\tgpa = hva_to_gpa(dev, hva, exp_size);\n-\t\tif (!gpa) {\n-\t\t\tVHOST_LOG_CONFIG(ERR,\n-\t\t\t\t\"VQ: Failed to find GPA for log_addr: 0x%\" PRIx64 \" hva: 0x%\" PRIx64 \"\\n\",\n-\t\t\t\tlog_addr, hva);\n-\t\t\treturn 0;\n-\t\t}\n-\t\treturn gpa;\n+\tvhost_user_iotlb_rd_lock(vq);\n+\tlog_gpa = translate_log_addr(dev, vq, vq->ring_addrs.log_guest_addr);\n+\tvhost_user_iotlb_rd_unlock(vq);\n \n-\t} else\n-\t\treturn log_addr;\n+\treturn log_gpa;\n }\n \n static struct virtio_net *\n@@ -712,7 +689,7 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index)\n \n \tif (addr->flags & (1 << VHOST_VRING_F_LOG)) {\n \t\tvq->log_guest_addr =\n-\t\t\ttranslate_log_addr(dev, vq, addr->log_guest_addr);\n+\t\t\tlog_addr_to_gpa(dev, vq);\n \t\tif (vq->log_guest_addr == 0) {\n \t\t\tVHOST_LOG_CONFIG(DEBUG,\n \t\t\t\t\"(%d) failed to map log_guest_addr.\\n\",\n@@ -2229,6 +2206,13 @@ is_vring_iotlb_split(struct vhost_virtqueue *vq, struct vhost_iotlb_msg *imsg)\n \tif (ra->used_user_addr < end && (ra->used_user_addr + len) > start)\n \t\treturn 1;\n \n+\tif (ra->flags & (1 << VHOST_VRING_F_LOG)) {\n+\t\tlen = sizeof(uint64_t);\n+\t\tif (ra->log_guest_addr < end &&\n+\t\t    (ra->log_guest_addr + len) > start)\n+\t\t\treturn 1;\n+\t}\n+\n \treturn 0;\n }\n \n@@ -2254,6 +2238,13 @@ is_vring_iotlb_packed(struct vhost_virtqueue *vq, struct vhost_iotlb_msg *imsg)\n \tif (ra->used_user_addr < end && (ra->used_user_addr + len) > start)\n \t\treturn 1;\n \n+\tif (ra->flags & (1 << VHOST_VRING_F_LOG)) {\n+\t\tlen = sizeof(uint64_t);\n+\t\tif (ra->log_guest_addr < end &&\n+\t\t    (ra->log_guest_addr + len) > start)\n+\t\t\treturn 1;\n+\t}\n+\n \treturn 0;\n }\n \n",
    "prefixes": []
}