Skip to contentSkip to conversation

mempool: fix sp sc mempool bug

PATCH In review Weiliang Luo 2 participants 3 messages Sep 8, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mempool: fix sp sc mempool bug

---
 lib/librte_mempool/rte_mempool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_mempool/rte_mempool.c +1 -1
index 2e28e2e..350d77a 100644
@@ -879,7 +879,7 @@ rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
 	 * Since we have 4 combinations of the SP/SC/MP/MC examine the flags to
 	 * set the correct index into the table of ops structs.
 	 */
-	if (flags & (MEMPOOL_F_SP_PUT | MEMPOOL_F_SC_GET))
+	if ((flags & MEMPOOL_F_SP_PUT) && (flags & MEMPOOL_F_SC_GET))
 		rte_mempool_set_ops_byname(mp, "ring_sp_sc", NULL);
 	else if (flags & MEMPOOL_F_SP_PUT)
 		rte_mempool_set_ops_byname(mp, "ring_sp_mc", NULL);
Signature · 1 line
2.7.4 (Apple Git-66)
Acked-by on v1 1/1
#1 lore raw

Hi Weiliang,

Quoted 11 lines · Weiliang Luo
---
 lib/librte_mempool/rte_mempool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_mempool/rte_mempool.c +0 -0
index 2e28e2e..350d77a 100644

lib/librte_mempool/rte_mempool.c rte_mempool_create(const char *name, unsigned n, unsigned elt_size, · line 885

Quoted 8 lines
lib/librte_mempool/rte_mempool.c +1 -1
@@ -879,7 +879,7 @@ rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
 	 * Since we have 4 combinations of the SP/SC/MP/MC examine the flags to
 	 * set the correct index into the table of ops structs.
 	 */
-	if (flags & (MEMPOOL_F_SP_PUT | MEMPOOL_F_SC_GET))
+	if ((flags & MEMPOOL_F_SP_PUT) && (flags & MEMPOOL_F_SC_GET))
 		rte_mempool_set_ops_byname(mp, "ring_sp_sc", NULL);
 	else if (flags & MEMPOOL_F_SP_PUT)
 		rte_mempool_set_ops_byname(mp, "ring_sp_mc", NULL);

I would just change the title and add some explanation in the commit log. I suggest:

"""
mempool: fix corruption due to invalid handler

When using rte_mempool_create(), the mempool handler is selected depending on the flags given by the user:
- multi-consumer / multi-producer
- multi-consumer / single-producer
- single-consumer / multi-producer
- single-consumer / single-producer

The flags were not properly tested, resulting in the selection of sc/sp handler if sc/mp or mc/sp was asked. This can lead to corruption or crashes because the get/put operations are not atomic.

Fixes 449c49b93a6b ("mempool: support handler operations")

"""

Thanks!
Olivier

#2 lore raw

Thanks for your suggestion, I have submitted again with amended commit msg.

Thanks,
Weiliang

Quoted 54 lines · Olivier Matz

Hi Weiliang,

lib/librte_mempool/rte_

Quoted 6 lines · Weiliang Luo
---
 lib/librte_mempool/rte_mempool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_mempool/rte_ renamed from lib/librte_mempool/rte_mempool.c +0 -0

mempool.c

lib/librte_mempool/rte_mempool.c rte_mempool_create(const char *name, unsigned n,

Quoted 4 lines

index 2e28e2e..350d77a 100644

lib/librte_mempool/rte_mempool.c +0 -0
@@ -879,7 +879,7 @@ rte_mempool_create(const char *name, unsigned n,

unsigned elt_size,

lib/librte_mempool/rte_mempool.c rte_mempool_create(const char *name, unsigned n, · line 879

Quoted 1 line
lib/librte_mempool/rte_mempool.c +0 -0
       * Since we have 4 combinations of the SP/SC/MP/MC examine the

flags to

lib/librte_mempool/rte_mempool.c rte_mempool_create(const char *name, unsigned n, unsigned elt_size, · line 885

Quoted 8 lines
lib/librte_mempool/rte_mempool.c +1 -1
       * set the correct index into the table of ops structs.
       */
-     if (flags & (MEMPOOL_F_SP_PUT | MEMPOOL_F_SC_GET))
+     if ((flags & MEMPOOL_F_SP_PUT) && (flags & MEMPOOL_F_SC_GET))
              rte_mempool_set_ops_byname(mp, "ring_sp_sc", NULL);
      else if (flags & MEMPOOL_F_SP_PUT)
              rte_mempool_set_ops_byname(mp, "ring_sp_mc", NULL);

I would just change the title and add some explanation in the commit log. I suggest:

"""
mempool: fix corruption due to invalid handler

When using rte_mempool_create(), the mempool handler is selected depending on the flags given by the user:
- multi-consumer / multi-producer
- multi-consumer / single-producer
- single-consumer / multi-producer
- single-consumer / single-producer

The flags were not properly tested, resulting in the selection of sc/sp handler if sc/mp or mc/sp was asked. This can lead to corruption or crashes because the get/put operations are not atomic.

Fixes 449c49b93a6b ("mempool: support handler operations")

"""

Thanks!
Olivier