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.129.124]) by passt.top (Postfix) with ESMTP id 5032C5A026F for ; Sun, 21 Jan 2024 23:16:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705875418; 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=OP4r9Ek2wXjl//V6jfDaPiJ6sJbyRWNqxCJqUjnFuqA=; b=SC6CHsCigl8f44Y7ueYNlU5iyLzn9I7jUiRb2e8sMrhIlTcqMI6xRfianvNbKwU18WPNKl Tm72q3Lo6c3pY2/p7MleSKxCZc4xyqysTSZJHtHIfLKu5aoHf6SUOXLPBEDdz9GY7nl8uw UjPfqNYJ1k5kH5+DhefTrpSDrx8/7Yg= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-279-G0iQiMKENoOGNes1qiXQ_w-1; Sun, 21 Jan 2024 17:16:56 -0500 X-MC-Unique: G0iQiMKENoOGNes1qiXQ_w-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a28f6a78b83so144088966b.1 for ; Sun, 21 Jan 2024 14:16:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705875415; x=1706480215; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=OP4r9Ek2wXjl//V6jfDaPiJ6sJbyRWNqxCJqUjnFuqA=; b=k6w4vLd/r/vxXCoxgBaIIAEhYO6qmqJVNqJ+eOz8KQEeRk7AerCdw0lNXI+fdw/QN2 6bdvTJbHBp3WV7X7xjtm2CLfWTQgQBGLQp+vsOauCXgEfk3zItb/PQYY8d3C6djcKg5U TAugXaU03BnEamF+5/SNyD048rGwR5djcXcjk7aeok1/oCdtvSVps4BQwYg9e2KZT+Nl dgLUUU9HL/wmAvMyvJL+7ApOatXouFp2hxOYS1ux0ialMbS9yXdZNFbH1jxR3/eDod2Y xKWYW7SPVznId2GnkshoJRcM2maGMiWB/BFqQItDOzdm2p12t9YVtrD+VYBSknMLUtf5 j99g== X-Gm-Message-State: AOJu0YyTog8OLYf26wbktXziiBsS1w7OlEOJk5aVe27PgjnUe6Oa0Uzs r3dZ+fXU6SJfz0iaM9ALaZgLJvbdcv2Yu99BRk2TqMD21Ln0zKwa2YLVUPph9wSf2FniOBdtzs2 vmAsWBtGnPle3SZv0SjmZ/0MDmfmJP8uv+5vcSzFyi3SBR/9J6A== X-Received: by 2002:a17:906:a213:b0:a2f:2000:5d4a with SMTP id r19-20020a170906a21300b00a2f20005d4amr1695716ejy.69.1705875415073; Sun, 21 Jan 2024 14:16:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IH5PkOhyR/6C0Q8XkgYGRUn88ocVdJWEVes6l9rN/LAqdV/dfmwMiw1hYOCJ5ElP6s8nbIKFw== X-Received: by 2002:a17:906:a213:b0:a2f:2000:5d4a with SMTP id r19-20020a170906a21300b00a2f20005d4amr1695705ejy.69.1705875414735; Sun, 21 Jan 2024 14:16:54 -0800 (PST) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id h25-20020a170906399900b00a29db9e8c84sm12730421eje.220.2024.01.21.14.16.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Jan 2024 14:16:54 -0800 (PST) Date: Sun, 21 Jan 2024 23:16:15 +0100 From: Stefano Brivio To: Jon Maloy , Paolo Abeni Subject: Re: [RFC net-next] tcp: add support for read with offset when using MSG_PEEK Message-ID: <20240121231615.13029448@elisabeth> In-Reply-To: <595d89f1-15b1-537d-f876-0ac4627db535@redhat.com> References: <20240111230057.305672-1-jmaloy@redhat.com> <595d89f1-15b1-537d-f876-0ac4627db535@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.1.1 (GTK 3.24.36; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: S3DST6DL6AWD7O7BSVX535T4VEJJU47L X-Message-ID-Hash: S3DST6DL6AWD7O7BSVX535T4VEJJU47L X-MailFrom: sbrivio@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 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. > I would love to hear other opinions on this, though. > > Regards > /jon > > > > > Cheers, > > > > Paolo -- Stefano