[V4,5/9] bus: add helper to handle sigbus
Checks
Commit Message
This patch aim to add a helper to iterate all buses to find the
corresponding bus to handle the sigbus error.
Signed-off-by: Jeff Guo <jia.guo@intel.com>
---
v4->v3:
split patches to be small and clear.
---
lib/librte_eal/common/eal_common_bus.c | 34 +++++++++++++++++++++++++++++++++-
lib/librte_eal/common/eal_private.h | 11 +++++++++++
2 files changed, 44 insertions(+), 1 deletion(-)
@@ -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"
@@ -220,7 +221,6 @@ rte_bus_find_by_device_name(const char *str)
return rte_bus_find(NULL, bus_can_parse, name);
}
-
/*
* Get iommu class of devices on the bus.
*/
@@ -242,3 +242,35 @@ rte_bus_get_iommu_class(void)
}
return mode;
}
+
+static int
+bus_handle_sigbus(const struct rte_bus *bus,
+ const void *failure_addr)
+{
+ return !(bus->sigbus_handler && bus->sigbus_handler(failure_addr) <= 0);
+}
+
+int
+rte_bus_sigbus_handler(const void *failure_addr)
+{
+ struct rte_bus *bus;
+ int old_errno = rte_errno;
+ int ret = 0;
+
+ rte_errno = 0;
+
+ bus = rte_bus_find(NULL, bus_handle_sigbus, failure_addr);
+ if (bus == NULL) {
+ RTE_LOG(ERR, EAL, "No bus can handle the sigbus error!");
+ ret = -1;
+ } else if (rte_errno != 0) {
+ RTE_LOG(ERR, EAL, "Failed to handle the sigbus error!");
+ ret = -1;
+ }
+
+ /* if sigbus not be handled, return back old errno. */
+ if (ret)
+ rte_errno = old_errno;
+
+ return ret;
+}
@@ -258,4 +258,15 @@ int rte_mp_channel_init(void);
*/
void dev_callback_process(char *device_name, enum rte_dev_event_type event);
+
+/**
+ * Iterate all buses to find the corresponding bus, to handle the sigbus error.
+ * @param failure_addr
+ * Pointer of the fault address of the sigbus error.
+ *
+ * @return
+ * 0 on success.
+ * -1 on error
+ */
+int rte_bus_sigbus_handler(const void *failure_addr);
#endif /* _EAL_PRIVATE_H_ */