Skip to contentSkip to conversation

eal: choose IOVA mode according to compilation flags

PATCH Superseded Viacheslav Ovsiienko 4 participants 8 messages Apr 12, 2023 – Jun 12, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eal: choose IOVA mode according to compilation flags

The DPDK can be compiled to be run in IOVA VA mode with 'enable_iova_as_pa=false' meson option. If there is no explicit EAL --iova-mode parameter specified in the command line the rte_eal_init() tried to deduce VA or PA mode without taking into account the above mentioned compile time option, resulting into initialization failure.

---
 lib/eal/linux/eal.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/eal/linux/eal.c +4 -1
index c37868b7f0..4481bc4ad8 100644
@@ -1080,7 +1080,10 @@ rte_eal_init(int argc, char **argv)
 		if (iova_mode == RTE_IOVA_DC) {
 			RTE_LOG(DEBUG, EAL, "Buses did not request a specific IOVA mode.\n");
 
-			if (!phys_addrs) {
+			if (!RTE_IOVA_IN_MBUF) {
+				iova_mode = RTE_IOVA_VA;
+				RTE_LOG(DEBUG, EAL, "IOVA VA mode is forced by build option.\n");
+			} else if (!phys_addrs) {
 				/* if we have no access to physical addresses,
 				 * pick IOVA as VA mode.
 				 */
Signature · 1 line
2.18.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines

From: Viacheslav Ovsiienko [mailto:[email protected]]
Sent: Wednesday, 12 April 2023 19.20

The DPDK can be compiled to be run in IOVA VA mode with 'enable_iova_as_pa=false' meson option. If there is no explicit EAL --iova-mode parameter specified in the command line the rte_eal_init() tried to deduce VA or PA mode without taking into account the above mentioned compile time option, resulting into initialization failure.

Quoted 3 lines
---
 lib/eal/linux/eal.c | 5 ++++-

This patch is close to being a bugfix. Good catch!

You could also consider another patch, logging warnings in rte_bus_get_iommu_class() [1] for the busses that want IOVA as PA when !RTE_IOVA_IN_MBUF.

[1]: https://elixir.bootlin.com/dpdk/v23.03/source/lib/eal/common/eal_common_bus.c#L224

Quoted 7 lines
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/eal/linux/eal.c +0 -0
index c37868b7f0..4481bc4ad8 100644

lib/eal/linux/eal.c rte_eal_init(int argc, char **argv) · line 1087

Quoted 9 lines
lib/eal/linux/eal.c +3 -1
@@ -1080,7 +1080,10 @@ rte_eal_init(int argc, char **argv)
 		if (iova_mode == RTE_IOVA_DC) {
 			RTE_LOG(DEBUG, EAL, "Buses did not request a specific
 IOVA mode.\n");
 
-			if (!phys_addrs) {
+			if (!RTE_IOVA_IN_MBUF) {
+				iova_mode = RTE_IOVA_VA;
+				RTE_LOG(DEBUG, EAL, "IOVA VA mode is forced by
 build option.\n");

Minor detail regarding conventions: "IOVA VA " -> "IOVA as VA"

Quoted 6 lines
lib/eal/linux/eal.c +1 -0
+			} else if (!phys_addrs) {
 				/* if we have no access to physical addresses,
lib/eal/linux/eal.c +0 -1
 				 * pick IOVA as VA mode.
 				 */
--

2.18.1

#2 lore raw
Quoted 21 lines

-----Original Message-----
From: Morten Brørup <[email protected]>
Sent: среда, 12 апреля 2023 г. 22:12
To: Slava Ovsiienko <[email protected]>; [email protected]
Cc: NBU-Contact-Thomas Monjalon (EXTERNAL) <[email protected]>; [email protected]
Subject: RE: [PATCH] eal: choose IOVA mode according to compilation flags

Quoted 9 lines

From: Viacheslav Ovsiienko [mailto:[email protected]]
Sent: Wednesday, 12 April 2023 19.20

The DPDK can be compiled to be run in IOVA VA mode with 'enable_iova_as_pa=false' meson option. If there is no explicit EAL --iova-mode parameter specified in the command line the rte_eal_init() tried to deduce VA or PA mode without taking into account the above mentioned compile time option, resulting into initialization failure.

Quoted 3 lines
---
 lib/eal/linux/eal.c | 5 ++++-
Quoted 5 lines

This patch is close to being a bugfix. Good catch!

You could also consider another patch, logging warnings in rte_bus_get_iommu_class() [1] for the busses that want IOVA as PA when !RTE_IOVA_IN_MBUF.

Yes, looks reasonable, thank you.
Let me gather the comments first, then will update the patch.

Quoted 34 lines

[1]:
https://elixir.bootlin.com/dpdk/v23.03/source/lib/eal/common/eal_common_
bus.c#L224

lib/eal/linux/eal.c rte_eal_init(int argc, char **argv) · line 1081

Quoted 9 lines
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/eal/linux/eal.c index renamed from lib/eal/linux/eal.c +0 -0

c37868b7f0..4481bc4ad8 100644

lib/eal/linux/eal.c +0 -0
@@ -1080,7 +1080,10 @@ rte_eal_init(int argc, char **argv)
 		if (iova_mode == RTE_IOVA_DC) {
 			RTE_LOG(DEBUG, EAL, "Buses did not request a

specific IOVA

lib/eal/linux/eal.c rte_eal_init(int argc, char **argv)

Quoted 6 lines
lib/eal/linux/eal.c +3 -1
 mode.\n");
 
-			if (!phys_addrs) {
+			if (!RTE_IOVA_IN_MBUF) {
+				iova_mode = RTE_IOVA_VA;
+				RTE_LOG(DEBUG, EAL, "IOVA VA mode is

forced by

lib/eal/linux/eal.c rte_eal_init(int argc, char **argv) · line 1087

Quoted 1 line
lib/eal/linux/eal.c +0 -0
 build option.\n");

Minor detail regarding conventions: "IOVA VA " -> "IOVA as VA"

Quoted 6 lines
lib/eal/linux/eal.c +1 -0
+			} else if (!phys_addrs) {
 				/* if we have no access to physical addresses,
lib/eal/linux/eal.c +0 -1
 				 * pick IOVA as VA mode.
 				 */
--

2.18.1

#3 lore raw

PATCH v2 1/1 eal: choose IOVA mode according to compilation flags

In reply to Viacheslav Ovsiienko

The DPDK can be compiled to be run in IOVA VA mode with 'enable_iova_as_pa=false' meson option. If there is no explicit EAL --iova-mode parameter specified in the command line the rte_eal_init() tried to deduce VA or PA mode without taking into account the above mentioned compile time option, resulting into initialization failure.

---
 lib/eal/linux/eal.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/eal/linux/eal.c +4 -1
index ae323cd492..9856ec9d12 100644
@@ -1081,7 +1081,10 @@ rte_eal_init(int argc, char **argv)
 		if (iova_mode == RTE_IOVA_DC) {
 			RTE_LOG(DEBUG, EAL, "Buses did not request a specific IOVA mode.\n");
 
-			if (!phys_addrs) {
+			if (!RTE_IOVA_IN_MBUF) {
+				iova_mode = RTE_IOVA_VA;
+				RTE_LOG(DEBUG, EAL, "IOVA as VA mode is forced by build option.\n");
+			} else if (!phys_addrs) {
 				/* if we have no access to physical addresses,
 				 * pick IOVA as VA mode.
 				 */
Signature · 1 line
2.18.1
Acked-by on v2 1/1
#4 lore raw
Quoted 18 lines · Viacheslav Ovsiienko

The DPDK can be compiled to be run in IOVA VA mode with 'enable_iova_as_pa=false' meson option. If there is no explicit EAL --iova-mode parameter specified in the command line the rte_eal_init() tried to deduce VA or PA mode without taking into account the above mentioned compile time option, resulting into initialization failure.

---
 lib/eal/linux/eal.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/eal/linux/eal.c +0 -0
index ae323cd492..9856ec9d12 100644
@@ -1081,7 +1081,10 @@ rte_eal_init(int argc, char **argv)
 		if (iova_mode == RTE_IOVA_DC) {

lib/eal/linux/eal.c rte_eal_init(int argc, char **argv) · line 1090

Quoted 10 lines
lib/eal/linux/eal.c +4 -1
 			RTE_LOG(DEBUG, EAL, "Buses did not request a specific IOVA mode.\n");
 
-			if (!phys_addrs) {
+			if (!RTE_IOVA_IN_MBUF) {
+				iova_mode = RTE_IOVA_VA;
+				RTE_LOG(DEBUG, EAL, "IOVA as VA mode is forced by build option.\n");
+			} else if (!phys_addrs) {
 				/* if we have no access to physical addresses,
 				 * pick IOVA as VA mode.
 				 */
Reviewed-by Morten Brørup
#5 lore raw

06/06/2023 17:23, Bruce Richardson:

Quoted 7 lines · Viacheslav Ovsiienko
Quoted 6 lines

The DPDK can be compiled to be run in IOVA VA mode with 'enable_iova_as_pa=false' meson option. If there is no explicit EAL --iova-mode parameter specified in the command line the rte_eal_init() tried to deduce VA or PA mode without taking into account the above mentioned compile time option, resulting into initialization failure.

It looks like a bug fix to backport. Do you agree? Could you add the fix tags?

Quoted 2 lines
Quoted 2 lines

You forgot previous tag:

Quoted 3 lines
Quoted 3 lines
---
 lib/eal/linux/eal.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

What about FreeBSD and Windows?
I suspect there is the same issue.

Quoted 14 lines

lib/eal/linux/eal.c rte_eal_init(int argc, char **argv) · line 1090

Quoted 12 lines
lib/eal/linux/eal.c +4 -1
@@ -1081,7 +1081,10 @@ rte_eal_init(int argc, char **argv)
 		if (iova_mode == RTE_IOVA_DC) {
 			RTE_LOG(DEBUG, EAL, "Buses did not request a specific IOVA mode.\n");
 
-			if (!phys_addrs) {
+			if (!RTE_IOVA_IN_MBUF) {
+				iova_mode = RTE_IOVA_VA;
+				RTE_LOG(DEBUG, EAL, "IOVA as VA mode is forced by build option.\n");
+			} else if (!phys_addrs) {
 				/* if we have no access to physical addresses,
 				 * pick IOVA as VA mode.
 				 */
#6 lore raw

PATCH v3 1/1 eal: choose IOVA mode according to compilation flags

In reply to Viacheslav Ovsiienko

The DPDK can be compiled to be run in IOVA VA mode with 'enable_iova_as_pa=false' meson option. If there is no explicit EAL --iova-mode parameter specified in the command line the rte_eal_init() tried to deduce VA or PA mode without taking into account the above mentioned compile time option, resulting into initialization failure.

Also, for FreeBSD and Windows EALs the IOVE mode checks were added or moved to be after the mode selection code block for final checking.

---
 lib/eal/freebsd/eal.c | 28 +++++++++++++++++++++-------
 lib/eal/linux/eal.c   |  5 ++++-
 lib/eal/windows/eal.c | 28 +++++++++++++++++++++-------
 3 files changed, 46 insertions(+), 15 deletions(-)

---
v2: - minor test message update
v3: - added the same change to FreeBSD and Windwos EALs
- added/mode chosen IOVA mode checks in FreeBSD/Windows

lib/eal/freebsd/eal.c +21 -7
index 7daf22e314..ff7da2473a 100644
@@ -694,22 +694,36 @@ rte_eal_init(int argc, char **argv)
 	 */
 	has_phys_addr = internal_conf->no_hugetlbfs == 0;
 	iova_mode = internal_conf->iova_mode;
-	if (iova_mode == RTE_IOVA_PA && !has_phys_addr) {
-		rte_eal_init_alert("Cannot use IOVA as 'PA' since physical addresses are not available");
-		rte_errno = EINVAL;
-		return -1;
-	}
 	if (iova_mode == RTE_IOVA_DC) {
 		RTE_LOG(DEBUG, EAL, "Specific IOVA mode is not requested, autodetecting\n");
 		if (has_phys_addr) {
 			RTE_LOG(DEBUG, EAL, "Selecting IOVA mode according to bus requests\n");
 			iova_mode = rte_bus_get_iommu_class();
-			if (iova_mode == RTE_IOVA_DC)
-				iova_mode = RTE_IOVA_PA;
+			if (iova_mode == RTE_IOVA_DC) {
+				if (!RTE_IOVA_IN_MBUF) {
+					iova_mode = RTE_IOVA_VA;
+					RTE_LOG(DEBUG, EAL, "IOVA as VA mode is forced by build option.\n");
+				} else	{
+					iova_mode = RTE_IOVA_PA;
+				}
+			}
 		} else {
 			iova_mode = RTE_IOVA_VA;
 		}
 	}
+
+	if (iova_mode == RTE_IOVA_PA && !has_phys_addr) {
+		rte_eal_init_alert("Cannot use IOVA as 'PA' since physical addresses are not available");
+		rte_errno = EINVAL;
+		return -1;
+	}
+
+	if (iova_mode == RTE_IOVA_PA && !RTE_IOVA_IN_MBUF) {
+		rte_eal_init_alert("Cannot use IOVA as 'PA' as it is disabled during build");
+		rte_errno = EINVAL;
+		return -1;
+	}
+
 	rte_eal_get_configuration()->iova_mode = iova_mode;
 	RTE_LOG(INFO, EAL, "Selected IOVA mode '%s'\n",
 		rte_eal_iova_mode() == RTE_IOVA_PA ? "PA" : "VA");
lib/eal/linux/eal.c +4 -1
index ae323cd492..9856ec9d12 100644
@@ -1081,7 +1081,10 @@ rte_eal_init(int argc, char **argv)
 		if (iova_mode == RTE_IOVA_DC) {
 			RTE_LOG(DEBUG, EAL, "Buses did not request a specific IOVA mode.\n");
 
-			if (!phys_addrs) {
+			if (!RTE_IOVA_IN_MBUF) {
+				iova_mode = RTE_IOVA_VA;
+				RTE_LOG(DEBUG, EAL, "IOVA as VA mode is forced by build option.\n");
+			} else if (!phys_addrs) {
 				/* if we have no access to physical addresses,
 				 * pick IOVA as VA mode.
 				 */
lib/eal/windows/eal.c +21 -7
index 033825c14c..9c9a49fda0 100644
@@ -362,22 +362,36 @@ rte_eal_init(int argc, char **argv)
 	}
 
 	iova_mode = internal_conf->iova_mode;
-	if (iova_mode == RTE_IOVA_PA && !has_phys_addr) {
-		rte_eal_init_alert("Cannot use IOVA as 'PA' since physical addresses are not available");
-		rte_errno = EINVAL;
-		return -1;
-	}
 	if (iova_mode == RTE_IOVA_DC) {
 		RTE_LOG(DEBUG, EAL, "Specific IOVA mode is not requested, autodetecting\n");
 		if (has_phys_addr) {
 			RTE_LOG(DEBUG, EAL, "Selecting IOVA mode according to bus requests\n");
 			iova_mode = rte_bus_get_iommu_class();
-			if (iova_mode == RTE_IOVA_DC)
-				iova_mode = RTE_IOVA_PA;
+			if (iova_mode == RTE_IOVA_DC) {
+				if (!RTE_IOVA_IN_MBUF) {
+					iova_mode = RTE_IOVA_VA;
+					RTE_LOG(DEBUG, EAL, "IOVA as VA mode is forced by build option.\n");
+				} else	{
+					iova_mode = RTE_IOVA_PA;
+				}
+			}
 		} else {
 			iova_mode = RTE_IOVA_VA;
 		}
 	}
+
+	if (iova_mode == RTE_IOVA_PA && !has_phys_addr) {
+		rte_eal_init_alert("Cannot use IOVA as 'PA' since physical addresses are not available");
+		rte_errno = EINVAL;
+		return -1;
+	}
+
+	if (iova_mode == RTE_IOVA_PA && !RTE_IOVA_IN_MBUF) {
+		rte_eal_init_alert("Cannot use IOVA as 'PA' as it is disabled during build");
+		rte_errno = EINVAL;
+		return -1;
+	}
+
 	RTE_LOG(DEBUG, EAL, "Selected IOVA mode '%s'\n",
 		iova_mode == RTE_IOVA_PA ? "PA" : "VA");
 	rte_eal_get_configuration()->iova_mode = iova_mode;
Signature · 1 line
2.18.1
#7 lore raw

08/06/2023 17:45, Viacheslav Ovsiienko:

Quoted 7 lines

The DPDK can be compiled to be run in IOVA VA mode with 'enable_iova_as_pa=false' meson option. If there is no explicit EAL --iova-mode parameter specified in the command line the rte_eal_init() tried to deduce VA or PA mode without taking into account the above mentioned compile time option, resulting into initialization failure.

Quoted 6 lines

Also, for FreeBSD and Windows EALs the IOVE mode checks were added or moved to be after the mode selection code block for final checking.

Applied, thanks.