Fix unused memseg length for memory issue
PATCH 1/1 Fix unused memseg length for memory issue
Fix the issue where OS memory is mistakenly freed with rte_free by setting the length (len) of unused memseg to 0.
When eal_legacy_hugepage_init releases the VA space for unused memseg lists, it does not reset their length to 0. As a result, mlx5_mem_is_rte may incorrectly identify OS memory as DPDK memory. This can lead to mlx_free calling rte_free on OS memory, causing an "EAL: Error: Invalid memory" log and failing to free the OS memory.
This issue is occasional and occurs when the DPDK program’s memory map places the heap address range between 0 and len(32G). In such cases, malloc may return an address less than len, causing mlx5_mem_is_rte to incorrectly treat it as DPDK memory.
--- lib/eal/linux/eal_memory.c | 1 + 1 file changed, 1 insertion(+)
lib/eal/linux/eal_memory.c +1 -0
@@ -1472,6 +1472,7 @@ eal_legacy_hugepage_init(void) mem_sz = msl->len;munmap (msl->base_va, mem_sz); msl->base_va =NULL ; + msl->len =0 ; msl->heap =0 ;/* destroy backing fbarray */
Signature · 1 line
2.34.1
2024-12-26 16:10 (UTC+0800), Yang Ming:
Quoted 29 lines
Fix the issue where OS memory is mistakenly freed with
rte_freeby setting the length (len) of unused memseg to 0.When
eal_legacy_hugepage_initreleases the VA space for unused memseg lists, it does not reset their length to 0. As a result,mlx5_mem_is_rtemay incorrectly identify OS memory as DPDK memory. This can lead tomlx_freecallingrte_freeon OS memory, causing an "EAL: Error: Invalid memory" log and failing to free the OS memory.This issue is occasional and occurs when the DPDK program’s memory map places the heap address range between 0 and len(32G). In such cases, malloc may return an address less than len, causing
mlx5_mem_is_rteto incorrectly treat it as DPDK memory.Fixes 66cc45e293ed ("mem: replace memseg with memseg lists")Signed-off-by Yang Ming <[email protected]>--- lib/eal/linux/eal_memory.c | 1 + 1 file changed, 1 insertion(+)lib/eal/linux/eal_memory.c +0
-0
lib/eal/linux/eal_memory.c eal_legacy_hugepage_init(void) · line 1478
Quoted 7 lines
lib/eal/linux/eal_memory.c +1
-0@@ -1472,6 +1472,7 @@ eal_legacy_hugepage_init(void) mem_sz = msl->len;munmap (msl->base_va, mem_sz); msl->base_va =NULL ; + msl->len =0 ; msl->heap =0 ;/* destroy backing fbarray */
Hi Yang,
It seems the bug affects more than just mlx5 PMD.
Consider how the MSL with base_va == NULL ends up in mlx5_mem_is_rte(). It comes from rte_mem_virt2memseg_list() which iterates MSLs and checks that an address belongs to [base_va; base_va+len) without checking whether base_va == NULL i.e. that the MSL is inactive. Your patch also corrects rte_mem_virt2memseg_list() behavior. Please mention this in the commit message.
Quoted 41 lines · Dmitry Kozlyuk
2024-12-26 16:10 (UTC+0800), Yang Ming:
Quoted 29 lines
Fix the issue where OS memory is mistakenly freed with
rte_freeby setting the length (len) of unused memseg to 0.When
eal_legacy_hugepage_initreleases the VA space for unused memseg lists, it does not reset their length to 0. As a result,mlx5_mem_is_rtemay incorrectly identify OS memory as DPDK memory. This can lead tomlx_freecallingrte_freeon OS memory, causing an "EAL: Error: Invalid memory" log and failing to free the OS memory.This issue is occasional and occurs when the DPDK program’s memory map places the heap address range between 0 and len(32G). In such cases, malloc may return an address less than len, causing
mlx5_mem_is_rteto incorrectly treat it as DPDK memory.Fixes 66cc45e293ed ("mem: replace memseg with memseg lists")Signed-off-by Yang Ming<[email protected]>--- lib/eal/linux/eal_memory.c | 1 + 1 file changed, 1 insertion(+)lib/eal/linux/eal_memory.c +0
-0lib/eal/linux/eal_memory.c eal_legacy_hugepage_init(void) · line 1478
Quoted 7 lines
lib/eal/linux/eal_memory.c +1
-0@@ -1472,6 +1472,7 @@ eal_legacy_hugepage_init(void) mem_sz = msl->len;munmap (msl->base_va, mem_sz); msl->base_va =NULL ; + msl->len =0 ; msl->heap =0 ;/* destroy backing fbarray */ Hi Yang,
It seems the bug affects more than just mlx5 PMD.
Quoted 8 lines
Consider how the MSL with
base_va == NULLends up inmlx5_mem_is_rte(). It comes fromrte_mem_virt2memseg_list()which iterates MSLs and checks that an address belongs to [base_va;base_va+len) without checking whetherbase_va == NULLi.e. that the MSL is inactive. Your patch also correctsrte_mem_virt2memseg_list()behavior. Please mention this in the commit message.Acked-by Dmitry Kozlyuk<[email protected]>
Hi Dmitry,
Thanks. I will update this patch within new version (v2) to add these content to the commit log.
PATCH v2 1/1 eal: fix unused memseg length
In reply to Yang MingFix the issue where OS memory is mistakenly freed with rte_free by setting the length (len) of unused memseg to 0.
When eal_legacy_hugepage_init() releases the VA space for unused memseg lists(MSLs), it does not reset MSLs' length to 0. As a result, mlx5_mem_is_rte() may incorrectly identify OS memory as rte memory.
This can lead to mlx_free() calling rte_free() on OS memory, causing an "EAL: Error: Invalid memory" log and failing to free the OS memory.
This issue is occasional and occurs when the DPDK program’s memory map places the heap address range between 0 and len(32G). In such cases, malloc may return an address less than len, causing mlx5_mem_is_rte() to incorrectly treat it as rte memory.
Also, consider how the MSL with base_va == NULL ends up in mlx5_mem_is_rte(). It comes from rte_mem_virt2memseg_list() which iterates MSLs and checks that an address belongs to [base_va; base_va+len) without checking whether base_va == NULL i.e. that the MSL is inactive. So this patch also corrects rte_mem_virt2memseg_list() behavior.
--- lib/eal/linux/eal_memory.c | 1 + 1 file changed, 1 insertion(+)
lib/eal/linux/eal_memory.c +1 -0
@@ -1472,6 +1472,7 @@ eal_legacy_hugepage_init(void) mem_sz = msl->len;munmap (msl->base_va, mem_sz); msl->base_va =NULL ; + msl->len =0 ; msl->heap =0 ;/* destroy backing fbarray */
Signature · 1 line
2.34.1
Re: [PATCH v2] eal: fix unused memseg length
Hi experts, is there any chance to review and accept this patch?
Quoted 46 lines · Yang Ming
Fix the issue where OS memory is mistakenly freed with
rte_freeby setting the length (len) of unused memseg to 0.When
eal_legacy_hugepage_init()releases the VA space for unused memseg lists(MSLs), it does not reset MSLs' length to 0. As a result,mlx5_mem_is_rte()may incorrectly identify OS memory as rte memory.
This can lead tomlx_free()callingrte_free()on OS memory, causing an "EAL: Error: Invalid memory" log and failing to free the OS memory.This issue is occasional and occurs when the DPDK program’s memory map places the heap address range between 0 and len(32G). In such cases, malloc may return an address less than len, causing
mlx5_mem_is_rte()to incorrectly treat it as rte memory.Also, consider how the MSL with
base_va == NULLends up inmlx5_mem_is_rte(). It comes fromrte_mem_virt2memseg_list()which iterates MSLs and checks that an address belongs to [base_va;base_va+len) without checking whetherbase_va == NULLi.e. that the MSL is inactive. So this patch also correctsrte_mem_virt2memseg_list()behavior.Fixes 66cc45e293ed ("mem: replace memseg with memseg lists")Signed-off-by Yang Ming <[email protected]>Acked-by Dmitry Kozlyuk <[email protected]>--- lib/eal/linux/eal_memory.c | 1 + 1 file changed, 1 insertion(+)lib/eal/linux/eal_memory.c +1
-0@@ -1472,6 +1472,7 @@ eal_legacy_hugepage_init(void) mem_sz = msl->len;munmap (msl->base_va, mem_sz); msl->base_va =NULL ; + msl->len =0 ; msl->heap =0 ;/* destroy backing fbarray */
David Marchand
AppliedRe: [PATCH v2] eal: fix unused memseg length
In reply to Yang MingQuoted 25 lines · Yang Ming
Fix the issue where OS memory is mistakenly freed with
rte_freeby setting the length (len) of unused memseg to 0.When
eal_legacy_hugepage_init()releases the VA space for unused memseg lists(MSLs), it does not reset MSLs' length to 0. As a result,mlx5_mem_is_rte()may incorrectly identify OS memory as rte memory.
This can lead tomlx_free()callingrte_free()on OS memory, causing an "EAL: Error: Invalid memory" log and failing to free the OS memory.This issue is occasional and occurs when the DPDK program’s memory map places the heap address range between 0 and len(32G). In such cases, malloc may return an address less than len, causing
mlx5_mem_is_rte()to incorrectly treat it as rte memory.Also, consider how the MSL with
base_va == NULLends up inmlx5_mem_is_rte(). It comes fromrte_mem_virt2memseg_list()which iterates MSLs and checks that an address belongs to [base_va;base_va+len) without checking whetherbase_va == NULLi.e. that the MSL is inactive. So this patch also correctsrte_mem_virt2memseg_list()behavior.
Quoted 5 lines
Fixes 66cc45e293ed ("mem: replace memseg with memseg lists")Signed-off-by Yang Ming <[email protected]>Acked-by Dmitry Kozlyuk <[email protected]>
Applied, thanks for the fix.
Signature · 1 line
David Marchand