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 3F56C7CBC for ; Thu, 27 Sep 2018 11:35:49 +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 75B0A5D669; Thu, 27 Sep 2018 09:35:48 +0000 (UTC) Received: from [10.36.112.65] (ovpn-112-65.ams2.redhat.com [10.36.112.65]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 14858600C7; Thu, 27 Sep 2018 09:35:43 +0000 (UTC) To: Alejandro Lucero Cc: dev , tiwei.bie@intel.com, zhihong.wang@intel.com, jfreimann@redhat.com, dgilbert@redhat.com References: <20180926072705.22641-1-maxime.coquelin@redhat.com> <20180926072705.22641-5-maxime.coquelin@redhat.com> From: Maxime Coquelin Message-ID: Date: Thu, 27 Sep 2018 11:35:42 +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: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit 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.39]); Thu, 27 Sep 2018 09:35:48 +0000 (UTC) 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: Thu, 27 Sep 2018 09:35:49 -0000 On 09/26/2018 05:22 PM, Alejandro Lucero wrote: > > > 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. Right, I'll fix it when rebasing. > >         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 > Thanks, Maxime