[v3] examples/vdpa: support running in nested virtualization environment

Message ID 20221025061939.3229676-1-chenh@yusur.tech (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series [v3] examples/vdpa: support running in nested virtualization environment |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS

Commit Message

Hao Chen Oct. 25, 2022, 6:19 a.m. UTC
  When we run dpdk vdpa in the nested virtual machine vm-L1 and ping
test in vm-L2, the ping is NG. The reason for troubleshooting is
that the virtio net in vm-L2 sends control information to the vring,
and the qemu back-end device in vm-L1 cannot obtain correct data
from the vring. This problem is related to the opening of the vIOMMU.

This patch add option '--iommu-support' to use guest vIOMMU to
protect vhost, then the ping test in vm-L2 is OK.
This option is required in a nested virtualization environment.

Signed-off-by: Hao Chen <chenh@yusur.tech>
---
v3:
*Modify mail title.

v2:
*fprintf all string including the eal one.
*remove exit(1).

 examples/vdpa/main.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
  

Comments

Maxime Coquelin Oct. 26, 2022, 6:10 a.m. UTC | #1
Hi Hao

On 10/25/22 08:19, Hao Chen wrote:
> When we run dpdk vdpa in the nested virtual machine vm-L1 and ping
> test in vm-L2, the ping is NG. The reason for troubleshooting is

NG == not good? Please don't use abbreviations.

> that the virtio net in vm-L2 sends control information to the vring,
> and the qemu back-end device in vm-L1 cannot obtain correct data
> from the vring. This problem is related to the opening of the vIOMMU.
> 
> This patch add option '--iommu-support' to use guest vIOMMU to
> protect vhost, then the ping test in vm-L2 is OK.
> This option is required in a nested virtualization environment.

I'm wondering whether the flag shouldn't just be set by default, as the
feature negotiation will be done between the vDPA driver & the guest
driver anyways?


> Signed-off-by: Hao Chen <chenh@yusur.tech>
> ---
> v3:
> *Modify mail title.
> 
> v2:
> *fprintf all string including the eal one.
> *remove exit(1).
> 
>   examples/vdpa/main.c | 17 ++++++++++++-----
>   1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c
> index 4c7e81d7b6..71149461c6 100644
> --- a/examples/vdpa/main.c
> +++ b/examples/vdpa/main.c
> @@ -43,16 +43,18 @@ static char iface[MAX_PATH_LEN];
>   static int devcnt;
>   static int interactive;
>   static int client_mode;
> +static int iommu_support;
>   
>   /* display usage */
>   static void
>   vdpa_usage(const char *prgname)
>   {
> -	printf("Usage: %s [EAL options] -- "
> -				 "	--interactive|-i: run in interactive mode.\n"
> -				 "	--iface <path>: specify the path prefix of the socket files, e.g. /tmp/vhost-user-.\n"
> -				 "	--client: register a vhost-user socket as client mode.\n",
> -				 prgname);
> +	const char *usage_str = "	--interactive|-i: run in interactive mode.\n"
> +				"	--iface <path>: specify the path prefix of the socket files, e.g. /tmp/vhost-user-.\n"
> +				"	--client: register a vhost-user socket as client mode.\n"
> +				"	--iommu-support: use guest vIOMMU to protect vhost.\n";
> +
> +	fprintf(stderr, "Usage: %s [EAL options] --\n%s", prgname, usage_str);
>   }
>   
>   static int
> @@ -63,6 +65,7 @@ parse_args(int argc, char **argv)
>   		{"iface", required_argument, NULL, 0},
>   		{"interactive", no_argument, &interactive, 1},
>   		{"client", no_argument, &client_mode, 1},
> +		{"iommu-support", no_argument, &iommu_support, 1},
>   		{NULL, 0, 0, 0},
>   	};
>   	int opt, idx;
> @@ -220,6 +223,10 @@ start_vdpa(struct vdpa_port *vport)
>   			socket_path);
>   		return -1;
>   	}
> +
> +	if (iommu_support)
> +		vport->flags |= RTE_VHOST_USER_IOMMU_SUPPORT;
> +
>   	ret = rte_vhost_driver_register(socket_path, vport->flags);
>   	if (ret != 0)
>   		rte_exit(EXIT_FAILURE,
  
Hao Chen Oct. 26, 2022, 6:48 a.m. UTC | #2
On 2022/10/26 14:10, Maxime Coquelin wrote:
> Hi Hao
>
> On 10/25/22 08:19, Hao Chen wrote:
>> When we run dpdk vdpa in the nested virtual machine vm-L1 and ping
>> test in vm-L2, the ping is NG. The reason for troubleshooting is
>
> NG == not good? Please don't use abbreviations.
>
Yes, I will pay attention to this later.
>> that the virtio net in vm-L2 sends control information to the vring,
>> and the qemu back-end device in vm-L1 cannot obtain correct data
>> from the vring. This problem is related to the opening of the vIOMMU.
>>
>> This patch add option '--iommu-support' to use guest vIOMMU to
>> protect vhost, then the ping test in vm-L2 is OK.
>> This option is required in a nested virtualization environment.
>
> I'm wondering whether the flag shouldn't just be set by default, as the
> feature negotiation will be done between the vDPA driver & the guest
> driver anyways?
>
Yes, It can be set by default rather than as an option. 
VIRTIO_F_IOMMU_PLATFORM feature will not be negotiated successfully if 
it is not in a nested virtualization environment.

I will simplify the patch.

Thanks.
>
>> Signed-off-by: Hao Chen <chenh@yusur.tech>
>> ---
>> v3:
>> *Modify mail title.
>>
>> v2:
>> *fprintf all string including the eal one.
>> *remove exit(1).
>>
>>   examples/vdpa/main.c | 17 ++++++++++++-----
>>   1 file changed, 12 insertions(+), 5 deletions(-)
>>
>> diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c
>> index 4c7e81d7b6..71149461c6 100644
>> --- a/examples/vdpa/main.c
>> +++ b/examples/vdpa/main.c
>> @@ -43,16 +43,18 @@ static char iface[MAX_PATH_LEN];
>>   static int devcnt;
>>   static int interactive;
>>   static int client_mode;
>> +static int iommu_support;
>>     /* display usage */
>>   static void
>>   vdpa_usage(const char *prgname)
>>   {
>> -    printf("Usage: %s [EAL options] -- "
>> -                 "    --interactive|-i: run in interactive mode.\n"
>> -                 "    --iface <path>: specify the path prefix of the 
>> socket files, e.g. /tmp/vhost-user-.\n"
>> -                 "    --client: register a vhost-user socket as 
>> client mode.\n",
>> -                 prgname);
>> +    const char *usage_str = "    --interactive|-i: run in 
>> interactive mode.\n"
>> +                "    --iface <path>: specify the path prefix of the 
>> socket files, e.g. /tmp/vhost-user-.\n"
>> +                "    --client: register a vhost-user socket as 
>> client mode.\n"
>> +                "    --iommu-support: use guest vIOMMU to protect 
>> vhost.\n";
>> +
>> +    fprintf(stderr, "Usage: %s [EAL options] --\n%s", prgname, 
>> usage_str);
>>   }
>>     static int
>> @@ -63,6 +65,7 @@ parse_args(int argc, char **argv)
>>           {"iface", required_argument, NULL, 0},
>>           {"interactive", no_argument, &interactive, 1},
>>           {"client", no_argument, &client_mode, 1},
>> +        {"iommu-support", no_argument, &iommu_support, 1},
>>           {NULL, 0, 0, 0},
>>       };
>>       int opt, idx;
>> @@ -220,6 +223,10 @@ start_vdpa(struct vdpa_port *vport)
>>               socket_path);
>>           return -1;
>>       }
>> +
>> +    if (iommu_support)
>> +        vport->flags |= RTE_VHOST_USER_IOMMU_SUPPORT;
>> +
>>       ret = rte_vhost_driver_register(socket_path, vport->flags);
>>       if (ret != 0)
>>           rte_exit(EXIT_FAILURE,
>
  

Patch

diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c
index 4c7e81d7b6..71149461c6 100644
--- a/examples/vdpa/main.c
+++ b/examples/vdpa/main.c
@@ -43,16 +43,18 @@  static char iface[MAX_PATH_LEN];
 static int devcnt;
 static int interactive;
 static int client_mode;
+static int iommu_support;
 
 /* display usage */
 static void
 vdpa_usage(const char *prgname)
 {
-	printf("Usage: %s [EAL options] -- "
-				 "	--interactive|-i: run in interactive mode.\n"
-				 "	--iface <path>: specify the path prefix of the socket files, e.g. /tmp/vhost-user-.\n"
-				 "	--client: register a vhost-user socket as client mode.\n",
-				 prgname);
+	const char *usage_str = "	--interactive|-i: run in interactive mode.\n"
+				"	--iface <path>: specify the path prefix of the socket files, e.g. /tmp/vhost-user-.\n"
+				"	--client: register a vhost-user socket as client mode.\n"
+				"	--iommu-support: use guest vIOMMU to protect vhost.\n";
+
+	fprintf(stderr, "Usage: %s [EAL options] --\n%s", prgname, usage_str);
 }
 
 static int
@@ -63,6 +65,7 @@  parse_args(int argc, char **argv)
 		{"iface", required_argument, NULL, 0},
 		{"interactive", no_argument, &interactive, 1},
 		{"client", no_argument, &client_mode, 1},
+		{"iommu-support", no_argument, &iommu_support, 1},
 		{NULL, 0, 0, 0},
 	};
 	int opt, idx;
@@ -220,6 +223,10 @@  start_vdpa(struct vdpa_port *vport)
 			socket_path);
 		return -1;
 	}
+
+	if (iommu_support)
+		vport->flags |= RTE_VHOST_USER_IOMMU_SUPPORT;
+
 	ret = rte_vhost_driver_register(socket_path, vport->flags);
 	if (ret != 0)
 		rte_exit(EXIT_FAILURE,