Skip to content

Commit

Permalink
common/mlx5: adjust fork call with new kernel API
Browse files Browse the repository at this point in the history
[ upstream commit 42f113c53cbbbc4585ad68b4d2a8aa9bddad23da ]

While doing process fork() the operating system remaps all the parent
process's memory to the address space of the child process and activates
the Copy-on-Write mechanics - it duplicates physical pages once memory
writing happens in the child process. Sometimes memory duplication is
not allowed - for example, if the page contains hardware queue
descriptors. To handle similar issues the rdma-core library should be
prepared for forking.

The ibv_fork_init() prepares the library to track all the related memory
and prevent it from forking using madvise() system API. This approach
allows fork, but not all the memory is forked to the child process and,
application should care not to touch pages where the parent application
allocated the rdma-core objects.

The newer kernels propose an option of copy-on-fork for DMA pages and
tracking all the memory and disabling it for the forking is no longer
needed. The new API routine ibv_is_fork_initialized() should be involved
to decide if library initialization for forking is required.

Fixes: 0e83b8e ("net/mlx5: move rdma-core calls to separate file")

Signed-off-by: Erez Ferber <erezf@nvidia.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
  • Loading branch information
Erez Ferber authored and kevintraynor committed Jul 12, 2023
1 parent be94ef9 commit 36b2f49
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/common/mlx5/linux/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ has_sym_args = [
'mlx5dv_dr_domain_allow_duplicate_rules' ],
[ 'HAVE_MLX5_IBV_REG_MR_IOVA', 'infiniband/verbs.h',
'ibv_reg_mr_iova' ],
[ 'HAVE_IBV_FORK_UNNEEDED', 'infiniband/verbs.h',
'ibv_is_fork_initialized'],
]
config = configuration_data()
foreach arg:has_sym_args
Expand Down
4 changes: 4 additions & 0 deletions drivers/common/mlx5/linux/mlx5_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
static int
mlx5_glue_fork_init(void)
{
#ifdef HAVE_IBV_FORK_UNNEEDED
if (ibv_is_fork_initialized() == IBV_FORK_UNNEEDED)
return 0; /* ibv_fork_init() not needed */
#endif
return ibv_fork_init();
}

Expand Down

0 comments on commit 36b2f49

Please sign in to comment.