From patchwork Fri Jul 23 08:09:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jiang, Cheng1" X-Patchwork-Id: 96231 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 E9E32A0C46; Fri, 23 Jul 2021 10:27:21 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 329F3410E9; Fri, 23 Jul 2021 10:27:10 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id 83981410E2 for ; Fri, 23 Jul 2021 10:27:08 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10053"; a="199042818" X-IronPort-AV: E=Sophos;i="5.84,263,1620716400"; d="scan'208";a="199042818" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jul 2021 01:27:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,263,1620716400"; d="scan'208";a="502430112" Received: from dpdk_jiangcheng.sh.intel.com ([10.67.119.149]) by FMSMGA003.fm.intel.com with ESMTP; 23 Jul 2021 01:27:06 -0700 From: Cheng Jiang To: maxime.coquelin@redhat.com, Chenbo.Xia@intel.com Cc: dev@dpdk.org, jiayu.hu@intel.com, yvonnex.yang@intel.com Date: Fri, 23 Jul 2021 08:09:36 +0000 Message-Id: <20210723080937.20256-4-cheng1.jiang@intel.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210723080937.20256-1-cheng1.jiang@intel.com> References: <20210602042802.31943-1-cheng1.jiang@intel.com> <20210723080937.20256-1-cheng1.jiang@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v8 3/4] vhost: handle memory hotplug for async vhost 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 Sender: "dev" From: Jiayu Hu When the guest memory is hotplugged, the vhost application which enables DMA acceleration must stop DMA transfers before the vhost re-maps the guest memory. This patch is to notify the vhost application of stopping DMA transfers. Signed-off-by: Jiayu Hu Reviewed-by: Maxime Coquelin --- lib/vhost/vhost_user.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c index 31300e194f..433f412fa8 100644 --- a/lib/vhost/vhost_user.c +++ b/lib/vhost/vhost_user.c @@ -1248,6 +1248,7 @@ vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg, int numa_node = SOCKET_ID_ANY; uint64_t mmap_offset; uint32_t i; + bool async_notify = false; if (validate_msg_fds(msg, memory->nregions) != 0) return RTE_VHOST_MSG_RESULT_ERR; @@ -1275,6 +1276,16 @@ vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg, vdpa_dev->ops->dev_close(dev->vid); dev->flags &= ~VIRTIO_DEV_VDPA_CONFIGURED; } + + /* notify the vhost application to stop DMA transfers */ + if (dev->async_copy && dev->notify_ops->vring_state_changed) { + for (i = 0; i < dev->nr_vring; i++) { + dev->notify_ops->vring_state_changed(dev->vid, + i, 0); + } + async_notify = true; + } + free_mem_region(dev); rte_free(dev->mem); dev->mem = NULL; @@ -1371,6 +1382,11 @@ vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg, dump_guest_pages(dev); + if (async_notify) { + for (i = 0; i < dev->nr_vring; i++) + dev->notify_ops->vring_state_changed(dev->vid, i, 1); + } + return RTE_VHOST_MSG_RESULT_OK; free_mem_table: