From nobody Sat Sep 11 14:13:37 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 393A017CD988; Sat, 11 Sep 2021 14:13:38 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) (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 4H6F8f0bFZz3FN2; Sat, 11 Sep 2021 14:13:38 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: by mail-qt1-x82a.google.com with SMTP id s32so4203094qtc.12; Sat, 11 Sep 2021 07:13:38 -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:content-transfer-encoding:in-reply-to; bh=Nl1Q3GpWIJBeymU+A6/6qPzFh1Fctu86VBLkGOoQhco=; b=asVtX2SzGprbis1RJw/HjcJlpaTWprCBwdGkrUx/wpFrjVRCnHY0aqD0PK0F6U+ZOx Blt/EzvDayFu4HmHuwHn4BuaiZELSaYy+cdyZ9aJ29RvdANmEJ51/+FBpEjzBrTjxKLQ mSSws8BNn4K+c7F78VaDlQb62pXXpZ4WfeEMBdK4HJgAt0NcWAIS1oMdNVNhLcCE02zL +2euyAU3kOsM0gTjPEFqbI33wBogcFB2lJFlmpF7mptmxtbugENLka8lindTveZPKKPf bfk7+A2vtfOM9GO3fbroZsvHkLddYLytKOo/Uuhag/uHtzZlLkdyoNrlmYv5IigLMavw vznw== 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 :content-transfer-encoding:in-reply-to; bh=Nl1Q3GpWIJBeymU+A6/6qPzFh1Fctu86VBLkGOoQhco=; b=2tBzFnvCuVowkk84WJyUlKaBSb7XhKyDS5LrdvpgeRVyrzAGjKb7Oa4L6DxcGau6iU 228aB+Z/peGyFDAQ+0A5dTyR6Wb2ZfALAg6Jc0dZCcliel/y0H6YrDFBe5ATcoHN8ox9 s0/DEbtmgAY35ZjPlZpxTvIKkrzKgW6Cb1w+blfSe9PUgurKLwnOXMD7Ex1soGA3NgO/ QrEIaEtCzCR/Vp6iF91wlnB3ESSna4Np9G6HmZt4P5yWRDJwaq6xKflYVq//MLI2g/53 ExpGWfCt2QXca3ttIMDWcUuvQ5fjzKCPxGejPuLDjlbn/fICDravrhSic1sy1jKEI9Ss XO9Q== X-Gm-Message-State: AOAM533X2aALZkk7AfM1CpT0jHzkzxjuOQKPYid3oLCFU7266LhEKpun vLCa2ruv9+Mv/eyWHT/uN2yAtoGUNRnL1g== X-Google-Smtp-Source: ABdhPJytBohmWdr/eNe4KJV1E0xE7aldHbBnJofOw5e1NHWNFT3wihGv4Ulht0b2QYZ+Wqg8ctkhwA== X-Received: by 2002:aed:3004:: with SMTP id 4mr2348689qte.407.1631369617377; Sat, 11 Sep 2021 07:13:37 -0700 (PDT) Received: from nuc ([142.126.175.196]) by smtp.gmail.com with ESMTPSA id t26sm1235668qkm.0.2021.09.11.07.13.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Sep 2021 07:13:37 -0700 (PDT) Date: Sat, 11 Sep 2021 10:13:37 -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> <4a2165c5-b97b-8fb7-9ada-0acae3197824@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=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Queue-Id: 4H6F8f0bFZz3FN2 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 Sat, Sep 11, 2021 at 11:15:12AM +0300, Andriy Gapon wrote: > On 10/09/2021 22:40, Andriy Gapon wrote: > > On 10/09/2021 22:38, Andriy Gapon wrote: > >> On 10/09/2021 22:35, Mark Johnston wrote: > >>> 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(). > > > > kn_data = sbavail(&so->so_rcv) - so->so_rcv.sb_ctl; > > Is this it? > > Looks simple enough for a quick test :) > > > Works perfectly. > Should I just commit it or is a larger discussion needed? I think the semantic change is ok. Did you change FIONREAD to lock the sockbuf? I think it would be necessary to avoid races with pulseaudio: sb_acc is modified before sb_ctl, so there could be windows where sbavail(sb) - sb->sb_ctl gives a larger. And, it is not really safe to lock the sockbuf itself, since it may be overwritten by a listen(2) call. SOCK_RECVBUF_LOCK(so) should be used instead.