From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B95FCA052A; Tue, 22 Dec 2020 11:51:23 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 12D5DCA60; Tue, 22 Dec 2020 11:51:22 +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 D064ACA3B for ; Tue, 22 Dec 2020 11:51:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608634278; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oIRQAO7+Y/zudarwpmLmZr2aNIPgfKVTOQ/P8ik75kc=; b=VfNb/d3WamYhE43DtRz0OdocoNW9BQWxwFtC0gLDiqs2f3UJS2z7HzD1/jHTmye/KNykEu vRsilZnxVfrQRwM87pE52M6eX1TAEWAz6OROeLAYjEAKQ213OPGIWthlZiT/Dk08T8EuJN pIJdiax9fHahrN5l0SvYiwqrMHC6RCE= 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-181-fLqwj7DEMv6Lm0QkNrJDIQ-1; Tue, 22 Dec 2020 05:51:14 -0500 X-MC-Unique: fLqwj7DEMv6Lm0QkNrJDIQ-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 29363100F352; Tue, 22 Dec 2020 10:51:13 +0000 (UTC) Received: from [10.36.110.46] (unknown [10.36.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 29AAE5DE68; Tue, 22 Dec 2020 10:51:11 +0000 (UTC) To: "Xia, Chenbo" , "dev@dpdk.org" , "Ding, Xuan" References: <20201116113620.587073-1-maxime.coquelin@redhat.com> <20201116113620.587073-2-maxime.coquelin@redhat.com> From: Maxime Coquelin Message-ID: Date: Tue, 22 Dec 2020 11:51:10 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: 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 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Subject: Re: [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" Hi Chenbo, On 12/9/20 3:16 PM, Xia, Chenbo wrote: > Hi Maxime, > >> -----Original Message----- >> From: Maxime Coquelin >> Sent: Monday, November 16, 2020 7:36 PM >> To: dev@dpdk.org; Xia, Chenbo ; Ding, Xuan >> >> Cc: Maxime Coquelin >> Subject: [PATCH 21.02 1/3] vhost: refactor postcopy region registration >> >> 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; >> +} > > Better add __rte_unused here to avoid warnings when postcopy not configured 😊 Good catch! I will post a v2 with adding these. Thanks, Maxime > Thanks, > Chenbo > >> +#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.26.2 >