Skip to content

Commit

Permalink
ipc: stop mp control thread on cleanup
Browse files Browse the repository at this point in the history
[ upstream commit e788528 ]

When calling rte_eal_cleanup, the mp channel cleanup routine only sets
mp_fd to -1 leaving the rte_mp_handle control thread running.
This control thread can spew warnings on reading on an invalid fd.
This is especially noticed with ASAN enabled.

To handle this situation, set mp_fd to -1 to signal the control thread
it should exit, but since this thread might be sleeping on the socket,
cancel the thread too.

Fixes: 85d6815 ("eal: close multi-process socket during cleanup")

Reported-by: Owen Hilyard <ohilyard@iol.unh.edu>
Signed-off-by: David Marchand <david.marchand@redhat.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
  • Loading branch information
david-marchand authored and cpaelzer committed Aug 9, 2021
1 parent 538280b commit b39b348
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/librte_eal/common/eal_common_proc.c
Expand Up @@ -34,6 +34,7 @@
#include "eal_internal_cfg.h"

static int mp_fd = -1;
static pthread_t mp_handle_tid;
static char mp_filter[PATH_MAX]; /* Filter for secondary process sockets */
static char mp_dir_path[PATH_MAX]; /* The directory path for all mp sockets */
static pthread_mutex_t mp_mutex_action = PTHREAD_MUTEX_INITIALIZER;
Expand Down Expand Up @@ -376,7 +377,7 @@ mp_handle(void *arg __rte_unused)
struct mp_msg_internal msg;
struct sockaddr_un sa;

while (1) {
while (mp_fd >= 0) {
if (read_msg(&msg, &sa) == 0)
process_msg(&msg, &sa);
}
Expand Down Expand Up @@ -560,14 +561,11 @@ open_socket_fd(void)
}

static void
close_socket_fd(void)
close_socket_fd(int fd)
{
char path[PATH_MAX];

if (mp_fd < 0)
return;

close(mp_fd);
close(fd);
create_socket_path(peer_name, path, sizeof(path));
unlink(path);
}
Expand All @@ -577,7 +575,6 @@ rte_mp_channel_init(void)
{
char path[PATH_MAX];
int dir_fd;
pthread_t mp_handle_tid;

/* in no shared files mode, we do not have secondary processes support,
* so no need to initialize IPC.
Expand Down Expand Up @@ -636,7 +633,16 @@ rte_mp_channel_init(void)
void
rte_mp_channel_cleanup(void)
{
close_socket_fd();
int fd;

if (mp_fd < 0)
return;

fd = mp_fd;
mp_fd = -1;
pthread_cancel(mp_handle_tid);
pthread_join(mp_handle_tid, NULL);
close_socket_fd(fd);
}

/**
Expand Down

0 comments on commit b39b348

Please sign in to comment.