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 6DE1C1B43D for ; Fri, 12 Oct 2018 12:01:37 +0200 (CEST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20181012100136euoutp013baf45f5a0dcb25b52669e0c49759a89~c1DT8Gj200741607416euoutp01L for ; Fri, 12 Oct 2018 10:01:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20181012100136euoutp013baf45f5a0dcb25b52669e0c49759a89~c1DT8Gj200741607416euoutp01L DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1539338496; bh=UmwB33Zz2lvNcSL2FjC14gnykzBguwS+TvC9HSnLkL8=; h=Subject:To:Cc:From:Date:In-Reply-To:References:From; b=MI9I9FIR1jMDP8D1G2PRkr0k8FhyrUXSP1OhGBf1gGtczPRCE/D/ItdDTpzRavfd/ 703vbiLp2lNRsATIzSZKzbbhHuj4RgxrwIZPJc/oWSXIMIgpRa74Qi1+J87N5eD7Dt xK0lcVlkURUlCOSC9r94EFPvvo8K6bmMA3bed/CU= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20181012100136eucas1p230f70145e14767363b9695c6484a46e7~c1DTWt-pU1733717337eucas1p28; Fri, 12 Oct 2018 10:01:36 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 92.CC.04806.FF070CB5; Fri, 12 Oct 2018 11:01:35 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20181012100135eucas1p2510d95d7418bd32ac9017de68ca5a4e7~c1DSnF8eP1735717357eucas1p2v; Fri, 12 Oct 2018 10:01:35 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20181012100135eusmtrp189c5e3915b57a70a93c7e7d8d3afc125~c1DSYZLgr2212822128eusmtrp16; Fri, 12 Oct 2018 10:01:35 +0000 (GMT) X-AuditID: cbfec7f5-367ff700000012c6-60-5bc070ffd13d Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 6D.B4.04284.EF070CB5; Fri, 12 Oct 2018 11:01:34 +0100 (BST) Received: from [106.109.129.180] (unknown [106.109.129.180]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20181012100134eusmtip1ae313749911cad04d2202f9da3f73666~c1DRnuIQb2474924749eusmtip1p; Fri, 12 Oct 2018 10:01:34 +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, dgilbert@redhat.com Cc: stable@dpdk.org From: Ilya Maximets Date: Fri, 12 Oct 2018 13:04:07 +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: Content-Language: en-GB Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrMKsWRmVeSWpSXmKPExsWy7djP87r/Cw5EG3x5q2dx7tMyJosbq+wt 3n3azmTRu+0eu8WV9p/sFufWLGWxONa5h8Xi9MJrLBb/Ov6wW2xt+M9ksfniJCYHbo9fC5ay euycdZfdY/Gel0we07sfMnu833eVzaNvyyrGALYoLpuU1JzMstQifbsEroyv/x+wF/w1rph6 YQ1rA+MGnS5GTg4JAROJxb0PmUBsIYEVjBILnxZ2MXIB2V8YJZZ23maHcD4zSuxf+JsVpuPR q7lsEInljBKvZ05jhnA+Mkqc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qCO9iPXWCA6PrNIXF48AWwsm4COxKnVR8C6eQXsJNb/OsoCYrMIqEo0tCwA qxEViJBYvfwFK0SNoMTJmU/AajiB6tetPsMEsUBd4s+8S1DLxCWavqxkhbDlJZq3zmaewCg0 C0n7LCQts5C0zELSsoCRZRWjSGppcW56brGhXnFibnFpXrpecn7uJkZgrG479nPzDsZLG4MP MQpwMCrx8P6YuD9aiDWxrLgy9xCjBAezkgjvgqwD0UK8KYmVValF+fFFpTmpxYcYTYGem8gs JZqcD0wjeSXxhqaG5haWhubG5sZmFkrivOcNKqOEBNITS1KzU1MLUotg+pg4OKUaGMOlbm6e FP7lws2widL/z39c8GqJg4jqbgbrNo7vBr++O4d5bgn6vqh861UDGabpois/c4nUfgxbqMbA Pmvda/PK/qUbZl1foM7EPz3wypGt++9t4lN1/uDsxCkWMnOtcMt0VqH3M4K0pZdYhpn8WbEj 8Crrx+lHtl0V331SxW2m6v31F5PlcwqVWIozEg21mIuKEwEeYsOa6wIAAA== Message-Id: <20181012100135eucas1p2510d95d7418bd32ac9017de68ca5a4e7~c1DSnF8eP1735717357eucas1p2v@eucas1p2.samsung.com> X-CMS-MailID: 20181012100135eucas1p2510d95d7418bd32ac9017de68ca5a4e7 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> <20181011155709eucas1p20da3d82e3f74a0f8b8bd06eae4baa0c5~cmQddRjzg2527125271eucas1p2_@eucas1p2.samsung.com> <377e0ee1-562d-e5cb-e411-e041f8c60ba5@redhat.com> <7df5b8ea-6570-e2ab-1983-e74d316e530d@redhat.com> <72d63d93-ba13-d228-d67a-0bbdbebeceaf@redhat.com> <20181012095039eucas1p12ad20f88162a3e0eed0464d05acc8a08~c05vvgLoP1463314633eucas1p1l@eucas1p1.samsung.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: Fri, 12 Oct 2018 10:01:37 -0000 On 12.10.2018 12:52, Maxime Coquelin wrote: > > > On 10/12/2018 11:53 AM, Ilya Maximets wrote: >> On 12.10.2018 11:57, Maxime Coquelin wrote: >>> >>> >>> On 10/12/2018 10:45 AM, Maxime Coquelin wrote: >>>> >>>> >>>> On 10/12/2018 10:43 AM, Maxime Coquelin wrote: >>>>> >>>>> >>>>> On 10/11/2018 05:59 PM, Ilya Maximets wrote: >>>>>> 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. >>>>> >>>>> Maybe it is better to remove check for MSG_CTRUNC. >>>> s/remove/rework/ >>>> >>>>> IIUC, if MSG_CTRUNC happens, we may have to close anyway the ones >>>>> received. >>>>> >>>>> Do you agree? >>> >>> So it seems that other use of MSG_CTRUNC in DPDK and QEMU does care >>> to close the ones that would have been received and just return an >>> error. >> >> Did you mean 'does not care'? > > Yes, I meant "does not care", sorry. ok. > >> 'read_msg()' in lib/librte_eal/common/eal_common_proc.c just returns -1 >> and 'slave_read()' in hw/virtio/vhost-user.c does not close fds, because >> 'fdsize' is not set at the time of checking the flag. >> >>> >>> I propose to do the same for now, an remove the got_fds > max_fds part. Agree. >>> >>>>>> +                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 >>>>>>> >>> >>> > >