From nobody Fri Sep 10 19:35:58 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 835B417AADCE; Fri, 10 Sep 2021 19:36:04 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4H5mM830JMz3NSc; Fri, 10 Sep 2021 19:36:04 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: by mail-qt1-x832.google.com with SMTP id l24so2489804qtj.4; Fri, 10 Sep 2021 12:36:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=yYrU/LO1iaox+aPVZZK2z6w0Yn8htO0Z5//kZSC4Fys=; b=jPArV8/S4y5hhaSuEqLZJmjPAO4IK3ZkOqEZ1L38d1v5fgtj8b4mJUcLa5UwOBe02D v8LwvPVA0fxKEXIYIPTTrKEve5shb/KzDRjUCqpVSAXMAeDMRjOWLnmgyx1+48S3Q7Xj t+ZKfk/uS3B1qLepy5OTdB9ySxi8fBP35OpCDzKgvzZdaKZxz3mSJujwZHuD6Q6fzhAI 9LlRm0N+g1mi64eRrPHJA6dWeDxLf8qIQelvNKABAcmpj2cQrvPMi/L6rWuQYQPdJsFB le+QDrT/nEkiMziPEuXtILZGaWUnFrDENOmEjnvdUhM1TrM21nxUNPXj2VWnBnrhNXxr 5/5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=yYrU/LO1iaox+aPVZZK2z6w0Yn8htO0Z5//kZSC4Fys=; b=XRUR7UwdKEbr/QxSSVLXg1D1fGR9mzR//go8B0ZT8m7M8GMQw2uD2oeZredNy8SiT+ M7p0SEWnBurk34mbdYseMK3vd/IqEs9h9NYroGZcVpggezMrlVYkAk0W/kjazo9Ky13p 6usQU6tlZUv071sIs+Rr0USufU92UR1nF5J0SGQWOSy7N4rIlVklF77yXaM9fRCVBnwM Y/frKkC8T7OrqU5BAejfoTlA9d/s9p6tG6Hjq7EKuVsktfeQdjaWuxm/CqQMk9YIiuiS WzDpv4KzH+8B6uV43oYkfJaV0WauoFEwIi+jKEae+1Lh8/fn393h2QgA/pdphZB0XRpV Tkxw== X-Gm-Message-State: AOAM530tYJ13GOItXlGyKiMyzkXNG+9pTFadDnRPkN8YQmqMobYBiYRk Jhom1Lu6+gpS7r46RDD60Cr78jhEF/PG8g== X-Google-Smtp-Source: ABdhPJxUwZ+NUIRXydySr9nKFfEOn2hQFwxAWnYmZSxfg71pEKVQxwhIc/G+4UaKh57/L2YNtMNJIQ== X-Received: by 2002:a05:622a:118f:: with SMTP id m15mr9846629qtk.107.1631302557999; Fri, 10 Sep 2021 12:35:57 -0700 (PDT) Received: from nuc ([142.126.175.196]) by smtp.gmail.com with ESMTPSA id d14sm1010898qto.36.2021.09.10.12.35.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 12:35:57 -0700 (PDT) Date: Fri, 10 Sep 2021 15:35:58 -0400 From: Mark Johnston To: Andriy Gapon Cc: "net@FreeBSD.org" , hackers@freebsd.org Subject: Re: recvmsg() "short receive" after FIONREAD Message-ID: References: <500a2272-c1b3-3f97-0096-9fe8117c4b95@FreeBSD.org> <6f455869-cbdd-ee20-f2f8-f633e22071e9@FreeBSD.org> 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 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6f455869-cbdd-ee20-f2f8-f633e22071e9@FreeBSD.org> X-Rspamd-Queue-Id: 4H5mM830JMz3NSc X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-ThisMailContainsUnwantedMimeParts: N 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.