get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 45719,
    "url": "http://patches.dpdk.org/api/patches/45719/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/1538316988-128382-5-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": "<1538316988-128382-5-git-send-email-jia.guo@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1538316988-128382-5-git-send-email-jia.guo@intel.com",
    "date": "2018-09-30T14:16:28",
    "name": "[v2,4/4] vfio: enable vfio hotplug by req notifier handler",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "29579f85e187b4b9b6b17b785a32af8ce26890ad",
    "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/1538316988-128382-5-git-send-email-jia.guo@intel.com/mbox/",
    "series": [
        {
            "id": 1607,
            "url": "http://patches.dpdk.org/api/series/1607/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=1607",
            "date": "2018-09-30T14:16:24",
            "name": "Enable hotplug in vfio",
            "version": 2,
            "mbox": "http://patches.dpdk.org/series/1607/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/45719/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/45719/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 3735A683E;\n\tSun, 30 Sep 2018 16:12:57 +0200 (CEST)",
            "from mga12.intel.com (mga12.intel.com [192.55.52.136])\n\tby dpdk.org (Postfix) with ESMTP id DCE775F65\n\tfor <dev@dpdk.org>; Sun, 30 Sep 2018 16:12:55 +0200 (CEST)",
            "from orsmga005.jf.intel.com ([10.7.209.41])\n\tby fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t30 Sep 2018 07:12:55 -0700",
            "from jeffguo-s2600wt2.sh.intel.com (HELO localhost.localdomain)\n\t([10.67.110.10])\n\tby orsmga005.jf.intel.com with ESMTP; 30 Sep 2018 07:12:51 -0700"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.54,324,1534834800\"; d=\"scan'208\";a=\"261661902\"",
        "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,\n\tbernard.iremonger@intel.com, \n\tarybchenko@solarflare.com, anatoly.burakov@intel.com",
        "Cc": "jblunck@infradead.org, shreyansh.jain@nxp.com, dev@dpdk.org,\n\tjia.guo@intel.com, helin.zhang@intel.com",
        "Date": "Sun, 30 Sep 2018 22:16:28 +0800",
        "Message-Id": "<1538316988-128382-5-git-send-email-jia.guo@intel.com>",
        "X-Mailer": "git-send-email 2.7.4",
        "In-Reply-To": "<1538316988-128382-1-git-send-email-jia.guo@intel.com>",
        "References": "<1534503091-31910-1-git-send-email-jia.guo@intel.com>\n\t<1538316988-128382-1-git-send-email-jia.guo@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v2 4/4] vfio: enable vfio hotplug by req notifier\n\thandler",
        "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 device is be hot-unplugged, the vfio kernel module will sent req\nnotifier to request user space to release the allocated resources at\nfirst. After that, vfio kernel module will detect the device disappear,\nand then delete the device in kernel.\n\nThis patch aim to add req notifier processing to enable hotplug for vfio.\nBy enable the req notifier monitoring and register the notifier callback,\nwhen device be hot-unplugged, the hot-unplug handler will be called to\nprocess hotplug for vfio.\n\nSigned-off-by: Jeff Guo <jia.guo@intel.com>\n---\nv2->v1:\nrefine some code logic.\n---\n drivers/bus/pci/linux/pci_vfio.c | 95 ++++++++++++++++++++++++++++++++++++++++\n drivers/bus/pci/pci_common.c     | 10 +++++\n 2 files changed, 105 insertions(+)",
    "diff": "diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c\nindex 686386d..c780860 100644\n--- a/drivers/bus/pci/linux/pci_vfio.c\n+++ b/drivers/bus/pci/linux/pci_vfio.c\n@@ -17,6 +17,8 @@\n #include <rte_eal_memconfig.h>\n #include <rte_malloc.h>\n #include <rte_vfio.h>\n+#include <rte_eal.h>\n+#include <rte_bus.h>\n \n #include \"eal_filesystem.h\"\n \n@@ -277,6 +279,89 @@ pci_vfio_setup_interrupts(struct rte_pci_device *dev, int vfio_dev_fd)\n \treturn -1;\n }\n \n+static void\n+pci_vfio_req_handler(void *param)\n+{\n+\tstruct rte_bus *bus;\n+\tint ret;\n+\tstruct rte_device *device = (struct rte_device *)param;\n+\n+\tbus = rte_bus_find_by_device(device);\n+\tif (bus == NULL) {\n+\t\tRTE_LOG(ERR, EAL, \"Cannot find bus for device (%s)\\n\",\n+\t\t\tdevice->name);\n+\t\treturn;\n+\t}\n+\n+\t/**\n+\t * vfio kernel module request user space to release allocated\n+\t * resources before device be deleted in kernel, so it can directly\n+\t * call the vfio bus hot-unplug handler to process it.\n+\t */\n+\tret = bus->hot_unplug_handler(device);\n+\tif (ret)\n+\t\tRTE_LOG(ERR, EAL, \"Can not handle hot-unplug for \"\n+\t\t\t\"device (%s)\\n\", device->name);\n+}\n+\n+/* enable notifier (only enable req now) */\n+static int\n+pci_vfio_enable_notifier(struct rte_pci_device *dev, int vfio_dev_fd)\n+{\n+\tint ret;\n+\tint fd = -1;\n+\n+\t/* set up an eventfd for req notifier */\n+\tfd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);\n+\tif (fd < 0) {\n+\t\tRTE_LOG(ERR, EAL, \"Cannot set up eventfd, \"\n+\t\t\t\t\"error %i (%s)\\n\", errno, strerror(errno));\n+\t\treturn -1;\n+\t}\n+\n+\tdev->req_notifier_handler.fd = fd;\n+\tdev->req_notifier_handler.type = RTE_INTR_HANDLE_VFIO_REQ;\n+\tdev->req_notifier_handler.vfio_dev_fd = vfio_dev_fd;\n+\tret = rte_intr_callback_register(&dev->req_notifier_handler,\n+\t\t\t\t\t pci_vfio_req_handler,\n+\t\t\t\t\t (void *)&dev->device);\n+\tif (ret) {\n+\t\tRTE_LOG(ERR, EAL, \"Fail to register req notifier handler.\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\tret = rte_intr_enable(&dev->req_notifier_handler);\n+\tif (ret) {\n+\t\tRTE_LOG(ERR, EAL, \"Fail to enable req notifier.\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/*disable notifier (only disable req now) */\n+static int\n+pci_vfio_disable_notifier(struct rte_pci_device *dev)\n+{\n+\tint ret;\n+\n+\tret = rte_intr_disable(&dev->req_notifier_handler);\n+\tif (ret) {\n+\t\tRTE_LOG(ERR, EAL, \"fail to disable req notifier.\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\tret = rte_intr_callback_unregister(&dev->req_notifier_handler,\n+\t\t\t\t\t   pci_vfio_req_handler,\n+\t\t\t\t\t   (void *)&dev->device);\n+\tif (ret) {\n+\t\tRTE_LOG(ERR, EAL,\n+\t\t\t \"fail to unregister req notifier handler.\\n\");\n+\t\treturn -1;\n+\t}\n+\treturn 0;\n+}\n+\n static int\n pci_vfio_is_ioport_bar(int vfio_dev_fd, int bar_index)\n {\n@@ -430,6 +515,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)\n \tstruct pci_map *maps;\n \n \tdev->intr_handle.fd = -1;\n+\tdev->req_notifier_handler.fd = -1;\n \n \t/* store PCI address string */\n \tsnprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT,\n@@ -521,6 +607,11 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)\n \t\tgoto err_vfio_res;\n \t}\n \n+\tif (pci_vfio_enable_notifier(dev, vfio_dev_fd) != 0) {\n+\t\tRTE_LOG(ERR, EAL, \"Error setting up notifier!\\n\");\n+\t\treturn -1;\n+\t}\n+\n \tTAILQ_INSERT_TAIL(vfio_res_list, vfio_res, next);\n \n \treturn 0;\n@@ -546,6 +637,7 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)\n \tstruct pci_map *maps;\n \n \tdev->intr_handle.fd = -1;\n+\tdev->req_notifier_handler.fd = -1;\n \n \t/* store PCI address string */\n \tsnprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT,\n@@ -586,6 +678,7 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)\n \n \t/* we need save vfio_dev_fd, so it can be used during release */\n \tdev->intr_handle.vfio_dev_fd = vfio_dev_fd;\n+\tdev->req_notifier_handler.vfio_dev_fd = vfio_dev_fd;\n \n \treturn 0;\n err_vfio_dev_fd:\n@@ -658,6 +751,8 @@ pci_vfio_unmap_resource_primary(struct rte_pci_device *dev)\n \tsnprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT,\n \t\t\tloc->domain, loc->bus, loc->devid, loc->function);\n \n+\tpci_vfio_disable_notifier(dev);\n+\n \tif (close(dev->intr_handle.fd) < 0) {\n \t\tRTE_LOG(INFO, EAL, \"Error when closing eventfd file descriptor for %s\\n\",\n \t\t\tpci_addr);\ndiff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c\nindex f313fe9..2a8e5e9 100644\n--- a/drivers/bus/pci/pci_common.c\n+++ b/drivers/bus/pci/pci_common.c\n@@ -446,6 +446,16 @@ pci_hot_unplug_handler(struct rte_device *dev)\n \t\treturn -1;\n \n \tswitch (pdev->kdrv) {\n+\tcase RTE_KDRV_VFIO:\n+\t\t/**\n+\t\t * vfio kernel module guaranty the pci device would not be\n+\t\t * deleted until the user space release the resource, so no\n+\t\t * need to remap BARs resource here, just directly notify\n+\t\t * the req event to the user space to handle it.\n+\t\t */\n+\t\trte_dev_event_callback_process(dev->name,\n+\t\t\t\t\t       RTE_DEV_EVENT_REMOVE);\n+\t\tbreak;\n \tcase RTE_KDRV_IGB_UIO:\n \tcase RTE_KDRV_UIO_GENERIC:\n \tcase RTE_KDRV_NIC_UIO:\n",
    "prefixes": [
        "v2",
        "4/4"
    ]
}