From patchwork Mon Nov 16 11:36:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 84233 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id DDD5FA04B5; Mon, 16 Nov 2020 12:36:53 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9ADF1C8DE; Mon, 16 Nov 2020 12:36:34 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by dpdk.org (Postfix) with ESMTP id 7F53AC8BC for ; Mon, 16 Nov 2020 12:36:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605526590; 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=1XHCLGfbVtcG0P6JNtxUqWfIgFW24Opv0vRwn6Xrpzo=; b=WmAdLGXgOqz+xzXpZcBz/G334Gwy/Ynu6NdzH7kxwdqq2hp/bWMGVIdHvtq9Co14YwEkP6 nbecGFl4wW4gaL7tTqllYERkpllGCl1ndBNTDRUhP8EeVv0JlhVD1FJThyhamtzxcDbeTX gF2Dj8vkmAnmrz02aDnO/ynM2WttO3w= 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-111-03ryDTbVNNSWteLhJE3O2A-1; Mon, 16 Nov 2020 06:36:29 -0500 X-MC-Unique: 03ryDTbVNNSWteLhJE3O2A-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CF89F9CC02; Mon, 16 Nov 2020 11:36:27 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id B45B45D9CC; Mon, 16 Nov 2020 11:36:26 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, xuan.ding@intel.com Cc: Maxime Coquelin Date: Mon, 16 Nov 2020 12:36:18 +0100 Message-Id: <20201116113620.587073-2-maxime.coquelin@redhat.com> In-Reply-To: <20201116113620.587073-1-maxime.coquelin@redhat.com> References: <20201116113620.587073-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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 Subject: [dpdk-dev] [PATCH 21.02 1/3] vhost: refactor postcopy region registration X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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 memory regions to userfaultfd to a dedicated function, with the goal of simplifying VHOST_USER_SET_MEM_TABLE request handling function. Signed-off-by: Maxime Coquelin --- lib/librte_vhost/vhost_user.c | 77 +++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 45c8ac09da..b8a9e41a2d 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -998,6 +998,49 @@ vhost_memory_changed(struct VhostUserMemory *new, return false; } +#ifdef RTE_LIBRTE_VHOST_POSTCOPY +static int +vhost_user_postcopy_region_register(struct virtio_net *dev, + struct rte_vhost_mem_region *reg) +{ + struct uffdio_register reg_struct; + + /* + * Let's register all the mmap'ed area to ensure + * alignment on page boundary. + */ + reg_struct.range.start = (uint64_t)(uintptr_t)reg->mmap_addr; + reg_struct.range.len = reg->mmap_size; + reg_struct.mode = UFFDIO_REGISTER_MODE_MISSING; + + if (ioctl(dev->postcopy_ufd, UFFDIO_REGISTER, + ®_struct)) { + VHOST_LOG_CONFIG(ERR, "Failed to register ufd for region " + "%" PRIx64 " - %" PRIx64 " (ufd = %d) %s\n", + (uint64_t)reg_struct.range.start, + (uint64_t)reg_struct.range.start + + (uint64_t)reg_struct.range.len - 1, + dev->postcopy_ufd, + strerror(errno)); + return -1; + } + + VHOST_LOG_CONFIG(INFO, "\t userfaultfd registered for range : %" PRIx64 " - %" PRIx64 "\n", + (uint64_t)reg_struct.range.start, + (uint64_t)reg_struct.range.start + + (uint64_t)reg_struct.range.len - 1); + + return 0; +} +#else +static int +vhost_user_postcopy_region_register(struct virtio_net *dev, + struct rte_vhost_mem_region *reg) +{ + return -1; +} +#endif + static int vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg, int main_fd) @@ -1209,38 +1252,10 @@ vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *msg, } /* Now userfault register and we can use the memory */ - for (i = 0; i < memory->nregions; i++) { -#ifdef RTE_LIBRTE_VHOST_POSTCOPY - reg = &dev->mem->regions[i]; - struct uffdio_register reg_struct; - - /* - * Let's register all the mmap'ed area to ensure - * alignment on page boundary. - */ - reg_struct.range.start = - (uint64_t)(uintptr_t)reg->mmap_addr; - reg_struct.range.len = reg->mmap_size; - reg_struct.mode = UFFDIO_REGISTER_MODE_MISSING; - - if (ioctl(dev->postcopy_ufd, UFFDIO_REGISTER, - ®_struct)) { - VHOST_LOG_CONFIG(ERR, - "Failed to register ufd for region %d: (ufd = %d) %s\n", - i, dev->postcopy_ufd, - strerror(errno)); + for (i = 0; i < memory->nregions; i++) + if (vhost_user_postcopy_region_register(dev, + &dev->mem->regions[i]) < 0) goto free_mem_table; - } - VHOST_LOG_CONFIG(INFO, - "\t userfaultfd registered for range : " - "%" PRIx64 " - %" PRIx64 "\n", - (uint64_t)reg_struct.range.start, - (uint64_t)reg_struct.range.start + - (uint64_t)reg_struct.range.len - 1); -#else - goto free_mem_table; -#endif - } } for (i = 0; i < dev->nr_vring; i++) {