Skip to contentSkip to conversation

mempool: fix the inverted pg_num check on create

PATCH In review Dan Aloni 2 participants 3 messages Aug 16, 2015 – Aug 17, 2015

lore
Share & tools
lore

Dan Aloni

author
#0 lore raw

PATCH 1/1 mempool: fix the inverted pg_num check on create

The rest of the code expects pg_num <= RTE_DIM(mp->elt_pa).

---
 lib/librte_mempool/rte_mempool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_mempool/rte_mempool.c +1 -1
index 8e185c545479..edcfa8bf9cb1 100644
@@ -461,7 +461,7 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size,
 	}
 
 	/* Check that pg_num and pg_shift parameters are valid. */
-	if (pg_num < RTE_DIM(mp->elt_pa) || pg_shift > MEMPOOL_PG_SHIFT_MAX) {
+	if (pg_num > RTE_DIM(mp->elt_pa) || pg_shift > MEMPOOL_PG_SHIFT_MAX) {
 		rte_errno = EINVAL;
 		return NULL;
 	}
Signature · 1 line
2.4.3
#1 lore raw

Hi,

Quoted 13 lines · Dan Aloni

The rest of the code expects pg_num <= RTE_DIM(mp->elt_pa).

---
 lib/librte_mempool/rte_mempool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_mempool/rte_mempool.c +0 -0
index 8e185c545479..edcfa8bf9cb1 100644

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

Quoted 8 lines
lib/librte_mempool/rte_mempool.c +1 -1
@@ -461,7 +461,7 @@ rte_mempool_xmem_create(const char *name, unsigned n, unsigned elt_size,
 	}
 
 	/* Check that pg_num and pg_shift parameters are valid. */
-	if (pg_num < RTE_DIM(mp->elt_pa) || pg_shift > MEMPOOL_PG_SHIFT_MAX) {
+	if (pg_num > RTE_DIM(mp->elt_pa) || pg_shift > MEMPOOL_PG_SHIFT_MAX) {
 		rte_errno = EINVAL;
 		return NULL;
 	}

Could you give some details about the conditions to reproduce and the consequences of the issue?

Quoted 1 line

From what I see, RTE_DIM(mp->elt_pa) is always 1:

	#define MEMPOOL_PG_NUM_DEFAULT  1
	struct rte_mempool {
		...
	        phys_addr_t elt_pa[MEMPOOL_PG_NUM_DEFAULT];
	}  __rte_cache_aligned;
Quoted 1 line

From rte_mempool_xmem_create() documentation, pg_num gives the size of

the paddr array, which is allocated by the caller. So I think there is no issue here.

Regards,
Olivier

author
#2 lore raw
Quoted 1 line · Olivier MATZ

On 08/16/2015 09:08 PM, Dan Aloni wrote:

[..]

Quoted 15 lines

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

Quoted 5 lines
lib/librte_mempool/rte_mempool.c +1 -1
 	/* Check that pg_num and pg_shift parameters are valid. */
-	if (pg_num < RTE_DIM(mp->elt_pa) || pg_shift > MEMPOOL_PG_SHIFT_MAX) {
+	if (pg_num > RTE_DIM(mp->elt_pa) || pg_shift > MEMPOOL_PG_SHIFT_MAX) {
 		rte_errno = EINVAL;
 		return NULL;

From what I see, RTE_DIM(mp->elt_pa) is always 1:

	#define MEMPOOL_PG_NUM_DEFAULT  1
	struct rte_mempool {
		...
	        phys_addr_t elt_pa[MEMPOOL_PG_NUM_DEFAULT];
	}  __rte_cache_aligned;
Quoted 3 lines

From rte_mempool_xmem_create() documentation, pg_num gives the size of the paddr array, which is allocated by the caller. So I think there is no issue here.

You're right, I missed on the fact that mempool takes pg_num as its run-time determined size of the array for both its dynamically allocated copy and the caller's provided array.

The MEMPOOL_PG_NUM_DEFAULT macro is was a bit distracting in this. I wanted to provide pg_num > 1 and it wasn't clear on whether to modify the macro, or simply call the function :). So, never mind the patch.

Signature · 1 line
Dan Aloni