From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id CEEA75A026D for ; Mon, 22 Jan 2024 17:22:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705940528; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gCjgU5cUmnQSby0Ldb5Z3fPfkJILeWuQyCkntvhbSuE=; b=hNLBdpLCEMWGQvNyD1Nr1u5SwkSyWRSsC2ymHkidKUKpy27PKfQKUUs3n+6WCZAoWiS8QG G29EtiDg2N8Hf4oFOGCkOZMa1YuAlLWBsQJbGUr8t7eWBSBWEsT2Avd/tj6sdz+7C439cx pQNqwm+r8ad3ULMb7lcIOH7PQHJ/IRw= Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-142-bHyzqGX4PLe_yKV6xyiKwg-1; Mon, 22 Jan 2024 11:22:07 -0500 X-MC-Unique: bHyzqGX4PLe_yKV6xyiKwg-1 Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3bd3ad69ab0so4942862b6e.2 for ; Mon, 22 Jan 2024 08:22:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705940526; x=1706545326; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gCjgU5cUmnQSby0Ldb5Z3fPfkJILeWuQyCkntvhbSuE=; b=Undtd6AOr5PItIYgZkKgIxaNkvO7aBKA947+l8CLLzVKWsPijTBfVNo0kVvDwM5R3T ADpGOlvb66uhqSeaATNAZFSSLB+x/T7Xq2LiCglbF0toeW+zHBdIUxSpgNTslufFvzLf 7Qwf6iGg8twroWRAK/+RKGTN+OfDm6CEpSKC2N8uf73aFuAqox+JvmzHt5ZIaWwXmVXk g/Qiwr7y6MOfYpwRmSvgeuUGBJf0un3goBKGkPlN5inZ4ihzkhHoNJ+YyC0C7wGo86ud bYK8GjngDSGAzc4txfMyRKHWgTT+pU2CVp8IlAHKr8CIQP3Gh2Qyz5CobimrdUUnp+cA O26w== X-Gm-Message-State: AOJu0YyJExrUGiAY0i6qE3X3yOgg2ZnOolrCxEvdg1QbrZpoB3iKMSow jJ99orvezeGr4TJb7wKloOAMxeWSig4dIcn/ft5uHe3AfZwdvXkxEC2/S0X+f/oz9/9Xv10kZwD 3TF7vzbfRCWfaT2PZCQDNqtWCD4g5twhBNJgpUWjqBrEiyqFCdg== X-Received: by 2002:a05:6870:d0d:b0:210:a3a9:af01 with SMTP id mk13-20020a0568700d0d00b00210a3a9af01mr127846oab.88.1705940526561; Mon, 22 Jan 2024 08:22:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IFV2QRCVvlrOlYJ97HPbRDvqgoszYvLmrgFp7dnp5V0fH+7X4IUvNDYIjk8blWmVmzTF2VSFQ== X-Received: by 2002:a05:6870:d0d:b0:210:a3a9:af01 with SMTP id mk13-20020a0568700d0d00b00210a3a9af01mr127839oab.88.1705940526298; Mon, 22 Jan 2024 08:22:06 -0800 (PST) Received: from [10.0.0.97] ([24.225.234.80]) by smtp.gmail.com with ESMTPSA id gu27-20020a056870ab1b00b00206516474f3sm2191302oab.38.2024.01.22.08.22.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Jan 2024 08:22:04 -0800 (PST) Message-ID: Date: Mon, 22 Jan 2024 11:22:03 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [RFC net-next] tcp: add support for read with offset when using MSG_PEEK To: Stefano Brivio , Paolo Abeni References: <20240111230057.305672-1-jmaloy@redhat.com> <595d89f1-15b1-537d-f876-0ac4627db535@redhat.com> <20240121231615.13029448@elisabeth> From: Jon Maloy In-Reply-To: <20240121231615.13029448@elisabeth> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: SFU4HX7QHWOCWRJVRAYNNRGJIYA3A76I X-Message-ID-Hash: SFU4HX7QHWOCWRJVRAYNNRGJIYA3A76I X-MailFrom: jmaloy@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org, passt-dev@passt.top, lvivier@redhat.com, dgibson@redhat.com X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 2024-01-21 17:16, Stefano Brivio wrote: > On Thu, 18 Jan 2024 17:22:52 -0500 > Jon Maloy wrote: > >> On 2024-01-16 05:49, Paolo Abeni wrote: >>> On Thu, 2024-01-11 at 18:00 -0500, jmaloy@redhat.com wrote: >>>> From: Jon Maloy >>>> >>>> When reading received messages from a socket with MSG_PEEK, we may want >>>> to read the contents with an offset, like we can do with pread/preadv() >>>> when reading files. Currently, it is not possible to do that. >> [...] >>>> + err = -EINVAL; >>>> + goto out; >>>> + } >>>> + peek_offset = msg->msg_iter.__iov[0].iov_len; >>>> + msg->msg_iter.__iov = &msg->msg_iter.__iov[1]; >>>> + msg->msg_iter.nr_segs -= 1; >>>> + msg->msg_iter.count -= peek_offset; >>>> + len -= peek_offset; >>>> + *seq += peek_offset; >>>> + } >>> IMHO this does not look like the correct interface to expose such >>> functionality. Doing the same with a different protocol should cause a >>> SIGSEG or the like, right? >> I would expect doing the same thing with a different protocol to cause >> an EFAULT, as it should. But I haven't tried it. > So, out of curiosity, I actually tried: the current behaviour is > recvmsg() failing with EFAULT, only as data is received (!), for TCP > and UDP with AF_INET, and for AF_UNIX (both datagram and stream). > > EFAULT, however, is not in the list of "shall fail", nor "may fail" > conditions described by POSIX.1-2008, so there isn't really anything > that mandates it API-wise. > > Likewise, POSIX doesn't require any signal to be delivered (and no > signals are delivered on Linux in any case: note that iov_base is not > dereferenced). > > For TCP sockets only, passing a NULL buffer is already supported by > recv() with MSG_TRUNC (same here, Linux extension). This change would > finally make recvmsg() consistent with that TCP-specific bit. > >> This is a change to TCP only, at least until somebody decides to >> implement it elsewhere (why not?) > Side note, I can't really think of a reasonable use case for UDP -- it > doesn't quite fit with the notion of message boundaries. > > Even letting alone the fact that passt(1) and pasta(1) don't need this > for UDP (no acknowledgement means no need to keep unacknowledged data > anywhere), if another application wants to do something conceptually > similar, we should probably target recvmmsg(). > >>> What about using/implementing SO_PEEK_OFF support instead? >> I looked at SO_PEEK_OFF, and it honestly looks both awkward and limited. > I think it's rather intended to skip headers with fixed size or > suchlike. > >> We would have to make frequent calls to setsockopt(), something that >> would beat much of the purpose of this feature. > ...right, we would need to reset the SO_PEEK_OFF value at every > recvmsg(), which is probably even worse than the current overhead. > >> I stand by my opinion here. >> This feature is simple, non-intrusive, totally backwards compatible and >> implies no changes to the API or BPI. > My thoughts as well, plus the advantage for our user-mode networking > case is quite remarkable given how simple the change is. After pondering more upon this, and also some team internal discussions, I have decided to give it a try with SO_PEEK_OFF, just to see to see the outcome, both at kernel level and in user space. So please wait with any possible application of this , if that ever happens with RFCs. ///jon > >> I would love to hear other opinions on this, though. >> >> Regards >> /jon >> >>> Cheers, >>> >>> Paolo