Skip to contentSkip to conversation

kni: add IOVA va support for kni

PATCH In review Kiran Kumar 15 participants 251 messages Sep 27, 2018 – Nov 15, 2019 Arm/Amlogic Meson SoC support Page 2 of 3

lore
Share & tools
lore
#120 lore raw

Re: [dpdk-dev] [PATCH v2 0/6] mempool: avoid objects allocations across pages

In reply to Olivier Matz

Series Acked-by: Nipun Gupta <[email protected]>

Quoted 81 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Olivier Matz
Sent: Wednesday, October 30, 2019 8:06 PM
To: [email protected]
Cc: Anatoly Burakov <[email protected]>; Andrew Rybchenko <[email protected]>; Ferruh Yigit <[email protected]>; Giridharan, Ganesan <[email protected]>; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; Stephen Hemminger <[email protected]>; Thomas Monjalon <[email protected]>; Vamsi Krishna Attunuru <[email protected]>
Subject: [dpdk-dev] [PATCH v2 0/6] mempool: avoid objects allocations across pages

KNI supposes that mbufs are contiguous in kernel virtual memory. This may not be true when using the IOVA=VA mode. To fix this, a possibility is to ensure that objects do not cross page boundaries in mempool. This patchset implements this in the last patch (5/5).

The previous patches prepare the job:
- allow to populate with an unaligned virtual area (1/5).
- reduce spaced wasted in the mempool size calculation when not using the iova-contiguous allocation (2/5).
- remove the iova-contiguous allocation when populating mempool (3/5):
a va-contiguous alloc does the job as well if we want to populate without crossing page boundaries, so simplify the mempool populate function.
- export a function to get the minimum page used in a mempool (4/5)

Memory consumption impact when using hugepages:
- worst case: + ~0.1% for a mbuf pool (objsize ~= 2368)
- best case: -50% for if pool size is just above page size

The memory consumption impact with 4K pages in IOVA=VA mode could however consume up to 75% more memory for mbuf pool, because there will be only 1 mbuf per page. Not sure how common this usecase is.

Caveat: this changes the behavior of the mempool (calc_mem_size and populate), and there is a small risk to break things, especially with alternate mempool drivers.

v2

* update octeontx2 driver to keep alignment constraint (issue seen by Vamsi)
* add a new patch to use RTE_MEMPOOL_ALIGN (Andrew)
* fix initialization of for loop in rte_mempool_populate_virt() (Andrew)
* use rte_mempool_populate_iova() if mz_flags has RTE_MEMZONE_IOVA_CONTIG (Andrew)
* check rte_mempool_get_page_size() return value (Andrew)
* some other minor style improvements

rfc -> v1

* remove first cleanup patch, it was pushed separately a2b5a8722f20 ("mempool: clarify default populate function")
* add missing change in rte_mempool_op_calc_mem_size_default()
* allow unaligned addr/len in populate virt
* better split patches
* try to better explain the change
* use DPDK align macros when relevant

Olivier Matz (6):
mempool: allow unaligned addr/len in populate virt
mempool: reduce wasted space on mempool populate
mempool: remove optimistic IOVA-contiguous allocation
mempool: introduce function to get mempool page size
mempool: prevent objects from being across pages
mempool: use the specific macro for object alignment

 drivers/mempool/octeontx2/Makefile           |   3 +
 drivers/mempool/octeontx2/meson.build        |   3 +
 drivers/mempool/octeontx2/otx2_mempool_ops.c | 119 +++++++++++++--
 lib/librte_mempool/rte_mempool.c             | 147 ++++++++-----------
 lib/librte_mempool/rte_mempool.h             |  15 +-
 lib/librte_mempool/rte_mempool_ops.c         |   4 +-
 lib/librte_mempool/rte_mempool_ops_default.c |  60 ++++++--
 lib/librte_mempool/rte_mempool_version.map   |   1 +
 8 files changed, 236 insertions(+), 116 deletions(-)

--
2.20.1

#121 lore raw

v3 cover mempool: avoid objects allocations across pages

In reply to Olivier Matz

KNI supposes that mbufs are contiguous in kernel virtual memory. This may not be true when using the IOVA=VA mode. To fix this, a possibility is to ensure that objects do not cross page boundaries in mempool. This patchset implements this in the last patch (5/5).

The previous patches prepare the job:
- allow to populate with an unaligned virtual area (1/5).
- reduce spaced wasted in the mempool size calculation when not using the iova-contiguous allocation (2/5).
- remove the iova-contiguous allocation when populating mempool (3/5):
a va-contiguous alloc does the job as well if we want to populate without crossing page boundaries, so simplify the mempool populate function.
- export a function to get the minimum page used in a mempool (4/5)

Memory consumption impact when using hugepages:
- worst case: + ~0.1% for a mbuf pool (objsize ~= 2368)
- best case: -50% for if pool size is just above page size

The memory consumption impact with 4K pages in IOVA=VA mode could however consume up to 75% more memory for mbuf pool, because there will be only 1 mbuf per page. Not sure how common this usecase is.

Caveat: this changes the behavior of the mempool (calc_mem_size and populate), and there is a small risk to break things, especially with alternate mempool drivers.

v3

* introduce new helpers to calculate required memory size and to populate mempool, use them in drivers: the alignment constraint of octeontx/octeontx2 is managed in this common code.
* fix octeontx mempool driver by taking alignment constraint in account like in octeontx2
* fix bucket mempool driver with 4K pages: limit bucket size in this case to ensure that objects do not cross page boundaries. With larger pages, it was already ok, because bucket size (64K) is smaller than a page.
* fix some api comments in mempool header file

v2

* update octeontx2 driver to keep alignment constraint (issue seen by Vamsi)
* add a new patch to use RTE_MEMPOOL_ALIGN (Andrew)
* fix initialization of for loop in rte_mempool_populate_virt() (Andrew)
* use rte_mempool_populate_iova() if mz_flags has RTE_MEMZONE_IOVA_CONTIG (Andrew)
* check rte_mempool_get_page_size() return value (Andrew)
* some other minor style improvements

rfc -> v1

* remove first cleanup patch, it was pushed separately a2b5a8722f20 ("mempool: clarify default populate function")
* add missing change in rte_mempool_op_calc_mem_size_default()
* allow unaligned addr/len in populate virt
* better split patches
* try to better explain the change
* use DPDK align macros when relevant

Olivier Matz (7):
mempool: allow unaligned addr/len in populate virt
mempool: reduce wasted space on mempool populate
mempool: remove optimistic IOVA-contiguous allocation
mempool: introduce function to get mempool page size
mempool: introduce helpers for populate and calc mem size
mempool: prevent objects from being across pages
mempool: use the specific macro for object alignment

 drivers/mempool/bucket/Makefile               |   2 +
 drivers/mempool/bucket/meson.build            |   3 +
 drivers/mempool/bucket/rte_mempool_bucket.c   |  10 +-
 drivers/mempool/dpaa/dpaa_mempool.c           |   4 +-
 drivers/mempool/dpaa2/dpaa2_hw_mempool.c      |   4 +-
 drivers/mempool/octeontx/Makefile             |   3 +
 drivers/mempool/octeontx/meson.build          |   3 +
 .../mempool/octeontx/rte_mempool_octeontx.c   |  21 +--
 drivers/mempool/octeontx2/Makefile            |   6 +
 drivers/mempool/octeontx2/meson.build         |   6 +
 drivers/mempool/octeontx2/otx2_mempool_ops.c  |  21 ++-
 lib/librte_mempool/rte_mempool.c              | 147 +++++++-----------
 lib/librte_mempool/rte_mempool.h              |  64 ++++++--
 lib/librte_mempool/rte_mempool_ops.c          |   4 +-
 lib/librte_mempool/rte_mempool_ops_default.c  | 113 +++++++++++---
 lib/librte_mempool/rte_mempool_version.map    |   3 +
 16 files changed, 272 insertions(+), 142 deletions(-)
Signature · 1 line
2.20.1
#122 lore raw

PATCH v3 1/7 mempool: allow unaligned addr/len in populate virt

rte_mempool_populate_virt() currently requires that both addr and length are page-aligned.

Remove this uneeded constraint which can be annoying with big hugepages (ex: 1GB).

---
 lib/librte_mempool/rte_mempool.c | 23 +++++++++++------------
 lib/librte_mempool/rte_mempool.h |  3 +--
 2 files changed, 12 insertions(+), 14 deletions(-)
lib/librte_mempool/rte_mempool.c +11 -12
index 0f29e8712..88e49c751 100644
@@ -368,17 +368,11 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
 	size_t off, phys_len;
 	int ret, cnt = 0;
 
-	/* address and len must be page-aligned */
-	if (RTE_PTR_ALIGN_CEIL(addr, pg_sz) != addr)
-		return -EINVAL;
-	if (RTE_ALIGN_CEIL(len, pg_sz) != len)
-		return -EINVAL;
-
 	if (mp->flags & MEMPOOL_F_NO_IOVA_CONTIG)
 		return rte_mempool_populate_iova(mp, addr, RTE_BAD_IOVA,
 			len, free_cb, opaque);
 
-	for (off = 0; off + pg_sz <= len &&
+	for (off = 0; off < len &&
 		     mp->populated_size < mp->size; off += phys_len) {
 
 		iova = rte_mem_virt2iova(addr + off);
@@ -389,12 +383,18 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
 		}
 
 		/* populate with the largest group of contiguous pages */
-		for (phys_len = pg_sz; off + phys_len < len; phys_len += pg_sz) {
+		for (phys_len = RTE_MIN(
+			(size_t)(RTE_PTR_ALIGN_CEIL(addr + off + 1, pg_sz) -
+				(addr + off)),
+			len - off);
+		     off + phys_len < len;
+		     phys_len = RTE_MIN(phys_len + pg_sz, len - off)) {
 			rte_iova_t iova_tmp;
 
 			iova_tmp = rte_mem_virt2iova(addr + off + phys_len);
 
-			if (iova_tmp != iova + phys_len)
+			if (iova_tmp == RTE_BAD_IOVA ||
+					iova_tmp != iova + phys_len)
 				break;
 		}
 
@@ -575,8 +575,7 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 			 * have
 			 */
 			mz = rte_memzone_reserve_aligned(mz_name, 0,
-					mp->socket_id, flags,
-					RTE_MAX(pg_sz, align));
+					mp->socket_id, flags, align);
 		}
 		if (mz == NULL) {
 			ret = -rte_errno;
@@ -601,7 +600,7 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 				(void *)(uintptr_t)mz);
 		else
 			ret = rte_mempool_populate_virt(mp, mz->addr,
-				RTE_ALIGN_FLOOR(mz->len, pg_sz), pg_sz,
+				mz->len, pg_sz,
 				rte_mempool_memchunk_mz_free,
 				(void *)(uintptr_t)mz);
 		if (ret < 0) {
lib/librte_mempool/rte_mempool.h +1 -2
index 8053f7a04..0fe8aa7b8 100644
@@ -1042,9 +1042,8 @@ int rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
  *   A pointer to the mempool structure.
  * @param addr
  *   The virtual address of memory that should be used to store objects.
- *   Must be page-aligned.
  * @param len
- *   The length of memory in bytes. Must be page-aligned.
+ *   The length of memory in bytes.
  * @param pg_sz
  *   The size of memory pages in this virtual area.
  * @param free_cb
Signature · 1 line
2.20.1
#123 lore raw

PATCH v3 2/7 mempool: reduce wasted space on mempool populate

In reply to Olivier Matz

The size returned by rte_mempool_op_calc_mem_size_default() is aligned to the specified page size. Therefore, with big pages, the returned size can be much more that what we really need to populate the mempool.

For instance, populating a mempool that requires 1.1GB of memory with 1GB hugepages can result in allocating 2GB of memory.

This problem is hidden most of the time due to the allocation method of rte_mempool_populate_default(): when try_iova_contig_mempool=true, it first tries to allocate an iova contiguous area, without the alignment constraint. If it fails, it fallbacks to an aligned allocation that does not require to be iova-contiguous. This can also fallback into several smaller aligned allocations.

This commit changes rte_mempool_op_calc_mem_size_default() to relax the alignment constraint to a cache line and to return a smaller size.

---
 lib/librte_mempool/rte_mempool.c             |  7 ++---
 lib/librte_mempool/rte_mempool.h             |  9 +++----
 lib/librte_mempool/rte_mempool_ops.c         |  4 ++-
 lib/librte_mempool/rte_mempool_ops_default.c | 28 +++++++++++++++-----
 4 files changed, 30 insertions(+), 18 deletions(-)
lib/librte_mempool/rte_mempool.c +2 -5
index 88e49c751..4e0d576f5 100644
@@ -477,11 +477,8 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 	 * wasting some space this way, but it's much nicer than looping around
 	 * trying to reserve each and every page size.
 	 *
-	 * However, since size calculation will produce page-aligned sizes, it
-	 * makes sense to first try and see if we can reserve the entire memzone
-	 * in one contiguous chunk as well (otherwise we might end up wasting a
-	 * 1G page on a 10MB memzone). If we fail to get enough contiguous
-	 * memory, then we'll go and reserve space page-by-page.
+	 * If we fail to get enough contiguous memory, then we'll go and
+	 * reserve space in smaller chunks.
 	 *
 	 * We also have to take into account the fact that memory that we're
 	 * going to allocate from can belong to an externally allocated memory
lib/librte_mempool/rte_mempool.h +3 -6
index 0fe8aa7b8..78b687bb6 100644
@@ -458,7 +458,7 @@ typedef unsigned (*rte_mempool_get_count)(const struct rte_mempool *mp);
  * @param[out] align
  *   Location for required memory chunk alignment.
  * @return
- *   Required memory size aligned at page boundary.
+ *   Required memory size.
  */
 typedef ssize_t (*rte_mempool_calc_mem_size_t)(const struct rte_mempool *mp,
 		uint32_t obj_num,  uint32_t pg_shift,
@@ -477,11 +477,8 @@ typedef ssize_t (*rte_mempool_calc_mem_size_t)(const struct rte_mempool *mp,
  * that pages are grouped in subsets of physically continuous pages big
  * enough to store at least one object.
  *
- * Minimum size of memory chunk is a maximum of the page size and total
- * element size.
- *
- * Required memory chunk alignment is a maximum of page size and cache
- * line size.
+ * Minimum size of memory chunk is the total element size.
+ * Required memory chunk alignment is the cache line size.
  */
 ssize_t rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
 		uint32_t obj_num, uint32_t pg_shift,
lib/librte_mempool/rte_mempool_ops.c +3 -1
index e02eb702c..22c5251eb 100644
@@ -100,7 +100,9 @@ rte_mempool_ops_get_count(const struct rte_mempool *mp)
 	return ops->get_count(mp);
 }
 
-/* wrapper to notify new memory area to external mempool */
+/* wrapper to calculate the memory size required to store given number
+ * of objects
+ */
 ssize_t
 rte_mempool_ops_calc_mem_size(const struct rte_mempool *mp,
 				uint32_t obj_num, uint32_t pg_shift,
lib/librte_mempool/rte_mempool_ops_default.c +22 -6
index 4e2bfc82d..f6aea7662 100644
@@ -12,7 +12,7 @@ rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
 				     size_t *min_chunk_size, size_t *align)
 {
 	size_t total_elt_sz;
-	size_t obj_per_page, pg_num, pg_sz;
+	size_t obj_per_page, pg_sz, objs_in_last_page;
 	size_t mem_size;
 
 	total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
@@ -33,14 +33,30 @@ rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
 			mem_size =
 				RTE_ALIGN_CEIL(total_elt_sz, pg_sz) * obj_num;
 		} else {
-			pg_num = (obj_num + obj_per_page - 1) / obj_per_page;
-			mem_size = pg_num << pg_shift;
+			/* In the best case, the allocator will return a
+			 * page-aligned address. For example, with 5 objs,
+			 * the required space is as below:
+			 *  |     page0     |     page1     |  page2 (last) |
+			 *  |obj0 |obj1 |xxx|obj2 |obj3 |xxx|obj4|
+			 *  <------------- mem_size ------------->
+			 */
+			objs_in_last_page = ((obj_num - 1) % obj_per_page) + 1;
+			/* room required for the last page */
+			mem_size = objs_in_last_page * total_elt_sz;
+			/* room required for other pages */
+			mem_size += ((obj_num - objs_in_last_page) /
+				obj_per_page) << pg_shift;
+
+			/* In the worst case, the allocator returns a
+			 * non-aligned pointer, wasting up to
+			 * total_elt_sz. Add a margin for that.
+			 */
+			 mem_size += total_elt_sz - 1;
 		}
 	}
 
-	*min_chunk_size = RTE_MAX((size_t)1 << pg_shift, total_elt_sz);
-
-	*align = RTE_MAX((size_t)RTE_CACHE_LINE_SIZE, (size_t)1 << pg_shift);
+	*min_chunk_size = total_elt_sz;
+	*align = RTE_CACHE_LINE_SIZE;
 
 	return mem_size;
 }
Signature · 1 line
2.20.1
#124 lore raw

PATCH v3 3/7 mempool: remove optimistic IOVA-contiguous allocation

In reply to Olivier Matz

The previous commit reduced the amount of required memory when populating the mempool with non iova-contiguous memory.

Since there is no big advantage to have a fully iova-contiguous mempool if it is not explicitly asked, remove this code, it simplifies the populate function.

---
 lib/librte_mempool/rte_mempool.c | 47 ++++++--------------------------
 1 file changed, 8 insertions(+), 39 deletions(-)
lib/librte_mempool/rte_mempool.c +8 -39
index 4e0d576f5..213e574fc 100644
@@ -430,7 +430,6 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 	unsigned mz_id, n;
 	int ret;
 	bool need_iova_contig_obj;
-	bool try_iova_contig_mempool;
 	bool alloc_in_ext_mem;
 
 	ret = mempool_ops_alloc_once(mp);
@@ -483,9 +482,7 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 	 * We also have to take into account the fact that memory that we're
 	 * going to allocate from can belong to an externally allocated memory
 	 * area, in which case the assumption of IOVA as VA mode being
-	 * synonymous with IOVA contiguousness will not hold. We should also try
-	 * to go for contiguous memory even if we're in no-huge mode, because
-	 * external memory may in fact be IOVA-contiguous.
+	 * synonymous with IOVA contiguousness will not hold.
 	 */
 
 	/* check if we can retrieve a valid socket ID */
@@ -494,7 +491,6 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 		return -EINVAL;
 	alloc_in_ext_mem = (ret == 1);
 	need_iova_contig_obj = !(mp->flags & MEMPOOL_F_NO_IOVA_CONTIG);
-	try_iova_contig_mempool = false;
 
 	if (!need_iova_contig_obj) {
 		pg_sz = 0;
@@ -503,7 +499,6 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 		pg_sz = 0;
 		pg_shift = 0;
 	} else if (rte_eal_has_hugepages() || alloc_in_ext_mem) {
-		try_iova_contig_mempool = true;
 		pg_sz = get_min_page_size(mp->socket_id);
 		pg_shift = rte_bsf32(pg_sz);
 	} else {
@@ -513,14 +508,9 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 
 	for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) {
 		size_t min_chunk_size;
-		unsigned int flags;
 
-		if (try_iova_contig_mempool || pg_sz == 0)
-			mem_size = rte_mempool_ops_calc_mem_size(mp, n,
-					0, &min_chunk_size, &align);
-		else
-			mem_size = rte_mempool_ops_calc_mem_size(mp, n,
-					pg_shift, &min_chunk_size, &align);
+		mem_size = rte_mempool_ops_calc_mem_size(
+			mp, n, pg_shift, &min_chunk_size, &align);
 
 		if (mem_size < 0) {
 			ret = mem_size;
@@ -534,36 +524,15 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 			goto fail;
 		}
 
-		flags = mz_flags;
-
 		/* if we're trying to reserve contiguous memory, add appropriate
 		 * memzone flag.
 		 */
-		if (try_iova_contig_mempool)
-			flags |= RTE_MEMZONE_IOVA_CONTIG;
+		if (min_chunk_size == (size_t)mem_size)
+			mz_flags |= RTE_MEMZONE_IOVA_CONTIG;
 
 		mz = rte_memzone_reserve_aligned(mz_name, mem_size,
-				mp->socket_id, flags, align);
-
-		/* if we were trying to allocate contiguous memory, failed and
-		 * minimum required contiguous chunk fits minimum page, adjust
-		 * memzone size to the page size, and try again.
-		 */
-		if (mz == NULL && try_iova_contig_mempool &&
-				min_chunk_size <= pg_sz) {
-			try_iova_contig_mempool = false;
-			flags &= ~RTE_MEMZONE_IOVA_CONTIG;
-
-			mem_size = rte_mempool_ops_calc_mem_size(mp, n,
-					pg_shift, &min_chunk_size, &align);
-			if (mem_size < 0) {
-				ret = mem_size;
-				goto fail;
-			}
+				mp->socket_id, mz_flags, align);
 
-			mz = rte_memzone_reserve_aligned(mz_name, mem_size,
-				mp->socket_id, flags, align);
-		}
 		/* don't try reserving with 0 size if we were asked to reserve
 		 * IOVA-contiguous memory.
 		 */
@@ -572,7 +541,7 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 			 * have
 			 */
 			mz = rte_memzone_reserve_aligned(mz_name, 0,
-					mp->socket_id, flags, align);
+					mp->socket_id, mz_flags, align);
 		}
 		if (mz == NULL) {
 			ret = -rte_errno;
@@ -590,7 +559,7 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 		else
 			iova = RTE_BAD_IOVA;
 
-		if (try_iova_contig_mempool || pg_sz == 0)
+		if (pg_sz == 0 || (mz_flags & RTE_MEMZONE_IOVA_CONTIG))
 			ret = rte_mempool_populate_iova(mp, mz->addr,
 				iova, mz->len,
 				rte_mempool_memchunk_mz_free,
Signature · 1 line
2.20.1
#125 lore raw

PATCH v3 4/7 mempool: introduce function to get mempool page size

In reply to Olivier Matz

In rte_mempool_populate_default(), we determine the page size, which is needed for calc_size and allocation of memory.

Move this in a function and export it, it will be used in a next commit.

---
 lib/librte_mempool/rte_mempool.c           | 51 ++++++++++++++--------
 lib/librte_mempool/rte_mempool.h           |  7 +++
 lib/librte_mempool/rte_mempool_version.map |  1 +
 3 files changed, 40 insertions(+), 19 deletions(-)
lib/librte_mempool/rte_mempool.c +32 -19
index 213e574fc..758c5410b 100644
@@ -414,6 +414,33 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
 	return ret;
 }
 
+/* Get the minimal page size used in a mempool before populating it. */
+int
+rte_mempool_get_page_size(struct rte_mempool *mp, size_t *pg_sz)
+{
+	bool need_iova_contig_obj;
+	bool alloc_in_ext_mem;
+	int ret;
+
+	/* check if we can retrieve a valid socket ID */
+	ret = rte_malloc_heap_socket_is_external(mp->socket_id);
+	if (ret < 0)
+		return -EINVAL;
+	alloc_in_ext_mem = (ret == 1);
+	need_iova_contig_obj = !(mp->flags & MEMPOOL_F_NO_IOVA_CONTIG);
+
+	if (!need_iova_contig_obj)
+		*pg_sz = 0;
+	else if (!alloc_in_ext_mem && rte_eal_iova_mode() == RTE_IOVA_VA)
+		*pg_sz = 0;
+	else if (rte_eal_has_hugepages() || alloc_in_ext_mem)
+		*pg_sz = get_min_page_size(mp->socket_id);
+	else
+		*pg_sz = getpagesize();
+
+	return 0;
+}
+
 /* Default function to populate the mempool: allocate memory in memzones,
  * and populate them. Return the number of objects added, or a negative
  * value on error.
@@ -425,12 +452,11 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 	char mz_name[RTE_MEMZONE_NAMESIZE];
 	const struct rte_memzone *mz;
 	ssize_t mem_size;
-	size_t align, pg_sz, pg_shift;
+	size_t align, pg_sz, pg_shift = 0;
 	rte_iova_t iova;
 	unsigned mz_id, n;
 	int ret;
 	bool need_iova_contig_obj;
-	bool alloc_in_ext_mem;
 
 	ret = mempool_ops_alloc_once(mp);
 	if (ret != 0)
@@ -485,26 +511,13 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 	 * synonymous with IOVA contiguousness will not hold.
 	 */
 
-	/* check if we can retrieve a valid socket ID */
-	ret = rte_malloc_heap_socket_is_external(mp->socket_id);
-	if (ret < 0)
-		return -EINVAL;
-	alloc_in_ext_mem = (ret == 1);
 	need_iova_contig_obj = !(mp->flags & MEMPOOL_F_NO_IOVA_CONTIG);
+	ret = rte_mempool_get_page_size(mp, &pg_sz);
+	if (ret < 0)
+		return ret;
 
-	if (!need_iova_contig_obj) {
-		pg_sz = 0;
-		pg_shift = 0;
-	} else if (!alloc_in_ext_mem && rte_eal_iova_mode() == RTE_IOVA_VA) {
-		pg_sz = 0;
-		pg_shift = 0;
-	} else if (rte_eal_has_hugepages() || alloc_in_ext_mem) {
-		pg_sz = get_min_page_size(mp->socket_id);
-		pg_shift = rte_bsf32(pg_sz);
-	} else {
-		pg_sz = getpagesize();
+	if (pg_sz != 0)
 		pg_shift = rte_bsf32(pg_sz);
-	}
 
 	for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) {
 		size_t min_chunk_size;
lib/librte_mempool/rte_mempool.h +7 -0
index 78b687bb6..1282414ba 100644
@@ -1688,6 +1688,13 @@ uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
 void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg),
 		      void *arg);
 
+/**
+ * @internal Get page size used for mempool object allocation.
+ */
+__rte_experimental
+int
+rte_mempool_get_page_size(struct rte_mempool *mp, size_t *pg_sz);
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_mempool/rte_mempool_version.map +1 -0
index 17cbca460..4eff2767d 100644
@@ -56,5 +56,6 @@ DPDK_18.05 {
 EXPERIMENTAL {
 	global:
 
+	rte_mempool_get_page_size;
 	rte_mempool_ops_get_info;
 };
Signature · 1 line
2.20.1
#126 lore raw

PATCH v3 5/7 mempool: introduce helpers for populate and calc mem size

In reply to Olivier Matz

Introduce new functions that can used by mempool drivers to calculate required memory size and to populate mempool.

For now, these helpers just replace the *_default() functions without change. They will be enhanced in next commit.

---
 drivers/mempool/bucket/Makefile               |  2 ++
 drivers/mempool/bucket/meson.build            |  3 ++
 drivers/mempool/bucket/rte_mempool_bucket.c   |  2 +-
 drivers/mempool/dpaa/dpaa_mempool.c           |  2 +-
 drivers/mempool/dpaa2/dpaa2_hw_mempool.c      |  2 +-
 drivers/mempool/octeontx/Makefile             |  3 ++
 drivers/mempool/octeontx/meson.build          |  3 ++
 .../mempool/octeontx/rte_mempool_octeontx.c   |  4 +--
 drivers/mempool/octeontx2/Makefile            |  3 ++
 drivers/mempool/octeontx2/meson.build         |  3 ++
 drivers/mempool/octeontx2/otx2_mempool_ops.c  |  4 +--
 lib/librte_mempool/rte_mempool.h              | 28 +++++++++++++++--
 lib/librte_mempool/rte_mempool_ops_default.c  | 31 +++++++++++++++----
 lib/librte_mempool/rte_mempool_version.map    |  2 ++
 14 files changed, 77 insertions(+), 15 deletions(-)
drivers/mempool/bucket/Makefile +2 -0
index 7364916bc..47be6b5f7 100644
@@ -15,6 +15,8 @@ LIB = librte_mempool_bucket.a
 
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
+# for mempool populate/calc_mem_size helpers
+CFLAGS += -DALLOW_EXPERIMENTAL_API
 
 LDLIBS += -lrte_eal -lrte_mempool -lrte_ring
 
drivers/mempool/bucket/meson.build +3 -0
index 618d79128..29df6751c 100644
@@ -6,4 +6,7 @@
 # This software was jointly developed between OKTET Labs (under contract
 # for Solarflare) and Solarflare Communications, Inc.
 
+# for mempool populate/calc_mem_size helpers
+allow_experimental_apis = true
+
 sources = files('rte_mempool_bucket.c')
drivers/mempool/bucket/rte_mempool_bucket.c +1 -1
index 78d2b9d04..dfeaf4e45 100644
@@ -585,7 +585,7 @@ bucket_populate(struct rte_mempool *mp, unsigned int max_objs,
 
 		hdr->fill_cnt = 0;
 		hdr->lcore_id = LCORE_ID_ANY;
-		rc = rte_mempool_op_populate_default(mp,
+		rc = rte_mempool_op_populate_helper(mp,
 						     RTE_MIN(bd->obj_per_bucket,
 							     max_objs - n_objs),
 						     iter + bucket_header_sz,
drivers/mempool/dpaa/dpaa_mempool.c +1 -1
index a25697f05..27736e6c2 100644
@@ -341,7 +341,7 @@ dpaa_populate(struct rte_mempool *mp, unsigned int max_objs,
 	 */
 	TAILQ_INSERT_HEAD(&rte_dpaa_memsegs, ms, next);
 
-	return rte_mempool_op_populate_default(mp, max_objs, vaddr, paddr, len,
+	return rte_mempool_op_populate_helper(mp, max_objs, vaddr, paddr, len,
 					       obj_cb, obj_cb_arg);
 }
 
drivers/mempool/dpaa2/dpaa2_hw_mempool.c +1 -1
index f26c30b00..8f8dbeada 100644
@@ -421,7 +421,7 @@ dpaa2_populate(struct rte_mempool *mp, unsigned int max_objs,
 	/* Insert entry into the PA->VA Table */
 	dpaax_iova_table_update(paddr, vaddr, len);
 
-	return rte_mempool_op_populate_default(mp, max_objs, vaddr, paddr, len,
+	return rte_mempool_op_populate_helper(mp, max_objs, vaddr, paddr, len,
 					       obj_cb, obj_cb_arg);
 }
 
drivers/mempool/octeontx/Makefile +3 -0
index a3e1dce88..6540a2ab4 100644
@@ -11,6 +11,9 @@ LIB = librte_mempool_octeontx.a
 
 CFLAGS += $(WERROR_FLAGS)
 CFLAGS += -I$(RTE_SDK)/drivers/common/octeontx/
+# for mempool populate/calc_mem_size helpers
+CFLAGS += -DALLOW_EXPERIMENTAL_API
+
 EXPORT_MAP := rte_mempool_octeontx_version.map
 
 LIBABIVER := 1
drivers/mempool/octeontx/meson.build +3 -0
index 3baaf7db2..f293afa96 100644
@@ -1,6 +1,9 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Cavium, Inc
 
+# for mempool populate/calc_mem_size helpers
+allow_experimental_apis = true
+
 sources = files('octeontx_fpavf.c',
 		'rte_mempool_octeontx.c'
 )
drivers/mempool/octeontx/rte_mempool_octeontx.c +2 -2
index ab94dfe91..fff33e5c6 100644
@@ -137,7 +137,7 @@ octeontx_fpavf_calc_mem_size(const struct rte_mempool *mp,
 	 * Simply need space for one more object to be able to
 	 * fulfil alignment requirements.
 	 */
-	mem_size = rte_mempool_op_calc_mem_size_default(mp, obj_num + 1,
+	mem_size = rte_mempool_op_calc_mem_size_helper(mp, obj_num + 1,
 							pg_shift,
 							min_chunk_size, align);
 	if (mem_size >= 0) {
@@ -184,7 +184,7 @@ octeontx_fpavf_populate(struct rte_mempool *mp, unsigned int max_objs,
 	if (ret < 0)
 		return ret;
 
-	return rte_mempool_op_populate_default(mp, max_objs, vaddr, iova, len,
+	return rte_mempool_op_populate_helper(mp, max_objs, vaddr, iova, len,
 					       obj_cb, obj_cb_arg);
 }
 
drivers/mempool/octeontx2/Makefile +3 -0
index 87cce22c6..8f55305c5 100644
@@ -23,6 +23,9 @@ CFLAGS += -diag-disable 2259
 endif
 endif
 
+# for mempool populate/calc_mem_size helpers
+CFLAGS += -DALLOW_EXPERIMENTAL_API
+
 EXPORT_MAP := rte_mempool_octeontx2_version.map
 
 LIBABIVER := 1
drivers/mempool/octeontx2/meson.build +3 -0
index 9fde40f0e..5f93bb495 100644
@@ -2,6 +2,9 @@
 # Copyright(C) 2019 Marvell International Ltd.
 #
 
+# for mempool populate/calc_mem_size helpers
+allow_experimental_apis = true
+
 sources = files('otx2_mempool_ops.c',
 		'otx2_mempool.c',
 		'otx2_mempool_irq.c',
drivers/mempool/octeontx2/otx2_mempool_ops.c +2 -2
index d769575f4..3aea92a01 100644
@@ -717,7 +717,7 @@ otx2_npa_calc_mem_size(const struct rte_mempool *mp, uint32_t obj_num,
 	 * Simply need space for one more object to be able to
 	 * fulfill alignment requirements.
 	 */
-	return rte_mempool_op_calc_mem_size_default(mp, obj_num + 1, pg_shift,
+	return rte_mempool_op_calc_mem_size_helper(mp, obj_num + 1, pg_shift,
 						    min_chunk_size, align);
 }
 
@@ -749,7 +749,7 @@ otx2_npa_populate(struct rte_mempool *mp, unsigned int max_objs, void *vaddr,
 	if (npa_lf_aura_range_update_check(mp->pool_id) < 0)
 		return -EBUSY;
 
-	return rte_mempool_op_populate_default(mp, max_objs, vaddr, iova, len,
+	return rte_mempool_op_populate_helper(mp, max_objs, vaddr, iova, len,
 					       obj_cb, obj_cb_arg);
 }
 
lib/librte_mempool/rte_mempool.h +26 -2
index 1282414ba..26a98af30 100644
@@ -465,7 +465,7 @@ typedef ssize_t (*rte_mempool_calc_mem_size_t)(const struct rte_mempool *mp,
 		size_t *min_chunk_size, size_t *align);
 
 /**
- * Default way to calculate memory size required to store given number of
+ * Helper to calculate memory size required to store given number of
  * objects.
  *
  * If page boundaries may be ignored, it is just a product of total
@@ -480,6 +480,18 @@ typedef ssize_t (*rte_mempool_calc_mem_size_t)(const struct rte_mempool *mp,
  * Minimum size of memory chunk is the total element size.
  * Required memory chunk alignment is the cache line size.
  */
+__rte_experimental
+ssize_t rte_mempool_op_calc_mem_size_helper(const struct rte_mempool *mp,
+		uint32_t obj_num, uint32_t pg_shift,
+		size_t *min_chunk_size, size_t *align);
+
+/**
+ * Default way to calculate memory size required to store given number of
+ * objects.
+ *
+ * Equivalent to rte_mempool_op_calc_mem_size_helper(mp, obj_num, pg_shift,
+ * min_chunk_size, align).
+ */
 ssize_t rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
 		uint32_t obj_num, uint32_t pg_shift,
 		size_t *min_chunk_size, size_t *align);
@@ -533,9 +545,21 @@ typedef int (*rte_mempool_populate_t)(struct rte_mempool *mp,
 		rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
 
 /**
- * Default way to populate memory pool object using provided memory
+ * Helper to populate memory pool object using provided memory
  * chunk: just slice objects one by one.
  */
+__rte_experimental
+int rte_mempool_op_populate_helper(struct rte_mempool *mp,
+		unsigned int max_objs,
+		void *vaddr, rte_iova_t iova, size_t len,
+		rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
+
+/**
+ * Default way to populate memory pool object using provided memory chunk.
+ *
+ * Equivalent to rte_mempool_op_populate_helper(mp, max_objs, vaddr, iova,
+ * len, obj_cb, obj_cb_arg).
+ */
 int rte_mempool_op_populate_default(struct rte_mempool *mp,
 		unsigned int max_objs,
 		void *vaddr, rte_iova_t iova, size_t len,
lib/librte_mempool/rte_mempool_ops_default.c +25 -6
index f6aea7662..0bfc63497 100644
@@ -7,9 +7,9 @@
 #include <rte_mempool.h>
 
 ssize_t
-rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
-				     uint32_t obj_num, uint32_t pg_shift,
-				     size_t *min_chunk_size, size_t *align)
+rte_mempool_op_calc_mem_size_helper(const struct rte_mempool *mp,
+				uint32_t obj_num, uint32_t pg_shift,
+				size_t *min_chunk_size, size_t *align)
 {
 	size_t total_elt_sz;
 	size_t obj_per_page, pg_sz, objs_in_last_page;
@@ -61,10 +61,19 @@ rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
 	return mem_size;
 }
 
+ssize_t
+rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
+				uint32_t obj_num, uint32_t pg_shift,
+				size_t *min_chunk_size, size_t *align)
+{
+	return rte_mempool_op_calc_mem_size_helper(mp, obj_num, pg_shift,
+						min_chunk_size, align);
+}
+
 int
-rte_mempool_op_populate_default(struct rte_mempool *mp, unsigned int max_objs,
-		void *vaddr, rte_iova_t iova, size_t len,
-		rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg)
+rte_mempool_op_populate_helper(struct rte_mempool *mp, unsigned int max_objs,
+			void *vaddr, rte_iova_t iova, size_t len,
+			rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg)
 {
 	size_t total_elt_sz;
 	size_t off;
@@ -84,3 +93,13 @@ rte_mempool_op_populate_default(struct rte_mempool *mp, unsigned int max_objs,
 
 	return i;
 }
+
+int
+rte_mempool_op_populate_default(struct rte_mempool *mp, unsigned int max_objs,
+				void *vaddr, rte_iova_t iova, size_t len,
+				rte_mempool_populate_obj_cb_t *obj_cb,
+				void *obj_cb_arg)
+{
+	return rte_mempool_op_populate_helper(mp, max_objs, vaddr, iova,
+					len, obj_cb, obj_cb_arg);
+}
lib/librte_mempool/rte_mempool_version.map +2 -0
index 4eff2767d..b5e9c91a9 100644
@@ -57,5 +57,7 @@ EXPERIMENTAL {
 	global:
 
 	rte_mempool_get_page_size;
+	rte_mempool_op_calc_mem_size_helper;
+	rte_mempool_op_populate_helper;
 	rte_mempool_ops_get_info;
 };
Signature · 1 line
2.20.1
Reviewed-by on v3 5/7
#127 lore raw

Re: [dpdk-dev] [PATCH v3 5/7] mempool: introduce helpers for populate and calc mem size

Quoted 8 lines · Olivier Matz

Introduce new functions that can used by mempool drivers to calculate required memory size and to populate mempool.

For now, these helpers just replace the *_default() functions without change. They will be enhanced in next commit.

#128 lore raw

PATCH v3 6/7 mempool: prevent objects from being across pages

In reply to Olivier Matz

When populating a mempool, ensure that objects are not located across several pages, except if user did not request iova contiguous objects.

---
 drivers/mempool/bucket/rte_mempool_bucket.c   |  2 +-
 drivers/mempool/dpaa/dpaa_mempool.c           |  4 +-
 drivers/mempool/dpaa2/dpaa2_hw_mempool.c      |  4 +-
 .../mempool/octeontx/rte_mempool_octeontx.c   | 21 +++---
 drivers/mempool/octeontx2/Makefile            |  3 +
 drivers/mempool/octeontx2/meson.build         |  3 +
 drivers/mempool/octeontx2/otx2_mempool_ops.c  | 21 +++---
 lib/librte_mempool/rte_mempool.c              | 23 ++-----
 lib/librte_mempool/rte_mempool.h              | 24 +++++--
 lib/librte_mempool/rte_mempool_ops_default.c  | 66 +++++++++++++++----
 10 files changed, 115 insertions(+), 56 deletions(-)
drivers/mempool/bucket/rte_mempool_bucket.c +1 -1
index dfeaf4e45..b978fd220 100644
@@ -585,7 +585,7 @@ bucket_populate(struct rte_mempool *mp, unsigned int max_objs,
 
 		hdr->fill_cnt = 0;
 		hdr->lcore_id = LCORE_ID_ANY;
-		rc = rte_mempool_op_populate_helper(mp,
+		rc = rte_mempool_op_populate_helper(mp, 0,
 						     RTE_MIN(bd->obj_per_bucket,
 							     max_objs - n_objs),
 						     iter + bucket_header_sz,
drivers/mempool/dpaa/dpaa_mempool.c +2 -2
index 27736e6c2..3a2528331 100644
@@ -341,8 +341,8 @@ dpaa_populate(struct rte_mempool *mp, unsigned int max_objs,
 	 */
 	TAILQ_INSERT_HEAD(&rte_dpaa_memsegs, ms, next);
 
-	return rte_mempool_op_populate_helper(mp, max_objs, vaddr, paddr, len,
-					       obj_cb, obj_cb_arg);
+	return rte_mempool_op_populate_helper(mp, 0, max_objs, vaddr, paddr,
+					       len, obj_cb, obj_cb_arg);
 }
 
 static const struct rte_mempool_ops dpaa_mpool_ops = {
drivers/mempool/dpaa2/dpaa2_hw_mempool.c +2 -2
index 8f8dbeada..36c93decf 100644
@@ -421,8 +421,8 @@ dpaa2_populate(struct rte_mempool *mp, unsigned int max_objs,
 	/* Insert entry into the PA->VA Table */
 	dpaax_iova_table_update(paddr, vaddr, len);
 
-	return rte_mempool_op_populate_helper(mp, max_objs, vaddr, paddr, len,
-					       obj_cb, obj_cb_arg);
+	return rte_mempool_op_populate_helper(mp, 0, max_objs, vaddr, paddr,
+					       len, obj_cb, obj_cb_arg);
 }
 
 static const struct rte_mempool_ops dpaa2_mpool_ops = {
drivers/mempool/octeontx/rte_mempool_octeontx.c +12 -9
index fff33e5c6..bd0070020 100644
@@ -132,14 +132,15 @@ octeontx_fpavf_calc_mem_size(const struct rte_mempool *mp,
 			     size_t *min_chunk_size, size_t *align)
 {
 	ssize_t mem_size;
+	size_t total_elt_sz;
 
-	/*
-	 * Simply need space for one more object to be able to
-	 * fulfil alignment requirements.
+	/* Need space for one more obj on each chunk to fulfill
+	 * alignment requirements.
 	 */
-	mem_size = rte_mempool_op_calc_mem_size_helper(mp, obj_num + 1,
-							pg_shift,
-							min_chunk_size, align);
+	total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
+	mem_size = rte_mempool_op_calc_mem_size_helper(mp, obj_num, pg_shift,
+						total_elt_sz, min_chunk_size,
+						align);
 	if (mem_size >= 0) {
 		/*
 		 * Memory area which contains objects must be physically
@@ -168,7 +169,7 @@ octeontx_fpavf_populate(struct rte_mempool *mp, unsigned int max_objs,
 	total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
 
 	/* align object start address to a multiple of total_elt_sz */
-	off = total_elt_sz - ((uintptr_t)vaddr % total_elt_sz);
+	off = total_elt_sz - ((((uintptr_t)vaddr - 1) % total_elt_sz) + 1);
 
 	if (len < off)
 		return -EINVAL;
@@ -184,8 +185,10 @@ octeontx_fpavf_populate(struct rte_mempool *mp, unsigned int max_objs,
 	if (ret < 0)
 		return ret;
 
-	return rte_mempool_op_populate_helper(mp, max_objs, vaddr, iova, len,
-					       obj_cb, obj_cb_arg);
+	return rte_mempool_op_populate_helper(mp,
+					RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ,
+					max_objs, vaddr, iova, len,
+					obj_cb, obj_cb_arg);
 }
 
 static struct rte_mempool_ops octeontx_fpavf_ops = {
drivers/mempool/octeontx2/Makefile +3 -0
index 8f55305c5..62e90f277 100644
@@ -30,6 +30,9 @@ EXPORT_MAP := rte_mempool_octeontx2_version.map
 
 LIBABIVER := 1
 
+# for rte_mempool_get_page_size
+CFLAGS += -DALLOW_EXPERIMENTAL_API
+
 #
 # all source are stored in SRCS-y
 #
drivers/mempool/octeontx2/meson.build +3 -0
index 5f93bb495..883b643da 100644
@@ -24,3 +24,6 @@ foreach flag: extra_flags
 endforeach
 
 deps += ['eal', 'mbuf', 'kvargs', 'bus_pci', 'common_octeontx2', 'mempool']
+
+# for rte_mempool_get_page_size
+allow_experimental_apis = true
drivers/mempool/octeontx2/otx2_mempool_ops.c +13 -8
index 3aea92a01..ea4b1c45d 100644
@@ -713,12 +713,15 @@ static ssize_t
 otx2_npa_calc_mem_size(const struct rte_mempool *mp, uint32_t obj_num,
 		       uint32_t pg_shift, size_t *min_chunk_size, size_t *align)
 {
-	/*
-	 * Simply need space for one more object to be able to
-	 * fulfill alignment requirements.
+	size_t total_elt_sz;
+
+	/* Need space for one more obj on each chunk to fulfill
+	 * alignment requirements.
 	 */
-	return rte_mempool_op_calc_mem_size_helper(mp, obj_num + 1, pg_shift,
-						    min_chunk_size, align);
+	total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
+	return rte_mempool_op_calc_mem_size_helper(mp, obj_num, pg_shift,
+						total_elt_sz, min_chunk_size,
+						align);
 }
 
 static int
@@ -735,7 +738,7 @@ otx2_npa_populate(struct rte_mempool *mp, unsigned int max_objs, void *vaddr,
 	total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
 
 	/* Align object start address to a multiple of total_elt_sz */
-	off = total_elt_sz - ((uintptr_t)vaddr % total_elt_sz);
+	off = total_elt_sz - ((((uintptr_t)vaddr - 1) % total_elt_sz) + 1);
 
 	if (len < off)
 		return -EINVAL;
@@ -749,8 +752,10 @@ otx2_npa_populate(struct rte_mempool *mp, unsigned int max_objs, void *vaddr,
 	if (npa_lf_aura_range_update_check(mp->pool_id) < 0)
 		return -EBUSY;
 
-	return rte_mempool_op_populate_helper(mp, max_objs, vaddr, iova, len,
-					       obj_cb, obj_cb_arg);
+	return rte_mempool_op_populate_helper(mp,
+					RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ,
+					max_objs, vaddr, iova, len,
+					obj_cb, obj_cb_arg);
 }
 
 static struct rte_mempool_ops otx2_npa_ops = {
lib/librte_mempool/rte_mempool.c +7 -16
index 758c5410b..d3db9273d 100644
@@ -431,8 +431,6 @@ rte_mempool_get_page_size(struct rte_mempool *mp, size_t *pg_sz)
 
 	if (!need_iova_contig_obj)
 		*pg_sz = 0;
-	else if (!alloc_in_ext_mem && rte_eal_iova_mode() == RTE_IOVA_VA)
-		*pg_sz = 0;
 	else if (rte_eal_has_hugepages() || alloc_in_ext_mem)
 		*pg_sz = get_min_page_size(mp->socket_id);
 	else
@@ -481,17 +479,15 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 	 * then just set page shift and page size to 0, because the user has
 	 * indicated that there's no need to care about anything.
 	 *
-	 * if we do need contiguous objects, there is also an option to reserve
-	 * the entire mempool memory as one contiguous block of memory, in
-	 * which case the page shift and alignment wouldn't matter as well.
+	 * if we do need contiguous objects (if a mempool driver has its
+	 * own calc_size() method returning min_chunk_size = mem_size),
+	 * there is also an option to reserve the entire mempool memory
+	 * as one contiguous block of memory.
 	 *
 	 * if we require contiguous objects, but not necessarily the entire
-	 * mempool reserved space to be contiguous, then there are two options.
-	 *
-	 * if our IO addresses are virtual, not actual physical (IOVA as VA
-	 * case), then no page shift needed - our memory allocation will give us
-	 * contiguous IO memory as far as the hardware is concerned, so
-	 * act as if we're getting contiguous memory.
+	 * mempool reserved space to be contiguous, pg_sz will be != 0,
+	 * and the default ops->populate() will take care of not placing
+	 * objects across pages.
 	 *
 	 * if our IO addresses are physical, we may get memory from bigger
 	 * pages, or we might get memory from smaller pages, and how much of it
@@ -504,11 +500,6 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 	 *
 	 * If we fail to get enough contiguous memory, then we'll go and
 	 * reserve space in smaller chunks.
-	 *
-	 * We also have to take into account the fact that memory that we're
-	 * going to allocate from can belong to an externally allocated memory
-	 * area, in which case the assumption of IOVA as VA mode being
-	 * synonymous with IOVA contiguousness will not hold.
 	 */
 
 	need_iova_contig_obj = !(mp->flags & MEMPOOL_F_NO_IOVA_CONTIG);
lib/librte_mempool/rte_mempool.h +19 -5
index 26a98af30..f1cba3521 100644
@@ -473,6 +473,10 @@ typedef ssize_t (*rte_mempool_calc_mem_size_t)(const struct rte_mempool *mp,
  * Otherwise, it is a number of pages required to store given number of
  * objects without crossing page boundary.
  *
+ * The chunk_reserve argument is the amount of memory that must be
+ * reserved at the beginning of each page, or at the beginning of the
+ * memory area if pg_shift is 0.
+ *
  * Note that if object size is bigger than page size, then it assumes
  * that pages are grouped in subsets of physically continuous pages big
  * enough to store at least one object.
@@ -482,7 +486,7 @@ typedef ssize_t (*rte_mempool_calc_mem_size_t)(const struct rte_mempool *mp,
  */
 __rte_experimental
 ssize_t rte_mempool_op_calc_mem_size_helper(const struct rte_mempool *mp,
-		uint32_t obj_num, uint32_t pg_shift,
+		uint32_t obj_num, uint32_t pg_shift, size_t chunk_reserve,
 		size_t *min_chunk_size, size_t *align);
 
 /**
@@ -490,7 +494,7 @@ ssize_t rte_mempool_op_calc_mem_size_helper(const struct rte_mempool *mp,
  * objects.
  *
  * Equivalent to rte_mempool_op_calc_mem_size_helper(mp, obj_num, pg_shift,
- * min_chunk_size, align).
+ * 0, min_chunk_size, align).
  */
 ssize_t rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
 		uint32_t obj_num, uint32_t pg_shift,
@@ -544,20 +548,30 @@ typedef int (*rte_mempool_populate_t)(struct rte_mempool *mp,
 		void *vaddr, rte_iova_t iova, size_t len,
 		rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
 
+/**
+ * Align objects on addresses multiple of total_elt_sz.
+ */
+#define RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ 0x0001
+
 /**
  * Helper to populate memory pool object using provided memory
- * chunk: just slice objects one by one.
+ * chunk: just slice objects one by one, taking care of not
+ * crossing page boundaries.
+ *
+ * If RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ is set in flags, the addresses
+ * of object headers will be aligned on a multiple of total_elt_sz.
+ * This feature is used by octeontx hardware.
  */
 __rte_experimental
 int rte_mempool_op_populate_helper(struct rte_mempool *mp,
-		unsigned int max_objs,
+		unsigned int flags, unsigned int max_objs,
 		void *vaddr, rte_iova_t iova, size_t len,
 		rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
 
 /**
  * Default way to populate memory pool object using provided memory chunk.
  *
- * Equivalent to rte_mempool_op_populate_helper(mp, max_objs, vaddr, iova,
+ * Equivalent to rte_mempool_op_populate_helper(mp, 0, max_objs, vaddr, iova,
  * len, obj_cb, obj_cb_arg).
  */
 int rte_mempool_op_populate_default(struct rte_mempool *mp,
lib/librte_mempool/rte_mempool_ops_default.c +53 -13

114 lines not on this page · raw message

Signature · 1 line
2.20.1
Acked-by on v3 6/7
#129 lore raw

Re: [dpdk-dev] [PATCH v3 6/7] mempool: prevent objects from being across pages

Quoted 6 lines · Olivier Matz

When populating a mempool, ensure that objects are not located across several pages, except if user did not request iova contiguous objects.

#130 lore raw

PATCH v3 7/7 mempool: use the specific macro for object alignment

In reply to Olivier Matz

For consistency, RTE_MEMPOOL_ALIGN should be used in place of RTE_CACHE_LINE_SIZE. They have the same value, because the only arch that was defining a specific value for it has been removed from dpdk.

---
 drivers/mempool/bucket/rte_mempool_bucket.c  | 8 +++++++-
 lib/librte_mempool/rte_mempool.c             | 2 +-
 lib/librte_mempool/rte_mempool.h             | 3 +++
 lib/librte_mempool/rte_mempool_ops_default.c | 2 +-
 4 files changed, 12 insertions(+), 3 deletions(-)
drivers/mempool/bucket/rte_mempool_bucket.c +7 -1
index b978fd220..5ce1ef16f 100644
@@ -401,6 +401,11 @@ bucket_alloc(struct rte_mempool *mp)
 	struct bucket_data *bd;
 	unsigned int i;
 	unsigned int bucket_header_size;
+	size_t pg_sz;
+
+	rc = rte_mempool_get_page_size(mp, &pg_sz);
+	if (rc < 0)
+		return rc;
 
 	bd = rte_zmalloc_socket("bucket_pool", sizeof(*bd),
 				RTE_CACHE_LINE_SIZE, mp->socket_id);
@@ -416,7 +421,8 @@ bucket_alloc(struct rte_mempool *mp)
 	RTE_BUILD_BUG_ON(sizeof(struct bucket_header) > RTE_CACHE_LINE_SIZE);
 	bd->header_size = mp->header_size + bucket_header_size;
 	bd->total_elt_size = mp->header_size + mp->elt_size + mp->trailer_size;
-	bd->bucket_mem_size = RTE_DRIVER_MEMPOOL_BUCKET_SIZE_KB * 1024;
+	bd->bucket_mem_size = RTE_MIN(pg_sz,
+			(size_t)(RTE_DRIVER_MEMPOOL_BUCKET_SIZE_KB * 1024));
 	bd->obj_per_bucket = (bd->bucket_mem_size - bucket_header_size) /
 		bd->total_elt_size;
 	bd->bucket_page_mask = ~(rte_align64pow2(bd->bucket_mem_size) - 1);
lib/librte_mempool/rte_mempool.c +1 -1
index d3db9273d..40cae3eb6 100644
@@ -329,7 +329,7 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
 	if (mp->flags & MEMPOOL_F_NO_CACHE_ALIGN)
 		off = RTE_PTR_ALIGN_CEIL(vaddr, 8) - vaddr;
 	else
-		off = RTE_PTR_ALIGN_CEIL(vaddr, RTE_CACHE_LINE_SIZE) - vaddr;
+		off = RTE_PTR_ALIGN_CEIL(vaddr, RTE_MEMPOOL_ALIGN) - vaddr;
 
 	if (off > len) {
 		ret = -EINVAL;
lib/librte_mempool/rte_mempool.h +3 -0
index f1cba3521..e9989a87e 100644
@@ -116,6 +116,9 @@ struct rte_mempool_objsz {
 #define	MEMPOOL_PG_NUM_DEFAULT	1
 
 #ifndef RTE_MEMPOOL_ALIGN
+/**
+ * Alignment of elements inside mempool.
+ */
 #define RTE_MEMPOOL_ALIGN	RTE_CACHE_LINE_SIZE
 #endif
 
lib/librte_mempool/rte_mempool_ops_default.c +1 -1
index e6be7152b..22fccf9d7 100644
@@ -60,7 +60,7 @@ rte_mempool_op_calc_mem_size_helper(const struct rte_mempool *mp,
 	}
 
 	*min_chunk_size = total_elt_sz;
-	*align = RTE_CACHE_LINE_SIZE;
+	*align = RTE_MEMPOOL_ALIGN;
 
 	return mem_size;
 }
Signature · 1 line
2.20.1
#131 lore raw

Re: [dpdk-dev] [PATCH v3 7/7] mempool: use the specific macro for object alignment

Quoted 19 lines · Olivier Matz

For consistency, RTE_MEMPOOL_ALIGN should be used in place of RTE_CACHE_LINE_SIZE. They have the same value, because the only arch that was defining a specific value for it has been removed from dpdk.

---
 drivers/mempool/bucket/rte_mempool_bucket.c  | 8 +++++++-
 lib/librte_mempool/rte_mempool.c             | 2 +-
 lib/librte_mempool/rte_mempool.h             | 3 +++
 lib/librte_mempool/rte_mempool_ops_default.c | 2 +-
 4 files changed, 12 insertions(+), 3 deletions(-)
drivers/mempool/bucket/rte_mempool_bucket.c +0 -0
index b978fd220..5ce1ef16f 100644

drivers/mempool/bucket/rte_mempool_bucket.c bucket_alloc(struct rte_mempool *mp) · line 408

Quoted 8 lines
drivers/mempool/bucket/rte_mempool_bucket.c +5 -0
@@ -401,6 +401,11 @@ bucket_alloc(struct rte_mempool *mp)
 	struct bucket_data *bd;
 	unsigned int i;
 	unsigned int bucket_header_size;
+	size_t pg_sz;
+
+	rc = rte_mempool_get_page_size(mp, &pg_sz);
+	if (rc < 0)
+		return rc;

Looks unrelated to the patch.

Quoted 2 lines
drivers/mempool/bucket/rte_mempool_bucket.c +0 -0
 	bd = rte_zmalloc_socket("bucket_pool", sizeof(*bd),
 				RTE_CACHE_LINE_SIZE, mp->socket_id);

[snip]

#132 lore raw

Re: [dpdk-dev] [PATCH v3 7/7] mempool: use the specific macro for object alignment

Quoted 15 lines · Andrew Rybchenko
Quoted 14 lines · Olivier Matz

For consistency, RTE_MEMPOOL_ALIGN should be used in place of RTE_CACHE_LINE_SIZE. They have the same value, because the only arch that was defining a specific value for it has been removed from dpdk.

---
 drivers/mempool/bucket/rte_mempool_bucket.c  | 8 +++++++-
 lib/librte_mempool/rte_mempool.c             | 2 +-
 lib/librte_mempool/rte_mempool.h             | 3 +++
 lib/librte_mempool/rte_mempool_ops_default.c | 2 +-
 4 files changed, 12 insertions(+), 3 deletions(-)
Quoted 15 lines

drivers/mempool/bucket/rte_mempool_bucket.c bucket_alloc(struct rte_mempool *mp) · line 408

Quoted 13 lines
drivers/mempool/bucket/rte_mempool_bucket.c +5 -0
index b978fd220..5ce1ef16f 100644
@@ -401,6 +401,11 @@ bucket_alloc(struct rte_mempool *mp)
 	struct bucket_data *bd;
 	unsigned int i;
 	unsigned int bucket_header_size;
+	size_t pg_sz;
+
+	rc = rte_mempool_get_page_size(mp, &pg_sz);
+	if (rc < 0)
+		return rc;

Looks unrelated to the patch.

Oops, indeed, every change in rte_mempool_bucket.c should be in patch 6/7 "mempool: prevent objects from being across pages", Thanks for spotting it.

Quoted 7 lines
Quoted 3 lines
drivers/mempool/bucket/rte_mempool_bucket.c +0 -0
 	bd = rte_zmalloc_socket("bucket_pool", sizeof(*bd),
 				RTE_CACHE_LINE_SIZE, mp->socket_id);

[snip]

#133 lore raw

v4 cover mempool: avoid objects allocations across pages

In reply to Olivier Matz

KNI supposes that mbufs are contiguous in kernel virtual memory. This may not be true when using the IOVA=VA mode. To fix this, a possibility is to ensure that objects do not cross page boundaries in mempool. This patchset implements this in the last patch (5/5).

The previous patches prepare the job:
- allow to populate with an unaligned virtual area (1/5).
- reduce spaced wasted in the mempool size calculation when not using the iova-contiguous allocation (2/5).
- remove the iova-contiguous allocation when populating mempool (3/5):
a va-contiguous alloc does the job as well if we want to populate without crossing page boundaries, so simplify the mempool populate function.
- export a function to get the minimum page used in a mempool (4/5)

Memory consumption impact when using hugepages:
- worst case: + ~0.1% for a mbuf pool (objsize ~= 2368)
- best case: -50% for if pool size is just above page size

The memory consumption impact with 4K pages in IOVA=VA mode could however consume up to 75% more memory for mbuf pool, because there will be only 1 mbuf per page. Not sure how common this usecase is.

Caveat: this changes the behavior of the mempool (calc_mem_size and populate), and there is a small risk to break things, especially with alternate mempool drivers.

v4

* remove useless comments in Makefiles and meson.build (sugg by David)
* add EXPERIMENTAL banner on new functions in API comments (David)
* sort by version in rte_mempool_version.map (David)
* remove duplicated -DALLOW_EXPERIMENTAL_API flag in octeontx2 mempool driver
* enhance API comments for new helpers

v3

* introduce new helpers to calculate required memory size and to populate mempool, use them in drivers: the alignment constraint of octeontx/octeontx2 is managed in this common code.
* fix octeontx mempool driver by taking alignment constraint in account like in octeontx2
* fix bucket mempool driver with 4K pages: limit bucket size in this case to ensure that objects do not cross page boundaries. With larger pages, it was already ok, because bucket size (64K) is smaller than a page.
* fix some api comments in mempool header file

v2

* update octeontx2 driver to keep alignment constraint (issue seen by Vamsi)
* add a new patch to use RTE_MEMPOOL_ALIGN (Andrew)
* fix initialization of for loop in rte_mempool_populate_virt() (Andrew)
* use rte_mempool_populate_iova() if mz_flags has RTE_MEMZONE_IOVA_CONTIG (Andrew)
* check rte_mempool_get_page_size() return value (Andrew)
* some other minor style improvements

rfc -> v1

* remove first cleanup patch, it was pushed separately a2b5a8722f20 ("mempool: clarify default populate function")
* add missing change in rte_mempool_op_calc_mem_size_default()
* allow unaligned addr/len in populate virt
* better split patches
* try to better explain the change
* use DPDK align macros when relevant

Olivier Matz (7):
mempool: allow unaligned addr/len in populate virt
mempool: reduce wasted space on mempool populate
mempool: remove optimistic IOVA-contiguous allocation
mempool: introduce function to get mempool page size
mempool: introduce helpers for populate and calc mem size
mempool: prevent objects from being across pages
mempool: use the specific macro for object alignment

 drivers/mempool/bucket/Makefile               |   1 +
 drivers/mempool/bucket/meson.build            |   2 +
 drivers/mempool/bucket/rte_mempool_bucket.c   |  10 +-
 drivers/mempool/dpaa/dpaa_mempool.c           |   4 +-
 drivers/mempool/dpaa2/dpaa2_hw_mempool.c      |   4 +-
 drivers/mempool/octeontx/Makefile             |   2 +
 drivers/mempool/octeontx/meson.build          |   2 +
 .../mempool/octeontx/rte_mempool_octeontx.c   |  21 +--
 drivers/mempool/octeontx2/Makefile            |   2 +
 drivers/mempool/octeontx2/meson.build         |   2 +
 drivers/mempool/octeontx2/otx2_mempool_ops.c  |  21 ++-
 lib/librte_mempool/rte_mempool.c              | 147 +++++++-----------
 lib/librte_mempool/rte_mempool.h              | 114 ++++++++++++--
 lib/librte_mempool/rte_mempool_ops.c          |   4 +-
 lib/librte_mempool/rte_mempool_ops_default.c  | 113 +++++++++++---
 lib/librte_mempool/rte_mempool_version.map    |   6 +
 16 files changed, 312 insertions(+), 143 deletions(-)
Signature · 1 line
2.20.1
#134 lore raw

PATCH v4 1/7 mempool: allow unaligned addr/len in populate virt

rte_mempool_populate_virt() currently requires that both addr and length are page-aligned.

Remove this uneeded constraint which can be annoying with big hugepages (ex: 1GB).

---
 lib/librte_mempool/rte_mempool.c | 23 +++++++++++------------
 lib/librte_mempool/rte_mempool.h |  3 +--
 2 files changed, 12 insertions(+), 14 deletions(-)
lib/librte_mempool/rte_mempool.c +11 -12
index 0f29e8712..88e49c751 100644
@@ -368,17 +368,11 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
 	size_t off, phys_len;
 	int ret, cnt = 0;
 
-	/* address and len must be page-aligned */
-	if (RTE_PTR_ALIGN_CEIL(addr, pg_sz) != addr)
-		return -EINVAL;
-	if (RTE_ALIGN_CEIL(len, pg_sz) != len)
-		return -EINVAL;
-
 	if (mp->flags & MEMPOOL_F_NO_IOVA_CONTIG)
 		return rte_mempool_populate_iova(mp, addr, RTE_BAD_IOVA,
 			len, free_cb, opaque);
 
-	for (off = 0; off + pg_sz <= len &&
+	for (off = 0; off < len &&
 		     mp->populated_size < mp->size; off += phys_len) {
 
 		iova = rte_mem_virt2iova(addr + off);
@@ -389,12 +383,18 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
 		}
 
 		/* populate with the largest group of contiguous pages */
-		for (phys_len = pg_sz; off + phys_len < len; phys_len += pg_sz) {
+		for (phys_len = RTE_MIN(
+			(size_t)(RTE_PTR_ALIGN_CEIL(addr + off + 1, pg_sz) -
+				(addr + off)),
+			len - off);
+		     off + phys_len < len;
+		     phys_len = RTE_MIN(phys_len + pg_sz, len - off)) {
 			rte_iova_t iova_tmp;
 
 			iova_tmp = rte_mem_virt2iova(addr + off + phys_len);
 
-			if (iova_tmp != iova + phys_len)
+			if (iova_tmp == RTE_BAD_IOVA ||
+					iova_tmp != iova + phys_len)
 				break;
 		}
 
@@ -575,8 +575,7 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 			 * have
 			 */
 			mz = rte_memzone_reserve_aligned(mz_name, 0,
-					mp->socket_id, flags,
-					RTE_MAX(pg_sz, align));
+					mp->socket_id, flags, align);
 		}
 		if (mz == NULL) {
 			ret = -rte_errno;
@@ -601,7 +600,7 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 				(void *)(uintptr_t)mz);
 		else
 			ret = rte_mempool_populate_virt(mp, mz->addr,
-				RTE_ALIGN_FLOOR(mz->len, pg_sz), pg_sz,
+				mz->len, pg_sz,
 				rte_mempool_memchunk_mz_free,
 				(void *)(uintptr_t)mz);
 		if (ret < 0) {
lib/librte_mempool/rte_mempool.h +1 -2
index 8053f7a04..0fe8aa7b8 100644
@@ -1042,9 +1042,8 @@ int rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
  *   A pointer to the mempool structure.
  * @param addr
  *   The virtual address of memory that should be used to store objects.
- *   Must be page-aligned.
  * @param len
- *   The length of memory in bytes. Must be page-aligned.
+ *   The length of memory in bytes.
  * @param pg_sz
  *   The size of memory pages in this virtual area.
  * @param free_cb
Signature · 1 line
2.20.1
#135 lore raw

PATCH v4 2/7 mempool: reduce wasted space on mempool populate

In reply to Olivier Matz

The size returned by rte_mempool_op_calc_mem_size_default() is aligned to the specified page size. Therefore, with big pages, the returned size can be much more that what we really need to populate the mempool.

For instance, populating a mempool that requires 1.1GB of memory with 1GB hugepages can result in allocating 2GB of memory.

This problem is hidden most of the time due to the allocation method of rte_mempool_populate_default(): when try_iova_contig_mempool=true, it first tries to allocate an iova contiguous area, without the alignment constraint. If it fails, it fallbacks to an aligned allocation that does not require to be iova-contiguous. This can also fallback into several smaller aligned allocations.

This commit changes rte_mempool_op_calc_mem_size_default() to relax the alignment constraint to a cache line and to return a smaller size.

---
 lib/librte_mempool/rte_mempool.c             |  7 ++---
 lib/librte_mempool/rte_mempool.h             |  9 +++----
 lib/librte_mempool/rte_mempool_ops.c         |  4 ++-
 lib/librte_mempool/rte_mempool_ops_default.c | 28 +++++++++++++++-----
 4 files changed, 30 insertions(+), 18 deletions(-)
lib/librte_mempool/rte_mempool.c +2 -5
index 88e49c751..4e0d576f5 100644
@@ -477,11 +477,8 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 	 * wasting some space this way, but it's much nicer than looping around
 	 * trying to reserve each and every page size.
 	 *
-	 * However, since size calculation will produce page-aligned sizes, it
-	 * makes sense to first try and see if we can reserve the entire memzone
-	 * in one contiguous chunk as well (otherwise we might end up wasting a
-	 * 1G page on a 10MB memzone). If we fail to get enough contiguous
-	 * memory, then we'll go and reserve space page-by-page.
+	 * If we fail to get enough contiguous memory, then we'll go and
+	 * reserve space in smaller chunks.
 	 *
 	 * We also have to take into account the fact that memory that we're
 	 * going to allocate from can belong to an externally allocated memory
lib/librte_mempool/rte_mempool.h +3 -6
index 0fe8aa7b8..78b687bb6 100644
@@ -458,7 +458,7 @@ typedef unsigned (*rte_mempool_get_count)(const struct rte_mempool *mp);
  * @param[out] align
  *   Location for required memory chunk alignment.
  * @return
- *   Required memory size aligned at page boundary.
+ *   Required memory size.
  */
 typedef ssize_t (*rte_mempool_calc_mem_size_t)(const struct rte_mempool *mp,
 		uint32_t obj_num,  uint32_t pg_shift,
@@ -477,11 +477,8 @@ typedef ssize_t (*rte_mempool_calc_mem_size_t)(const struct rte_mempool *mp,
  * that pages are grouped in subsets of physically continuous pages big
  * enough to store at least one object.
  *
- * Minimum size of memory chunk is a maximum of the page size and total
- * element size.
- *
- * Required memory chunk alignment is a maximum of page size and cache
- * line size.
+ * Minimum size of memory chunk is the total element size.
+ * Required memory chunk alignment is the cache line size.
  */
 ssize_t rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
 		uint32_t obj_num, uint32_t pg_shift,
lib/librte_mempool/rte_mempool_ops.c +3 -1
index e02eb702c..22c5251eb 100644
@@ -100,7 +100,9 @@ rte_mempool_ops_get_count(const struct rte_mempool *mp)
 	return ops->get_count(mp);
 }
 
-/* wrapper to notify new memory area to external mempool */
+/* wrapper to calculate the memory size required to store given number
+ * of objects
+ */
 ssize_t
 rte_mempool_ops_calc_mem_size(const struct rte_mempool *mp,
 				uint32_t obj_num, uint32_t pg_shift,
lib/librte_mempool/rte_mempool_ops_default.c +22 -6
index 4e2bfc82d..f6aea7662 100644
@@ -12,7 +12,7 @@ rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
 				     size_t *min_chunk_size, size_t *align)
 {
 	size_t total_elt_sz;
-	size_t obj_per_page, pg_num, pg_sz;
+	size_t obj_per_page, pg_sz, objs_in_last_page;
 	size_t mem_size;
 
 	total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
@@ -33,14 +33,30 @@ rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
 			mem_size =
 				RTE_ALIGN_CEIL(total_elt_sz, pg_sz) * obj_num;
 		} else {
-			pg_num = (obj_num + obj_per_page - 1) / obj_per_page;
-			mem_size = pg_num << pg_shift;
+			/* In the best case, the allocator will return a
+			 * page-aligned address. For example, with 5 objs,
+			 * the required space is as below:
+			 *  |     page0     |     page1     |  page2 (last) |
+			 *  |obj0 |obj1 |xxx|obj2 |obj3 |xxx|obj4|
+			 *  <------------- mem_size ------------->
+			 */
+			objs_in_last_page = ((obj_num - 1) % obj_per_page) + 1;
+			/* room required for the last page */
+			mem_size = objs_in_last_page * total_elt_sz;
+			/* room required for other pages */
+			mem_size += ((obj_num - objs_in_last_page) /
+				obj_per_page) << pg_shift;
+
+			/* In the worst case, the allocator returns a
+			 * non-aligned pointer, wasting up to
+			 * total_elt_sz. Add a margin for that.
+			 */
+			 mem_size += total_elt_sz - 1;
 		}
 	}
 
-	*min_chunk_size = RTE_MAX((size_t)1 << pg_shift, total_elt_sz);
-
-	*align = RTE_MAX((size_t)RTE_CACHE_LINE_SIZE, (size_t)1 << pg_shift);
+	*min_chunk_size = total_elt_sz;
+	*align = RTE_CACHE_LINE_SIZE;
 
 	return mem_size;
 }
Signature · 1 line
2.20.1
#136 lore raw

PATCH v4 3/7 mempool: remove optimistic IOVA-contiguous allocation

In reply to Olivier Matz

The previous commit reduced the amount of required memory when populating the mempool with non iova-contiguous memory.

Since there is no big advantage to have a fully iova-contiguous mempool if it is not explicitly asked, remove this code, it simplifies the populate function.

---
 lib/librte_mempool/rte_mempool.c | 47 ++++++--------------------------
 1 file changed, 8 insertions(+), 39 deletions(-)
lib/librte_mempool/rte_mempool.c +8 -39
index 4e0d576f5..213e574fc 100644
@@ -430,7 +430,6 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 	unsigned mz_id, n;
 	int ret;
 	bool need_iova_contig_obj;
-	bool try_iova_contig_mempool;
 	bool alloc_in_ext_mem;
 
 	ret = mempool_ops_alloc_once(mp);
@@ -483,9 +482,7 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 	 * We also have to take into account the fact that memory that we're
 	 * going to allocate from can belong to an externally allocated memory
 	 * area, in which case the assumption of IOVA as VA mode being
-	 * synonymous with IOVA contiguousness will not hold. We should also try
-	 * to go for contiguous memory even if we're in no-huge mode, because
-	 * external memory may in fact be IOVA-contiguous.
+	 * synonymous with IOVA contiguousness will not hold.
 	 */
 
 	/* check if we can retrieve a valid socket ID */
@@ -494,7 +491,6 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 		return -EINVAL;
 	alloc_in_ext_mem = (ret == 1);
 	need_iova_contig_obj = !(mp->flags & MEMPOOL_F_NO_IOVA_CONTIG);
-	try_iova_contig_mempool = false;
 
 	if (!need_iova_contig_obj) {
 		pg_sz = 0;
@@ -503,7 +499,6 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 		pg_sz = 0;
 		pg_shift = 0;
 	} else if (rte_eal_has_hugepages() || alloc_in_ext_mem) {
-		try_iova_contig_mempool = true;
 		pg_sz = get_min_page_size(mp->socket_id);
 		pg_shift = rte_bsf32(pg_sz);
 	} else {
@@ -513,14 +508,9 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 
 	for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) {
 		size_t min_chunk_size;
-		unsigned int flags;
 
-		if (try_iova_contig_mempool || pg_sz == 0)
-			mem_size = rte_mempool_ops_calc_mem_size(mp, n,
-					0, &min_chunk_size, &align);
-		else
-			mem_size = rte_mempool_ops_calc_mem_size(mp, n,
-					pg_shift, &min_chunk_size, &align);
+		mem_size = rte_mempool_ops_calc_mem_size(
+			mp, n, pg_shift, &min_chunk_size, &align);
 
 		if (mem_size < 0) {
 			ret = mem_size;
@@ -534,36 +524,15 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 			goto fail;
 		}
 
-		flags = mz_flags;
-
 		/* if we're trying to reserve contiguous memory, add appropriate
 		 * memzone flag.
 		 */
-		if (try_iova_contig_mempool)
-			flags |= RTE_MEMZONE_IOVA_CONTIG;
+		if (min_chunk_size == (size_t)mem_size)
+			mz_flags |= RTE_MEMZONE_IOVA_CONTIG;
 
 		mz = rte_memzone_reserve_aligned(mz_name, mem_size,
-				mp->socket_id, flags, align);
-
-		/* if we were trying to allocate contiguous memory, failed and
-		 * minimum required contiguous chunk fits minimum page, adjust
-		 * memzone size to the page size, and try again.
-		 */
-		if (mz == NULL && try_iova_contig_mempool &&
-				min_chunk_size <= pg_sz) {
-			try_iova_contig_mempool = false;
-			flags &= ~RTE_MEMZONE_IOVA_CONTIG;
-
-			mem_size = rte_mempool_ops_calc_mem_size(mp, n,
-					pg_shift, &min_chunk_size, &align);
-			if (mem_size < 0) {
-				ret = mem_size;
-				goto fail;
-			}
+				mp->socket_id, mz_flags, align);
 
-			mz = rte_memzone_reserve_aligned(mz_name, mem_size,
-				mp->socket_id, flags, align);
-		}
 		/* don't try reserving with 0 size if we were asked to reserve
 		 * IOVA-contiguous memory.
 		 */
@@ -572,7 +541,7 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 			 * have
 			 */
 			mz = rte_memzone_reserve_aligned(mz_name, 0,
-					mp->socket_id, flags, align);
+					mp->socket_id, mz_flags, align);
 		}
 		if (mz == NULL) {
 			ret = -rte_errno;
@@ -590,7 +559,7 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 		else
 			iova = RTE_BAD_IOVA;
 
-		if (try_iova_contig_mempool || pg_sz == 0)
+		if (pg_sz == 0 || (mz_flags & RTE_MEMZONE_IOVA_CONTIG))
 			ret = rte_mempool_populate_iova(mp, mz->addr,
 				iova, mz->len,
 				rte_mempool_memchunk_mz_free,
Signature · 1 line
2.20.1
#137 lore raw

PATCH v4 4/7 mempool: introduce function to get mempool page size

In reply to Olivier Matz

In rte_mempool_populate_default(), we determine the page size, which is needed for calc_size and allocation of memory.

Move this in a function and export it, it will be used in a next commit.

---
 lib/librte_mempool/rte_mempool.c           | 51 ++++++++++++++--------
 lib/librte_mempool/rte_mempool.h           | 11 +++++
 lib/librte_mempool/rte_mempool_version.map |  4 ++
 3 files changed, 47 insertions(+), 19 deletions(-)
lib/librte_mempool/rte_mempool.c +32 -19
index 213e574fc..758c5410b 100644
@@ -414,6 +414,33 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
 	return ret;
 }
 
+/* Get the minimal page size used in a mempool before populating it. */
+int
+rte_mempool_get_page_size(struct rte_mempool *mp, size_t *pg_sz)
+{
+	bool need_iova_contig_obj;
+	bool alloc_in_ext_mem;
+	int ret;
+
+	/* check if we can retrieve a valid socket ID */
+	ret = rte_malloc_heap_socket_is_external(mp->socket_id);
+	if (ret < 0)
+		return -EINVAL;
+	alloc_in_ext_mem = (ret == 1);
+	need_iova_contig_obj = !(mp->flags & MEMPOOL_F_NO_IOVA_CONTIG);
+
+	if (!need_iova_contig_obj)
+		*pg_sz = 0;
+	else if (!alloc_in_ext_mem && rte_eal_iova_mode() == RTE_IOVA_VA)
+		*pg_sz = 0;
+	else if (rte_eal_has_hugepages() || alloc_in_ext_mem)
+		*pg_sz = get_min_page_size(mp->socket_id);
+	else
+		*pg_sz = getpagesize();
+
+	return 0;
+}
+
 /* Default function to populate the mempool: allocate memory in memzones,
  * and populate them. Return the number of objects added, or a negative
  * value on error.
@@ -425,12 +452,11 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 	char mz_name[RTE_MEMZONE_NAMESIZE];
 	const struct rte_memzone *mz;
 	ssize_t mem_size;
-	size_t align, pg_sz, pg_shift;
+	size_t align, pg_sz, pg_shift = 0;
 	rte_iova_t iova;
 	unsigned mz_id, n;
 	int ret;
 	bool need_iova_contig_obj;
-	bool alloc_in_ext_mem;
 
 	ret = mempool_ops_alloc_once(mp);
 	if (ret != 0)
@@ -485,26 +511,13 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 	 * synonymous with IOVA contiguousness will not hold.
 	 */
 
-	/* check if we can retrieve a valid socket ID */
-	ret = rte_malloc_heap_socket_is_external(mp->socket_id);
-	if (ret < 0)
-		return -EINVAL;
-	alloc_in_ext_mem = (ret == 1);
 	need_iova_contig_obj = !(mp->flags & MEMPOOL_F_NO_IOVA_CONTIG);
+	ret = rte_mempool_get_page_size(mp, &pg_sz);
+	if (ret < 0)
+		return ret;
 
-	if (!need_iova_contig_obj) {
-		pg_sz = 0;
-		pg_shift = 0;
-	} else if (!alloc_in_ext_mem && rte_eal_iova_mode() == RTE_IOVA_VA) {
-		pg_sz = 0;
-		pg_shift = 0;
-	} else if (rte_eal_has_hugepages() || alloc_in_ext_mem) {
-		pg_sz = get_min_page_size(mp->socket_id);
-		pg_shift = rte_bsf32(pg_sz);
-	} else {
-		pg_sz = getpagesize();
+	if (pg_sz != 0)
 		pg_shift = rte_bsf32(pg_sz);
-	}
 
 	for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) {
 		size_t min_chunk_size;
lib/librte_mempool/rte_mempool.h +11 -0
index 78b687bb6..9e41f595e 100644
@@ -1688,6 +1688,17 @@ uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
 void rte_mempool_walk(void (*func)(struct rte_mempool *, void *arg),
 		      void *arg);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * @internal Get page size used for mempool object allocation.
+ * This function is internal to mempool library and mempool drivers.
+ */
+__rte_experimental
+int
+rte_mempool_get_page_size(struct rte_mempool *mp, size_t *pg_sz);
+
 #ifdef __cplusplus
 }
 #endif
lib/librte_mempool/rte_mempool_version.map +4 -0
index 17cbca460..aa75cf086 100644
@@ -56,5 +56,9 @@ DPDK_18.05 {
 EXPERIMENTAL {
 	global:
 
+	# added in 18.05
 	rte_mempool_ops_get_info;
+
+	# added in 19.11
+	rte_mempool_get_page_size;
 };
Signature · 1 line
2.20.1
#138 lore raw

PATCH v4 5/7 mempool: introduce helpers for populate and calc mem size

In reply to Olivier Matz

Introduce new functions that can used by mempool drivers to calculate required memory size and to populate mempool.

For now, these helpers just replace the *_default() functions without change. They will be enhanced in next commit.

---
 drivers/mempool/bucket/Makefile               |  1 +
 drivers/mempool/bucket/meson.build            |  2 +
 drivers/mempool/bucket/rte_mempool_bucket.c   |  2 +-
 drivers/mempool/dpaa/dpaa_mempool.c           |  2 +-
 drivers/mempool/dpaa2/dpaa2_hw_mempool.c      |  2 +-
 drivers/mempool/octeontx/Makefile             |  2 +
 drivers/mempool/octeontx/meson.build          |  2 +
 .../mempool/octeontx/rte_mempool_octeontx.c   |  4 +-
 drivers/mempool/octeontx2/Makefile            |  2 +
 drivers/mempool/octeontx2/meson.build         |  2 +
 drivers/mempool/octeontx2/otx2_mempool_ops.c  |  4 +-
 lib/librte_mempool/rte_mempool.h              | 71 ++++++++++++++++++-
 lib/librte_mempool/rte_mempool_ops_default.c  | 31 ++++++--
 lib/librte_mempool/rte_mempool_version.map    |  2 +
 14 files changed, 113 insertions(+), 16 deletions(-)
drivers/mempool/bucket/Makefile +1 -0
index 7364916bc..d6660b09c 100644
@@ -15,6 +15,7 @@ LIB = librte_mempool_bucket.a
 
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
+CFLAGS += -DALLOW_EXPERIMENTAL_API
 
 LDLIBS += -lrte_eal -lrte_mempool -lrte_ring
 
drivers/mempool/bucket/meson.build +2 -0
index 618d79128..2fd77f9d4 100644
@@ -6,4 +6,6 @@
 # This software was jointly developed between OKTET Labs (under contract
 # for Solarflare) and Solarflare Communications, Inc.
 
+allow_experimental_apis = true
+
 sources = files('rte_mempool_bucket.c')
drivers/mempool/bucket/rte_mempool_bucket.c +1 -1
index 78d2b9d04..dfeaf4e45 100644
@@ -585,7 +585,7 @@ bucket_populate(struct rte_mempool *mp, unsigned int max_objs,
 
 		hdr->fill_cnt = 0;
 		hdr->lcore_id = LCORE_ID_ANY;
-		rc = rte_mempool_op_populate_default(mp,
+		rc = rte_mempool_op_populate_helper(mp,
 						     RTE_MIN(bd->obj_per_bucket,
 							     max_objs - n_objs),
 						     iter + bucket_header_sz,
drivers/mempool/dpaa/dpaa_mempool.c +1 -1
index a25697f05..27736e6c2 100644
@@ -341,7 +341,7 @@ dpaa_populate(struct rte_mempool *mp, unsigned int max_objs,
 	 */
 	TAILQ_INSERT_HEAD(&rte_dpaa_memsegs, ms, next);
 
-	return rte_mempool_op_populate_default(mp, max_objs, vaddr, paddr, len,
+	return rte_mempool_op_populate_helper(mp, max_objs, vaddr, paddr, len,
 					       obj_cb, obj_cb_arg);
 }
 
drivers/mempool/dpaa2/dpaa2_hw_mempool.c +1 -1
index f26c30b00..8f8dbeada 100644
@@ -421,7 +421,7 @@ dpaa2_populate(struct rte_mempool *mp, unsigned int max_objs,
 	/* Insert entry into the PA->VA Table */
 	dpaax_iova_table_update(paddr, vaddr, len);
 
-	return rte_mempool_op_populate_default(mp, max_objs, vaddr, paddr, len,
+	return rte_mempool_op_populate_helper(mp, max_objs, vaddr, paddr, len,
 					       obj_cb, obj_cb_arg);
 }
 
drivers/mempool/octeontx/Makefile +2 -0
index a3e1dce88..25efc5cf2 100644
@@ -11,6 +11,8 @@ LIB = librte_mempool_octeontx.a
 
 CFLAGS += $(WERROR_FLAGS)
 CFLAGS += -I$(RTE_SDK)/drivers/common/octeontx/
+CFLAGS += -DALLOW_EXPERIMENTAL_API
+
 EXPORT_MAP := rte_mempool_octeontx_version.map
 
 LIBABIVER := 1
drivers/mempool/octeontx/meson.build +2 -0
index 3baaf7db2..195435950 100644
@@ -1,6 +1,8 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Cavium, Inc
 
+allow_experimental_apis = true
+
 sources = files('octeontx_fpavf.c',
 		'rte_mempool_octeontx.c'
 )
drivers/mempool/octeontx/rte_mempool_octeontx.c +2 -2
index ab94dfe91..fff33e5c6 100644
@@ -137,7 +137,7 @@ octeontx_fpavf_calc_mem_size(const struct rte_mempool *mp,
 	 * Simply need space for one more object to be able to
 	 * fulfil alignment requirements.
 	 */
-	mem_size = rte_mempool_op_calc_mem_size_default(mp, obj_num + 1,
+	mem_size = rte_mempool_op_calc_mem_size_helper(mp, obj_num + 1,
 							pg_shift,
 							min_chunk_size, align);
 	if (mem_size >= 0) {
@@ -184,7 +184,7 @@ octeontx_fpavf_populate(struct rte_mempool *mp, unsigned int max_objs,
 	if (ret < 0)
 		return ret;
 
-	return rte_mempool_op_populate_default(mp, max_objs, vaddr, iova, len,
+	return rte_mempool_op_populate_helper(mp, max_objs, vaddr, iova, len,
 					       obj_cb, obj_cb_arg);
 }
 
drivers/mempool/octeontx2/Makefile +2 -0
index 87cce22c6..4961a4a35 100644
@@ -23,6 +23,8 @@ CFLAGS += -diag-disable 2259
 endif
 endif
 
+CFLAGS += -DALLOW_EXPERIMENTAL_API
+
 EXPORT_MAP := rte_mempool_octeontx2_version.map
 
 LIBABIVER := 1
drivers/mempool/octeontx2/meson.build +2 -0
index 9fde40f0e..8255377df 100644
@@ -2,6 +2,8 @@
 # Copyright(C) 2019 Marvell International Ltd.
 #
 
+allow_experimental_apis = true
+
 sources = files('otx2_mempool_ops.c',
 		'otx2_mempool.c',
 		'otx2_mempool_irq.c',
drivers/mempool/octeontx2/otx2_mempool_ops.c +2 -2
index d769575f4..3aea92a01 100644
@@ -717,7 +717,7 @@ otx2_npa_calc_mem_size(const struct rte_mempool *mp, uint32_t obj_num,
 	 * Simply need space for one more object to be able to
 	 * fulfill alignment requirements.
 	 */
-	return rte_mempool_op_calc_mem_size_default(mp, obj_num + 1, pg_shift,
+	return rte_mempool_op_calc_mem_size_helper(mp, obj_num + 1, pg_shift,
 						    min_chunk_size, align);
 }
 
@@ -749,7 +749,7 @@ otx2_npa_populate(struct rte_mempool *mp, unsigned int max_objs, void *vaddr,
 	if (npa_lf_aura_range_update_check(mp->pool_id) < 0)
 		return -EBUSY;
 
-	return rte_mempool_op_populate_default(mp, max_objs, vaddr, iova, len,
+	return rte_mempool_op_populate_helper(mp, max_objs, vaddr, iova, len,
 					       obj_cb, obj_cb_arg);
 }
 
lib/librte_mempool/rte_mempool.h +68 -3

90 lines not on this page · raw message

lib/librte_mempool/rte_mempool_ops_default.c +25 -6
index f6aea7662..0bfc63497 100644
@@ -7,9 +7,9 @@
 #include <rte_mempool.h>
 
 ssize_t
-rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
-				     uint32_t obj_num, uint32_t pg_shift,
-				     size_t *min_chunk_size, size_t *align)
+rte_mempool_op_calc_mem_size_helper(const struct rte_mempool *mp,
+				uint32_t obj_num, uint32_t pg_shift,
+				size_t *min_chunk_size, size_t *align)
 {
 	size_t total_elt_sz;
 	size_t obj_per_page, pg_sz, objs_in_last_page;
@@ -61,10 +61,19 @@ rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
 	return mem_size;
 }
 
+ssize_t
+rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
+				uint32_t obj_num, uint32_t pg_shift,
+				size_t *min_chunk_size, size_t *align)
+{
+	return rte_mempool_op_calc_mem_size_helper(mp, obj_num, pg_shift,
+						min_chunk_size, align);
+}
+
 int
-rte_mempool_op_populate_default(struct rte_mempool *mp, unsigned int max_objs,
-		void *vaddr, rte_iova_t iova, size_t len,
-		rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg)
+rte_mempool_op_populate_helper(struct rte_mempool *mp, unsigned int max_objs,
+			void *vaddr, rte_iova_t iova, size_t len,
+			rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg)
 {
 	size_t total_elt_sz;
 	size_t off;
@@ -84,3 +93,13 @@ rte_mempool_op_populate_default(struct rte_mempool *mp, unsigned int max_objs,
 
 	return i;
 }
+
+int
+rte_mempool_op_populate_default(struct rte_mempool *mp, unsigned int max_objs,
+				void *vaddr, rte_iova_t iova, size_t len,
+				rte_mempool_populate_obj_cb_t *obj_cb,
+				void *obj_cb_arg)
+{
+	return rte_mempool_op_populate_helper(mp, max_objs, vaddr, iova,
+					len, obj_cb, obj_cb_arg);
+}
lib/librte_mempool/rte_mempool_version.map +2 -0
index aa75cf086..ce9e791e7 100644
@@ -61,4 +61,6 @@ EXPERIMENTAL {
 
 	# added in 19.11
 	rte_mempool_get_page_size;
+	rte_mempool_op_calc_mem_size_helper;
+	rte_mempool_op_populate_helper;
 };
Signature · 1 line
2.20.1
#139 lore raw

PATCH v4 6/7 mempool: prevent objects from being across pages

In reply to Olivier Matz

When populating a mempool, ensure that objects are not located across several pages, except if user did not request iova contiguous objects.

---
 drivers/mempool/bucket/rte_mempool_bucket.c   | 10 ++-
 drivers/mempool/dpaa/dpaa_mempool.c           |  4 +-
 drivers/mempool/dpaa2/dpaa2_hw_mempool.c      |  4 +-
 .../mempool/octeontx/rte_mempool_octeontx.c   | 21 +++---
 drivers/mempool/octeontx2/otx2_mempool_ops.c  | 21 +++---
 lib/librte_mempool/rte_mempool.c              | 23 ++-----
 lib/librte_mempool/rte_mempool.h              | 27 ++++++--
 lib/librte_mempool/rte_mempool_ops_default.c  | 66 +++++++++++++++----
 8 files changed, 119 insertions(+), 57 deletions(-)
drivers/mempool/bucket/rte_mempool_bucket.c +8 -2
index dfeaf4e45..5ce1ef16f 100644
@@ -401,6 +401,11 @@ bucket_alloc(struct rte_mempool *mp)
 	struct bucket_data *bd;
 	unsigned int i;
 	unsigned int bucket_header_size;
+	size_t pg_sz;
+
+	rc = rte_mempool_get_page_size(mp, &pg_sz);
+	if (rc < 0)
+		return rc;
 
 	bd = rte_zmalloc_socket("bucket_pool", sizeof(*bd),
 				RTE_CACHE_LINE_SIZE, mp->socket_id);
@@ -416,7 +421,8 @@ bucket_alloc(struct rte_mempool *mp)
 	RTE_BUILD_BUG_ON(sizeof(struct bucket_header) > RTE_CACHE_LINE_SIZE);
 	bd->header_size = mp->header_size + bucket_header_size;
 	bd->total_elt_size = mp->header_size + mp->elt_size + mp->trailer_size;
-	bd->bucket_mem_size = RTE_DRIVER_MEMPOOL_BUCKET_SIZE_KB * 1024;
+	bd->bucket_mem_size = RTE_MIN(pg_sz,
+			(size_t)(RTE_DRIVER_MEMPOOL_BUCKET_SIZE_KB * 1024));
 	bd->obj_per_bucket = (bd->bucket_mem_size - bucket_header_size) /
 		bd->total_elt_size;
 	bd->bucket_page_mask = ~(rte_align64pow2(bd->bucket_mem_size) - 1);
@@ -585,7 +591,7 @@ bucket_populate(struct rte_mempool *mp, unsigned int max_objs,
 
 		hdr->fill_cnt = 0;
 		hdr->lcore_id = LCORE_ID_ANY;
-		rc = rte_mempool_op_populate_helper(mp,
+		rc = rte_mempool_op_populate_helper(mp, 0,
 						     RTE_MIN(bd->obj_per_bucket,
 							     max_objs - n_objs),
 						     iter + bucket_header_sz,
drivers/mempool/dpaa/dpaa_mempool.c +2 -2
index 27736e6c2..3a2528331 100644
@@ -341,8 +341,8 @@ dpaa_populate(struct rte_mempool *mp, unsigned int max_objs,
 	 */
 	TAILQ_INSERT_HEAD(&rte_dpaa_memsegs, ms, next);
 
-	return rte_mempool_op_populate_helper(mp, max_objs, vaddr, paddr, len,
-					       obj_cb, obj_cb_arg);
+	return rte_mempool_op_populate_helper(mp, 0, max_objs, vaddr, paddr,
+					       len, obj_cb, obj_cb_arg);
 }
 
 static const struct rte_mempool_ops dpaa_mpool_ops = {
drivers/mempool/dpaa2/dpaa2_hw_mempool.c +2 -2
index 8f8dbeada..36c93decf 100644
@@ -421,8 +421,8 @@ dpaa2_populate(struct rte_mempool *mp, unsigned int max_objs,
 	/* Insert entry into the PA->VA Table */
 	dpaax_iova_table_update(paddr, vaddr, len);
 
-	return rte_mempool_op_populate_helper(mp, max_objs, vaddr, paddr, len,
-					       obj_cb, obj_cb_arg);
+	return rte_mempool_op_populate_helper(mp, 0, max_objs, vaddr, paddr,
+					       len, obj_cb, obj_cb_arg);
 }
 
 static const struct rte_mempool_ops dpaa2_mpool_ops = {
drivers/mempool/octeontx/rte_mempool_octeontx.c +12 -9
index fff33e5c6..bd0070020 100644
@@ -132,14 +132,15 @@ octeontx_fpavf_calc_mem_size(const struct rte_mempool *mp,
 			     size_t *min_chunk_size, size_t *align)
 {
 	ssize_t mem_size;
+	size_t total_elt_sz;
 
-	/*
-	 * Simply need space for one more object to be able to
-	 * fulfil alignment requirements.
+	/* Need space for one more obj on each chunk to fulfill
+	 * alignment requirements.
 	 */
-	mem_size = rte_mempool_op_calc_mem_size_helper(mp, obj_num + 1,
-							pg_shift,
-							min_chunk_size, align);
+	total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
+	mem_size = rte_mempool_op_calc_mem_size_helper(mp, obj_num, pg_shift,
+						total_elt_sz, min_chunk_size,
+						align);
 	if (mem_size >= 0) {
 		/*
 		 * Memory area which contains objects must be physically
@@ -168,7 +169,7 @@ octeontx_fpavf_populate(struct rte_mempool *mp, unsigned int max_objs,
 	total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
 
 	/* align object start address to a multiple of total_elt_sz */
-	off = total_elt_sz - ((uintptr_t)vaddr % total_elt_sz);
+	off = total_elt_sz - ((((uintptr_t)vaddr - 1) % total_elt_sz) + 1);
 
 	if (len < off)
 		return -EINVAL;
@@ -184,8 +185,10 @@ octeontx_fpavf_populate(struct rte_mempool *mp, unsigned int max_objs,
 	if (ret < 0)
 		return ret;
 
-	return rte_mempool_op_populate_helper(mp, max_objs, vaddr, iova, len,
-					       obj_cb, obj_cb_arg);
+	return rte_mempool_op_populate_helper(mp,
+					RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ,
+					max_objs, vaddr, iova, len,
+					obj_cb, obj_cb_arg);
 }
 
 static struct rte_mempool_ops octeontx_fpavf_ops = {
drivers/mempool/octeontx2/otx2_mempool_ops.c +13 -8
index 3aea92a01..ea4b1c45d 100644
@@ -713,12 +713,15 @@ static ssize_t
 otx2_npa_calc_mem_size(const struct rte_mempool *mp, uint32_t obj_num,
 		       uint32_t pg_shift, size_t *min_chunk_size, size_t *align)
 {
-	/*
-	 * Simply need space for one more object to be able to
-	 * fulfill alignment requirements.
+	size_t total_elt_sz;
+
+	/* Need space for one more obj on each chunk to fulfill
+	 * alignment requirements.
 	 */
-	return rte_mempool_op_calc_mem_size_helper(mp, obj_num + 1, pg_shift,
-						    min_chunk_size, align);
+	total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
+	return rte_mempool_op_calc_mem_size_helper(mp, obj_num, pg_shift,
+						total_elt_sz, min_chunk_size,
+						align);
 }
 
 static int
@@ -735,7 +738,7 @@ otx2_npa_populate(struct rte_mempool *mp, unsigned int max_objs, void *vaddr,
 	total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
 
 	/* Align object start address to a multiple of total_elt_sz */
-	off = total_elt_sz - ((uintptr_t)vaddr % total_elt_sz);
+	off = total_elt_sz - ((((uintptr_t)vaddr - 1) % total_elt_sz) + 1);
 
 	if (len < off)
 		return -EINVAL;
@@ -749,8 +752,10 @@ otx2_npa_populate(struct rte_mempool *mp, unsigned int max_objs, void *vaddr,
 	if (npa_lf_aura_range_update_check(mp->pool_id) < 0)
 		return -EBUSY;
 
-	return rte_mempool_op_populate_helper(mp, max_objs, vaddr, iova, len,
-					       obj_cb, obj_cb_arg);
+	return rte_mempool_op_populate_helper(mp,
+					RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ,
+					max_objs, vaddr, iova, len,
+					obj_cb, obj_cb_arg);
 }
 
 static struct rte_mempool_ops otx2_npa_ops = {
lib/librte_mempool/rte_mempool.c +7 -16
index 758c5410b..d3db9273d 100644
@@ -431,8 +431,6 @@ rte_mempool_get_page_size(struct rte_mempool *mp, size_t *pg_sz)
 
 	if (!need_iova_contig_obj)
 		*pg_sz = 0;
-	else if (!alloc_in_ext_mem && rte_eal_iova_mode() == RTE_IOVA_VA)
-		*pg_sz = 0;
 	else if (rte_eal_has_hugepages() || alloc_in_ext_mem)
 		*pg_sz = get_min_page_size(mp->socket_id);
 	else
@@ -481,17 +479,15 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 	 * then just set page shift and page size to 0, because the user has
 	 * indicated that there's no need to care about anything.
 	 *
-	 * if we do need contiguous objects, there is also an option to reserve
-	 * the entire mempool memory as one contiguous block of memory, in
-	 * which case the page shift and alignment wouldn't matter as well.
+	 * if we do need contiguous objects (if a mempool driver has its
+	 * own calc_size() method returning min_chunk_size = mem_size),
+	 * there is also an option to reserve the entire mempool memory
+	 * as one contiguous block of memory.
 	 *
 	 * if we require contiguous objects, but not necessarily the entire
-	 * mempool reserved space to be contiguous, then there are two options.
-	 *
-	 * if our IO addresses are virtual, not actual physical (IOVA as VA
-	 * case), then no page shift needed - our memory allocation will give us
-	 * contiguous IO memory as far as the hardware is concerned, so
-	 * act as if we're getting contiguous memory.
+	 * mempool reserved space to be contiguous, pg_sz will be != 0,
+	 * and the default ops->populate() will take care of not placing
+	 * objects across pages.
 	 *
 	 * if our IO addresses are physical, we may get memory from bigger
 	 * pages, or we might get memory from smaller pages, and how much of it
@@ -504,11 +500,6 @@ rte_mempool_populate_default(struct rte_mempool *mp)
 	 *
 	 * If we fail to get enough contiguous memory, then we'll go and
 	 * reserve space in smaller chunks.
-	 *
-	 * We also have to take into account the fact that memory that we're
-	 * going to allocate from can belong to an externally allocated memory
-	 * area, in which case the assumption of IOVA as VA mode being
-	 * synonymous with IOVA contiguousness will not hold.
 	 */
 
 	need_iova_contig_obj = !(mp->flags & MEMPOOL_F_NO_IOVA_CONTIG);
lib/librte_mempool/rte_mempool.h +22 -5
index ad7cc6ad2..225bf9fc9 100644
@@ -491,6 +491,9 @@ typedef ssize_t (*rte_mempool_calc_mem_size_t)(const struct rte_mempool *mp,
  *   Number of objects to be added in mempool.
  * @param[in] pg_shift
  *   LOG2 of the physical pages size. If set to 0, ignore page boundaries.
+ * @param[in] chunk_reserve
+ *   Amount of memory that must be reserved at the beginning of each page,
+ *   or at the beginning of the memory area if pg_shift is 0.
  * @param[out] min_chunk_size
  *   Location for minimum size of the memory chunk which may be used to
  *   store memory pool objects.
@@ -501,7 +504,7 @@ typedef ssize_t (*rte_mempool_calc_mem_size_t)(const struct rte_mempool *mp,
  */
 __rte_experimental
 ssize_t rte_mempool_op_calc_mem_size_helper(const struct rte_mempool *mp,
-		uint32_t obj_num, uint32_t pg_shift,
+		uint32_t obj_num, uint32_t pg_shift, size_t chunk_reserve,
 		size_t *min_chunk_size, size_t *align);
 
 /**
@@ -509,7 +512,7 @@ ssize_t rte_mempool_op_calc_mem_size_helper(const struct rte_mempool *mp,
  * objects.
  *
  * Equivalent to rte_mempool_op_calc_mem_size_helper(mp, obj_num, pg_shift,
- * min_chunk_size, align).
+ * 0, min_chunk_size, align).
  */
 ssize_t rte_mempool_op_calc_mem_size_default(const struct rte_mempool *mp,
 		uint32_t obj_num, uint32_t pg_shift,
@@ -563,17 +566,31 @@ typedef int (*rte_mempool_populate_t)(struct rte_mempool *mp,
 		void *vaddr, rte_iova_t iova, size_t len,
 		rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
 
+/**
+ * Align objects on addresses multiple of total_elt_sz.
+ */
+#define RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ 0x0001
+
 /**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
  *
  * @internal Helper to populate memory pool object using provided memory
- * chunk: just slice objects one by one.
+ * chunk: just slice objects one by one, taking care of not
+ * crossing page boundaries.
+ *
+ * If RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ is set in flags, the addresses
+ * of object headers will be aligned on a multiple of total_elt_sz.
+ * This feature is used by octeontx hardware.
  *
  * This function is internal to mempool library and mempool drivers.
  *
  * @param[in] mp
  *   A pointer to the mempool structure.
+ * @param[in] flags
+ *   Logical OR of following flags:
+ *   - RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ: align objects on addresses
+ *     multiple of total_elt_sz.
  * @param[in] max_objs
  *   Maximum number of objects to be added in mempool.
  * @param[in] vaddr
@@ -591,14 +608,14 @@ typedef int (*rte_mempool_populate_t)(struct rte_mempool *mp,
  */
 __rte_experimental
 int rte_mempool_op_populate_helper(struct rte_mempool *mp,
-		unsigned int max_objs,
+		unsigned int flags, unsigned int max_objs,
 		void *vaddr, rte_iova_t iova, size_t len,
 		rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg);
 
 /**
  * Default way to populate memory pool object using provided memory chunk.
  *
- * Equivalent to rte_mempool_op_populate_helper(mp, max_objs, vaddr, iova,
+ * Equivalent to rte_mempool_op_populate_helper(mp, 0, max_objs, vaddr, iova,
  * len, obj_cb, obj_cb_arg).
  */
 int rte_mempool_op_populate_default(struct rte_mempool *mp,
lib/librte_mempool/rte_mempool_ops_default.c +53 -13

114 lines not on this page · raw message

Signature · 1 line
2.20.1
#140 lore raw

PATCH v4 7/7 mempool: use the specific macro for object alignment

In reply to Olivier Matz

For consistency, RTE_MEMPOOL_ALIGN should be used in place of RTE_CACHE_LINE_SIZE. They have the same value, because the only arch that was defining a specific value for it has been removed from dpdk.

---
 lib/librte_mempool/rte_mempool.c             | 2 +-
 lib/librte_mempool/rte_mempool.h             | 3 +++
 lib/librte_mempool/rte_mempool_ops_default.c | 2 +-
 3 files changed, 5 insertions(+), 2 deletions(-)
lib/librte_mempool/rte_mempool.c +1 -1
index d3db9273d..40cae3eb6 100644
@@ -329,7 +329,7 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
 	if (mp->flags & MEMPOOL_F_NO_CACHE_ALIGN)
 		off = RTE_PTR_ALIGN_CEIL(vaddr, 8) - vaddr;
 	else
-		off = RTE_PTR_ALIGN_CEIL(vaddr, RTE_CACHE_LINE_SIZE) - vaddr;
+		off = RTE_PTR_ALIGN_CEIL(vaddr, RTE_MEMPOOL_ALIGN) - vaddr;
 
 	if (off > len) {
 		ret = -EINVAL;
lib/librte_mempool/rte_mempool.h +3 -0
index 225bf9fc9..f81152af9 100644
@@ -116,6 +116,9 @@ struct rte_mempool_objsz {
 #define	MEMPOOL_PG_NUM_DEFAULT	1
 
 #ifndef RTE_MEMPOOL_ALIGN
+/**
+ * Alignment of elements inside mempool.
+ */
 #define RTE_MEMPOOL_ALIGN	RTE_CACHE_LINE_SIZE
 #endif
 
lib/librte_mempool/rte_mempool_ops_default.c +1 -1
index e6be7152b..22fccf9d7 100644
@@ -60,7 +60,7 @@ rte_mempool_op_calc_mem_size_helper(const struct rte_mempool *mp,
 	}
 
 	*min_chunk_size = total_elt_sz;
-	*align = RTE_CACHE_LINE_SIZE;
+	*align = RTE_MEMPOOL_ALIGN;
 
 	return mem_size;
 }
Signature · 1 line
2.20.1
#141 lore raw

Re: [dpdk-dev] [PATCH v4 0/7] mempool: avoid objects allocations across pages

In reply to Olivier Matz
Quoted 27 lines · Olivier Matz

KNI supposes that mbufs are contiguous in kernel virtual memory. This may not be true when using the IOVA=VA mode. To fix this, a possibility is to ensure that objects do not cross page boundaries in mempool. This patchset implements this in the last patch (5/5).

The previous patches prepare the job:
- allow to populate with an unaligned virtual area (1/5).
- reduce spaced wasted in the mempool size calculation when not using the iova-contiguous allocation (2/5).
- remove the iova-contiguous allocation when populating mempool (3/5):
a va-contiguous alloc does the job as well if we want to populate without crossing page boundaries, so simplify the mempool populate function.
- export a function to get the minimum page used in a mempool (4/5)

Memory consumption impact when using hugepages:
- worst case: + ~0.1% for a mbuf pool (objsize ~= 2368)
- best case: -50% for if pool size is just above page size

The memory consumption impact with 4K pages in IOVA=VA mode could however consume up to 75% more memory for mbuf pool, because there will be only 1 mbuf per page. Not sure how common this usecase is.

Caveat: this changes the behavior of the mempool (calc_mem_size and populate), and there is a small risk to break things, especially with alternate mempool drivers.

Quoted 8 lines

v4

* remove useless comments in Makefiles and meson.build (sugg by David)
* add EXPERIMENTAL banner on new functions in API comments (David)
* sort by version in rte_mempool_version.map (David)
* remove duplicated -DALLOW_EXPERIMENTAL_API flag in octeontx2 mempool driver
* enhance API comments for new helpers

I forgot:

* move bucket mempool driver modifications from patch 7 to patch 6 (seen by Andrew)

Quoted 65 lines

v3

* introduce new helpers to calculate required memory size and to populate mempool, use them in drivers: the alignment constraint of octeontx/octeontx2 is managed in this common code.
* fix octeontx mempool driver by taking alignment constraint in account like in octeontx2
* fix bucket mempool driver with 4K pages: limit bucket size in this case to ensure that objects do not cross page boundaries. With larger pages, it was already ok, because bucket size (64K) is smaller than a page.
* fix some api comments in mempool header file

v2

* update octeontx2 driver to keep alignment constraint (issue seen by Vamsi)
* add a new patch to use RTE_MEMPOOL_ALIGN (Andrew)
* fix initialization of for loop in rte_mempool_populate_virt() (Andrew)
* use rte_mempool_populate_iova() if mz_flags has RTE_MEMZONE_IOVA_CONTIG (Andrew)
* check rte_mempool_get_page_size() return value (Andrew)
* some other minor style improvements

rfc -> v1

* remove first cleanup patch, it was pushed separately a2b5a8722f20 ("mempool: clarify default populate function")
* add missing change in rte_mempool_op_calc_mem_size_default()
* allow unaligned addr/len in populate virt
* better split patches
* try to better explain the change
* use DPDK align macros when relevant

Olivier Matz (7):
mempool: allow unaligned addr/len in populate virt
mempool: reduce wasted space on mempool populate
mempool: remove optimistic IOVA-contiguous allocation
mempool: introduce function to get mempool page size
mempool: introduce helpers for populate and calc mem size
mempool: prevent objects from being across pages
mempool: use the specific macro for object alignment

 drivers/mempool/bucket/Makefile               |   1 +
 drivers/mempool/bucket/meson.build            |   2 +
 drivers/mempool/bucket/rte_mempool_bucket.c   |  10 +-
 drivers/mempool/dpaa/dpaa_mempool.c           |   4 +-
 drivers/mempool/dpaa2/dpaa2_hw_mempool.c      |   4 +-
 drivers/mempool/octeontx/Makefile             |   2 +
 drivers/mempool/octeontx/meson.build          |   2 +
 .../mempool/octeontx/rte_mempool_octeontx.c   |  21 +--
 drivers/mempool/octeontx2/Makefile            |   2 +
 drivers/mempool/octeontx2/meson.build         |   2 +
 drivers/mempool/octeontx2/otx2_mempool_ops.c  |  21 ++-
 lib/librte_mempool/rte_mempool.c              | 147 +++++++-----------
 lib/librte_mempool/rte_mempool.h              | 114 ++++++++++++--
 lib/librte_mempool/rte_mempool_ops.c          |   4 +-
 lib/librte_mempool/rte_mempool_ops_default.c  | 113 +++++++++++---
 lib/librte_mempool/rte_mempool_version.map    |   6 +
 16 files changed, 312 insertions(+), 143 deletions(-)
Signature · 1 line
2.20.1
#142 lore raw

Re: [dpdk-dev] [PATCH v4 0/7] mempool: avoid objects allocations across pages

In reply to Olivier Matz

05/11/2019 16:36, Olivier Matz:

Quoted 8 lines

Olivier Matz (7):
mempool: allow unaligned addr/len in populate virt
mempool: reduce wasted space on mempool populate
mempool: remove optimistic IOVA-contiguous allocation
mempool: introduce function to get mempool page size
mempool: introduce helpers for populate and calc mem size
mempool: prevent objects from being across pages
mempool: use the specific macro for object alignment

Applied, thanks

Release notes were added.

#143 lore raw

PATCH v7 2/4 kni: add IOVA = VA support in KNI lib

In reply to [email protected]

From: Vamsi Attunuru <[email protected]>

Current KNI implmentation only operates in IOVA=PA mode, patch adds required functionality in KNI lib to support IOVA=VA mode.

KNI kernel module requires device info to get iommu domain related information for IOVA addr related translations. Patch defines device related info in rte_kni_device_info struct and passes device info to kernel KNI module when IOVA=VA mode is enabled.

---
 lib/librte_eal/linux/eal/include/rte_kni_common.h |  8 ++++
 lib/librte_kni/Makefile                           |  1 +
 lib/librte_kni/meson.build                        |  1 +
 lib/librte_kni/rte_kni.c                          | 54 +++++++++++++++++++++++
 4 files changed, 64 insertions(+)
lib/librte_eal/linux/eal/include/rte_kni_common.h +8 -0
index 37d9ee8..4fd8a90 100644
@@ -111,6 +111,13 @@ struct rte_kni_device_info {
 	void * mbuf_va;
 	phys_addr_t mbuf_phys;
 
+	/* PCI info */
+	uint16_t vendor_id;           /**< Vendor ID or PCI_ANY_ID. */
+	uint16_t device_id;           /**< Device ID or PCI_ANY_ID. */
+	uint8_t bus;                  /**< Device bus */
+	uint8_t devid;                /**< Device ID */
+	uint8_t function;             /**< Device function. */
+
 	uint16_t group_id;            /**< Group ID */
 	uint32_t core_id;             /**< core ID to bind for kernel thread */
 
@@ -121,6 +128,7 @@ struct rte_kni_device_info {
 	unsigned mbuf_size;
 	unsigned int mtu;
 	uint8_t mac_addr[6];
+	uint8_t iova_mode;
 };
 
 #define KNI_DEVICE "kni"
lib/librte_kni/Makefile +1 -0
index cbd6599..ab15d10 100644
@@ -7,6 +7,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 LIB = librte_kni.a
 
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -fno-strict-aliasing
+CFLAGS += -I$(RTE_SDK)/drivers/bus/pci
 LDLIBS += -lrte_eal -lrte_mempool -lrte_mbuf -lrte_ethdev
 
 EXPORT_MAP := rte_kni_version.map
lib/librte_kni/meson.build +1 -0
index 41fa2e3..fd46f87 100644
@@ -9,3 +9,4 @@ version = 2
 sources = files('rte_kni.c')
 headers = files('rte_kni.h')
 deps += ['ethdev', 'pci']
+includes += include_directories('../../drivers/bus/pci')
lib/librte_kni/rte_kni.c +54 -0

78 lines not on this page · raw message

Signature · 1 line
2.8.4
#144 lore raw

PATCH v7 3/4 kni: add IOVA=VA support in KNI module

In reply to [email protected]

From: Kiran Kumar K <[email protected]>

Patch adds support for kernel module to work in IOVA = VA mode, the idea is to get physical address from IOVA address using iommu_iova_to_phys API and later use phys_to_virt API to convert the physical address to kernel virtual address.

When compared with IOVA = PA mode, there is no performance drop with this approach.

This approach does not work with the kernel versions less than 4.4.0 because of API compatibility issues.

Patch also updates these support details in KNI documentation.

---
 doc/guides/prog_guide/kernel_nic_interface.rst |  8 +++
 kernel/linux/kni/compat.h                      |  4 ++
 kernel/linux/kni/kni_dev.h                     |  4 ++
 kernel/linux/kni/kni_misc.c                    | 71 ++++++++++++++++++++++----
 kernel/linux/kni/kni_net.c                     | 59 ++++++++++++++++-----
 5 files changed, 124 insertions(+), 22 deletions(-)
doc/guides/prog_guide/kernel_nic_interface.rst +8 -0
index 38369b3..fd2ce63 100644
@@ -291,6 +291,14 @@ The sk_buff is then freed and the mbuf sent in the tx_q FIFO.
 The DPDK TX thread dequeues the mbuf and sends it to the PMD via ``rte_eth_tx_burst()``.
 It then puts the mbuf back in the cache.
 
+IOVA = VA: Support
+------------------
+
+KNI can be operated in IOVA as VA scheme when following criteria are fullfilled
+
+- LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)
+- eal param `--iova-mode va` is passed or bus IOVA scheme is set to RTE_IOVA_VA
+
 Ethtool
 -------
 
kernel/linux/kni/compat.h +4 -0
index 562d8bf..ee997a6 100644
@@ -121,3 +121,7 @@
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
 #define HAVE_SIGNAL_FUNCTIONS_OWN_HEADER
 #endif
+
+#if KERNEL_VERSION(4, 4, 0) <= LINUX_VERSION_CODE
+#define HAVE_IOVA_AS_VA_SUPPORT
+#endif
kernel/linux/kni/kni_dev.h +4 -0
index c1ca678..d5898f3 100644
@@ -25,6 +25,7 @@
 #include <linux/netdevice.h>
 #include <linux/spinlock.h>
 #include <linux/list.h>
+#include <linux/iommu.h>
 
 #include <rte_kni_common.h>
 #define KNI_KTHREAD_RESCHEDULE_INTERVAL 5 /* us */
@@ -41,6 +42,9 @@ struct kni_dev {
 	/* kni list */
 	struct list_head list;
 
+	uint8_t iova_mode;
+	struct iommu_domain *domain;
+
 	uint32_t core_id;            /* Core ID to bind */
 	char name[RTE_KNI_NAMESIZE]; /* Network device name */
 	struct task_struct *pthread;
kernel/linux/kni/kni_misc.c +62 -9

83 lines not on this page · raw message

kernel/linux/kni/kni_net.c +46 -13

116 lines not on this page · raw message

Signature · 1 line
2.8.4
#145 lore raw

PATCH v7 4/4 kni: modify IOVA mode checks to support VA

In reply to [email protected]

From: Vamsi Attunuru <[email protected]>

Patch addresses checks in KNI and eal that enforce IOVA=PA when IOVA=VA mode is enabled, since KNI kernel module supports VA mode for kernel versions >= 4.4.0.

---
 lib/librte_eal/linux/eal/eal.c | 4 +++-
 lib/librte_kni/rte_kni.c       | 5 -----
 2 files changed, 3 insertions(+), 6 deletions(-)
lib/librte_eal/linux/eal/eal.c +3 -1
index 2e5499f..9705243 100644
@@ -1070,12 +1070,14 @@ rte_eal_init(int argc, char **argv)
 		/* Workaround for KNI which requires physical address to work */
 		if (iova_mode == RTE_IOVA_VA &&
 				rte_eal_check_module("rte_kni") == 1) {
+#if KERNEL_VERSION(4, 4, 0) > LINUX_VERSION_CODE
 			if (phys_addrs) {
 				iova_mode = RTE_IOVA_PA;
-				RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI module is loaded\n");
+				RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI module does not support VA\n");
 			} else {
 				RTE_LOG(DEBUG, EAL, "KNI can not work since physical addresses are unavailable\n");
 			}
+#endif
 		}
 #endif
 		rte_eal_get_configuration()->iova_mode = iova_mode;
lib/librte_kni/rte_kni.c +0 -5
index 2cb653e..959088e 100644
@@ -98,11 +98,6 @@ static volatile int kni_fd = -1;
 int
 rte_kni_init(unsigned int max_kni_ifaces __rte_unused)
 {
-	if (rte_eal_iova_mode() != RTE_IOVA_PA) {
-		RTE_LOG(ERR, KNI, "KNI requires IOVA as PA\n");
-		return -1;
-	}
-
 	/* Check FD and open */
 	if (kni_fd < 0) {
 		kni_fd = open("/dev/" KNI_DEVICE, O_RDWR);
Signature · 1 line
2.8.4
#146 lore raw

v8 cover kni: add IOVA=VA support

In reply to [email protected]

From: Vamsi Attunuru <[email protected]>

---
V8 Changes:
* Remove default mempool populate() routine changes.
* Add kni app specific mempool create & free routines.
* Add new mempool populate routine to allocate page-aligned memzones with page size to make sure all mempool objects reside on a page.
* Update release notes and map files.

V7 Changes:
* Removed previously proposed mempool flag and made those page boundary checks default in mempool populate() except for the objects size bigger than the size of page.
* Removed KNI example application related changes since pool related requirement is taken care in mempool lib.
* All PCI dev related info is moved under rte_eal_iova_mode() == VA check.
* Added wrapper functions in KNI module to hide IOVA checks and make address translation routines more readable.
* Updated IOVA mode checks that enforcing IOVA=PA mode when IOVA=VA mode is enabled.

V6 Changes:
* Added new mempool flag to ensure mbuf memory is not scattered across page boundaries.
* Added KNI kernel module required PCI device information.
* Modified KNI example application to create mempool with new mempool flag.

V5 changes:
* Fixed build issue with 32b build

V4 changes:
* Fixed build issues with older kernel versions
* This approach will only work with kernel above 4.4.0

V3 Changes:
* Add new approach to work kni with IOVA=VA mode using iommu_iova_to_phys API.

Kiran Kumar K (1):
kni: add IOVA=VA support in KNI module

Vamsi Attunuru (4):
mempool: populate mempool with page sized chunks of memory add IOVA -VA support in KNI lib
kni: add app specific mempool create & free routine
kni: modify IOVA mode checks to support VA

 doc/guides/prog_guide/kernel_nic_interface.rst    |   8 ++
 doc/guides/rel_notes/release_19_08.rst            |   6 ++
 examples/kni/main.c                               |   6 +-
 kernel/linux/kni/compat.h                         |   4 +
 kernel/linux/kni/kni_dev.h                        |   4 +
 kernel/linux/kni/kni_misc.c                       |  71 +++++++++++++--
 kernel/linux/kni/kni_net.c                        |  59 ++++++++++---
 lib/librte_eal/linux/eal/eal.c                    |   4 +-
 lib/librte_eal/linux/eal/include/rte_kni_common.h |   8 ++
 lib/librte_kni/Makefile                           |   2 +
 lib/librte_kni/meson.build                        |   2 +
 lib/librte_kni/rte_kni.c                          | 100 ++++++++++++++++++++--
 lib/librte_kni/rte_kni.h                          |  49 +++++++++++
 lib/librte_kni/rte_kni_version.map                |   2 +
 lib/librte_mempool/rte_mempool.c                  |  59 +++++++++++++
 lib/librte_mempool/rte_mempool.h                  |  17 ++++
 lib/librte_mempool/rte_mempool_version.map        |   1 +
 17 files changed, 373 insertions(+), 29 deletions(-)
Signature · 1 line
2.8.4
#147 lore raw

PATCH v8 1/5 mempool: populate mempool with page sized chunks of memory

From: Vamsi Attunuru <[email protected]>

Patch adds a routine to populate mempool from page aligned and page sized chunks of memory to ensures memory objs do not fall across the page boundaries. It's useful for applications that require physically contiguous mbuf memory while running in IOVA=VA mode.

---
 lib/librte_mempool/rte_mempool.c           | 59 ++++++++++++++++++++++++++++++
 lib/librte_mempool/rte_mempool.h           | 17 +++++++++
 lib/librte_mempool/rte_mempool_version.map |  1 +
 3 files changed, 77 insertions(+)
lib/librte_mempool/rte_mempool.c +59 -0
index 7260ce0..5312c8f 100644
@@ -414,6 +414,65 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
 	return ret;
 }
 
+/* Function to populate mempool from page sized mem chunks, allocate page size
+ * of memory in memzone and populate them. Return the number of objects added,
+ * or a negative value on error.
+ */
+int
+rte_mempool_populate_from_pg_sz_chunks(struct rte_mempool *mp)
+{
+	char mz_name[RTE_MEMZONE_NAMESIZE];
+	size_t align, pg_sz, pg_shift;
+	const struct rte_memzone *mz;
+	unsigned int mz_id, n;
+	size_t chunk_size;
+	int ret;
+
+	ret = mempool_ops_alloc_once(mp);
+	if (ret != 0)
+		return ret;
+
+	if (mp->nb_mem_chunks != 0)
+		return -EEXIST;
+
+	pg_sz = get_min_page_size(mp->socket_id);
+	pg_shift = rte_bsf32(pg_sz);
+
+	for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) {
+
+		rte_mempool_op_calc_mem_size_default(mp, n, pg_shift,
+			     &chunk_size, &align);
+
+		if (chunk_size > pg_sz)
+			goto fail;
+
+		ret = snprintf(mz_name, sizeof(mz_name),
+			RTE_MEMPOOL_MZ_FORMAT "_%d", mp->name, mz_id);
+		if (ret < 0 || ret >= (int)sizeof(mz_name)) {
+			ret = -ENAMETOOLONG;
+			goto fail;
+		}
+
+		mz = rte_memzone_reserve_aligned(mz_name, chunk_size,
+				mp->socket_id, 0, align);
+
+		ret = rte_mempool_populate_iova(mp, mz->addr,
+				mz->iova, mz->len,
+				rte_mempool_memchunk_mz_free,
+				(void *)(uintptr_t)mz);
+		if (ret < 0) {
+			rte_memzone_free(mz);
+			goto fail;
+		}
+	}
+
+	return mp->size;
+
+fail:
+	rte_mempool_free_memchunks(mp);
+	return ret;
+}
+
 /* Default function to populate the mempool: allocate memory in memzones,
  * and populate them. Return the number of objects added, or a negative
  * value on error.
lib/librte_mempool/rte_mempool.h +17 -0
index 8053f7a..73d6ada 100644
@@ -1064,6 +1064,23 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
 /**
  * Add memory for objects in the pool at init
  *
+ * This is the function used to populate the mempool with page aligned memzone
+ * memory. It ensures all mempool objects being on the page by allocating
+ * memzones with page size.
+ *
+ * @param mp
+ *   A pointer to the mempool structure.
+ * @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.
+ */
+__rte_experimental
+int rte_mempool_populate_from_pg_sz_chunks(struct rte_mempool *mp);
+
+/**
+ * Add memory for objects in the pool at init
+ *
  * This is the default function used by rte_mempool_create() to populate
  * the mempool. It adds memory allocated using rte_memzone_reserve().
  *
lib/librte_mempool/rte_mempool_version.map +1 -0
index 17cbca4..9a6fe65 100644
@@ -57,4 +57,5 @@ EXPERIMENTAL {
 	global:
 
 	rte_mempool_ops_get_info;
+	rte_mempool_populate_from_pg_sz_chunks;
 };
Signature · 1 line
2.8.4
#148 lore raw

Re: [dpdk-dev] [PATCH v8 1/5] mempool: populate mempool with page sized chunks of memory

Quoted 26 lines · On 7/23/19 8:38 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

Patch adds a routine to populate mempool from page aligned and page sized chunks of memory to ensures memory objs do not fall across the page boundaries. It's useful for applications that require physically contiguous mbuf memory while running in IOVA=VA mode.

---
  lib/librte_mempool/rte_mempool.c           | 59 ++++++++++++++++++++++++++++++
  lib/librte_mempool/rte_mempool.h           | 17 +++++++++
  lib/librte_mempool/rte_mempool_version.map |  1 +
  3 files changed, 77 insertions(+)
lib/librte_mempool/rte_mempool.c +2 -0
index 7260ce0..5312c8f 100644
@@ -414,6 +414,65 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
  	return ret;
  }
 
+/* Function to populate mempool from page sized mem chunks, allocate page size
+ * of memory in memzone and populate them. Return the number of objects added,

lib/librte_mempool/rte_mempool.c rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, · line 428

Quoted 10 lines
lib/librte_mempool/rte_mempool.c +10 -0
+ * or a negative value on error.
+ */
+int
+rte_mempool_populate_from_pg_sz_chunks(struct rte_mempool *mp)
+{
+	char mz_name[RTE_MEMZONE_NAMESIZE];
+	size_t align, pg_sz, pg_shift;
+	const struct rte_memzone *mz;
+	unsigned int mz_id, n;
+	size_t chunk_size;

I think it would be better to keep min_chunk_size name here. It would make it easier to read and understand the code.

Quoted 6 lines
lib/librte_mempool/rte_mempool.c +6 -0
+	int ret;
+
+	ret = mempool_ops_alloc_once(mp);
+	if (ret != 0)
+		return ret;
+

lib/librte_mempool/rte_mempool.c rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, · line 444

Quoted 10 lines
lib/librte_mempool/rte_mempool.c +10 -0
+	if (mp->nb_mem_chunks != 0)
+		return -EEXIST;
+
+	pg_sz = get_min_page_size(mp->socket_id);
+	pg_shift = rte_bsf32(pg_sz);
+
+	for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) {
+
+		rte_mempool_op_calc_mem_size_default(mp, n, pg_shift,
+			     &chunk_size, &align);

It is incorrect to ignore mempool pool ops and enforce default handler. Use rte_mempool_ops_calc_mem_size(). Also it is better to treat negative return value as an error as default function does.
(May be it my mistake in return value description that it is not mentioned).

lib/librte_mempool/rte_mempool.c rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, · line 457

Quoted 13 lines
lib/librte_mempool/rte_mempool.c +13 -0
+
+		if (chunk_size > pg_sz)
+			goto fail;
+
+		ret = snprintf(mz_name, sizeof(mz_name),
+			RTE_MEMPOOL_MZ_FORMAT "_%d", mp->name, mz_id);
+		if (ret < 0 || ret >= (int)sizeof(mz_name)) {
+			ret = -ENAMETOOLONG;
+			goto fail;
+		}
+
+		mz = rte_memzone_reserve_aligned(mz_name, chunk_size,
+				mp->socket_id, 0, align);

NULL return value must be handled.

Quoted 26 lines
lib/librte_mempool/rte_mempool.c +18 -0
+
+		ret = rte_mempool_populate_iova(mp, mz->addr,
+				mz->iova, mz->len,
+				rte_mempool_memchunk_mz_free,
+				(void *)(uintptr_t)mz);
+		if (ret < 0) {
+			rte_memzone_free(mz);
+			goto fail;
+		}
+	}
+
+	return mp->size;
+
+fail:
+	rte_mempool_free_memchunks(mp);
+	return ret;
+}
+
  /* Default function to populate the mempool: allocate memory in memzones,
   * and populate them. Return the number of objects added, or a negative
   * value on error.
lib/librte_mempool/rte_mempool.h +0 -0
index 8053f7a..73d6ada 100644

lib/librte_mempool/rte_mempool.h rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, · line 1065

Quoted 2 lines
lib/librte_mempool/rte_mempool.h +0 -0
@@ -1064,6 +1064,23 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
  /**
   * Add memory for objects in the pool at init

The different from default must be highlighted in the summary.

Quoted 31 lines
lib/librte_mempool/rte_mempool.h +17 -0
   *
+ * This is the function used to populate the mempool with page aligned memzone
+ * memory. It ensures all mempool objects being on the page by allocating
+ * memzones with page size.
+ *
+ * @param mp
+ *   A pointer to the mempool structure.
+ * @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.
+ */
+__rte_experimental
+int rte_mempool_populate_from_pg_sz_chunks(struct rte_mempool *mp);
+
+/**
+ * Add memory for objects in the pool at init
+ *
   * This is the default function used by rte_mempool_create() to populate
   * the mempool. It adds memory allocated using rte_memzone_reserve().
   *
lib/librte_mempool/rte_mempool_version.map +1 -0
index 17cbca4..9a6fe65 100644
@@ -57,4 +57,5 @@ EXPERIMENTAL {
  	global:
 
  	rte_mempool_ops_get_info;
+	rte_mempool_populate_from_pg_sz_chunks;
  };
#149 lore raw

Re: [dpdk-dev] [PATCH v8 1/5] mempool: populate mempool with page sized chunks of memory

Quoted 40 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, July 23, 2019 4:38 PM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v8 1/5] mempool: populate mempool with page sized chunks of memory

Quoted 11 lines · On 7/23/19 8:38 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

Patch adds a routine to populate mempool from page aligned and page sized chunks of memory to ensures memory objs do not fall across the page boundaries. It's useful for applications that require physically contiguous mbuf memory while running in IOVA=VA mode.

---
  lib/librte_mempool/rte_mempool.c           | 59

++++++++++++++++++++++++++++++

lib/librte_mempool/rte_mempool.c rte_mempool_populate_virt(struct rte_mempool

Quoted 10 lines
  lib/librte_mempool/rte_mempool.h           | 17 +++++++++
  lib/librte_mempool/rte_mempool_version.map |  1 +
  3 files changed, 77 insertions(+)
lib/librte_mempool/rte_mempool.c +0 -0
index 7260ce0..5312c8f 100644
@@ -414,6 +414,65 @@ rte_mempool_populate_virt(struct rte_mempool

*mp, char *addr,

Quoted 3 lines
lib/librte_mempool/rte_mempool.c +0 -0
  	return ret;
  }
 
Quoted 16 lines

lib/librte_mempool/rte_mempool.c rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, · line 428

Quoted 13 lines
lib/librte_mempool/rte_mempool.c +13 -0
+/* Function to populate mempool from page sized mem chunks, allocate
+page size
+ * of memory in memzone and populate them. Return the number of
+objects added,
+ * or a negative value on error.
+ */
+int
+rte_mempool_populate_from_pg_sz_chunks(struct rte_mempool *mp) {
+	char mz_name[RTE_MEMZONE_NAMESIZE];
+	size_t align, pg_sz, pg_shift;
+	const struct rte_memzone *mz;
+	unsigned int mz_id, n;
+	size_t chunk_size;

I think it would be better to keep min_chunk_size name here. It would make it easier to read and understand the code.

ack

Quoted 15 lines
Quoted 15 lines
lib/librte_mempool/rte_mempool.c +14 -0
+	int ret;
+
+	ret = mempool_ops_alloc_once(mp);
+	if (ret != 0)
+		return ret;
+
+	if (mp->nb_mem_chunks != 0)
+		return -EEXIST;
+
+	pg_sz = get_min_page_size(mp->socket_id);
+	pg_shift = rte_bsf32(pg_sz);
+
+	for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) {
+
Quoted 9 lines

lib/librte_mempool/rte_mempool.c rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, · line 444

Quoted 2 lines
lib/librte_mempool/rte_mempool.c +2 -0
+		rte_mempool_op_calc_mem_size_default(mp, n, pg_shift,
+			     &chunk_size, &align);

It is incorrect to ignore mempool pool ops and enforce default handler. Use rte_mempool_ops_calc_mem_size().
Also it is better to treat negative return value as an error as default function does.
(May be it my mistake in return value description that it is not mentioned).

Yes, I thought so, but ops_calc_mem_size() would in turn call mempool pmd's calc_mem_size() op which
may/may not return required chunk_size and align values in this case. Or else it would be skipped completely and use pg_sz for both memzone len and align, anyways this page sized alignment will suits the pmd's specific align requirements.

Quoted 7 lines

lib/librte_mempool/rte_mempool.c rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,

Quoted 6 lines
lib/librte_mempool/rte_mempool.c +6 -0
+
+		if (chunk_size > pg_sz)
+			goto fail;
+
+		ret = snprintf(mz_name, sizeof(mz_name),
+			RTE_MEMPOOL_MZ_FORMAT "_%d", mp->name,

mz_id);

Quoted 10 lines

lib/librte_mempool/rte_mempool.c rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, · line 457

Quoted 7 lines
lib/librte_mempool/rte_mempool.c +7 -0
+		if (ret < 0 || ret >= (int)sizeof(mz_name)) {
+			ret = -ENAMETOOLONG;
+			goto fail;
+		}
+
+		mz = rte_memzone_reserve_aligned(mz_name, chunk_size,
+				mp->socket_id, 0, align);

NULL return value must be handled.

Ack.

Quoted 29 lines
Quoted 9 lines
lib/librte_mempool/rte_mempool.c +9 -0
+
+		ret = rte_mempool_populate_iova(mp, mz->addr,
+				mz->iova, mz->len,
+				rte_mempool_memchunk_mz_free,
+				(void *)(uintptr_t)mz);
+		if (ret < 0) {
+			rte_memzone_free(mz);
+			goto fail;
+		}

lib/librte_mempool/rte_mempool.c rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,

Quoted 10 lines
lib/librte_mempool/rte_mempool.c +9 -0
+	}
+
+	return mp->size;
+
+fail:
+	rte_mempool_free_memchunks(mp);
+	return ret;
+}
+
  /* Default function to populate the mempool: allocate memory in

memzones,

lib/librte_mempool/rte_mempool.h rte_mempool_populate_virt(struct

Quoted 8 lines
lib/librte_mempool/rte_mempool.c +0 -0
   * and populate them. Return the number of objects added, or a negative
   * value on error.
lib/librte_mempool/rte_mempool.h +0 -0
index 8053f7a..73d6ada 100644
@@ -1064,6 +1064,23 @@ rte_mempool_populate_virt(struct

rte_mempool *mp, char *addr,

Quoted 4 lines

lib/librte_mempool/rte_mempool.h rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, · line 1065

Quoted 2 lines
lib/librte_mempool/rte_mempool.h +0 -0
  /**
   * Add memory for objects in the pool at init

The different from default must be highlighted in the summary.

Sure, will add more details.

Quoted 36 lines
Quoted 7 lines
lib/librte_mempool/rte_mempool.h +5 -0
   *
+ * This is the function used to populate the mempool with page
+aligned memzone
+ * memory. It ensures all mempool objects being on the page by
+allocating
+ * memzones with page size.

lib/librte_mempool/rte_mempool.h rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,

Quoted 10 lines
lib/librte_mempool/rte_mempool.h +10 -0
+ *
+ * @param mp
+ *   A pointer to the mempool structure.
+ * @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.
+ */
+__rte_experimental
+int rte_mempool_populate_from_pg_sz_chunks(struct rte_mempool

*mp);

Quoted 18 lines
lib/librte_mempool/rte_mempool.h +4 -0
+
+/**
+ * Add memory for objects in the pool at init
+ *
   * This is the default function used by rte_mempool_create() to populate
   * the mempool. It adds memory allocated using rte_memzone_reserve().
   *
lib/librte_mempool/rte_mempool_version.map +1 -0
index 17cbca4..9a6fe65 100644
@@ -57,4 +57,5 @@ EXPERIMENTAL {
  	global:
 
  	rte_mempool_ops_get_info;
+	rte_mempool_populate_from_pg_sz_chunks;
  };
#150 lore raw

Re: [dpdk-dev] [PATCH v8 1/5] mempool: populate mempool with page sized chunks of memory

Quoted 22 lines · Vamsi Krishna Attunuru
Quoted 22 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, July 23, 2019 4:38 PM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v8 1/5] mempool: populate mempool with page sized chunks of memory

Quoted 10 lines · On 7/23/19 8:38 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

Patch adds a routine to populate mempool from page aligned and page sized chunks of memory to ensures memory objs do not fall across the page boundaries. It's useful for applications that require physically contiguous mbuf memory while running in IOVA=VA mode.

---

<...>

Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
lib/librte_mempool/rte_mempool.c +13 -0
+	int ret;
+
+	ret = mempool_ops_alloc_once(mp);
+	if (ret != 0)
+		return ret;
+
+	if (mp->nb_mem_chunks != 0)
+		return -EEXIST;
+
+	pg_sz = get_min_page_size(mp->socket_id);
+	pg_shift = rte_bsf32(pg_sz);
+
+	for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) {
Quoted 9 lines

lib/librte_mempool/rte_mempool.c rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, · line 444

Quoted 3 lines
lib/librte_mempool/rte_mempool.c +3 -0
+
+		rte_mempool_op_calc_mem_size_default(mp, n, pg_shift,
+			     &chunk_size, &align);

It is incorrect to ignore mempool pool ops and enforce default handler. Use rte_mempool_ops_calc_mem_size().
Also it is better to treat negative return value as an error as default function does.
(May be it my mistake in return value description that it is not mentioned).

Quoted 3 lines

Yes, I thought so, but ops_calc_mem_size() would in turn call mempool pmd's calc_mem_size() op which
may/may not return required chunk_size and align values in this case. Or else it would be skipped completely and use pg_sz for both memzone len and align, anyways this page sized alignment will suits the pmd's specific align requirements.

Anyway it is incorrect to violate driver ops. default is definitely wrong for bucket. min_chunk_size and align is mempool driver requirements. You can harden it, but should not violate it.

#151 lore raw

Re: [dpdk-dev] [PATCH v8 1/5] mempool: populate mempool with page sized chunks of memory

Quoted 63 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Wednesday, July 24, 2019 1:04 AM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v8 1/5] mempool: populate mempool with page sized chunks of memory

Quoted 22 lines · Vamsi Krishna Attunuru
Quoted 22 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, July 23, 2019 4:38 PM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v8 1/5] mempool: populate mempool with page sized chunks of memory

Quoted 10 lines · On 7/23/19 8:38 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

Patch adds a routine to populate mempool from page aligned and page sized chunks of memory to ensures memory objs do not fall across the page boundaries. It's useful for applications that require physically contiguous mbuf memory while running in IOVA=VA mode.

---

<...>

Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
lib/librte_mempool/rte_mempool.c +13 -0
+	int ret;
+
+	ret = mempool_ops_alloc_once(mp);
+	if (ret != 0)
+		return ret;
+
+	if (mp->nb_mem_chunks != 0)
+		return -EEXIST;
+
+	pg_sz = get_min_page_size(mp->socket_id);
+	pg_shift = rte_bsf32(pg_sz);
+
+	for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) {
Quoted 9 lines

lib/librte_mempool/rte_mempool.c rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, · line 444

Quoted 3 lines
lib/librte_mempool/rte_mempool.c +3 -0
+
+		rte_mempool_op_calc_mem_size_default(mp, n, pg_shift,
+			     &chunk_size, &align);

It is incorrect to ignore mempool pool ops and enforce default handler. Use rte_mempool_ops_calc_mem_size().
Also it is better to treat negative return value as an error as default function does.
(May be it my mistake in return value description that it is not mentioned).

Quoted 3 lines

Yes, I thought so, but ops_calc_mem_size() would in turn call mempool pmd's calc_mem_size() op which may/may not return required chunk_size and align values in this case. Or else it would be skipped completely and use

Quoted 7 lines

pg_sz for both memzone len and align, anyways this page sized alignment will suits the pmd's specific align requirements.

Anyway it is incorrect to violate driver ops. default is definitely wrong for bucket.
min_chunk_size and align is mempool driver requirements. You can harden it, but should not violate it.

fine, I will modify the routine as below, call pmd's calc_mem_size() op and over write min_chunk_size if it does not suit for this function's purpose.

+ total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
+ if (total_elt_sz > pg_sz)
+ return ret;

+ for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) {

- rte_mempool_op_calc_mem_size_default(mp, n, pg_shift,
- &chunk_size, &align);
+ ret = rte_mempool_ops_calc_mem_size(mp, n, pg_shift,
+ &min_chunk_size, &align);
+
+ if (ret < 0)

                        goto fail;

+ if (min_chunk_size > pg_sz)
+ min_chunk_size = pg_sz;

Changes look fine.?

#152 lore raw

Re: [dpdk-dev] [PATCH v8 1/5] mempool: populate mempool with page sized chunks of memory

Quoted 87 lines · Vamsi Krishna Attunuru
Quoted 61 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Wednesday, July 24, 2019 1:04 AM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v8 1/5] mempool: populate mempool with page sized chunks of memory

Quoted 22 lines · Vamsi Krishna Attunuru
Quoted 22 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, July 23, 2019 4:38 PM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v8 1/5] mempool: populate mempool with page sized chunks of memory

Quoted 10 lines · On 7/23/19 8:38 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

Patch adds a routine to populate mempool from page aligned and page sized chunks of memory to ensures memory objs do not fall across the page boundaries. It's useful for applications that require physically contiguous mbuf memory while running in IOVA=VA mode.

---

<...>

Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
lib/librte_mempool/rte_mempool.c +13 -0
+	int ret;
+
+	ret = mempool_ops_alloc_once(mp);
+	if (ret != 0)
+		return ret;
+
+	if (mp->nb_mem_chunks != 0)
+		return -EEXIST;
+
+	pg_sz = get_min_page_size(mp->socket_id);
+	pg_shift = rte_bsf32(pg_sz);
+
+	for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) {
Quoted 9 lines

lib/librte_mempool/rte_mempool.c rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, · line 444

Quoted 3 lines
lib/librte_mempool/rte_mempool.c +3 -0
+
+		rte_mempool_op_calc_mem_size_default(mp, n, pg_shift,
+			     &chunk_size, &align);

It is incorrect to ignore mempool pool ops and enforce default handler. Use rte_mempool_ops_calc_mem_size().
Also it is better to treat negative return value as an error as default function does.
(May be it my mistake in return value description that it is not mentioned).

Quoted 3 lines

Yes, I thought so, but ops_calc_mem_size() would in turn call mempool pmd's calc_mem_size() op which may/may not return required chunk_size and align values in this case. Or else it would be skipped completely and use

Quoted 7 lines

pg_sz for both memzone len and align, anyways this page sized alignment will suits the pmd's specific align requirements.

Anyway it is incorrect to violate driver ops. default is definitely wrong for bucket.
min_chunk_size and align is mempool driver requirements. You can harden it, but should not violate it.

fine, I will modify the routine as below, call pmd's calc_mem_size() op and over write min_chunk_size if it does not suit for this function's purpose.

(quoted diff) +10 -2
+       total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
+       if (total_elt_sz > pg_sz)
+               return ret;
 
+       for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) {
 
-               rte_mempool_op_calc_mem_size_default(mp, n, pg_shift,
-                            &chunk_size, &align);
+               ret = rte_mempool_ops_calc_mem_size(mp, n, pg_shift,
+                               &min_chunk_size, &align);
+
+               if (ret < 0)
                         goto fail;
 
+               if (min_chunk_size > pg_sz)
+                       min_chunk_size = pg_sz;
Quoted 1 line

Changes look fine.?

No, you can't violate min_chunk_size requirement. If it is unacceptable, error should be returned. So, you should not check total_elt_sz above separately.

#153 lore raw

Re: [dpdk-dev] [PATCH v8 1/5] mempool: populate mempool with page sized chunks of memory

Hi,

Quoted 99 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Wednesday, July 24, 2019 12:58 PM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v8 1/5] mempool: populate mempool with page sized chunks of memory

Quoted 24 lines · Vamsi Krishna Attunuru
Quoted 24 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Wednesday, July 24, 2019 1:04 AM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v8 1/5] mempool: populate mempool with page sized chunks of memory

Quoted 11 lines · Vamsi Krishna Attunuru
Quoted 11 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, July 23, 2019 4:38 PM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v8 1/5] mempool: populate mempool with page sized chunks of memory

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines · On 7/23/19 8:38 AM, [email protected] wrote:
Quoted 6 lines

From: Vamsi Attunuru <[email protected]>

Patch adds a routine to populate mempool from page aligned and page sized chunks of memory to ensures memory objs do not fall across the page boundaries. It's useful for applications that require physically contiguous mbuf memory while running in IOVA=VA

mode.

Quoted 32 lines
Quoted 32 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

---

<...>

Quoted 26 lines
Quoted 13 lines
Quoted 13 lines
lib/librte_mempool/rte_mempool.c +13 -0
+	int ret;
+
+	ret = mempool_ops_alloc_once(mp);
+	if (ret != 0)
+		return ret;
+
+	if (mp->nb_mem_chunks != 0)
+		return -EEXIST;
+
+	pg_sz = get_min_page_size(mp->socket_id);
+	pg_shift = rte_bsf32(pg_sz);
+
+	for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) {
Quoted 9 lines

lib/librte_mempool/rte_mempool.c rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, · line 444

Quoted 3 lines
lib/librte_mempool/rte_mempool.c +3 -0
+
+		rte_mempool_op_calc_mem_size_default(mp, n, pg_shift,
+			     &chunk_size, &align);

It is incorrect to ignore mempool pool ops and enforce default handler. Use rte_mempool_ops_calc_mem_size().
Also it is better to treat negative return value as an error as default function does.
(May be it my mistake in return value description that it is not mentioned).

Yes, I thought so, but ops_calc_mem_size() would in turn call mempool pmd's calc_mem_size() op which may/may not return required chunk_size and align values in this case. Or else it would be skipped completely and use

Quoted 8 lines
Quoted 7 lines

pg_sz for both memzone len and align, anyways this page sized alignment will suits the pmd's specific align requirements.

Anyway it is incorrect to violate driver ops. default is definitely wrong for bucket.
min_chunk_size and align is mempool driver requirements. You can harden it, but should not violate it.

fine, I will modify the routine as below, call pmd's calc_mem_size() op and

over write min_chunk_size if it does not suit for this function's purpose.

Quoted 15 lines
(quoted diff) +8 -2
+       total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
+       if (total_elt_sz > pg_sz)
+               return ret;
 
+       for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) {
 
-               rte_mempool_op_calc_mem_size_default(mp, n, pg_shift,
-                            &chunk_size, &align);
+               ret = rte_mempool_ops_calc_mem_size(mp, n, pg_shift,
+                               &min_chunk_size, &align);
+
+               if (ret < 0)
                         goto fail;
Quoted 7 lines
Quoted 4 lines
(quoted diff) +2 -0
+               if (min_chunk_size > pg_sz)
+                       min_chunk_size = pg_sz;

Changes look fine.?

No, you can't violate min_chunk_size requirement. If it is unacceptable, error should be returned. So, you should not check total_elt_sz above separately.

Fine, will put min_chunk_size req check and return error if it's inappropriate. I will send V9 with addressing all other comments.
Btw, sorry for delayed response.

#154 lore raw

PATCH v8 2/5 add IOVA -VA support in KNI lib

In reply to [email protected]

From: Vamsi Attunuru <[email protected]>

Current KNI implementation only operates in IOVA=PA mode, patch adds required functionality in KNI lib to support IOVA=VA mode.

KNI kernel module requires device info to get iommu domain related information for IOVA addr related translations. Patch defines device related info in rte_kni_device_info struct and passes device info to kernel KNI module when IOVA=VA mode is enabled.

---
 lib/librte_eal/linux/eal/include/rte_kni_common.h |  8 +++++
 lib/librte_kni/Makefile                           |  1 +
 lib/librte_kni/meson.build                        |  1 +
 lib/librte_kni/rte_kni.c                          | 36 +++++++++++++++++++++++
 4 files changed, 46 insertions(+)
lib/librte_eal/linux/eal/include/rte_kni_common.h +8 -0
index 37d9ee8..4fd8a90 100644
@@ -111,6 +111,13 @@ struct rte_kni_device_info {
 	void * mbuf_va;
 	phys_addr_t mbuf_phys;
 
+	/* PCI info */
+	uint16_t vendor_id;           /**< Vendor ID or PCI_ANY_ID. */
+	uint16_t device_id;           /**< Device ID or PCI_ANY_ID. */
+	uint8_t bus;                  /**< Device bus */
+	uint8_t devid;                /**< Device ID */
+	uint8_t function;             /**< Device function. */
+
 	uint16_t group_id;            /**< Group ID */
 	uint32_t core_id;             /**< core ID to bind for kernel thread */
 
@@ -121,6 +128,7 @@ struct rte_kni_device_info {
 	unsigned mbuf_size;
 	unsigned int mtu;
 	uint8_t mac_addr[6];
+	uint8_t iova_mode;
 };
 
 #define KNI_DEVICE "kni"
lib/librte_kni/Makefile +1 -0
index cbd6599..ab15d10 100644
@@ -7,6 +7,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 LIB = librte_kni.a
 
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -fno-strict-aliasing
+CFLAGS += -I$(RTE_SDK)/drivers/bus/pci
 LDLIBS += -lrte_eal -lrte_mempool -lrte_mbuf -lrte_ethdev
 
 EXPORT_MAP := rte_kni_version.map
lib/librte_kni/meson.build +1 -0
index 41fa2e3..fd46f87 100644
@@ -9,3 +9,4 @@ version = 2
 sources = files('rte_kni.c')
 headers = files('rte_kni.h')
 deps += ['ethdev', 'pci']
+includes += include_directories('../../drivers/bus/pci')
lib/librte_kni/rte_kni.c +36 -0
index 4b51fb4..ae17075 100644
@@ -14,6 +14,7 @@
 #include <rte_spinlock.h>
 #include <rte_string_fns.h>
 #include <rte_ethdev.h>
+#include <rte_bus_pci.h>
 #include <rte_malloc.h>
 #include <rte_log.h>
 #include <rte_kni.h>
@@ -199,6 +200,26 @@ kni_release_mz(struct rte_kni *kni)
 	rte_memzone_free(kni->m_sync_addr);
 }
 
+static void
+kni_dev_pci_addr_get(struct rte_pci_addr *addr,
+		    struct rte_pci_id *id, uint16_t port_id)
+{
+	const struct rte_pci_device *pci_dev;
+	const struct rte_bus *bus = NULL;
+	struct rte_eth_dev_info dev_info;
+
+	memset(&dev_info, 0, sizeof(dev_info));
+	rte_eth_dev_info_get(port_id, &dev_info);
+
+	if (dev_info.device)
+		bus = rte_bus_find_by_device(dev_info.device);
+	if (bus && !strcmp(bus->name, "pci")) {
+		pci_dev = RTE_DEV_TO_PCI(dev_info.device);
+		*addr = pci_dev->addr;
+		*id = pci_dev->id;
+	}
+}
+
 struct rte_kni *
 rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 	      const struct rte_kni_conf *conf,
@@ -247,6 +268,19 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 		kni->ops.port_id = UINT16_MAX;
 
 	memset(&dev_info, 0, sizeof(dev_info));
+
+	if (rte_eal_iova_mode() == RTE_IOVA_VA) {
+		uint16_t port_id = conf->group_id;
+		struct rte_pci_addr addr = { 0 };
+		struct rte_pci_id id = { 0 };
+
+		kni_dev_pci_addr_get(&addr, &id, port_id);
+		dev_info.bus = addr.bus;
+		dev_info.devid = addr.devid;
+		dev_info.function = addr.function;
+		dev_info.vendor_id = id.vendor_id;
+		dev_info.device_id = id.device_id;
+	}
 	dev_info.core_id = conf->core_id;
 	dev_info.force_bind = conf->force_bind;
 	dev_info.group_id = conf->group_id;
@@ -300,6 +334,8 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 	kni->group_id = conf->group_id;
 	kni->mbuf_size = conf->mbuf_size;
 
+	dev_info.iova_mode = (rte_eal_iova_mode() == RTE_IOVA_VA) ? 1 : 0;
+
 	ret = ioctl(kni_fd, RTE_KNI_IOCTL_CREATE, &dev_info);
 	if (ret < 0)
 		goto ioctl_fail;
Signature · 1 line
2.8.4
#155 lore raw

Re: [dpdk-dev] [PATCH v8 2/5] add IOVA -VA support in KNI lib

Quoted 12 lines · On 7/23/19 8:38 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

Current KNI implementation only operates in IOVA=PA mode, patch adds required functionality in KNI lib to support IOVA=VA mode.

KNI kernel module requires device info to get iommu domain related information for IOVA addr related translations. Patch defines device related info in rte_kni_device_info struct and passes device info to kernel KNI module when IOVA=VA mode is enabled.

<...>

Quoted 17 lines
lib/librte_kni/Makefile +1 -0
index cbd6599..ab15d10 100644
@@ -7,6 +7,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
  LIB = librte_kni.a
 
  CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -fno-strict-aliasing
+CFLAGS += -I$(RTE_SDK)/drivers/bus/pci
  LDLIBS += -lrte_eal -lrte_mempool -lrte_mbuf -lrte_ethdev
 
  EXPORT_MAP := rte_kni_version.map
lib/librte_kni/meson.build +0 -0
index 41fa2e3..fd46f87 100644

lib/librte_kni/meson.build version = 2 · line 11

Quoted 3 lines
lib/librte_kni/meson.build +0 -0
@@ -9,3 +9,4 @@ version = 2
  sources = files('rte_kni.c')
  headers = files('rte_kni.h')
  deps += ['ethdev', 'pci']

Not directly related to the patch, but are mempool and mbuf dependencies lost here. Cc Bruce to comment.
The library uses rte_mempool_obj_iter() and rte_pktmbuf_free() (which uses rte_mbuf_sanity_check()).

Quoted 14 lines
lib/librte_kni/meson.build +1 -0
+includes += include_directories('../../drivers/bus/pci')
lib/librte_kni/rte_kni.c +1 -0
index 4b51fb4..ae17075 100644
@@ -14,6 +14,7 @@
  #include <rte_spinlock.h>
  #include <rte_string_fns.h>
  #include <rte_ethdev.h>
+#include <rte_bus_pci.h>
  #include <rte_malloc.h>
  #include <rte_log.h>
  #include <rte_kni.h>

lib/librte_kni/rte_kni.c kni_release_mz(struct rte_kni *kni) · line 205

Quoted 6 lines
lib/librte_kni/rte_kni.c +3 -0
@@ -199,6 +200,26 @@ kni_release_mz(struct rte_kni *kni)
  	rte_memzone_free(kni->m_sync_addr);
  }
 
+static void
+kni_dev_pci_addr_get(struct rte_pci_addr *addr,
+		    struct rte_pci_id *id, uint16_t port_id)

Please, consider to make port_id the first argument. It is mandatory input argument which is used as a key to fill in other two output arguments.

lib/librte_kni/rte_kni.c kni_release_mz(struct rte_kni *kni) · line 211

Quoted 6 lines
lib/librte_kni/rte_kni.c +6 -0
+{
+	const struct rte_pci_device *pci_dev;
+	const struct rte_bus *bus = NULL;
+	struct rte_eth_dev_info dev_info;
+
+	memset(&dev_info, 0, sizeof(dev_info));

Most likely not required even now, but for sure not required if the patch [1] applied.

[1] http://patches.dpdk.org/patch/56959/

lib/librte_kni/rte_kni.c kni_release_mz(struct rte_kni *kni) · line 219

Quoted 8 lines
lib/librte_kni/rte_kni.c +8 -0
+	rte_eth_dev_info_get(port_id, &dev_info);
+
+	if (dev_info.device)
+		bus = rte_bus_find_by_device(dev_info.device);
+	if (bus && !strcmp(bus->name, "pci")) {
+		pci_dev = RTE_DEV_TO_PCI(dev_info.device);
+		*addr = pci_dev->addr;
+		*id = pci_dev->id;

I think it would be better to always init addr and id in the function. Otherwise caller does not know when it is initialized or not.

Quoted 7 lines
lib/librte_kni/rte_kni.c +3 -0
+	}
+}
+
  struct rte_kni *
  rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
  	      const struct rte_kni_conf *conf,

lib/librte_kni/rte_kni.c rte_kni_alloc(struct rte_mempool *pktmbuf_pool, · line 275

Quoted 8 lines
lib/librte_kni/rte_kni.c +5 -0
@@ -247,6 +268,19 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
  		kni->ops.port_id = UINT16_MAX;
 
  	memset(&dev_info, 0, sizeof(dev_info));
+
+	if (rte_eal_iova_mode() == RTE_IOVA_VA) {
+		uint16_t port_id = conf->group_id;
+		struct rte_pci_addr addr = { 0 };
+		struct rte_pci_id id = { 0 };

If addr and id are always initialized in kni_dev_pci_addr_get() init here would be not required.

Quoted 20 lines
lib/librte_kni/rte_kni.c +10 -0
+
+		kni_dev_pci_addr_get(&addr, &id, port_id);
+		dev_info.bus = addr.bus;
+		dev_info.devid = addr.devid;
+		dev_info.function = addr.function;
+		dev_info.vendor_id = id.vendor_id;
+		dev_info.device_id = id.device_id;
+	}
  	dev_info.core_id = conf->core_id;
  	dev_info.force_bind = conf->force_bind;
  	dev_info.group_id = conf->group_id;
@@ -300,6 +334,8 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
  	kni->group_id = conf->group_id;
  	kni->mbuf_size = conf->mbuf_size;
 
+	dev_info.iova_mode = (rte_eal_iova_mode() == RTE_IOVA_VA) ? 1 : 0;
+
  	ret = ioctl(kni_fd, RTE_KNI_IOCTL_CREATE, &dev_info);
  	if (ret < 0)
  		goto ioctl_fail;
#156 lore raw

PATCH v8 3/5 kni: add app specific mempool create & free routine

In reply to [email protected]

From: Vamsi Attunuru <[email protected]>

When KNI operates in IOVA = VA mode, it requires mbuf memory to be physically contiguous to ensure KNI kernel module could translate IOVA addresses properly. Patch adds a KNI specific mempool create routine to populate the KNI packet mbuf pool with memory objects that are being on a page.

KNI applications need to use this mempool create & free routines so that mbuf related requirements in IOVA = VA mode are handled inside those routines based on the enabled mode.

Updated the release notes with these new routine details.

---
 doc/guides/rel_notes/release_19_08.rst |  6 ++++
 examples/kni/main.c                    |  6 +++-
 lib/librte_kni/Makefile                |  1 +
 lib/librte_kni/meson.build             |  1 +
 lib/librte_kni/rte_kni.c               | 59 ++++++++++++++++++++++++++++++++++
 lib/librte_kni/rte_kni.h               | 49 ++++++++++++++++++++++++++++
 lib/librte_kni/rte_kni_version.map     |  2 ++
 7 files changed, 123 insertions(+), 1 deletion(-)
doc/guides/rel_notes/release_19_08.rst +6 -0
index 0a3f840..bd01e99 100644
@@ -281,6 +281,12 @@ API Changes
   offload flag from the library. The application must set this flag if it is
   supported by the platform and application wishes to use it.
 
+* kni: ``rte_kni_pktmbuf_pool_create`` ``rte_kni_pktmbuf_pool_free`` functions
+  were introduced for KNI applications for creating & freeing packet pool.
+  Since IOVA=VA mode was added in KNI, packet pool's mbuf memory should be
+  physically contiguous for the KNI kernel module to work in IOVA=VA mode,
+  this requirment was taken care in the kni packet pool creation fucntions.
+
 
 ABI Changes
 -----------
examples/kni/main.c +5 -1
index 4710d71..3b9c067 100644
@@ -975,7 +975,7 @@ main(int argc, char** argv)
 		rte_exit(EXIT_FAILURE, "Could not parse input parameters\n");
 
 	/* Create the mbuf pool */
-	pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF,
+	pktmbuf_pool = rte_kni_pktmbuf_pool_create("mbuf_pool", NB_MBUF,
 		MEMPOOL_CACHE_SZ, 0, MBUF_DATA_SZ, rte_socket_id());
 	if (pktmbuf_pool == NULL) {
 		rte_exit(EXIT_FAILURE, "Could not initialise mbuf pool\n");
@@ -1043,6 +1043,10 @@ main(int argc, char** argv)
 			continue;
 		kni_free_kni(port);
 	}
+
+	if (pktmbuf_pool)
+		rte_kni_pktmbuf_pool_free(pktmbuf_pool);
+
 	for (i = 0; i < RTE_MAX_ETHPORTS; i++)
 		if (kni_port_params_array[i]) {
 			rte_free(kni_port_params_array[i]);
lib/librte_kni/Makefile +1 -0
index ab15d10..5e3dd01 100644
@@ -6,6 +6,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 # library name
 LIB = librte_kni.a
 
+CFLAGS += -DALLOW_EXPERIMENTAL_API
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -fno-strict-aliasing
 CFLAGS += -I$(RTE_SDK)/drivers/bus/pci
 LDLIBS += -lrte_eal -lrte_mempool -lrte_mbuf -lrte_ethdev
lib/librte_kni/meson.build +1 -0
index fd46f87..e357445 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
+allow_experimental_apis = true
 if not is_linux or not dpdk_conf.get('RTE_ARCH_64')
 	build = false
 	reason = 'only supported on 64-bit linux'
lib/librte_kni/rte_kni.c +59 -0

65 lines not on this page · raw message

lib/librte_kni/rte_kni.h +49 -0

61 lines not on this page · raw message

lib/librte_kni/rte_kni_version.map +2 -0
index c877dc6..aba9728 100644
@@ -20,4 +20,6 @@ EXPERIMENTAL {
 	global:
 
 	rte_kni_update_link;
+	rte_kni_pktmbuf_pool_create;
+	rte_kni_pktmbuf_pool_free;
 };
Signature · 1 line
2.8.4
#157 lore raw

Re: [dpdk-dev] [PATCH v8 3/5] kni: add app specific mempool create & free routine

Quoted 57 lines · On 7/23/19 8:38 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

When KNI operates in IOVA = VA mode, it requires mbuf memory to be physically contiguous to ensure KNI kernel module could translate IOVA addresses properly. Patch adds a KNI specific mempool create routine to populate the KNI packet mbuf pool with memory objects that are being on a page.

KNI applications need to use this mempool create & free routines so that mbuf related requirements in IOVA = VA mode are handled inside those routines based on the enabled mode.

Updated the release notes with these new routine details.

---
  doc/guides/rel_notes/release_19_08.rst |  6 ++++
  examples/kni/main.c                    |  6 +++-
  lib/librte_kni/Makefile                |  1 +
  lib/librte_kni/meson.build             |  1 +
  lib/librte_kni/rte_kni.c               | 59 ++++++++++++++++++++++++++++++++++
  lib/librte_kni/rte_kni.h               | 49 ++++++++++++++++++++++++++++
  lib/librte_kni/rte_kni_version.map     |  2 ++
  7 files changed, 123 insertions(+), 1 deletion(-)
doc/guides/rel_notes/release_19_08.rst +6 -0
index 0a3f840..bd01e99 100644
@@ -281,6 +281,12 @@ API Changes
    offload flag from the library. The application must set this flag if it is
    supported by the platform and application wishes to use it.
 
+* kni: ``rte_kni_pktmbuf_pool_create`` ``rte_kni_pktmbuf_pool_free`` functions
+  were introduced for KNI applications for creating & freeing packet pool.
+  Since IOVA=VA mode was added in KNI, packet pool's mbuf memory should be
+  physically contiguous for the KNI kernel module to work in IOVA=VA mode,
+  this requirment was taken care in the kni packet pool creation fucntions.
+
 
  ABI Changes
  -----------
examples/kni/main.c +1 -1
index 4710d71..3b9c067 100644
@@ -975,7 +975,7 @@ main(int argc, char** argv)
  		rte_exit(EXIT_FAILURE, "Could not parse input parameters\n");
 
  	/* Create the mbuf pool */
-	pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF,
+	pktmbuf_pool = rte_kni_pktmbuf_pool_create("mbuf_pool", NB_MBUF,
  		MEMPOOL_CACHE_SZ, 0, MBUF_DATA_SZ, rte_socket_id());
  	if (pktmbuf_pool == NULL) {
  		rte_exit(EXIT_FAILURE, "Could not initialise mbuf pool\n");

examples/kni/main.c main(int argc, char** argv) · line 1047

Quoted 5 lines
examples/kni/main.c +2 -0
@@ -1043,6 +1043,10 @@ main(int argc, char** argv)
  			continue;
  		kni_free_kni(port);
  	}
+
+	if (pktmbuf_pool)

Typically pointer is compared to NULL, but it is not required here anyway, since rte_mempool_free() handles NULL perfectly itself.

Quoted 5 lines
examples/kni/main.c +2 -0
+		rte_kni_pktmbuf_pool_free(pktmbuf_pool);
+
  	for (i = 0; i < RTE_MAX_ETHPORTS; i++)
  		if (kni_port_params_array[i]) {
  			rte_free(kni_port_params_array[i]);

<...>

lib/librte_kni/rte_kni.h line 23

Quoted 9 lines
lib/librte_kni/rte_kni.h +1 -0
index 5699a64..7f11927 100644
@@ -20,6 +20,7 @@
  #include <rte_pci.h>
  #include <rte_memory.h>
  #include <rte_mempool.h>
+#include <rte_mbuf_pool_ops.h>

I don't understand why it is included here.

Quoted 4 lines
lib/librte_kni/rte_kni.h +0 -0
  #include <rte_ether.h>
 
  #include <rte_kni_common.h>

<...>

#158 lore raw

Re: [dpdk-dev] [PATCH v8 3/5] kni: add app specific mempool create & free routine

Quoted 67 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Tuesday, July 23, 2019 4:20 PM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v8 3/5] kni: add app specific mempool create & free routine

Quoted 54 lines · On 7/23/19 8:38 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

When KNI operates in IOVA = VA mode, it requires mbuf memory to be physically contiguous to ensure KNI kernel module could translate IOVA addresses properly. Patch adds a KNI specific mempool create routine to populate the KNI packet mbuf pool with memory objects that are being on a page.

KNI applications need to use this mempool create & free routines so that mbuf related requirements in IOVA = VA mode are handled inside those routines based on the enabled mode.

Updated the release notes with these new routine details.

---
  doc/guides/rel_notes/release_19_08.rst |  6 ++++
  examples/kni/main.c                    |  6 +++-
  lib/librte_kni/Makefile                |  1 +
  lib/librte_kni/meson.build             |  1 +
  lib/librte_kni/rte_kni.c               | 59 ++++++++++++++++++++++++++++++++++
  lib/librte_kni/rte_kni.h               | 49 ++++++++++++++++++++++++++++
  lib/librte_kni/rte_kni_version.map     |  2 ++
  7 files changed, 123 insertions(+), 1 deletion(-)
doc/guides/rel_notes/release_19_08.rst +9 -0
index 0a3f840..bd01e99 100644
@@ -281,6 +281,12 @@ API Changes
    offload flag from the library. The application must set this flag if it is
    supported by the platform and application wishes to use it.
 
+* kni: ``rte_kni_pktmbuf_pool_create`` ``rte_kni_pktmbuf_pool_free``
+functions
+  were introduced for KNI applications for creating & freeing packet pool.
+  Since IOVA=VA mode was added in KNI, packet pool's mbuf memory
+should be
+  physically contiguous for the KNI kernel module to work in IOVA=VA
+mode,
+  this requirment was taken care in the kni packet pool creation fucntions.
+
 
  ABI Changes
  -----------
examples/kni/main.c index renamed from examples/kni/main.c +0 -0

4710d71..3b9c067 100644

examples/kni/main.c +0 -0
@@ -975,7 +975,7 @@ main(int argc, char** argv)
  		rte_exit(EXIT_FAILURE, "Could not parse input parameters\n");
 
Quoted 15 lines

examples/kni/main.c main(int argc, char** argv)

Quoted 12 lines
examples/kni/main.c +3 -2
  	/* Create the mbuf pool */
-	pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF,
+	pktmbuf_pool = rte_kni_pktmbuf_pool_create("mbuf_pool", NB_MBUF,
  		MEMPOOL_CACHE_SZ, 0, MBUF_DATA_SZ, rte_socket_id());
  	if (pktmbuf_pool == NULL) {
  		rte_exit(EXIT_FAILURE, "Could not initialise mbuf pool\n"); @@
-1043,6 +1043,10 @@ main(int argc, char** argv)
  			continue;
  		kni_free_kni(port);
  	}
+
+	if (pktmbuf_pool)

Typically pointer is compared to NULL, but it is not required here anyway, since rte_mempool_free() handles NULL perfectly itself.

Ack

Quoted 9 lines
Quoted 6 lines
examples/kni/main.c +2 -0
+		rte_kni_pktmbuf_pool_free(pktmbuf_pool);
+
  	for (i = 0; i < RTE_MAX_ETHPORTS; i++)
  		if (kni_port_params_array[i]) {
  			rte_free(kni_port_params_array[i]);

<...>

Quoted 12 lines

lib/librte_kni/rte_kni.h line 23

Quoted 9 lines
lib/librte_kni/rte_kni.h index renamed from lib/librte_kni/rte_kni.h +0 -0

5699a64..7f11927 100644

lib/librte_kni/rte_kni.h +1 -0
@@ -20,6 +20,7 @@
  #include <rte_pci.h>
  #include <rte_memory.h>
  #include <rte_mempool.h>
+#include <rte_mbuf_pool_ops.h>

I don't understand why it is included here.

included to fix compilation of rte_kni.c post this patch changes, could be included in rte_kni.c though.

Quoted 6 lines
Quoted 4 lines
lib/librte_kni/rte_kni.h +0 -0
  #include <rte_ether.h>
 
  #include <rte_kni_common.h>

<...>

#159 lore raw

PATCH v8 4/5 kni: add IOVA=VA support in KNI module

In reply to [email protected]

From: Kiran Kumar K <[email protected]>

Patch adds support for kernel module to work in IOVA = VA mode, the idea is to get physical address from IOVA address using iommu_iova_to_phys API and later use phys_to_virt API to convert the physical address to kernel virtual address.

When compared with IOVA = PA mode, there is no performance drop with this approach.

This approach does not work with the kernel versions less than 4.4.0 because of API compatibility issues.

Patch also updates these support details in KNI documentation.

---
 kernel/linux/kni/compat.h   |  4 +++
 kernel/linux/kni/kni_dev.h  |  4 +++
 kernel/linux/kni/kni_misc.c | 71 +++++++++++++++++++++++++++++++++++++++------
 kernel/linux/kni/kni_net.c  | 59 ++++++++++++++++++++++++++++---------
 4 files changed, 116 insertions(+), 22 deletions(-)
kernel/linux/kni/compat.h +4 -0
index 562d8bf..ee997a6 100644
@@ -121,3 +121,7 @@
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
 #define HAVE_SIGNAL_FUNCTIONS_OWN_HEADER
 #endif
+
+#if KERNEL_VERSION(4, 4, 0) <= LINUX_VERSION_CODE
+#define HAVE_IOVA_AS_VA_SUPPORT
+#endif
kernel/linux/kni/kni_dev.h +4 -0
index c1ca678..d5898f3 100644
@@ -25,6 +25,7 @@
 #include <linux/netdevice.h>
 #include <linux/spinlock.h>
 #include <linux/list.h>
+#include <linux/iommu.h>
 
 #include <rte_kni_common.h>
 #define KNI_KTHREAD_RESCHEDULE_INTERVAL 5 /* us */
@@ -41,6 +42,9 @@ struct kni_dev {
 	/* kni list */
 	struct list_head list;
 
+	uint8_t iova_mode;
+	struct iommu_domain *domain;
+
 	uint32_t core_id;            /* Core ID to bind */
 	char name[RTE_KNI_NAMESIZE]; /* Network device name */
 	struct task_struct *pthread;
kernel/linux/kni/kni_misc.c +62 -9

83 lines not on this page · raw message

kernel/linux/kni/kni_net.c +46 -13

116 lines not on this page · raw message

Signature · 1 line
2.8.4
#160 lore raw

PATCH v8 5/5 kni: modify IOVA mode checks to support VA

In reply to [email protected]

From: Vamsi Attunuru <[email protected]>

Patch addresses checks in KNI and eal that enforce IOVA=PA when IOVA=VA mode is enabled, since KNI kernel module supports VA mode for kernel versions >= 4.4.0.

Updated KNI documentation with above details.

---
 doc/guides/prog_guide/kernel_nic_interface.rst | 8 ++++++++
 lib/librte_eal/linux/eal/eal.c                 | 4 +++-
 lib/librte_kni/rte_kni.c                       | 5 -----
 3 files changed, 11 insertions(+), 6 deletions(-)
doc/guides/prog_guide/kernel_nic_interface.rst +8 -0
index 38369b3..fd2ce63 100644
@@ -291,6 +291,14 @@ The sk_buff is then freed and the mbuf sent in the tx_q FIFO.
 The DPDK TX thread dequeues the mbuf and sends it to the PMD via ``rte_eth_tx_burst()``.
 It then puts the mbuf back in the cache.
 
+IOVA = VA: Support
+------------------
+
+KNI can be operated in IOVA as VA scheme when following criteria are fullfilled
+
+- LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)
+- eal param `--iova-mode va` is passed or bus IOVA scheme is set to RTE_IOVA_VA
+
 Ethtool
 -------
 
lib/librte_eal/linux/eal/eal.c +3 -1
index 2e5499f..9705243 100644
@@ -1070,12 +1070,14 @@ rte_eal_init(int argc, char **argv)
 		/* Workaround for KNI which requires physical address to work */
 		if (iova_mode == RTE_IOVA_VA &&
 				rte_eal_check_module("rte_kni") == 1) {
+#if KERNEL_VERSION(4, 4, 0) > LINUX_VERSION_CODE
 			if (phys_addrs) {
 				iova_mode = RTE_IOVA_PA;
-				RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI module is loaded\n");
+				RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI module does not support VA\n");
 			} else {
 				RTE_LOG(DEBUG, EAL, "KNI can not work since physical addresses are unavailable\n");
 			}
+#endif
 		}
 #endif
 		rte_eal_get_configuration()->iova_mode = iova_mode;
lib/librte_kni/rte_kni.c +0 -5
index 897a5bb..6a95230 100644
@@ -98,11 +98,6 @@ static volatile int kni_fd = -1;
 int
 rte_kni_init(unsigned int max_kni_ifaces __rte_unused)
 {
-	if (rte_eal_iova_mode() != RTE_IOVA_PA) {
-		RTE_LOG(ERR, KNI, "KNI requires IOVA as PA\n");
-		return -1;
-	}
-
 	/* Check FD and open */
 	if (kni_fd < 0) {
 		kni_fd = open("/dev/" KNI_DEVICE, O_RDWR);
Signature · 1 line
2.8.4
#161 lore raw

Re: [dpdk-dev] [PATCH v8 0/5] kni: add IOVA=VA support

In reply to [email protected]

Ping,

Req for V8 review comments..

Quoted 80 lines

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Tuesday, July 23, 2019 11:08 AM
To: [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>; Vamsi Krishna Attunuru <[email protected]>
Subject: [dpdk-dev] [PATCH v8 0/5] kni: add IOVA=VA support

From: Vamsi Attunuru <[email protected]>

---
V8 Changes:
* Remove default mempool populate() routine changes.
* Add kni app specific mempool create & free routines.
* Add new mempool populate routine to allocate page-aligned memzones with page size to make sure all mempool objects reside on a page.
* Update release notes and map files.

V7 Changes:
* Removed previously proposed mempool flag and made those page boundary checks default in mempool populate() except for the objects size bigger than the size of page.
* Removed KNI example application related changes since pool related requirement is taken care in mempool lib.
* All PCI dev related info is moved under rte_eal_iova_mode() == VA check.
* Added wrapper functions in KNI module to hide IOVA checks and make address translation routines more readable.
* Updated IOVA mode checks that enforcing IOVA=PA mode when IOVA=VA mode is enabled.

V6 Changes:
* Added new mempool flag to ensure mbuf memory is not scattered across page boundaries.
* Added KNI kernel module required PCI device information.
* Modified KNI example application to create mempool with new mempool flag.

V5 changes:
* Fixed build issue with 32b build

V4 changes:
* Fixed build issues with older kernel versions
* This approach will only work with kernel above 4.4.0

V3 Changes:
* Add new approach to work kni with IOVA=VA mode using iommu_iova_to_phys API.

Kiran Kumar K (1):
kni: add IOVA=VA support in KNI module

Vamsi Attunuru (4):
mempool: populate mempool with page sized chunks of memory add IOVA -VA support in KNI lib
kni: add app specific mempool create & free routine
kni: modify IOVA mode checks to support VA

 doc/guides/prog_guide/kernel_nic_interface.rst    |   8 ++
 doc/guides/rel_notes/release_19_08.rst            |   6 ++
 examples/kni/main.c                               |   6 +-
 kernel/linux/kni/compat.h                         |   4 +
 kernel/linux/kni/kni_dev.h                        |   4 +
 kernel/linux/kni/kni_misc.c                       |  71 +++++++++++++--
 kernel/linux/kni/kni_net.c                        |  59 ++++++++++---
 lib/librte_eal/linux/eal/eal.c                    |   4 +-
 lib/librte_eal/linux/eal/include/rte_kni_common.h |   8 ++
 lib/librte_kni/Makefile                           |   2 +
 lib/librte_kni/meson.build                        |   2 +
 lib/librte_kni/rte_kni.c                          | 100 ++++++++++++++++++++--
 lib/librte_kni/rte_kni.h                          |  49 +++++++++++
 lib/librte_kni/rte_kni_version.map                |   2 +
 lib/librte_mempool/rte_mempool.c                  |  59 +++++++++++++
 lib/librte_mempool/rte_mempool.h                  |  17 ++++
 lib/librte_mempool/rte_mempool_version.map        |   1 +
 17 files changed, 373 insertions(+), 29 deletions(-)

--
2.8.4

#162 lore raw

v9 cover kni: add IOVA=VA support

In reply to [email protected]

From: Vamsi Attunuru <[email protected]>

---
V9 Changes:
* Used rte_mempool_ops_calc_mem_size() instead of default handler in the new mempool populate routine.
* Check min_chunk_size and return values.
* Removed ethdev_info memset to '0' and moved pci dev_info populate into kni_dev_pci_addr_get() routine.
* Addressed misc. review comments.

V8 Changes:
* Remove default mempool populate() routine changes.
* Add kni app specific mempool create & free routines.
* Add new mempool populate routine to allocate page-aligned memzones with page size to make sure all mempool objects reside on a page.
* Update release notes and map files.

V7 Changes:
* Removed previously proposed mempool flag and made those page boundary checks default in mempool populate() except for the objects size bigger than the size of page.
* Removed KNI example application related changes since pool related requirement is taken care in mempool lib.
* All PCI dev related info is moved under rte_eal_iova_mode() == VA check.
* Added wrapper functions in KNI module to hide IOVA checks and make address translation routines more readable.
* Updated IOVA mode checks that enforcing IOVA=PA mode when IOVA=VA mode is enabled.

V6 Changes:
* Added new mempool flag to ensure mbuf memory is not scattered across page boundaries.
* Added KNI kernel module required PCI device information.
* Modified KNI example application to create mempool with new mempool flag.

V5 changes:
* Fixed build issue with 32b build

V4 changes:
* Fixed build issues with older kernel versions
* This approach will only work with kernel above 4.4.0

V3 Changes:
* Add new approach to work kni with IOVA=VA mode using iommu_iova_to_phys API.

Kiran Kumar K (1):
kni: add IOVA=VA support in KNI module

Vamsi Attunuru (4):
mempool: populate mempool with the page sized chunks of memory
kni: add IOVA=VA support in KNI lib
kni: add app specific mempool create & free routine
kni: modify IOVA mode checks to support VA

 doc/guides/prog_guide/kernel_nic_interface.rst    |  8 ++
 doc/guides/rel_notes/release_19_08.rst            |  6 ++
 examples/kni/main.c                               |  5 +-
 kernel/linux/kni/compat.h                         |  4 +
 kernel/linux/kni/kni_dev.h                        |  4 +
 kernel/linux/kni/kni_misc.c                       | 71 ++++++++++++++---
 kernel/linux/kni/kni_net.c                        | 59 ++++++++++----
 lib/librte_eal/linux/eal/eal.c                    |  4 +-
 lib/librte_eal/linux/eal/include/rte_kni_common.h |  8 ++
 lib/librte_kni/Makefile                           |  2 +
 lib/librte_kni/meson.build                        |  2 +
 lib/librte_kni/rte_kni.c                          | 95 +++++++++++++++++++++--
 lib/librte_kni/rte_kni.h                          | 48 ++++++++++++
 lib/librte_kni/rte_kni_version.map                |  2 +
 lib/librte_mempool/rte_mempool.c                  | 64 +++++++++++++++
 lib/librte_mempool/rte_mempool.h                  | 17 ++++
 lib/librte_mempool/rte_mempool_version.map        |  1 +
 17 files changed, 371 insertions(+), 29 deletions(-)
Signature · 1 line
2.8.4
#163 lore raw

PATCH v9 1/5 mempool: populate mempool with the page sized chunks of memory

From: Vamsi Attunuru <[email protected]>

Patch adds a routine to populate mempool from page aligned and page sized chunks of memory to ensure memory objs do not fall across the page boundaries. It's useful for applications that require physically contiguous mbuf memory while running in IOVA=VA mode.

---
 lib/librte_mempool/rte_mempool.c           | 64 ++++++++++++++++++++++++++++++
 lib/librte_mempool/rte_mempool.h           | 17 ++++++++
 lib/librte_mempool/rte_mempool_version.map |  1 +
 3 files changed, 82 insertions(+)
lib/librte_mempool/rte_mempool.c +64 -0
index 7260ce0..00619bd 100644
@@ -414,6 +414,70 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
 	return ret;
 }
 
+/* Function to populate mempool from page sized mem chunks, allocate page size
+ * of memory in memzone and populate them. Return the number of objects added,
+ * or a negative value on error.
+ */
+int
+rte_mempool_populate_from_pg_sz_chunks(struct rte_mempool *mp)
+{
+	char mz_name[RTE_MEMZONE_NAMESIZE];
+	size_t align, pg_sz, pg_shift;
+	const struct rte_memzone *mz;
+	unsigned int mz_id, n;
+	size_t min_chunk_size;
+	int ret;
+
+	ret = mempool_ops_alloc_once(mp);
+	if (ret != 0)
+		return ret;
+
+	if (mp->nb_mem_chunks != 0)
+		return -EEXIST;
+
+	pg_sz = get_min_page_size(mp->socket_id);
+	pg_shift = rte_bsf32(pg_sz);
+
+	for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) {
+
+		ret = rte_mempool_ops_calc_mem_size(mp, n,
+				pg_shift, &min_chunk_size, &align);
+
+		if (ret < 0 || min_chunk_size > pg_sz)
+			goto fail;
+
+		ret = snprintf(mz_name, sizeof(mz_name),
+			RTE_MEMPOOL_MZ_FORMAT "_%d", mp->name, mz_id);
+		if (ret < 0 || ret >= (int)sizeof(mz_name)) {
+			ret = -ENAMETOOLONG;
+			goto fail;
+		}
+
+		mz = rte_memzone_reserve_aligned(mz_name, min_chunk_size,
+				mp->socket_id, 0, align);
+
+		if (mz == NULL) {
+			ret = -rte_errno;
+			goto fail;
+		}
+
+		ret = rte_mempool_populate_iova(mp, mz->addr,
+				mz->iova, mz->len,
+				rte_mempool_memchunk_mz_free,
+				(void *)(uintptr_t)mz);
+		if (ret < 0) {
+			rte_memzone_free(mz);
+			goto fail;
+		}
+	}
+
+	return mp->size;
+
+fail:
+	rte_mempool_free_memchunks(mp);
+	return ret;
+}
+
 /* Default function to populate the mempool: allocate memory in memzones,
  * and populate them. Return the number of objects added, or a negative
  * value on error.
lib/librte_mempool/rte_mempool.h +17 -0
index 8053f7a..3046e4f 100644
@@ -1062,6 +1062,23 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
 	void *opaque);
 
 /**
+ * Add memory from page sized memzones for objects in the pool at init
+ *
+ * This is the function used to populate the mempool with page aligned and
+ * page sized memzone memory to avoid spreading object memory across two pages
+ * and to ensure all mempool objects reside on the page memory.
+ *
+ * @param mp
+ *   A pointer to the mempool structure.
+ * @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.
+ */
+__rte_experimental
+int rte_mempool_populate_from_pg_sz_chunks(struct rte_mempool *mp);
+
+/**
  * Add memory for objects in the pool at init
  *
  * This is the default function used by rte_mempool_create() to populate
lib/librte_mempool/rte_mempool_version.map +1 -0
index 17cbca4..9a6fe65 100644
@@ -57,4 +57,5 @@ EXPERIMENTAL {
 	global:
 
 	rte_mempool_ops_get_info;
+	rte_mempool_populate_from_pg_sz_chunks;
 };
Signature · 1 line
2.8.4
Acked-by on v9 1/5
#164 lore raw

Re: [dpdk-dev] [PATCH v9 1/5] mempool: populate mempool with the page sized chunks of memory

Quoted 10 lines · On 7/29/19 3:13 PM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

Patch adds a routine to populate mempool from page aligned and page sized chunks of memory to ensure memory objs do not fall across the page boundaries. It's useful for applications that require physically contiguous mbuf memory while running in IOVA=VA mode.

When two below issues fixed:

As I understand it is likely to be a temporary solution until the problem is fixed in a generic way.

Quoted 34 lines
---
  lib/librte_mempool/rte_mempool.c           | 64 ++++++++++++++++++++++++++++++
  lib/librte_mempool/rte_mempool.h           | 17 ++++++++
  lib/librte_mempool/rte_mempool_version.map |  1 +
  3 files changed, 82 insertions(+)
lib/librte_mempool/rte_mempool.c +20 -0
index 7260ce0..00619bd 100644
@@ -414,6 +414,70 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
  	return ret;
  }
 
+/* Function to populate mempool from page sized mem chunks, allocate page size
+ * of memory in memzone and populate them. Return the number of objects added,
+ * or a negative value on error.
+ */
+int
+rte_mempool_populate_from_pg_sz_chunks(struct rte_mempool *mp)
+{
+	char mz_name[RTE_MEMZONE_NAMESIZE];
+	size_t align, pg_sz, pg_shift;
+	const struct rte_memzone *mz;
+	unsigned int mz_id, n;
+	size_t min_chunk_size;
+	int ret;
+
+	ret = mempool_ops_alloc_once(mp);
+	if (ret != 0)
+		return ret;
+
+	if (mp->nb_mem_chunks != 0)
+		return -EEXIST;

lib/librte_mempool/rte_mempool.c rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, · line 446

Quoted 10 lines
lib/librte_mempool/rte_mempool.c +10 -0
+
+	pg_sz = get_min_page_size(mp->socket_id);
+	pg_shift = rte_bsf32(pg_sz);
+
+	for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) {
+
+		ret = rte_mempool_ops_calc_mem_size(mp, n,
+				pg_shift, &min_chunk_size, &align);
+
+		if (ret < 0 || min_chunk_size > pg_sz)

If min_chunk_size is greater than pg_sz, ret is 0 and function returns success.

Quoted 42 lines
lib/librte_mempool/rte_mempool.c +34 -0
+			goto fail;
+
+		ret = snprintf(mz_name, sizeof(mz_name),
+			RTE_MEMPOOL_MZ_FORMAT "_%d", mp->name, mz_id);
+		if (ret < 0 || ret >= (int)sizeof(mz_name)) {
+			ret = -ENAMETOOLONG;
+			goto fail;
+		}
+
+		mz = rte_memzone_reserve_aligned(mz_name, min_chunk_size,
+				mp->socket_id, 0, align);
+
+		if (mz == NULL) {
+			ret = -rte_errno;
+			goto fail;
+		}
+
+		ret = rte_mempool_populate_iova(mp, mz->addr,
+				mz->iova, mz->len,
+				rte_mempool_memchunk_mz_free,
+				(void *)(uintptr_t)mz);
+		if (ret < 0) {
+			rte_memzone_free(mz);
+			goto fail;
+		}
+	}
+
+	return mp->size;
+
+fail:
+	rte_mempool_free_memchunks(mp);
+	return ret;
+}
+
  /* Default function to populate the mempool: allocate memory in memzones,
   * and populate them. Return the number of objects added, or a negative
   * value on error.
lib/librte_mempool/rte_mempool.h +0 -0
index 8053f7a..3046e4f 100644

lib/librte_mempool/rte_mempool.h rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, · line 1064

Quoted 3 lines
lib/librte_mempool/rte_mempool.h +0 -0
@@ -1062,6 +1062,23 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
  	void *opaque);
 
  /**

 * @warning
 * @b EXPERIMENTAL: this API may change without prior notice.

is missing

Quoted 30 lines
lib/librte_mempool/rte_mempool.h +17 -0
+ * Add memory from page sized memzones for objects in the pool at init
+ *
+ * This is the function used to populate the mempool with page aligned and
+ * page sized memzone memory to avoid spreading object memory across two pages
+ * and to ensure all mempool objects reside on the page memory.
+ *
+ * @param mp
+ *   A pointer to the mempool structure.
+ * @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.
+ */
+__rte_experimental
+int rte_mempool_populate_from_pg_sz_chunks(struct rte_mempool *mp);
+
+/**
   * Add memory for objects in the pool at init
   *
   * This is the default function used by rte_mempool_create() to populate
lib/librte_mempool/rte_mempool_version.map +1 -0
index 17cbca4..9a6fe65 100644
@@ -57,4 +57,5 @@ EXPERIMENTAL {
  	global:
 
  	rte_mempool_ops_get_info;
+	rte_mempool_populate_from_pg_sz_chunks;
  };
#165 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v9 1/5] mempool: populate mempool with the page sized chunks of memory

Quoted 75 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Monday, July 29, 2019 6:12 PM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: [EXT] Re: [dpdk-dev] [PATCH v9 1/5] mempool: populate mempool with the page sized chunks of memory

External Email

----------------------------------------------------------------------

Quoted 9 lines · On 7/29/19 3:13 PM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

Patch adds a routine to populate mempool from page aligned and page sized chunks of memory to ensure memory objs do not fall across the page boundaries. It's useful for applications that require physically contiguous mbuf memory while running in IOVA=VA mode.

When two below issues fixed:

As I understand it is likely to be a temporary solution until the problem is fixed in a generic way.

Quoted 2 lines
---
  lib/librte_mempool/rte_mempool.c           | 64

++++++++++++++++++++++++++++++

lib/librte_mempool/rte_mempool.c rte_mempool_populate_virt(struct rte_mempool

Quoted 10 lines
  lib/librte_mempool/rte_mempool.h           | 17 ++++++++
  lib/librte_mempool/rte_mempool_version.map |  1 +
  3 files changed, 82 insertions(+)
lib/librte_mempool/rte_mempool.c +0 -0
index 7260ce0..00619bd 100644
@@ -414,6 +414,70 @@ rte_mempool_populate_virt(struct rte_mempool

*mp, char *addr,

Quoted 28 lines
lib/librte_mempool/rte_mempool.c +25 -0
  	return ret;
  }
 
+/* Function to populate mempool from page sized mem chunks, allocate
+page size
+ * of memory in memzone and populate them. Return the number of
+objects added,
+ * or a negative value on error.
+ */
+int
+rte_mempool_populate_from_pg_sz_chunks(struct rte_mempool *mp) {
+	char mz_name[RTE_MEMZONE_NAMESIZE];
+	size_t align, pg_sz, pg_shift;
+	const struct rte_memzone *mz;
+	unsigned int mz_id, n;
+	size_t min_chunk_size;
+	int ret;
+
+	ret = mempool_ops_alloc_once(mp);
+	if (ret != 0)
+		return ret;
+
+	if (mp->nb_mem_chunks != 0)
+		return -EEXIST;
+
+	pg_sz = get_min_page_size(mp->socket_id);
+	pg_shift = rte_bsf32(pg_sz);
+
Quoted 8 lines

lib/librte_mempool/rte_mempool.c rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, · line 446

Quoted 6 lines
lib/librte_mempool/rte_mempool.c +6 -0
+	for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) {
+
+		ret = rte_mempool_ops_calc_mem_size(mp, n,
+				pg_shift, &min_chunk_size, &align);
+
+		if (ret < 0 || min_chunk_size > pg_sz)

If min_chunk_size is greater than pg_sz, ret is 0 and function returns success.

Ack, will fix it in next version.

Quoted 48 lines

lib/librte_mempool/rte_mempool.c rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,

Quoted 5 lines
lib/librte_mempool/rte_mempool.c +4 -0
+			goto fail;
+
+		ret = snprintf(mz_name, sizeof(mz_name),
+			RTE_MEMPOOL_MZ_FORMAT "_%d", mp->name,

mz_id);

lib/librte_mempool/rte_mempool.c rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,

Quoted 6 lines
lib/librte_mempool/rte_mempool.c +6 -0
+		if (ret < 0 || ret >= (int)sizeof(mz_name)) {
+			ret = -ENAMETOOLONG;
+			goto fail;
+		}
+
+		mz = rte_memzone_reserve_aligned(mz_name,

min_chunk_size,

Quoted 15 lines
lib/librte_mempool/rte_mempool.c +15 -0
+				mp->socket_id, 0, align);
+
+		if (mz == NULL) {
+			ret = -rte_errno;
+			goto fail;
+		}
+
+		ret = rte_mempool_populate_iova(mp, mz->addr,
+				mz->iova, mz->len,
+				rte_mempool_memchunk_mz_free,
+				(void *)(uintptr_t)mz);
+		if (ret < 0) {
+			rte_memzone_free(mz);
+			goto fail;
+		}

lib/librte_mempool/rte_mempool.c rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,

Quoted 10 lines
lib/librte_mempool/rte_mempool.c +9 -0
+	}
+
+	return mp->size;
+
+fail:
+	rte_mempool_free_memchunks(mp);
+	return ret;
+}
+
  /* Default function to populate the mempool: allocate memory in

memzones,

lib/librte_mempool/rte_mempool.h rte_mempool_populate_virt(struct

Quoted 8 lines
lib/librte_mempool/rte_mempool.c +0 -0
   * and populate them. Return the number of objects added, or a negative
   * value on error.
lib/librte_mempool/rte_mempool.h +0 -0
index 8053f7a..3046e4f 100644
@@ -1062,6 +1062,23 @@ rte_mempool_populate_virt(struct

rte_mempool *mp, char *addr,

Quoted 8 lines

lib/librte_mempool/rte_mempool.h rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, · line 1064

Quoted 3 lines
lib/librte_mempool/rte_mempool.h +0 -0
  	void *opaque);
 
  /**

 * @warning
 * @b EXPERIMENTAL: this API may change without prior notice.

is missing

Ack

Quoted 36 lines
Quoted 9 lines
lib/librte_mempool/rte_mempool.h +8 -0
+ * Add memory from page sized memzones for objects in the pool at
+init
+ *
+ * This is the function used to populate the mempool with page
+aligned and
+ * page sized memzone memory to avoid spreading object memory across
+two pages
+ * and to ensure all mempool objects reside on the page memory.

lib/librte_mempool/rte_mempool.h rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,

Quoted 10 lines
lib/librte_mempool/rte_mempool.h +10 -0
+ *
+ * @param mp
+ *   A pointer to the mempool structure.
+ * @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.
+ */
+__rte_experimental
+int rte_mempool_populate_from_pg_sz_chunks(struct rte_mempool

*mp);

Quoted 16 lines
lib/librte_mempool/rte_mempool.h +2 -0
+
+/**
   * Add memory for objects in the pool at init
   *
   * This is the default function used by rte_mempool_create() to

populate diff --git a/lib/librte_mempool/rte_mempool_version.map b/lib/librte_mempool/rte_mempool_version.map
index 17cbca4..9a6fe65 100644

lib/librte_mempool/rte_mempool_version.map +1 -0
@@ -57,4 +57,5 @@ EXPERIMENTAL {
  	global:
 
  	rte_mempool_ops_get_info;
+	rte_mempool_populate_from_pg_sz_chunks;
  };
#166 lore raw

v10 cover kni: add IOVA=VA support

In reply to [email protected]

From: Vamsi Attunuru <[email protected]>

---
V10 Changes:
* Fixed function return code on failure when min_chunk_size > pg_sz.
* Marked new mempool populate routine as EXPERIMENTAL.

V9 Changes:
* Used rte_mempool_ops_calc_mem_size() instead of default handler in the new mempool populate routine.
* Check min_chunk_size and return values.
* Removed ethdev_info memset to '0' and moved pci dev_info populate into kni_dev_pci_addr_get() routine.
* Addressed misc. review comments.

V8 Changes:
* Remove default mempool populate() routine changes.
* Add kni app specific mempool create & free routines.
* Add new mempool populate routine to allocate page-aligned memzones with page size to make sure all mempool objects reside on a page.
* Update release notes and map files.

V7 Changes:
* Removed previously proposed mempool flag and made those page boundary checks default in mempool populate() except for the objects size bigger than the size of page.
* Removed KNI example application related changes since pool related requirement is taken care in mempool lib.
* All PCI dev related info is moved under rte_eal_iova_mode() == VA check.
* Added wrapper functions in KNI module to hide IOVA checks and make address translation routines more readable.
* Updated IOVA mode checks that enforcing IOVA=PA mode when IOVA=VA mode is enabled.

V6 Changes:
* Added new mempool flag to ensure mbuf memory is not scattered across page boundaries.
* Added KNI kernel module required PCI device information.
* Modified KNI example application to create mempool with new mempool flag.

V5 changes:
* Fixed build issue with 32b build

V4 changes:
* Fixed build issues with older kernel versions
* This approach will only work with kernel above 4.4.0

V3 Changes:
* Add new approach to work kni with IOVA=VA mode using iommu_iova_to_phys API.

Kiran Kumar K (1):
kni: add IOVA=VA support in KNI module

Vamsi Attunuru (4):
mempool: populate mempool with the page sized chunks
kni: add IOVA=VA support in KNI lib
kni: add app specific mempool create and free routines
kni: modify IOVA mode checks to support VA

 doc/guides/prog_guide/kernel_nic_interface.rst    |  8 ++
 doc/guides/rel_notes/release_19_11.rst            |  5 ++
 examples/kni/main.c                               |  5 +-
 kernel/linux/kni/compat.h                         |  4 +
 kernel/linux/kni/kni_dev.h                        |  4 +
 kernel/linux/kni/kni_misc.c                       | 71 ++++++++++++++---
 kernel/linux/kni/kni_net.c                        | 59 ++++++++++----
 lib/librte_eal/linux/eal/eal.c                    |  4 +-
 lib/librte_eal/linux/eal/include/rte_kni_common.h |  8 ++
 lib/librte_kni/Makefile                           |  2 +
 lib/librte_kni/meson.build                        |  2 +
 lib/librte_kni/rte_kni.c                          | 95 +++++++++++++++++++++--
 lib/librte_kni/rte_kni.h                          | 48 ++++++++++++
 lib/librte_kni/rte_kni_version.map                |  2 +
 lib/librte_mempool/rte_mempool.c                  | 69 ++++++++++++++++
 lib/librte_mempool/rte_mempool.h                  | 20 +++++
 lib/librte_mempool/rte_mempool_version.map        |  1 +
 17 files changed, 378 insertions(+), 29 deletions(-)
Signature · 1 line
2.8.4
#167 lore raw

PATCH v10 1/5 mempool: populate mempool with the page sized chunks

From: Vamsi Attunuru <[email protected]>

Patch adds a routine to populate mempool from page aligned and page sized chunks of memory to ensure memory objs do not fall across the page boundaries. It's useful for applications that require physically contiguous mbuf memory while running in IOVA=VA mode.

---
 lib/librte_mempool/rte_mempool.c           | 69 ++++++++++++++++++++++++++++++
 lib/librte_mempool/rte_mempool.h           | 20 +++++++++
 lib/librte_mempool/rte_mempool_version.map |  1 +
 3 files changed, 90 insertions(+)
lib/librte_mempool/rte_mempool.c +69 -0
index 7260ce0..0683750 100644
@@ -414,6 +414,75 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
 	return ret;
 }
 
+/* Function to populate mempool from page sized mem chunks, allocate page size
+ * of memory in memzone and populate them. Return the number of objects added,
+ * or a negative value on error.
+ */
+int
+rte_mempool_populate_from_pg_sz_chunks(struct rte_mempool *mp)
+{
+	char mz_name[RTE_MEMZONE_NAMESIZE];
+	size_t align, pg_sz, pg_shift;
+	const struct rte_memzone *mz;
+	unsigned int mz_id, n;
+	size_t min_chunk_size;
+	int ret;
+
+	ret = mempool_ops_alloc_once(mp);
+	if (ret != 0)
+		return ret;
+
+	if (mp->nb_mem_chunks != 0)
+		return -EEXIST;
+
+	pg_sz = get_min_page_size(mp->socket_id);
+	pg_shift = rte_bsf32(pg_sz);
+
+	for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) {
+
+		ret = rte_mempool_ops_calc_mem_size(mp, n,
+				pg_shift, &min_chunk_size, &align);
+
+		if (ret < 0)
+			goto fail;
+
+		if (min_chunk_size > pg_sz) {
+			ret = -EINVAL;
+			goto fail;
+		}
+
+		ret = snprintf(mz_name, sizeof(mz_name),
+			RTE_MEMPOOL_MZ_FORMAT "_%d", mp->name, mz_id);
+		if (ret < 0 || ret >= (int)sizeof(mz_name)) {
+			ret = -ENAMETOOLONG;
+			goto fail;
+		}
+
+		mz = rte_memzone_reserve_aligned(mz_name, min_chunk_size,
+				mp->socket_id, 0, align);
+
+		if (mz == NULL) {
+			ret = -rte_errno;
+			goto fail;
+		}
+
+		ret = rte_mempool_populate_iova(mp, mz->addr,
+				mz->iova, mz->len,
+				rte_mempool_memchunk_mz_free,
+				(void *)(uintptr_t)mz);
+		if (ret < 0) {
+			rte_memzone_free(mz);
+			goto fail;
+		}
+	}
+
+	return mp->size;
+
+fail:
+	rte_mempool_free_memchunks(mp);
+	return ret;
+}
+
 /* Default function to populate the mempool: allocate memory in memzones,
  * and populate them. Return the number of objects added, or a negative
  * value on error.
lib/librte_mempool/rte_mempool.h +20 -0
index 8053f7a..2f5126e 100644
@@ -1062,6 +1062,26 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
 	void *opaque);
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Add memory from page sized memzones for objects in the pool at init
+ *
+ * This is the function used to populate the mempool with page aligned and
+ * page sized memzone memory to avoid spreading object memory across two pages
+ * and to ensure all mempool objects reside on the page memory.
+ *
+ * @param mp
+ *   A pointer to the mempool structure.
+ * @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.
+ */
+__rte_experimental
+int rte_mempool_populate_from_pg_sz_chunks(struct rte_mempool *mp);
+
+/**
  * Add memory for objects in the pool at init
  *
  * This is the default function used by rte_mempool_create() to populate
lib/librte_mempool/rte_mempool_version.map +1 -0
index 17cbca4..9a6fe65 100644
@@ -57,4 +57,5 @@ EXPERIMENTAL {
 	global:
 
 	rte_mempool_ops_get_info;
+	rte_mempool_populate_from_pg_sz_chunks;
 };
Signature · 1 line
2.8.4
Acked-by on v10 1/5
#168 lore raw

Re: [dpdk-dev] [PATCH v10 1/5] mempool: populate mempool with the page sized chunks

Quoted 10 lines · On Fri, Aug 16, 2019 at 11:42:48AM +0530, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

Patch adds a routine to populate mempool from page aligned and page sized chunks of memory to ensure memory objs do not fall across the page boundaries. It's useful for applications that require physically contiguous mbuf memory while running in IOVA=VA mode.

Do you confirm that this patch could be removed if this patchset is applied?
http://patchwork.dpdk.org/project/dpdk/list/?series=5624

I'll try to address Andrew's comments.

Thanks,
Olivier

#169 lore raw

Re: [dpdk-dev] [PATCH v10 1/5] mempool: populate mempool with the page sized chunks

Quoted 26 lines

-----Original Message-----
From: Olivier Matz <[email protected]>
Sent: Tuesday, October 8, 2019 2:57 PM
To: Vamsi Krishna Attunuru <[email protected]>
Cc: [email protected]; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v10 1/5] mempool: populate mempool with the page sized chunks

Quoted 9 lines · On Fri, Aug 16, 2019 at 11:42:48AM +0530, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

Patch adds a routine to populate mempool from page aligned and page sized chunks of memory to ensure memory objs do not fall across the page boundaries. It's useful for applications that require physically contiguous mbuf memory while running in IOVA=VA mode.

Quoted 8 lines

Do you confirm that this patch could be removed if this patchset is applied?
https://urldefense.proofpoint.com/v2/url?u=http-
3A__patchwork.dpdk.org_project_dpdk_list_-3Fseries- 3D5624&d=DwIBAg&c=nKjWec2b6R0mOyPaz7xtfQ&r=WllrYaumVkxaWjgKto6E_ rtDQshhIhik2jkvzFyRhW8&m=VNggnjZkAmMB9zBeJoncc5h26m4L1UT3wxfEzeY2 Shg&s=OVsOCqIXXvzJHMZdVqXp-7wvZdK2qYPze39QNYkf4Jo&e=

I'll try to address Andrew's comments.

Yes, this patch will be redundant and can be removed once the above patchset is applied.

Thanks
Vamsi

Quoted 3 lines

Thanks,
Olivier

#170 lore raw

PATCH v10 2/5 kni: add IOVA=VA support in KNI lib

In reply to [email protected]

From: Vamsi Attunuru <[email protected]>

Current KNI implementation only operates in IOVA=PA mode, patch adds required functionality in KNI lib to support IOVA=VA mode.

KNI kernel module requires device info to get iommu domain related information for IOVA addr related translations. Patch defines device related info in rte_kni_device_info structure and passes device info to the kernel KNI module when IOVA=VA mode is enabled.

---
 lib/librte_eal/linux/eal/include/rte_kni_common.h |  8 ++++++
 lib/librte_kni/Makefile                           |  1 +
 lib/librte_kni/meson.build                        |  1 +
 lib/librte_kni/rte_kni.c                          | 30 +++++++++++++++++++++++
 4 files changed, 40 insertions(+)
lib/librte_eal/linux/eal/include/rte_kni_common.h +8 -0
index 37d9ee8..4fd8a90 100644
@@ -111,6 +111,13 @@ struct rte_kni_device_info {
 	void * mbuf_va;
 	phys_addr_t mbuf_phys;
 
+	/* PCI info */
+	uint16_t vendor_id;           /**< Vendor ID or PCI_ANY_ID. */
+	uint16_t device_id;           /**< Device ID or PCI_ANY_ID. */
+	uint8_t bus;                  /**< Device bus */
+	uint8_t devid;                /**< Device ID */
+	uint8_t function;             /**< Device function. */
+
 	uint16_t group_id;            /**< Group ID */
 	uint32_t core_id;             /**< core ID to bind for kernel thread */
 
@@ -121,6 +128,7 @@ struct rte_kni_device_info {
 	unsigned mbuf_size;
 	unsigned int mtu;
 	uint8_t mac_addr[6];
+	uint8_t iova_mode;
 };
 
 #define KNI_DEVICE "kni"
lib/librte_kni/Makefile +1 -0
index cbd6599..ab15d10 100644
@@ -7,6 +7,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 LIB = librte_kni.a
 
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -fno-strict-aliasing
+CFLAGS += -I$(RTE_SDK)/drivers/bus/pci
 LDLIBS += -lrte_eal -lrte_mempool -lrte_mbuf -lrte_ethdev
 
 EXPORT_MAP := rte_kni_version.map
lib/librte_kni/meson.build +1 -0
index 41fa2e3..fd46f87 100644
@@ -9,3 +9,4 @@ version = 2
 sources = files('rte_kni.c')
 headers = files('rte_kni.h')
 deps += ['ethdev', 'pci']
+includes += include_directories('../../drivers/bus/pci')
lib/librte_kni/rte_kni.c +30 -0
index 4b51fb4..2aaaeaa 100644
@@ -14,6 +14,7 @@
 #include <rte_spinlock.h>
 #include <rte_string_fns.h>
 #include <rte_ethdev.h>
+#include <rte_bus_pci.h>
 #include <rte_malloc.h>
 #include <rte_log.h>
 #include <rte_kni.h>
@@ -199,6 +200,27 @@ kni_release_mz(struct rte_kni *kni)
 	rte_memzone_free(kni->m_sync_addr);
 }
 
+static void
+kni_dev_pci_addr_get(uint16_t port_id, struct rte_kni_device_info *kni_dev_info)
+{
+	const struct rte_pci_device *pci_dev;
+	struct rte_eth_dev_info dev_info;
+	const struct rte_bus *bus = NULL;
+
+	rte_eth_dev_info_get(port_id, &dev_info);
+
+	if (dev_info.device)
+		bus = rte_bus_find_by_device(dev_info.device);
+	if (bus && !strcmp(bus->name, "pci")) {
+		pci_dev = RTE_DEV_TO_PCI(dev_info.device);
+		kni_dev_info->bus = pci_dev->addr.bus;
+		kni_dev_info->devid = pci_dev->addr.devid;
+		kni_dev_info->function = pci_dev->addr.function;
+		kni_dev_info->vendor_id = pci_dev->id.vendor_id;
+		kni_dev_info->device_id = pci_dev->id.device_id;
+	}
+}
+
 struct rte_kni *
 rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 	      const struct rte_kni_conf *conf,
@@ -247,6 +269,12 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 		kni->ops.port_id = UINT16_MAX;
 
 	memset(&dev_info, 0, sizeof(dev_info));
+
+	if (rte_eal_iova_mode() == RTE_IOVA_VA) {
+		uint16_t port_id = conf->group_id;
+
+		kni_dev_pci_addr_get(port_id, &dev_info);
+	}
 	dev_info.core_id = conf->core_id;
 	dev_info.force_bind = conf->force_bind;
 	dev_info.group_id = conf->group_id;
@@ -300,6 +328,8 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 	kni->group_id = conf->group_id;
 	kni->mbuf_size = conf->mbuf_size;
 
+	dev_info.iova_mode = (rte_eal_iova_mode() == RTE_IOVA_VA) ? 1 : 0;
+
 	ret = ioctl(kni_fd, RTE_KNI_IOCTL_CREATE, &dev_info);
 	if (ret < 0)
 		goto ioctl_fail;
Signature · 1 line
2.8.4
#171 lore raw

Re: [dpdk-dev] [PATCH v10 2/5] kni: add IOVA=VA support in KNI lib

Quoted 120 lines · On 8/16/2019 7:12 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

Current KNI implementation only operates in IOVA=PA mode, patch adds required functionality in KNI lib to support IOVA=VA mode.

KNI kernel module requires device info to get iommu domain related information for IOVA addr related translations. Patch defines device related info in rte_kni_device_info structure and passes device info to the kernel KNI module when IOVA=VA mode is enabled.

---
 lib/librte_eal/linux/eal/include/rte_kni_common.h |  8 ++++++
 lib/librte_kni/Makefile                           |  1 +
 lib/librte_kni/meson.build                        |  1 +
 lib/librte_kni/rte_kni.c                          | 30 +++++++++++++++++++++++
 4 files changed, 40 insertions(+)
lib/librte_eal/linux/eal/include/rte_kni_common.h +8 -0
index 37d9ee8..4fd8a90 100644
@@ -111,6 +111,13 @@ struct rte_kni_device_info {
 	void * mbuf_va;
 	phys_addr_t mbuf_phys;
 
+	/* PCI info */
+	uint16_t vendor_id;           /**< Vendor ID or PCI_ANY_ID. */
+	uint16_t device_id;           /**< Device ID or PCI_ANY_ID. */
+	uint8_t bus;                  /**< Device bus */
+	uint8_t devid;                /**< Device ID */
+	uint8_t function;             /**< Device function. */
+
 	uint16_t group_id;            /**< Group ID */
 	uint32_t core_id;             /**< core ID to bind for kernel thread */
 
@@ -121,6 +128,7 @@ struct rte_kni_device_info {
 	unsigned mbuf_size;
 	unsigned int mtu;
 	uint8_t mac_addr[6];
+	uint8_t iova_mode;
 };
 
 #define KNI_DEVICE "kni"
lib/librte_kni/Makefile +1 -0
index cbd6599..ab15d10 100644
@@ -7,6 +7,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 LIB = librte_kni.a
 
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -fno-strict-aliasing
+CFLAGS += -I$(RTE_SDK)/drivers/bus/pci
 LDLIBS += -lrte_eal -lrte_mempool -lrte_mbuf -lrte_ethdev
 
 EXPORT_MAP := rte_kni_version.map
lib/librte_kni/meson.build +1 -0
index 41fa2e3..fd46f87 100644
@@ -9,3 +9,4 @@ version = 2
 sources = files('rte_kni.c')
 headers = files('rte_kni.h')
 deps += ['ethdev', 'pci']
+includes += include_directories('../../drivers/bus/pci')
lib/librte_kni/rte_kni.c +28 -0
index 4b51fb4..2aaaeaa 100644
@@ -14,6 +14,7 @@
 #include <rte_spinlock.h>
 #include <rte_string_fns.h>
 #include <rte_ethdev.h>
+#include <rte_bus_pci.h>
 #include <rte_malloc.h>
 #include <rte_log.h>
 #include <rte_kni.h>
@@ -199,6 +200,27 @@ kni_release_mz(struct rte_kni *kni)
 	rte_memzone_free(kni->m_sync_addr);
 }
 
+static void
+kni_dev_pci_addr_get(uint16_t port_id, struct rte_kni_device_info *kni_dev_info)
+{
+	const struct rte_pci_device *pci_dev;
+	struct rte_eth_dev_info dev_info;
+	const struct rte_bus *bus = NULL;
+
+	rte_eth_dev_info_get(port_id, &dev_info);
+
+	if (dev_info.device)
+		bus = rte_bus_find_by_device(dev_info.device);
+	if (bus && !strcmp(bus->name, "pci")) {
+		pci_dev = RTE_DEV_TO_PCI(dev_info.device);
+		kni_dev_info->bus = pci_dev->addr.bus;
+		kni_dev_info->devid = pci_dev->addr.devid;
+		kni_dev_info->function = pci_dev->addr.function;
+		kni_dev_info->vendor_id = pci_dev->id.vendor_id;
+		kni_dev_info->device_id = pci_dev->id.device_id;
+	}
+}
+
 struct rte_kni *
 rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 	      const struct rte_kni_conf *conf,
@@ -247,6 +269,12 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 		kni->ops.port_id = UINT16_MAX;
 
 	memset(&dev_info, 0, sizeof(dev_info));
+
+	if (rte_eal_iova_mode() == RTE_IOVA_VA) {
+		uint16_t port_id = conf->group_id;
+
+		kni_dev_pci_addr_get(port_id, &dev_info);
+	}
 	dev_info.core_id = conf->core_id;
 	dev_info.force_bind = conf->force_bind;
 	dev_info.group_id = conf->group_id;

lib/librte_kni/rte_kni.c rte_kni_alloc(struct rte_mempool *pktmbuf_pool, · line 332

Quoted 5 lines
lib/librte_kni/rte_kni.c +2 -0
@@ -300,6 +328,8 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 	kni->group_id = conf->group_id;
 	kni->mbuf_size = conf->mbuf_size;
 
+	dev_info.iova_mode = (rte_eal_iova_mode() == RTE_IOVA_VA) ? 1 : 0;
+

"dev_info.iova_mode = 1;" can be moved into above "RTE_IOVA_VA" check block.

Quoted 4 lines
lib/librte_kni/rte_kni.c +0 -0
 	ret = ioctl(kni_fd, RTE_KNI_IOCTL_CREATE, &dev_info);
 	if (ret < 0)
 		goto ioctl_fail;
#172 lore raw

PATCH v10 3/5 kni: add app specific mempool create and free routines

In reply to [email protected]

From: Vamsi Attunuru <[email protected]>

When KNI operates in IOVA = VA mode, it requires mbuf memory to be physically contiguous to ensure KNI kernel module could translate IOVA addresses properly. Patch adds a KNI specific mempool create routine to populate the KNI packet mbuf pool with memory objects that are being on a page.

KNI applications need to use this mempool create & free routines so that mbuf related requirements in IOVA = VA mode are handled inside those routines based on the enabled mode.

Updated the release notes with these new routine details.

---
 doc/guides/rel_notes/release_19_11.rst |  5 +++
 examples/kni/main.c                    |  5 ++-
 lib/librte_kni/Makefile                |  1 +
 lib/librte_kni/meson.build             |  1 +
 lib/librte_kni/rte_kni.c               | 60 ++++++++++++++++++++++++++++++++++
 lib/librte_kni/rte_kni.h               | 48 +++++++++++++++++++++++++++
 lib/librte_kni/rte_kni_version.map     |  2 ++
 7 files changed, 121 insertions(+), 1 deletion(-)
doc/guides/rel_notes/release_19_11.rst +5 -0
index 8490d89..8813a10 100644
@@ -85,6 +85,11 @@ API Changes
    Also, make sure to start the actual text at the margin.
    =========================================================
 
+* kni: ``rte_kni_pktmbuf_pool_create`` ``rte_kni_pktmbuf_pool_free`` functions
+  were introduced for KNI applications for creating & freeing packet pool.
+  Since IOVA=VA mode was added in KNI, packet pool's mbuf memory should be
+  physically contiguous for the KNI kernel module to work in IOVA=VA mode,
+  this requirement was taken care in the kni packet pool creation fucntions.
 
 ABI Changes
 -----------
examples/kni/main.c +4 -1
index 4710d71..fdfeed2 100644
@@ -975,7 +975,7 @@ main(int argc, char** argv)
 		rte_exit(EXIT_FAILURE, "Could not parse input parameters\n");
 
 	/* Create the mbuf pool */
-	pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF,
+	pktmbuf_pool = rte_kni_pktmbuf_pool_create("mbuf_pool", NB_MBUF,
 		MEMPOOL_CACHE_SZ, 0, MBUF_DATA_SZ, rte_socket_id());
 	if (pktmbuf_pool == NULL) {
 		rte_exit(EXIT_FAILURE, "Could not initialise mbuf pool\n");
@@ -1043,6 +1043,9 @@ main(int argc, char** argv)
 			continue;
 		kni_free_kni(port);
 	}
+
+	rte_kni_pktmbuf_pool_free(pktmbuf_pool);
+
 	for (i = 0; i < RTE_MAX_ETHPORTS; i++)
 		if (kni_port_params_array[i]) {
 			rte_free(kni_port_params_array[i]);
lib/librte_kni/Makefile +1 -0
index ab15d10..5e3dd01 100644
@@ -6,6 +6,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 # library name
 LIB = librte_kni.a
 
+CFLAGS += -DALLOW_EXPERIMENTAL_API
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -fno-strict-aliasing
 CFLAGS += -I$(RTE_SDK)/drivers/bus/pci
 LDLIBS += -lrte_eal -lrte_mempool -lrte_mbuf -lrte_ethdev
lib/librte_kni/meson.build +1 -0
index fd46f87..e357445 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
+allow_experimental_apis = true
 if not is_linux or not dpdk_conf.get('RTE_ARCH_64')
 	build = false
 	reason = 'only supported on 64-bit linux'
lib/librte_kni/rte_kni.c +60 -0

72 lines not on this page · raw message

lib/librte_kni/rte_kni.h +48 -0

54 lines not on this page · raw message

lib/librte_kni/rte_kni_version.map +2 -0
index c877dc6..aba9728 100644
@@ -20,4 +20,6 @@ EXPERIMENTAL {
 	global:
 
 	rte_kni_update_link;
+	rte_kni_pktmbuf_pool_create;
+	rte_kni_pktmbuf_pool_free;
 };
Signature · 1 line
2.8.4
#173 lore raw

Re: [dpdk-dev] [PATCH v10 3/5] kni: add app specific mempool create and free routines

Quoted 15 lines · On 8/16/2019 7:12 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

When KNI operates in IOVA = VA mode, it requires mbuf memory to be physically contiguous to ensure KNI kernel module could translate IOVA addresses properly. Patch adds a KNI specific mempool create routine to populate the KNI packet mbuf pool with memory objects that are being on a page.

KNI applications need to use this mempool create & free routines so that mbuf related requirements in IOVA = VA mode are handled inside those routines based on the enabled mode.

Updated the release notes with these new routine details.

<...>

examples/kni/main.c main(int argc, char** argv) · line 978

Quoted 6 lines
examples/kni/main.c +1 -1
@@ -975,7 +975,7 @@ main(int argc, char** argv)
 		rte_exit(EXIT_FAILURE, "Could not parse input parameters\n");
 
 	/* Create the mbuf pool */
-	pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF,
+	pktmbuf_pool = rte_kni_pktmbuf_pool_create("mbuf_pool", NB_MBUF,

This sample application is in our control but what about user applications?

If this is a must to switch to this API I think it should be at least documented in the KNI documentation.

Quoted 18 lines
examples/kni/main.c +3 -0
 		MEMPOOL_CACHE_SZ, 0, MBUF_DATA_SZ, rte_socket_id());
 	if (pktmbuf_pool == NULL) {
 		rte_exit(EXIT_FAILURE, "Could not initialise mbuf pool\n");
@@ -1043,6 +1043,9 @@ main(int argc, char** argv)
 			continue;
 		kni_free_kni(port);
 	}
+
+	rte_kni_pktmbuf_pool_free(pktmbuf_pool);
+
 	for (i = 0; i < RTE_MAX_ETHPORTS; i++)
 		if (kni_port_params_array[i]) {
 			rte_free(kni_port_params_array[i]);
lib/librte_kni/Makefile +0 -0
index ab15d10..5e3dd01 100644

lib/librte_kni/Makefile include $(RTE_SDK)/mk/rte.vars.mk · line 9

Quoted 4 lines
lib/librte_kni/Makefile +1 -0
@@ -6,6 +6,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 # library name
 LIB = librte_kni.a
 
+CFLAGS += -DALLOW_EXPERIMENTAL_API

Can you please list the experimental APIs called that requires this flag as commented, same for meson. This is to help how to know this flag later.

<...>

lib/librte_kni/Makefile EXPERIMENTAL { · line 24

Quoted 6 lines
lib/librte_kni/Makefile +2 -0
@@ -20,4 +20,6 @@ EXPERIMENTAL {
 	global:
 
 	rte_kni_update_link;
+	rte_kni_pktmbuf_pool_create;
+	rte_kni_pktmbuf_pool_free;

Can you please add comment on which DPDK version these APIs added, like done is "lib/librte_eal/rte_eal_version.map"

Quoted 2 lines
lib/librte_kni/Makefile +0 -0
 };
#174 lore raw

PATCH v10 4/5 kni: add IOVA=VA support in KNI module

In reply to [email protected]

From: Kiran Kumar K <[email protected]>

Patch adds support for kernel module to work in IOVA = VA mode, the idea is to get physical address from IOVA address using iommu_iova_to_phys API and later use phys_to_virt API to convert the physical address to kernel virtual address.

When compared with IOVA = PA mode, there is no performance drop with this approach.

This approach does not work with the kernel versions less than 4.4.0 because of API compatibility issues.

Patch also updates these support details in KNI documentation.

---
 kernel/linux/kni/compat.h   |  4 +++
 kernel/linux/kni/kni_dev.h  |  4 +++
 kernel/linux/kni/kni_misc.c | 71 +++++++++++++++++++++++++++++++++++++++------
 kernel/linux/kni/kni_net.c  | 59 ++++++++++++++++++++++++++++---------
 4 files changed, 116 insertions(+), 22 deletions(-)
kernel/linux/kni/compat.h +4 -0
index 562d8bf..ee997a6 100644
@@ -121,3 +121,7 @@
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
 #define HAVE_SIGNAL_FUNCTIONS_OWN_HEADER
 #endif
+
+#if KERNEL_VERSION(4, 4, 0) <= LINUX_VERSION_CODE
+#define HAVE_IOVA_AS_VA_SUPPORT
+#endif
kernel/linux/kni/kni_dev.h +4 -0
index c1ca678..d5898f3 100644
@@ -25,6 +25,7 @@
 #include <linux/netdevice.h>
 #include <linux/spinlock.h>
 #include <linux/list.h>
+#include <linux/iommu.h>
 
 #include <rte_kni_common.h>
 #define KNI_KTHREAD_RESCHEDULE_INTERVAL 5 /* us */
@@ -41,6 +42,9 @@ struct kni_dev {
 	/* kni list */
 	struct list_head list;
 
+	uint8_t iova_mode;
+	struct iommu_domain *domain;
+
 	uint32_t core_id;            /* Core ID to bind */
 	char name[RTE_KNI_NAMESIZE]; /* Network device name */
 	struct task_struct *pthread;
kernel/linux/kni/kni_misc.c +62 -9

83 lines not on this page · raw message

kernel/linux/kni/kni_net.c +46 -13

116 lines not on this page · raw message

Signature · 1 line
2.8.4
#175 lore raw

Re: [dpdk-dev] [PATCH v10 4/5] kni: add IOVA=VA support in KNI module

Quoted 17 lines · On 8/16/2019 7:12 AM, [email protected] wrote:

From: Kiran Kumar K <[email protected]>

Patch adds support for kernel module to work in IOVA = VA mode, the idea is to get physical address from IOVA address using iommu_iova_to_phys API and later use phys_to_virt API to convert the physical address to kernel virtual address.

When compared with IOVA = PA mode, there is no performance drop with this approach.

This approach does not work with the kernel versions less than 4.4.0 because of API compatibility issues.

Patch also updates these support details in KNI documentation.

<...>

Quoted 11 lines
kernel/linux/kni/kni_misc.c +0 -7
@@ -348,15 +351,65 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
 	strncpy(kni->name, dev_info.name, RTE_KNI_NAMESIZE);
 
 	/* Translate user space info into kernel space info */
-	kni->tx_q = phys_to_virt(dev_info.tx_phys);
-	kni->rx_q = phys_to_virt(dev_info.rx_phys);
-	kni->alloc_q = phys_to_virt(dev_info.alloc_phys);
-	kni->free_q = phys_to_virt(dev_info.free_phys);
-
-	kni->req_q = phys_to_virt(dev_info.req_phys);
-	kni->resp_q = phys_to_virt(dev_info.resp_phys);

kernel/linux/kni/kni_misc.c kni_ioctl_create(struct net *net, uint32_t ioctl_num, · line 361

Quoted 10 lines
kernel/linux/kni/kni_misc.c +8 -2
-	kni->sync_va = dev_info.sync_va;
-	kni->sync_kva = phys_to_virt(dev_info.sync_phys);
+	if (dev_info.iova_mode) {
+#ifdef HAVE_IOVA_AS_VA_SUPPORT
+		pci = pci_get_device(dev_info.vendor_id,
+				     dev_info.device_id, NULL);
+		if (pci == NULL) {
+			pr_err("pci dev does not exist\n");
+			return -ENODEV;
+		}

If there is no PCI device KNI should still work.

#176 lore raw

Re: [dpdk-dev] [PATCH v10 4/5] kni: add IOVA=VA support in KNI module

Quoted 36 lines · Ferruh
Quoted 17 lines · On 8/16/2019 7:12 AM, [email protected] wrote:

From: Kiran Kumar K <[email protected]>

Patch adds support for kernel module to work in IOVA = VA mode, the idea is to get physical address from IOVA address using iommu_iova_to_phys API and later use phys_to_virt API to convert the physical address to kernel virtual address.

When compared with IOVA = PA mode, there is no performance drop with this approach.

This approach does not work with the kernel versions less than 4.4.0 because of API compatibility issues.

Patch also updates these support details in KNI documentation.

<...>

Quoted 15 lines
kernel/linux/kni/kni_misc.c +2 -9
@@ -348,15 +351,65 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
 	strncpy(kni->name, dev_info.name, RTE_KNI_NAMESIZE);
 
 	/* Translate user space info into kernel space info */
-	kni->tx_q = phys_to_virt(dev_info.tx_phys);
-	kni->rx_q = phys_to_virt(dev_info.rx_phys);
-	kni->alloc_q = phys_to_virt(dev_info.alloc_phys);
-	kni->free_q = phys_to_virt(dev_info.free_phys);
-
-	kni->req_q = phys_to_virt(dev_info.req_phys);
-	kni->resp_q = phys_to_virt(dev_info.resp_phys);
-	kni->sync_va = dev_info.sync_va;
-	kni->sync_kva = phys_to_virt(dev_info.sync_phys);
+	if (dev_info.iova_mode) {
+#ifdef HAVE_IOVA_AS_VA_SUPPORT
Quoted 8 lines

kernel/linux/kni/kni_misc.c kni_ioctl_create(struct net *net, uint32_t ioctl_num, · line 361

Quoted 6 lines
kernel/linux/kni/kni_misc.c +6 -0
+		pci = pci_get_device(dev_info.vendor_id,
+				     dev_info.device_id, NULL);
+		if (pci == NULL) {
+			pr_err("pci dev does not exist\n");
+			return -ENODEV;
+		}  

If there is no PCI device KNI should still work.

Right now it is possible to use KNI with netvsc PMD on Hyper-V/Azure. With this patch that won't be possible.

#177 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v10 4/5] kni: add IOVA=VA support in KNI module

Quoted 66 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Tuesday, October 15, 2019 9:16 PM
To: Yigit, Ferruh <[email protected]>
Cc: Vamsi Krishna Attunuru <[email protected]>; [email protected]; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: [EXT] Re: [dpdk-dev] [PATCH v10 4/5] kni: add IOVA=VA support in KNI module

External Email

----------------------------------------------------------------------

Quoted 14 lines · Ferruh
Quoted 13 lines · On 8/16/2019 7:12 AM, [email protected] wrote:

From: Kiran Kumar K <[email protected]>

Patch adds support for kernel module to work in IOVA = VA mode, the idea is to get physical address from IOVA address using iommu_iova_to_phys API and later use phys_to_virt API to convert the physical address to kernel virtual address.

When compared with IOVA = PA mode, there is no performance drop with this approach.

This approach does not work with the kernel versions less than 4.4.0 because of API compatibility issues.

Quoted 8 lines
Quoted 4 lines

Patch also updates these support details in KNI documentation.

<...>

Review kni_ioctl_create(struct net *net, uint32_t

Quoted 1 line
(quoted diff) +0 -0
@@ -348,15 +351,65 @@ kni_ioctl_create(struct net *net, uint32_t

ioctl_num,

Quoted 14 lines
Quoted 14 lines
kernel/linux/kni/kni_misc.c +2 -9
 	strncpy(kni->name, dev_info.name, RTE_KNI_NAMESIZE);
 
 	/* Translate user space info into kernel space info */
-	kni->tx_q = phys_to_virt(dev_info.tx_phys);
-	kni->rx_q = phys_to_virt(dev_info.rx_phys);
-	kni->alloc_q = phys_to_virt(dev_info.alloc_phys);
-	kni->free_q = phys_to_virt(dev_info.free_phys);
-
-	kni->req_q = phys_to_virt(dev_info.req_phys);
-	kni->resp_q = phys_to_virt(dev_info.resp_phys);
-	kni->sync_va = dev_info.sync_va;
-	kni->sync_kva = phys_to_virt(dev_info.sync_phys);
+	if (dev_info.iova_mode) {
+#ifdef HAVE_IOVA_AS_VA_SUPPORT
Quoted 8 lines

kernel/linux/kni/kni_misc.c kni_ioctl_create(struct net *net, uint32_t ioctl_num, · line 361

Quoted 6 lines
kernel/linux/kni/kni_misc.c +6 -0
+		pci = pci_get_device(dev_info.vendor_id,
+				     dev_info.device_id, NULL);
+		if (pci == NULL) {
+			pr_err("pci dev does not exist\n");
+			return -ENODEV;
+		}

If there is no PCI device KNI should still work.

Quoted 2 lines

Right now it is possible to use KNI with netvsc PMD on Hyper-V/Azure. With this patch that won't be possible.

Hi Ferruh, Stephen,

These can be fixed by forcing iommu_mode as PA when vdevs are used for KNI usecase.

rte_bus_get_iommu_class(void)

 {
        enum rte_iova_mode mode = RTE_IOVA_DC;
+       struct rte_devargs *devargs = NULL;
        bool buses_want_va = false;
        bool buses_want_pa = false;
        struct rte_bus *bus;

+ if (rte_eal_check_module("rte_kni") == 1) {
+ RTE_EAL_DEVARGS_FOREACH("vdev", devargs) {
+ return RTE_IOVA_PA;
+ }
+ }
+

        TAILQ_FOREACH(bus, &rte_bus_list, next) {
                enum rte_iova_mode bus_iova_mode;

I think this will solve various use cases/combinations like PA or VA mode, pdev or vdev used for KNI. Existing use cases would not be affected by these patch series with above fix.

#178 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v10 4/5] kni: add IOVA=VA support in KNI module

Quoted 105 lines

-----Original Message-----
From: Vamsi Krishna Attunuru
Sent: Wednesday, October 16, 2019 4:56 PM
To: Stephen Hemminger <[email protected]>; Yigit, Ferruh <[email protected]>
Cc: [email protected]; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: RE: [EXT] Re: [dpdk-dev] [PATCH v10 4/5] kni: add IOVA=VA support in KNI module

Quoted 64 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Tuesday, October 15, 2019 9:16 PM
To: Yigit, Ferruh <[email protected]>
Cc: Vamsi Krishna Attunuru <[email protected]>; [email protected]; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: [EXT] Re: [dpdk-dev] [PATCH v10 4/5] kni: add IOVA=VA support in KNI module

External Email

----------------------------------------------------------------------

Quoted 14 lines · Ferruh
Quoted 13 lines · On 8/16/2019 7:12 AM, [email protected] wrote:

From: Kiran Kumar K <[email protected]>

Patch adds support for kernel module to work in IOVA = VA mode, the idea is to get physical address from IOVA address using iommu_iova_to_phys API and later use phys_to_virt API to convert the physical address to kernel virtual address.

When compared with IOVA = PA mode, there is no performance drop with this approach.

This approach does not work with the kernel versions less than 4.4.0 because of API compatibility issues.

Quoted 8 lines
Quoted 4 lines

Patch also updates these support details in KNI documentation.

<...>

Review kni_ioctl_create(struct net *net, uint32_t

Quoted 1 line
(quoted diff) +0 -0
@@ -348,15 +351,65 @@ kni_ioctl_create(struct net *net, uint32_t

ioctl_num,

Quoted 14 lines
Quoted 14 lines
kernel/linux/kni/kni_misc.c +2 -9
 	strncpy(kni->name, dev_info.name, RTE_KNI_NAMESIZE);
 
 	/* Translate user space info into kernel space info */
-	kni->tx_q = phys_to_virt(dev_info.tx_phys);
-	kni->rx_q = phys_to_virt(dev_info.rx_phys);
-	kni->alloc_q = phys_to_virt(dev_info.alloc_phys);
-	kni->free_q = phys_to_virt(dev_info.free_phys);
-
-	kni->req_q = phys_to_virt(dev_info.req_phys);
-	kni->resp_q = phys_to_virt(dev_info.resp_phys);
-	kni->sync_va = dev_info.sync_va;
-	kni->sync_kva = phys_to_virt(dev_info.sync_phys);
+	if (dev_info.iova_mode) {
+#ifdef HAVE_IOVA_AS_VA_SUPPORT
Quoted 8 lines

kernel/linux/kni/kni_misc.c kni_ioctl_create(struct net *net, uint32_t ioctl_num, · line 361

Quoted 6 lines
kernel/linux/kni/kni_misc.c +6 -0
+		pci = pci_get_device(dev_info.vendor_id,
+				     dev_info.device_id, NULL);
+		if (pci == NULL) {
+			pr_err("pci dev does not exist\n");
+			return -ENODEV;
+		}

If there is no PCI device KNI should still work.

Quoted 2 lines

Right now it is possible to use KNI with netvsc PMD on Hyper-V/Azure. With this patch that won't be possible.

Hi Ferruh, Stephen,

These can be fixed by forcing iommu_mode as PA when vdevs are used for KNI usecase.

rte_bus_get_iommu_class(void)

 {
        enum rte_iova_mode mode = RTE_IOVA_DC;
(quoted diff) +7 -0
+       struct rte_devargs *devargs = NULL;
        bool buses_want_va = false;
        bool buses_want_pa = false;
        struct rte_bus *bus;
 
+       if (rte_eal_check_module("rte_kni") == 1) {
+               RTE_EAL_DEVARGS_FOREACH("vdev", devargs) {
+                       return RTE_IOVA_PA;
+               }
+       }
+
        TAILQ_FOREACH(bus, &rte_bus_list, next) {
                enum rte_iova_mode bus_iova_mode;
Quoted 3 lines

I think this will solve various use cases/combinations like PA or VA mode, pdev or vdev used for KNI.
Existing use cases would not be affected by these patch series with above fix.

Hi Ferruh, Stephen,

Pushed a patch for above mentioned fix. Fix is moved to vdev bus driver. Patch adds get_iommu_class callback in vdev bus driver and returns iova=pa for kni usecase.
http://patches.dpdk.org/patch/61312/

#179 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v10 4/5] kni: add IOVA=VA support in KNI module

In reply to Vamsi Krishna Attunuru
Quoted 91 lines · Vamsi Krishna Attunuru
Quoted 66 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Tuesday, October 15, 2019 9:16 PM
To: Yigit, Ferruh <[email protected]>
Cc: Vamsi Krishna Attunuru <[email protected]>; [email protected]; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: [EXT] Re: [dpdk-dev] [PATCH v10 4/5] kni: add IOVA=VA support in KNI module

External Email

----------------------------------------------------------------------

Quoted 14 lines · Ferruh
Quoted 13 lines · On 8/16/2019 7:12 AM, [email protected] wrote:

From: Kiran Kumar K <[email protected]>

Patch adds support for kernel module to work in IOVA = VA mode, the idea is to get physical address from IOVA address using iommu_iova_to_phys API and later use phys_to_virt API to convert the physical address to kernel virtual address.

When compared with IOVA = PA mode, there is no performance drop with this approach.

This approach does not work with the kernel versions less than 4.4.0 because of API compatibility issues.

Quoted 8 lines
Quoted 4 lines

Patch also updates these support details in KNI documentation.

<...>

Review kni_ioctl_create(struct net *net, uint32_t

Quoted 1 line
(quoted diff) +0 -0
@@ -348,15 +351,65 @@ kni_ioctl_create(struct net *net, uint32_t

ioctl_num,

Quoted 14 lines
Quoted 14 lines
kernel/linux/kni/kni_misc.c +2 -9
 	strncpy(kni->name, dev_info.name, RTE_KNI_NAMESIZE);
 
 	/* Translate user space info into kernel space info */
-	kni->tx_q = phys_to_virt(dev_info.tx_phys);
-	kni->rx_q = phys_to_virt(dev_info.rx_phys);
-	kni->alloc_q = phys_to_virt(dev_info.alloc_phys);
-	kni->free_q = phys_to_virt(dev_info.free_phys);
-
-	kni->req_q = phys_to_virt(dev_info.req_phys);
-	kni->resp_q = phys_to_virt(dev_info.resp_phys);
-	kni->sync_va = dev_info.sync_va;
-	kni->sync_kva = phys_to_virt(dev_info.sync_phys);
+	if (dev_info.iova_mode) {
+#ifdef HAVE_IOVA_AS_VA_SUPPORT
Quoted 8 lines

kernel/linux/kni/kni_misc.c kni_ioctl_create(struct net *net, uint32_t ioctl_num, · line 361

Quoted 6 lines
kernel/linux/kni/kni_misc.c +6 -0
+		pci = pci_get_device(dev_info.vendor_id,
+				     dev_info.device_id, NULL);
+		if (pci == NULL) {
+			pr_err("pci dev does not exist\n");
+			return -ENODEV;
+		}

If there is no PCI device KNI should still work.

Quoted 2 lines

Right now it is possible to use KNI with netvsc PMD on Hyper-V/Azure. With this patch that won't be possible.

Hi Ferruh, Stephen,

These can be fixed by forcing iommu_mode as PA when vdevs are used for KNI usecase.

rte_bus_get_iommu_class(void)

 {
        enum rte_iova_mode mode = RTE_IOVA_DC;
(quoted diff) +7 -0
+       struct rte_devargs *devargs = NULL;
        bool buses_want_va = false;
        bool buses_want_pa = false;
        struct rte_bus *bus;
 
+       if (rte_eal_check_module("rte_kni") == 1) {
+               RTE_EAL_DEVARGS_FOREACH("vdev", devargs) {
+                       return RTE_IOVA_PA;
+               }
+       }
+
        TAILQ_FOREACH(bus, &rte_bus_list, next) {
                enum rte_iova_mode bus_iova_mode;
Quoted 3 lines

I think this will solve various use cases/combinations like PA or VA mode, pdev or vdev used for KNI. Existing use cases would not be affected by these patch series with above fix.

Hi Vamsi,

I think this is not a problem of using vdev so I think we can't solve this via vdev check only.

The sample I give (KNI PMD) is using vdev, but application can use KNI library APIs directly to create kni interface and have kernel/user space communication without any device involved. KNI PMD (vdev) is just a wrapper to make this easy.

Just thinking aloud,
KNI is sharing in userspace buffer with kernel, so basically it needs to do virtual address to kernel virtual address translation, in a reasonably fast manner.

iova=va breaks KNI because:
1) physical memory is not continuous anymore which break our address translation logic
2) we were using physical address of the buffer for the address translation, but we have no more have it, we now have iova address.

I assume 1) is resolved with 'rte_kni_pktmbuf_pool_create()' it would be helpful though if you can explain how this works?

For second, a simple question, do we need to get a PCIe device information to be able to convert iova to kernel virtual address? Can't I get this information from iommu somehow?
Think about a case "--iova-mode=va" provided but there is no physical device bind to vfio-pci, can I still allocated memor? And how can I use KNI in that case?

#180 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v10 4/5] kni: add IOVA=VA support in KNI module

Quoted 129 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Ferruh Yigit
Sent: Wednesday, October 16, 2019 9:44 PM
To: Vamsi Krishna Attunuru <[email protected]>; Stephen Hemminger <[email protected]>; Yigit, Ferruh <[email protected]>
Cc: [email protected]; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: Re: [dpdk-dev] [EXT] Re: [PATCH v10 4/5] kni: add IOVA=VA support in KNI module

Quoted 92 lines · Vamsi Krishna Attunuru
Quoted 67 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Tuesday, October 15, 2019 9:16 PM
To: Yigit, Ferruh <[email protected]>
Cc: Vamsi Krishna Attunuru <[email protected]>; [email protected]; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: [EXT] Re: [dpdk-dev] [PATCH v10 4/5] kni: add IOVA=VA support in KNI module

External Email

---------------------------------------------------------------------
-

Quoted 14 lines · Ferruh
Quoted 13 lines · On 8/16/2019 7:12 AM, [email protected] wrote:

From: Kiran Kumar K <[email protected]>

Patch adds support for kernel module to work in IOVA = VA mode, the idea is to get physical address from IOVA address using iommu_iova_to_phys API and later use phys_to_virt API to convert the physical address to kernel virtual address.

When compared with IOVA = PA mode, there is no performance drop with this approach.

This approach does not work with the kernel versions less than 4.4.0 because of API compatibility issues.

Quoted 8 lines
Quoted 4 lines

Patch also updates these support details in KNI documentation.

<...>

Review kni_ioctl_create(struct net *net, uint32_t

Quoted 1 line
(quoted diff) +0 -0
@@ -348,15 +351,65 @@ kni_ioctl_create(struct net *net, uint32_t

ioctl_num,

Quoted 14 lines
Quoted 14 lines
kernel/linux/kni/kni_misc.c +2 -9
 	strncpy(kni->name, dev_info.name, RTE_KNI_NAMESIZE);
 
 	/* Translate user space info into kernel space info */
-	kni->tx_q = phys_to_virt(dev_info.tx_phys);
-	kni->rx_q = phys_to_virt(dev_info.rx_phys);
-	kni->alloc_q = phys_to_virt(dev_info.alloc_phys);
-	kni->free_q = phys_to_virt(dev_info.free_phys);
-
-	kni->req_q = phys_to_virt(dev_info.req_phys);
-	kni->resp_q = phys_to_virt(dev_info.resp_phys);
-	kni->sync_va = dev_info.sync_va;
-	kni->sync_kva = phys_to_virt(dev_info.sync_phys);
+	if (dev_info.iova_mode) {
+#ifdef HAVE_IOVA_AS_VA_SUPPORT
Quoted 8 lines

kernel/linux/kni/kni_misc.c kni_ioctl_create(struct net *net, uint32_t ioctl_num, · line 361

Quoted 6 lines
kernel/linux/kni/kni_misc.c +6 -0
+		pci = pci_get_device(dev_info.vendor_id,
+				     dev_info.device_id, NULL);
+		if (pci == NULL) {
+			pr_err("pci dev does not exist\n");
+			return -ENODEV;
+		}

If there is no PCI device KNI should still work.

Quoted 2 lines

Right now it is possible to use KNI with netvsc PMD on Hyper-V/Azure. With this patch that won't be possible.

Hi Ferruh, Stephen,

These can be fixed by forcing iommu_mode as PA when vdevs are used for KNI usecase.

rte_bus_get_iommu_class(void)

 {
        enum rte_iova_mode mode = RTE_IOVA_DC;
(quoted diff) +7 -0
+       struct rte_devargs *devargs = NULL;
        bool buses_want_va = false;
        bool buses_want_pa = false;
        struct rte_bus *bus;
 
+       if (rte_eal_check_module("rte_kni") == 1) {
+               RTE_EAL_DEVARGS_FOREACH("vdev", devargs) {
+                       return RTE_IOVA_PA;
+               }
+       }
+
        TAILQ_FOREACH(bus, &rte_bus_list, next) {
                enum rte_iova_mode bus_iova_mode;
Quoted 1 line

I think this will solve various use cases/combinations like PA or VA mode,

pdev or vdev used for KNI.

Quoted 1 line

Existing use cases would not be affected by these patch series with above

fix.

Quoted 1 line

Hi Vamsi,

I think this is not a problem of using vdev so I think we can't solve this via vdev check only.

The sample I give (KNI PMD) is using vdev, but application can use KNI library APIs directly to create kni interface and have kernel/user space communication without any device involved. KNI PMD (vdev) is just a wrapper to make this easy.

Just thinking aloud,
KNI is sharing in userspace buffer with kernel, so basically it needs to do virtual address to kernel virtual address translation, in a reasonably fast manner.

Quoted 8 lines

iova=va breaks KNI because:
1) physical memory is not continuous anymore which break our address translation logic
2) we were using physical address of the buffer for the address translation, but we have no more have it, we now have iova address.

I assume 1) is resolved with 'rte_kni_pktmbuf_pool_create()' it would be helpful though if you can explain how this works?

KNI kernel module uses pa2va, va2pa calls to translate buffer pointers, this will only work when both pa & va are 1-to-1 contiguous. In such cases, dpdk mbuf memory should not cross physical page boundary, If it crosses, it's iova/va will be contiguous, but it's pa may or may not be contiguous. Kni pktmbuf pool api ensures that mempool is not populated with those type of mbufs(that cross page boundary). Once the pool is created, all mbufs in that pool resides with in the page limits.

Quoted 7 lines

For second, a simple question, do we need to get a PCIe device information to be able to convert iova to kernel virtual address? Can't I get this information from iommu somehow?
Think about a case "--iova-mode=va" provided but there is no physical device bind to vfio-pci, can I still allocated memor? And how can I use KNI in that case?

We found a way to translate iova/uva to kva using kernel mm subsystem calls, using get_user_pages_remote() call KNI module is able to get mapping for iova to kva. This solution worked for pdevs(without sharing any dev info) and also for wrapper vdev pmds.

I will push next version of patches with these solution and other command line arg changes. Since the major architectural issue is fixed in enabling iova=va for KNI, we are planning to merge these patch series in 19.11 release.

#181 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v10 4/5] kni: add IOVA=VA support in KNI module

Quoted 135 lines · Vamsi Krishna Attunuru
Quoted 135 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Ferruh Yigit
Sent: Wednesday, October 16, 2019 9:44 PM
To: Vamsi Krishna Attunuru <[email protected]>; Stephen Hemminger <[email protected]>; Yigit, Ferruh <[email protected]>
Cc: [email protected]; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: Re: [dpdk-dev] [EXT] Re: [PATCH v10 4/5] kni: add IOVA=VA support in KNI module

Quoted 92 lines · Vamsi Krishna Attunuru
Quoted 67 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Tuesday, October 15, 2019 9:16 PM
To: Yigit, Ferruh <[email protected]>
Cc: Vamsi Krishna Attunuru <[email protected]>; [email protected]; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: [EXT] Re: [dpdk-dev] [PATCH v10 4/5] kni: add IOVA=VA support in KNI module

External Email

---------------------------------------------------------------------
-

Quoted 14 lines · Ferruh
Quoted 13 lines · On 8/16/2019 7:12 AM, [email protected] wrote:

From: Kiran Kumar K <[email protected]>

Patch adds support for kernel module to work in IOVA = VA mode, the idea is to get physical address from IOVA address using iommu_iova_to_phys API and later use phys_to_virt API to convert the physical address to kernel virtual address.

When compared with IOVA = PA mode, there is no performance drop with this approach.

This approach does not work with the kernel versions less than 4.4.0 because of API compatibility issues.

Quoted 8 lines
Quoted 4 lines

Patch also updates these support details in KNI documentation.

<...>

Review kni_ioctl_create(struct net *net, uint32_t

Quoted 1 line
(quoted diff) +0 -0
@@ -348,15 +351,65 @@ kni_ioctl_create(struct net *net, uint32_t

ioctl_num,

Quoted 14 lines
Quoted 14 lines
kernel/linux/kni/kni_misc.c +2 -9
 	strncpy(kni->name, dev_info.name, RTE_KNI_NAMESIZE);
 
 	/* Translate user space info into kernel space info */
-	kni->tx_q = phys_to_virt(dev_info.tx_phys);
-	kni->rx_q = phys_to_virt(dev_info.rx_phys);
-	kni->alloc_q = phys_to_virt(dev_info.alloc_phys);
-	kni->free_q = phys_to_virt(dev_info.free_phys);
-
-	kni->req_q = phys_to_virt(dev_info.req_phys);
-	kni->resp_q = phys_to_virt(dev_info.resp_phys);
-	kni->sync_va = dev_info.sync_va;
-	kni->sync_kva = phys_to_virt(dev_info.sync_phys);
+	if (dev_info.iova_mode) {
+#ifdef HAVE_IOVA_AS_VA_SUPPORT
Quoted 8 lines

kernel/linux/kni/kni_misc.c kni_ioctl_create(struct net *net, uint32_t ioctl_num, · line 361

Quoted 6 lines
kernel/linux/kni/kni_misc.c +6 -0
+		pci = pci_get_device(dev_info.vendor_id,
+				     dev_info.device_id, NULL);
+		if (pci == NULL) {
+			pr_err("pci dev does not exist\n");
+			return -ENODEV;
+		}

If there is no PCI device KNI should still work.

Quoted 2 lines

Right now it is possible to use KNI with netvsc PMD on Hyper-V/Azure. With this patch that won't be possible.

Hi Ferruh, Stephen,

These can be fixed by forcing iommu_mode as PA when vdevs are used for KNI usecase.

rte_bus_get_iommu_class(void)

 {
        enum rte_iova_mode mode = RTE_IOVA_DC;
(quoted diff) +7 -0
+       struct rte_devargs *devargs = NULL;
        bool buses_want_va = false;
        bool buses_want_pa = false;
        struct rte_bus *bus;
 
+       if (rte_eal_check_module("rte_kni") == 1) {
+               RTE_EAL_DEVARGS_FOREACH("vdev", devargs) {
+                       return RTE_IOVA_PA;
+               }
+       }
+
        TAILQ_FOREACH(bus, &rte_bus_list, next) {
                enum rte_iova_mode bus_iova_mode;
Quoted 1 line

I think this will solve various use cases/combinations like PA or VA mode,

pdev or vdev used for KNI.

Quoted 1 line

Existing use cases would not be affected by these patch series with above

fix.

Quoted 1 line

Hi Vamsi,

I think this is not a problem of using vdev so I think we can't solve this via vdev check only.

The sample I give (KNI PMD) is using vdev, but application can use KNI library APIs directly to create kni interface and have kernel/user space communication without any device involved. KNI PMD (vdev) is just a wrapper to make this easy.

Just thinking aloud,
KNI is sharing in userspace buffer with kernel, so basically it needs to do virtual address to kernel virtual address translation, in a reasonably fast manner.

iova=va breaks KNI because:
1) physical memory is not continuous anymore which break our address translation logic
2) we were using physical address of the buffer for the address translation, but we have no more have it, we now have iova address.

Quoted 4 lines
Quoted 2 lines

I assume 1) is resolved with 'rte_kni_pktmbuf_pool_create()' it would be helpful though if you can explain how this works?

KNI kernel module uses pa2va, va2pa calls to translate buffer pointers, this will only work when both pa & va are 1-to-1 contiguous. In such cases, dpdk mbuf memory should not cross physical page boundary, If it crosses, it's iova/va will be contiguous, but it's pa may or may not be contiguous. Kni pktmbuf pool api ensures that mempool is not populated with those type of mbufs(that cross page boundary). Once the pool is created, all mbufs in that pool resides with in the page limits.

ack.

Quoted 9 lines
Quoted 7 lines

For second, a simple question, do we need to get a PCIe device information to be able to convert iova to kernel virtual address? Can't I get this information from iommu somehow?
Think about a case "--iova-mode=va" provided but there is no physical device bind to vfio-pci, can I still allocated memor? And how can I use KNI in that case?

We found a way to translate iova/uva to kva using kernel mm subsystem calls, using get_user_pages_remote() call KNI module is able to get mapping for iova to kva. This solution worked for pdevs(without sharing any dev info) and also for wrapper vdev pmds.

Good to hear this.

Quoted 3 lines

I will push next version of patches with these solution and other command line arg changes. Since the major architectural issue is fixed in enabling iova=va for KNI, we are planning to merge these patch series in 19.11 release.

#182 lore raw

PATCH v10 5/5 kni: modify IOVA mode checks to support VA

In reply to [email protected]

From: Vamsi Attunuru <[email protected]>

Patch addresses checks in KNI and eal that enforce IOVA=PA when IOVA=VA mode is enabled, since KNI kernel module supports VA mode for kernel versions >= 4.4.0.

Updated KNI documentation with above details.

---
 doc/guides/prog_guide/kernel_nic_interface.rst | 8 ++++++++
 lib/librte_eal/linux/eal/eal.c                 | 4 +++-
 lib/librte_kni/rte_kni.c                       | 5 -----
 3 files changed, 11 insertions(+), 6 deletions(-)
doc/guides/prog_guide/kernel_nic_interface.rst +8 -0
index 38369b3..fd2ce63 100644
@@ -291,6 +291,14 @@ The sk_buff is then freed and the mbuf sent in the tx_q FIFO.
 The DPDK TX thread dequeues the mbuf and sends it to the PMD via ``rte_eth_tx_burst()``.
 It then puts the mbuf back in the cache.
 
+IOVA = VA: Support
+------------------
+
+KNI can be operated in IOVA as VA scheme when following criteria are fullfilled
+
+- LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)
+- eal param `--iova-mode va` is passed or bus IOVA scheme is set to RTE_IOVA_VA
+
 Ethtool
 -------
 
lib/librte_eal/linux/eal/eal.c +3 -1
index 946222c..73d64c8 100644
@@ -1114,12 +1114,14 @@ rte_eal_init(int argc, char **argv)
 		/* Workaround for KNI which requires physical address to work */
 		if (iova_mode == RTE_IOVA_VA &&
 				rte_eal_check_module("rte_kni") == 1) {
+#if KERNEL_VERSION(4, 4, 0) > LINUX_VERSION_CODE
 			if (phys_addrs) {
 				iova_mode = RTE_IOVA_PA;
-				RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI module is loaded\n");
+				RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI module does not support VA\n");
 			} else {
 				RTE_LOG(DEBUG, EAL, "KNI can not work since physical addresses are unavailable\n");
 			}
+#endif
 		}
 #endif
 		rte_eal_get_configuration()->iova_mode = iova_mode;
lib/librte_kni/rte_kni.c +0 -5
index 15dda45..c77d76f 100644
@@ -99,11 +99,6 @@ static volatile int kni_fd = -1;
 int
 rte_kni_init(unsigned int max_kni_ifaces __rte_unused)
 {
-	if (rte_eal_iova_mode() != RTE_IOVA_PA) {
-		RTE_LOG(ERR, KNI, "KNI requires IOVA as PA\n");
-		return -1;
-	}
-
 	/* Check FD and open */
 	if (kni_fd < 0) {
 		kni_fd = open("/dev/" KNI_DEVICE, O_RDWR);
Signature · 1 line
2.8.4
#183 lore raw

Re: [dpdk-dev] [PATCH v10 0/5] kni: add IOVA=VA support

In reply to [email protected]

PING.

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Friday, August 16, 2019 11:43 AM
To: [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>; Vamsi Krishna Attunuru <[email protected]>
Subject: [dpdk-dev] [PATCH v10 0/5] kni: add IOVA=VA support

From: Vamsi Attunuru <[email protected]>

---
V10 Changes:
* Fixed function return code on failure when min_chunk_size > pg_sz.
* Marked new mempool populate routine as EXPERIMENTAL.

V9 Changes:
* Used rte_mempool_ops_calc_mem_size() instead of default handler in the new mempool populate routine.
* Check min_chunk_size and return values.
* Removed ethdev_info memset to '0' and moved pci dev_info populate into kni_dev_pci_addr_get() routine.
* Addressed misc. review comments.

V8 Changes:
* Remove default mempool populate() routine changes.
* Add kni app specific mempool create & free routines.
* Add new mempool populate routine to allocate page-aligned memzones with page size to make sure all mempool objects reside on a page.
* Update release notes and map files.

V7 Changes:
* Removed previously proposed mempool flag and made those page boundary checks default in mempool populate() except for the objects size bigger than the size of page.
* Removed KNI example application related changes since pool related requirement is taken care in mempool lib.
* All PCI dev related info is moved under rte_eal_iova_mode() == VA check.
* Added wrapper functions in KNI module to hide IOVA checks and make address translation routines more readable.
* Updated IOVA mode checks that enforcing IOVA=PA mode when IOVA=VA mode is enabled.

V6 Changes:
* Added new mempool flag to ensure mbuf memory is not scattered across page boundaries.
* Added KNI kernel module required PCI device information.
* Modified KNI example application to create mempool with new mempool flag.

V5 changes:
* Fixed build issue with 32b build

V4 changes:
* Fixed build issues with older kernel versions
* This approach will only work with kernel above 4.4.0

V3 Changes:
* Add new approach to work kni with IOVA=VA mode using iommu_iova_to_phys API.

Kiran Kumar K (1):
kni: add IOVA=VA support in KNI module

Vamsi Attunuru (4):
mempool: populate mempool with the page sized chunks
kni: add IOVA=VA support in KNI lib
kni: add app specific mempool create and free routines
kni: modify IOVA mode checks to support VA

 doc/guides/prog_guide/kernel_nic_interface.rst    |  8 ++
 doc/guides/rel_notes/release_19_11.rst            |  5 ++
 examples/kni/main.c                               |  5 +-
 kernel/linux/kni/compat.h                         |  4 +
 kernel/linux/kni/kni_dev.h                        |  4 +
 kernel/linux/kni/kni_misc.c                       | 71 ++++++++++++++---
 kernel/linux/kni/kni_net.c                        | 59 ++++++++++----
 lib/librte_eal/linux/eal/eal.c                    |  4 +-
 lib/librte_eal/linux/eal/include/rte_kni_common.h |  8 ++
 lib/librte_kni/Makefile                           |  2 +
 lib/librte_kni/meson.build                        |  2 +
 lib/librte_kni/rte_kni.c                          | 95 +++++++++++++++++++++--
 lib/librte_kni/rte_kni.h                          | 48 ++++++++++++
 lib/librte_kni/rte_kni_version.map                |  2 +
 lib/librte_mempool/rte_mempool.c                  | 69 ++++++++++++++++
 lib/librte_mempool/rte_mempool.h                  | 20 +++++
 lib/librte_mempool/rte_mempool_version.map        |  1 +
 17 files changed, 378 insertions(+), 29 deletions(-)

--
2.8.4

#184 lore raw

Re: [dpdk-dev] [PATCH v10 0/5] kni: add IOVA=VA support

@All, we are expecting to merge this in 19.11 release and if any one have comments please respond.

Quoted 105 lines

-----Original Message-----
From: Vamsi Krishna Attunuru
Sent: Wednesday, September 25, 2019 9:30 AM
To: [email protected]; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: RE: [dpdk-dev] [PATCH v10 0/5] kni: add IOVA=VA support

PING.

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Friday, August 16, 2019 11:43 AM
To: [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>; Vamsi Krishna Attunuru <[email protected]>
Subject: [dpdk-dev] [PATCH v10 0/5] kni: add IOVA=VA support

From: Vamsi Attunuru <[email protected]>

---
V10 Changes:
* Fixed function return code on failure when min_chunk_size > pg_sz.
* Marked new mempool populate routine as EXPERIMENTAL.

V9 Changes:
* Used rte_mempool_ops_calc_mem_size() instead of default handler in the new mempool populate routine.
* Check min_chunk_size and return values.
* Removed ethdev_info memset to '0' and moved pci dev_info populate into kni_dev_pci_addr_get() routine.
* Addressed misc. review comments.

V8 Changes:
* Remove default mempool populate() routine changes.
* Add kni app specific mempool create & free routines.
* Add new mempool populate routine to allocate page-aligned memzones with page size to make sure all mempool objects reside on a page.
* Update release notes and map files.

V7 Changes:
* Removed previously proposed mempool flag and made those page boundary checks default in mempool populate() except for the objects size bigger than the size of page.
* Removed KNI example application related changes since pool related requirement is taken care in mempool lib.
* All PCI dev related info is moved under rte_eal_iova_mode() == VA check.
* Added wrapper functions in KNI module to hide IOVA checks and make address translation routines more readable.
* Updated IOVA mode checks that enforcing IOVA=PA mode when IOVA=VA mode is enabled.

V6 Changes:
* Added new mempool flag to ensure mbuf memory is not scattered across page boundaries.
* Added KNI kernel module required PCI device information.
* Modified KNI example application to create mempool with new mempool flag.

V5 changes:
* Fixed build issue with 32b build

V4 changes:
* Fixed build issues with older kernel versions
* This approach will only work with kernel above 4.4.0

V3 Changes:
* Add new approach to work kni with IOVA=VA mode using iommu_iova_to_phys API.

Kiran Kumar K (1):
kni: add IOVA=VA support in KNI module

Vamsi Attunuru (4):
mempool: populate mempool with the page sized chunks
kni: add IOVA=VA support in KNI lib
kni: add app specific mempool create and free routines
kni: modify IOVA mode checks to support VA

 doc/guides/prog_guide/kernel_nic_interface.rst    |  8 ++
 doc/guides/rel_notes/release_19_11.rst            |  5 ++
 examples/kni/main.c                               |  5 +-
 kernel/linux/kni/compat.h                         |  4 +
 kernel/linux/kni/kni_dev.h                        |  4 +
 kernel/linux/kni/kni_misc.c                       | 71 ++++++++++++++---
 kernel/linux/kni/kni_net.c                        | 59 ++++++++++----
 lib/librte_eal/linux/eal/eal.c                    |  4 +-
 lib/librte_eal/linux/eal/include/rte_kni_common.h |  8 ++
 lib/librte_kni/Makefile                           |  2 +
 lib/librte_kni/meson.build                        |  2 +
 lib/librte_kni/rte_kni.c                          | 95 +++++++++++++++++++++--
 lib/librte_kni/rte_kni.h                          | 48 ++++++++++++
 lib/librte_kni/rte_kni_version.map                |  2 +
 lib/librte_mempool/rte_mempool.c                  | 69 ++++++++++++++++
 lib/librte_mempool/rte_mempool.h                  | 20 +++++
 lib/librte_mempool/rte_mempool_version.map        |  1 +
 17 files changed, 378 insertions(+), 29 deletions(-)

--
2.8.4

#185 lore raw

Re: [dpdk-dev] [PATCH v10 0/5] kni: add IOVA=VA support

Hi Ferruh,

Mempool related patch has been acked by Olivier. Could you please review the kni related patches and make sure that it will be merged in 19.11 release.

Regards,
Vamsi

Quoted 119 lines

-----Original Message-----
From: Vamsi Krishna Attunuru <[email protected]>
Sent: Tuesday, October 8, 2019 10:39 AM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: RE: [dpdk-dev] [PATCH v10 0/5] kni: add IOVA=VA support

@All, we are expecting to merge this in 19.11 release and if any one have comments please respond.

Quoted 106 lines

-----Original Message-----
From: Vamsi Krishna Attunuru
Sent: Wednesday, September 25, 2019 9:30 AM
To: [email protected]; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: RE: [dpdk-dev] [PATCH v10 0/5] kni: add IOVA=VA support

PING.

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Friday, August 16, 2019 11:43 AM
To: [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>; Vamsi Krishna Attunuru <[email protected]>
Subject: [dpdk-dev] [PATCH v10 0/5] kni: add IOVA=VA support

From: Vamsi Attunuru <[email protected]>

---
V10 Changes:
* Fixed function return code on failure when min_chunk_size > pg_sz.
* Marked new mempool populate routine as EXPERIMENTAL.

V9 Changes:
* Used rte_mempool_ops_calc_mem_size() instead of default handler in the new mempool populate routine.
* Check min_chunk_size and return values.
* Removed ethdev_info memset to '0' and moved pci dev_info populate into
kni_dev_pci_addr_get() routine.
* Addressed misc. review comments.

V8 Changes:
* Remove default mempool populate() routine changes.
* Add kni app specific mempool create & free routines.
* Add new mempool populate routine to allocate page-aligned memzones with page size to make sure all mempool objects reside on a page.
* Update release notes and map files.

V7 Changes:
* Removed previously proposed mempool flag and made those page boundary checks default in mempool populate() except for the objects size bigger than the size of page.
* Removed KNI example application related changes since pool related requirement is taken care in mempool lib.
* All PCI dev related info is moved under rte_eal_iova_mode() == VA check.
* Added wrapper functions in KNI module to hide IOVA checks and make address translation routines more readable.
* Updated IOVA mode checks that enforcing IOVA=PA mode when IOVA=VA mode is enabled.

V6 Changes:
* Added new mempool flag to ensure mbuf memory is not scattered across page boundaries.
* Added KNI kernel module required PCI device information.
* Modified KNI example application to create mempool with new mempool flag.

V5 changes:
* Fixed build issue with 32b build

V4 changes:
* Fixed build issues with older kernel versions
* This approach will only work with kernel above 4.4.0

V3 Changes:
* Add new approach to work kni with IOVA=VA mode using iommu_iova_to_phys API.

Kiran Kumar K (1):
kni: add IOVA=VA support in KNI module

Vamsi Attunuru (4):
mempool: populate mempool with the page sized chunks
kni: add IOVA=VA support in KNI lib
kni: add app specific mempool create and free routines
kni: modify IOVA mode checks to support VA

 doc/guides/prog_guide/kernel_nic_interface.rst    |  8 ++
 doc/guides/rel_notes/release_19_11.rst            |  5 ++
 examples/kni/main.c                               |  5 +-
 kernel/linux/kni/compat.h                         |  4 +
 kernel/linux/kni/kni_dev.h                        |  4 +
 kernel/linux/kni/kni_misc.c                       | 71 ++++++++++++++---
 kernel/linux/kni/kni_net.c                        | 59 ++++++++++----
 lib/librte_eal/linux/eal/eal.c                    |  4 +-
 lib/librte_eal/linux/eal/include/rte_kni_common.h |  8 ++
 lib/librte_kni/Makefile                           |  2 +
 lib/librte_kni/meson.build                        |  2 +
 lib/librte_kni/rte_kni.c                          | 95 +++++++++++++++++++++--
 lib/librte_kni/rte_kni.h                          | 48 ++++++++++++
 lib/librte_kni/rte_kni_version.map                |  2 +
 lib/librte_mempool/rte_mempool.c                  | 69 ++++++++++++++++
 lib/librte_mempool/rte_mempool.h                  | 20 +++++
 lib/librte_mempool/rte_mempool_version.map        |  1 +
 17 files changed, 378 insertions(+), 29 deletions(-)

--
2.8.4

#186 lore raw

Re: [dpdk-dev] [PATCH v10 0/5] kni: add IOVA=VA support

In reply to [email protected]
Quoted 52 lines · On 8/16/2019 7:12 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

---
V10 Changes:
* Fixed function return code on failure when min_chunk_size > pg_sz.
* Marked new mempool populate routine as EXPERIMENTAL.

V9 Changes:
* Used rte_mempool_ops_calc_mem_size() instead of default handler in the new mempool populate routine.
* Check min_chunk_size and return values.
* Removed ethdev_info memset to '0' and moved pci dev_info populate into kni_dev_pci_addr_get() routine.
* Addressed misc. review comments.

V8 Changes:
* Remove default mempool populate() routine changes.
* Add kni app specific mempool create & free routines.
* Add new mempool populate routine to allocate page-aligned memzones with page size to make sure all mempool objects reside on a page.
* Update release notes and map files.

V7 Changes:
* Removed previously proposed mempool flag and made those page boundary checks default in mempool populate() except for the objects size bigger than the size of page.
* Removed KNI example application related changes since pool related requirement is taken care in mempool lib.
* All PCI dev related info is moved under rte_eal_iova_mode() == VA check.
* Added wrapper functions in KNI module to hide IOVA checks and make address translation routines more readable.
* Updated IOVA mode checks that enforcing IOVA=PA mode when IOVA=VA mode is enabled.

V6 Changes:
* Added new mempool flag to ensure mbuf memory is not scattered across page boundaries.
* Added KNI kernel module required PCI device information.
* Modified KNI example application to create mempool with new mempool flag.

V5 changes:
* Fixed build issue with 32b build

V4 changes:
* Fixed build issues with older kernel versions
* This approach will only work with kernel above 4.4.0

V3 Changes:
* Add new approach to work kni with IOVA=VA mode using iommu_iova_to_phys API.

Quoted 8 lines

Kiran Kumar K (1):
kni: add IOVA=VA support in KNI module

Vamsi Attunuru (4):
mempool: populate mempool with the page sized chunks
kni: add IOVA=VA support in KNI lib
kni: add app specific mempool create and free routines
kni: modify IOVA mode checks to support VA

Hi Vamsi,

I am aware that this patchset is around for a long time, and I have seen your request to merge in 19.11, but as you can understand the concern I have is to break KNI or existing KNI applications while trying to add this new feature.

In high level, there are two issues,

1) kernel modules updates expect there will be a backed device of the KNI which is not always true:

         if (dev_info.iova_mode) {
 #ifdef HAVE_IOVA_AS_VA_SUPPORT
                 pci = pci_get_device(dev_info.vendor_id,
                                      dev_info.device_id, NULL);
                 if (pci == NULL) {
                         pr_err("pci dev does not exist\n");
                         return -ENODEV;
                 }

For example this breaks:
./build/app/testpmd -w0:0.0 --vdev net_kni0 --vdev net_kni1 -- -i

2) Applications will have to change the API to allocate the mempool. If the user upgraded to new version of DPDK, now it is possible to have iova=va mode and application should use new KNI API 'rte_kni_pktmbuf_pool_create()' to allocate mempool. And most probably application will have datapath and will use the KNI only for exception path, will there be any affect using KNI version of mempool alloc?

I would like to see KNI is enabled via iova=va mode, but can we have it limited to a specific command line argument or config option? This increases the test surface but at least old application can continue to work by default, what do you think?

And I will put a few minor comments to the patches...

#187 lore raw

Re: [dpdk-dev] [PATCH v10 0/5] kni: add IOVA=VA support

Quoted 95 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Yigit, Ferruh
Sent: Tuesday, October 15, 2019 9:05 PM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v10 0/5] kni: add IOVA=VA support

Quoted 53 lines · On 8/16/2019 7:12 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

---
V10 Changes:
* Fixed function return code on failure when min_chunk_size > pg_sz.
* Marked new mempool populate routine as EXPERIMENTAL.

V9 Changes:
* Used rte_mempool_ops_calc_mem_size() instead of default handler in the new mempool populate routine.
* Check min_chunk_size and return values.
* Removed ethdev_info memset to '0' and moved pci dev_info populate into
kni_dev_pci_addr_get() routine.
* Addressed misc. review comments.

V8 Changes:
* Remove default mempool populate() routine changes.
* Add kni app specific mempool create & free routines.
* Add new mempool populate routine to allocate page-aligned memzones with page size to make sure all mempool objects reside on a page.
* Update release notes and map files.

V7 Changes:
* Removed previously proposed mempool flag and made those page boundary checks default in mempool populate() except for the objects size bigger than the size of page.
* Removed KNI example application related changes since pool related requirement is taken care in mempool lib.
* All PCI dev related info is moved under rte_eal_iova_mode() == VA check.
* Added wrapper functions in KNI module to hide IOVA checks and make address translation routines more readable.
* Updated IOVA mode checks that enforcing IOVA=PA mode when IOVA=VA mode is enabled.

V6 Changes:
* Added new mempool flag to ensure mbuf memory is not scattered across page boundaries.
* Added KNI kernel module required PCI device information.
* Modified KNI example application to create mempool with new mempool flag.

V5 changes:
* Fixed build issue with 32b build

V4 changes:
* Fixed build issues with older kernel versions
* This approach will only work with kernel above 4.4.0

V3 Changes:
* Add new approach to work kni with IOVA=VA mode using iommu_iova_to_phys API.

Quoted 8 lines

Kiran Kumar K (1):
kni: add IOVA=VA support in KNI module

Vamsi Attunuru (4):
mempool: populate mempool with the page sized chunks
kni: add IOVA=VA support in KNI lib
kni: add app specific mempool create and free routines
kni: modify IOVA mode checks to support VA

Hi Vamsi,

I am aware that this patchset is around for a long time, and I have seen your request to merge in 19.11, but as you can understand the concern I have is to break KNI or existing KNI applications while trying to add this new feature.

In high level, there are two issues,

1) kernel modules updates expect there will be a backed device of the KNI which is not always true:

         if (dev_info.iova_mode) {
 #ifdef HAVE_IOVA_AS_VA_SUPPORT
                 pci = pci_get_device(dev_info.vendor_id,
                                      dev_info.device_id, NULL);
                 if (pci == NULL) {
                         pr_err("pci dev does not exist\n");
                         return -ENODEV;
                 }
Quoted 2 lines

For example this breaks:
./build/app/testpmd -w0:0.0 --vdev net_kni0 --vdev net_kni1 -- -i

Vamsi> Yes, these can be fixed by forcing iommu_mode to PA for vdev or vdev&pdev based KNI usecases.

Quoted 8 lines

2) Applications will have to change the API to allocate the mempool. If the user upgraded to new version of DPDK, now it is possible to have iova=va mode and application should use new KNI API 'rte_kni_pktmbuf_pool_create()' to allocate mempool. And most probably application will have datapath and will use the KNI only for exception path, will there be any affect using KNI version of mempool alloc?

Vamsi> There would not be any affect in using KNI version of mempool.

Quoted 6 lines

I would like to see KNI is enabled via iova=va mode, but can we have it limited to a specific command line argument or config option? This increases the test surface but at least old application can continue to work by default, what do you think?

Vamsi> Yes, it's appropriate to control the mode to ensure old apps work by default. We are fine with having a command line arg or config option to enable KNI in iova=va mode. Earlier we thought of having similar approach that also controls mempool allocation using a newer mempool flag. After multiple reviews, flag has been discard and added a separate mempool populate routine for these usecase.

When command line arg/config option is introduced, functionality will be as below. Please correct me if any cases are missed or not considered.
Without command:
Existing KNI is intact, iommu mode will be PA.
With command:
Pdev/vdev's iommu mode is considered and accordingly iova=va/pa is enabled. Application is supposed to use KNI version of mempool alloc. I think these mempool quirk will go away when Olivier's mempool patchset(RFC) is merged.

Quoted 3 lines

And I will put a few minor comments to the patches...

#188 lore raw

Re: [dpdk-dev] [PATCH v10 0/5] kni: add IOVA=VA support

Quoted 103 lines · Vamsi Krishna Attunuru
Quoted 95 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Yigit, Ferruh
Sent: Tuesday, October 15, 2019 9:05 PM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v10 0/5] kni: add IOVA=VA support

Quoted 53 lines · On 8/16/2019 7:12 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

---
V10 Changes:
* Fixed function return code on failure when min_chunk_size > pg_sz.
* Marked new mempool populate routine as EXPERIMENTAL.

V9 Changes:
* Used rte_mempool_ops_calc_mem_size() instead of default handler in the new mempool populate routine.
* Check min_chunk_size and return values.
* Removed ethdev_info memset to '0' and moved pci dev_info populate into
kni_dev_pci_addr_get() routine.
* Addressed misc. review comments.

V8 Changes:
* Remove default mempool populate() routine changes.
* Add kni app specific mempool create & free routines.
* Add new mempool populate routine to allocate page-aligned memzones with page size to make sure all mempool objects reside on a page.
* Update release notes and map files.

V7 Changes:
* Removed previously proposed mempool flag and made those page boundary checks default in mempool populate() except for the objects size bigger than the size of page.
* Removed KNI example application related changes since pool related requirement is taken care in mempool lib.
* All PCI dev related info is moved under rte_eal_iova_mode() == VA check.
* Added wrapper functions in KNI module to hide IOVA checks and make address translation routines more readable.
* Updated IOVA mode checks that enforcing IOVA=PA mode when IOVA=VA mode is enabled.

V6 Changes:
* Added new mempool flag to ensure mbuf memory is not scattered across page boundaries.
* Added KNI kernel module required PCI device information.
* Modified KNI example application to create mempool with new mempool flag.

V5 changes:
* Fixed build issue with 32b build

V4 changes:
* Fixed build issues with older kernel versions
* This approach will only work with kernel above 4.4.0

V3 Changes:
* Add new approach to work kni with IOVA=VA mode using iommu_iova_to_phys API.

Quoted 8 lines

Kiran Kumar K (1):
kni: add IOVA=VA support in KNI module

Vamsi Attunuru (4):
mempool: populate mempool with the page sized chunks
kni: add IOVA=VA support in KNI lib
kni: add app specific mempool create and free routines
kni: modify IOVA mode checks to support VA

Hi Vamsi,

I am aware that this patchset is around for a long time, and I have seen your request to merge in 19.11, but as you can understand the concern I have is to break KNI or existing KNI applications while trying to add this new feature.

In high level, there are two issues,

1) kernel modules updates expect there will be a backed device of the KNI which is not always true:

         if (dev_info.iova_mode) {
 #ifdef HAVE_IOVA_AS_VA_SUPPORT
                 pci = pci_get_device(dev_info.vendor_id,
                                      dev_info.device_id, NULL);
                 if (pci == NULL) {
                         pr_err("pci dev does not exist\n");
                         return -ENODEV;
                 }
Quoted 2 lines

For example this breaks:
./build/app/testpmd -w0:0.0 --vdev net_kni0 --vdev net_kni1 -- -i

Vamsi> Yes, these can be fixed by forcing iommu_mode to PA for vdev or vdev&pdev based KNI usecases.

Quoted 2 lines
Quoted 8 lines
Quoted 6 lines

2) Applications will have to change the API to allocate the mempool. If the user upgraded to new version of DPDK, now it is possible to have iova=va mode and application should use new KNI API 'rte_kni_pktmbuf_pool_create()' to allocate mempool. And most probably application will have datapath and will use the KNI only for exception path, will there be any affect using KNI version of mempool alloc?

Vamsi> There would not be any affect in using KNI version of mempool.

If you were developing a product, would you rely on a KNI API for pkt_mbuf allocation? What if there is a problem, will it be as easy as mempool/mbuf API to figure out and fix? I am not sure about pushing users to this direction?

Quoted 8 lines
Quoted 7 lines

I would like to see KNI is enabled via iova=va mode, but can we have it limited to a specific command line argument or config option? This increases the test surface but at least old application can continue to work by default, what do you think?

Quoted 5 lines

Vamsi> Yes, it's appropriate to control the mode to ensure old apps work by default. We are fine with having a command line arg or config option to enable KNI in iova=va mode. Earlier we thought of having similar approach that also controls mempool allocation using a newer mempool flag. After multiple reviews, flag has been discard and added a separate mempool populate routine for these usecase.

I didn't like the idea of having a flag in mempool library, but perhaps we can have it in KNI scope.

Quoted 5 lines

When command line arg/config option is introduced, functionality will be as below. Please correct me if any cases are missed or not considered.
Without command:
Existing KNI is intact, iommu mode will be PA.

+1

Quoted 3 lines

With command:
Pdev/vdev's iommu mode is considered and accordingly iova=va/pa is enabled. Application is supposed to use KNI version of mempool alloc.

+1

Quoted 7 lines

I think these mempool quirk will go away when
Olivier's mempool patchset(RFC) is merged.

Quoted 3 lines

And I will put a few minor comments to the patches...

#189 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v10 0/5] kni: add IOVA=VA support

Quoted 132 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Wednesday, October 16, 2019 9:52 PM
To: Vamsi Krishna Attunuru <[email protected]>; Yigit, Ferruh <[email protected]>
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]
Subject: [EXT] Re: [dpdk-dev] [PATCH v10 0/5] kni: add IOVA=VA support

External Email

----------------------------------------------------------------------

Quoted 29 lines · Vamsi Krishna Attunuru
Quoted 29 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Yigit, Ferruh
Sent: Tuesday, October 15, 2019 9:05 PM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Kiran Kumar Kokkilagadda <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v10 0/5] kni: add IOVA=VA support

Quoted 16 lines · On 8/16/2019 7:12 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

---
V10 Changes:
* Fixed function return code on failure when min_chunk_size > pg_sz.
* Marked new mempool populate routine as EXPERIMENTAL.

V9 Changes:
* Used rte_mempool_ops_calc_mem_size() instead of default handler in the new mempool populate routine.
* Check min_chunk_size and return values.
* Removed ethdev_info memset to '0' and moved pci dev_info populate into
kni_dev_pci_addr_get() routine.
* Addressed misc. review comments.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

V8 Changes:
* Remove default mempool populate() routine changes.
* Add kni app specific mempool create & free routines.
* Add new mempool populate routine to allocate page-aligned

memzones

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

with page size to make sure all mempool objects reside on a page.
* Update release notes and map files.

V7 Changes:
* Removed previously proposed mempool flag and made those page boundary checks default in mempool populate() except for the objects size bigger than the size of page.
* Removed KNI example application related changes since pool related requirement is taken care in mempool lib.
* All PCI dev related info is moved under rte_eal_iova_mode() == VA

check.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

* Added wrapper functions in KNI module to hide IOVA checks and make address translation routines more readable.
* Updated IOVA mode checks that enforcing IOVA=PA mode when

IOVA=VA

Quoted 29 lines
Quoted 29 lines
Quoted 28 lines

mode is enabled.

V6 Changes:
* Added new mempool flag to ensure mbuf memory is not scattered across page boundaries.
* Added KNI kernel module required PCI device information.
* Modified KNI example application to create mempool with new mempool flag.

V5 changes:
* Fixed build issue with 32b build

V4 changes:
* Fixed build issues with older kernel versions
* This approach will only work with kernel above 4.4.0

V3 Changes:
* Add new approach to work kni with IOVA=VA mode using iommu_iova_to_phys API.

Kiran Kumar K (1):
kni: add IOVA=VA support in KNI module

Vamsi Attunuru (4):
mempool: populate mempool with the page sized chunks
kni: add IOVA=VA support in KNI lib
kni: add app specific mempool create and free routines
kni: modify IOVA mode checks to support VA

Quoted 5 lines
Quoted 5 lines

Hi Vamsi,

I am aware that this patchset is around for a long time, and I have seen your request to merge in 19.11, but as you can understand the concern I have is to break KNI or existing KNI applications while trying to

add this new feature.

Quoted 15 lines
Quoted 15 lines

In high level, there are two issues,

1) kernel modules updates expect there will be a backed device of the KNI which is not always true:

         if (dev_info.iova_mode) {
 #ifdef HAVE_IOVA_AS_VA_SUPPORT
                 pci = pci_get_device(dev_info.vendor_id,
                                      dev_info.device_id, NULL);
                 if (pci == NULL) {
                         pr_err("pci dev does not exist\n");
                         return -ENODEV;
                 }
Quoted 11 lines
Quoted 2 lines

For example this breaks:
./build/app/testpmd -w0:0.0 --vdev net_kni0 --vdev net_kni1 -- -i

Vamsi> Yes, these can be fixed by forcing iommu_mode to PA for vdev or vdev&pdev based KNI usecases.

Quoted 5 lines

2) Applications will have to change the API to allocate the mempool. If the user upgraded to new version of DPDK, now it is possible to have iova=va mode and application should use new KNI API

'rte_kni_pktmbuf_pool_create()'

Quoted 4 lines
Quoted 3 lines

to allocate mempool. And most probably application will have datapath and will use the KNI only for exception path, will there be any affect using KNI version of mempool alloc?

Quoted 5 lines
Quoted 1 line

Vamsi> There would not be any affect in using KNI version of mempool.

If you were developing a product, would you rely on a KNI API for pkt_mbuf allocation? What if there is a problem, will it be as easy as mempool/mbuf API to figure out and fix? I am not sure about pushing users to this direction?

Vamsi > If user wants to run KNI app in iova=va mode, mempool populate needs to ensure mbuf would not be allocated from a page boundary. IMO after having config option/cmd line parameter to enable KNI iova=va mode, existing KNI will be intact and these mempool API only be called upon request. I will document these details in KNI document. Based on earlier comments and discussions with Olivier and Andrew on the mempool populate patch, we arrived at these solution.

Hi Olivier,
Please let us know your thoughts on these patch. I am open to any of your suggestions/solution to fix mempool populate issue for KNI iova=va use case.

Quoted 12 lines
Quoted 10 lines
Quoted 8 lines

I would like to see KNI is enabled via iova=va mode, but can we have it limited to a specific command line argument or config option? This increases the test surface but at least old application can continue to work by default, what do you think?

Vamsi> Yes, it's appropriate to control the mode to ensure old apps work

by default.

Quoted 1 line

We are fine with having a command line arg or config option to enable KNI

Quoted 8 lines

in iova=va mode.

Quoted 3 lines

Earlier we thought of having similar approach that also controls mempool allocation using a newer mempool flag. After multiple reviews, flag has been discard and added a separate mempool populate routine for

these usecase.

I didn't like the idea of having a flag in mempool library, but perhaps we can have it in KNI scope.

Vamsi> I failed to understand KNI scope here, IMO, though we have flag in KNI scope, it needs to be affected in mempool lib right finally.

Quoted 23 lines
Quoted 3 lines

When command line arg/config option is introduced, functionality will be

as below.

Quoted 3 lines

Please correct me if any cases are missed or not considered. Without command:
Existing KNI is intact, iommu mode will be PA.

+1

Quoted 3 lines

With command:
Pdev/vdev's iommu mode is considered and accordingly iova=va/pa is enabled. Application is supposed to use KNI version of mempool alloc.

+1

Quoted 7 lines

I think these mempool quirk will go away when Olivier's mempool patchset(RFC) is merged.

Quoted 3 lines

And I will put a few minor comments to the patches...

#190 lore raw

v11 cover kni: add IOVA=VA mode support

In reply to [email protected]

From: Vamsi Attunuru <[email protected]>

---
V11 Changes:
* Added iova to kva address translation routines in kernel module to make it work in iova=va mode which enables DPDK to create kni devices on any kind of backed device/memory.
* Added ``--legacy-kni`` eal option to make existing KNI applications work with DPDK 19.11 and later versions.
* Removed previously added pci device info from kni device info struct.

V10 Changes:
* Fixed function return code on failure when min_chunk_size > pg_sz.
* Marked new mempool populate routine as EXPERIMENTAL.

V9 Changes:
* Used rte_mempool_ops_calc_mem_size() instead of default handler in the new mempool populate routine.
* Check min_chunk_size and return values.
* Removed ethdev_info memset to '0' and moved pci dev_info populate into kni_dev_pci_addr_get() routine.
* Addressed misc. review comments.

V8 Changes:
* Remove default mempool populate() routine changes.
* Add kni app specific mempool create & free routines.
* Add new mempool populate routine to allocate page-aligned memzones with page size to make sure all mempool objects reside on a page.
* Update release notes and map files.

V7 Changes:
* Removed previously proposed mempool flag and made those page boundary checks default in mempool populate() except for the objects size bigger than the size of page.
* Removed KNI example application related changes since pool related requirement is taken care in mempool lib.
* All PCI dev related info is moved under rte_eal_iova_mode() == VA check.
* Added wrapper functions in KNI module to hide IOVA checks and make address translation routines more readable.
* Updated IOVA mode checks that enforcing IOVA=PA mode when IOVA=VA mode is enabled.

V6 Changes:
* Added new mempool flag to ensure mbuf memory is not scattered across page boundaries.
* Added KNI kernel module required PCI device information.
* Modified KNI example application to create mempool with new mempool flag.

V5 changes:
* Fixed build issue with 32b build

V4 changes:
* Fixed build issues with older kernel versions
* This approach will only work with kernel above 4.4.0

V3 Changes:
* Add new approach to work kni with IOVA=VA mode using iommu_iova_to_phys API.

Vamsi Attunuru (4):
mempool: populate mempool with the page sized chunks
eal: add legacy kni option
kni: add IOVA=VA support
kni: add IOVA=VA support in kernel module

 doc/guides/prog_guide/kernel_nic_interface.rst    | 26 +++++++++
 doc/guides/rel_notes/release_19_11.rst            | 17 ++++++
 examples/kni/main.c                               |  6 +-
 kernel/linux/kni/compat.h                         |  4 ++
 kernel/linux/kni/kni_dev.h                        | 31 ++++++++++
 kernel/linux/kni/kni_misc.c                       | 39 ++++++++++---
 kernel/linux/kni/kni_net.c                        | 58 ++++++++++++++-----
 lib/librte_eal/common/eal_common_options.c        |  5 ++
 lib/librte_eal/common/eal_internal_cfg.h          |  2 +
 lib/librte_eal/common/eal_options.h               |  2 +
 lib/librte_eal/linux/eal/eal.c                    | 40 +++++++++----
 lib/librte_eal/linux/eal/include/rte_kni_common.h |  1 +
 lib/librte_kni/Makefile                           |  1 +
 lib/librte_kni/meson.build                        |  1 +
 lib/librte_kni/rte_kni.c                          | 67 ++++++++++++++++++++--
 lib/librte_kni/rte_kni.h                          | 48 ++++++++++++++++
 lib/librte_kni/rte_kni_version.map                |  3 +
 lib/librte_mempool/rte_mempool.c                  | 69 +++++++++++++++++++++++
 lib/librte_mempool/rte_mempool.h                  | 20 +++++++
 lib/librte_mempool/rte_mempool_version.map        |  2 +
 20 files changed, 402 insertions(+), 40 deletions(-)
Signature · 1 line
2.8.4
#191 lore raw

PATCH v11 1/4 mempool: populate mempool with the page sized chunks

From: Vamsi Attunuru <[email protected]>

Patch adds a routine to populate mempool from page aligned and page sized chunks of memory to ensure memory objs do not fall across the page boundaries. It's useful for applications that require physically contiguous mbuf memory while running in IOVA=VA mode.

---
 lib/librte_mempool/rte_mempool.c           | 69 ++++++++++++++++++++++++++++++
 lib/librte_mempool/rte_mempool.h           | 20 +++++++++
 lib/librte_mempool/rte_mempool_version.map |  2 +
 3 files changed, 91 insertions(+)
lib/librte_mempool/rte_mempool.c +69 -0
index 0f29e87..ef1298d 100644
@@ -414,6 +414,75 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
 	return ret;
 }
 
+/* Function to populate mempool from page sized mem chunks, allocate page size
+ * of memory in memzone and populate them. Return the number of objects added,
+ * or a negative value on error.
+ */
+int
+rte_mempool_populate_from_pg_sz_chunks(struct rte_mempool *mp)
+{
+	char mz_name[RTE_MEMZONE_NAMESIZE];
+	size_t align, pg_sz, pg_shift;
+	const struct rte_memzone *mz;
+	unsigned int mz_id, n;
+	size_t min_chunk_size;
+	int ret;
+
+	ret = mempool_ops_alloc_once(mp);
+	if (ret != 0)
+		return ret;
+
+	if (mp->nb_mem_chunks != 0)
+		return -EEXIST;
+
+	pg_sz = get_min_page_size(mp->socket_id);
+	pg_shift = rte_bsf32(pg_sz);
+
+	for (mz_id = 0, n = mp->size; n > 0; mz_id++, n -= ret) {
+
+		ret = rte_mempool_ops_calc_mem_size(mp, n,
+				pg_shift, &min_chunk_size, &align);
+
+		if (ret < 0)
+			goto fail;
+
+		if (min_chunk_size > pg_sz) {
+			ret = -EINVAL;
+			goto fail;
+		}
+
+		ret = snprintf(mz_name, sizeof(mz_name),
+			RTE_MEMPOOL_MZ_FORMAT "_%d", mp->name, mz_id);
+		if (ret < 0 || ret >= (int)sizeof(mz_name)) {
+			ret = -ENAMETOOLONG;
+			goto fail;
+		}
+
+		mz = rte_memzone_reserve_aligned(mz_name, min_chunk_size,
+				mp->socket_id, 0, align);
+
+		if (mz == NULL) {
+			ret = -rte_errno;
+			goto fail;
+		}
+
+		ret = rte_mempool_populate_iova(mp, mz->addr,
+				mz->iova, mz->len,
+				rte_mempool_memchunk_mz_free,
+				(void *)(uintptr_t)mz);
+		if (ret < 0) {
+			rte_memzone_free(mz);
+			goto fail;
+		}
+	}
+
+	return mp->size;
+
+fail:
+	rte_mempool_free_memchunks(mp);
+	return ret;
+}
+
 /* Default function to populate the mempool: allocate memory in memzones,
  * and populate them. Return the number of objects added, or a negative
  * value on error.
lib/librte_mempool/rte_mempool.h +20 -0
index 8053f7a..2f5126e 100644
@@ -1062,6 +1062,26 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr,
 	void *opaque);
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Add memory from page sized memzones for objects in the pool at init
+ *
+ * This is the function used to populate the mempool with page aligned and
+ * page sized memzone memory to avoid spreading object memory across two pages
+ * and to ensure all mempool objects reside on the page memory.
+ *
+ * @param mp
+ *   A pointer to the mempool structure.
+ * @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.
+ */
+__rte_experimental
+int rte_mempool_populate_from_pg_sz_chunks(struct rte_mempool *mp);
+
+/**
  * Add memory for objects in the pool at init
  *
  * This is the default function used by rte_mempool_create() to populate
lib/librte_mempool/rte_mempool_version.map +2 -0
index 17cbca4..d6fe5a5 100644
@@ -57,4 +57,6 @@ EXPERIMENTAL {
 	global:
 
 	rte_mempool_ops_get_info;
+	# added in 19.11
+	rte_mempool_populate_from_pg_sz_chunks;
 };
Signature · 1 line
2.8.4
#192 lore raw

PATCH v11 2/4 eal: add legacy kni option

In reply to [email protected]

From: Vamsi Attunuru <[email protected]>

This adds a "--legacy-kni" command-line option. It will be used to run existing KNI applications with DPDK 19.11 and later.

---
 doc/guides/rel_notes/release_19_11.rst     | 4 ++++
 lib/librte_eal/common/eal_common_options.c | 5 +++++
 lib/librte_eal/common/eal_internal_cfg.h   | 2 ++
 lib/librte_eal/common/eal_options.h        | 2 ++
 4 files changed, 13 insertions(+)
doc/guides/rel_notes/release_19_11.rst +4 -0
index 85953b9..ab2c381 100644
@@ -115,6 +115,10 @@ New Features
   Added eBPF JIT support for arm64 architecture to improve the eBPF program
   performance.
 
+* **Added EAL option to operate KNI in legacy mode.**
+
+  Added EAL option ``--legacy-kni`` to make existing KNI applications work
+  with DPDK 19.11 and later.
 
 Removed Items
 -------------
lib/librte_eal/common/eal_common_options.c +5 -0
index 05cae5f..8f5174e 100644
@@ -81,6 +81,7 @@ eal_long_options[] = {
 	{OPT_LEGACY_MEM,        0, NULL, OPT_LEGACY_MEM_NUM       },
 	{OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM},
 	{OPT_MATCH_ALLOCATIONS, 0, NULL, OPT_MATCH_ALLOCATIONS_NUM},
+	{OPT_LEGACY_KNI,        0, NULL, OPT_LEGACY_KNI_NUM       },
 	{0,                     0, NULL, 0                        }
 };
 
@@ -1408,6 +1409,9 @@ eal_parse_common_option(int opt, const char *optarg,
 			return -1;
 		}
 		break;
+	case OPT_LEGACY_KNI_NUM:
+		conf->legacy_kni = 1;
+		break;
 
 	/* don't know what to do, leave this to caller */
 	default:
@@ -1636,6 +1640,7 @@ eal_common_usage(void)
 	       "                      (ex: --vdev=net_pcap0,iface=eth2).\n"
 	       "  --"OPT_IOVA_MODE"   Set IOVA mode. 'pa' for IOVA_PA\n"
 	       "                      'va' for IOVA_VA\n"
+	       "  --"OPT_LEGACY_KNI"  Run KNI in IOVA_PA mode (legacy mode)\n"
 	       "  -d LIB.so|DIR       Add a driver or driver directory\n"
 	       "                      (can be used multiple times)\n"
 	       "  --"OPT_VMWARE_TSC_MAP"    Use VMware TSC map instead of native RDTSC\n"
lib/librte_eal/common/eal_internal_cfg.h +2 -0
index a42f349..eee71ec 100644
@@ -82,6 +82,8 @@ struct internal_config {
 	rte_cpuset_t ctrl_cpuset;         /**< cpuset for ctrl threads */
 	volatile unsigned int init_complete;
 	/**< indicates whether EAL has completed initialization */
+	volatile unsigned legacy_kni;
+	/**< true to enable legacy kni behavior */
 };
 extern struct internal_config internal_config; /**< Global EAL configuration. */
 
lib/librte_eal/common/eal_options.h +2 -0
index 9855429..1010ed3 100644
@@ -69,6 +69,8 @@ enum {
 	OPT_IOVA_MODE_NUM,
 #define OPT_MATCH_ALLOCATIONS  "match-allocations"
 	OPT_MATCH_ALLOCATIONS_NUM,
+#define OPT_LEGACY_KNI      "legacy-kni"
+	OPT_LEGACY_KNI_NUM,
 	OPT_LONG_MAX_NUM
 };
 
Signature · 1 line
2.8.4
#193 lore raw

Re: [dpdk-dev] [PATCH v11 2/4] eal: add legacy kni option

Quoted 8 lines · On 10/21/2019 9:03 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

This adds a "--legacy-kni" command-line option. It will be used to run existing KNI applications with DPDK 19.11 and later.

<...>

lib/librte_eal/common/eal_options.h enum { · line 75

Quoted 12 lines
lib/librte_eal/common/eal_options.h +2 -0
index 9855429..1010ed3 100644
@@ -69,6 +69,8 @@ enum {
 	OPT_IOVA_MODE_NUM,
 #define OPT_MATCH_ALLOCATIONS  "match-allocations"
 	OPT_MATCH_ALLOCATIONS_NUM,
+#define OPT_LEGACY_KNI      "legacy-kni"
+	OPT_LEGACY_KNI_NUM,
 	OPT_LONG_MAX_NUM
 };

Two concerns,

1- "legacy-kni" doesn't have enough context

2- I prefer to keep existing behavior default, at least for a while, something like next LTS etc, meanwhile this patch can be around for a good time and can be good to switch.

Based on above to, what do you think to rename the option to 'kni-iova-va', if not set by default it will be "IOVA=PA", when set it will enable "IOVA=VA" mode?

#194 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Quoted 44 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Monday, October 21, 2019 5:25 PM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [EXT] Re: [dpdk-dev] [PATCH v11 2/4] eal: add legacy kni option

External Email

----------------------------------------------------------------------

Quoted 7 lines · On 10/21/2019 9:03 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

This adds a "--legacy-kni" command-line option. It will be used to run existing KNI applications with DPDK 19.11 and later.

<...>

lib/librte_eal/common/eal_options.h enum { · line 75

Quoted 13 lines
lib/librte_eal/common/eal_options.h +2 -0
index 9855429..1010ed3 100644
@@ -69,6 +69,8 @@ enum {
 	OPT_IOVA_MODE_NUM,
 #define OPT_MATCH_ALLOCATIONS  "match-allocations"
 	OPT_MATCH_ALLOCATIONS_NUM,
+#define OPT_LEGACY_KNI      "legacy-kni"
+	OPT_LEGACY_KNI_NUM,
 	OPT_LONG_MAX_NUM
 };

Two concerns,

1- "legacy-kni" doesn't have enough context

Quoted 7 lines

2- I prefer to keep existing behavior default, at least for a while, something like next LTS etc, meanwhile this patch can be around for a good time and can be good to switch.

Based on above to, what do you think to rename the option to 'kni-iova-va', if not set by default it will be "IOVA=PA", when set it will enable "IOVA=VA" mode?

Hi Ferruh,

I think the new eal flag(legacy-kni) is quite intuitive. Since release notes will be having the required details about it's purpose and how it enables users to use existing applications on latest dpdk.

Current EAL does set iova as va if bus iommu returns DC, meaning iova=va is the kind of default mode(in most of use cases) and for running kni, we have to explicitly set the flag to run kni in iova=va mode all the time. I think having a flag for legacy usage(PA mode) is more appropriate than having kni-iova-va kind of flag.

Otx2 net pmd that runs on Octeontx2 platforms only supports iova=va mode, we would like to have KNI running by default without any flags passed.

#195 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Quoted 48 lines · Vamsi Krishna Attunuru
Quoted 48 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Monday, October 21, 2019 5:25 PM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [EXT] Re: [dpdk-dev] [PATCH v11 2/4] eal: add legacy kni option

External Email

----------------------------------------------------------------------

Quoted 7 lines · On 10/21/2019 9:03 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

This adds a "--legacy-kni" command-line option. It will be used to run existing KNI applications with DPDK 19.11 and later.

<...>

lib/librte_eal/common/eal_options.h enum { · line 75

Quoted 13 lines
lib/librte_eal/common/eal_options.h +2 -0
index 9855429..1010ed3 100644
@@ -69,6 +69,8 @@ enum {
 	OPT_IOVA_MODE_NUM,
 #define OPT_MATCH_ALLOCATIONS  "match-allocations"
 	OPT_MATCH_ALLOCATIONS_NUM,
+#define OPT_LEGACY_KNI      "legacy-kni"
+	OPT_LEGACY_KNI_NUM,
 	OPT_LONG_MAX_NUM
 };

Two concerns,

1- "legacy-kni" doesn't have enough context

2- I prefer to keep existing behavior default, at least for a while, something like next LTS etc, meanwhile this patch can be around for a good time and can be good to switch.

Quoted 7 lines
Quoted 3 lines

Based on above to, what do you think to rename the option to 'kni-iova-va', if not set by default it will be "IOVA=PA", when set it will enable "IOVA=VA" mode?

Hi Ferruh,

I think the new eal flag(legacy-kni) is quite intuitive. Since release notes will be having the required details about it's purpose and how it enables users to use existing applications on latest dpdk.

what exactly 'legacy' means, what has been changed, is the old one completely replaced/re-written ????, but whoever not following what is happening won't underase tand what is old in the KNI, digging through release notes and commits will give this information but it will be hard to get it from binary and get harder by a few releases passed.

Quoted 2 lines

Current EAL does set iova as va if bus iommu returns DC, meaning iova=va is the kind of default mode(in most of use cases) and for running kni, we have to explicitly set the flag to run kni in iova=va mode all the time. I think having a flag for legacy usage(PA mode) is more appropriate than having kni-iova-va kind of flag.

It is about keeping the existing behavior same, right now if the kni module is inserted it will force the PA mode. With your update it will be possible to run iova=va with kni module inserted when flag is set. I suggest giving some time to this new behavior before making it default.

Quoted 3 lines

Otx2 net pmd that runs on Octeontx2 platforms only supports iova=va mode, we would like to have KNI running by default without any flags passed.

I see, but other way around will affect all existing KNI users, they will either need to add this flag or update their application.

This is new feature, who want to use it adding a specific flag makes more sense to me than all old users have to add the flag.

#196 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Hi Olivier, Andrew,

Quoted 48 lines
Quoted 7 lines
Quoted 7 lines

lib/librte_eal/common/eal_options.h enum { · line 75

Quoted 4 lines
lib/librte_eal/common/eal_options.h +2 -0
+#define OPT_LEGACY_KNI      "legacy-kni"
+	OPT_LEGACY_KNI_NUM,
 	OPT_LONG_MAX_NUM
 };

Two concerns,

Quoted 8 lines
Quoted 8 lines

1- "legacy-kni" doesn't have enough context

2- I prefer to keep existing behavior default, at least for a while, something like next LTS etc, meanwhile this patch can be around for a good time and can be good to switch.

Based on above to, what do you think to rename the option to 'kni-iova-va', if not set by default it will be "IOVA=PA", when set it will

enable "IOVA=VA"

Quoted 5 lines
Quoted 1 line

mode?

Hi Ferruh,

I think the new eal flag(legacy-kni) is quite intuitive. Since release notes will

be having the required details about it's purpose and how it enables users to use existing applications on latest dpdk.

what exactly 'legacy' means, what has been changed, is the old one completely replaced/re-written ????, but whoever not following what is happening won't underase tand what is old in the KNI, digging through release notes and commits will give this information but it will be hard to get it from binary and get harder by a few releases passed.

Quoted 2 lines

Current EAL does set iova as va if bus iommu returns DC, meaning iova=va

is the kind of default mode(in most of use cases) and for running kni, we have to explicitly set the flag to run kni in iova=va mode all the time. I think having a flag for legacy usage(PA mode) is more appropriate than having kni- iova-va kind of flag.

It is about keeping the existing behavior same, right now if the kni module is inserted it will force the PA mode. With your update it will be possible to run iova=va with kni module inserted when flag is set. I suggest giving some time to this new behavior before making it default.

Quoted 2 lines

Otx2 net pmd that runs on Octeontx2 platforms only supports iova=va

mode, we would like to have KNI running by default without any flags passed.

Quoted 1 line
Quoted 5 lines

I see, but other way around will affect all existing KNI users, they will either need to add this flag or update their application.

This is new feature, who want to use it adding a specific flag makes more sense to me than all old users have to add the flag.

Ferruh suggested to have a flag for enabling these new feature and also not interested in having newer mempool alloc APIs for KNI(see V10 review comments). Before reworking on the flag changes, I would like check with you whether the same flag can be used in mempool lib for checking and fulfilling the mempool page boundary requirement (mempool patch v11 1/4), by doing so, it can avoid newer exported APIs both in mempool and KNI lib. Anyways, these mempool requirement can be addressed with Olivier's below patches.

http://patchwork.dpdk.org/project/dpdk/list/?series=5624

When those patches are merged, flag check can be removed.

Regards
A Vamsi

Quoted 101 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Monday, October 21, 2019 7:02 PM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [EXT] Re: [dpdk-dev] [PATCH v11 2/4] eal: add legacy kni option

Quoted 44 lines · Vamsi Krishna Attunuru
Quoted 44 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Monday, October 21, 2019 5:25 PM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [EXT] Re: [dpdk-dev] [PATCH v11 2/4] eal: add legacy kni option

External Email

---------------------------------------------------------------------

Quoted 7 lines · - On 10/21/2019 9:03 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

This adds a "--legacy-kni" command-line option. It will be used to run existing KNI applications with DPDK 19.11 and later.

<...>

lib/librte_eal/common/eal_options.h enum { · line 75

Quoted 13 lines
lib/librte_eal/common/eal_options.h +2 -0
index 9855429..1010ed3 100644
@@ -69,6 +69,8 @@ enum {
 	OPT_IOVA_MODE_NUM,
 #define OPT_MATCH_ALLOCATIONS  "match-allocations"
 	OPT_MATCH_ALLOCATIONS_NUM,
+#define OPT_LEGACY_KNI      "legacy-kni"
+	OPT_LEGACY_KNI_NUM,
 	OPT_LONG_MAX_NUM
 };

Two concerns,

Quoted 8 lines
Quoted 8 lines

1- "legacy-kni" doesn't have enough context

2- I prefer to keep existing behavior default, at least for a while, something like next LTS etc, meanwhile this patch can be around for a good time and can be good to switch.

Based on above to, what do you think to rename the option to 'kni-iova-va', if not set by default it will be "IOVA=PA", when set it will

enable "IOVA=VA"

Quoted 5 lines
Quoted 1 line

mode?

Hi Ferruh,

I think the new eal flag(legacy-kni) is quite intuitive. Since release notes will

be having the required details about it's purpose and how it enables users to use existing applications on latest dpdk.

what exactly 'legacy' means, what has been changed, is the old one completely replaced/re-written ????, but whoever not following what is happening won't underase tand what is old in the KNI, digging through release notes and commits will give this information but it will be hard to get it from binary and get harder by a few releases passed.

Quoted 2 lines

Current EAL does set iova as va if bus iommu returns DC, meaning iova=va

is the kind of default mode(in most of use cases) and for running kni, we have to explicitly set the flag to run kni in iova=va mode all the time. I think having a flag for legacy usage(PA mode) is more appropriate than having kni- iova-va kind of flag.

It is about keeping the existing behavior same, right now if the kni module is inserted it will force the PA mode. With your update it will be possible to run iova=va with kni module inserted when flag is set. I suggest giving some time to this new behavior before making it default.

Quoted 2 lines

Otx2 net pmd that runs on Octeontx2 platforms only supports iova=va

mode, we would like to have KNI running by default without any flags passed.

Quoted 1 line

I see, but other way around will affect all existing KNI users, they will either need to add this flag or update their application.

This is new feature, who want to use it adding a specific flag makes more sense to me than all old users have to add the flag.

#197 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Hi Olivier, Andrew,

Please share your thoughts/comments on below email.

Quoted 199 lines

-----Original Message-----
From: Vamsi Krishna Attunuru
Sent: Monday, October 21, 2019 8:08 PM
To: [email protected]; Andrew Rybchenko <[email protected]>
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Ferruh Yigit <[email protected]>; [email protected]
Subject: RE: [EXT] Re: [dpdk-dev] [PATCH v11 2/4] eal: add legacy kni option

Hi Olivier, Andrew,

Quoted 51 lines
Quoted 9 lines
Quoted 9 lines

lib/librte_eal/common/eal_options.h enum { · line 75

Quoted 4 lines
lib/librte_eal/common/eal_options.h +2 -0
+#define OPT_LEGACY_KNI      "legacy-kni"
+	OPT_LEGACY_KNI_NUM,
 	OPT_LONG_MAX_NUM
 };

Two concerns,

1- "legacy-kni" doesn't have enough context

Quoted 7 lines
Quoted 7 lines

2- I prefer to keep existing behavior default, at least for a while, something like next LTS etc, meanwhile this patch can be around for a good time and can be good to switch.

Based on above to, what do you think to rename the option to 'kni-iova-va', if not set by default it will be "IOVA=PA", when set it will

enable "IOVA=VA"

Quoted 6 lines
Quoted 1 line

mode?

Hi Ferruh,

I think the new eal flag(legacy-kni) is quite intuitive. Since release notes will

be having the required details about it's purpose and how it enables users to use existing applications on latest dpdk.

what exactly 'legacy' means, what has been changed, is the old one completely replaced/re-written ????, but whoever not following what is happening won't underase tand what is old in the KNI, digging through release notes and commits will give this information but it will be hard to get it from binary and get harder by a few releases passed.

Quoted 3 lines

Current EAL does set iova as va if bus iommu returns DC, meaning iova=va

is the kind of default mode(in most of use cases) and for running kni, we have to explicitly set the flag to run kni in iova=va mode all the time. I think having a flag for legacy usage(PA mode) is more appropriate than having kni- iova-va kind of flag.

It is about keeping the existing behavior same, right now if the kni module is inserted it will force the PA mode. With your update it will be possible to run iova=va with kni module inserted when flag is set. I suggest giving some time to this new behavior before making it default.

Quoted 2 lines

Otx2 net pmd that runs on Octeontx2 platforms only supports iova=va

mode, we would like to have KNI running by default without any flags passed.

Quoted 1 line
Quoted 5 lines

I see, but other way around will affect all existing KNI users, they will either need to add this flag or update their application.

This is new feature, who want to use it adding a specific flag makes more sense to me than all old users have to add the flag.

Ferruh suggested to have a flag for enabling these new feature and also not interested in having newer mempool alloc APIs for KNI(see V10 review comments). Before reworking on the flag changes, I would like check with you whether the same flag can be used in mempool lib for checking and fulfilling the mempool page boundary requirement (mempool patch v11 1/4), by doing so, it can avoid newer exported APIs both in mempool and KNI lib. Anyways, these mempool requirement can be addressed with Olivier's below patches.

http://patchwork.dpdk.org/project/dpdk/list/?series=5624

When those patches are merged, flag check can be removed.

Regards
A Vamsi

Quoted 107 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Monday, October 21, 2019 7:02 PM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [EXT] Re: [dpdk-dev] [PATCH v11 2/4] eal: add legacy kni option

Quoted 47 lines · Vamsi Krishna Attunuru
Quoted 47 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Monday, October 21, 2019 5:25 PM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [EXT] Re: [dpdk-dev] [PATCH v11 2/4] eal: add legacy kni option

External Email

-------------------------------------------------------------------
--

Quoted 7 lines · - On 10/21/2019 9:03 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

This adds a "--legacy-kni" command-line option. It will be used to run existing KNI applications with DPDK 19.11 and later.

<...>

lib/librte_eal/common/eal_options.h enum { · line 75

Quoted 13 lines
lib/librte_eal/common/eal_options.h +2 -0
index 9855429..1010ed3 100644
@@ -69,6 +69,8 @@ enum {
 	OPT_IOVA_MODE_NUM,
 #define OPT_MATCH_ALLOCATIONS  "match-allocations"
 	OPT_MATCH_ALLOCATIONS_NUM,
+#define OPT_LEGACY_KNI      "legacy-kni"
+	OPT_LEGACY_KNI_NUM,
 	OPT_LONG_MAX_NUM
 };

Two concerns,

1- "legacy-kni" doesn't have enough context

Quoted 7 lines
Quoted 7 lines

2- I prefer to keep existing behavior default, at least for a while, something like next LTS etc, meanwhile this patch can be around for a good time and can be good to switch.

Based on above to, what do you think to rename the option to 'kni-iova-va', if not set by default it will be "IOVA=PA", when set it will

enable "IOVA=VA"

Quoted 6 lines
Quoted 1 line

mode?

Hi Ferruh,

I think the new eal flag(legacy-kni) is quite intuitive. Since release notes will

be having the required details about it's purpose and how it enables users to use existing applications on latest dpdk.

what exactly 'legacy' means, what has been changed, is the old one completely replaced/re-written ????, but whoever not following what is happening won't underase tand what is old in the KNI, digging through release notes and commits will give this information but it will be hard to get it from binary and get harder by a few releases passed.

Quoted 3 lines

Current EAL does set iova as va if bus iommu returns DC, meaning iova=va

is the kind of default mode(in most of use cases) and for running kni, we have to explicitly set the flag to run kni in iova=va mode all the time. I think having a flag for legacy usage(PA mode) is more appropriate than having kni- iova-va kind of flag.

It is about keeping the existing behavior same, right now if the kni module is inserted it will force the PA mode. With your update it will be possible to run iova=va with kni module inserted when flag is set. I suggest giving some time to this new behavior before making it default.

Quoted 2 lines

Otx2 net pmd that runs on Octeontx2 platforms only supports iova=va

mode, we would like to have KNI running by default without any flags passed.

Quoted 1 line

I see, but other way around will affect all existing KNI users, they will either need to add this flag or update their application.

This is new feature, who want to use it adding a specific flag makes more sense to me than all old users have to add the flag.

#198 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

In reply to Vamsi Krishna Attunuru

Hi Vasmi,

Quoted 47 lines · Vamsi Krishna Attunuru

Hi Olivier, Andrew,

Quoted 45 lines
Quoted 6 lines
Quoted 6 lines

lib/librte_eal/common/eal_options.h enum { · line 75

Quoted 4 lines
lib/librte_eal/common/eal_options.h +2 -0
+#define OPT_LEGACY_KNI      "legacy-kni"
+	OPT_LEGACY_KNI_NUM,
  	OPT_LONG_MAX_NUM
  };

Two concerns,

Quoted 8 lines
Quoted 8 lines

1- "legacy-kni" doesn't have enough context

2- I prefer to keep existing behavior default, at least for a while, something like next LTS etc, meanwhile this patch can be around for a good time and can be good to switch.

Based on above to, what do you think to rename the option to 'kni-iova-va', if not set by default it will be "IOVA=PA", when set it will

enable "IOVA=VA"

Quoted 4 lines
Quoted 1 line

mode?

Hi Ferruh,

I think the new eal flag(legacy-kni) is quite intuitive. Since release notes will

be having the required details about it's purpose and how it enables users to use existing applications on latest dpdk.

what exactly 'legacy' means, what has been changed, is the old one completely replaced/re-written ????, but whoever not following what is happening won't underase tand what is old in the KNI, digging through release notes and commits will give this information but it will be hard to get it from binary and get harder by a few releases passed.

Quoted 1 line

Current EAL does set iova as va if bus iommu returns DC, meaning iova=va

is the kind of default mode(in most of use cases) and for running kni, we have to explicitly set the flag to run kni in iova=va mode all the time. I think having a flag for legacy usage(PA mode) is more appropriate than having kni- iova-va kind of flag.

It is about keeping the existing behavior same, right now if the kni module is inserted it will force the PA mode. With your update it will be possible to run iova=va with kni module inserted when flag is set. I suggest giving some time to this new behavior before making it default.

Quoted 1 line

Otx2 net pmd that runs on Octeontx2 platforms only supports iova=va

mode, we would like to have KNI running by default without any flags passed.
I see, but other way around will affect all existing KNI users, they will either need to add this flag or update their application.

Quoted 8 lines
Quoted 2 lines

This is new feature, who want to use it adding a specific flag makes more sense to me than all old users have to add the flag.

Ferruh suggested to have a flag for enabling these new feature and also not interested in having newer mempool alloc APIs for KNI(see V10 review comments). Before reworking on the flag changes, I would like check with you whether the same flag can be used in mempool lib for checking and fulfilling the mempool page boundary requirement (mempool patch v11 1/4), by doing so, it can avoid newer exported APIs both in mempool and KNI lib. Anyways, these mempool requirement can be addressed with Olivier's below patches.

http://patchwork.dpdk.org/project/dpdk/list/?series=5624

When those patches are merged, flag check can be removed.

It is really hard to follow, sorry.
Is it really a problem to have KNI switcher to enable new behaviour and document it that dedicated function should be used to allocate mbufs?

Andrew.

Quoted 101 lines

Regards
A Vamsi

Quoted 93 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Monday, October 21, 2019 7:02 PM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [EXT] Re: [dpdk-dev] [PATCH v11 2/4] eal: add legacy kni option

Quoted 41 lines · Vamsi Krishna Attunuru
Quoted 41 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Monday, October 21, 2019 5:25 PM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [EXT] Re: [dpdk-dev] [PATCH v11 2/4] eal: add legacy kni option

External Email

---------------------------------------------------------------------

Quoted 7 lines · - On 10/21/2019 9:03 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

This adds a "--legacy-kni" command-line option. It will be used to run existing KNI applications with DPDK 19.11 and later.

<...>

lib/librte_eal/common/eal_options.h enum { · line 75

Quoted 13 lines
lib/librte_eal/common/eal_options.h +2 -0
index 9855429..1010ed3 100644
@@ -69,6 +69,8 @@ enum {
  	OPT_IOVA_MODE_NUM,
  #define OPT_MATCH_ALLOCATIONS  "match-allocations"
  	OPT_MATCH_ALLOCATIONS_NUM,
+#define OPT_LEGACY_KNI      "legacy-kni"
+	OPT_LEGACY_KNI_NUM,
  	OPT_LONG_MAX_NUM
  };

Two concerns,

Quoted 8 lines
Quoted 8 lines

1- "legacy-kni" doesn't have enough context

2- I prefer to keep existing behavior default, at least for a while, something like next LTS etc, meanwhile this patch can be around for a good time and can be good to switch.

Based on above to, what do you think to rename the option to 'kni-iova-va', if not set by default it will be "IOVA=PA", when set it will

enable "IOVA=VA"

Quoted 4 lines
Quoted 1 line

mode?

Hi Ferruh,

I think the new eal flag(legacy-kni) is quite intuitive. Since release notes will

be having the required details about it's purpose and how it enables users to use existing applications on latest dpdk.

what exactly 'legacy' means, what has been changed, is the old one completely replaced/re-written ????, but whoever not following what is happening won't underase tand what is old in the KNI, digging through release notes and commits will give this information but it will be hard to get it from binary and get harder by a few releases passed.

Quoted 1 line

Current EAL does set iova as va if bus iommu returns DC, meaning iova=va

is the kind of default mode(in most of use cases) and for running kni, we have to explicitly set the flag to run kni in iova=va mode all the time. I think having a flag for legacy usage(PA mode) is more appropriate than having kni- iova-va kind of flag.

It is about keeping the existing behavior same, right now if the kni module is inserted it will force the PA mode. With your update it will be possible to run iova=va with kni module inserted when flag is set. I suggest giving some time to this new behavior before making it default.

Quoted 1 line

Otx2 net pmd that runs on Octeontx2 platforms only supports iova=va

mode, we would like to have KNI running by default without any flags passed.
I see, but other way around will affect all existing KNI users, they will either need to add this flag or update their application.

This is new feature, who want to use it adding a specific flag makes more sense to me than all old users have to add the flag.

#199 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Hi Ferruh,

Can you please explain the problems in using kni dedicated mbuf alloc routines while enabling kni iova=va mode. Please see the below discussion with Andrew. He wanted to know the problems in having newer APIs.

I wanted to clarify ourselves about the need of mem pool patch(V11 1/4) and where to fit the fix(newer APIs or fix in mempool lib) before I start reworking the patches.

Regards
A Vamsi

Quoted 31 lines

snipped

Quoted 5 lines
Quoted 3 lines

This is new feature, who want to use it adding a specific flag makes more sense to me than all old users have to add the flag.

Ferruh suggested to have a flag for enabling these new feature and also not

interested in having newer mempool alloc APIs for KNI(see V10 review comments). Before reworking on the flag changes, I would like check with you whether the same flag can be used in mempool lib for checking and fulfilling the mempool page boundary requirement (mempool patch v11 1/4), by doing so, it can avoid newer exported APIs both in mempool and KNI lib. Anyways, these mempool requirement can be addressed with Olivier's below patches.

Quoted 3 lines

https://urldefense.proofpoint.com/v2/url?u=http-3A__patchwork.dpdk.org
_project_dpdk_list_-3Fseries-

3D5624&d=DwICaQ&c=nKjWec2b6R0mOyPaz7xtfQ&

Quoted 1 line

r=WllrYaumVkxaWjgKto6E_rtDQshhIhik2jkvzFyRhW8&m=tCO-

8E27vdyIVMm_35Qv6K

Quoted 1 line

-OwGCIobWI0H9DGGBm-gc&s=9aLHS9Og5L0uhuLGFAuQ9NAT3-

hlFmtc9RrrSbLQC00&e=

Quoted 2 lines

When those patches are merged, flag check can be removed.

It is really hard to follow, sorry.
Is it really a problem to have KNI switcher to enable new behaviour and document it that dedicated function should be used to allocate mbufs?

Andrew.

Quoted 2 lines

Regards
A Vamsi

#200 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Quoted 4 lines · Vamsi Krishna Attunuru

Hi Ferruh,

Can you please explain the problems in using kni dedicated mbuf alloc routines while enabling kni iova=va mode. Please see the below discussion with Andrew. He wanted to know the problems in having newer APIs.

While waiting for the Ferruh reply, I would like to summarise the current status

# In order to make KNI work with IOVA as VA, We need to make sure mempool pool _object_ should not span across two huge pages

# This problem can be fixed by, either of:

a) Introduce a flag in mempool to define this constraint, so that, when only needed, this constraint enforced and this is in line with existing semantics of addressing such problems in mempool

b) Instead of creating a flag, Make this behavior by default in mempool for IOVA as VA case

Upside:
b1) There is no need for specific mempool_create for KNI.

Downside:
b2) Not align with existing mempool API semantics
b3) There will be a trivial amount of memory waste as we can not allocate from the edge. Considering the normal huge page memory size is 1G or 512MB this not a real issue.

c) Make IOVA as PA when KNI kernel module is loaded

Upside:
c1) Doing option (a) would call for new KNI specific mempool create API i.e existing KNI applications need a one-line change in application to make it work with release 19.11 or later.

Downslide:
c2) Driver which needs RTE_PCI_DRV_NEED_IOVA_AS_VA can not work with KNI c3) Need root privilege to run KNI as IOVA as PA need root privilege

For the next year, we expect applications to work 19.11 without any code change. My personal opinion to make go with option (a) and update the release notes to document the change any it simple one-line change.

The selection of (a) vs (b) is between KNI and Mempool maintainers. Could we please reach a consensus? Or can we discuss this TB meeting?

We are going back and forth on this feature on for the last 3 releases. Now that, we solved all the technical problems, please help us
to decide (a) vs (b) to make forward progress.

Quoted 37 lines

I wanted to clarify ourselves about the need of mem pool patch(V11 1/4) and where to fit the fix(newer APIs or fix in mempool lib) before I start reworking the patches.

Regards
A Vamsi

Quoted 31 lines

snipped

Quoted 5 lines
Quoted 3 lines

This is new feature, who want to use it adding a specific flag makes more sense to me than all old users have to add the flag.

Ferruh suggested to have a flag for enabling these new feature and also not

interested in having newer mempool alloc APIs for KNI(see V10 review comments). Before reworking on the flag changes, I would like check with you whether the same flag can be used in mempool lib for checking and fulfilling the mempool page boundary requirement (mempool patch v11 1/4), by doing so, it can avoid newer exported APIs both in mempool and KNI lib. Anyways, these mempool requirement can be addressed with Olivier's below patches.

Quoted 3 lines

https://urldefense.proofpoint.com/v2/url?u=http-3A__patchwork.dpdk.org
_project_dpdk_list_-3Fseries-

3D5624&d=DwICaQ&c=nKjWec2b6R0mOyPaz7xtfQ&

Quoted 1 line

r=WllrYaumVkxaWjgKto6E_rtDQshhIhik2jkvzFyRhW8&m=tCO-

8E27vdyIVMm_35Qv6K

Quoted 1 line

-OwGCIobWI0H9DGGBm-gc&s=9aLHS9Og5L0uhuLGFAuQ9NAT3-

hlFmtc9RrrSbLQC00&e=

Quoted 2 lines

When those patches are merged, flag check can be removed.

It is really hard to follow, sorry.
Is it really a problem to have KNI switcher to enable new behaviour and document it that dedicated function should be used to allocate mbufs?

Andrew.

Quoted 2 lines

Regards
A Vamsi

#201 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Hi,

Quoted 48 lines · Jerin Jacob
Quoted 4 lines · Vamsi Krishna Attunuru

Hi Ferruh,

Can you please explain the problems in using kni dedicated mbuf alloc routines while enabling kni iova=va mode. Please see the below discussion with Andrew. He wanted to know the problems in having newer APIs.

While waiting for the Ferruh reply, I would like to summarise the current status

# In order to make KNI work with IOVA as VA, We need to make sure mempool pool _object_ should not span across two huge pages

# This problem can be fixed by, either of:

a) Introduce a flag in mempool to define this constraint, so that, when only needed, this constraint enforced and this is in line with existing semantics of addressing such problems in mempool

b) Instead of creating a flag, Make this behavior by default in mempool for IOVA as VA case

Upside:
b1) There is no need for specific mempool_create for KNI.

Downside:
b2) Not align with existing mempool API semantics
b3) There will be a trivial amount of memory waste as we can not allocate from the edge. Considering the normal huge page memory size is 1G or 512MB this not a real issue.

c) Make IOVA as PA when KNI kernel module is loaded

Upside:
c1) Doing option (a) would call for new KNI specific mempool create API i.e existing KNI applications need a one-line change in application to make it work with release 19.11 or later.

Downslide:
c2) Driver which needs RTE_PCI_DRV_NEED_IOVA_AS_VA can not work with KNI c3) Need root privilege to run KNI as IOVA as PA need root privilege

For the next year, we expect applications to work 19.11 without any code change. My personal opinion to make go with option (a) and update the release notes to document the change any it simple one-line change.

Quoted 7 lines

The selection of (a) vs (b) is between KNI and Mempool maintainers. Could we please reach a consensus? Or can we discuss this TB meeting?

We are going back and forth on this feature on for the last 3 releases. Now that, we solved all the technical problems, please help us
to decide (a) vs (b) to make forward progress.

Thank you for the summary.
What is not clear to me is if (a) or (b) may break an existing application, and if yes, in which case.

#202 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Quoted 55 lines · Olivier Matz

Hi,

Quoted 51 lines · Jerin Jacob
Quoted 4 lines · Vamsi Krishna Attunuru

Hi Ferruh,

Can you please explain the problems in using kni dedicated mbuf alloc routines while enabling kni iova=va mode. Please see the below discussion with Andrew. He wanted to know the problems in having newer APIs.

While waiting for the Ferruh reply, I would like to summarise the current status

# In order to make KNI work with IOVA as VA, We need to make sure mempool pool _object_ should not span across two huge pages

# This problem can be fixed by, either of:

a) Introduce a flag in mempool to define this constraint, so that, when only needed, this constraint enforced and this is in line with existing semantics of addressing such problems in mempool

b) Instead of creating a flag, Make this behavior by default in mempool for IOVA as VA case

Upside:
b1) There is no need for specific mempool_create for KNI.

Downside:
b2) Not align with existing mempool API semantics
b3) There will be a trivial amount of memory waste as we can not allocate from the edge. Considering the normal huge page memory size is 1G or 512MB this not a real issue.

c) Make IOVA as PA when KNI kernel module is loaded

Upside:
c1) Doing option (a) would call for new KNI specific mempool create API i.e existing KNI applications need a one-line change in application to make it work with release 19.11 or later.

Downslide:
c2) Driver which needs RTE_PCI_DRV_NEED_IOVA_AS_VA can not work with KNI c3) Need root privilege to run KNI as IOVA as PA need root privilege

For the next year, we expect applications to work 19.11 without any code change. My personal opinion to make go with option (a) and update the release notes to document the change any it simple one-line change.

The selection of (a) vs (b) is between KNI and Mempool maintainers. Could we please reach a consensus? Or can we discuss this TB meeting?

Quoted 8 lines
Quoted 4 lines

We are going back and forth on this feature on for the last 3 releases. Now that, we solved all the technical problems, please help us
to decide (a) vs (b) to make forward progress.

Thank you for the summary.
What is not clear to me is if (a) or (b) may break an existing application, and if yes, in which case.

Thanks for the reply.

To be clear we are talking about out of tree KNI tree application. Which they don't want to
change rte_pktmbuf_pool_create() to rte_kni_pktmbuf_pool_create() and build for v19.11

So in case (b) there is no issue as It will be using rte_pktmbuf_pool_create (). But in case of (a) it will create an issue if out of tree KNI application is using rte_pktmbuf_pool_create() which is not using the NEW flag.

#203 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Hi,

Quoted 72 lines · Jerin Jacob
Quoted 55 lines · Olivier Matz

Hi,

Quoted 51 lines · Jerin Jacob
Quoted 4 lines · Vamsi Krishna Attunuru

Hi Ferruh,

Can you please explain the problems in using kni dedicated mbuf alloc routines while enabling kni iova=va mode. Please see the below discussion with Andrew. He wanted to know the problems in having newer APIs.

While waiting for the Ferruh reply, I would like to summarise the current status

# In order to make KNI work with IOVA as VA, We need to make sure mempool pool _object_ should not span across two huge pages

# This problem can be fixed by, either of:

a) Introduce a flag in mempool to define this constraint, so that, when only needed, this constraint enforced and this is in line with existing semantics of addressing such problems in mempool

b) Instead of creating a flag, Make this behavior by default in mempool for IOVA as VA case

Upside:
b1) There is no need for specific mempool_create for KNI.

Downside:
b2) Not align with existing mempool API semantics
b3) There will be a trivial amount of memory waste as we can not allocate from the edge. Considering the normal huge page memory size is 1G or 512MB this not a real issue.

c) Make IOVA as PA when KNI kernel module is loaded

Upside:
c1) Doing option (a) would call for new KNI specific mempool create API i.e existing KNI applications need a one-line change in application to make it work with release 19.11 or later.

Downslide:
c2) Driver which needs RTE_PCI_DRV_NEED_IOVA_AS_VA can not work with KNI c3) Need root privilege to run KNI as IOVA as PA need root privilege

For the next year, we expect applications to work 19.11 without any code change. My personal opinion to make go with option (a) and update the release notes to document the change any it simple one-line change.

The selection of (a) vs (b) is between KNI and Mempool maintainers. Could we please reach a consensus? Or can we discuss this TB meeting?

Quoted 8 lines
Quoted 4 lines

We are going back and forth on this feature on for the last 3 releases. Now that, we solved all the technical problems, please help us
to decide (a) vs (b) to make forward progress.

Thank you for the summary.
What is not clear to me is if (a) or (b) may break an existing application, and if yes, in which case.

Thanks for the reply.

To be clear we are talking about out of tree KNI tree application. Which they don't want to
change rte_pktmbuf_pool_create() to rte_kni_pktmbuf_pool_create() and build for v19.11

Quoted 4 lines

So in case (b) there is no issue as It will be using rte_pktmbuf_pool_create (). But in case of (a) it will create an issue if out of tree KNI application is using rte_pktmbuf_pool_create() which is not using the NEW flag.

Following yesterday's discussion at techboard, I looked at the mempool code and at my previous RFC patch. It took some time to remind me what was my worries.

Currently, in rte_mempool_populate_default(), when the mempool is populated, we first try to allocate one iova-contiguous block of (n * elt_size). On success, we use this memory to fully populate the mempool without taking care of crossing page boundaries.

If we change the behavior to prevent objects from crossing pages, the assumption that allocating (n * elt_size) is always enough becomes wrong. By luck, there is no real impact, because if the mempool is not fully populated after this first iteration, it will allocate a new chunk.

To be rigorous, we need to better calculate the amount of memory to allocate, according to page size.

Looking at the code, I found another problem in the same area: let's say we populate a mempool that requires 1.1GB (and we use 1G huge pages):

1/ mempool code will first tries to allocate an iova-contiguous zone
of 1.1G -> fail
2/ it then tries to allocate a page-aligned non iova-contiguous
zone of 1.1G, which is 2G. On success, a lot of memory is wasted.
3/ on error, we try to allocate the biggest zone, it can still return
a zone between 1.1G and 2G, which can also waste memory.

I will rework my mempool patchset to properly address these issues, hopefully tomorrow.

Also, I thought about another idea to solve your issue, not sure it is better but it would not imply to change the mempool behavior. If I understood the problem, when a mbuf is accross 2 pages, the copy of the data can fail in kni because the mbuf is not virtually contiguous in the kernel. So why not in this case splitting the memcpy() into several, each of them being on a single page (and calling phys2virt() for each page)? The same would have to be done when accessing the fields of the mbuf structure if it crosses a page boundary. Would that work? This could be a B plan.

Olivier

#204 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Quoted 76 lines · Olivier Matz

Hi,

Quoted 72 lines · Jerin Jacob
Quoted 55 lines · Olivier Matz

Hi,

Quoted 51 lines · Jerin Jacob
Quoted 4 lines · Vamsi Krishna Attunuru

Hi Ferruh,

Can you please explain the problems in using kni dedicated mbuf alloc routines while enabling kni iova=va mode. Please see the below discussion with Andrew. He wanted to know the problems in having newer APIs.

While waiting for the Ferruh reply, I would like to summarise the current status

# In order to make KNI work with IOVA as VA, We need to make sure mempool pool _object_ should not span across two huge pages

# This problem can be fixed by, either of:

a) Introduce a flag in mempool to define this constraint, so that, when only needed, this constraint enforced and this is in line with existing semantics of addressing such problems in mempool

b) Instead of creating a flag, Make this behavior by default in mempool for IOVA as VA case

Upside:
b1) There is no need for specific mempool_create for KNI.

Downside:
b2) Not align with existing mempool API semantics
b3) There will be a trivial amount of memory waste as we can not allocate from the edge. Considering the normal huge page memory size is 1G or 512MB this not a real issue.

c) Make IOVA as PA when KNI kernel module is loaded

Upside:
c1) Doing option (a) would call for new KNI specific mempool create API i.e existing KNI applications need a one-line change in application to make it work with release 19.11 or later.

Downslide:
c2) Driver which needs RTE_PCI_DRV_NEED_IOVA_AS_VA can not work with KNI c3) Need root privilege to run KNI as IOVA as PA need root privilege

For the next year, we expect applications to work 19.11 without any code change. My personal opinion to make go with option (a) and update the release notes to document the change any it simple one-line change.

The selection of (a) vs (b) is between KNI and Mempool maintainers. Could we please reach a consensus? Or can we discuss this TB meeting?

Quoted 8 lines
Quoted 4 lines

We are going back and forth on this feature on for the last 3 releases. Now that, we solved all the technical problems, please help us
to decide (a) vs (b) to make forward progress.

Thank you for the summary.
What is not clear to me is if (a) or (b) may break an existing application, and if yes, in which case.

Thanks for the reply.

To be clear we are talking about out of tree KNI tree application. Which they don't want to
change rte_pktmbuf_pool_create() to rte_kni_pktmbuf_pool_create() and build for v19.11

Quoted 8 lines
Quoted 4 lines

So in case (b) there is no issue as It will be using rte_pktmbuf_pool_create (). But in case of (a) it will create an issue if out of tree KNI application is using rte_pktmbuf_pool_create() which is not using the NEW flag.

Following yesterday's discussion at techboard, I looked at the mempool code and at my previous RFC patch. It took some time to remind me what was my worries.

Thanks for the review Olivier.

Just to make sure the correct one is reviewed.

1) v7 had similar issue mentioned
http://patches.dpdk.org/patch/56585/

2) v11 addressed the review comments and you have given the Acked-by for mempool change
http://patches.dpdk.org/patch/61559/

My thought process in the TB meeting was, since rte_mempool_populate_from_pg_sz_chunks() reviwed
replace rte_pktmbuf_pool_create's rte_mempool_populate_default() with rte_mempool_populate_from_pg_sz_chunks()
in IOVA == VA case to avoid a new KNI mempool_create API.

Quoted 25 lines

Currently, in rte_mempool_populate_default(), when the mempool is populated, we first try to allocate one iova-contiguous block of (n * elt_size). On success, we use this memory to fully populate the mempool without taking care of crossing page boundaries.

If we change the behavior to prevent objects from crossing pages, the assumption that allocating (n * elt_size) is always enough becomes wrong. By luck, there is no real impact, because if the mempool is not fully populated after this first iteration, it will allocate a new chunk.

To be rigorous, we need to better calculate the amount of memory to allocate, according to page size.

Looking at the code, I found another problem in the same area: let's say we populate a mempool that requires 1.1GB (and we use 1G huge pages):

1/ mempool code will first tries to allocate an iova-contiguous zone
of 1.1G -> fail
2/ it then tries to allocate a page-aligned non iova-contiguous
zone of 1.1G, which is 2G. On success, a lot of memory is wasted.
3/ on error, we try to allocate the biggest zone, it can still return
a zone between 1.1G and 2G, which can also waste memory.

Quoted 2 lines

I will rework my mempool patchset to properly address these issues, hopefully tomorrow.

OK.

Quoted 5 lines

Also, I thought about another idea to solve your issue, not sure it is better but it would not imply to change the mempool behavior. If I understood the problem, when a mbuf is accross 2 pages, the copy of the data can fail in kni because the mbuf is not virtually contiguous in the

For KNI use case, we would need _physically_ contiguous to make sure that using, get_user_pages_remote() we get physically contiguous memory map, so that both KNI kernel thread and KNI kernel context and DPDK userspace can use the same memory in different contexts.

Quoted 4 lines

kernel. So why not in this case splitting the memcpy() into several, each of them being on a single page (and calling phys2virt() for each page)? The same would have to be done when accessing the fields of the mbuf structure if it crosses a page boundary. Would that work? This

If the above is the requirement, Does this logic need to be in slow path or fast path?

Quoted 1 line

could be a B plan.

OK.

Quoted 2 lines

Olivier

#205 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Quoted 123 lines

-----Original Message-----
From: Jerin Jacob <[email protected]>
Sent: Friday, October 25, 2019 1:01 AM
To: Olivier Matz <[email protected]>
Cc: Vamsi Krishna Attunuru <[email protected]>; Andrew Rybchenko <[email protected]>; Ferruh Yigit <[email protected]>; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Quoted 5 lines · Olivier Matz

Hi,

Quoted 1 line · Jerin Jacob

On Wed, Oct 23, 2019 at 8:17 PM Olivier Matz <[email protected]>

Quoted 10 lines · wrote:
Quoted 10 lines
Quoted 10 lines

Hi,

Quoted 6 lines · Jerin Jacob
Quoted 4 lines · Vamsi Krishna Attunuru

Hi Ferruh,

Can you please explain the problems in using kni dedicated mbuf alloc

routines while enabling kni iova=va mode. Please see the below discussion with Andrew. He wanted to know the problems in having newer APIs.

Quoted 63 lines
Quoted 63 lines
Quoted 48 lines
Quoted 48 lines

While waiting for the Ferruh reply, I would like to summarise the current status

# In order to make KNI work with IOVA as VA, We need to make sure mempool pool _object_ should not span across two huge pages

# This problem can be fixed by, either of:

a) Introduce a flag in mempool to define this constraint, so that, when only needed, this constraint enforced and this is in line with existing semantics of addressing such problems in mempool

b) Instead of creating a flag, Make this behavior by default in mempool for IOVA as VA case

Upside:
b1) There is no need for specific mempool_create for KNI.

Downside:
b2) Not align with existing mempool API semantics
b3) There will be a trivial amount of memory waste as we can not allocate from the edge. Considering the normal huge page memory size is 1G or 512MB this not a real issue.

c) Make IOVA as PA when KNI kernel module is loaded

Upside:
c1) Doing option (a) would call for new KNI specific mempool create API i.e existing KNI applications need a one-line change in application to make it work with release 19.11 or later.

Downslide:
c2) Driver which needs RTE_PCI_DRV_NEED_IOVA_AS_VA can not work with KNI
c3) Need root privilege to run KNI as IOVA as PA need root privilege

For the next year, we expect applications to work 19.11 without any code change. My personal opinion to make go with option (a) and update the release notes to document the change any it simple one-line change.

The selection of (a) vs (b) is between KNI and Mempool maintainers. Could we please reach a consensus? Or can we discuss this TB meeting?

Quoted 7 lines
Quoted 3 lines

We are going back and forth on this feature on for the last 3 releases. Now that, we solved all the technical problems, please help us to decide (a) vs (b) to make forward progress.

Thank you for the summary.
What is not clear to me is if (a) or (b) may break an existing application, and if yes, in which case.

Thanks for the reply.

To be clear we are talking about out of tree KNI tree application. Which they don't want to
change rte_pktmbuf_pool_create() to rte_kni_pktmbuf_pool_create() and build for v19.11

Quoted 8 lines
Quoted 4 lines

So in case (b) there is no issue as It will be using rte_pktmbuf_pool_create (). But in case of (a) it will create an issue if out of tree KNI application is using rte_pktmbuf_pool_create() which is not using the NEW flag.

Following yesterday's discussion at techboard, I looked at the mempool code and at my previous RFC patch. It took some time to remind me what was my worries.

Thanks for the review Olivier.

Just to make sure the correct one is reviewed.

1) v7 had similar issue mentioned
https://urldefense.proofpoint.com/v2/url?u=http-
3A__patches.dpdk.org_patch_56585_&d=DwIBaQ&c=nKjWec2b6R0mOyPaz7xtf Q&r=WllrYaumVkxaWjgKto6E_rtDQshhIhik2jkvzFyRhW8&m=MMwAZe76YMVHe 8UcHjL4IBnfX5YvtbocwICAZGBY97A&s=mfN_afnyFm65sQYzaAg_- uM9o22A5j392TdBZY-bKK4&e=

2) v11 addressed the review comments and you have given the Acked-by for mempool change https://urldefense.proofpoint.com/v2/url?u=http-
3A__patches.dpdk.org_patch_61559_&d=DwIBaQ&c=nKjWec2b6R0mOyPaz7xtf Q&r=WllrYaumVkxaWjgKto6E_rtDQshhIhik2jkvzFyRhW8&m=MMwAZe76YMVHe 8UcHjL4IBnfX5YvtbocwICAZGBY97A&s=frFvKOHFDRhTam6jDZZc6omK2gb1RU62 xzAiiBMnf0I&e=

Quoted 20 lines

My thought process in the TB meeting was, since rte_mempool_populate_from_pg_sz_chunks() reviwed replace rte_pktmbuf_pool_create's rte_mempool_populate_default() with rte_mempool_populate_from_pg_sz_chunks()
in IOVA == VA case to avoid a new KNI mempool_create API.

Quoted 14 lines

Currently, in rte_mempool_populate_default(), when the mempool is populated, we first try to allocate one iova-contiguous block of (n * elt_size). On success, we use this memory to fully populate the mempool without taking care of crossing page boundaries.

If we change the behavior to prevent objects from crossing pages, the assumption that allocating (n * elt_size) is always enough becomes wrong. By luck, there is no real impact, because if the mempool is not fully populated after this first iteration, it will allocate a new chunk.

To be rigorous, we need to better calculate the amount of memory to allocate, according to page size.

Hi Olivier,

Thanks for the review, I think the below mentioned problems exist with current mempool_populate_default() api and will there be high chances of hitting those problems when we precalculate the memory size(after preventing objs from pg boundary and fit complete mempool memory in single mem chunk) and if mempool size goes beyond page size as below example. ?,

Regards,
Vamsi

Quoted 45 lines
Quoted 11 lines

Looking at the code, I found another problem in the same area: let's say we populate a mempool that requires 1.1GB (and we use 1G huge pages):

1/ mempool code will first tries to allocate an iova-contiguous zone
of 1.1G -> fail
2/ it then tries to allocate a page-aligned non iova-contiguous
zone of 1.1G, which is 2G. On success, a lot of memory is wasted.
3/ on error, we try to allocate the biggest zone, it can still return
a zone between 1.1G and 2G, which can also waste memory.

Quoted 2 lines

I will rework my mempool patchset to properly address these issues, hopefully tomorrow.

OK.

Quoted 6 lines

Also, I thought about another idea to solve your issue, not sure it is better but it would not imply to change the mempool behavior. If I understood the problem, when a mbuf is accross 2 pages, the copy of the data can fail in kni because the mbuf is not virtually contiguous in the

For KNI use case, we would need _physically_ contiguous to make sure that using, get_user_pages_remote() we get physically contiguous memory map, so that both KNI kernel thread and KNI kernel context and DPDK userspace can use the same memory in different contexts.

Quoted 4 lines

kernel. So why not in this case splitting the memcpy() into several, each of them being on a single page (and calling phys2virt() for each page)? The same would have to be done when accessing the fields of the mbuf structure if it crosses a page boundary. Would that work? This

If the above is the requirement, Does this logic need to be in slow path or fast path?

Quoted 1 line

could be a B plan.

OK.

Quoted 2 lines

Olivier

#206 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Hi Jerin, Hi Vamsi,

Quoted 107 lines · Vamsi Krishna Attunuru
Quoted 107 lines

-----Original Message-----
From: Jerin Jacob <[email protected]>
Sent: Friday, October 25, 2019 1:01 AM
To: Olivier Matz <[email protected]>
Cc: Vamsi Krishna Attunuru <[email protected]>; Andrew Rybchenko <[email protected]>; Ferruh Yigit <[email protected]>; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Quoted 5 lines · Olivier Matz

Hi,

Quoted 1 line · Jerin Jacob

On Wed, Oct 23, 2019 at 8:17 PM Olivier Matz <[email protected]>

Quoted 10 lines · wrote:
Quoted 10 lines
Quoted 10 lines

Hi,

Quoted 6 lines · Jerin Jacob
Quoted 4 lines · Vamsi Krishna Attunuru

Hi Ferruh,

Can you please explain the problems in using kni dedicated mbuf alloc

routines while enabling kni iova=va mode. Please see the below discussion with Andrew. He wanted to know the problems in having newer APIs.

Quoted 63 lines
Quoted 63 lines
Quoted 48 lines
Quoted 48 lines

While waiting for the Ferruh reply, I would like to summarise the current status

# In order to make KNI work with IOVA as VA, We need to make sure mempool pool _object_ should not span across two huge pages

# This problem can be fixed by, either of:

a) Introduce a flag in mempool to define this constraint, so that, when only needed, this constraint enforced and this is in line with existing semantics of addressing such problems in mempool

b) Instead of creating a flag, Make this behavior by default in mempool for IOVA as VA case

Upside:
b1) There is no need for specific mempool_create for KNI.

Downside:
b2) Not align with existing mempool API semantics
b3) There will be a trivial amount of memory waste as we can not allocate from the edge. Considering the normal huge page memory size is 1G or 512MB this not a real issue.

c) Make IOVA as PA when KNI kernel module is loaded

Upside:
c1) Doing option (a) would call for new KNI specific mempool create API i.e existing KNI applications need a one-line change in application to make it work with release 19.11 or later.

Downslide:
c2) Driver which needs RTE_PCI_DRV_NEED_IOVA_AS_VA can not work with KNI
c3) Need root privilege to run KNI as IOVA as PA need root privilege

For the next year, we expect applications to work 19.11 without any code change. My personal opinion to make go with option (a) and update the release notes to document the change any it simple one-line change.

The selection of (a) vs (b) is between KNI and Mempool maintainers. Could we please reach a consensus? Or can we discuss this TB meeting?

Quoted 7 lines
Quoted 3 lines

We are going back and forth on this feature on for the last 3 releases. Now that, we solved all the technical problems, please help us to decide (a) vs (b) to make forward progress.

Thank you for the summary.
What is not clear to me is if (a) or (b) may break an existing application, and if yes, in which case.

Thanks for the reply.

To be clear we are talking about out of tree KNI tree application. Which they don't want to
change rte_pktmbuf_pool_create() to rte_kni_pktmbuf_pool_create() and build for v19.11

Quoted 8 lines
Quoted 4 lines

So in case (b) there is no issue as It will be using rte_pktmbuf_pool_create (). But in case of (a) it will create an issue if out of tree KNI application is using rte_pktmbuf_pool_create() which is not using the NEW flag.

Following yesterday's discussion at techboard, I looked at the mempool code and at my previous RFC patch. It took some time to remind me what was my worries.

Thanks for the review Olivier.

Quoted 8 lines
Quoted 8 lines

Just to make sure the correct one is reviewed.

1) v7 had similar issue mentioned
https://urldefense.proofpoint.com/v2/url?u=http-
3A__patches.dpdk.org_patch_56585_&d=DwIBaQ&c=nKjWec2b6R0mOyPaz7xtf Q&r=WllrYaumVkxaWjgKto6E_rtDQshhIhik2jkvzFyRhW8&m=MMwAZe76YMVHe 8UcHjL4IBnfX5YvtbocwICAZGBY97A&s=mfN_afnyFm65sQYzaAg_- uM9o22A5j392TdBZY-bKK4&e=

The v7 has the problem I described below: the iova-contiguous allocation may fail because the calculated size is too small, and remaining objects will be added in another chunk. This can happen if a fully iova-contiguous mempool is requested (it happens for octeontx).

Also, the way page size is retrieved in rte_mempool_op_populate_default() assume that memzones are used, which is not correct.

Quoted 6 lines
Quoted 6 lines

2) v11 addressed the review comments and you have given the Acked-by for mempool change https://urldefense.proofpoint.com/v2/url?u=http-
3A__patches.dpdk.org_patch_61559_&d=DwIBaQ&c=nKjWec2b6R0mOyPaz7xtf Q&r=WllrYaumVkxaWjgKto6E_rtDQshhIhik2jkvzFyRhW8&m=MMwAZe76YMVHe 8UcHjL4IBnfX5YvtbocwICAZGBY97A&s=frFvKOHFDRhTam6jDZZc6omK2gb1RU62 xzAiiBMnf0I&e=

The v11 looked fine to me, because it does not impact any default behavior, and the plan was to remove this new function when my mempool patchset was in.

Quoted 22 lines
Quoted 21 lines

My thought process in the TB meeting was, since rte_mempool_populate_from_pg_sz_chunks() reviwed replace rte_pktmbuf_pool_create's rte_mempool_populate_default() with rte_mempool_populate_from_pg_sz_chunks()
in IOVA == VA case to avoid a new KNI mempool_create API.

Quoted 14 lines

Currently, in rte_mempool_populate_default(), when the mempool is populated, we first try to allocate one iova-contiguous block of (n * elt_size). On success, we use this memory to fully populate the mempool without taking care of crossing page boundaries.

If we change the behavior to prevent objects from crossing pages, the assumption that allocating (n * elt_size) is always enough becomes wrong. By luck, there is no real impact, because if the mempool is not fully populated after this first iteration, it will allocate a new chunk.

To be rigorous, we need to better calculate the amount of memory to allocate, according to page size.

Quoted 7 lines

Hi Olivier,

Thanks for the review, I think the below mentioned problems exist with current mempool_populate_default() api and will there be high chances of hitting those problems when we precalculate the memory size(after preventing objs from pg boundary and fit complete mempool memory in single mem chunk) and if mempool size goes beyond page size as below example. ?,

Yes, the problem described below (alloc a mempool of 1.1GB resulting in 2GB reserved) exists in the current version. It will be fixed in the new version of my "mempool: avoid objects allocations across pages" patchset.

FYI, a reworked patchset is alsmost ready, I'll send it monday.

Quoted 42 lines

Regards,
Vamsi

Quoted 38 lines
Quoted 11 lines

Looking at the code, I found another problem in the same area: let's say we populate a mempool that requires 1.1GB (and we use 1G huge pages):

1/ mempool code will first tries to allocate an iova-contiguous zone
of 1.1G -> fail
2/ it then tries to allocate a page-aligned non iova-contiguous
zone of 1.1G, which is 2G. On success, a lot of memory is wasted.
3/ on error, we try to allocate the biggest zone, it can still return
a zone between 1.1G and 2G, which can also waste memory.

Quoted 2 lines

I will rework my mempool patchset to properly address these issues, hopefully tomorrow.

OK.

Quoted 6 lines

Also, I thought about another idea to solve your issue, not sure it is better but it would not imply to change the mempool behavior. If I understood the problem, when a mbuf is accross 2 pages, the copy of the data can fail in kni because the mbuf is not virtually contiguous in the

For KNI use case, we would need _physically_ contiguous to make sure that using, get_user_pages_remote() we get physically contiguous memory map, so that both KNI kernel thread and KNI kernel context and DPDK userspace can use the same memory in different contexts.

Quoted 4 lines

kernel. So why not in this case splitting the memcpy() into several, each of them being on a single page (and calling phys2virt() for each page)? The same would have to be done when accessing the fields of the mbuf structure if it crosses a page boundary. Would that work? This

If the above is the requirement, Does this logic need to be in slow path or fast path?

In fast path. But I don't think the performance impact would be significative.

Vamsi, do you confirm this approach could also solve the issue without changing the mempool?

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

could be a B plan.

OK.

Quoted 2 lines

Olivier

#207 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Hi Olivier,

Quoted 203 lines

-----Original Message-----
From: Olivier Matz <[email protected]>
Sent: Saturday, October 26, 2019 5:55 PM
To: Vamsi Krishna Attunuru <[email protected]>
Cc: Jerin Jacob <[email protected]>; Andrew Rybchenko <[email protected]>; Ferruh Yigit <[email protected]>; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Hi Jerin, Hi Vamsi,

Quoted 7 lines · Vamsi Krishna Attunuru
Quoted 7 lines

-----Original Message-----
From: Jerin Jacob <[email protected]>
Sent: Friday, October 25, 2019 1:01 AM
To: Olivier Matz <[email protected]>
Cc: Vamsi Krishna Attunuru <[email protected]>; Andrew

Rybchenko

Quoted 4 lines
Quoted 4 lines

<[email protected]>; Ferruh Yigit <[email protected]>; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected];

[email protected]

Quoted 20 lines
Quoted 20 lines

Subject: Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Quoted 6 lines · Olivier Matz

Hi,

Quoted 2 lines · Jerin Jacob

On Wed, Oct 23, 2019 at 8:17 PM Olivier Matz
<[email protected]>

Quoted 7 lines · wrote:
Quoted 7 lines
Quoted 7 lines

Hi,

Quoted 3 lines · Jerin Jacob
Quoted 1 line · Vamsi Krishna Attunuru
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Hi Ferruh,

Can you please explain the problems in using kni dedicated mbuf alloc

routines while enabling kni iova=va mode. Please see the below discussion with Andrew. He wanted to know the problems in having

newer APIs.

Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines

While waiting for the Ferruh reply, I would like to summarise the current status

# In order to make KNI work with IOVA as VA, We need to make sure mempool pool _object_ should not span across two huge pages

# This problem can be fixed by, either of:

a) Introduce a flag in mempool to define this constraint, so that, when only needed, this constraint enforced and this is in line with existing semantics of addressing such problems in mempool

b) Instead of creating a flag, Make this behavior by default in mempool for IOVA as VA case

Upside:
b1) There is no need for specific mempool_create for KNI.

Downside:
b2) Not align with existing mempool API semantics b3) There will be a trivial amount of memory waste as we can not allocate from the edge. Considering the normal huge page memory size is 1G or 512MB this not a real issue.

c) Make IOVA as PA when KNI kernel module is loaded

Upside:
c1) Doing option (a) would call for new KNI specific mempool create API i.e existing KNI applications need a one-line change in application to make it work with release 19.11 or later.

Downslide:
c2) Driver which needs RTE_PCI_DRV_NEED_IOVA_AS_VA can not work with KNI
c3) Need root privilege to run KNI as IOVA as PA need root privilege

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

For the next year, we expect applications to work 19.11 without any code change. My personal opinion to make go with option (a) and update the release notes to document the change any it simple one-line change.

The selection of (a) vs (b) is between KNI and Mempool

maintainers.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Could we please reach a consensus? Or can we discuss this TB

meeting?

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines

We are going back and forth on this feature on for the last 3 releases. Now that, we solved all the technical problems, please help us to decide (a) vs (b) to make forward progress.

Thank you for the summary.
What is not clear to me is if (a) or (b) may break an existing application, and if yes, in which case.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Thanks for the reply.

To be clear we are talking about out of tree KNI tree application. Which they don't want to
change rte_pktmbuf_pool_create() to rte_kni_pktmbuf_pool_create() and build for v19.11

So in case (b) there is no issue as It will be using

rte_pktmbuf_pool_create ().

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

But in case of (a) it will create an issue if out of tree KNI application is using rte_pktmbuf_pool_create() which is not using the NEW flag.

Following yesterday's discussion at techboard, I looked at the mempool code and at my previous RFC patch. It took some time to remind me what was my worries.

Quoted 7 lines
Quoted 7 lines

Thanks for the review Olivier.

Just to make sure the correct one is reviewed.

1) v7 had similar issue mentioned
https://urldefense.proofpoint.com/v2/url?u=http-

3A__patches.dpdk.org_patch_56585_&d=DwIBaQ&c=nKjWec2b6R0mOyPaz7 xtf

Quoted 1 line
Quoted 1 line

Q&r=WllrYaumVkxaWjgKto6E_rtDQshhIhik2jkvzFyRhW8&m=MMwAZe76YM VHe

Quoted 2 lines
Quoted 2 lines

8UcHjL4IBnfX5YvtbocwICAZGBY97A&s=mfN_afnyFm65sQYzaAg_- uM9o22A5j392TdBZY-bKK4&e=

The v7 has the problem I described below: the iova-contiguous allocation may fail because the calculated size is too small, and remaining objects will be added in another chunk. This can happen if a fully iova-contiguous mempool is requested (it happens for octeontx).

Also, the way page size is retrieved in rte_mempool_op_populate_default() assume that memzones are used, which is not correct.

Quoted 3 lines
Quoted 3 lines

2) v11 addressed the review comments and you have given the Acked-by for mempool change https://urldefense.proofpoint.com/v2/url?u=http-

3A__patches.dpdk.org_patch_61559_&d=DwIBaQ&c=nKjWec2b6R0mOyPaz7 xtf

Quoted 1 line
Quoted 1 line

Q&r=WllrYaumVkxaWjgKto6E_rtDQshhIhik2jkvzFyRhW8&m=MMwAZe76YM VHe

Quoted 1 line
Quoted 1 line

8UcHjL4IBnfX5YvtbocwICAZGBY97A&s=frFvKOHFDRhTam6jDZZc6omK2gb1RU 62

Quoted 1 line
Quoted 1 line

xzAiiBMnf0I&e=

The v11 looked fine to me, because it does not impact any default behavior, and the plan was to remove this new function when my mempool patchset was in.

Quoted 22 lines
Quoted 21 lines

My thought process in the TB meeting was, since rte_mempool_populate_from_pg_sz_chunks() reviwed replace rte_pktmbuf_pool_create's rte_mempool_populate_default() with rte_mempool_populate_from_pg_sz_chunks()
in IOVA == VA case to avoid a new KNI mempool_create API.

Quoted 14 lines

Currently, in rte_mempool_populate_default(), when the mempool is populated, we first try to allocate one iova-contiguous block of (n * elt_size). On success, we use this memory to fully populate the mempool without taking care of crossing page boundaries.

If we change the behavior to prevent objects from crossing pages, the assumption that allocating (n * elt_size) is always enough becomes wrong. By luck, there is no real impact, because if the mempool is not fully populated after this first iteration, it will allocate a new chunk.

To be rigorous, we need to better calculate the amount of memory to allocate, according to page size.

Quoted 8 lines

Hi Olivier,

Thanks for the review, I think the below mentioned problems exist with current mempool_populate_default() api and will there be high chances of hitting those problems when we precalculate the memory size(after preventing objs from pg boundary and fit complete mempool memory in single mem chunk) and if mempool size goes beyond page size as below example. ?,

Quoted 6 lines

Yes, the problem described below (alloc a mempool of 1.1GB resulting in 2GB reserved) exists in the current version. It will be fixed in the new version of my "mempool: avoid objects allocations across pages"
patchset.

FYI, a reworked patchset is alsmost ready, I'll send it monday.

Thanks a lot Olivier.

Quoted 43 lines
Quoted 8 lines

Regards,
Vamsi

Quoted 3 lines
Quoted 3 lines

Looking at the code, I found another problem in the same area:
let's say we populate a mempool that requires 1.1GB (and we use 1G

huge pages):

Quoted 34 lines
Quoted 34 lines
Quoted 10 lines

1/ mempool code will first tries to allocate an iova-contiguous zone
of 1.1G -> fail
2/ it then tries to allocate a page-aligned non iova-contiguous
zone of 1.1G, which is 2G. On success, a lot of memory is wasted.
3/ on error, we try to allocate the biggest zone, it can still return
a zone between 1.1G and 2G, which can also waste memory.

I will rework my mempool patchset to properly address these issues, hopefully tomorrow.

OK.

Quoted 6 lines

Also, I thought about another idea to solve your issue, not sure it is better but it would not imply to change the mempool behavior. If I understood the problem, when a mbuf is accross 2 pages, the copy of the data can fail in kni because the mbuf is not virtually contiguous in the

For KNI use case, we would need _physically_ contiguous to make sure that using, get_user_pages_remote() we get physically contiguous memory map, so that both KNI kernel thread and KNI kernel context and DPDK userspace can use the same memory in different contexts.

Quoted 5 lines

kernel. So why not in this case splitting the memcpy() into several, each of them being on a single page (and calling phys2virt() for each page)? The same would have to be done when accessing the fields of the mbuf structure if it crosses a page boundary. Would that work? This

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

If the above is the requirement, Does this logic need to be in slow path or fast path?

In fast path. But I don't think the performance impact would be significative.

Vamsi, do you confirm this approach could also solve the issue without changing the mempool?

So far there is no performance impact observed when these feature(kni iova as va) is enabled with this patch set. Not sure of impact if when memcpy split and extra address translations are introduced, this approach might solve but I feel it's not a clearer way of solving the issue.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

could be a B plan.

OK.

Quoted 2 lines

Olivier

#208 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Quoted 260 lines · Vamsi Krishna Attunuru

Hi Olivier,

Quoted 203 lines

-----Original Message-----
From: Olivier Matz <[email protected]>
Sent: Saturday, October 26, 2019 5:55 PM
To: Vamsi Krishna Attunuru <[email protected]>
Cc: Jerin Jacob <[email protected]>; Andrew Rybchenko <[email protected]>; Ferruh Yigit <[email protected]>; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Hi Jerin, Hi Vamsi,

Quoted 7 lines · Vamsi Krishna Attunuru
Quoted 7 lines

-----Original Message-----
From: Jerin Jacob <[email protected]>
Sent: Friday, October 25, 2019 1:01 AM
To: Olivier Matz <[email protected]>
Cc: Vamsi Krishna Attunuru <[email protected]>; Andrew

Rybchenko

Quoted 4 lines
Quoted 4 lines

<[email protected]>; Ferruh Yigit <[email protected]>; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected];

[email protected]

Quoted 20 lines
Quoted 20 lines

Subject: Re: [dpdk-dev] [EXT] Re: [PATCH v11 2/4] eal: add legacy kni option

Quoted 6 lines · Olivier Matz

Hi,

Quoted 2 lines · Jerin Jacob

On Wed, Oct 23, 2019 at 8:17 PM Olivier Matz
<[email protected]>

Quoted 7 lines · wrote:
Quoted 7 lines
Quoted 7 lines

Hi,

Quoted 3 lines · Jerin Jacob
Quoted 1 line · Vamsi Krishna Attunuru
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Hi Ferruh,

Can you please explain the problems in using kni dedicated mbuf alloc

routines while enabling kni iova=va mode. Please see the below discussion with Andrew. He wanted to know the problems in having

newer APIs.

Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines

While waiting for the Ferruh reply, I would like to summarise the current status

# In order to make KNI work with IOVA as VA, We need to make sure mempool pool _object_ should not span across two huge pages

# This problem can be fixed by, either of:

a) Introduce a flag in mempool to define this constraint, so that, when only needed, this constraint enforced and this is in line with existing semantics of addressing such problems in mempool

b) Instead of creating a flag, Make this behavior by default in mempool for IOVA as VA case

Upside:
b1) There is no need for specific mempool_create for KNI.

Downside:
b2) Not align with existing mempool API semantics b3) There will be a trivial amount of memory waste as we can not allocate from the edge. Considering the normal huge page memory size is 1G or 512MB this not a real issue.

c) Make IOVA as PA when KNI kernel module is loaded

Upside:
c1) Doing option (a) would call for new KNI specific mempool create API i.e existing KNI applications need a one-line change in application to make it work with release 19.11 or later.

Downslide:
c2) Driver which needs RTE_PCI_DRV_NEED_IOVA_AS_VA can not work with KNI
c3) Need root privilege to run KNI as IOVA as PA need root privilege

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

For the next year, we expect applications to work 19.11 without any code change. My personal opinion to make go with option (a) and update the release notes to document the change any it simple one-line change.

The selection of (a) vs (b) is between KNI and Mempool

maintainers.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Could we please reach a consensus? Or can we discuss this TB

meeting?

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines

We are going back and forth on this feature on for the last 3 releases. Now that, we solved all the technical problems, please help us to decide (a) vs (b) to make forward progress.

Thank you for the summary.
What is not clear to me is if (a) or (b) may break an existing application, and if yes, in which case.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Thanks for the reply.

To be clear we are talking about out of tree KNI tree application. Which they don't want to
change rte_pktmbuf_pool_create() to rte_kni_pktmbuf_pool_create() and build for v19.11

So in case (b) there is no issue as It will be using

rte_pktmbuf_pool_create ().

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

But in case of (a) it will create an issue if out of tree KNI application is using rte_pktmbuf_pool_create() which is not using the NEW flag.

Following yesterday's discussion at techboard, I looked at the mempool code and at my previous RFC patch. It took some time to remind me what was my worries.

Quoted 7 lines
Quoted 7 lines

Thanks for the review Olivier.

Just to make sure the correct one is reviewed.

1) v7 had similar issue mentioned
https://urldefense.proofpoint.com/v2/url?u=http-

3A__patches.dpdk.org_patch_56585_&d=DwIBaQ&c=nKjWec2b6R0mOyPaz7 xtf

Quoted 1 line
Quoted 1 line

Q&r=WllrYaumVkxaWjgKto6E_rtDQshhIhik2jkvzFyRhW8&m=MMwAZe76YM VHe

Quoted 2 lines
Quoted 2 lines

8UcHjL4IBnfX5YvtbocwICAZGBY97A&s=mfN_afnyFm65sQYzaAg_- uM9o22A5j392TdBZY-bKK4&e=

The v7 has the problem I described below: the iova-contiguous allocation may fail because the calculated size is too small, and remaining objects will be added in another chunk. This can happen if a fully iova-contiguous mempool is requested (it happens for octeontx).

Also, the way page size is retrieved in rte_mempool_op_populate_default() assume that memzones are used, which is not correct.

Quoted 3 lines
Quoted 3 lines

2) v11 addressed the review comments and you have given the Acked-by for mempool change https://urldefense.proofpoint.com/v2/url?u=http-

3A__patches.dpdk.org_patch_61559_&d=DwIBaQ&c=nKjWec2b6R0mOyPaz7 xtf

Quoted 1 line
Quoted 1 line

Q&r=WllrYaumVkxaWjgKto6E_rtDQshhIhik2jkvzFyRhW8&m=MMwAZe76YM VHe

Quoted 1 line
Quoted 1 line

8UcHjL4IBnfX5YvtbocwICAZGBY97A&s=frFvKOHFDRhTam6jDZZc6omK2gb1RU 62

Quoted 1 line
Quoted 1 line

xzAiiBMnf0I&e=

The v11 looked fine to me, because it does not impact any default behavior, and the plan was to remove this new function when my mempool patchset was in.

Quoted 22 lines
Quoted 21 lines

My thought process in the TB meeting was, since rte_mempool_populate_from_pg_sz_chunks() reviwed replace rte_pktmbuf_pool_create's rte_mempool_populate_default() with rte_mempool_populate_from_pg_sz_chunks()
in IOVA == VA case to avoid a new KNI mempool_create API.

Quoted 14 lines

Currently, in rte_mempool_populate_default(), when the mempool is populated, we first try to allocate one iova-contiguous block of (n * elt_size). On success, we use this memory to fully populate the mempool without taking care of crossing page boundaries.

If we change the behavior to prevent objects from crossing pages, the assumption that allocating (n * elt_size) is always enough becomes wrong. By luck, there is no real impact, because if the mempool is not fully populated after this first iteration, it will allocate a new chunk.

To be rigorous, we need to better calculate the amount of memory to allocate, according to page size.

Quoted 8 lines

Hi Olivier,

Thanks for the review, I think the below mentioned problems exist with current mempool_populate_default() api and will there be high chances of hitting those problems when we precalculate the memory size(after preventing objs from pg boundary and fit complete mempool memory in single mem chunk) and if mempool size goes beyond page size as below example. ?,

Quoted 6 lines

Yes, the problem described below (alloc a mempool of 1.1GB resulting in 2GB reserved) exists in the current version. It will be fixed in the new version of my "mempool: avoid objects allocations across pages"
patchset.

FYI, a reworked patchset is alsmost ready, I'll send it monday.

Thanks a lot Olivier.

Quoted 46 lines
Quoted 8 lines

Regards,
Vamsi

Quoted 3 lines
Quoted 3 lines

Looking at the code, I found another problem in the same area:
let's say we populate a mempool that requires 1.1GB (and we use 1G

huge pages):

Quoted 36 lines
Quoted 36 lines
Quoted 10 lines

1/ mempool code will first tries to allocate an iova-contiguous zone
of 1.1G -> fail
2/ it then tries to allocate a page-aligned non iova-contiguous
zone of 1.1G, which is 2G. On success, a lot of memory is wasted.
3/ on error, we try to allocate the biggest zone, it can still return
a zone between 1.1G and 2G, which can also waste memory.

I will rework my mempool patchset to properly address these issues, hopefully tomorrow.

OK.

Quoted 6 lines

Also, I thought about another idea to solve your issue, not sure it is better but it would not imply to change the mempool behavior. If I understood the problem, when a mbuf is accross 2 pages, the copy of the data can fail in kni because the mbuf is not virtually contiguous in the

For KNI use case, we would need _physically_ contiguous to make sure that using, get_user_pages_remote() we get physically contiguous memory map, so that both KNI kernel thread and KNI kernel context and DPDK userspace can use the same memory in different contexts.

Quoted 5 lines

kernel. So why not in this case splitting the memcpy() into several, each of them being on a single page (and calling phys2virt() for each page)? The same would have to be done when accessing the fields of the mbuf structure if it crosses a page boundary. Would that work? This

If the above is the requirement, Does this logic need to be in slow path or fast path?

Quoted 6 lines
Quoted 4 lines

In fast path. But I don't think the performance impact would be significative.

Vamsi, do you confirm this approach could also solve the issue without changing the mempool?

So far there is no performance impact observed when these feature(kni iova as va) is enabled with this patch set. Not sure of impact if when memcpy split and extra address translations are introduced, this approach might solve but I feel it's not a clearer way of solving the issue.

Agree it's not the clearer way, but maybe less risky.

As you can see, the reworked patchset is not that short:
http://inbox.dpdk.org/dev/[email protected]/T/#m6249311baae8469f5727f07c32e4e6e6844eae6a

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

could be a B plan.

OK.

Quoted 2 lines

Olivier

#209 lore raw

PATCH v11 3/4 kni: add IOVA=VA support

In reply to [email protected]

From: Vamsi Attunuru <[email protected]>

Current KNI implementation only operates in IOVA_PA mode patch adds required functionality to enable KNI in IOVA_VA mode.

Packet pool's mbuf memory should be physically contiguous for the KNI kernel module to work in IOVA=VA mode, new KNI packet pool create APIs are introduced to take care of this memory requirement.

examples/kni/ updated to use this API to enable IOVA as VA or IOVA as PA mode.

Existing KNI applications can use ``--legacy-kni`` eal option to work with DPDK 19.11 and later versions. When this option is selected, IOVA mode will be forced to PA mode to enable old KNI applications work with the latest DPDK without code change.

---
 doc/guides/prog_guide/kernel_nic_interface.rst    | 26 +++++++++
 doc/guides/rel_notes/release_19_11.rst            | 13 +++++
 examples/kni/main.c                               |  6 +-
 lib/librte_eal/linux/eal/eal.c                    | 39 +++++++++----
 lib/librte_eal/linux/eal/include/rte_kni_common.h |  1 +
 lib/librte_kni/Makefile                           |  1 +
 lib/librte_kni/meson.build                        |  1 +
 lib/librte_kni/rte_kni.c                          | 67 +++++++++++++++++++++--
 lib/librte_kni/rte_kni.h                          | 48 ++++++++++++++++
 lib/librte_kni/rte_kni_version.map                |  3 +
 10 files changed, 187 insertions(+), 18 deletions(-)
doc/guides/prog_guide/kernel_nic_interface.rst +26 -0
index 2fd58e1..80f731c 100644
@@ -300,6 +300,32 @@ The sk_buff is then freed and the mbuf sent in the tx_q FIFO.
 The DPDK TX thread dequeues the mbuf and sends it to the PMD via ``rte_eth_tx_burst()``.
 It then puts the mbuf back in the cache.
 
+IOVA = VA: Support
+------------------
+
+KNI can be operated in IOVA_VA scheme when
+
+- LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) and
+- eal option `iova-mode=va` is passed or bus IOVA scheme in the DPDK is selected
+  as RTE_IOVA_VA.
+
+Packet Pool APIs for IOVA=VA mode
+---------------------------------
+
+``rte_kni_pktmbuf_pool_create`` and ``rte_kni_pktmbuf_pool_free`` APIs need to
+be used for creating packet pools for running KNI applications in IOVA=VA mode.
+Packet pool's mbuf memory should be physically contiguous for the KNI kernel
+module to work in IOVA=VA mode, this memory requirement was taken care inside
+those KNI packet pool create APIs.
+
+Command-line option for legacy KNI
+----------------------------------
+
+Existing KNI applications can use ``--legacy-kni`` eal command-line option to
+work with DPDK 19.11 and later versions. When this option is selected, IOVA mode
+will be forced to PA mode to enable old KNI applications work with the latest
+DPDK without code changes.
+
 Ethtool
 -------
 
doc/guides/rel_notes/release_19_11.rst +13 -0
index ab2c381..e4296a0 100644
@@ -120,6 +120,19 @@ New Features
   Added EAL option ``--legacy-kni`` to make existing KNI applications work
   with DPDK 19.11 and later.
 
+* **Added IOVA as VA support for KNI.**
+
+  Added IOVA as VA support for KNI. When KNI needs to operate in IOVA = VA
+  mode, packet pool's mbuf memory should be physically contiguous. This memory
+  requirement taken care using the new ``rte_kni_pktmbuf_pool_create`` and
+  ``rte_kni_pktmbuf_pool_free`` routines.
+
+  The ``examples/kni/`` updated to use this API to enable IOVA as VA or
+  IOVA as PA mode.
+
+  When "--legacy-kni" selected, IOVA mode will be forced to PA mode to enable
+  old KNI application work with the latest DPDK without code changes.
+
 Removed Items
 -------------
 
examples/kni/main.c +5 -1
index c576fc7..d2f3b46 100644
@@ -1017,8 +1017,9 @@ main(int argc, char** argv)
 		rte_exit(EXIT_FAILURE, "Could not parse input parameters\n");
 
 	/* Create the mbuf pool */
-	pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF,
+	pktmbuf_pool = rte_kni_pktmbuf_pool_create("mbuf_pool", NB_MBUF,
 		MEMPOOL_CACHE_SZ, 0, MBUF_DATA_SZ, rte_socket_id());
+
 	if (pktmbuf_pool == NULL) {
 		rte_exit(EXIT_FAILURE, "Could not initialise mbuf pool\n");
 		return -1;
@@ -1085,6 +1086,9 @@ main(int argc, char** argv)
 			continue;
 		kni_free_kni(port);
 	}
+
+	rte_kni_pktmbuf_pool_free(pktmbuf_pool);
+
 	for (i = 0; i < RTE_MAX_ETHPORTS; i++)
 		if (kni_port_params_array[i]) {
 			rte_free(kni_port_params_array[i]);
lib/librte_eal/linux/eal/eal.c +27 -12
index f397206..f807044 100644
@@ -947,6 +947,29 @@ static int rte_eal_vfio_setup(void)
 }
 #endif
 
+static enum rte_iova_mode
+rte_eal_kni_get_iova_mode(enum rte_iova_mode iova_mode)
+{
+	if (iova_mode == RTE_IOVA_PA)
+		goto exit;
+
+	if (internal_config.legacy_kni) {
+		iova_mode = RTE_IOVA_PA;
+		RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because legacy KNI is enabled\n");
+		goto exit;
+	}
+
+	if (iova_mode == RTE_IOVA_VA) {
+#if KERNEL_VERSION(4, 8, 0) > LINUX_VERSION_CODE
+		iova_mode = RTE_IOVA_PA;
+		RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI module does not support VA\n");
+#endif
+	}
+
+exit:
+	return iova_mode;
+}
+
 static void rte_eal_init_alert(const char *msg)
 {
 	fprintf(stderr, "EAL: FATAL: %s\n", msg);
@@ -1110,24 +1133,16 @@ rte_eal_init(int argc, char **argv)
 				RTE_LOG(DEBUG, EAL, "IOMMU is not available, selecting IOVA as PA mode.\n");
 			}
 		}
-#ifdef RTE_LIBRTE_KNI
-		/* Workaround for KNI which requires physical address to work */
-		if (iova_mode == RTE_IOVA_VA &&
-				rte_eal_check_module("rte_kni") == 1) {
-			if (phys_addrs) {
-				iova_mode = RTE_IOVA_PA;
-				RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI module is loaded\n");
-			} else {
-				RTE_LOG(DEBUG, EAL, "KNI can not work since physical addresses are unavailable\n");
-			}
-		}
-#endif
 		rte_eal_get_configuration()->iova_mode = iova_mode;
 	} else {
 		rte_eal_get_configuration()->iova_mode =
 			internal_config.iova_mode;
 	}
 
+	if (rte_eal_check_module("rte_kni") == 1)
+		rte_eal_get_configuration()->iova_mode =
+				rte_eal_kni_get_iova_mode(rte_eal_iova_mode());
+
 	if (rte_eal_iova_mode() == RTE_IOVA_PA && !phys_addrs) {
 		rte_eal_init_alert("Cannot use IOVA as 'PA' since physical addresses are not available");
 		rte_errno = EINVAL;
lib/librte_eal/linux/eal/include/rte_kni_common.h +1 -0
index b51fe27..1b96cf6 100644
@@ -123,6 +123,7 @@ struct rte_kni_device_info {
 	unsigned mbuf_size;
 	unsigned int mtu;
 	uint8_t mac_addr[6];
+	uint8_t iova_mode;
 };
 
 #define KNI_DEVICE "kni"
lib/librte_kni/Makefile +1 -0
index cbd6599..6405524 100644
@@ -6,6 +6,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 # library name
 LIB = librte_kni.a
 
+CFLAGS += -DALLOW_EXPERIMENTAL_API
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -fno-strict-aliasing
 LDLIBS += -lrte_eal -lrte_mempool -lrte_mbuf -lrte_ethdev
 
lib/librte_kni/meson.build +1 -0
index 41fa2e3..dd4c8da 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
+allow_experimental_apis = true
 if not is_linux or not dpdk_conf.get('RTE_ARCH_64')
 	build = false
 	reason = 'only supported on 64-bit linux'
lib/librte_kni/rte_kni.c +62 -5

91 lines not on this page · raw message

lib/librte_kni/rte_kni.h +48 -0

54 lines not on this page · raw message

lib/librte_kni/rte_kni_version.map +3 -0
index c877dc6..5937bff 100644
@@ -19,5 +19,8 @@ DPDK_2.0 {
 EXPERIMENTAL {
 	global:
 
+	# added in 19.11
 	rte_kni_update_link;
+	rte_kni_pktmbuf_pool_create;
+	rte_kni_pktmbuf_pool_free;
 };
Signature · 1 line
2.8.4
#210 lore raw

PATCH v11 4/4 kni: add IOVA=VA support in kernel module

In reply to [email protected]

From: Vamsi Attunuru <[email protected]>

Patch adds support for kernel module to work in IOVA = VA mode by providing address translation routines to convert IOVA aka user space VA to kernel virtual addresses.

---
 kernel/linux/kni/compat.h   |  4 ++++
 kernel/linux/kni/kni_dev.h  | 31 ++++++++++++++++++++++++
 kernel/linux/kni/kni_misc.c | 39 +++++++++++++++++++++++-------
 kernel/linux/kni/kni_net.c  | 58 +++++++++++++++++++++++++++++++++++----------
 4 files changed, 110 insertions(+), 22 deletions(-)
kernel/linux/kni/compat.h +4 -0
index 562d8bf..b5e8914 100644
@@ -121,3 +121,7 @@
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
 #define HAVE_SIGNAL_FUNCTIONS_OWN_HEADER
 #endif
+
+#if KERNEL_VERSION(4, 8, 0) <= LINUX_VERSION_CODE
+#define HAVE_IOVA_TO_KVA_MAPPING_SUPPORT
+#endif
kernel/linux/kni/kni_dev.h +31 -0
index c1ca678..abe9b14 100644
@@ -41,6 +41,8 @@ struct kni_dev {
 	/* kni list */
 	struct list_head list;
 
+	uint8_t iova_mode;
+
 	uint32_t core_id;            /* Core ID to bind */
 	char name[RTE_KNI_NAMESIZE]; /* Network device name */
 	struct task_struct *pthread;
@@ -84,8 +86,37 @@ struct kni_dev {
 	void *va[MBUF_BURST_SZ];
 	void *alloc_pa[MBUF_BURST_SZ];
 	void *alloc_va[MBUF_BURST_SZ];
+
+	struct task_struct *usr_tsk;
 };
 
+static inline phys_addr_t iova_to_phys(struct task_struct *tsk,
+				       unsigned long iova)
+{
+	unsigned int flags = FOLL_TOUCH;
+	phys_addr_t offset, phys_addr;
+	struct page *page = NULL;
+	int ret;
+
+	offset = iova & (PAGE_SIZE - 1);
+
+	/* Read one page struct info */
+	ret =  get_user_pages_remote(tsk, tsk->mm, iova, 1,
+				     flags, &page, 0, 0);
+	if (ret < 0)
+		return 0;
+
+	phys_addr = page_to_phys(page) | offset;
+	put_page(page);
+
+	return phys_addr;
+}
+
+static inline void *iova_to_kva(struct task_struct *tsk, unsigned long iova)
+{
+	return phys_to_virt(iova_to_phys(tsk, iova));
+}
+
 void kni_net_release_fifo_phy(struct kni_dev *kni);
 void kni_net_rx(struct kni_dev *kni);
 void kni_net_init(struct net_device *dev);
kernel/linux/kni/kni_misc.c +30 -9
index 2b75502..7af7ab4 100644
@@ -348,15 +348,36 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
 	strncpy(kni->name, dev_info.name, RTE_KNI_NAMESIZE);
 
 	/* Translate user space info into kernel space info */
-	kni->tx_q = phys_to_virt(dev_info.tx_phys);
-	kni->rx_q = phys_to_virt(dev_info.rx_phys);
-	kni->alloc_q = phys_to_virt(dev_info.alloc_phys);
-	kni->free_q = phys_to_virt(dev_info.free_phys);
-
-	kni->req_q = phys_to_virt(dev_info.req_phys);
-	kni->resp_q = phys_to_virt(dev_info.resp_phys);
-	kni->sync_va = dev_info.sync_va;
-	kni->sync_kva = phys_to_virt(dev_info.sync_phys);
+	if (dev_info.iova_mode) {
+#ifdef HAVE_IOVA_TO_KVA_MAPPING_SUPPORT
+		kni->tx_q = iova_to_kva(current, dev_info.tx_phys);
+		kni->rx_q = iova_to_kva(current, dev_info.rx_phys);
+		kni->alloc_q = iova_to_kva(current, dev_info.alloc_phys);
+		kni->free_q = iova_to_kva(current, dev_info.free_phys);
+
+		kni->req_q = iova_to_kva(current, dev_info.req_phys);
+		kni->resp_q = iova_to_kva(current, dev_info.resp_phys);
+		kni->sync_va = dev_info.sync_va;
+		kni->sync_kva = iova_to_kva(current, dev_info.sync_phys);
+		kni->usr_tsk = current;
+		kni->iova_mode = 1;
+#else
+		pr_err("KNI module does not support IOVA to VA translation\n");
+		return -EINVAL;
+#endif
+	} else {
+
+		kni->tx_q = phys_to_virt(dev_info.tx_phys);
+		kni->rx_q = phys_to_virt(dev_info.rx_phys);
+		kni->alloc_q = phys_to_virt(dev_info.alloc_phys);
+		kni->free_q = phys_to_virt(dev_info.free_phys);
+
+		kni->req_q = phys_to_virt(dev_info.req_phys);
+		kni->resp_q = phys_to_virt(dev_info.resp_phys);
+		kni->sync_va = dev_info.sync_va;
+		kni->sync_kva = phys_to_virt(dev_info.sync_phys);
+		kni->iova_mode = 0;
+	}
 
 	kni->mbuf_size = dev_info.mbuf_size;
 
kernel/linux/kni/kni_net.c +45 -13

115 lines not on this page · raw message

Signature · 1 line
2.8.4
#211 lore raw

Re: [dpdk-dev] [PATCH v11 4/4] kni: add IOVA=VA support in kernel module

Quoted 9 lines · On 10/21/2019 9:03 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

Patch adds support for kernel module to work in IOVA = VA mode by providing address translation routines to convert IOVA aka user space VA to kernel virtual addresses.

<...>

Quoted 16 lines
kernel/linux/kni/kni_dev.h +16 -0
+static inline phys_addr_t iova_to_phys(struct task_struct *tsk,
+				       unsigned long iova)
+{
+	unsigned int flags = FOLL_TOUCH;
+	phys_addr_t offset, phys_addr;
+	struct page *page = NULL;
+	int ret;
+
+	offset = iova & (PAGE_SIZE - 1);
+
+	/* Read one page struct info */
+	ret =  get_user_pages_remote(tsk, tsk->mm, iova, 1,
+				     flags, &page, 0, 0);
+	if (ret < 0)
+		return 0;
+

kernel/linux/kni/kni_dev.h struct kni_dev { · line 118

Quoted 10 lines
kernel/linux/kni/kni_dev.h +10 -0
+	phys_addr = page_to_phys(page) | offset;
+	put_page(page);
+
+	return phys_addr;
+}
+
+static inline void *iova_to_kva(struct task_struct *tsk, unsigned long iova)
+{
+	return phys_to_virt(iova_to_phys(tsk, iova));
+}

Do you have any measurement for the performance affect of this change?

Quoted 13 lines
kernel/linux/kni/kni_dev.h +1 -0
+
 void kni_net_release_fifo_phy(struct kni_dev *kni);
 void kni_net_rx(struct kni_dev *kni);
 void kni_net_init(struct net_device *dev);
kernel/linux/kni/kni_misc.c +0 -1
index 2b75502..7af7ab4 100644
@@ -348,15 +348,36 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
 	strncpy(kni->name, dev_info.name, RTE_KNI_NAMESIZE);
 
 	/* Translate user space info into kernel space info */
-	kni->tx_q = phys_to_virt(dev_info.tx_phys);

kernel/linux/kni/kni_misc.c kni_ioctl_create(struct net *net, uint32_t ioctl_num, · line 352

Quoted 10 lines
kernel/linux/kni/kni_misc.c +2 -8
-	kni->rx_q = phys_to_virt(dev_info.rx_phys);
-	kni->alloc_q = phys_to_virt(dev_info.alloc_phys);
-	kni->free_q = phys_to_virt(dev_info.free_phys);
-
-	kni->req_q = phys_to_virt(dev_info.req_phys);
-	kni->resp_q = phys_to_virt(dev_info.resp_phys);
-	kni->sync_va = dev_info.sync_va;
-	kni->sync_kva = phys_to_virt(dev_info.sync_phys);
+	if (dev_info.iova_mode) {
+#ifdef HAVE_IOVA_TO_KVA_MAPPING_SUPPORT

Do you think is a runtime check required, for the case code has been compiled on a box that has newer kernel but run in a box with older kernel?
Not sure about it myself either...

<...>

kernel/linux/kni/kni_misc.c kva2data_kva(struct rte_kni_mbuf *m) · line 82

Quoted 8 lines
kernel/linux/kni/kni_misc.c +4 -0
@@ -62,6 +76,24 @@ kva2data_kva(struct rte_kni_mbuf *m)
 	return phys_to_virt(m->buf_physaddr + m->data_off);
 }
 
+static inline void *
+get_kva(struct kni_dev *kni, void *pa)
+{
+	if (kni->iova_mode == 1)

This check done multiple times per packet, I wonder if this can be prevented, again even with the original mode do you have any numbers related to the performance affect of this check?

Thanks,
ferruh

#212 lore raw

v12 cover add IOVA=VA mode support

In reply to [email protected]

From: Vamsi Attunuru <[email protected]>

---
V12 Changes:
* Removed previously added --legacy-kni eal option.
* Removed previously added kni specific mempool create routines and mempool populate routines.

This patch set(V12) is dependent on following patch set, since the mempool related support to enable KNI in IOVA=VA mode is taken care in below patchset.

https://patchwork.dpdk.org/cover/62376/

V11 Changes:
* Added iova to kva address translation routines in kernel module to make it work in iova=va mode which enables DPDK to create kni devices on any kind of backed device/memory.
* Added ``--legacy-kni`` eal option to make existing KNI applications work with DPDK 19.11 and later versions.
* Removed previously added pci device info from kni device info struct.

V10 Changes:
* Fixed function return code on failure when min_chunk_size > pg_sz.
* Marked new mempool populate routine as EXPERIMENTAL.

V9 Changes:
* Used rte_mempool_ops_calc_mem_size() instead of default handler in the new mempool populate routine.
* Check min_chunk_size and return values.
* Removed ethdev_info memset to '0' and moved pci dev_info populate into kni_dev_pci_addr_get() routine.
* Addressed misc. review comments.

V8 Changes:
* Remove default mempool populate() routine changes.
* Add kni app specific mempool create & free routines.
* Add new mempool populate routine to allocate page-aligned memzones with page size to make sure all mempool objects reside on a page.
* Update release notes and map files.

V7 Changes:
* Removed previously proposed mempool flag and made those page boundary checks default in mempool populate() except for the objects size bigger than the size of page.
* Removed KNI example application related changes since pool related requirement is taken care in mempool lib.
* All PCI dev related info is moved under rte_eal_iova_mode() == VA check.
* Added wrapper functions in KNI module to hide IOVA checks and make address translation routines more readable.
* Updated IOVA mode checks that enforcing IOVA=PA mode when IOVA=VA mode is enabled.

V6 Changes:
* Added new mempool flag to ensure mbuf memory is not scattered across page boundaries.
* Added KNI kernel module required PCI device information.
* Modified KNI example application to create mempool with new mempool flag.

V5 changes:
* Fixed build issue with 32b build

V4 changes:
* Fixed build issues with older kernel versions
* This approach will only work with kernel above 4.4.0

V3 Changes:
* Add new approach to work kni with IOVA=VA mode using iommu_iova_to_phys API.

Vamsi Attunuru (2):
kni: add IOVA=VA mode support
kni: add IOVA=VA support in kernel module

 doc/guides/prog_guide/kernel_nic_interface.rst    |  9 ++++
 doc/guides/rel_notes/release_19_11.rst            |  5 ++
 kernel/linux/kni/compat.h                         | 15 ++++++
 kernel/linux/kni/kni_dev.h                        | 42 +++++++++++++++
 kernel/linux/kni/kni_misc.c                       | 39 ++++++++++----
 kernel/linux/kni/kni_net.c                        | 62 ++++++++++++++++++-----
 lib/librte_eal/linux/eal/eal.c                    | 29 ++++++-----
 lib/librte_eal/linux/eal/include/rte_kni_common.h |  1 +
 lib/librte_kni/rte_kni.c                          |  7 +--
 9 files changed, 170 insertions(+), 39 deletions(-)
Signature · 1 line
2.8.4
#213 lore raw

PATCH v12 1/2 kni: add IOVA=VA mode support

From: Vamsi Attunuru <[email protected]>

Current KNI implementation only operates in IOVA_PA mode patch adds required functionality to enable KNI in IOVA_VA mode.

KNI can operate in IOVA_VA mode when this mode is requested using eal option (iova-mode=va) or when bus iommu scheme is selected as RTE_IOVA_VA.

During KNI creation, app's iova_mode details are passed to the KNI kernel module, accordingly kernel module translates PA/IOVA addresses to KVA and vice-versa.

---
 doc/guides/prog_guide/kernel_nic_interface.rst    |  9 +++++++
 doc/guides/rel_notes/release_19_11.rst            |  5 ++++
 lib/librte_eal/linux/eal/eal.c                    | 29 +++++++++++++----------
 lib/librte_eal/linux/eal/include/rte_kni_common.h |  1 +
 lib/librte_kni/rte_kni.c                          |  7 ++----
 5 files changed, 34 insertions(+), 17 deletions(-)
doc/guides/prog_guide/kernel_nic_interface.rst +9 -0
index 2fd58e1..f869493 100644
@@ -300,6 +300,15 @@ The sk_buff is then freed and the mbuf sent in the tx_q FIFO.
 The DPDK TX thread dequeues the mbuf and sends it to the PMD via ``rte_eth_tx_burst()``.
 It then puts the mbuf back in the cache.
 
+IOVA = VA: Support
+------------------
+
+KNI operates in IOVA_VA scheme when
+
+- LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) and
+- eal option `iova-mode=va` is passed or bus IOVA scheme in the DPDK is selected
+  as RTE_IOVA_VA.
+
 Ethtool
 -------
 
doc/guides/rel_notes/release_19_11.rst +5 -0
index ae8e7b2..e5d2996 100644
@@ -231,6 +231,11 @@ New Features
   * Added a console command to testpmd app, ``show port (port_id) ptypes`` which
     gives ability to print port supported ptypes in different protocol layers.
 
+* **Added IOVA as VA support for KNI.**
+
+  Added IOVA = VA support for KNI, KNI can operate in IOVA = VA mode when
+  `iova-mode=va` eal option is passed to the application or when bus IOVA
+  scheme is selected as RTE_IOVA_VA.
 
 Removed Items
 -------------
lib/librte_eal/linux/eal/eal.c +17 -12
index 9e2d50c..a1c5bf6 100644
@@ -922,6 +922,19 @@ static int rte_eal_vfio_setup(void)
 }
 #endif
 
+static enum rte_iova_mode
+rte_eal_kni_get_iova_mode(enum rte_iova_mode iova_mode)
+{
+	if (iova_mode == RTE_IOVA_VA) {
+#if KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE
+		iova_mode = RTE_IOVA_PA;
+		RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI module does not support VA\n");
+#endif
+	}
+
+	return iova_mode;
+}
+
 static void rte_eal_init_alert(const char *msg)
 {
 	fprintf(stderr, "EAL: FATAL: %s\n", msg);
@@ -1085,24 +1098,16 @@ rte_eal_init(int argc, char **argv)
 				RTE_LOG(DEBUG, EAL, "IOMMU is not available, selecting IOVA as PA mode.\n");
 			}
 		}
-#ifdef RTE_LIBRTE_KNI
-		/* Workaround for KNI which requires physical address to work */
-		if (iova_mode == RTE_IOVA_VA &&
-				rte_eal_check_module("rte_kni") == 1) {
-			if (phys_addrs) {
-				iova_mode = RTE_IOVA_PA;
-				RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI module is loaded\n");
-			} else {
-				RTE_LOG(DEBUG, EAL, "KNI can not work since physical addresses are unavailable\n");
-			}
-		}
-#endif
 		rte_eal_get_configuration()->iova_mode = iova_mode;
 	} else {
 		rte_eal_get_configuration()->iova_mode =
 			internal_config.iova_mode;
 	}
 
+	if (rte_eal_check_module("rte_kni") == 1)
+		rte_eal_get_configuration()->iova_mode =
+				rte_eal_kni_get_iova_mode(rte_eal_iova_mode());
+
 	if (rte_eal_iova_mode() == RTE_IOVA_PA && !phys_addrs) {
 		rte_eal_init_alert("Cannot use IOVA as 'PA' since physical addresses are not available");
 		rte_errno = EINVAL;
lib/librte_eal/linux/eal/include/rte_kni_common.h +1 -0
index 46f75a7..2427a96 100644
@@ -125,6 +125,7 @@ struct rte_kni_device_info {
 	unsigned int min_mtu;
 	unsigned int max_mtu;
 	uint8_t mac_addr[6];
+	uint8_t iova_mode;
 };
 
 #define KNI_DEVICE "kni"
lib/librte_kni/rte_kni.c +2 -5
index 7fbcf22..7221280 100644
@@ -97,11 +97,6 @@ static volatile int kni_fd = -1;
 int
 rte_kni_init(unsigned int max_kni_ifaces __rte_unused)
 {
-	if (rte_eal_iova_mode() != RTE_IOVA_PA) {
-		RTE_LOG(ERR, KNI, "KNI requires IOVA as PA\n");
-		return -1;
-	}
-
 	/* Check FD and open */
 	if (kni_fd < 0) {
 		kni_fd = open("/dev/" KNI_DEVICE, O_RDWR);
@@ -302,6 +297,8 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 	kni->group_id = conf->group_id;
 	kni->mbuf_size = conf->mbuf_size;
 
+	dev_info.iova_mode = (rte_eal_iova_mode() == RTE_IOVA_VA) ? 1 : 0;
+
 	ret = ioctl(kni_fd, RTE_KNI_IOCTL_CREATE, &dev_info);
 	if (ret < 0)
 		goto ioctl_fail;
Signature · 1 line
2.8.4
#214 lore raw

Re: [dpdk-dev] [PATCH v12 1/2] kni: add IOVA=VA mode support

Quoted 51 lines · On Tue, Nov 5, 2019 at 12:05 PM <[email protected]> wrote:

From: Vamsi Attunuru <[email protected]>

Current KNI implementation only operates in IOVA_PA mode patch adds required functionality to enable KNI in IOVA_VA mode.

KNI can operate in IOVA_VA mode when this mode is requested using eal option (iova-mode=va) or when bus iommu scheme is selected as RTE_IOVA_VA.

During KNI creation, app's iova_mode details are passed to the KNI kernel module, accordingly kernel module translates PA/IOVA addresses to KVA and vice-versa.

---
 doc/guides/prog_guide/kernel_nic_interface.rst    |  9 +++++++
 doc/guides/rel_notes/release_19_11.rst            |  5 ++++
 lib/librte_eal/linux/eal/eal.c                    | 29 +++++++++++++----------
 lib/librte_eal/linux/eal/include/rte_kni_common.h |  1 +
 lib/librte_kni/rte_kni.c                          |  7 ++----
 5 files changed, 34 insertions(+), 17 deletions(-)
doc/guides/prog_guide/kernel_nic_interface.rst +9 -0
index 2fd58e1..f869493 100644
@@ -300,6 +300,15 @@ The sk_buff is then freed and the mbuf sent in the tx_q FIFO.
 The DPDK TX thread dequeues the mbuf and sends it to the PMD via ``rte_eth_tx_burst()``.
 It then puts the mbuf back in the cache.
 
+IOVA = VA: Support
+------------------
+
+KNI operates in IOVA_VA scheme when
+
+- LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) and
+- eal option `iova-mode=va` is passed or bus IOVA scheme in the DPDK is selected
+  as RTE_IOVA_VA.
+
 Ethtool
 -------
 
doc/guides/rel_notes/release_19_11.rst +0 -0
index ae8e7b2..e5d2996 100644

doc/guides/rel_notes/release_19_11.rst New Features · line 238

Quoted 8 lines
doc/guides/rel_notes/release_19_11.rst +5 -0
@@ -231,6 +231,11 @@ New Features
   * Added a console command to testpmd app, ``show port (port_id) ptypes`` which
     gives ability to print port supported ptypes in different protocol layers.
 
+* **Added IOVA as VA support for KNI.**
+
+  Added IOVA = VA support for KNI, KNI can operate in IOVA = VA mode when
+  `iova-mode=va` eal option is passed to the application or when bus IOVA
+  scheme is selected as RTE_IOVA_VA.

Add a mention about the kernel requirement here too please.

Missing newline.

Quoted 8 lines
doc/guides/rel_notes/release_19_11.rst +0 -0
 Removed Items
 -------------
lib/librte_eal/linux/eal/eal.c +0 -0
index 9e2d50c..a1c5bf6 100644

lib/librte_eal/linux/eal/eal.c static int rte_eal_vfio_setup(void) · line 929

Quoted 8 lines
lib/librte_eal/linux/eal/eal.c +5 -0
@@ -922,6 +922,19 @@ static int rte_eal_vfio_setup(void)
 }
 #endif
 
+static enum rte_iova_mode
+rte_eal_kni_get_iova_mode(enum rte_iova_mode iova_mode)
+{
+       if (iova_mode == RTE_IOVA_VA) {
+#if KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE

I understood that IOVA as VA is possible with kernel >= 4.6. Should it be < ?

Quoted 12 lines
lib/librte_eal/linux/eal/eal.c +8 -0
+               iova_mode = RTE_IOVA_PA;
+               RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI module does not support VA\n");
+#endif
+       }
+
+       return iova_mode;
+}
+
 static void rte_eal_init_alert(const char *msg)
 {
        fprintf(stderr, "EAL: FATAL: %s\n", msg);

lib/librte_eal/linux/eal/eal.c rte_eal_init(int argc, char **argv) · line 1088

Quoted 4 lines
lib/librte_eal/linux/eal/eal.c +0 -1
@@ -1085,24 +1098,16 @@ rte_eal_init(int argc, char **argv)
                                RTE_LOG(DEBUG, EAL, "IOMMU is not available, selecting IOVA as PA mode.\n");
                        }
                }
-#ifdef RTE_LIBRTE_KNI

You removed this part, but we don't have to consider kni things if RTE_LIBRTE_KNI is not compiled in.

lib/librte_eal/linux/eal/eal.c rte_eal_init(int argc, char **argv) · line 1092

Quoted 4 lines
lib/librte_eal/linux/eal/eal.c +0 -4
-               /* Workaround for KNI which requires physical address to work */
-               if (iova_mode == RTE_IOVA_VA &&
-                               rte_eal_check_module("rte_kni") == 1) {
-                       if (phys_addrs) {

The check on physical address availability has been lost.

Quoted 7 lines
lib/librte_eal/linux/eal/eal.c +0 -7
-                               iova_mode = RTE_IOVA_PA;
-                               RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI module is loaded\n");
-                       } else {
-                               RTE_LOG(DEBUG, EAL, "KNI can not work since physical addresses are unavailable\n");
-                       }
-               }
-#endif

lib/librte_eal/linux/eal/eal.c rte_eal_init(int argc, char **argv) · line 1110

Quoted 10 lines
lib/librte_eal/linux/eal/eal.c +4 -0
                rte_eal_get_configuration()->iova_mode = iova_mode;
        } else {
                rte_eal_get_configuration()->iova_mode =
                        internal_config.iova_mode;
        }
 
+       if (rte_eal_check_module("rte_kni") == 1)
+               rte_eal_get_configuration()->iova_mode =
+                               rte_eal_kni_get_iova_mode(rte_eal_iova_mode());
+

You are forcing this even if the user specified a iova mode.

In the end, can't we just change the check on the workaround? Something like:

@@ -1085,7 +1085,7 @@ rte_eal_init(int argc, char **argv)
RTE_LOG(DEBUG, EAL, "IOMMU is not
available, selecting IOVA as PA mode.\n");

                        }
                }
-#ifdef RTE_LIBRTE_KNI
+#if defined(RTE_LIBRTE_KNI) && KERNEL_VERSION(4, 6, 0) < LINUX_VERSION_CODE
                /* Workaround for KNI which requires physical address to work */
                if (iova_mode == RTE_IOVA_VA &&
                                rte_eal_check_module("rte_kni") == 1) {

It would be the only change in the whole file lib/librte_eal/linux/eal/eal.c

Quoted 20 lines
lib/librte_eal/linux/eal/eal.c +0 -0
        if (rte_eal_iova_mode() == RTE_IOVA_PA && !phys_addrs) {
                rte_eal_init_alert("Cannot use IOVA as 'PA' since physical addresses are not available");
                rte_errno = EINVAL;
lib/librte_eal/linux/eal/include/rte_kni_common.h +1 -0
index 46f75a7..2427a96 100644
@@ -125,6 +125,7 @@ struct rte_kni_device_info {
        unsigned int min_mtu;
        unsigned int max_mtu;
        uint8_t mac_addr[6];
+       uint8_t iova_mode;
 };
 
 #define KNI_DEVICE "kni"
lib/librte_kni/rte_kni.c +0 -0
index 7fbcf22..7221280 100644

lib/librte_kni/rte_kni.c static volatile int kni_fd = -1; · line 99

Quoted 3 lines
lib/librte_kni/rte_kni.c +0 -0
@@ -97,11 +97,6 @@ static volatile int kni_fd = -1;
 int
 rte_kni_init(unsigned int max_kni_ifaces __rte_unused)
 {

Should this check still apply with kernel < 4.6? Like:
+ #if KERNEL_VERSION(4, 6, 0) < LINUX_VERSION_CODE

lib/librte_kni/rte_kni.c static volatile int kni_fd = -1; · line 104

Quoted 5 lines
lib/librte_kni/rte_kni.c +0 -5
-       if (rte_eal_iova_mode() != RTE_IOVA_PA) {
-               RTE_LOG(ERR, KNI, "KNI requires IOVA as PA\n");
-               return -1;
-       }
-

+ #endif

Quoted 15 lines
lib/librte_kni/rte_kni.c +2 -1
        /* Check FD and open */
        if (kni_fd < 0) {
                kni_fd = open("/dev/" KNI_DEVICE, O_RDWR);
@@ -302,6 +297,8 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
        kni->group_id = conf->group_id;
        kni->mbuf_size = conf->mbuf_size;
 
+       dev_info.iova_mode = (rte_eal_iova_mode() == RTE_IOVA_VA) ? 1 : 0;
+
        ret = ioctl(kni_fd, RTE_KNI_IOCTL_CREATE, &dev_info);
        if (ret < 0)
                goto ioctl_fail;
--

2.8.4

Signature · 1 line
David Marchand
#215 lore raw

Re: [dpdk-dev] [PATCH v12 1/2] kni: add IOVA=VA mode support

Quoted 9 lines · David Marchand
Quoted 8 lines · On Tue, Nov 5, 2019 at 12:05 PM <[email protected]> wrote:
lib/librte_eal/linux/eal/eal.c +0 -0
index 9e2d50c..a1c5bf6 100644
@@ -922,6 +922,19 @@ static int rte_eal_vfio_setup(void)
 }
 #endif
 
Quoted 8 lines

lib/librte_eal/linux/eal/eal.c static int rte_eal_vfio_setup(void) · line 929

Quoted 5 lines
lib/librte_eal/linux/eal/eal.c +5 -0
+static enum rte_iova_mode
+rte_eal_kni_get_iova_mode(enum rte_iova_mode iova_mode)
+{
+       if (iova_mode == RTE_IOVA_VA) {
+#if KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE

I understood that IOVA as VA is possible with kernel >= 4.6. Should it be < ?

I meant "Should the #if check be < ?".

I did not mention this first, but thinking again, don't we have an issue here? This won't work for distributions that ship dpdk with kni built with dkms.

Cc Luca.
Signature · 1 line
David Marchand
#216 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v12 1/2] kni: add IOVA=VA mode support

Quoted 35 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Thursday, November 14, 2019 4:43 PM
To: Vamsi Krishna Attunuru <[email protected]>
Cc: dev <[email protected]>; Thomas Monjalon <[email protected]>; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; Olivier Matz <[email protected]>; Yigit, Ferruh <[email protected]>; Burakov, Anatoly <[email protected]>; Andrew Rybchenko <[email protected]>; Stephen Hemminger <[email protected]>; Luca Boccassi <[email protected]>
Subject: [EXT] Re: [dpdk-dev] [PATCH v12 1/2] kni: add IOVA=VA mode support

External Email

----------------------------------------------------------------------

Quoted 7 lines · David Marchand
Quoted 6 lines · On Tue, Nov 5, 2019 at 12:05 PM <[email protected]> wrote:
(quoted diff) +0 -0

b/lib/librte_eal/linux/eal/eal.c index 9e2d50c..a1c5bf6 100644

lib/librte_eal/linux/eal/eal.c +0 -0
@@ -922,6 +922,19 @@ static int rte_eal_vfio_setup(void)  }  #endif
 
Quoted 7 lines

lib/librte_eal/linux/eal/eal.c static int rte_eal_vfio_setup(void) } #endif · line 926

Quoted 4 lines
lib/librte_eal/linux/eal/eal.c +4 -0
+static enum rte_iova_mode
+rte_eal_kni_get_iova_mode(enum rte_iova_mode iova_mode) {
+       if (iova_mode == RTE_IOVA_VA) { #if KERNEL_VERSION(4, 6, 0)
+> LINUX_VERSION_CODE

I understood that IOVA as VA is possible with kernel >= 4.6. Should it be < ?

Quoted 5 lines

I meant "Should the #if check be < ?".

I did not mention this first, but thinking again, don't we have an issue here? This won't work for distributions that ship dpdk with kni built with dkms.

Hi David,

Are you referring the following problem, like if dpdk was build with some older kernel (<4.6) version and shipped, later kernel was updated to 4.8 and kni module got build with newer kernel.?, In this case, kni application will continue work in PA mode without any issues. KNI module decides it's iova mode that application has communicated during kni allocation. If the user expectation is to make KNI application work in VA mode, the check has to be dynamic than. Please correct me if the issue that is anticipated is something different.

BTW, eal has few of these kernel version checks in header files too(rte_vfio.h & eal_vfio.h), not sure if it would cause similar issues.

Regards
A Vamsi

Quoted 5 lines
Cc Luca.

--
David Marchand

#217 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v12 1/2] kni: add IOVA=VA mode support

Quoted 38 lines · Vamsi Krishna Attunuru
Quoted 38 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Thursday, November 14, 2019 4:43 PM
To: Vamsi Krishna Attunuru <[email protected]>
Cc: dev <[email protected]>; Thomas Monjalon <[email protected]>; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; Olivier Matz <[email protected]>; Yigit, Ferruh <[email protected]>; Burakov, Anatoly <[email protected]>; Andrew Rybchenko <[email protected]>; Stephen Hemminger <[email protected]>; Luca Boccassi <[email protected]>
Subject: [EXT] Re: [dpdk-dev] [PATCH v12 1/2] kni: add IOVA=VA mode support

External Email

----------------------------------------------------------------------

Quoted 7 lines · David Marchand
Quoted 6 lines · On Tue, Nov 5, 2019 at 12:05 PM <[email protected]> wrote:
(quoted diff) +0 -0

b/lib/librte_eal/linux/eal/eal.c index 9e2d50c..a1c5bf6 100644

lib/librte_eal/linux/eal/eal.c +0 -0
@@ -922,6 +922,19 @@ static int rte_eal_vfio_setup(void)  }  #endif
 
Quoted 7 lines

lib/librte_eal/linux/eal/eal.c static int rte_eal_vfio_setup(void) } #endif · line 926

Quoted 4 lines
lib/librte_eal/linux/eal/eal.c +4 -0
+static enum rte_iova_mode
+rte_eal_kni_get_iova_mode(enum rte_iova_mode iova_mode) {
+       if (iova_mode == RTE_IOVA_VA) { #if KERNEL_VERSION(4, 6, 0)
+> LINUX_VERSION_CODE

I understood that IOVA as VA is possible with kernel >= 4.6. Should it be < ?

I meant "Should the #if check be < ?".

Quoted 7 lines
Quoted 3 lines

I did not mention this first, but thinking again, don't we have an issue here? This won't work for distributions that ship dpdk with kni built with dkms.

Hi David,

Are you referring the following problem, like if dpdk was build with some older kernel (<4.6) version and shipped, later kernel was updated to 4.8 and kni module got build with newer kernel.?, In this case, kni application will continue work in PA mode without any issues. KNI module decides it's iova mode that application has communicated during kni allocation. If the user expectation is to make KNI application work in VA mode, the check has to be dynamic than. Please correct me if the issue that is anticipated is something different.

The dpdk application will request PA (since compiled in with no regard to the actual kni capabilities) and will refuse to run as non root user.
Which is already the case before this change.
Ok, maybe something to improve later if people wants to use kni as non root.

My other comments still apply though.

--
David Marchand

#218 lore raw

Re: [dpdk-dev] [PATCH v12 1/2] kni: add IOVA=VA mode support

In reply to David Marchand
Quoted 9 lines · David Marchand
Quoted 8 lines · On Tue, Nov 5, 2019 at 12:05 PM <[email protected]> wrote:
lib/librte_eal/linux/eal/eal.c +0 -0
index 9e2d50c..a1c5bf6 100644
@@ -922,6 +922,19 @@ static int rte_eal_vfio_setup(void)
 }
 #endif
 
Quoted 8 lines

lib/librte_eal/linux/eal/eal.c static int rte_eal_vfio_setup(void) · line 929

Quoted 5 lines
lib/librte_eal/linux/eal/eal.c +5 -0
+static enum rte_iova_mode
+rte_eal_kni_get_iova_mode(enum rte_iova_mode iova_mode)
+{
+       if (iova_mode == RTE_IOVA_VA) {
+#if KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE

I understood that IOVA as VA is possible with kernel >= 4.6. Should it be < ?

I had read it backwards.
So, the check is ok.

[snip]

lib/librte_eal/linux/eal/eal.c rte_eal_init(int argc, char **argv) · line 1089

Quoted 10 lines

In the end, can't we just change the check on the workaround? Something like:

lib/librte_eal/linux/eal/eal.c +1 -1
@@ -1085,7 +1085,7 @@ rte_eal_init(int argc, char **argv)
                                RTE_LOG(DEBUG, EAL, "IOMMU is not
 available, selecting IOVA as PA mode.\n");
                        }
                }
-#ifdef RTE_LIBRTE_KNI
+#if defined(RTE_LIBRTE_KNI) && KERNEL_VERSION(4, 6, 0) < LINUX_VERSION_CODE

Then it becomes:

+#if defined(RTE_LIBRTE_KNI) && KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE

Quoted 6 lines
(quoted diff) +0 -0
                /* Workaround for KNI which requires physical address to work */
                if (iova_mode == RTE_IOVA_VA &&
                                rte_eal_check_module("rte_kni") == 1) {

It would be the only change in the whole file lib/librte_eal/linux/eal/eal.c

Signature · 1 line
David Marchand
#219 lore raw

PATCH v12 2/2 kni: add IOVA=VA support in kernel module

In reply to [email protected]

From: Vamsi Attunuru <[email protected]>

Patch adds support for kernel module to work in IOVA = VA mode by providing address translation routines to convert IOVA aka user space VA to kernel virtual addresses.

When compared with IOVA=PA mode, there is no drop in performance with this approach, also there is no performance impact on IOVA=PA mode with this patch.

This approach does not work with the kernel versions less than 4.6.0.

---
 kernel/linux/kni/compat.h   | 15 +++++++++++
 kernel/linux/kni/kni_dev.h  | 42 ++++++++++++++++++++++++++++++
 kernel/linux/kni/kni_misc.c | 39 +++++++++++++++++++++-------
 kernel/linux/kni/kni_net.c  | 62 +++++++++++++++++++++++++++++++++++----------
 4 files changed, 136 insertions(+), 22 deletions(-)
kernel/linux/kni/compat.h +15 -0
index 562d8bf..6591dd7 100644
@@ -121,3 +121,18 @@
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
 #define HAVE_SIGNAL_FUNCTIONS_OWN_HEADER
 #endif
+
+#if KERNEL_VERSION(4, 6, 0) <= LINUX_VERSION_CODE
+
+#define HAVE_IOVA_TO_KVA_MAPPING_SUPPORT
+
+#if (KERNEL_VERSION(4, 6, 0) <= LINUX_VERSION_CODE) && \
+	(KERNEL_VERSION(4, 9, 0) > LINUX_VERSION_CODE)
+#define GET_USER_PAGES_REMOTE_API_V1
+#elif KERNEL_VERSION(4, 9, 0) == LINUX_VERSION_CODE
+#define GET_USER_PAGES_REMOTE_API_V2
+#else
+#define GET_USER_PAGES_REMOTE_API_V3
+#endif
+
+#endif
kernel/linux/kni/kni_dev.h +42 -0

56 lines not on this page · raw message

kernel/linux/kni/kni_misc.c +30 -9
index 84ef03b..cda71bd 100644
@@ -348,15 +348,36 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
 	strncpy(kni->name, dev_info.name, RTE_KNI_NAMESIZE);
 
 	/* Translate user space info into kernel space info */
-	kni->tx_q = phys_to_virt(dev_info.tx_phys);
-	kni->rx_q = phys_to_virt(dev_info.rx_phys);
-	kni->alloc_q = phys_to_virt(dev_info.alloc_phys);
-	kni->free_q = phys_to_virt(dev_info.free_phys);
-
-	kni->req_q = phys_to_virt(dev_info.req_phys);
-	kni->resp_q = phys_to_virt(dev_info.resp_phys);
-	kni->sync_va = dev_info.sync_va;
-	kni->sync_kva = phys_to_virt(dev_info.sync_phys);
+	if (dev_info.iova_mode) {
+#ifdef HAVE_IOVA_TO_KVA_MAPPING_SUPPORT
+		kni->tx_q = iova_to_kva(current, dev_info.tx_phys);
+		kni->rx_q = iova_to_kva(current, dev_info.rx_phys);
+		kni->alloc_q = iova_to_kva(current, dev_info.alloc_phys);
+		kni->free_q = iova_to_kva(current, dev_info.free_phys);
+
+		kni->req_q = iova_to_kva(current, dev_info.req_phys);
+		kni->resp_q = iova_to_kva(current, dev_info.resp_phys);
+		kni->sync_va = dev_info.sync_va;
+		kni->sync_kva = iova_to_kva(current, dev_info.sync_phys);
+		kni->usr_tsk = current;
+		kni->iova_mode = 1;
+#else
+		pr_err("KNI module does not support IOVA to VA translation\n");
+		return -EINVAL;
+#endif
+	} else {
+
+		kni->tx_q = phys_to_virt(dev_info.tx_phys);
+		kni->rx_q = phys_to_virt(dev_info.rx_phys);
+		kni->alloc_q = phys_to_virt(dev_info.alloc_phys);
+		kni->free_q = phys_to_virt(dev_info.free_phys);
+
+		kni->req_q = phys_to_virt(dev_info.req_phys);
+		kni->resp_q = phys_to_virt(dev_info.resp_phys);
+		kni->sync_va = dev_info.sync_va;
+		kni->sync_kva = phys_to_virt(dev_info.sync_phys);
+		kni->iova_mode = 0;
+	}
 
 	kni->mbuf_size = dev_info.mbuf_size;
 
kernel/linux/kni/kni_net.c +49 -13

119 lines not on this page · raw message

Signature · 1 line
2.8.4
#220 lore raw

Re: [dpdk-dev] [PATCH v12 0/2] add IOVA=VA mode support

In reply to [email protected]

For info, the mempool patches are merged now.

05/11/2019 12:04, [email protected]:

Quoted 3 lines

Vamsi Attunuru (2):
kni: add IOVA=VA mode support
kni: add IOVA=VA support in kernel module

Should the kernel support be the first patch?

About the titles, can it be simply "support IOVA mode"?

#221 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v12 0/2] add IOVA=VA mode support

Quoted 17 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Wednesday, November 6, 2019 4:19 PM
To: Vamsi Krishna Attunuru <[email protected]>
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [EXT] Re: [dpdk-dev] [PATCH v12 0/2] add IOVA=VA mode support

External Email

----------------------------------------------------------------------
For info, the mempool patches are merged now.

Quoted 6 lines

05/11/2019 12:04, [email protected]:

Quoted 3 lines

Vamsi Attunuru (2):
kni: add IOVA=VA mode support
kni: add IOVA=VA support in kernel module

Should the kernel support be the first patch?

But required variable iova_mode is defined in first patch currently.
Either one is fine to me. Please let me know if want to put kernel support patch at first, I will send next version accordingly.

Quoted 2 lines

About the titles, can it be simply "support IOVA mode"?

Yes, "support IOVA_VA mode" should be fine.

Quoted 1 line
#222 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v12 0/2] add IOVA=VA mode support

06/11/2019 12:09, Vamsi Krishna Attunuru:

Quoted 8 lines

From: Thomas Monjalon <[email protected]>

Quoted 6 lines

05/11/2019 12:04, [email protected]:

Quoted 3 lines

Vamsi Attunuru (2):
kni: add IOVA=VA mode support
kni: add IOVA=VA support in kernel module

Should the kernel support be the first patch?

Quoted 7 lines

But required variable iova_mode is defined in first patch currently.
Either one is fine to me. Please let me know if want to put kernel support patch at first, I will send next version accordingly.

Quoted 2 lines

About the titles, can it be simply "support IOVA mode"?

Yes, "support IOVA_VA mode" should be fine.

I really dislike the name IOVA_VA.

You mean support virtual IO addressing?

#223 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v12 0/2] add IOVA=VA mode support

Quoted 26 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Wednesday, November 6, 2019 5:23 PM
To: Vamsi Krishna Attunuru <[email protected]>
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [EXT] Re: [dpdk-dev] [PATCH v12 0/2] add IOVA=VA mode support

06/11/2019 12:09, Vamsi Krishna Attunuru:

Quoted 10 lines

From: Thomas Monjalon <[email protected]>

Quoted 6 lines

05/11/2019 12:04, [email protected]:

Quoted 3 lines

Vamsi Attunuru (2):
kni: add IOVA=VA mode support
kni: add IOVA=VA support in kernel module

Should the kernel support be the first patch?

But required variable iova_mode is defined in first patch currently. Either one is fine to me. Please let me know if want to put kernel support

patch at first, I will send next version accordingly.

Quoted 2 lines
Quoted 2 lines
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

About the titles, can it be simply "support IOVA mode"?

Yes, "support IOVA_VA mode" should be fine.

I really dislike the name IOVA_VA.

You mean support virtual IO addressing?

Yes.

#224 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v12 0/2] add IOVA=VA mode support

In reply to Vamsi Krishna Attunuru

Hi Ferruh,

Could you please review v12.

Regards,
A Vamsi

Quoted 44 lines

-----Original Message-----
From: Vamsi Krishna Attunuru
Sent: Wednesday, November 6, 2019 4:39 PM
To: Thomas Monjalon <[email protected]>
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [EXT] Re: [dpdk-dev] [PATCH v12 0/2] add IOVA=VA mode support

Quoted 16 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Wednesday, November 6, 2019 4:19 PM
To: Vamsi Krishna Attunuru <[email protected]>
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [EXT] Re: [dpdk-dev] [PATCH v12 0/2] add IOVA=VA mode support

External Email

----------------------------------------------------------------------
For info, the mempool patches are merged now.

Quoted 6 lines

05/11/2019 12:04, [email protected]:

Quoted 3 lines

Vamsi Attunuru (2):
kni: add IOVA=VA mode support
kni: add IOVA=VA support in kernel module

Should the kernel support be the first patch?

But required variable iova_mode is defined in first patch currently. Either one is fine to me. Please let me know if want to put kernel support patch at first, I will send next version accordingly.

Quoted 2 lines

About the titles, can it be simply "support IOVA mode"?

Yes, "support IOVA_VA mode" should be fine.

Quoted 1 line
#225 lore raw

Re: [dpdk-dev] [PATCH v12 0/2] add IOVA=VA mode support

In reply to [email protected]
Quoted 8 lines · On 11/5/2019 11:04 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

---
V12 Changes:
* Removed previously added --legacy-kni eal option.
* Removed previously added kni specific mempool create routines and mempool populate routines.

Quoted 5 lines

This patch set(V12) is dependent on following patch set, since the mempool related support to enable KNI in IOVA=VA mode is taken care in below patchset.

   https://patchwork.dpdk.org/cover/62376/

Hi Vasim, Jerin,

Overall looks good and I not getting any functional error but I am observing a huge performance drop with this update, 3.8Mpps to 0.7Mpps [1].

I don't know really what to do, I think we need to give a decision as community, and even we go with the patch we should document this performance drop clearly and document how to mitigate it.

[1]
This is with kni sample application,
a) IOVA=VA mode selected
./examples/kni/build/kni -l0,40-47 --log-level=*:debug -- -p 0x3 -P --config "(0,44,45,40),(1,46,47,41)"

forwarding performance is around 0.7Mpps and 'kni_single' kernel thread consumes all cpu.

b) IOVA=PA mode forced
./examples/kni/build/kni -l0,40-47 --log-level=*:debug --iova=pa -- -p 0x3 -P --config "(0,44,45,40),(1,46,47,41)"

forwarding performance is around 3.8Mpps and 'kni_single' core utilization is ~80%.

I am on 5.1.20-300.fc30.x86_64 kernel.
kni module inserted as: "insmod ./build/kmod/rte_kni.ko lo_mode=lo_mode_fifo"

Quoted 73 lines

V11 Changes:
* Added iova to kva address translation routines in kernel module to make it work in iova=va mode which enables DPDK to create kni devices on any kind of backed device/memory.
* Added ``--legacy-kni`` eal option to make existing KNI applications work with DPDK 19.11 and later versions.
* Removed previously added pci device info from kni device info struct.

V10 Changes:
* Fixed function return code on failure when min_chunk_size > pg_sz.
* Marked new mempool populate routine as EXPERIMENTAL.

V9 Changes:
* Used rte_mempool_ops_calc_mem_size() instead of default handler in the new mempool populate routine.
* Check min_chunk_size and return values.
* Removed ethdev_info memset to '0' and moved pci dev_info populate into kni_dev_pci_addr_get() routine.
* Addressed misc. review comments.

V8 Changes:
* Remove default mempool populate() routine changes.
* Add kni app specific mempool create & free routines.
* Add new mempool populate routine to allocate page-aligned memzones with page size to make sure all mempool objects reside on a page.
* Update release notes and map files.

V7 Changes:
* Removed previously proposed mempool flag and made those page boundary checks default in mempool populate() except for the objects size bigger than the size of page.
* Removed KNI example application related changes since pool related requirement is taken care in mempool lib.
* All PCI dev related info is moved under rte_eal_iova_mode() == VA check.
* Added wrapper functions in KNI module to hide IOVA checks and make address translation routines more readable.
* Updated IOVA mode checks that enforcing IOVA=PA mode when IOVA=VA mode is enabled.

V6 Changes:
* Added new mempool flag to ensure mbuf memory is not scattered across page boundaries.
* Added KNI kernel module required PCI device information.
* Modified KNI example application to create mempool with new mempool flag.

V5 changes:
* Fixed build issue with 32b build

V4 changes:
* Fixed build issues with older kernel versions
* This approach will only work with kernel above 4.4.0

V3 Changes:
* Add new approach to work kni with IOVA=VA mode using iommu_iova_to_phys API.

Vamsi Attunuru (2):
kni: add IOVA=VA mode support
kni: add IOVA=VA support in kernel module

 doc/guides/prog_guide/kernel_nic_interface.rst    |  9 ++++
 doc/guides/rel_notes/release_19_11.rst            |  5 ++
 kernel/linux/kni/compat.h                         | 15 ++++++
 kernel/linux/kni/kni_dev.h                        | 42 +++++++++++++++
 kernel/linux/kni/kni_misc.c                       | 39 ++++++++++----
 kernel/linux/kni/kni_net.c                        | 62 ++++++++++++++++++-----
 lib/librte_eal/linux/eal/eal.c                    | 29 ++++++-----
 lib/librte_eal/linux/eal/include/rte_kni_common.h |  1 +
 lib/librte_kni/rte_kni.c                          |  7 +--
 9 files changed, 170 insertions(+), 39 deletions(-)
#226 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v12 0/2] add IOVA=VA mode support

Quoted 49 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Friday, November 8, 2019 1:23 AM
To: Vamsi Krishna Attunuru <[email protected]>; [email protected]
Cc: [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [EXT] Re: [dpdk-dev] [PATCH v12 0/2] add IOVA=VA mode support

External Email

----------------------------------------------------------------------

Quoted 18 lines · On 11/5/2019 11:04 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

---

V12 Changes:

* Removed previously added --legacy-kni eal option.

* Removed previously added kni specific mempool create routines

and mempool populate routines.

This patch set(V12) is dependent on following patch set, since the mempool

Quoted 7 lines

related support to enable KNI in IOVA=VA mode is taken care in below

patchset.

https://urldefense.proofpoint.com/v2/url?u=https-

3A__patchwork.dpdk.org_cover_62376_&d=DwIDaQ&c=nKjWec2b6R0mOyPaz7 xtfQ&r=WllrYaumVkxaWjgKto6E_rtDQshhIhik2jkvzFyRhW8&m=sEREtIZWQwtHJ CxXRRv8euBGdr5q6K4L8Kz7PI25QcY&s=5Rz1dbSeIWt56cCtiwR6pfGprEFUumtcd 34TmF3sjs4&e=

Quoted 7 lines

Hi Vasim, Jerin,

Overall looks good and I not getting any functional error but I am observing a

huge performance drop with this update, 3.8Mpps to 0.7Mpps [1].

Hi Ferruh,

When it comes to actual kernel netdev test cases like iperf or any other use cases, there would not be any impact on performance. I think synthetic test case like loopback mode might not be the actual test case alone to depend on when the kernel module is featured to work with kind of devices(pdev or vdev). Users can always fallback to pa mode with cmd line option.

Please suggest your thoughts on considering what test case to use & evaluate the performance difference.

Quoted 202 lines

I don't know really what to do, I think we need to give a decision as community,

and even we go with the patch we should document this performance drop clearly

and document how to mitigate it.

[1]

This is with kni sample application,

a) IOVA=VA mode selected

./examples/kni/build/kni -l0,40-47 --log-level=*:debug -- -p 0x3 -P --config

"(0,44,45,40),(1,46,47,41)"

forwarding performance is around 0.7Mpps and 'kni_single' kernel thread consumes

all cpu.

b) IOVA=PA mode forced

./examples/kni/build/kni -l0,40-47 --log-level=*:debug --iova=pa -- -p 0x3 -P

--config "(0,44,45,40),(1,46,47,41)"

forwarding performance is around 3.8Mpps and 'kni_single' core utilization is ~80%.

I am on 5.1.20-300.fc30.x86_64 kernel.

kni module inserted as: "insmod ./build/kmod/rte_kni.ko lo_mode=lo_mode_fifo"

Quoted 145 lines

V11 Changes:

* Added iova to kva address translation routines in kernel module to

make it work in iova=va mode which enables DPDK to create kni devices

on any kind of backed device/memory.

* Added ``--legacy-kni`` eal option to make existing KNI applications

work with DPDK 19.11 and later versions.

* Removed previously added pci device info from kni device info struct.

V10 Changes:

* Fixed function return code on failure when min_chunk_size > pg_sz.

* Marked new mempool populate routine as EXPERIMENTAL.

V9 Changes:

* Used rte_mempool_ops_calc_mem_size() instead of default handler in the

new mempool populate routine.

* Check min_chunk_size and return values.

* Removed ethdev_info memset to '0' and moved pci dev_info populate into

kni_dev_pci_addr_get() routine.

* Addressed misc. review comments.

V8 Changes:

* Remove default mempool populate() routine changes.

* Add kni app specific mempool create & free routines.

* Add new mempool populate routine to allocate page-aligned memzones

with page size to make sure all mempool objects reside on a page.

* Update release notes and map files.

V7 Changes:

* Removed previously proposed mempool flag and made those page

boundary checks default in mempool populate() except for the objects size

bigger than the size of page.

* Removed KNI example application related changes since pool related

requirement is taken care in mempool lib.

* All PCI dev related info is moved under rte_eal_iova_mode() == VA check.

* Added wrapper functions in KNI module to hide IOVA checks and make

address translation routines more readable.

* Updated IOVA mode checks that enforcing IOVA=PA mode when IOVA=VA

mode is enabled.

V6 Changes:

* Added new mempool flag to ensure mbuf memory is not scattered across

page boundaries.

* Added KNI kernel module required PCI device information.

* Modified KNI example application to create mempool with new mempool

flag.

V5 changes:

* Fixed build issue with 32b build

V4 changes:

* Fixed build issues with older kernel versions

* This approach will only work with kernel above 4.4.0

V3 Changes:

* Add new approach to work kni with IOVA=VA mode using

iommu_iova_to_phys API.

Vamsi Attunuru (2):

kni: add IOVA=VA mode support

kni: add IOVA=VA support in kernel module

 doc/guides/prog_guide/kernel_nic_interface.rst    |  9 ++++
 doc/guides/rel_notes/release_19_11.rst            |  5 ++
 kernel/linux/kni/compat.h                         | 15 ++++++
 kernel/linux/kni/kni_dev.h                        | 42 +++++++++++++++
 kernel/linux/kni/kni_misc.c                       | 39 ++++++++++----
 kernel/linux/kni/kni_net.c                        | 62 ++++++++++++++++++-----
 lib/librte_eal/linux/eal/eal.c                    | 29 ++++++-----
 lib/librte_eal/linux/eal/include/rte_kni_common.h |  1 +
 lib/librte_kni/rte_kni.c                          |  7 +--
 9 files changed, 170 insertions(+), 39 deletions(-)
#227 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v12 0/2] add IOVA=VA mode support

Quoted 10 lines
Quoted 5 lines

Hi Vasim, Jerin,

Overall looks good and I not getting any functional error but I am observing a huge performance drop with this update, 3.8Mpps to 0.7Mpps [1].

Hi Ferruh,
When it comes to actual kernel netdev test cases like iperf or any other use cases, there would not be any impact on performance. I think synthetic test case like loopback mode might not be the actual test case alone to depend on when the kernel module is featured to work with kind of devices(pdev or vdev). Users can always fallback to pa mode with cmd line option.

Please suggest your thoughts on considering what test case to use & evaluate the performance difference.

Hi Vasim,

I also assume the real life test cases will be affected less, but the loopback performance testing is good to show performance impact of the change.

(Stephen's predictions that KNI is not as fast as tun/tap are getting more real by time J)

At least I think the possible performance drop and how to mitigate it should be documented both in release notes and kni documentation.

For the final decision, I am not objecting it but I would like to see more ack from community to confirm that we trade off iova=va functionality against performance.

@Jerin, @Thomas, should we conclude this in techboard? Perhaps we can get it for rc2 and drop it back if rejected in techboard?

Regards,
ferruh

#228 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v12 0/2] add IOVA=VA mode support

Quoted 10 lines · Ferruh Yigit
Quoted 10 lines
Quoted 6 lines

Hi Vasim, Jerin,

Overall looks good and I not getting any functional error but I am observing a huge performance drop with this update, 3.8Mpps to 0.7Mpps [1].

Hi Ferruh,
When it comes to actual kernel netdev test cases like iperf or any other use cases, there would not be any impact on performance. I think synthetic test case like loopback mode might not be the actual test case alone to depend on when the kernel module is featured to work with kind of devices(pdev or vdev). Users can always fallback to pa mode with cmd line option.

Quoted 6 lines
Quoted 1 line

Please suggest your thoughts on considering what test case to use & evaluate the performance difference.

Hi Vasim,

I also assume the real life test cases will be affected less, but the loopback performance testing is good to show performance impact of the change.

Yes. real-world case Linux kernel stack will be the bottleneck.

Quoted 6 lines

(Stephen's predictions that KNI is not as fast as tun/tap are getting more real by time J)

At least I think the possible performance drop and how to mitigate it should be documented both in release notes and kni documentation.

+1 for adding documentation. Setting iova-mode=pa will be mitigation if the application does
not care about iova-mode.

Quoted 4 lines

For the final decision, I am not objecting it but I would like to see more ack from community to confirm that we trade off iova=va functionality against performance.

In my view, IOVA as VA mode case, translation cannot be avoided and we have the requirement
where it needs to work with vdev(where is not backed by any IOMMU context) so I am not sure how to avoid the translation cost. Since we have support for both modes,i.e
existing IOVA as PA path still exists, I don't think, we are losing anything.

Quoted 5 lines

@Jerin, @Thomas, should we conclude this in techboard? Perhaps we can get it for rc2 and drop it back if rejected in techboard?

Regards,
ferruh

#229 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v12 0/2] add IOVA=VA mode support

Quoted 55 lines

-----Original Message-----
From: Jerin Jacob <[email protected]>
Sent: Friday, November 8, 2019 8:24 PM
To: Ferruh Yigit <[email protected]>
Cc: Vamsi Krishna Attunuru <[email protected]>; [email protected]; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [EXT] Re: [PATCH v12 0/2] add IOVA=VA mode support

Quoted 6 lines · Ferruh Yigit
Quoted 6 lines
Quoted 6 lines

Hi Vasim, Jerin,

Overall looks good and I not getting any functional error but I am observing a huge performance drop with this update, 3.8Mpps to 0.7Mpps

[1].

Quoted 3 lines
Quoted 3 lines

Hi Ferruh,
When it comes to actual kernel netdev test cases like iperf or any other use

cases, there would not be any impact on performance. I think synthetic test case like loopback mode might not be the actual test case alone to depend on when the kernel module is featured to work with kind of devices(pdev or vdev). Users can always fallback to pa mode with cmd line option.

Quoted 2 lines
Quoted 2 lines

Please suggest your thoughts on considering what test case to use &

evaluate the performance difference.

Quoted 5 lines

Hi Vasim,

I also assume the real life test cases will be affected less, but the loopback performance testing is good to show performance impact of the

change.

Yes. real-world case Linux kernel stack will be the bottleneck.

Quoted 6 lines

(Stephen's predictions that KNI is not as fast as tun/tap are getting more real by time J)

At least I think the possible performance drop and how to mitigate it should be documented both in release notes and kni documentation.

+1 for adding documentation. Setting iova-mode=pa will be mitigation if the application does
not care about iova-mode.

Quoted 4 lines

For the final decision, I am not objecting it but I would like to see more ack from community to confirm that we trade off iova=va functionality against performance.

Quoted 9 lines

In my view, IOVA as VA mode case, translation cannot be avoided and we have the requirement where it needs to work with vdev(where is not backed by any IOMMU context) so I am not sure how to avoid the translation cost. Since we have support for both modes,i.e existing IOVA as PA path still exists, I don't think, we are losing anything.

Quoted 3 lines

@Jerin, @Thomas, should we conclude this in techboard? Perhaps we can get it for
rc2 and drop it back if rejected in techboard?

Hi Ferruh,

Any update on the conclusion about the acceptance of patch set. I will send the next version of patch set with updated documentation part on performance impact if there are no other concerns.

Regards
A Vamsi

Quoted 3 lines
Quoted 3 lines

Regards,
ferruh

#230 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v12 0/2] add IOVA=VA mode support

Quoted 61 lines · Vamsi Krishna Attunuru
Quoted 61 lines

-----Original Message-----
From: Jerin Jacob <[email protected]>
Sent: Friday, November 8, 2019 8:24 PM
To: Ferruh Yigit <[email protected]>
Cc: Vamsi Krishna Attunuru <[email protected]>; [email protected]; [email protected]; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [EXT] Re: [PATCH v12 0/2] add IOVA=VA mode support

Quoted 6 lines · Ferruh Yigit
Quoted 6 lines
Quoted 6 lines

Hi Vasim, Jerin,

Overall looks good and I not getting any functional error but I am observing a huge performance drop with this update, 3.8Mpps to 0.7Mpps

[1].

Quoted 3 lines
Quoted 3 lines

Hi Ferruh,
When it comes to actual kernel netdev test cases like iperf or any other use

cases, there would not be any impact on performance. I think synthetic test case like loopback mode might not be the actual test case alone to depend on when the kernel module is featured to work with kind of devices(pdev or vdev). Users can always fallback to pa mode with cmd line option.

Quoted 2 lines
Quoted 2 lines

Please suggest your thoughts on considering what test case to use &

evaluate the performance difference.

Quoted 5 lines

Hi Vasim,

I also assume the real life test cases will be affected less, but the loopback performance testing is good to show performance impact of the

change.

Yes. real-world case Linux kernel stack will be the bottleneck.

Quoted 6 lines

(Stephen's predictions that KNI is not as fast as tun/tap are getting more real by time J)

At least I think the possible performance drop and how to mitigate it should be documented both in release notes and kni documentation.

+1 for adding documentation. Setting iova-mode=pa will be mitigation if the application does
not care about iova-mode.

Quoted 4 lines

For the final decision, I am not objecting it but I would like to see more ack from community to confirm that we trade off iova=va functionality against performance.

In my view, IOVA as VA mode case, translation cannot be avoided and we have the requirement where it needs to work with vdev(where is not backed by any IOMMU context) so I am not sure how to avoid the translation cost. Since we have support for both modes,i.e existing IOVA as PA path still exists, I don't think, we are losing anything.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

@Jerin, @Thomas, should we conclude this in techboard? Perhaps we can get it for
rc2 and drop it back if rejected in techboard?

Hi Ferruh,

Any update on the conclusion about the acceptance of patch set. I will send the next version of patch set with updated documentation part on performance impact if there are no other concerns.

Hi Vamsi,

From my perspective there is no other change request than the documentation update, I suggest sending new version.

For the final decision, it can be in technical board but there is no meeting this week, so I will start an offline discussion.

Thanks,
ferruh

#231 lore raw

v13 cover kni: support IOVA mode

In reply to [email protected]

From: Vamsi Attunuru <[email protected]>

---
V13 Changes:
* For KNI case, to restore the existing behaviour, forcing IOVA as PA if bus iommu returns IOVA_DC.
* Restored phys_addr and kni_lib defination checks.
* Simplified patch titles.
* Updated documentation about patch set's impact on performance and kernel version requirement.

V12 Changes:
* Removed previously added --legacy-kni eal option.
* Removed previously added kni specific mempool create routines and mempool populate routines.

V11 Changes:
* Added iova to kva address translation routines in kernel module to make it work in iova=va mode which enables DPDK to create kni devices on any kind of backed device/memory.
* Added ``--legacy-kni`` eal option to make existing KNI applications work with DPDK 19.11 and later versions.
* Removed previously added pci device info from kni device info struct.

V10 Changes:
* Fixed function return code on failure when min_chunk_size > pg_sz.
* Marked new mempool populate routine as EXPERIMENTAL.

V9 Changes:
* Used rte_mempool_ops_calc_mem_size() instead of default handler in the new mempool populate routine.
* Check min_chunk_size and return values.
* Removed ethdev_info memset to '0' and moved pci dev_info populate into kni_dev_pci_addr_get() routine.
* Addressed misc. review comments.

V8 Changes:
* Remove default mempool populate() routine changes.
* Add kni app specific mempool create & free routines.
* Add new mempool populate routine to allocate page-aligned memzones with page size to make sure all mempool objects reside on a page.
* Update release notes and map files.

V7 Changes:
* Removed previously proposed mempool flag and made those page boundary checks default in mempool populate() except for the objects size bigger than the size of page.
* Removed KNI example application related changes since pool related requirement is taken care in mempool lib.
* All PCI dev related info is moved under rte_eal_iova_mode() == VA check.
* Added wrapper functions in KNI module to hide IOVA checks and make address translation routines more readable.
* Updated IOVA mode checks that enforcing IOVA=PA mode when IOVA=VA mode is enabled.

V6 Changes:
* Added new mempool flag to ensure mbuf memory is not scattered across page boundaries.
* Added KNI kernel module required PCI device information.
* Modified KNI example application to create mempool with new mempool flag.

V5 changes:
* Fixed build issue with 32b build

V4 changes:
* Fixed build issues with older kernel versions
* This approach will only work with kernel above 4.4.0

Vamsi Attunuru (2):
kni: support IOVA mode in kernel module
kni: support IOVA mode

 doc/guides/prog_guide/kernel_nic_interface.rst    | 14 +++++
 doc/guides/rel_notes/release_19_11.rst            | 12 ++++-
 kernel/linux/kni/compat.h                         | 14 +++++
 kernel/linux/kni/kni_dev.h                        | 42 +++++++++++++++
 kernel/linux/kni/kni_misc.c                       | 39 ++++++++++----
 kernel/linux/kni/kni_net.c                        | 62 ++++++++++++++++++-----
 lib/librte_eal/linux/eal/eal.c                    | 19 ++++---
 lib/librte_eal/linux/eal/include/rte_kni_common.h |  1 +
 lib/librte_kni/rte_kni.c                          |  6 +++
 9 files changed, 180 insertions(+), 29 deletions(-)
Signature · 1 line
2.8.4
#232 lore raw

PATCH v13 1/2 kni: support IOVA mode in kernel module

From: Vamsi Attunuru <[email protected]>

Patch adds support for kernel module to work in IOVA = VA mode by providing address translation routines to convert IOVA aka user space VA to kernel virtual addresses.

When compared with IOVA = PA mode, KNI netdev ports does not have any impact on performance with this approach, also there is no performance impact on IOVA = PA mode with this patch.

This approach does not work with the kernel versions less than 4.6.0.

---
 kernel/linux/kni/compat.h                         | 14 +++++
 kernel/linux/kni/kni_dev.h                        | 42 +++++++++++++++
 kernel/linux/kni/kni_misc.c                       | 39 ++++++++++----
 kernel/linux/kni/kni_net.c                        | 62 ++++++++++++++++++-----
 lib/librte_eal/linux/eal/include/rte_kni_common.h |  1 +
 5 files changed, 136 insertions(+), 22 deletions(-)
kernel/linux/kni/compat.h +14 -0
index 562d8bf..062b170 100644
@@ -121,3 +121,17 @@
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
 #define HAVE_SIGNAL_FUNCTIONS_OWN_HEADER
 #endif
+
+#if KERNEL_VERSION(4, 6, 0) <= LINUX_VERSION_CODE
+
+#define HAVE_IOVA_TO_KVA_MAPPING_SUPPORT
+
+#if KERNEL_VERSION(4, 9, 0) > LINUX_VERSION_CODE
+#define GET_USER_PAGES_REMOTE_API_V1
+#elif KERNEL_VERSION(4, 9, 0) == LINUX_VERSION_CODE
+#define GET_USER_PAGES_REMOTE_API_V2
+#else
+#define GET_USER_PAGES_REMOTE_API_V3
+#endif
+
+#endif
kernel/linux/kni/kni_dev.h +42 -0

56 lines not on this page · raw message

kernel/linux/kni/kni_misc.c +30 -9
index 84ef03b..cda71bd 100644
@@ -348,15 +348,36 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num,
 	strncpy(kni->name, dev_info.name, RTE_KNI_NAMESIZE);
 
 	/* Translate user space info into kernel space info */
-	kni->tx_q = phys_to_virt(dev_info.tx_phys);
-	kni->rx_q = phys_to_virt(dev_info.rx_phys);
-	kni->alloc_q = phys_to_virt(dev_info.alloc_phys);
-	kni->free_q = phys_to_virt(dev_info.free_phys);
-
-	kni->req_q = phys_to_virt(dev_info.req_phys);
-	kni->resp_q = phys_to_virt(dev_info.resp_phys);
-	kni->sync_va = dev_info.sync_va;
-	kni->sync_kva = phys_to_virt(dev_info.sync_phys);
+	if (dev_info.iova_mode) {
+#ifdef HAVE_IOVA_TO_KVA_MAPPING_SUPPORT
+		kni->tx_q = iova_to_kva(current, dev_info.tx_phys);
+		kni->rx_q = iova_to_kva(current, dev_info.rx_phys);
+		kni->alloc_q = iova_to_kva(current, dev_info.alloc_phys);
+		kni->free_q = iova_to_kva(current, dev_info.free_phys);
+
+		kni->req_q = iova_to_kva(current, dev_info.req_phys);
+		kni->resp_q = iova_to_kva(current, dev_info.resp_phys);
+		kni->sync_va = dev_info.sync_va;
+		kni->sync_kva = iova_to_kva(current, dev_info.sync_phys);
+		kni->usr_tsk = current;
+		kni->iova_mode = 1;
+#else
+		pr_err("KNI module does not support IOVA to VA translation\n");
+		return -EINVAL;
+#endif
+	} else {
+
+		kni->tx_q = phys_to_virt(dev_info.tx_phys);
+		kni->rx_q = phys_to_virt(dev_info.rx_phys);
+		kni->alloc_q = phys_to_virt(dev_info.alloc_phys);
+		kni->free_q = phys_to_virt(dev_info.free_phys);
+
+		kni->req_q = phys_to_virt(dev_info.req_phys);
+		kni->resp_q = phys_to_virt(dev_info.resp_phys);
+		kni->sync_va = dev_info.sync_va;
+		kni->sync_kva = phys_to_virt(dev_info.sync_phys);
+		kni->iova_mode = 0;
+	}
 
 	kni->mbuf_size = dev_info.mbuf_size;
 
kernel/linux/kni/kni_net.c +49 -13

119 lines not on this page · raw message

lib/librte_eal/linux/eal/include/rte_kni_common.h +1 -0
index 46f75a7..2427a96 100644
@@ -125,6 +125,7 @@ struct rte_kni_device_info {
 	unsigned int min_mtu;
 	unsigned int max_mtu;
 	uint8_t mac_addr[6];
+	uint8_t iova_mode;
 };
 
 #define KNI_DEVICE "kni"
Signature · 1 line
2.8.4
#233 lore raw

PATCH v13 2/2 kni: support IOVA mode

In reply to [email protected]

From: Vamsi Attunuru <[email protected]>

Current KNI implementation only operates in IOVA_PA mode patch adds required functionality to enable KNI in IOVA_VA mode.

KNI loopback mode tests will have performance impact in this mode due to IOVA to KVA address translations. However, In KNI real world use cases, the performace impact will be based on Linux kernel stack and scheduler latencies. Performance varies based on the KNI use case. If bus iommu scheme is IOVA_DC and KNI module is loaded, DPDK chooses IOVA as PA as existing behaviour.

During KNI creation, app's iova_mode details are passed to the KNI kernel module, accordingly kernel module translates PA/IOVA addresses to KVA and vice-versa.

---
 doc/guides/prog_guide/kernel_nic_interface.rst | 15 +++++++++++++++
 doc/guides/rel_notes/release_19_11.rst         | 15 ++++++++++++++-
 lib/librte_eal/linux/eal/eal.c                 | 23 ++++++++++++++++-------
 lib/librte_kni/rte_kni.c                       |  6 ++++++
 4 files changed, 51 insertions(+), 8 deletions(-)
doc/guides/prog_guide/kernel_nic_interface.rst +15 -0
index 2fd58e1..3bed18f 100644
@@ -300,6 +300,21 @@ The sk_buff is then freed and the mbuf sent in the tx_q FIFO.
 The DPDK TX thread dequeues the mbuf and sends it to the PMD via ``rte_eth_tx_burst()``.
 It then puts the mbuf back in the cache.
 
+IOVA = VA: Support
+------------------
+
+KNI operates in IOVA_VA scheme when
+
+- LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) and
+- eal option `iova-mode=va` is passed or bus IOVA scheme in the DPDK is selected
+  as RTE_IOVA_VA.
+
+KNI loopback mode tests will have performance impact in this mode due to IOVA to
+KVA address translations. However, In KNI real world use cases, the performace
+impact will be based on Linux kernel stack and scheduler latencies. Performance
+varies based on the KNI use case. If bus iommu scheme is IOVA_DC and KNI module
+is loaded, DPDK chooses IOVA as PA as existing behaviour.
+
 Ethtool
 -------
 
doc/guides/rel_notes/release_19_11.rst +14 -1
index 682c1bd..c207c93 100644
@@ -292,8 +292,21 @@ New Features
   compilers store their internal representation of the source code that
   the linker uses at the final stage of compilation process.
 
-  See :doc:`../prog_guide/lto` for more information:
+* **Added IOVA as VA support for KNI.**
+
+  * Added IOVA = VA support for KNI, KNI can operate in IOVA = VA mode when
+    `iova-mode=va` eal option is passed to the application or when bus IOVA
+    scheme is selected as RTE_IOVA_VA. This mode only works on Linux Kernel
+    versions 4.6.0 and above.
 
+  * KNI loopback mode tests will have performance impact in this mode due
+    to IOVA to KVA address translations. However, In KNI real world use cases,
+    the performace impact will be based on Linux kernel stack and scheduler
+    latencies. Performance varies based on the KNI use case. If bus iommu
+    scheme is IOVA_DC and KNI module is loaded, DPDK chooses IOVA as PA as
+    existing behaviour.
+
+  See :doc:`../prog_guide/lto` for more information:
 
 
 Removed Items
lib/librte_eal/linux/eal/eal.c +16 -7
index 9e2d50c..53ca84b 100644
@@ -1086,14 +1086,23 @@ rte_eal_init(int argc, char **argv)
 			}
 		}
 #ifdef RTE_LIBRTE_KNI
-		/* Workaround for KNI which requires physical address to work */
-		if (iova_mode == RTE_IOVA_VA &&
-				rte_eal_check_module("rte_kni") == 1) {
-			if (phys_addrs) {
+		if (rte_eal_check_module("rte_kni") == 1) {
+#if KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE
+			if (iova_mode == RTE_IOVA_VA) {
 				iova_mode = RTE_IOVA_PA;
-				RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI module is loaded\n");
-			} else {
-				RTE_LOG(DEBUG, EAL, "KNI can not work since physical addresses are unavailable\n");
+				RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because "
+						"Kernel version supports only 'PA' mode for KNI module\n");
+			}
+#endif
+			if (rte_bus_get_iommu_class() == RTE_IOVA_DC)
+				iova_mode = RTE_IOVA_PA;
+
+			if (iova_mode == RTE_IOVA_PA) {
+				if (phys_addrs && is_iommu_enabled())
+					RTE_LOG(WARNING, EAL, "Forced IOVA as 'PA' because KNI module is loaded\n");
+
+				if (!phys_addrs)
+					RTE_LOG(DEBUG, EAL, "KNI can not work since physical addresses are unavailable\n");
 			}
 		}
 #endif
lib/librte_kni/rte_kni.c +6 -0
index 7fbcf22..a609d2f 100644
@@ -6,6 +6,8 @@
 #error "KNI is not supported"
 #endif
 
+#include <linux/version.h>
+
 #include <string.h>
 #include <fcntl.h>
 #include <unistd.h>
@@ -97,10 +99,12 @@ static volatile int kni_fd = -1;
 int
 rte_kni_init(unsigned int max_kni_ifaces __rte_unused)
 {
+#if KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE
 	if (rte_eal_iova_mode() != RTE_IOVA_PA) {
 		RTE_LOG(ERR, KNI, "KNI requires IOVA as PA\n");
 		return -1;
 	}
+#endif
 
 	/* Check FD and open */
 	if (kni_fd < 0) {
@@ -302,6 +306,8 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
 	kni->group_id = conf->group_id;
 	kni->mbuf_size = conf->mbuf_size;
 
+	dev_info.iova_mode = (rte_eal_iova_mode() == RTE_IOVA_VA) ? 1 : 0;
+
 	ret = ioctl(kni_fd, RTE_KNI_IOCTL_CREATE, &dev_info);
 	if (ret < 0)
 		goto ioctl_fail;
Signature · 1 line
2.8.4
#234 lore raw

Re: [dpdk-dev] [PATCH v13 2/2] kni: support IOVA mode

Quoted 40 lines · On 11/15/2019 11:18 AM, [email protected] wrote:

From: Vamsi Attunuru <[email protected]>

Current KNI implementation only operates in IOVA_PA mode patch adds required functionality to enable KNI in IOVA_VA mode.

KNI loopback mode tests will have performance impact in this mode due to IOVA to KVA address translations. However, In KNI real world use cases, the performace impact will be based on Linux kernel stack and scheduler latencies. Performance varies based on the KNI use case. If bus iommu scheme is IOVA_DC and KNI module is loaded, DPDK chooses IOVA as PA as existing behaviour.

During KNI creation, app's iova_mode details are passed to the KNI kernel module, accordingly kernel module translates PA/IOVA addresses to KVA and vice-versa.

---
 doc/guides/prog_guide/kernel_nic_interface.rst | 15 +++++++++++++++
 doc/guides/rel_notes/release_19_11.rst         | 15 ++++++++++++++-
 lib/librte_eal/linux/eal/eal.c                 | 23 ++++++++++++++++-------
 lib/librte_kni/rte_kni.c                       |  6 ++++++
 4 files changed, 51 insertions(+), 8 deletions(-)
doc/guides/prog_guide/kernel_nic_interface.rst +4 -0
index 2fd58e1..3bed18f 100644
@@ -300,6 +300,21 @@ The sk_buff is then freed and the mbuf sent in the tx_q FIFO.
 The DPDK TX thread dequeues the mbuf and sends it to the PMD via ``rte_eth_tx_burst()``.
 It then puts the mbuf back in the cache.
 
+IOVA = VA: Support
+------------------
+
+KNI operates in IOVA_VA scheme when

doc/guides/prog_guide/kernel_nic_interface.rst The sk_buff is then freed and the mbuf sent in the tx_q FIFO. · line 316

Quoted 10 lines
doc/guides/prog_guide/kernel_nic_interface.rst +10 -0
+
+- LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) and
+- eal option `iova-mode=va` is passed or bus IOVA scheme in the DPDK is selected
+  as RTE_IOVA_VA.
+
+KNI loopback mode tests will have performance impact in this mode due to IOVA to
+KVA address translations. However, In KNI real world use cases, the performace
+impact will be based on Linux kernel stack and scheduler latencies. Performance
+varies based on the KNI use case. If bus iommu scheme is IOVA_DC and KNI module
+is loaded, DPDK chooses IOVA as PA as existing behaviour.

I understand you are trying to neglect the affect but mentioning the Linux kernel stack and scheduler latency etc is confusing I think, also I am for mentioning the availability of the eal "--iova-mode=pa" option, what about following like more simple message:

"
Due to IOVA to KVA address translations, based on the KNI use case there can be a performance impact. For mitigation forcing IOVA to PA via eal "--iova-mode=pa" option can be used.
"

IOVA_DC bus iommu scheme resulting IOVA as PA either can be another paragraph I think, as a single sentences.

#235 lore raw

Re: [dpdk-dev] [PATCH v13 2/2] kni: support IOVA mode

In reply to [email protected]

I can't see an interest in splitting this patch from the kmod update. Ferruh, what do you think?

Quoted 10 lines · On Fri, Nov 15, 2019 at 12:19 PM <[email protected]> wrote:

From: Vamsi Attunuru <[email protected]>

Current KNI implementation only operates in IOVA_PA mode patch adds required functionality to enable KNI in IOVA_VA mode.

KNI loopback mode tests will have performance impact in this mode due to IOVA to KVA address translations. However, In KNI real world use cases, the performace

performance

Quoted 19 lines

impact will be based on Linux kernel stack and scheduler latencies. Performance varies based on the KNI use case. If bus iommu scheme is IOVA_DC and KNI module is loaded, DPDK chooses IOVA as PA as existing behaviour.

During KNI creation, app's iova_mode details are passed to the KNI kernel module, accordingly kernel module translates PA/IOVA addresses to KVA and vice-versa.

---
 doc/guides/prog_guide/kernel_nic_interface.rst | 15 +++++++++++++++
 doc/guides/rel_notes/release_19_11.rst         | 15 ++++++++++++++-
 lib/librte_eal/linux/eal/eal.c                 | 23 ++++++++++++++++-------
 lib/librte_kni/rte_kni.c                       |  6 ++++++
 4 files changed, 51 insertions(+), 8 deletions(-)

[snip]

Quoted 15 lines
lib/librte_eal/linux/eal/eal.c +3 -4
index 9e2d50c..53ca84b 100644
@@ -1086,14 +1086,23 @@ rte_eal_init(int argc, char **argv)
                        }
                }
 #ifdef RTE_LIBRTE_KNI
-               /* Workaround for KNI which requires physical address to work */
-               if (iova_mode == RTE_IOVA_VA &&
-                               rte_eal_check_module("rte_kni") == 1) {
-                       if (phys_addrs) {
+               if (rte_eal_check_module("rte_kni") == 1) {
+#if KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE
+                       if (iova_mode == RTE_IOVA_VA) {

lib/librte_eal/linux/eal/eal.c rte_eal_init(int argc, char **argv) · line 1098

Quoted 10 lines
lib/librte_eal/linux/eal/eal.c +6 -3
                                iova_mode = RTE_IOVA_PA;
-                               RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI module is loaded\n");
-                       } else {
-                               RTE_LOG(DEBUG, EAL, "KNI can not work since physical addresses are unavailable\n");
+                               RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because "
+                                               "Kernel version supports only 'PA' mode for KNI module\n");
+                       }
+#endif
+                       if (rte_bus_get_iommu_class() == RTE_IOVA_DC)
+                               iova_mode = RTE_IOVA_PA;

If physical addresses are unavailable, this code forces PA anyway.

lib/librte_eal/linux/eal/eal.c rte_eal_init(int argc, char **argv) · line 1106

Quoted 8 lines
lib/librte_eal/linux/eal/eal.c +7 -0
+
+                       if (iova_mode == RTE_IOVA_PA) {
+                               if (phys_addrs && is_iommu_enabled())
+                                       RTE_LOG(WARNING, EAL, "Forced IOVA as 'PA' because KNI module is loaded\n");
+
+                               if (!phys_addrs)
+                                       RTE_LOG(DEBUG, EAL, "KNI can not work since physical addresses are unavailable\n");
                        }

Checking physical addresses availability after, and having a log is not enough.

So far, KNI could not work with IOVA as VA.
Your patchset adds support for IOVA as VA if kernel is >= 4.6. Repeating my proposal (as far as eal.c is concerned) of just changing:

@@ -1085,7 +1085,7 @@ rte_eal_init(int argc, char **argv)
RTE_LOG(DEBUG, EAL, "IOMMU is not
available, selecting IOVA as PA mode.\n");

                        }
                }
-#ifdef RTE_LIBRTE_KNI
+#if defined(RTE_LIBRTE_KNI) && KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE
                /* Workaround for KNI which requires physical address to work */
                if (iova_mode == RTE_IOVA_VA &&

--
David Marchand

#236 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v13 2/2] kni: support IOVA mode

Quoted 102 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Friday, November 15, 2019 6:29 PM
To: Vamsi Krishna Attunuru <[email protected]>; Yigit, Ferruh <[email protected]>
Cc: dev <[email protected]>; Thomas Monjalon <[email protected]>; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; Olivier Matz <[email protected]>; Burakov, Anatoly <[email protected]>; Andrew Rybchenko <[email protected]>; Stephen Hemminger <[email protected]>
Subject: [EXT] Re: [dpdk-dev] [PATCH v13 2/2] kni: support IOVA mode

External Email

----------------------------------------------------------------------
I can't see an interest in splitting this patch from the kmod update. Ferruh, what do you think?

Quoted 9 lines · On Fri, Nov 15, 2019 at 12:19 PM <[email protected]> wrote:

From: Vamsi Attunuru <[email protected]>

Current KNI implementation only operates in IOVA_PA mode patch adds required functionality to enable KNI in IOVA_VA mode.

KNI loopback mode tests will have performance impact in this mode due to IOVA to KVA address translations.
However, In KNI real world use cases, the performace

performance

Quoted 19 lines

impact will be based on Linux kernel stack and scheduler latencies. Performance varies based on the KNI use case.
If bus iommu scheme is IOVA_DC and KNI module is loaded, DPDK chooses IOVA as PA as existing behaviour.

During KNI creation, app's iova_mode details are passed to the KNI kernel module, accordingly kernel module translates PA/IOVA addresses to KVA and vice-versa.

---
 doc/guides/prog_guide/kernel_nic_interface.rst | 15 +++++++++++++++
 doc/guides/rel_notes/release_19_11.rst         | 15 ++++++++++++++-
 lib/librte_eal/linux/eal/eal.c                 | 23 ++++++++++++++++-------
 lib/librte_kni/rte_kni.c                       |  6 ++++++
 4 files changed, 51 insertions(+), 8 deletions(-)

[snip]

Quoted 7 lines
(quoted diff) +0 -0

b/lib/librte_eal/linux/eal/eal.c index 9e2d50c..53ca84b 100644

lib/librte_eal/linux/eal/eal.c +0 -0
@@ -1086,14 +1086,23 @@ rte_eal_init(int argc, char **argv)
                        }
                }

lib/librte_eal/linux/eal/eal.c rte_eal_init(int argc, char **argv) · line 1094

Quoted 10 lines
lib/librte_eal/linux/eal/eal.c +3 -5
 #ifdef RTE_LIBRTE_KNI
-               /* Workaround for KNI which requires physical address to work */
-               if (iova_mode == RTE_IOVA_VA &&
-                               rte_eal_check_module("rte_kni") == 1) {
-                       if (phys_addrs) {
+               if (rte_eal_check_module("rte_kni") == 1) { #if
+KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE
+                       if (iova_mode == RTE_IOVA_VA) {
                                iova_mode = RTE_IOVA_PA;
-                               RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI

module is loaded\n");

lib/librte_eal/linux/eal/eal.c rte_eal_init(int argc, char **argv) · line 1096

Quoted 2 lines
lib/librte_eal/linux/eal/eal.c +0 -2
-                       } else {
-                               RTE_LOG(DEBUG, EAL, "KNI can not work since physical

addresses are unavailable\n");

lib/librte_eal/linux/eal/eal.c rte_eal_init(int argc, char **argv) · line 1094

Quoted 2 lines
lib/librte_eal/linux/eal/eal.c +2 -0
+                               RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because "
+                                               "Kernel version supports only 'PA' mode for KNI

module\n");

lib/librte_eal/linux/eal/eal.c rte_eal_init(int argc, char **argv) · line 1098

Quoted 4 lines
lib/librte_eal/linux/eal/eal.c +4 -0
+                       }
+#endif
+                       if (rte_bus_get_iommu_class() == RTE_IOVA_DC)
+                               iova_mode = RTE_IOVA_PA;

If physical addresses are unavailable, this code forces PA anyway.

lib/librte_eal/linux/eal/eal.c rte_eal_init(int argc, char **argv) · line 1106

Quoted 10 lines
lib/librte_eal/linux/eal/eal.c +9 -0
+
+                       if (iova_mode == RTE_IOVA_PA) {
+                               if (phys_addrs && is_iommu_enabled())
+                                       RTE_LOG(WARNING, EAL, "Forced
+ IOVA as 'PA' because KNI module is loaded\n");
+
+                               if (!phys_addrs)
+                                       RTE_LOG(DEBUG, EAL, "KNI can
+ not work since physical addresses are unavailable\n");
                        }

Checking physical addresses availability after, and having a log is not enough.

Quoted 3 lines

So far, KNI could not work with IOVA as VA.
Your patchset adds support for IOVA as VA if kernel is >= 4.6. Repeating my proposal (as far as eal.c is concerned) of just changing:

To keep the existing behavior intact when bus iommu returns IOVA_DC, had to handle those case also here.

How about below scheme:

#ifdef RTE_LIBRTE_KNI
- /* Workaround for KNI which requires physical address to work */
- if (iova_mode == RTE_IOVA_VA &&
- rte_eal_check_module("rte_kni") == 1) {
- if (phys_addrs) {
- iova_mode = RTE_IOVA_PA;
- RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI module is loaded\n");
- } else {
- RTE_LOG(DEBUG, EAL, "KNI can not work since physical addresses are unavailable\n");
+ if (rte_eal_check_module("rte_kni") == 1) {
+ bool force_iova_as_pa = false;
+#if KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE
+ if (iova_mode == RTE_IOVA_VA) {
+ force_iova_as_pa = true;
+ RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because "
+ "Kernel version supports only 'PA' mode for KNI module\n");
+ }
+#endif
+ if (rte_bus_get_iommu_class() == RTE_IOVA_DC)
+ force_iova_as_pa = true;
+
+ if (force_iova_as_pa) {
+ if (phys_addrs) {
+ iova_mode = RTE_IOVA_PA;
+ RTE_LOG(WARNING, EAL, "Forced IOVA as 'PA' because KNI module is loaded\n");
+ } else
+ RTE_LOG(DEBUG, EAL, "KNI can not work since physical addresses are unavailable\n");

                        }
                }

#endif

Quoted 16 lines
(quoted diff) +2 -2
@@ -1085,7 +1085,7 @@ rte_eal_init(int argc, char **argv)
                                RTE_LOG(DEBUG, EAL, "IOMMU is not available, selecting
 IOVA as PA mode.\n");
                        }
                }
-#ifdef RTE_LIBRTE_KNI
+#if defined(RTE_LIBRTE_KNI) && KERNEL_VERSION(4, 6, 0) >
+LINUX_VERSION_CODE
                /* Workaround for KNI which requires physical address to work */
                if (iova_mode == RTE_IOVA_VA &&
 
 
 
--

David Marchand

#237 lore raw

Re: [dpdk-dev] [EXT] Re: [PATCH v13 2/2] kni: support IOVA mode

Quoted 103 lines · Vamsi Krishna Attunuru
Quoted 103 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: Friday, November 15, 2019 6:29 PM
To: Vamsi Krishna Attunuru <[email protected]>; Yigit, Ferruh <[email protected]>
Cc: dev <[email protected]>; Thomas Monjalon <[email protected]>; Jerin Jacob Kollanukkaran <[email protected]>; Kiran Kumar Kokkilagadda <[email protected]>; Olivier Matz <[email protected]>; Burakov, Anatoly <[email protected]>; Andrew Rybchenko <[email protected]>; Stephen Hemminger <[email protected]>
Subject: [EXT] Re: [dpdk-dev] [PATCH v13 2/2] kni: support IOVA mode

External Email

----------------------------------------------------------------------
I can't see an interest in splitting this patch from the kmod update. Ferruh, what do you think?

Quoted 9 lines · On Fri, Nov 15, 2019 at 12:19 PM <[email protected]> wrote:

From: Vamsi Attunuru <[email protected]>

Current KNI implementation only operates in IOVA_PA mode patch adds required functionality to enable KNI in IOVA_VA mode.

KNI loopback mode tests will have performance impact in this mode due to IOVA to KVA address translations.
However, In KNI real world use cases, the performace

performance

Quoted 19 lines

impact will be based on Linux kernel stack and scheduler latencies. Performance varies based on the KNI use case.
If bus iommu scheme is IOVA_DC and KNI module is loaded, DPDK chooses IOVA as PA as existing behaviour.

During KNI creation, app's iova_mode details are passed to the KNI kernel module, accordingly kernel module translates PA/IOVA addresses to KVA and vice-versa.

---
 doc/guides/prog_guide/kernel_nic_interface.rst | 15 +++++++++++++++
 doc/guides/rel_notes/release_19_11.rst         | 15 ++++++++++++++-
 lib/librte_eal/linux/eal/eal.c                 | 23 ++++++++++++++++-------
 lib/librte_kni/rte_kni.c                       |  6 ++++++
 4 files changed, 51 insertions(+), 8 deletions(-)

[snip]

Quoted 7 lines
(quoted diff) +0 -0

b/lib/librte_eal/linux/eal/eal.c index 9e2d50c..53ca84b 100644

lib/librte_eal/linux/eal/eal.c +0 -0
@@ -1086,14 +1086,23 @@ rte_eal_init(int argc, char **argv)
                        }
                }

lib/librte_eal/linux/eal/eal.c rte_eal_init(int argc, char **argv) · line 1094

Quoted 10 lines
lib/librte_eal/linux/eal/eal.c +3 -5
 #ifdef RTE_LIBRTE_KNI
-               /* Workaround for KNI which requires physical address to work */
-               if (iova_mode == RTE_IOVA_VA &&
-                               rte_eal_check_module("rte_kni") == 1) {
-                       if (phys_addrs) {
+               if (rte_eal_check_module("rte_kni") == 1) { #if
+KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE
+                       if (iova_mode == RTE_IOVA_VA) {
                                iova_mode = RTE_IOVA_PA;
-                               RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI

module is loaded\n");

lib/librte_eal/linux/eal/eal.c rte_eal_init(int argc, char **argv) · line 1096

Quoted 2 lines
lib/librte_eal/linux/eal/eal.c +0 -2
-                       } else {
-                               RTE_LOG(DEBUG, EAL, "KNI can not work since physical

addresses are unavailable\n");

lib/librte_eal/linux/eal/eal.c rte_eal_init(int argc, char **argv) · line 1094

Quoted 2 lines
lib/librte_eal/linux/eal/eal.c +2 -0
+                               RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because "
+                                               "Kernel version supports only 'PA' mode for KNI

module\n");

lib/librte_eal/linux/eal/eal.c rte_eal_init(int argc, char **argv) · line 1098

Quoted 4 lines
lib/librte_eal/linux/eal/eal.c +4 -0
+                       }
+#endif
+                       if (rte_bus_get_iommu_class() == RTE_IOVA_DC)
+                               iova_mode = RTE_IOVA_PA;

If physical addresses are unavailable, this code forces PA anyway.

lib/librte_eal/linux/eal/eal.c rte_eal_init(int argc, char **argv) · line 1106

Quoted 10 lines
lib/librte_eal/linux/eal/eal.c +9 -0
+
+                       if (iova_mode == RTE_IOVA_PA) {
+                               if (phys_addrs && is_iommu_enabled())
+                                       RTE_LOG(WARNING, EAL, "Forced
+ IOVA as 'PA' because KNI module is loaded\n");
+
+                               if (!phys_addrs)
+                                       RTE_LOG(DEBUG, EAL, "KNI can
+ not work since physical addresses are unavailable\n");
                        }

Checking physical addresses availability after, and having a log is not enough.

Quoted 5 lines
Quoted 3 lines

So far, KNI could not work with IOVA as VA.
Your patchset adds support for IOVA as VA if kernel is >= 4.6. Repeating my proposal (as far as eal.c is concerned) of just changing:

To keep the existing behavior intact when bus iommu returns IOVA_DC, had to handle those case also here.

No.
If you want to change something, do it in a separate patch with full explanation.

Signature · 1 line
David Marchand
#238 lore raw

Re: [dpdk-dev] [PATCH v13 2/2] kni: support IOVA mode

In reply to David Marchand
Quoted 82 lines · David Marchand

I can't see an interest in splitting this patch from the kmod update. Ferruh, what do you think?

Quoted 10 lines · On Fri, Nov 15, 2019 at 12:19 PM <[email protected]> wrote:

From: Vamsi Attunuru <[email protected]>

Current KNI implementation only operates in IOVA_PA mode patch adds required functionality to enable KNI in IOVA_VA mode.

KNI loopback mode tests will have performance impact in this mode due to IOVA to KVA address translations. However, In KNI real world use cases, the performace

performance

Quoted 19 lines

impact will be based on Linux kernel stack and scheduler latencies. Performance varies based on the KNI use case. If bus iommu scheme is IOVA_DC and KNI module is loaded, DPDK chooses IOVA as PA as existing behaviour.

During KNI creation, app's iova_mode details are passed to the KNI kernel module, accordingly kernel module translates PA/IOVA addresses to KVA and vice-versa.

---
 doc/guides/prog_guide/kernel_nic_interface.rst | 15 +++++++++++++++
 doc/guides/rel_notes/release_19_11.rst         | 15 ++++++++++++++-
 lib/librte_eal/linux/eal/eal.c                 | 23 ++++++++++++++++-------
 lib/librte_kni/rte_kni.c                       |  6 ++++++
 4 files changed, 51 insertions(+), 8 deletions(-)

[snip]

Quoted 15 lines
lib/librte_eal/linux/eal/eal.c +3 -4
index 9e2d50c..53ca84b 100644
@@ -1086,14 +1086,23 @@ rte_eal_init(int argc, char **argv)
                        }
                }
 #ifdef RTE_LIBRTE_KNI
-               /* Workaround for KNI which requires physical address to work */
-               if (iova_mode == RTE_IOVA_VA &&
-                               rte_eal_check_module("rte_kni") == 1) {
-                       if (phys_addrs) {
+               if (rte_eal_check_module("rte_kni") == 1) {
+#if KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE
+                       if (iova_mode == RTE_IOVA_VA) {

lib/librte_eal/linux/eal/eal.c rte_eal_init(int argc, char **argv) · line 1098

Quoted 10 lines
lib/librte_eal/linux/eal/eal.c +6 -3
                                iova_mode = RTE_IOVA_PA;
-                               RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI module is loaded\n");
-                       } else {
-                               RTE_LOG(DEBUG, EAL, "KNI can not work since physical addresses are unavailable\n");
+                               RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because "
+                                               "Kernel version supports only 'PA' mode for KNI module\n");
+                       }
+#endif
+                       if (rte_bus_get_iommu_class() == RTE_IOVA_DC)
+                               iova_mode = RTE_IOVA_PA;

If physical addresses are unavailable, this code forces PA anyway.

lib/librte_eal/linux/eal/eal.c rte_eal_init(int argc, char **argv) · line 1106

Quoted 8 lines
lib/librte_eal/linux/eal/eal.c +7 -0
+
+                       if (iova_mode == RTE_IOVA_PA) {
+                               if (phys_addrs && is_iommu_enabled())
+                                       RTE_LOG(WARNING, EAL, "Forced IOVA as 'PA' because KNI module is loaded\n");
+
+                               if (!phys_addrs)
+                                       RTE_LOG(DEBUG, EAL, "KNI can not work since physical addresses are unavailable\n");
                        }

Checking physical addresses availability after, and having a log is not enough.

Quoted 3 lines

So far, KNI could not work with IOVA as VA.
Your patchset adds support for IOVA as VA if kernel is >= 4.6. Repeating my proposal (as far as eal.c is concerned) of just changing:

We need achive the following.

IOVA as PA has performance implication on KNI case. So we need to make IOVA as PA when KNI module is loaded.
Your suggestion makes IOVA as PA when bus return IOVA as VA due the fact the KNI check is latter. We need to move that up.

How about the following

[master]dell[dpdk.org] $ git diff

lib/librte_eal/linux/eal/eal.c +9 -0
index 9e2d50cfb..085fde767 100644
@@ -1064,6 +1064,21 @@ rte_eal_init(int argc, char **argv)
                /* autodetect the IOVA mapping mode */
                enum rte_iova_mode iova_mode = rte_bus_get_iommu_class();
 
+#if defined(RTE_LIBRTE_KNI) && KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE
+               /* IOVA as PA gives better performance for KNI. Choose IOVA as
+                 * PA when bus returns RTE_IOVA_DC and KNI module is present.
+                 */
+               if (iova_mode == RTE_IOVA_DC &&
+                               rte_eal_check_module("rte_kni") == 1) {
+                       if (phys_addrs) {
+                               iova_mode = RTE_IOVA_PA;
+                               RTE_LOG(WARNING, EAL, "Forcing IOVA as

'PA' because KNI module is loaded\n");
+ } else {
+ RTE_LOG(DEBUG, EAL, "KNI can not work
since physical addresses are unavailable\n");
+ }
+ }
+#endif
+
if (iova_mode == RTE_IOVA_DC) {
RTE_LOG(DEBUG, EAL, "Buses did not request a
specific IOVA mode.\n");

@@ -1085,18 +1100,6 @@ rte_eal_init(int argc, char **argv)
RTE_LOG(DEBUG, EAL, "IOMMU is not
available, selecting IOVA as PA mode.\n");

                        }
                }

-#ifdef RTE_LIBRTE_KNI
- /* Workaround for KNI which requires physical address to work */
- if (iova_mode == RTE_IOVA_VA &&
- rte_eal_check_module("rte_kni") == 1) {
- if (phys_addrs) {
- iova_mode = RTE_IOVA_PA;
- RTE_LOG(WARNING, EAL, "Forcing IOVA as
'PA' because KNI module is loaded\n");
- } else {
- RTE_LOG(DEBUG, EAL, "KNI can not work
since physical addresses are unavailable\n");
- }
- }
-#endif

                rte_eal_get_configuration()->iova_mode = iova_mode;
        } else {
                rte_eal_get_configuration()->iova_mode =

[master]dell[dpdk.org] $

Quoted 16 lines
(quoted diff) +1 -2
@@ -1085,7 +1085,7 @@ rte_eal_init(int argc, char **argv)
                                RTE_LOG(DEBUG, EAL, "IOMMU is not
 available, selecting IOVA as PA mode.\n");
                        }
                }
-#ifdef RTE_LIBRTE_KNI
+#if defined(RTE_LIBRTE_KNI) && KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE
                /* Workaround for KNI which requires physical address to work */
                if (iova_mode == RTE_IOVA_VA &&
 
 
 
--

David Marchand