get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 41389,
    "url": "http://patches.dpdk.org/api/patches/41389/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/1529668268-7462-2-git-send-email-jia.guo@intel.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": "<1529668268-7462-2-git-send-email-jia.guo@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1529668268-7462-2-git-send-email-jia.guo@intel.com",
    "date": "2018-06-22T11:51:05",
    "name": "[v2,1/4] bus/pci: handle device hot unplug",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "288fd9deb746c105be4e7f269653a744d7c657cf",
    "submitter": {
        "id": 507,
        "url": "http://patches.dpdk.org/api/people/507/?format=api",
        "name": "Guo, Jia",
        "email": "jia.guo@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/1529668268-7462-2-git-send-email-jia.guo@intel.com/mbox/",
    "series": [
        {
            "id": 205,
            "url": "http://patches.dpdk.org/api/series/205/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=205",
            "date": "2018-06-22T11:51:04",
            "name": "hot plug failure handle mechanism",
            "version": 2,
            "mbox": "http://patches.dpdk.org/series/205/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/41389/comments/",
    "check": "warning",
    "checks": "http://patches.dpdk.org/api/patches/41389/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 566B91BB32;\n\tFri, 22 Jun 2018 13:48:09 +0200 (CEST)",
            "from mga09.intel.com (mga09.intel.com [134.134.136.24])\n\tby dpdk.org (Postfix) with ESMTP id 9DBB51BB15\n\tfor <dev@dpdk.org>; Fri, 22 Jun 2018 13:48:05 +0200 (CEST)",
            "from fmsmga007.fm.intel.com ([10.253.24.52])\n\tby orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t22 Jun 2018 04:48:04 -0700",
            "from jeffguo-s2600wt2.sh.intel.com (HELO localhost.localdomain)\n\t([10.67.110.10])\n\tby fmsmga007.fm.intel.com with ESMTP; 22 Jun 2018 04:48:02 -0700"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.51,256,1526367600\"; d=\"scan'208\";a=\"49078344\"",
        "From": "Jeff Guo <jia.guo@intel.com>",
        "To": "stephen@networkplumber.org, bruce.richardson@intel.com,\n\tferruh.yigit@intel.com, konstantin.ananyev@intel.com,\n\tgaetan.rivet@6wind.com, jingjing.wu@intel.com, thomas@monjalon.net,\n\tmotih@mellanox.com, matan@mellanox.com, harry.van.haaren@intel.com,\n\tqi.z.zhang@intel.com, shaopeng.he@intel.com",
        "Cc": "jblunck@infradead.org, shreyansh.jain@nxp.com, dev@dpdk.org,\n\tjia.guo@intel.com, helin.zhang@intel.com",
        "Date": "Fri, 22 Jun 2018 19:51:05 +0800",
        "Message-Id": "<1529668268-7462-2-git-send-email-jia.guo@intel.com>",
        "X-Mailer": "git-send-email 2.7.4",
        "In-Reply-To": "<1529668268-7462-1-git-send-email-jia.guo@intel.com>",
        "References": "<1498711073-42917-1-git-send-email-jia.guo@intel.com>\n\t<1529668268-7462-1-git-send-email-jia.guo@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v2 1/4] bus/pci: handle device hot unplug",
        "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\t<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\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "When a hardware device is removed physically or the software disables\nit, the hot unplug occur. App need to call ether dev API to detach the\ndevice, to unplug the device at the bus level and make access to the device\ninvalid. But the problem is that, the removal of the device from the\nsoftware lists is not going to be instantaneous, at this time if the data\npath still read/write the device, it will cause MMIO error and result of\nthe app crash out. So a hot unplug handle mechanism need to guaranty app\nwill not crash out when hot unplug device.\n\nTo handle device hot unplug is bus-specific behavior, this patch introduces\na bus ops so that each kind of bus can implement its own logic. Further,\nthis patch implements the ops for PCI bus: remap a dummy memory to avoid\nbus read/write error.\n\nSigned-off-by: Jeff Guo <jia.guo@intel.com>\n---\nv2->v1(v21):\nrefind commit log\n---\n drivers/bus/pci/pci_common.c            | 65 +++++++++++++++++++++++++++++++++\n drivers/bus/pci/pci_common_uio.c        | 33 +++++++++++++++++\n drivers/bus/pci/private.h               | 12 ++++++\n lib/librte_eal/common/include/rte_bus.h | 16 ++++++++\n 4 files changed, 126 insertions(+)",
    "diff": "diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c\nindex 7215aae..74d9aa8 100644\n--- a/drivers/bus/pci/pci_common.c\n+++ b/drivers/bus/pci/pci_common.c\n@@ -472,6 +472,70 @@ pci_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,\n \treturn NULL;\n }\n \n+static struct rte_pci_device *\n+pci_find_device_by_addr(void *failure_addr)\n+{\n+\tstruct rte_pci_device *pdev = NULL;\n+\tint i;\n+\n+\tFOREACH_DEVICE_ON_PCIBUS(pdev) {\n+\t\tfor (i = 0; i != RTE_DIM(pdev->mem_resource); i++) {\n+\t\t\tif ((uint64_t)(uintptr_t)failure_addr >=\n+\t\t\t    (uint64_t)(uintptr_t)pdev->mem_resource[i].addr &&\n+\t\t\t    (uint64_t)(uintptr_t)failure_addr <\n+\t\t\t    (uint64_t)(uintptr_t)pdev->mem_resource[i].addr +\n+\t\t\t    pdev->mem_resource[i].len) {\n+\t\t\t\tRTE_LOG(ERR, EAL, \"Failure address \"\n+\t\t\t\t\t\"%16.16\"PRIx64\" belongs to \"\n+\t\t\t\t\t\"device %s!\\n\",\n+\t\t\t\t\t(uint64_t)(uintptr_t)failure_addr,\n+\t\t\t\t\tpdev->device.name);\n+\t\t\t\treturn pdev;\n+\t\t\t}\n+\t\t}\n+\t}\n+\treturn NULL;\n+}\n+static int\n+pci_handle_hot_unplug(struct rte_device *dev, void *failure_addr)\n+{\n+\tstruct rte_pci_device *pdev = NULL;\n+\tint ret = 0;\n+\n+\tif (dev != NULL)\n+\t\tpdev = RTE_DEV_TO_PCI(dev);\n+\telse\n+\t\tpdev = pci_find_device_by_addr(failure_addr);\n+\n+\tif (!pdev)\n+\t\treturn -1;\n+\n+\t/* remap resources for devices */\n+\tswitch (pdev->kdrv) {\n+\tcase RTE_KDRV_VFIO:\n+#ifdef VFIO_PRESENT\n+\t\t/* TODO */\n+\t\tret = -1;\n+#endif\n+\t\tbreak;\n+\tcase RTE_KDRV_IGB_UIO:\n+\tcase RTE_KDRV_UIO_GENERIC:\n+\tcase RTE_KDRV_NIC_UIO:\n+\t\tret = pci_uio_remap_resource(pdev);\n+\t\tbreak;\n+\tdefault:\n+\t\tRTE_LOG(DEBUG, EAL,\n+\t\t\t\"Not managed by a supported kernel driver, skipped\\n\");\n+\t\tret = -1;\n+\t\tbreak;\n+\t}\n+\n+\tif (ret != 0)\n+\t\tRTE_LOG(ERR, EAL, \"Failed to handle hot unplug of device %s\",\n+\t\t\tpdev->name);\n+\treturn ret;\n+}\n+\n static int\n pci_plug(struct rte_device *dev)\n {\n@@ -502,6 +566,7 @@ struct rte_pci_bus rte_pci_bus = {\n \t\t.unplug = pci_unplug,\n \t\t.parse = pci_parse,\n \t\t.get_iommu_class = rte_pci_get_iommu_class,\n+\t\t.handle_hot_unplug = pci_handle_hot_unplug,\n \t},\n \t.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),\n \t.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),\ndiff --git a/drivers/bus/pci/pci_common_uio.c b/drivers/bus/pci/pci_common_uio.c\nindex 54bc20b..7ea73db 100644\n--- a/drivers/bus/pci/pci_common_uio.c\n+++ b/drivers/bus/pci/pci_common_uio.c\n@@ -146,6 +146,39 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res)\n \t}\n }\n \n+/* remap the PCI resource of a PCI device in anonymous virtual memory */\n+int\n+pci_uio_remap_resource(struct rte_pci_device *dev)\n+{\n+\tint i;\n+\tvoid *map_address;\n+\n+\tif (dev == NULL)\n+\t\treturn -1;\n+\n+\t/* Remap all BARs */\n+\tfor (i = 0; i != PCI_MAX_RESOURCE; i++) {\n+\t\t/* skip empty BAR */\n+\t\tif (dev->mem_resource[i].phys_addr == 0)\n+\t\t\tcontinue;\n+\t\tmap_address = mmap(dev->mem_resource[i].addr,\n+\t\t\t\t(size_t)dev->mem_resource[i].len,\n+\t\t\t\tPROT_READ | PROT_WRITE,\n+\t\t\t\tMAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);\n+\t\tif (map_address == MAP_FAILED) {\n+\t\t\tRTE_LOG(ERR, EAL,\n+\t\t\t\t\"Cannot remap resource for device %s\\n\",\n+\t\t\t\tdev->name);\n+\t\t\treturn -1;\n+\t\t}\n+\t\tRTE_LOG(INFO, EAL,\n+\t\t\t\"Successful remap resource for device %s\\n\",\n+\t\t\tdev->name);\n+\t}\n+\n+\treturn 0;\n+}\n+\n static struct mapped_pci_resource *\n pci_uio_find_resource(struct rte_pci_device *dev)\n {\ndiff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h\nindex 88fa587..5551506 100644\n--- a/drivers/bus/pci/private.h\n+++ b/drivers/bus/pci/private.h\n@@ -173,6 +173,18 @@ void pci_uio_free_resource(struct rte_pci_device *dev,\n \t\tstruct mapped_pci_resource *uio_res);\n \n /**\n+ * Remap the PCI resource of a PCI device in anonymous virtual memory.\n+ *\n+ * @param dev\n+ *   Point to the struct rte pci device.\n+ * @return\n+ *   - On success, zero.\n+ *   - On failure, a negative value.\n+ */\n+int\n+pci_uio_remap_resource(struct rte_pci_device *dev);\n+\n+/**\n  * Map device memory to uio resource\n  *\n  * This function is private to EAL.\ndiff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h\nindex eb9eded..6a5609f 100644\n--- a/lib/librte_eal/common/include/rte_bus.h\n+++ b/lib/librte_eal/common/include/rte_bus.h\n@@ -168,6 +168,20 @@ typedef int (*rte_bus_unplug_t)(struct rte_device *dev);\n typedef int (*rte_bus_parse_t)(const char *name, void *addr);\n \n /**\n+ * Implementation a specific hot unplug handler, which is responsible\n+ * for handle the failure when hot unplug the device, guaranty the system\n+ * would not hung in the case.\n+ * @param dev\n+ *\tPointer of the device structure.\n+ *\n+ * @return\n+ *\t0 on success.\n+ *\t!0 on error.\n+ */\n+typedef int (*rte_bus_handle_hot_unplug_t)(struct rte_device *dev,\n+\t\t\t\t\t\tvoid *dev_addr);\n+\n+/**\n  * Bus scan policies\n  */\n enum rte_bus_scan_mode {\n@@ -209,6 +223,8 @@ struct rte_bus {\n \trte_bus_plug_t plug;         /**< Probe single device for drivers */\n \trte_bus_unplug_t unplug;     /**< Remove single device from driver */\n \trte_bus_parse_t parse;       /**< Parse a device name */\n+\trte_bus_handle_hot_unplug_t handle_hot_unplug; /**< handle hot unplug\n+\t\t\t\t\t\t\tdevice event */\n \tstruct rte_bus_conf conf;    /**< Bus configuration */\n \trte_bus_get_iommu_class_t get_iommu_class; /**< Get iommu class */\n };\n",
    "prefixes": [
        "v2",
        "1/4"
    ]
}