From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (xvm-189-124.dc0.ghst.net [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4429DA09FF; Tue, 5 Jan 2021 13:58:21 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 22C5B160841; Tue, 5 Jan 2021 13:58:10 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id DD82E160838 for ; Tue, 5 Jan 2021 13:58:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609851488; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xAuUduvcTWoWwgwvJ+yKhTan6h+7U3MPwdlTdkyj6ho=; b=jPKipx60lyLgIJHc4maCemj3dTHj5AhBUMzfIE6RjoEO5QAVgVCqv92oS73q4NuF7ipyeP EW3f485r+6tYKtPjUdfUrdMqfGl7X0aNOtxN05p1PqCAlEfyF2EdUfVncmOoefhy1F9LzI OeIf8Klo2rlxYnLQU1ZphiBMec6ZunQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-361-Y5T5wh7fNJqrD7CSR2d8ww-1; Tue, 05 Jan 2021 07:58:06 -0500 X-MC-Unique: Y5T5wh7fNJqrD7CSR2d8ww-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 517471842149; Tue, 5 Jan 2021 12:58:05 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.36.110.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 192555B4A4; Tue, 5 Jan 2021 12:58:03 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, xuan.ding@intel.com Cc: Maxime Coquelin Date: Tue, 5 Jan 2021 13:57:27 +0100 Message-Id: <20210105125728.102413-3-maxime.coquelin@redhat.com> In-Reply-To: <20210105125728.102413-1-maxime.coquelin@redhat.com> References: <20210105125728.102413-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-dev] [PATCH v2 2/3] vhost: refactor postcopy registration 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" This patch moves the registration of postcopy to a dedicated function, with the goal of simplifying VHOST_USER_SET_MEM_TABLE request handling function. Signed-off-by: Maxime Coquelin Reviewed-by: Chenbo Xia --- lib/librte_vhost/vhost_user.c | 98 +++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 40 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index b6c8e2e17f..382b9732b8 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -1041,6 +1041,62 @@ vhost_user_postcopy_region_register(struct virtio_net *dev __rte_unused, } #endif +static int +vhost_user_postcopy_register(struct virtio_net *dev, int main_fd, + struct VhostUserMsg *msg) +{ + struct VhostUserMemory *memory; + struct rte_vhost_mem_region *reg; + VhostUserMsg ack_msg; + uint32_t i; + + if (!dev->postcopy_listening) + return 0; + + /* + * We haven't a better way right now than sharing + * DPDK's virtual address with Qemu, so that Qemu can + * retrieve the region offset when handling userfaults. + */ + memory = &msg->payload.memory; + for (i = 0; i < memory->nregions; i++) { + reg = &dev->mem->regions[i]; + memory->regions[i].userspace_addr = reg->host_user_addr; + } + + /* Send the addresses back to qemu */ + msg->fd_num = 0; + send_vhost_reply(main_fd, msg); + + /* Wait for qemu to acknolwedge it's got the addresses + * we've got to wait before we're allowed to generate faults. + */ + if (read_vhost_message(main_fd, &ack_msg) <= 0) { + VHOST_LOG_CONFIG(ERR, + "Failed to read qemu ack on postcopy set-mem-table\n"); + return -1; + } + + if (validate_msg_fds(&ack_msg, 0) != 0) + return -1; + + if (ack_msg.request.master != VHOST_USER_SET_MEM_TABLE) { + VHOST_LOG_CONFIG(ERR, + "Bad qemu ack on postcopy set-mem-table (%d)\n", + ack_msg.request.master); + return -1; + } + + /* Now userfault register and we can use the memory */ + for (i = 0; i < memory->nregions; i++) { + reg = &dev->mem->regions[i]; + if (vhost_user_postcopy_region_register(dev, reg) < 0) + return -1; + } + + return 0; +} + static int vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg, int main_fd) @@ -1215,48 +1271,10 @@ vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg, mmap_size, alignment, mmap_offset); - - if (dev->postcopy_listening) { - /* - * We haven't a better way right now than sharing - * DPDK's virtual address with Qemu, so that Qemu can - * retrieve the region offset when handling userfaults. - */ - memory->regions[i].userspace_addr = - reg->host_user_addr; - } } - if (dev->postcopy_listening) { - /* Send the addresses back to qemu */ - msg->fd_num = 0; - send_vhost_reply(main_fd, msg); - - /* Wait for qemu to acknolwedge it's got the addresses - * we've got to wait before we're allowed to generate faults. - */ - VhostUserMsg ack_msg; - if (read_vhost_message(main_fd, &ack_msg) <= 0) { - VHOST_LOG_CONFIG(ERR, - "Failed to read qemu ack on postcopy set-mem-table\n"); - goto free_mem_table; - } - - if (validate_msg_fds(&ack_msg, 0) != 0) - goto free_mem_table; - - if (ack_msg.request.master != VHOST_USER_SET_MEM_TABLE) { - VHOST_LOG_CONFIG(ERR, - "Bad qemu ack on postcopy set-mem-table (%d)\n", - ack_msg.request.master); - goto free_mem_table; - } - /* Now userfault register and we can use the memory */ - for (i = 0; i < memory->nregions; i++) - if (vhost_user_postcopy_region_register(dev, - &dev->mem->regions[i]) < 0) - goto free_mem_table; - } + if (vhost_user_postcopy_register(dev, main_fd, msg) < 0) + goto free_mem_table; for (i = 0; i < dev->nr_vring; i++) { struct vhost_virtqueue *vq = dev->virtqueue[i]; -- 2.29.2