drivers: fix ASan ODR violation on glue symbols
Subsystems (2)
PATCH 1/2 drivers: fix ASan ODR violation on glue symbols
With ibverbs linked by dlopen, a static PMD and its glue library each define one global. net/mlx4 and librte_net_mlx4_glue both define mlx4_glue. common/mlx5 and librte_common_mlx5_glue both define mlx5_glue. This is not a clash between mlx4 and mlx5.
Only AddressSanitizer detects this collision. The linker keeps one copy, so a normal process is unaffected. AddressSanitizer records both definitions and aborts at startup.
Keep the name dlsym() looks up in the glue library. Point the PMD at that table through a private symbol.
--- drivers/common/mlx5/linux/meson.build | 2 +- drivers/common/mlx5/linux/mlx5_common_os.c | 4 ++-- drivers/common/mlx5/linux/mlx5_glue.h | 11 +++++++++++ drivers/net/mlx4/meson.build | 2 +- drivers/net/mlx4/mlx4.c | 2 +- drivers/net/mlx4/mlx4_glue.h | 11 +++++++++++ 6 files changed, 27 insertions(+), 5 deletions(-)
drivers/common/mlx5/linux/meson.build +1 -1
@@ -245,7 +245,7 @@ if dlopen_ibverbs dlopen_lib_name, dlopen_sources, include_directories: dlopen_includes, - c_args: cflags, + c_args: cflags + ['-DMLX5_GLUE_LIBRARY'], dependencies: libs, link_args: [ '-Wl,-export-dynamic',
drivers/common/mlx5/linux/mlx5_common_os.c +2 -2
@@ -28,8 +28,8 @@#include "mlx5_glue.h" #ifdef MLX5_GLUE -RTE_EXPORT_INTERNAL_SYMBOL (mlx5_glue) -const struct mlx5_glue *mlx5_glue; +RTE_EXPORT_INTERNAL_SYMBOL (mlx5_glue_handle) +const mlx5_glue_t *mlx5_glue;#endif RTE_EXPORT_INTERNAL_SYMBOL (mlx5_get_pci_addr)
drivers/common/mlx5/linux/mlx5_glue.h +11 -0
@@ -412,6 +412,17 @@ struct mlx5_glue { int (*destroy_steering_anchor)(struct mlx5dv_steering_anchor *sa); }; +#if defined(RTE_IBVERBS_LINK_DLOPEN ) && !defined(MLX5_GLUE_LIBRARY ) +/* +* The PMD keeps the address of the glue table in a private symbol. The glue +* library exports mlx5_glue for lookup with dlsym(). +*/ +typedef struct mlx5_glue mlx5_glue_t ; + +extern const mlx5_glue_t *mlx5_glue_handle; +#define mlx5_glue mlx5_glue_handle +#else extern const struct mlx5_glue *mlx5_glue; +#endif #endif /* MLX5_GLUE_H_ */
drivers/net/mlx4/meson.build +1 -1
@@ -125,7 +125,7 @@ if dlopen_ibverbs dlopen_lib_name, dlopen_sources, include_directories: global_inc, - c_args: cflags, + c_args: cflags + ['-DMLX4_GLUE_LIBRARY'], dependencies: libs, link_args: [ '-Wl,-export-dynamic',
drivers/net/mlx4/mlx4.c +1 -1
@@ -50,7 +50,7 @@#include "mlx4_utils.h" #ifdef MLX4_GLUE -const struct mlx4_glue *mlx4_glue; +const mlx4_glue_t *mlx4_glue;#endif static const char *MZ_MLX4_PMD_SHARED_DATA ="mlx4_pmd_shared_data" ;
drivers/net/mlx4/mlx4_glue.h +11 -0
@@ -83,6 +83,17 @@ struct mlx4_glue { void *attr); }; +#if defined(MLX4_GLUE ) && !defined(MLX4_GLUE_LIBRARY ) +/* +* The PMD keeps the address of the glue table in a private symbol. The glue +* library exports mlx4_glue for lookup with dlsym(). +*/ +typedef struct mlx4_glue mlx4_glue_t ; + +extern const mlx4_glue_t *mlx4_glue_handle; +#define mlx4_glue mlx4_glue_handle +#else extern const struct mlx4_glue *mlx4_glue; +#endif #endif /* MLX4_GLUE_H_ */
Signature · 1 line
2.25.1
PATCH 2/2 common/mlx5: fix errno clobber on interrupt FD clear
rte_intr_fd_set() can fail and replace rte_errno. Check the call when clearing an interrupt fd, and restore the error that caused handler creation to fail.
Coverity issue: 912881
Coverity issue: 912878
--- drivers/common/mlx5/linux/mlx5_common_os.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/common/mlx5/linux/mlx5_common_os.c +9 -2
@@ -1108,7 +1108,13 @@ mlx5_os_interrupt_handler_create(int mode, bool set_fd_nonblock, int fd, }return tmp_intr_handle; err: -rte_intr_fd_set (tmp_intr_handle,-1 ); +if (tmp_intr_handle !=NULL ) { +int saved_errno = rte_errno; + +if (rte_intr_fd_set (tmp_intr_handle,-1 ) !=0 ) +DRV_LOG (DEBUG ,"failed to reset interrupt fd" ); + rte_errno = saved_errno; + }rte_intr_instance_free (tmp_intr_handle);return NULL ; }
@@ -1185,7 +1191,8 @@ mlx5_os_interrupt_handler_destroy(struct rte_intr_handle *intr_handle,if (rte_intr_fd_get (intr_handle) >=0 ) {mlx5_intr_callback_unregister (intr_handle, cb, cb_arg);/* fd is not owned by the driver, only clear reference here. */ -rte_intr_fd_set (intr_handle,-1 ); +if (rte_intr_fd_set (intr_handle,-1 ) !=0 ) +DRV_LOG (DEBUG ,"failed to reset interrupt fd" ); }rte_intr_instance_free (intr_handle); }
Signature · 1 line
2.25.1
Re: [PATCH 2/2] common/mlx5: fix errno clobber on interrupt FD clear
Patch applied to next-net-mlx.
Thanks,
Raslan Darawsheh
Patch applied to next-net-mlx.
Thanks,
Raslan Darawsheh