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 767351B1BB; Thu, 11 Oct 2018 11:25:57 +0200 (CEST) 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 mx1.redhat.com (Postfix) with ESMTPS id AD78343A22; Thu, 11 Oct 2018 09:25:56 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-55.ams2.redhat.com [10.36.112.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0EB2718A44; Thu, 11 Oct 2018 09:25:47 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, tiwei.bie@intel.com, zhihong.wang@intel.com, jfreimann@redhat.com, nicknickolaev@gmail.com, i.maximets@samsung.com, bruce.richardson@intel.com, alejandro.lucero@netronome.com Cc: dgilbert@redhat.com, stable@dpdk.org, Maxime Coquelin Date: Thu, 11 Oct 2018 11:24:24 +0200 Message-Id: <20181011092432.22275-12-maxime.coquelin@redhat.com> In-Reply-To: <20181011092432.22275-1-maxime.coquelin@redhat.com> References: <20181011092432.22275-1-maxime.coquelin@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 11 Oct 2018 09:25:56 +0000 (UTC) Subject: [dpdk-dev] [PATCH v6 11/19] vhost: introduce postcopy's advise message 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: , X-List-Received-Date: Thu, 11 Oct 2018 09:25:58 -0000 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 | 50 +++++++++++++++++++++++++++++++++++ lib/librte_vhost/vhost_user.h | 3 ++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index 341b0a147..4c591a410 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -358,6 +358,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 99adcedfa..970ad5896 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", }; static uint64_t @@ -120,6 +127,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; + } } /* @@ -1500,6 +1512,43 @@ 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); + dev->postcopy_ufd = -1; + 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); @@ -1527,6 +1576,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 9a91d496b..04295d9a6 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 { -- 2.17.1