get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 815326,
    "url": "http://patchwork.ozlabs.org/api/patches/815326/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/1505807208-9063-11-git-send-email-eric.auger@redhat.com/",
    "project": {
        "id": 14,
        "url": "http://patchwork.ozlabs.org/api/projects/14/?format=api",
        "name": "QEMU Development",
        "link_name": "qemu-devel",
        "list_id": "qemu-devel.nongnu.org",
        "list_email": "qemu-devel@nongnu.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": "",
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<1505807208-9063-11-git-send-email-eric.auger@redhat.com>",
    "list_archive_url": null,
    "date": "2017-09-19T07:46:42",
    "name": "[RFC,v4,10/16] virtio-iommu: Implement probe request",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "da8e1273ca740af5f7fb04ff091333da0951e6da",
    "submitter": {
        "id": 69187,
        "url": "http://patchwork.ozlabs.org/api/people/69187/?format=api",
        "name": "Eric Auger",
        "email": "eric.auger@redhat.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/1505807208-9063-11-git-send-email-eric.auger@redhat.com/mbox/",
    "series": [
        {
            "id": 3796,
            "url": "http://patchwork.ozlabs.org/api/series/3796/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=3796",
            "date": "2017-09-19T07:46:32",
            "name": "VIRTIO-IOMMU device",
            "version": 4,
            "mbox": "http://patchwork.ozlabs.org/series/3796/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/815326/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/815326/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>",
        "X-Original-To": "incoming@patchwork.ozlabs.org",
        "Delivered-To": "patchwork-incoming@bilbo.ozlabs.org",
        "Authentication-Results": [
            "ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)",
            "ext-mx08.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com",
            "ext-mx08.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=eric.auger@redhat.com"
        ],
        "Received": [
            "from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xxFXk4xdVz9s82\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 19 Sep 2017 17:55:18 +1000 (AEST)",
            "from localhost ([::1]:40625 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1duDNE-00057s-P7\n\tfor incoming@patchwork.ozlabs.org; Tue, 19 Sep 2017 03:55:16 -0400",
            "from eggs.gnu.org ([2001:4830:134:3::10]:48018)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <eric.auger@redhat.com>) id 1duDHZ-0000qk-On\n\tfor qemu-devel@nongnu.org; Tue, 19 Sep 2017 03:49:27 -0400",
            "from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <eric.auger@redhat.com>) id 1duDHY-0001PU-90\n\tfor qemu-devel@nongnu.org; Tue, 19 Sep 2017 03:49:25 -0400",
            "from mx1.redhat.com ([209.132.183.28]:46580)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <eric.auger@redhat.com>)\n\tid 1duDHR-0001Lc-QM; Tue, 19 Sep 2017 03:49:18 -0400",
            "from smtp.corp.redhat.com\n\t(int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id B4783C0546EC;\n\tTue, 19 Sep 2017 07:49:16 +0000 (UTC)",
            "from localhost.localdomain.com (ovpn-116-197.ams2.redhat.com\n\t[10.36.116.197])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id C9CFF61348;\n\tTue, 19 Sep 2017 07:48:55 +0000 (UTC)"
        ],
        "DMARC-Filter": "OpenDMARC Filter v1.3.2 mx1.redhat.com B4783C0546EC",
        "From": "Eric Auger <eric.auger@redhat.com>",
        "To": "eric.auger.pro@gmail.com, eric.auger@redhat.com, peter.maydell@linaro.org,\n\talex.williamson@redhat.com, mst@redhat.com, qemu-arm@nongnu.org,\n\tqemu-devel@nongnu.org, jean-philippe.brucker@arm.com",
        "Date": "Tue, 19 Sep 2017 09:46:42 +0200",
        "Message-Id": "<1505807208-9063-11-git-send-email-eric.auger@redhat.com>",
        "In-Reply-To": "<1505807208-9063-1-git-send-email-eric.auger@redhat.com>",
        "References": "<1505807208-9063-1-git-send-email-eric.auger@redhat.com>",
        "X-Scanned-By": "MIMEDefang 2.79 on 10.5.11.11",
        "X-Greylist": "Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.32]);\n\tTue, 19 Sep 2017 07:49:16 +0000 (UTC)",
        "X-detected-operating-system": "by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]",
        "X-Received-From": "209.132.183.28",
        "Subject": "[Qemu-devel] [RFC v4 10/16] virtio-iommu: Implement probe request",
        "X-BeenThere": "qemu-devel@nongnu.org",
        "X-Mailman-Version": "2.1.21",
        "Precedence": "list",
        "List-Id": "<qemu-devel.nongnu.org>",
        "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>",
        "List-Archive": "<http://lists.nongnu.org/archive/html/qemu-devel/>",
        "List-Post": "<mailto:qemu-devel@nongnu.org>",
        "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>",
        "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>",
        "Cc": "wei@redhat.com, kevin.tian@intel.com, marc.zyngier@arm.com,\n\ttn@semihalf.com, \n\twill.deacon@arm.com, drjones@redhat.com, peterx@redhat.com,\n\tlinuc.decode@gmail.com, bharat.bhushan@nxp.com,\n\tchristoffer.dall@linaro.org",
        "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org",
        "Sender": "\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"
    },
    "content": "This patch implements the PROBE request. At the moment,\nno reserved regions are returned.\n\nAt the moment reserved regions are stored per device.\n\nSigned-off-by: Eric Auger <eric.auger@redhat.com>\n\n---\n\nWaiting for clarifications on v0.4 spec\n---\n hw/virtio/trace-events   |   2 +\n hw/virtio/virtio-iommu.c | 173 ++++++++++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 173 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events\nindex 9010fbd..9ccfad1 100644\n--- a/hw/virtio/trace-events\n+++ b/hw/virtio/trace-events\n@@ -46,3 +46,5 @@ virtio_iommu_unmap_left_interval(uint64_t low, uint64_t high, uint64_t next_low,\n virtio_iommu_unmap_right_interval(uint64_t low, uint64_t high, uint64_t next_low, uint64_t next_high) \"Unmap right [0x%\"PRIx64\",0x%\"PRIx64\"], new interval=[0x%\"PRIx64\",0x%\"PRIx64\"]\"\n virtio_iommu_unmap_inc_interval(uint64_t low, uint64_t high) \"Unmap inc [0x%\"PRIx64\",0x%\"PRIx64\"]\"\n virtio_iommu_translate_out(uint64_t virt_addr, uint64_t phys_addr, uint32_t sid) \"0x%\"PRIx64\" -> 0x%\"PRIx64 \" for sid=%d\"\n+virtio_iommu_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t addr, uint64_t size, uint32_t flags, size_t filled) \"dev= %d, subtype=%d addr=0x%\"PRIx64\" size=0x%\"PRIx64\" flags=%d filled=0x%lx\"\n+virtio_iommu_fill_none_property(uint32_t devid) \"devid=%d\"\ndiff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c\nindex db46a91..281b0f8 100644\n--- a/hw/virtio/virtio-iommu.c\n+++ b/hw/virtio/virtio-iommu.c\n@@ -37,6 +37,11 @@\n \n /* Max size */\n #define VIOMMU_DEFAULT_QUEUE_SIZE 256\n+#define VIOMMU_PROBE_SIZE 512\n+\n+#define SUPPORTED_PROBE_PROPERTIES (\\\n+    VIRTIO_IOMMU_PROBE_T_NONE | \\\n+    VIRTIO_IOMMU_PROBE_T_RESV_MEM)\n \n typedef struct viommu_as {\n     uint32_t id;\n@@ -49,6 +54,7 @@ typedef struct viommu_dev {\n     viommu_as *as;\n     QLIST_ENTRY(viommu_dev) next;\n     VirtIOIOMMU *viommu;\n+    GTree *reserved_regions;\n } viommu_dev;\n \n typedef struct viommu_interval {\n@@ -63,6 +69,13 @@ typedef struct viommu_mapping {\n     uint32_t flags;\n } viommu_mapping;\n \n+typedef struct viommu_property_buffer {\n+    viommu_dev *dev;\n+    size_t filled;\n+    uint8_t *start;\n+    bool error;\n+} viommu_property_buffer;\n+\n static inline uint16_t virtio_iommu_get_sid(IOMMUDevice *dev)\n {\n     return PCI_BUILD_BDF(pci_bus_num(dev->bus), dev->devfn);\n@@ -101,6 +114,9 @@ static viommu_dev *virtio_iommu_get_dev(VirtIOIOMMU *s, uint32_t devid)\n     dev->viommu = s;\n     trace_virtio_iommu_get_dev(devid);\n     g_tree_insert(s->devices, GUINT_TO_POINTER(devid), dev);\n+    dev->reserved_regions = g_tree_new_full((GCompareDataFunc)interval_cmp,\n+                                            NULL, (GDestroyNotify)g_free,\n+                                            (GDestroyNotify)g_free);\n     return dev;\n }\n \n@@ -114,6 +130,7 @@ static void virtio_iommu_put_dev(gpointer data)\n     }\n \n     trace_virtio_iommu_put_dev(dev->id);\n+    g_tree_destroy(dev->reserved_regions);\n     g_free(dev);\n }\n \n@@ -369,6 +386,123 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s,\n     return VIRTIO_IOMMU_S_INVAL;\n }\n \n+static gboolean virtio_iommu_fill_resv_mem_prop(gpointer key,\n+                                                gpointer value,\n+                                                gpointer data)\n+{\n+    struct virtio_iommu_probe_resv_mem *resv =\n+        (struct virtio_iommu_probe_resv_mem *)value;\n+    struct virtio_iommu_probe_property *prop;\n+    struct virtio_iommu_probe_resv_mem *current;\n+    viommu_property_buffer *bufstate = (viommu_property_buffer *)data;\n+    size_t size = sizeof(*resv), total_size;\n+\n+    total_size = size + 4;\n+\n+    if (bufstate->filled >= VIOMMU_PROBE_SIZE) {\n+        bufstate->error = true;\n+        return true;\n+    }\n+    prop = (struct virtio_iommu_probe_property *)\n+                (bufstate->start + bufstate->filled);\n+    prop->type = cpu_to_le16(VIRTIO_IOMMU_PROBE_T_RESV_MEM) &\n+                    VIRTIO_IOMMU_PROBE_T_MASK;\n+    prop->length = size;\n+\n+    current = (struct virtio_iommu_probe_resv_mem *)prop->value;\n+    *current = *resv;\n+    bufstate->filled += total_size;\n+    trace_virtio_iommu_fill_resv_property(bufstate->dev->id,\n+                                          resv->subtype, resv->addr,\n+                                          resv->size, resv->flags,\n+                                          bufstate->filled);\n+    return false;\n+}\n+\n+static int virtio_iommu_fill_none_prop(viommu_property_buffer *bufstate)\n+{\n+    struct virtio_iommu_probe_property *prop;\n+\n+    prop = (struct virtio_iommu_probe_property *)\n+                (bufstate->start + bufstate->filled);\n+    prop->type = cpu_to_le16(VIRTIO_IOMMU_PROBE_T_NONE)\n+                    & VIRTIO_IOMMU_PROBE_T_MASK;\n+    prop->length = 0;\n+    bufstate->filled += 4;\n+    trace_virtio_iommu_fill_none_property(bufstate->dev->id);\n+    return 0;\n+}\n+\n+static int virtio_iommu_fill_property(int devid, int type,\n+                                      viommu_property_buffer *bufstate)\n+{\n+    int ret = -ENOSPC;\n+\n+    if (bufstate->filled + 4 >= VIOMMU_PROBE_SIZE) {\n+        bufstate->error = true;\n+        goto out;\n+    }\n+\n+    switch (type) {\n+    case VIRTIO_IOMMU_PROBE_T_NONE:\n+        ret = virtio_iommu_fill_none_prop(bufstate);\n+        break;\n+    case VIRTIO_IOMMU_PROBE_T_RESV_MEM:\n+    {\n+        viommu_dev *dev = bufstate->dev;\n+\n+        g_tree_foreach(dev->reserved_regions,\n+                       virtio_iommu_fill_resv_mem_prop,\n+                       bufstate);\n+        if (!bufstate->error) {\n+            ret = 0;\n+        }\n+        break;\n+    }\n+    default:\n+        ret = -ENOENT;\n+        break;\n+    }\n+out:\n+    if (ret) {\n+        error_report(\"%s property of type=%d could not be filled (%d),\"\n+                     \" remaining size = 0x%lx\",\n+                     __func__, type, ret, bufstate->filled);\n+    }\n+    return ret;\n+}\n+\n+static int virtio_iommu_probe(VirtIOIOMMU *s,\n+                              struct virtio_iommu_req_probe *req,\n+                              uint8_t *buf)\n+{\n+    uint32_t devid = le32_to_cpu(req->device);\n+    int16_t prop_types = SUPPORTED_PROBE_PROPERTIES, type;\n+    viommu_property_buffer bufstate;\n+    viommu_dev *dev;\n+    int ret;\n+\n+    dev = g_tree_lookup(s->devices, GUINT_TO_POINTER(devid));\n+    if (!dev) {\n+        return -EINVAL;\n+    }\n+\n+    bufstate.start = buf;\n+    bufstate.filled = 0;\n+    bufstate.dev = dev;\n+\n+    while ((type = ctz32(prop_types)) != 32) {\n+        ret = virtio_iommu_fill_property(devid, 1 << type, &bufstate);\n+        if (ret) {\n+            break;\n+        }\n+        prop_types &= ~(1 << type);\n+    }\n+    virtio_iommu_fill_property(devid, VIRTIO_IOMMU_PROBE_T_NONE, &bufstate);\n+\n+    return VIRTIO_IOMMU_S_OK;\n+}\n+\n #define get_payload_size(req) (\\\n sizeof((req)) - sizeof(struct virtio_iommu_req_tail))\n \n@@ -433,6 +567,24 @@ static int virtio_iommu_handle_unmap(VirtIOIOMMU *s,\n     return virtio_iommu_unmap(s, &req);\n }\n \n+static int virtio_iommu_handle_probe(VirtIOIOMMU *s,\n+                                     struct iovec *iov,\n+                                     unsigned int iov_cnt,\n+                                     uint8_t *buf)\n+{\n+    struct virtio_iommu_req_probe req;\n+    size_t sz, payload_sz;\n+\n+    payload_sz = get_payload_size(req);\n+\n+    sz = iov_to_buf(iov, iov_cnt, 0, &req, payload_sz);\n+    if (sz != payload_sz) {\n+        return VIRTIO_IOMMU_S_INVAL;\n+    }\n+\n+    return virtio_iommu_probe(s, &req, buf);\n+}\n+\n static void virtio_iommu_handle_command(VirtIODevice *vdev, VirtQueue *vq)\n {\n     VirtIOIOMMU *s = VIRTIO_IOMMU(vdev);\n@@ -477,16 +629,31 @@ static void virtio_iommu_handle_command(VirtIODevice *vdev, VirtQueue *vq)\n         case VIRTIO_IOMMU_T_UNMAP:\n             tail.status = virtio_iommu_handle_unmap(s, iov, iov_cnt);\n             break;\n+        case VIRTIO_IOMMU_T_PROBE:\n+        {\n+            struct virtio_iommu_req_tail *ptail;\n+            uint8_t *buf = g_malloc0(s->config.probe_size + sizeof(tail));\n+\n+            ptail = (struct virtio_iommu_req_tail *)buf + s->config.probe_size;\n+            ptail->status = virtio_iommu_handle_probe(s, iov, iov_cnt, buf);\n+\n+            sz = iov_from_buf(elem->in_sg, elem->in_num, 0,\n+                              buf, s->config.probe_size + sizeof(tail));\n+            g_free(buf);\n+            assert(sz == s->config.probe_size + sizeof(tail));\n+            goto push;\n+        }\n         default:\n             tail.status = VIRTIO_IOMMU_S_UNSUPP;\n         }\n-        qemu_mutex_unlock(&s->mutex);\n \n         sz = iov_from_buf(elem->in_sg, elem->in_num, 0,\n                           &tail, sizeof(tail));\n         assert(sz == sizeof(tail));\n \n-        virtqueue_push(vq, elem, sizeof(tail));\n+push:\n+        qemu_mutex_unlock(&s->mutex);\n+        virtqueue_push(vq, elem, sz);\n         virtio_notify(vdev, vq);\n         g_free(elem);\n     }\n@@ -574,6 +741,7 @@ static uint64_t virtio_iommu_get_features(VirtIODevice *vdev, uint64_t f,\n     virtio_add_feature(&f, VIRTIO_RING_F_INDIRECT_DESC);\n     virtio_add_feature(&f, VIRTIO_IOMMU_F_INPUT_RANGE);\n     virtio_add_feature(&f, VIRTIO_IOMMU_F_MAP_UNMAP);\n+    virtio_add_feature(&f, VIRTIO_IOMMU_F_PROBE);\n     return f;\n }\n \n@@ -631,6 +799,7 @@ static void virtio_iommu_device_realize(DeviceState *dev, Error **errp)\n \n     s->config.page_size_mask = TARGET_PAGE_MASK;\n     s->config.input_range.end = -1UL;\n+    s->config.probe_size = VIOMMU_PROBE_SIZE;\n \n     qemu_mutex_init(&s->mutex);\n \n",
    "prefixes": [
        "RFC",
        "v4",
        "10/16"
    ]
}