From: Olivier Matz Date: Wed, 8 Jan 2020 15:05:41 +0000 (+0100) Subject: mempool: fix mempool virt populate with small chunks X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=b6197a7beb511f273aeca829c59355d993353261;p=dpdk.git mempool: fix mempool virt populate with small chunks To populate a mempool with a virtual area, the mempool code calls rte_mempool_populate_iova() for each iova-contiguous area. It happens (rarely) that this area is too small to store one object. In this case, rte_mempool_populate_iova() returns an error, which is forwarded by rte_mempool_populate_virt(). This case should not throw an error in rte_mempool_populate_virt(). Instead, the area that is too small should just be ignored. To fix this issue, change the return value of rte_mempool_populate_iova() to -ENOBUFS when no object can be populated, so it can be ignored by the caller. As this would be an API change, add a compat wrapper to keep the current API unchanged. The wrapper will be removed for 20.11. Fixes: 354788b60cfd ("mempool: allow populating with unaligned virtual area") Cc: stable@dpdk.org Signed-off-by: Olivier Matz --- diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst index afa94b43e2..b6e89d9a22 100644 --- a/doc/guides/rel_notes/deprecation.rst +++ b/doc/guides/rel_notes/deprecation.rst @@ -86,3 +86,7 @@ Deprecation Notices to set new power environment if power environment was already initialized. In this case the function will return -1 unless the environment is unset first (using ``rte_power_unset_env``). Other function usage scenarios will not change. + +* mempool: starting from v20.11, rte_mempool_populate_iova() will + return -ENOBUFS instead of -EINVAL when there is not enough room to + store one object. diff --git a/lib/librte_mempool/meson.build b/lib/librte_mempool/meson.build index f8710b61bc..4fe267cd8d 100644 --- a/lib/librte_mempool/meson.build +++ b/lib/librte_mempool/meson.build @@ -18,3 +18,4 @@ deps += ['ring'] # memseg walk is not yet part of stable API allow_experimental_apis = true +use_function_versioning = true diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index 78d8eb941e..ff95f4185a 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "rte_mempool.h" @@ -293,12 +294,17 @@ mempool_ops_alloc_once(struct rte_mempool *mp) return 0; } +int +rte_mempool_populate_iova_v20_0_1(struct rte_mempool *mp, char *vaddr, + rte_iova_t iova, size_t len, rte_mempool_memchunk_free_cb_t *free_cb, + void *opaque); + /* Add objects in the pool, using a physically contiguous memory * zone. Return the number of objects added, or a negative value * on error. */ int -rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr, +rte_mempool_populate_iova_v20_0_1(struct rte_mempool *mp, char *vaddr, rte_iova_t iova, size_t len, rte_mempool_memchunk_free_cb_t *free_cb, void *opaque) { @@ -332,7 +338,7 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr, off = RTE_PTR_ALIGN_CEIL(vaddr, RTE_MEMPOOL_ALIGN) - vaddr; if (off > len) { - ret = -EINVAL; + ret = -ENOBUFS; goto fail; } @@ -343,7 +349,7 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr, /* not enough room to store one object */ if (i == 0) { - ret = -EINVAL; + ret = -ENOBUFS; goto fail; } @@ -355,6 +361,33 @@ fail: rte_free(memhdr); return ret; } +BIND_DEFAULT_SYMBOL(rte_mempool_populate_iova, _v20_0_1, 20.0.1); +MAP_STATIC_SYMBOL( + int rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr, + rte_iova_t iova, size_t len, + rte_mempool_memchunk_free_cb_t *free_cb, + void *opaque), + rte_mempool_populate_iova_v20_0_1); + +int +rte_mempool_populate_iova_v20_0(struct rte_mempool *mp, char *vaddr, + rte_iova_t iova, size_t len, rte_mempool_memchunk_free_cb_t *free_cb, + void *opaque); +int +rte_mempool_populate_iova_v20_0(struct rte_mempool *mp, char *vaddr, + rte_iova_t iova, size_t len, rte_mempool_memchunk_free_cb_t *free_cb, + void *opaque) +{ + int ret; + + ret = rte_mempool_populate_iova_v20_0_1(mp, vaddr, iova, len, free_cb, + opaque); + if (ret == -ENOBUFS) + ret = -EINVAL; + + return ret; +} +VERSION_SYMBOL(rte_mempool_populate_iova, _v20_0, 20.0); static rte_iova_t get_iova(void *addr) @@ -381,6 +414,13 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, size_t off, phys_len; int ret, cnt = 0; + /* call alloc_once() in advance, it avoids a misinterpretation + * of -ENOBUFS when delegated to rte_mempool_populate_iova(). + */ + ret = mempool_ops_alloc_once(mp); + if (ret != 0) + return ret; + if (mp->flags & MEMPOOL_F_NO_IOVA_CONTIG) return rte_mempool_populate_iova(mp, addr, RTE_BAD_IOVA, len, free_cb, opaque); @@ -406,8 +446,10 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, break; } - ret = rte_mempool_populate_iova(mp, addr + off, iova, + ret = rte_mempool_populate_iova_v20_0_1(mp, addr + off, iova, phys_len, free_cb, opaque); + if (ret == -ENOBUFS) + continue; if (ret < 0) goto fail; /* no need to call the free callback for next chunks */ diff --git a/lib/librte_mempool/rte_mempool.h b/lib/librte_mempool/rte_mempool.h index f81152af96..c08bb444ff 100644 --- a/lib/librte_mempool/rte_mempool.h +++ b/lib/librte_mempool/rte_mempool.h @@ -1108,7 +1108,10 @@ rte_mempool_free(struct rte_mempool *mp); * @return * The number of objects added on success. * On error, the chunk is not added in the memory list of the - * mempool and a negative errno is returned. + * mempool and a negative errno is returned: + * (-ENOBUFS): not enough room in chunk for one object. + * (-ENOSPC): mempool is already populated. + * (-ENOMEM): allocation failure. */ int rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr, rte_iova_t iova, size_t len, rte_mempool_memchunk_free_cb_t *free_cb, diff --git a/lib/librte_mempool/rte_mempool_version.map b/lib/librte_mempool/rte_mempool_version.map index d002dfc46f..402e731ff4 100644 --- a/lib/librte_mempool/rte_mempool_version.map +++ b/lib/librte_mempool/rte_mempool_version.map @@ -35,6 +35,12 @@ DPDK_20.0 { local: *; }; +DPDK_20.0.1 { + global: + + rte_mempool_populate_iova; +} DPDK_20.0; + EXPERIMENTAL { global: