http://bugs.dpdk.org/show_bug.cgi?id=1875
Bug ID: 1875
Summary: mlx5: pthread mutex in shared memory missing
PTHREAD_PROCESS_SHARED
Product: DPDK
Version: 25.11
Hardware: All
OS: All
Status: UNCONFIRMED
Severity: normal
Priority: Normal
Component: ethdev
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: ---
This is the mlx5 subset of bugzilla 662
The mlx5 specific analysis was:
## MLX5 Driver PTHREAD_PROCESS_SHARED Issue
### Summary
The mlx5 driver has pthread mutexes in shared memory that are initialized
without `PTHREAD_PROCESS_SHARED`, which causes undefined behavior when used
across multiple processes.
### Affected Mutexes
1. **`sh->txpp.mutex`** (`drivers/net/mlx5/mlx5.c`, line 1846)
- Location: `struct mlx5_dev_txpp` inside `struct mlx5_dev_ctx_shared`
- Purpose: Pacing create/destroy mutex for Tx packet pacing
2. **`sh->lwm_config_lock`** (`drivers/net/mlx5/mlx5.c`, line 1963)
- Location: `struct mlx5_dev_ctx_shared`
- Purpose: Low watermark configuration lock
### Why This Is a Problem
The `mlx5_dev_ctx_shared` structure is allocated via `mlx5_malloc(MLX5_MEM_ZERO
| MLX5_MEM_RTE, ...)` which uses hugepage-backed shared memory. This shared
context is accessible by both primary and secondary processes.
While the shared context is only **allocated** in the primary process (enforced
by assertion at line 1826), secondary processes can obtain a reference to this
shared context and potentially call operations that lock these mutexes.
Per POSIX, mutexes in shared memory accessed by multiple processes must be
initialized with `PTHREAD_PROCESS_SHARED` attribute. Without this,
synchronization between processes is undefined behavior.
### Note
A third mutex, `mlx5_dev_ctx_list_mutex` (line 201), is a static global
variable and is **not affected** since each process has its own copy.
### Suggested Fix
Initialize the mutexes with `PTHREAD_PROCESS_SHARED`:
```c
static void
mlx5_init_shared_mutex(pthread_mutex_t *mutex)
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
pthread_mutex_init(mutex, &attr);
pthread_mutexattr_destroy(&attr);
}
```
Then replace:
```c
pthread_mutex_init(&sh->txpp.mutex, NULL);
pthread_mutex_init(&priv->sh->lwm_config_lock, NULL);
```
With:
```c
mlx5_init_shared_mutex(&sh->txpp.mutex);
mlx5_init_shared_mutex(&priv->sh->lwm_config_lock);
```
--
You are receiving this mail because:
You are the assignee for the bug.