From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 4D1FE49E0; Tue, 9 Oct 2018 09:59:27 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5892B308427C; Tue, 9 Oct 2018 07:59:26 +0000 (UTC) Received: from [10.36.112.57] (ovpn-112-57.ams2.redhat.com [10.36.112.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1E8211057072; Tue, 9 Oct 2018 07:59:12 +0000 (UTC) To: Ilya Maximets , dev@dpdk.org, tiwei.bie@intel.com, zhihong.wang@intel.com, jfreimann@redhat.com, nicknickolaev@gmail.com, bruce.richardson@intel.com, alejandro.lucero@netronome.com Cc: dgilbert@redhat.com, stable@dpdk.org References: <20181008152557.14275-1-maxime.coquelin@redhat.com> <20181008152557.14275-12-maxime.coquelin@redhat.com> <20181008161952eucas1p2f3a63c4bff2e2160b482d865a6a0c9d9~brobzb3311921019210eucas1p2h@eucas1p2.samsung.com> From: Maxime Coquelin Message-ID: Date: Tue, 9 Oct 2018 09:59:10 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20181008161952eucas1p2f3a63c4bff2e2160b482d865a6a0c9d9~brobzb3311921019210eucas1p2h@eucas1p2.samsung.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 09 Oct 2018 07:59:26 +0000 (UTC) Subject: Re: [dpdk-stable] [PATCH v4 11/19] vhost: introduce postcopy's advise message X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Oct 2018 07:59:27 -0000 On 10/08/2018 06:22 PM, Ilya Maximets wrote: > On 08.10.2018 18:25, Maxime Coquelin wrote: >> This patch opens a userfaultfd and sends it back to Qemu's >> VHOST_USER_POSTCOPY_ADVISE request. >> >> Signed-off-by: Dr. David Alan Gilbert >> Signed-off-by: Maxime Coquelin >> --- >> lib/librte_vhost/vhost.h | 2 ++ >> lib/librte_vhost/vhost_user.c | 49 +++++++++++++++++++++++++++++++++++ >> lib/librte_vhost/vhost_user.h | 3 ++- >> 3 files changed, 53 insertions(+), 1 deletion(-) >> >> diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h >> index 25ffd7614..21722d8a8 100644 >> --- a/lib/librte_vhost/vhost.h >> +++ b/lib/librte_vhost/vhost.h >> @@ -363,6 +363,8 @@ struct virtio_net { >> int slave_req_fd; >> rte_spinlock_t slave_req_lock; >> >> + int postcopy_ufd; >> + >> /* >> * Device id to identify a specific backend device. >> * It's set to -1 for the default software implementation. >> diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c >> index 20f38267d..3cdd2af28 100644 >> --- a/lib/librte_vhost/vhost_user.c >> +++ b/lib/librte_vhost/vhost_user.c >> @@ -24,13 +24,19 @@ >> #include >> #include >> #include >> +#include >> +#include >> #include >> #include >> #include >> +#include >> #include >> #ifdef RTE_LIBRTE_VHOST_NUMA >> #include >> #endif >> +#ifdef RTE_LIBRTE_VHOST_POSTCOPY >> +#include >> +#endif >> >> #include >> #include >> @@ -69,6 +75,7 @@ static const char *vhost_message_str[VHOST_USER_MAX] = { >> [VHOST_USER_IOTLB_MSG] = "VHOST_USER_IOTLB_MSG", >> [VHOST_USER_CRYPTO_CREATE_SESS] = "VHOST_USER_CRYPTO_CREATE_SESS", >> [VHOST_USER_CRYPTO_CLOSE_SESS] = "VHOST_USER_CRYPTO_CLOSE_SESS", >> + [VHOST_USER_POSTCOPY_ADVISE] = "VHOST_USER_POSTCOPY_ADVISE", >> }; >> >> /* The possible results of a message handling function */ >> @@ -130,6 +137,11 @@ vhost_backend_cleanup(struct virtio_net *dev) >> close(dev->slave_req_fd); >> dev->slave_req_fd = -1; >> } >> + >> + if (dev->postcopy_ufd >= 0) { >> + close(dev->postcopy_ufd); >> + dev->postcopy_ufd = -1; >> + } >> } >> >> /* >> @@ -1508,6 +1520,42 @@ vhost_user_iotlb_msg(struct virtio_net **pdev, struct VhostUserMsg *msg, >> return VH_RESULT_OK; >> } >> >> +static int >> +vhost_user_set_postcopy_advise(struct virtio_net **pdev, >> + struct VhostUserMsg *msg, >> + int main_fd __rte_unused) >> +{ >> + struct virtio_net *dev = *pdev; >> +#ifdef RTE_LIBRTE_VHOST_POSTCOPY >> + struct uffdio_api api_struct; >> + >> + dev->postcopy_ufd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK); >> + >> + if (dev->postcopy_ufd == -1) { >> + RTE_LOG(ERR, VHOST_CONFIG, "Userfaultfd not available: %s\n", >> + strerror(errno)); >> + return VH_RESULT_ERR; >> + } >> + api_struct.api = UFFD_API; >> + api_struct.features = 0; >> + if (ioctl(dev->postcopy_ufd, UFFDIO_API, &api_struct)) { >> + RTE_LOG(ERR, VHOST_CONFIG, "UFFDIO_API ioctl failure: %s\n", >> + strerror(errno)); >> + close(dev->postcopy_ufd); > > Need to clear dev->postcopy_ufd value to avoid accidental closing of some > other fd on backend cleanup. Good catch, it will be fixed in v5. Thanks! Maxime