From 289d8dd6dbe4edb0949829e2c9a8895b5ae660a8 Mon Sep 17 00:00:00 2001 From: Harry van Haaren Date: Wed, 9 Mar 2016 13:37:24 +0000 Subject: [PATCH] eal: fix race condition in multi-process startup This patch fixes a race-condition when a primary and secondary process simultaneously probe PCI devices. This is implemented by moving the rte_eal_mcfg_complete() function call in rte_eal_init() until after rte_eal_pci_probe(). The memory mapping of PCI device in the secondary process *must* happen after the primary has finished doing the mapping as it relies on information written by the primary. The end result is that the secondary process waits longer, until the primary has completed its PCI probing, and then notifies the secondary process. This race-condition became visible during the development of a function that allows a secondary process to be polling until a primary process exists. The secondary would then probe PCI devices at the same time, causing an error during rte_eal_init() Linux EAL: Fixes: 916e4f4f4e45 ("memory: fix for multi process support") BSD EAL: Fixes: 764bf26873b9 ("add FreeBSD support") Signed-off-by: Harry van Haaren Acked-by: Sergio Gonzalez Monroy --- lib/librte_eal/bsdapp/eal/eal.c | 6 +++--- lib/librte_eal/linuxapp/eal/eal.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index a34e61d6db..06bfd4e0a1 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. + * Copyright(c) 2010-2016 Intel Corporation. All rights reserved. * Copyright(c) 2014 6WIND S.A. * All rights reserved. * @@ -569,8 +569,6 @@ rte_eal_init(int argc, char **argv) eal_check_mem_on_local_socket(); - rte_eal_mcfg_complete(); - if (eal_plugins_init() < 0) rte_panic("Cannot init plugins\n"); @@ -621,6 +619,8 @@ rte_eal_init(int argc, char **argv) if (rte_eal_pci_probe()) rte_panic("Cannot probe PCI\n"); + rte_eal_mcfg_complete(); + return fctret; } diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index ceac435490..364f303cdc 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. + * Copyright(c) 2010-2016 Intel Corporation. All rights reserved. * Copyright(c) 2012-2014 6WIND S.A. * All rights reserved. * @@ -821,8 +821,6 @@ rte_eal_init(int argc, char **argv) eal_check_mem_on_local_socket(); - rte_eal_mcfg_complete(); - if (eal_plugins_init() < 0) rte_panic("Cannot init plugins\n"); @@ -880,6 +878,8 @@ rte_eal_init(int argc, char **argv) if (rte_eal_pci_probe()) rte_panic("Cannot probe PCI\n"); + rte_eal_mcfg_complete(); + return fctret; } -- 2.20.1