Skip to contentSkip to conversation

memzone: Check socket_id value when creating memzone.

PATCH Applied Tonghao Zhang 3 participants 5 messages May 12, 2017 – Jun 5, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 memzone: Check socket_id value when creating memzone.

If the socket_id is invalid (e.g. -2, -3), the memzone_reserve_aligned_thread_unsafe should return the EINVAL and not ENOMEM. To avoid it, we should check the socket_id before calling malloc_heap_alloc.

---
 lib/librte_eal/common/eal_common_memzone.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/librte_eal/common/eal_common_memzone.c +2 -1
index 64f4e0a..3026e36 100644
@@ -189,7 +189,8 @@
 		return NULL;
 	}
 
-	if ((socket_id != SOCKET_ID_ANY) && (socket_id >= RTE_MAX_NUMA_NODES)) {
+	if ((socket_id != SOCKET_ID_ANY) &&
+	    (socket_id >= RTE_MAX_NUMA_NODES || socket_id < 0)) {
 		rte_errno = EINVAL;
 		return NULL;
 	}
Signature · 1 line
1.8.3.1
Acked-by on v1 1/1
#1 lore raw
Quoted 16 lines · Tonghao Zhang

If the socket_id is invalid (e.g. -2, -3), the memzone_reserve_aligned_thread_unsafe should return the EINVAL and not ENOMEM. To avoid it, we should check the socket_id before calling malloc_heap_alloc.

---
 lib/librte_eal/common/eal_common_memzone.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/librte_eal/common/eal_common_memzone.c +0 -0
index 64f4e0a..3026e36 100644

lib/librte_eal/common/eal_common_memzone.c line 196

Quoted 9 lines
lib/librte_eal/common/eal_common_memzone.c +2 -1
@@ -189,7 +189,8 @@
 		return NULL;
 	}
 
-	if ((socket_id != SOCKET_ID_ANY) && (socket_id >= RTE_MAX_NUMA_NODES)) {
+	if ((socket_id != SOCKET_ID_ANY) &&
+	    (socket_id >= RTE_MAX_NUMA_NODES || socket_id < 0)) {
 		rte_errno = EINVAL;
 		return NULL;
 	}

Looks a sensible thing to do.

#2 lore raw
Quoted 32 lines · Bruce Richardson
Quoted 16 lines · Tonghao Zhang

If the socket_id is invalid (e.g. -2, -3), the memzone_reserve_aligned_thread_unsafe should return the EINVAL and not ENOMEM. To avoid it, we should check the socket_id before calling malloc_heap_alloc.

---
lib/librte_eal/common/eal_common_memzone.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
lib/librte_eal/common/eal_common_memzone.c +0 -0
index 64f4e0a..3026e36 100644

lib/librte_eal/common/eal_common_memzone.c line 196

Quoted 9 lines
lib/librte_eal/common/eal_common_memzone.c +2 -1
@@ -189,7 +189,8 @@
 		return NULL;
 	}
 
-	if ((socket_id != SOCKET_ID_ANY) && (socket_id >= RTE_MAX_NUMA_NODES)) {
+	if ((socket_id != SOCKET_ID_ANY) &&
+	    (socket_id >= RTE_MAX_NUMA_NODES || socket_id < 0)) {
 		rte_errno = EINVAL;
 		return NULL;
 	}

Looks a sensible thing to do.

Quoted 1 line
Acked-by Bruce Richardson <[email protected] <mailto:[email protected]>>

Thanks for your review.

#3 lore raw
In reply to Bruce Richardson

If that patch is ok, will we apply it to master?
Thanks.
Nick

Quoted 32 lines · Bruce Richardson
Quoted 16 lines · Tonghao Zhang

If the socket_id is invalid (e.g. -2, -3), the memzone_reserve_aligned_thread_unsafe should return the EINVAL and not ENOMEM. To avoid it, we should check the socket_id before calling malloc_heap_alloc.

---
lib/librte_eal/common/eal_common_memzone.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
lib/librte_eal/common/eal_common_memzone.c +0 -0
index 64f4e0a..3026e36 100644

lib/librte_eal/common/eal_common_memzone.c line 196

Quoted 9 lines
lib/librte_eal/common/eal_common_memzone.c +2 -1
@@ -189,7 +189,8 @@
 		return NULL;
 	}
 
-	if ((socket_id != SOCKET_ID_ANY) && (socket_id >= RTE_MAX_NUMA_NODES)) {
+	if ((socket_id != SOCKET_ID_ANY) &&
+	    (socket_id >= RTE_MAX_NUMA_NODES || socket_id < 0)) {
 		rte_errno = EINVAL;
 		return NULL;
 	}

Looks a sensible thing to do.

Acked-by Bruce Richardson <[email protected] <mailto:[email protected]>>
#4 lore raw
In reply to Bruce Richardson

12/05/2017 10:42, Bruce Richardson:

Quoted 11 lines · Tonghao Zhang
Quoted 6 lines

If the socket_id is invalid (e.g. -2, -3), the memzone_reserve_aligned_thread_unsafe should return the EINVAL and not ENOMEM. To avoid it, we should check the socket_id before calling malloc_heap_alloc.

Looks a sensible thing to do.

Applied, thanks