From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ilya Maximets Subject: Re: [PATCH v3 11/19] vhost: introduce postcopy's advise message Date: Fri, 5 Oct 2018 14:58:01 +0300 Message-ID: <20181005115541eucas1p1893250ad7dc2d2ab3c7da5000a68b199~atF62GFUW1471914719eucas1p1O@eucas1p1.samsung.com> References: <20181004081403.8039-1-maxime.coquelin@redhat.com> <20181004081403.8039-12-maxime.coquelin@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: dgilbert@redhat.com, stable@dpdk.org To: Maxime Coquelin , 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 Return-path: Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id 5090323D for ; Fri, 5 Oct 2018 13:55:43 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20181005115543euoutp011de34e3f69328cb65da69515f432e26b~atF8RIxs61116511165euoutp01O for ; Fri, 5 Oct 2018 11:55:43 +0000 (GMT) In-Reply-To: <20181004081403.8039-12-maxime.coquelin@redhat.com> Content-Language: en-GB List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Cleanup part is missing in this patch. We should close and clear postcopy_ufd in vhost_backend_cleanup(). Best regards, Ilya Maximets. On 04.10.2018 11:13, 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 | 44 +++++++++++++++++++++++++++++++++++ > lib/librte_vhost/vhost_user.h | 3 ++- > 3 files changed, 48 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 0a1934649..3d4fc60fc 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 */ > @@ -1509,6 +1516,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); > + return VH_RESULT_ERR; > + } > + msg->fds[0] = dev->postcopy_ufd; > + msg->fd_num = 1; > + > + return VH_RESULT_REPLY; > +#else > + dev->postcopy_ufd = -1; > + msg->fd_num = 0; > + > + return VH_RESULT_ERR; > +#endif > +} > + > typedef int (*vhost_message_handler_t)(struct virtio_net **pdev, > struct VhostUserMsg *msg, > int main_fd); > @@ -1536,6 +1579,7 @@ static vhost_message_handler_t vhost_message_handlers[VHOST_USER_MAX] = { > [VHOST_USER_NET_SET_MTU] = vhost_user_net_set_mtu, > [VHOST_USER_SET_SLAVE_REQ_FD] = vhost_user_set_req_fd, > [VHOST_USER_IOTLB_MSG] = vhost_user_iotlb_msg, > + [VHOST_USER_POSTCOPY_ADVISE] = vhost_user_set_postcopy_advise, > }; > > > diff --git a/lib/librte_vhost/vhost_user.h b/lib/librte_vhost/vhost_user.h > index dd0262f8f..2030b40a5 100644 > --- a/lib/librte_vhost/vhost_user.h > +++ b/lib/librte_vhost/vhost_user.h > @@ -50,7 +50,8 @@ typedef enum VhostUserRequest { > VHOST_USER_IOTLB_MSG = 22, > VHOST_USER_CRYPTO_CREATE_SESS = 26, > VHOST_USER_CRYPTO_CLOSE_SESS = 27, > - VHOST_USER_MAX = 28 > + VHOST_USER_POSTCOPY_ADVISE = 28, > + VHOST_USER_MAX = 29 > } VhostUserRequest; > > typedef enum VhostUserSlaveRequest { >