From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by dpdk.org (Postfix) with ESMTP id 375157CD2 for ; Wed, 26 Sep 2018 17:23:10 +0200 (CEST) Received: by mail-ed1-f66.google.com with SMTP id f38-v6so2237478edd.8 for ; Wed, 26 Sep 2018 08:23:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/7skFKomewFGqvV/8rKhgUhVjAt+zvn5EkhzCxfzNQs=; b=J71QDQ5rRuEVtte6JhiZcZIFVeki4F5FxnBccLL+zRL0SQlRV3+iGwDNL4aWjalyzM PnevrfHM/Ua6hW5b+h8RRLooXDMBvbXrldgSTJkLpc5i6cTgQFnVfxTngc18JY+dLXm3 de7Nx5vZakyCJHMmcw9jIK8Ph4s2GcrnAwnAuPIqhjTiXIuhAbCtO6CQ2NDLIbLQ3wkb ghoDW4xvxW8/YSMF+i1HyuK35bX5LBfzB6bJOSqDfbUKaTuBQpCOWqUtwYKH7AEI58Yl IM0/PtskFQLT3q6BFuDQkvIG0BeW3h+AE2941bb/KkFVA6k0COfiScyZdBSECIh6hsBj PKCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/7skFKomewFGqvV/8rKhgUhVjAt+zvn5EkhzCxfzNQs=; b=on4f5ZxxHR/ayt96IqhI147GlpuWW47jXNrAWugZ0sEFptRfL6VRFu3vPe8ynSToA4 2o4LYZ0W3ULf1MTwuF3lR3KqMp82Lz7VYuiazMA3FGeuGi1QlCFEXq7zdZwH07dcLTq9 pmjDluhwaKh3QVY1aeuYLxLvaCSc6YtLZfjt5YOnKNtMjOazdQmtxA9d20fZ82wtoUqv 4gFfQmRWGmai9MLpjOikiFY/wuBAFZGpCbZhf/ISYaFbV7EIxdb8lpAD2CuWaUwV5QI4 uG9leocE9wEj+rdmbqyvcjmcQSwU0W+ABr9x6adnLUbO3T2J24jXyUfNrtudznS6Bh77 5qfA== X-Gm-Message-State: ABuFfohVtqkXMXCzOWtt7sDnDz0CvkKlKiIrVtJgUjvx5VzKXdPUnPLO 14bffbXPpXWlKDiKExpc4cOU3WlyGvvYlK9sdOSScE5P X-Google-Smtp-Source: ACcGV63d7eyblvdg3tF44KlMstpIf7JVNrkAssEXsN82GmyRI9MZmTpJCb0eBgOxkqmtPw5LwIVyC6M4iVJIcY6s88k= X-Received: by 2002:a05:6402:1545:: with SMTP id p5mr10016756edx.104.1537975389843; Wed, 26 Sep 2018 08:23:09 -0700 (PDT) MIME-Version: 1.0 References: <20180926072705.22641-1-maxime.coquelin@redhat.com> <20180926072705.22641-5-maxime.coquelin@redhat.com> In-Reply-To: <20180926072705.22641-5-maxime.coquelin@redhat.com> From: Alejandro Lucero Date: Wed, 26 Sep 2018 16:22:59 +0100 Message-ID: To: Maxime Coquelin Cc: dev , tiwei.bie@intel.com, zhihong.wang@intel.com, jfreimann@redhat.com, dgilbert@redhat.com Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: Re: [dpdk-dev] [PATCH 04/12] 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: Wed, 26 Sep 2018 15:23:10 -0000 On Wed, Sep 26, 2018 at 8:27 AM 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 | 37 +++++++++++++++++++++++++++++++++++ > lib/librte_vhost/vhost_user.h | 3 ++- > 3 files changed, 41 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 a9b429598..bdfe2cac0 100644 > --- a/lib/librte_vhost/vhost_user.c > +++ b/lib/librte_vhost/vhost_user.c > @@ -24,9 +24,13 @@ > #include > #include > #include > +#include > +#include > +#include > #include > #include > #include > +#include > #include > #ifdef RTE_LIBRTE_VHOST_NUMA > #include > @@ -69,6 +73,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 > @@ -1412,6 +1417,33 @@ vhost_user_iotlb_msg(struct virtio_net **pdev, > struct VhostUserMsg *msg) > return 0; > } > > +static int > +vhost_user_set_postcopy_advise(struct virtio_net *dev, struct > VhostUserMsg *msg) > +{ > + 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 -1; > + } > + 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 -1; > + } > + msg->fds[0] = dev->postcopy_ufd; > + msg->fd_num = 1; > + > + return 0; > +} > + > /* return bytes# of read on success or negative val on failure. */ > static int > read_vhost_message(int sockfd, struct VhostUserMsg *msg) > @@ -1756,6 +1788,11 @@ vhost_user_msg_handler(int vid, int fd) > ret = vhost_user_iotlb_msg(&dev, &msg); > break; > > + case VHOST_USER_POSTCOPY_ADVISE: > + vhost_user_set_postcopy_advise(dev, &msg); > + send_vhost_reply(fd, &msg); > + break; > + > This should handle the case of vhost_user_set_postcopy_advise returning an error. Otherwise the msg wrong contents are sent back. > default: > ret = -1; > break; > 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 { > -- > 2.17.1 > >