[v2] mem: fix infinite loop

Message ID 20250403025736.135846-1-huangdengdui@huawei.com (mailing list archive)
State Accepted
Delegated to: David Marchand
Headers
Series [v2] mem: fix infinite loop |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/loongarch-compilation success Compilation OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-mellanox-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS

Commit Message

Dengdui Huang April 3, 2025, 2:57 a.m. UTC
When the process address space is insufficient,
mmap will fail, which will cause an infinite loop.
This patch stops attempting mmap if it fails and
the requested size cannot be reduced.

Fixes: b7cc54187ea4 ("mem: move virtual area function in common directory")
Cc: stable@dpdk.org

Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/eal/common/eal_common_memory.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
  

Comments

Burakov, Anatoly May 8, 2025, 11:40 a.m. UTC | #1
On 4/3/2025 4:57 AM, Dengdui Huang wrote:
> When the process address space is insufficient,
> mmap will fail, which will cause an infinite loop.
> This patch stops attempting mmap if it fails and
> the requested size cannot be reduced.
> 
> Fixes: b7cc54187ea4 ("mem: move virtual area function in common directory")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
> Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
  
David Marchand June 4, 2025, 4:03 p.m. UTC | #2
On Thu, Apr 3, 2025 at 4:57 AM Dengdui Huang <huangdengdui@huawei.com> wrote:
>
> When the process address space is insufficient,
> mmap will fail, which will cause an infinite loop.
> This patch stops attempting mmap if it fails and
> the requested size cannot be reduced.
>
> Fixes: b7cc54187ea4 ("mem: move virtual area function in common directory")
> Cc: stable@dpdk.org
>
> Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
> Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>

Applied, thanks.
  

Patch

diff --git a/lib/eal/common/eal_common_memory.c b/lib/eal/common/eal_common_memory.c
index a185e0b580..0c997201bd 100644
--- a/lib/eal/common/eal_common_memory.c
+++ b/lib/eal/common/eal_common_memory.c
@@ -101,8 +101,12 @@  eal_get_virtual_area(void *requested_addr, size_t *size,
 
 		mapped_addr = eal_mem_reserve(
 			requested_addr, (size_t)map_sz, reserve_flags);
-		if ((mapped_addr == NULL) && allow_shrink)
-			*size -= page_sz;
+		if (mapped_addr == NULL) {
+			if (allow_shrink)
+				*size -= page_sz;
+			else
+				break;
+		}
 
 		if ((mapped_addr != NULL) && addr_is_hint &&
 				(mapped_addr != requested_addr)) {