From nobody Fri Sep 10 19:38:21 2021 X-Original-To: hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 7F3C317ADEF0; Fri, 10 Sep 2021 19:38:24 +0000 (UTC) (envelope-from avg@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4H5mPr1crkz3Qjy; Fri, 10 Sep 2021 19:38:24 +0000 (UTC) (envelope-from avg@freebsd.org) Received: from [192.168.0.88] (unknown [195.64.148.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: avg/mail) by smtp.freebsd.org (Postfix) with ESMTPSA id 7D8084AB4; Fri, 10 Sep 2021 19:38:23 +0000 (UTC) (envelope-from avg@freebsd.org) From: Andriy Gapon Subject: Re: recvmsg() "short receive" after FIONREAD To: Mark Johnston Cc: "net@FreeBSD.org" , hackers@freebsd.org References: <500a2272-c1b3-3f97-0096-9fe8117c4b95@FreeBSD.org> <6f455869-cbdd-ee20-f2f8-f633e22071e9@FreeBSD.org> Message-ID: Date: Fri, 10 Sep 2021 22:38:21 +0300 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:78.0) Gecko/20100101 Firefox/78.0 Thunderbird/78.14.0 List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-ThisMailContainsUnwantedMimeParts: N On 10/09/2021 22:35, Mark Johnston wrote: > On Fri, Sep 10, 2021 at 10:15:37PM +0300, Andriy Gapon wrote: >> On 10/09/2021 21:51, Andriy Gapon wrote: >>> >>> >>> I observe a problem with the code that can be seen here: >>> https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/blob/master/src/modules/rtp/sap.c#L142 >>> >>> >>> The code uses ioctl(FIONREAD) to check the size of available data in a socket. >>> Does / should this work? >>> >>> Then the code calls recvmsg() on the socket with single vector with iov_len >>> equal to the size obtained earlier. >>> >>> But the return value from recvmsg() is smaller than the iov_len value. >>> In my test I see 215 vs expected 263 (so, the difference is 48). >>> >>> Does this ring a bell to anyone? >>> I see this on a month old 14.0-CURRENT arm64. >>> >> >> From a quick look at soreceive_dgram() and some dtrace-ing, it seems that each >> time recvmsg() is called soreceive_dgram() gets an mbuf chain where the first >> mbuf is MT_SONAME (8), the second one is MT_CONTROL (14) and only the third one >> is MT_DATA. >> >> Could it be that data in the first two mbuf-s (especially the MT_CONTROL one) is >> reported by FIONREAD? Or, in other words, accounted in sb_acc? >> But then it's not actually returned, of course, in recvmsg() ? > > Indeed, I suspect that this is the problem. Note that for > kevent(EVFILT_READ) we subtract the number of control message bytes from > the returned value, see filt_soread(). I wonder if FIONREAD should do > the same thing. Thank you for the suggestion. I think that it is a reasonable expectation that FIONREAD returns a number of bytes that can be actually read. I'll look at filt_soread(). Thank you! -- Andriy Gapon