From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by dpdk.org (Postfix) with ESMTP id C4DF41B575 for ; Thu, 11 Oct 2018 17:57:11 +0200 (CEST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20181011155710euoutp01abb330d5063d4d0c128dfb53c73b0add~cmQeyCjdT2805328053euoutp01L for ; Thu, 11 Oct 2018 15:57:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20181011155710euoutp01abb330d5063d4d0c128dfb53c73b0add~cmQeyCjdT2805328053euoutp01L DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1539273431; bh=2B6gwC+77U1IdNOwgKuvMch/Ma4bzKGfboAhNwT+lKA=; h=Subject:To:Cc:From:Date:In-Reply-To:References:From; b=Dtir7ANZigR5/LCqXyzx/SqAymKSYrgRPRKVJfq7jXekJCCxMdSW7HKPT5UDPPuG6 8RKGZLMkOdUAQXch8PrtY/O/UkgZAw09wHOBHDEguGEIGHOXffSWFbU9v0Cp2Dd3kI PODzY/4pK68SmvIb55/xi+bOuwP4x3gVHFonwwEY= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20181011155710eucas1p1abf7f4aff4aa73e24c9ba3d35227743e~cmQePu_5B1723417234eucas1p1E; Thu, 11 Oct 2018 15:57:10 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 90.BD.04294.6D27FBB5; Thu, 11 Oct 2018 16:57:10 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20181011155709eucas1p20da3d82e3f74a0f8b8bd06eae4baa0c5~cmQddRjzg2527125271eucas1p2_; Thu, 11 Oct 2018 15:57:09 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20181011155709eusmtrp157c599fdb13bb6e53712d58d036f71c4~cmQdMTZ-83269932699eusmtrp1l; Thu, 11 Oct 2018 15:57:09 +0000 (GMT) X-AuditID: cbfec7f4-835ff700000010c6-0c-5bbf72d61107 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 2D.C9.04128.5D27FBB5; Thu, 11 Oct 2018 16:57:09 +0100 (BST) Received: from [106.109.129.180] (unknown [106.109.129.180]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20181011155708eusmtip2558008c408b7f13e3e87415dbb886418~cmQcgQk2h0944209442eusmtip2G; Thu, 11 Oct 2018 15:57:08 +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: Thu, 11 Oct 2018 18:59:38 +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: <20181011092432.22275-8-maxime.coquelin@redhat.com> Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA01Se0hTcRTmd+/ddrVm16ns+MJaSimlFRK3kFQI2p/2glTQVl585FQ2tQwi K03zRWo6HSaT8jUr0Ww+UMthLrVMh0/KXhih5iOdpCarbVfJ/77zfec753xwSFzwmuNERscl MrI4SayIa01oetYGDo7KXoYeerfAoQeWqjB6XO1Pzy81Y3Su5hOPHs5Y49EDTyoJuudeO0H3 V4wStDFzg0e/SP2L0c+HCrCAHeJ1VSVH3Kqc5IkftU9jYkX2V1y80DnCFec1qV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AJYYEoiamb3jGBJEQE 7jBKbJl1hhEkwSygIbH+6hMwW0jgJKPEr73CIDabgI7EqdVHwOK8AnYSD9+0sIPYLAKqEtsn vQLbLCoQIbF6+QtWiBpBiZMzn4At4xRwkPh+cTITxHx1iT/zLjFD2OISTV9WskLY8hLb385h nsAoNAtJ+ywkLbOQtMxC0rKAkWUVo0hqaXFuem6xkV5xYm5xaV66XnJ+7iZGYKRuO/Zzyw7G rnfBhxgFOBiVeHh/SO2LFmJNLCuuzD3EKMHBrCTCqz8DKMSbklhZlVqUH19UmpNafIjRFOi5 icxSosn5wCSSVxJvaGpobmFpaG5sbmxmoSTOe96gMkpIID2xJDU7NbUgtQimj4mDU6qBMdLn X/+PUx67ND05d+2SzPNy2LXpkq1yydqzJv3PgkXz2UzuBl+JvzFp3yWbrXmWuy3uT/0sJLKB bdEe/qt2S3cs90+9tofjvqikUsjXgFbWg0Y8B80s+1d8tjx+SLru5KSspz8flM+wPlZc1yJY emL/oTzzE2/WFW40bZGcdyBLQ67lr+X0S0osxRmJhlrMRcWJAJVW8wHqAgAA Message-Id: <20181011155709eucas1p20da3d82e3f74a0f8b8bd06eae4baa0c5~cmQddRjzg2527125271eucas1p2_@eucas1p2.samsung.com> X-CMS-MailID: 20181011155709eucas1p20da3d82e3f74a0f8b8bd06eae4baa0c5 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20181011092527epcas3p4fd03af04db4d68c5c094521cf509e26c X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20181011092527epcas3p4fd03af04db4d68c5c094521cf509e26c References: <20181011092432.22275-1-maxime.coquelin@redhat.com> <20181011092432.22275-8-maxime.coquelin@redhat.com> Subject: Re: [dpdk-dev] [PATCH v6 07/19] vhost: add number of fds to vhost-user messages and use it 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 15:57:11 -0000 On 11.10.2018 12:24, Maxime Coquelin wrote: > As soon as some ancillary data (fds) are received, it is copied > without checking its length. > > This patch adds the number of fds received to the message, > which is set in read_vhost_message(). > > This is preliminary work to support sending fds to Qemu. > > Signed-off-by: Dr. David Alan Gilbert > Signed-off-by: Maxime Coquelin > --- > lib/librte_vhost/socket.c | 25 ++++++++++++++++++++----- > lib/librte_vhost/vhost_user.c | 2 +- > lib/librte_vhost/vhost_user.h | 4 +++- > 3 files changed, 24 insertions(+), 7 deletions(-) > > diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c > index d63031747..3b0287a26 100644 > --- a/lib/librte_vhost/socket.c > +++ b/lib/librte_vhost/socket.c > @@ -94,18 +94,24 @@ static struct vhost_user vhost_user = { > .mutex = PTHREAD_MUTEX_INITIALIZER, > }; > > -/* return bytes# of read on success or negative val on failure. */ > +/* > + * return bytes# of read on success or negative val on failure. Update fdnum > + * with number of fds read. > + */ > int > -read_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num) > +read_fd_message(int sockfd, char *buf, int buflen, int *fds, int max_fds, > + int *fd_num) > { > struct iovec iov; > struct msghdr msgh; > - size_t fdsize = fd_num * sizeof(int); > - char control[CMSG_SPACE(fdsize)]; > + char control[CMSG_SPACE(max_fds * sizeof(int))]; > struct cmsghdr *cmsg; > int got_fds = 0; > + int *tmp_fds; > int ret; > > + *fd_num = 0; > + > memset(&msgh, 0, sizeof(msgh)); > iov.iov_base = buf; > iov.iov_len = buflen; > @@ -131,13 +137,22 @@ read_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num) > if ((cmsg->cmsg_level == SOL_SOCKET) && > (cmsg->cmsg_type == SCM_RIGHTS)) { > got_fds = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int); > + if (got_fds > max_fds) { Hmm. I just noticed that 'msg_controllen' is set to receive not more than max_fds descriptors. So, this case should not be possible. We will receive MSG_CTRUNC and return before the loop. > + RTE_LOG(ERR, VHOST_CONFIG, > + "Received msg contains more fds than supported\n"); > + tmp_fds = (int *)CMSG_DATA(cmsg); > + while (got_fds--) > + close(tmp_fds[got_fds]); > + return -1; > + } > + *fd_num = got_fds; > memcpy(fds, CMSG_DATA(cmsg), got_fds * sizeof(int)); > break; > } > } > > /* Clear out unused file descriptors */ > - while (got_fds < fd_num) > + while (got_fds < max_fds) > fds[got_fds++] = -1; > > return ret; > diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c > index 83d3e6321..c1c5f35ff 100644 > --- a/lib/librte_vhost/vhost_user.c > +++ b/lib/librte_vhost/vhost_user.c > @@ -1509,7 +1509,7 @@ read_vhost_message(int sockfd, struct VhostUserMsg *msg) > int ret; > > ret = read_fd_message(sockfd, (char *)msg, VHOST_USER_HDR_SIZE, > - msg->fds, VHOST_MEMORY_MAX_NREGIONS); > + msg->fds, VHOST_MEMORY_MAX_NREGIONS, &msg->fd_num); > if (ret <= 0) > return ret; > > diff --git a/lib/librte_vhost/vhost_user.h b/lib/librte_vhost/vhost_user.h > index 62654f736..9a91d496b 100644 > --- a/lib/librte_vhost/vhost_user.h > +++ b/lib/librte_vhost/vhost_user.h > @@ -132,6 +132,7 @@ typedef struct VhostUserMsg { > VhostUserVringArea area; > } payload; > int fds[VHOST_MEMORY_MAX_NREGIONS]; > + int fd_num; > } __attribute((packed)) VhostUserMsg; > > #define VHOST_USER_HDR_SIZE offsetof(VhostUserMsg, payload.u64) > @@ -155,7 +156,8 @@ int vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm); > int vhost_user_host_notifier_ctrl(int vid, bool enable); > > /* socket.c */ > -int read_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num); > +int read_fd_message(int sockfd, char *buf, int buflen, int *fds, int max_fds, > + int *fd_num); > int send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num); > > #endif >