mem: fix cleanup after incomplete initialization

Message ID 20210409171631.18219-1-dmitry.kozliuk@gmail.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series mem: fix cleanup after incomplete initialization |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/travis-robot success travis build: passed
ci/github-robot success github build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/intel-Testing success Testing PASS

Commit Message

Dmitry Kozlyuk April 9, 2021, 5:16 p.m. UTC
  In case of EAL initialization failure rte_eal_memory_detach() may be
called before mapping memory configuration, which in this case points
to the static structure. Attempt to unmap it yields error:

    EAL: Could not unmap shared memory config: Invalid argument

Skip unmapping memory configuration if it's not yet shared.

Fixes: dfbc61a2f9a6 ("mem: detach memsegs on cleanup")
Cc: Anatoly Burakov <anatoly.burakov@intel.com>

Reported-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_eal/common/eal_common_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Burakov, Anatoly April 20, 2021, 4:49 p.m. UTC | #1
On 09-Apr-21 6:16 PM, Dmitry Kozlyuk wrote:
> In case of EAL initialization failure rte_eal_memory_detach() may be
> called before mapping memory configuration, which in this case points
> to the static structure. Attempt to unmap it yields error:
> 
>      EAL: Could not unmap shared memory config: Invalid argument
> 
> Skip unmapping memory configuration if it's not yet shared.
> 
> Fixes: dfbc61a2f9a6 ("mem: detach memsegs on cleanup")
> Cc: Anatoly Burakov <anatoly.burakov@intel.com>
> 
> Reported-by: David Marchand <david.marchand@redhat.com>
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---

Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
  
Thomas Monjalon April 20, 2021, 9:34 p.m. UTC | #2
20/04/2021 18:49, Burakov, Anatoly:
> On 09-Apr-21 6:16 PM, Dmitry Kozlyuk wrote:
> > In case of EAL initialization failure rte_eal_memory_detach() may be
> > called before mapping memory configuration, which in this case points
> > to the static structure. Attempt to unmap it yields error:
> > 
> >      EAL: Could not unmap shared memory config: Invalid argument
> > 
> > Skip unmapping memory configuration if it's not yet shared.
> > 
> > Fixes: dfbc61a2f9a6 ("mem: detach memsegs on cleanup")
> > Cc: Anatoly Burakov <anatoly.burakov@intel.com>
> > 
> > Reported-by: David Marchand <david.marchand@redhat.com>
> > Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> 
> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c
index 2581dd5f58..f83b75092e 100644
--- a/lib/librte_eal/common/eal_common_memory.c
+++ b/lib/librte_eal/common/eal_common_memory.c
@@ -1055,7 +1055,7 @@  rte_eal_memory_detach(void)
 	 * config - we can't zero it out because it might still be referenced
 	 * by other processes.
 	 */
-	if (internal_conf->no_shconf == 0) {
+	if (internal_conf->no_shconf == 0 && mcfg->mem_cfg_addr != 0) {
 		if (rte_mem_unmap(mcfg, RTE_ALIGN(sizeof(*mcfg), page_sz)) != 0)
 			RTE_LOG(ERR, EAL, "Could not unmap shared memory config: %s\n",
 					rte_strerror(rte_errno));