From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by dpdk.org (Postfix) with ESMTP id 2C2C41B20E for ; Mon, 8 Oct 2018 18:19:54 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20181008161953euoutp0246b4f9ed8413f054f9e46b889bad4992~brodPPR6M0697506975euoutp02u for ; Mon, 8 Oct 2018 16:19:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20181008161953euoutp0246b4f9ed8413f054f9e46b889bad4992~brodPPR6M0697506975euoutp02u DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1539015593; bh=EcKfsgx3rK9cqyxKtvbkXtiz0/NILVmAIy2ExUDgB5k=; h=Subject:To:Cc:From:Date:In-Reply-To:References:From; b=ecZggSef91EoUmgYEzyX37Gfv+6nHfNn8QRwWTOUC5f5KBSvUszM7vpHxYCXnZbRT DlYHTqjT12vx31J5AAwhJYYM3JtVURrw/kXKDYCuAiW29/+bfYPOicnO53FCBY2cjt oFpdq1EGTLxne6/KYQMlNxEQ6+srFiSR7Dh+TYHo= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20181008161953eucas1p13f32f279824f71c642cf16ee72905203~brocvS42i1624716247eucas1p1p; Mon, 8 Oct 2018 16:19:53 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 14.39.04294.8A38BBB5; Mon, 8 Oct 2018 17:19:52 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20181008161952eucas1p2f3a63c4bff2e2160b482d865a6a0c9d9~brobzb3311921019210eucas1p2h; Mon, 8 Oct 2018 16:19:52 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20181008161952eusmtrp1d3c0aa43f896586d42b095f0c0d11da3~brobhVaTP2175321753eusmtrp1E; Mon, 8 Oct 2018 16:19:52 +0000 (GMT) X-AuditID: cbfec7f4-835ff700000010c6-b9-5bbb83a854bd Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id F4.D5.04128.7A38BBB5; Mon, 8 Oct 2018 17:19:51 +0100 (BST) Received: from [106.109.129.180] (unknown [106.109.129.180]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20181008161951eusmtip13c78e6c99ea5bea8b21b2a4e6bc69b88~broa0n1Pj1731117311eusmtip1s; Mon, 8 Oct 2018 16:19:51 +0000 (GMT) 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 Cc: dgilbert@redhat.com, stable@dpdk.org From: Ilya Maximets Date: Mon, 8 Oct 2018 19:22:14 +0300 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: <20181008152557.14275-12-maxime.coquelin@redhat.com> Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA01SfyyUcRze99733vd1nL0Ou89OTbusaKFi864a1Zrd6p+stcrNcuUNw7F7 UfxRKuVXP3QWdVNYHfIjqUOOWo4dUhfC2PqhZhOGhWp+jNy9LP893+f5Ps/z+Xz3pTBJq1BG RasTWY1aFSsnRHi9ed7iXX6tSblrocyPscyUCpjBiiBmaqZBwNyq/0oyfRnzJGOp0uOMOasZ Z7pKBnBmOXOJZOrSVgTMyx6t4IC9YqFYL1Q06r6QisfNYwJFQc53TDH9pp9Q3DZUoGN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5hBkkIC3hIXJm/FiwhInCH UWLLrDOMIAlmAQ2J9VefMEJ0nGKUuLl9BztIgk1AR+LU6iNgRbwCdhJb9vaB2SwCKhKtlyeD TRUViJBYvfwFK0SNoMTJmU9YQGxOAUeJrQtboBaoS/yZd4kZwhaXaPqykhXClpfY/nYO8wRG oVlI2mchaZmFpGUWkpYFjCyrGEVSS4tz03OLjfSKE3OLS/PS9ZLzczcxAmN127GfW3Ywdr0L PsQowMGoxMM7I293tBBrYllxZe4hRgkOZiURXtHtu6KFeFMSK6tSi/Lji0pzUosPMZoCPTeR WUo0OR+YRvJK4g1NDc0tLA3Njc2NzSyUxHnPG1RGCQmkJ5akZqemFqQWwfQxcXBKNTA277a/ +8XL4sX1asGrjhuWbXy55kTeZ+H7SssLndTttQqNehjXOq4WiGVVnnnEdor4go60vy+nyvdc yP78yCx663xeSxZxoRvplyOvLjm64aH1PIl1Mauu/PvxWMDM97BmwFaxJ1IH2c05Owyy66ri ZzPN2FUzd/3vMvbj9utZv9bWRVgdia5SYinOSDTUYi4qTgQACm0cuesCAAA= Message-Id: <20181008161952eucas1p2f3a63c4bff2e2160b482d865a6a0c9d9~brobzb3311921019210eucas1p2h@eucas1p2.samsung.com> X-CMS-MailID: 20181008161952eucas1p2f3a63c4bff2e2160b482d865a6a0c9d9 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20181008152658epcas2p1b7fc9c1c265ab06b3ed55cffaa038460 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20181008152658epcas2p1b7fc9c1c265ab06b3ed55cffaa038460 References: <20181008152557.14275-1-maxime.coquelin@redhat.com> <20181008152557.14275-12-maxime.coquelin@redhat.com> Subject: Re: [dpdk-dev] [PATCH v4 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: Mon, 08 Oct 2018 16:19:55 -0000 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. > + 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); > @@ -1535,6 +1583,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 { >