The failsafe driver supports secondary process attachment via
rte_eth_dev_attach_secondary() in rte_pmd_failsafe_probe(). The
hotplug_mutex in fs_priv protects shared state but is initialized
without PTHREAD_PROCESS_SHARED attribute.

POSIX mutexes are by default private to the process creating them.
When a mutex protects data structures accessed by multiple processes,
pthread_mutexattr_setpshared() must be called with PTHREAD_PROCESS_SHARED.

Also add missing pthread_mutexattr_destroy() call to avoid resource leak.

Bugzilla ID: 662
Fixes: 655fcd68c7d2 ("net/failsafe: fix hotplug races")
Cc: [email protected]

Signed-off-by: Stephen Hemminger <[email protected]>
---
 drivers/net/failsafe/failsafe.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/net/failsafe/failsafe.c b/drivers/net/failsafe/failsafe.c
index 3e590d38f7..aa3fe53b22 100644
--- a/drivers/net/failsafe/failsafe.c
+++ b/drivers/net/failsafe/failsafe.c
@@ -144,11 +144,20 @@ fs_mutex_init(struct fs_priv *priv)
        /* Allow mutex relocks for the thread holding the mutex. */
        ret = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
        if (ret) {
-               ERROR("Cannot set mutex type - %s", strerror(ret));
-               return ret;
+               ERROR("Cannot set mutex recursive - %s", strerror(ret));
+               goto out;
+       }
+       /* Allow mutex to be shared between processes. */
+       ret = pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
+       if (ret) {
+               ERROR("Cannot set mutex pshared - %s", strerror(ret));
+               goto out;
        }
+       pthread_mutex_init(&priv->hotplug_mutex, &attr);
 
-       return pthread_mutex_init(&priv->hotplug_mutex, &attr);
+out:
+       pthread_mutexattr_destroy(&attr);
+       return ret;
 }
 
 static int
-- 
2.51.0

Reply via email to