summaryrefslogtreecommitdiff
path: root/lib/librte_eal/common/eal_common_bus.c
diff options
context:
space:
mode:
authorJeff Guo <jia.guo@intel.com>2018-10-15 19:27:25 +0800
committerThomas Monjalon <thomas@monjalon.net>2018-10-15 22:17:35 +0200
commit62e63653baf5fb20315c887bb3d21bebd0259e73 (patch)
tree7f7d8c3fe7058d741070e19c27aa2845a5bcb445 /lib/librte_eal/common/eal_common_bus.c
parent5c96a299340fcb67a86217de656bbe63ba7ce15e (diff)
downloaddpdk-62e63653baf5fb20315c887bb3d21bebd0259e73.zip
dpdk-62e63653baf5fb20315c887bb3d21bebd0259e73.tar.gz
dpdk-62e63653baf5fb20315c887bb3d21bebd0259e73.tar.xz
bus: add helper to handle sigbus
This patch aims to add a helper to iterate over all buses to find the relevant bus to handle the sigbus error. Signed-off-by: Jeff Guo <jia.guo@intel.com> Acked-by: Shaopeng He <shaopeng.he@intel.com> Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
Diffstat (limited to 'lib/librte_eal/common/eal_common_bus.c')
-rw-r--r--lib/librte_eal/common/eal_common_bus.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index 0943851..62b7318 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -37,6 +37,7 @@
#include <rte_bus.h>
#include <rte_debug.h>
#include <rte_string_fns.h>
+#include <rte_errno.h>
#include "eal_private.h"
@@ -242,3 +243,45 @@ rte_bus_get_iommu_class(void)
}
return mode;
}
+
+static int
+bus_handle_sigbus(const struct rte_bus *bus,
+ const void *failure_addr)
+{
+ int ret;
+
+ if (!bus->sigbus_handler)
+ return -1;
+
+ ret = bus->sigbus_handler(failure_addr);
+
+ /* find bus but handle failed, keep the errno be set. */
+ if (ret < 0 && rte_errno == 0)
+ rte_errno = ENOTSUP;
+
+ return ret > 0;
+}
+
+int
+rte_bus_sigbus_handler(const void *failure_addr)
+{
+ struct rte_bus *bus;
+
+ int ret = 0;
+ int old_errno = rte_errno;
+
+ rte_errno = 0;
+
+ bus = rte_bus_find(NULL, bus_handle_sigbus, failure_addr);
+ /* can not find bus. */
+ if (!bus)
+ return 1;
+ /* find bus but handle failed, pass on the new errno. */
+ else if (rte_errno != 0)
+ return -1;
+
+ /* restore the old errno. */
+ rte_errno = old_errno;
+
+ return ret;
+}