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 710D6A09FF; Tue, 5 Jan 2021 13:58:13 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0545416083B; Tue, 5 Jan 2021 13:58:09 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mails.dpdk.org (Postfix) with ESMTP id D3E88160829 for ; Tue, 5 Jan 2021 13:58:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609851486; 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=ar0grFvVc+FcwtXEGRzpcEHAMwdToBRARoPJY7VBIsY=; b=F9+csdkEdwOpPlTfuzSfav7oeGYIzlVsqX6yuEno8pcIdtVyGXdEJapFuSrEBiUJs+Xt3i v2gt9gLIrWdWp1hDxwxbWRQwcfR5di5tSqC+/isBd1QyMh5Bu8d5Dd3gDuvk3mF+aG10Td S8IGTFfmXdvzdRfCrZF02rgZ9aQb/6Y= 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-204-frlVlBrFOmO7M5iEyWYAKA-1; Tue, 05 Jan 2021 07:58:04 -0500 X-MC-Unique: frlVlBrFOmO7M5iEyWYAKA-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 A3764107ACE4; Tue, 5 Jan 2021 12:58:03 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.36.110.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B40A18B5E; Tue, 5 Jan 2021 12:58:02 +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:26 +0100 Message-Id: <20210105125728.102413-2-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 1/3] vhost: refactor postcopy region 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 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..b6c8e2e17f 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 __rte_unused, + struct rte_vhost_mem_region *reg __rte_unused) +{ + 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++) { -- 2.29.2