Skip to contentSkip to conversation

enic: pthread mutex in shared memory missing PTHREAD_PROCESS_SHARED (

DPDK/ethdev Bug 1876 [email protected] 1 participant 1 message Jan 30

lore
Share & tools
lore
#0 lore raw

http://bugs.dpdk.org/show_bug.cgi?id=1876

            Bug ID: 1876
           Summary: enic: 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 the enic driver portion of existing bug 662

The enic driver has a pthread mutex in shared memory that is initialized without PTHREAD_PROCESS_SHARED, which causes undefined behavior when used across multiple processes.

### Affected Mutex

1. **enic->admin_chan_lock** (drivers/net/enic/enic_sriov.c, line 352)
- Location: struct enic (device private data)
- Purpose: Protects SR-IOV admin channel operations between VF and PF

### Why This Is a Problem

The struct enic is the device private data accessed via eth_dev->data->dev_private, which resides in shared memory accessible by both primary and secondary processes.

The mutex is initialized in enic_enable_vf_admin_chan():

```c
pthread_mutex_init(&enic->admin_chan_lock, NULL);
```

And used to protect admin channel operations:

```c
static void lock_admin_chan(struct enic *enic)
{
    pthread_mutex_lock(&enic->admin_chan_lock);
}

static void unlock_admin_chan(struct enic *enic)
{
    pthread_mutex_unlock(&enic->admin_chan_lock);
}
```

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.

### Suggested Fix

Initialize the mutex with PTHREAD_PROCESS_SHARED:

```c
static void
enic_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(&enic->admin_chan_lock, NULL);
```

With:

```c
enic_init_shared_mutex(&enic->admin_chan_lock);
```
Signature · 2 lines
You are receiving this mail because:
You are the assignee for the bug.