get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 43768,
    "url": "http://patches.dpdk.org/api/patches/43768/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/1534502916-31636-8-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": "<1534502916-31636-8-git-send-email-jia.guo@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1534502916-31636-8-git-send-email-jia.guo@intel.com",
    "date": "2018-08-17T10:48:34",
    "name": "[v10,6/8] eal: add failure handle mechanism for hotplug",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "afe9f73eb09e6a78da1355c7e280b2f1af4ba247",
    "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/1534502916-31636-8-git-send-email-jia.guo@intel.com/mbox/",
    "series": [
        {
            "id": 1007,
            "url": "http://patches.dpdk.org/api/series/1007/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=1007",
            "date": "2018-08-17T10:48:27",
            "name": "hotplug failure handle mechanism",
            "version": 10,
            "mbox": "http://patches.dpdk.org/series/1007/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/43768/comments/",
    "check": "warning",
    "checks": "http://patches.dpdk.org/api/patches/43768/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 CF2A74C57;\n\tFri, 17 Aug 2018 12:51:42 +0200 (CEST)",
            "from mga14.intel.com (mga14.intel.com [192.55.52.115])\n\tby dpdk.org (Postfix) with ESMTP id B39BE4CBB\n\tfor <dev@dpdk.org>; Fri, 17 Aug 2018 12:51:40 +0200 (CEST)",
            "from fmsmga007.fm.intel.com ([10.253.24.52])\n\tby fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t17 Aug 2018 03:51:40 -0700",
            "from jeffguo-z170x-ud5.sh.intel.com (HELO localhost.localdomain)\n\t([10.67.104.10])\n\tby fmsmga007.fm.intel.com with ESMTP; 17 Aug 2018 03:51:37 -0700"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.53,250,1531810800\"; d=\"scan'208\";a=\"63131875\"",
        "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, wenzhuo.lu@intel.com",
        "Cc": "jblunck@infradead.org, shreyansh.jain@nxp.com, dev@dpdk.org,\n\tjia.guo@intel.com, helin.zhang@intel.com",
        "Date": "Fri, 17 Aug 2018 18:48:34 +0800",
        "Message-Id": "<1534502916-31636-8-git-send-email-jia.guo@intel.com>",
        "X-Mailer": "git-send-email 2.7.4",
        "In-Reply-To": "<1534502916-31636-1-git-send-email-jia.guo@intel.com>",
        "References": "<1498711073-42917-1-git-send-email-jia.guo@intel.com>\n\t<1534502916-31636-1-git-send-email-jia.guo@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v10 6/8] eal: add failure handle mechanism for\n\thotplug",
        "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": "The mechanism can initially register the sigbus handler after the device\nevent monitor is enabled. When a sigbus error is captured, the mechanism\nwill check the failure address and accordingly remap the invalid memory\nfor the corresponding device. It could prevent the application from\ncrashing when a device is hotplugged out.\n\nBy this patch, users could call below new added APIs to enable/disable\nthe device failure handle mechanism:\n  - rte_dev_hotplug_handle_enable\n  - rte_dev_hotplug_handle_disable\n\nSigned-off-by: Jeff Guo <jia.guo@intel.com>\n---\nv10->v9:\nadd new APIs to enable/disable hotplug handling\n---\n doc/guides/rel_notes/release_18_08.rst  |   5 +\n lib/librte_eal/bsdapp/eal/eal_dev.c     |  14 +++\n lib/librte_eal/common/eal_private.h     |  26 ++++++\n lib/librte_eal/common/include/rte_dev.h |  26 ++++++\n lib/librte_eal/linuxapp/eal/eal_dev.c   | 159 +++++++++++++++++++++++++++++++-\n lib/librte_eal/rte_eal_version.map      |   2 +\n 6 files changed, 231 insertions(+), 1 deletion(-)",
    "diff": "diff --git a/doc/guides/rel_notes/release_18_08.rst b/doc/guides/rel_notes/release_18_08.rst\nindex 321fa84..95dc1e0 100644\n--- a/doc/guides/rel_notes/release_18_08.rst\n+++ b/doc/guides/rel_notes/release_18_08.rst\n@@ -117,6 +117,11 @@ New Features\n \n   Added support for chained mbufs (input and output).\n \n+* **Added failure handle mechanism for hotplug.**\n+\n+  ``rte_dev_hotplug_handle_enable`` and ``rte_dev_hotplug_handle_disable`` are\n+  for enable or disable failure handle mechanism for hotplug.\n+\n \n API Changes\n -----------\ndiff --git a/lib/librte_eal/bsdapp/eal/eal_dev.c b/lib/librte_eal/bsdapp/eal/eal_dev.c\nindex 1c6c51b..ae1c558 100644\n--- a/lib/librte_eal/bsdapp/eal/eal_dev.c\n+++ b/lib/librte_eal/bsdapp/eal/eal_dev.c\n@@ -19,3 +19,17 @@ rte_dev_event_monitor_stop(void)\n \tRTE_LOG(ERR, EAL, \"Device event is not supported for FreeBSD\\n\");\n \treturn -1;\n }\n+\n+int\n+rte_dev_hotplug_handle_enable(void)\n+{\n+\tRTE_LOG(ERR, EAL, \"Device event is not supported for FreeBSD\\n\");\n+\treturn -1;\n+}\n+\n+int\n+rte_dev_hotplug_handle_disable(void)\n+{\n+\tRTE_LOG(ERR, EAL, \"Device event is not supported for FreeBSD\\n\");\n+\treturn -1;\n+}\ndiff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h\nindex 168430e..3cf0357 100644\n--- a/lib/librte_eal/common/eal_private.h\n+++ b/lib/librte_eal/common/eal_private.h\n@@ -316,4 +316,30 @@ rte_devargs_layers_parse(struct rte_devargs *devargs,\n  */\n int rte_bus_sigbus_handler(const void *failure_addr);\n \n+/**\n+ * @warning\n+ * @b EXPERIMENTAL: this API may change without prior notice\n+ *\n+ * Register the sigbus hander.\n+ *\n+ * @return\n+ *   - On success, zero.\n+ *   - On failure, a negative value.\n+ */\n+int\n+rte_dev_sigbus_handler_register(void);\n+\n+/**\n+ * @warning\n+ * @b EXPERIMENTAL: this API may change without prior notice\n+ *\n+ * Unregister the sigbus hander.\n+ *\n+ * @return\n+ *   - On success, zero.\n+ *   - On failure, a negative value.\n+ */\n+int\n+rte_dev_sigbus_handler_unregister(void);\n+\n #endif /* _EAL_PRIVATE_H_ */\ndiff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h\nindex b80a805..ff580a0 100644\n--- a/lib/librte_eal/common/include/rte_dev.h\n+++ b/lib/librte_eal/common/include/rte_dev.h\n@@ -460,4 +460,30 @@ rte_dev_event_monitor_start(void);\n int __rte_experimental\n rte_dev_event_monitor_stop(void);\n \n+/**\n+ * @warning\n+ * @b EXPERIMENTAL: this API may change without prior notice\n+ *\n+ * Enable hotplug handling for devices.\n+ *\n+ * @return\n+ *   - On success, zero.\n+ *   - On failure, a negative value.\n+ */\n+int __rte_experimental\n+rte_dev_hotplug_handle_enable(void);\n+\n+/**\n+ * @warning\n+ * @b EXPERIMENTAL: this API may change without prior notice\n+ *\n+ * Disable hotplug handling for devices.\n+ *\n+ * @return\n+ *   - On success, zero.\n+ *   - On failure, a negative value.\n+ */\n+int __rte_experimental\n+rte_dev_hotplug_handle_disable(void);\n+\n #endif /* _RTE_DEV_H_ */\ndiff --git a/lib/librte_eal/linuxapp/eal/eal_dev.c b/lib/librte_eal/linuxapp/eal/eal_dev.c\nindex 1cf6aeb..fa5cb9b 100644\n--- a/lib/librte_eal/linuxapp/eal/eal_dev.c\n+++ b/lib/librte_eal/linuxapp/eal/eal_dev.c\n@@ -4,6 +4,8 @@\n \n #include <string.h>\n #include <unistd.h>\n+#include <fcntl.h>\n+#include <signal.h>\n #include <sys/socket.h>\n #include <linux/netlink.h>\n \n@@ -14,15 +16,31 @@\n #include <rte_malloc.h>\n #include <rte_interrupts.h>\n #include <rte_alarm.h>\n+#include <rte_bus.h>\n+#include <rte_eal.h>\n+#include <rte_spinlock.h>\n+#include <rte_errno.h>\n \n #include \"eal_private.h\"\n \n static struct rte_intr_handle intr_handle = {.fd = -1 };\n static bool monitor_started;\n+static bool hotplug_handle;\n \n #define EAL_UEV_MSG_LEN 4096\n #define EAL_UEV_MSG_ELEM_LEN 128\n \n+/*\n+ * spinlock for device failure handle, if try to access bus or device,\n+ * such as handle sigbus on bus or handle memory failure for device just use\n+ * this lock. It could protect the bus and the device to avoid race condition.\n+ */\n+static rte_spinlock_t failure_handle_lock = RTE_SPINLOCK_INITIALIZER;\n+\n+static struct sigaction sigbus_action_old;\n+\n+static int sigbus_need_recover;\n+\n static void dev_uev_handler(__rte_unused void *param);\n \n /* identify the system layer which reports this event. */\n@@ -33,6 +51,49 @@ enum eal_dev_event_subsystem {\n \tEAL_DEV_EVENT_SUBSYSTEM_MAX\n };\n \n+static void\n+sigbus_action_recover(void)\n+{\n+\tif (sigbus_need_recover) {\n+\t\tsigaction(SIGBUS, &sigbus_action_old, NULL);\n+\t\tsigbus_need_recover = 0;\n+\t}\n+}\n+\n+static void sigbus_handler(int signum, siginfo_t *info,\n+\t\t\t\tvoid *ctx __rte_unused)\n+{\n+\tint ret;\n+\n+\tRTE_LOG(INFO, EAL, \"Thread[%d] catch SIGBUS, fault address:%p\\n\",\n+\t\t(int)pthread_self(), info->si_addr);\n+\n+\trte_spinlock_lock(&failure_handle_lock);\n+\tret = rte_bus_sigbus_handler(info->si_addr);\n+\trte_spinlock_unlock(&failure_handle_lock);\n+\tif (ret == -1) {\n+\t\trte_exit(EXIT_FAILURE,\n+\t\t\t \"Failed to handle SIGBUS for hotplug, \"\n+\t\t\t \"(rte_errno: %s)!\", strerror(rte_errno));\n+\t} else if (ret == 1) {\n+\t\tif (sigbus_action_old.sa_handler)\n+\t\t\t(*(sigbus_action_old.sa_handler))(signum);\n+\t\telse\n+\t\t\trte_exit(EXIT_FAILURE,\n+\t\t\t\t \"Failed to handle generic SIGBUS!\");\n+\t}\n+\n+\tRTE_LOG(INFO, EAL, \"Success to handle SIGBUS for hotplug!\\n\");\n+}\n+\n+static int cmp_dev_name(const struct rte_device *dev,\n+\tconst void *_name)\n+{\n+\tconst char *name = _name;\n+\n+\treturn strcmp(dev->name, name);\n+}\n+\n static int\n dev_uev_socket_fd_create(void)\n {\n@@ -147,6 +208,9 @@ dev_uev_handler(__rte_unused void *param)\n \tstruct rte_dev_event uevent;\n \tint ret;\n \tchar buf[EAL_UEV_MSG_LEN];\n+\tstruct rte_bus *bus;\n+\tstruct rte_device *dev;\n+\tconst char *busname = \"\";\n \n \tmemset(&uevent, 0, sizeof(struct rte_dev_event));\n \tmemset(buf, 0, EAL_UEV_MSG_LEN);\n@@ -171,8 +235,43 @@ dev_uev_handler(__rte_unused void *param)\n \tRTE_LOG(DEBUG, EAL, \"receive uevent(name:%s, type:%d, subsystem:%d)\\n\",\n \t\tuevent.devname, uevent.type, uevent.subsystem);\n \n-\tif (uevent.devname)\n+\tswitch (uevent.subsystem) {\n+\tcase EAL_DEV_EVENT_SUBSYSTEM_PCI:\n+\tcase EAL_DEV_EVENT_SUBSYSTEM_UIO:\n+\t\tbusname = \"pci\";\n+\t\tbreak;\n+\tdefault:\n+\t\tbreak;\n+\t}\n+\n+\tif (uevent.devname) {\n+\t\tif (uevent.type == RTE_DEV_EVENT_REMOVE && hotplug_handle) {\n+\t\t\trte_spinlock_lock(&failure_handle_lock);\n+\t\t\tbus = rte_bus_find_by_name(busname);\n+\t\t\tif (bus == NULL) {\n+\t\t\t\tRTE_LOG(ERR, EAL, \"Cannot find bus (%s)\\n\",\n+\t\t\t\t\tbusname);\n+\t\t\t\treturn;\n+\t\t\t}\n+\n+\t\t\tdev = bus->find_device(NULL, cmp_dev_name,\n+\t\t\t\t\t       uevent.devname);\n+\t\t\tif (dev == NULL) {\n+\t\t\t\tRTE_LOG(ERR, EAL, \"Cannot find device (%s) on \"\n+\t\t\t\t\t\"bus (%s)\\n\", uevent.devname, busname);\n+\t\t\t\treturn;\n+\t\t\t}\n+\n+\t\t\tret = bus->memory_failure_handler(dev);\n+\t\t\trte_spinlock_unlock(&failure_handle_lock);\n+\t\t\tif (ret) {\n+\t\t\t\tRTE_LOG(ERR, EAL, \"Can not handle hotplug for \"\n+\t\t\t\t\t\"device (%s)\\n\", dev->name);\n+\t\t\t\treturn;\n+\t\t\t}\n+\t\t}\n \t\tdev_callback_process(uevent.devname, uevent.type);\n+\t}\n }\n \n int __rte_experimental\n@@ -220,5 +319,63 @@ rte_dev_event_monitor_stop(void)\n \tclose(intr_handle.fd);\n \tintr_handle.fd = -1;\n \tmonitor_started = false;\n+\n \treturn 0;\n }\n+\n+int\n+rte_dev_sigbus_handler_register(void)\n+{\n+\tsigset_t mask;\n+\tstruct sigaction action;\n+\n+\trte_errno = 0;\n+\n+\tsigemptyset(&mask);\n+\tsigaddset(&mask, SIGBUS);\n+\taction.sa_flags = SA_SIGINFO;\n+\taction.sa_mask = mask;\n+\taction.sa_sigaction = sigbus_handler;\n+\tsigbus_need_recover = !sigaction(SIGBUS, &action, &sigbus_action_old);\n+\n+\treturn rte_errno;\n+}\n+\n+int\n+rte_dev_sigbus_handler_unregister(void)\n+{\n+\trte_errno = 0;\n+\tsigbus_need_recover = 1;\n+\n+\tsigbus_action_recover();\n+\n+\treturn rte_errno;\n+}\n+\n+int\n+rte_dev_hotplug_handle_enable(void)\n+{\n+\tint ret = 0;\n+\n+\tret = rte_dev_sigbus_handler_register();\n+\tif (ret < 0)\n+\t\tRTE_LOG(ERR, EAL, \"fail to register sigbus handler for devices.\\n\");\n+\n+\thotplug_handle = true;\n+\n+\treturn ret;\n+}\n+\n+int\n+rte_dev_hotplug_handle_disable(void)\n+{\n+\tint ret = 0;\n+\n+\tret = rte_dev_sigbus_handler_unregister();\n+\tif (ret < 0)\n+\t\tRTE_LOG(ERR, EAL, \"fail to unregister sigbus handler for devices.\\n\");\n+\n+\thotplug_handle = false;\n+\n+\treturn ret;\n+}\ndiff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map\nindex 344a43d..996e709 100644\n--- a/lib/librte_eal/rte_eal_version.map\n+++ b/lib/librte_eal/rte_eal_version.map\n@@ -274,6 +274,8 @@ EXPERIMENTAL {\n \trte_dev_event_callback_unregister;\n \trte_dev_event_monitor_start;\n \trte_dev_event_monitor_stop;\n+\trte_dev_hotplug_handle_enable;\n+\trte_dev_hotplug_handle_disable;\n \trte_dev_iterator_init;\n \trte_dev_iterator_next;\n \trte_devargs_add;\n",
    "prefixes": [
        "v10",
        "6/8"
    ]
}