[dpdk-dev,1/2] mempool: fix returned value on 64 bit after counting objects

Message ID 1432571266-25840-1-git-send-email-adrien.mazarguil@6wind.com (mailing list archive)
State Accepted, archived
Headers

Commit Message

Adrien Mazarguil May 25, 2015, 4:27 p.m. UTC
  rte_mempool_xmem_usage()'s return type is ssize_t which has the same
architecture-dependent width as size_t but is signed.

On 64-bit architectures, returning a negative uint32_t value without casting
to ssize_t first does not work as intended, the sign bit is lost and the
returned value is garbage.

This commit fixes an assertion failure in testpmd on 64 bit architectures
when combining --no-huge and --mp-anon outside of Xen Dom0:

 PANIC in mempool_anon_create():
 line 170        assert "elt_num == mp->size" failed

Fixes: 148f963fb532 ("xen: core library changes")

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
 lib/librte_mempool/rte_mempool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Ananyev, Konstantin May 27, 2015, 12:43 a.m. UTC | #1
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Adrien Mazarguil
> Sent: Monday, May 25, 2015 5:28 PM
> To: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH 1/2] mempool: fix returned value on 64 bit after counting objects
> 
> rte_mempool_xmem_usage()'s return type is ssize_t which has the same
> architecture-dependent width as size_t but is signed.
> 
> On 64-bit architectures, returning a negative uint32_t value without casting
> to ssize_t first does not work as intended, the sign bit is lost and the
> returned value is garbage.
> 
> This commit fixes an assertion failure in testpmd on 64 bit architectures
> when combining --no-huge and --mp-anon outside of Xen Dom0:
> 
>  PANIC in mempool_anon_create():
>  line 170        assert "elt_num == mp->size" failed
> 
> Fixes: 148f963fb532 ("xen: core library changes")
> 
> Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
> ---
>  lib/librte_mempool/rte_mempool.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c
> index 01972ba..d1a02a2 100644
> --- a/lib/librte_mempool/rte_mempool.c
> +++ b/lib/librte_mempool/rte_mempool.c
> @@ -361,7 +361,7 @@ rte_mempool_xmem_usage(void *vaddr, uint32_t elt_num, size_t elt_sz,
>  	if ((n = rte_mempool_obj_iter(vaddr, elt_num, elt_sz, 1,
>  			paddr, pg_num, pg_shift, mempool_lelem_iter,
>  			&uv)) != elt_num) {
> -		return (-n);
> +		return (-(ssize_t)n);
>  	}
> 
>  	uv = RTE_ALIGN_CEIL(uv, pg_sz);
> --

Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>

> 2.1.0
  
Thomas Monjalon May 29, 2015, 3:57 p.m. UTC | #2
2015-05-27 00:43, Ananyev, Konstantin:
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Adrien Mazarguil
> > rte_mempool_xmem_usage()'s return type is ssize_t which has the same
> > architecture-dependent width as size_t but is signed.
> > 
> > On 64-bit architectures, returning a negative uint32_t value without casting
> > to ssize_t first does not work as intended, the sign bit is lost and the
> > returned value is garbage.
> > 
> > This commit fixes an assertion failure in testpmd on 64 bit architectures
> > when combining --no-huge and --mp-anon outside of Xen Dom0:
> > 
> >  PANIC in mempool_anon_create():
> >  line 170        assert "elt_num == mp->size" failed
> > 
> > Fixes: 148f963fb532 ("xen: core library changes")
> > 
> > Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
> 
> Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c
index 01972ba..d1a02a2 100644
--- a/lib/librte_mempool/rte_mempool.c
+++ b/lib/librte_mempool/rte_mempool.c
@@ -361,7 +361,7 @@  rte_mempool_xmem_usage(void *vaddr, uint32_t elt_num, size_t elt_sz,
 	if ((n = rte_mempool_obj_iter(vaddr, elt_num, elt_sz, 1,
 			paddr, pg_num, pg_shift, mempool_lelem_iter,
 			&uv)) != elt_num) {
-		return (-n);
+		return (-(ssize_t)n);
 	}
 
 	uv = RTE_ALIGN_CEIL(uv, pg_sz);