From patchwork Tue Oct 11 02:55:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Chen X-Patchwork-Id: 117870 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 29A07A0544; Tue, 11 Oct 2022 04:55:37 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1956640F19; Tue, 11 Oct 2022 04:55:37 +0200 (CEST) Received: from out28-217.mail.aliyun.com (out28-217.mail.aliyun.com [115.124.28.217]) by mails.dpdk.org (Postfix) with ESMTP id 7F17340146 for ; Tue, 11 Oct 2022 04:55:35 +0200 (CEST) X-Alimail-AntiSpam: AC=CONTINUE; BC=0.0750918|-1; CH=green; DM=|CONTINUE|false|; DS=CONTINUE|ham_system_inform|0.000335794-8.98666e-06-0.999655; FP=10250182168108606698|3|1|2|0|-1|-1|-1; HT=ay29a033018047202; MF=chenh@yusur.tech; NM=1; PH=DS; RN=5; RT=5; SR=0; TI=SMTPD_---.PYnHeWW_1665456931; Received: from localhost.localdomain(mailfrom:chenh@yusur.tech fp:SMTPD_---.PYnHeWW_1665456931) by smtp.aliyun-inc.com; Tue, 11 Oct 2022 10:55:32 +0800 From: Hao Chen To: maxime.coquelin@redhat.com, chenbo.xia@intel.com Cc: dev@dpdk.org, houyl@yusur.tech, zy@yusur.tech Subject: [PATCH] example: vdpa: support run in nested virtualization environment Date: Mon, 10 Oct 2022 22:55:31 -0400 Message-Id: <20221011025531.887043-1-chenh@yusur.tech> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- examples/vdpa/main.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c index 4c7e81d7b6..a24c78d7a4 100644 --- a/examples/vdpa/main.c +++ b/examples/vdpa/main.c @@ -43,16 +43,20 @@ 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 : 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); + printf("Usage: %s [EAL options] --\n", prgname); + const char *usage_str = " --interactive|-i: run in interactive mode.\n" + " --iface : 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, "%s", usage_str); + exit(1); } static int @@ -63,6 +67,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 +225,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,