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 E68745A026D for ; Mon, 4 Sep 2023 19:14:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693847663; 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=LVyh7eNBOhmDN4MhEQoM3C4nR3S1hKGkmlHr8BSBnq8=; b=eO9O3gqamWo1otcCtgF+6Q9qZY5wHgodua/iRoPen8zY9KdVDdFxRpbFPobhMF5neGBPqh tAiROzkp15ROyWAiqSJfSPhazMwzalege3vw4puwv7bUwaNjKbeNWdEG7KihB7zDZ6IeDV +j2Wp+R+l/oVk7MksV1ZAyE39V5PSQg= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-164-6JGHUnubPN--_bHDfzU5Cg-1; Mon, 04 Sep 2023 13:14:20 -0400 X-MC-Unique: 6JGHUnubPN--_bHDfzU5Cg-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-64bca259c4bso18074726d6.1 for ; Mon, 04 Sep 2023 10:14:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693847659; x=1694452459; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LVyh7eNBOhmDN4MhEQoM3C4nR3S1hKGkmlHr8BSBnq8=; b=aaWpJwiBmVEVnrsoDMHvsN8oaQVH8YED0uy/tijjoHHKwwR3SKcZvlWUGhl6zNF1FE fK4NdD5BobU+R0kXfuB5us4JaeagOv8BOw9B6kM6MbEbEY4ZkQIYa0Yre8MVDbavc3Yc hi5Dws1RD1wc6v+lgTLIoBMyRwzuI64Blasj1POzmi/RPKvJut+mQig/nbekkFM6Pn5v 0qidI//B5t0QcyHniZ25QRWcXUL1gVilqDWCdIU0YLwx6ZdC4IHHjhzr251m4NsUSSkB sQGCjv9de8Bpx/oLNqViCWXcQxEPQduNF/eF05KO1+rvwd6U4LnmLF1xGQfATN3GlhrF BwkA== X-Gm-Message-State: AOJu0YwaclDy7G5QyElVCPVdq2klF3QAWTsxGBv9W9OxF1bfEdq4FLTR yT94Kcxh2SwuCVC7v2I29tn/FfFq4NeBRMsO/St7nZGCgCw5AT+H8JWYH08UD5zfwn5/x8GMxmY iRv/sRbo6LmfN X-Received: by 2002:a0c:e483:0:b0:649:384f:ed9 with SMTP id n3-20020a0ce483000000b00649384f0ed9mr10433753qvl.32.1693847659661; Mon, 04 Sep 2023 10:14:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFm3+mZGFszZLOIlR3ZgTX5YBdImRz5fzb5zncsbk2VF1ZqAUGeIHjlsvhrluBloYvGfe6akw== X-Received: by 2002:a0c:e483:0:b0:649:384f:ed9 with SMTP id n3-20020a0ce483000000b00649384f0ed9mr10433739qvl.32.1693847659336; Mon, 04 Sep 2023 10:14:19 -0700 (PDT) Received: from [10.0.0.97] ([24.225.234.80]) by smtp.gmail.com with ESMTPSA id n3-20020a0ce543000000b00626362f1bf1sm3721401qvm.63.2023.09.04.10.14.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Sep 2023 10:14:18 -0700 (PDT) Message-ID: Date: Mon, 4 Sep 2023 13:14:17 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [RFC v2] tcp: add support for read with offset when using MSG_PEEK To: Stefano Brivio References: <20230623021227.2625490-1-jmaloy@redhat.com> <20230623130106.68d0e058@elisabeth> From: Jon Maloy In-Reply-To: <20230623130106.68d0e058@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: OBUGCCSY4HURKSC7SJU4RMRQ2AB3DEH2 X-Message-ID-Hash: OBUGCCSY4HURKSC7SJU4RMRQ2AB3DEH2 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: lvivier@redhat.com, dgibson@redhat.com, passt-dev@passt.top 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 2023-06-23 07:02, Stefano Brivio wrote: > On Thu, 22 Jun 2023 22:12:27 -0400 > Jon Maloy wrote: > >> When reading received messages with MSG_PEEK, we sometines have to read >> the leading bytes of the stream several times, only to reach the bytes >> we really want. This is clearly non-optimal. >> >> What we would want is something similar to pread/preadv(), but working >> even for tcp sockets. At the same time, we obviously don't want to add >> any new arguments to the recv/recvmsg() calls. >> >> In this commit, we allow the user to set iovec.iov_base in the first >> vector entry to NULL. This tells the socket to skip the first entry, >> hence making the iov_len field of that entry indicate the offset value. >> This way, there is no need to add any new arguments. > Ah-ha! I'm glad you found an acceptable way to pass a NULL pointer > there. :) > >> This change is simple and non-intrusive, and should be safe addition to >> the socket API. We have measured it to give a throughput improvement of > ...it would be nice to also do a bit of profiling with perf(1) -- > that's where I originally noticed we were wasting cycles on filling up > tcp_buf_discard. Plus, sure, there's also some value in dropping a > useless 16 MiB buffer. > > If you need examples/inspiration: the pasta (automated) demo shows > that, skip at 9:20 in: https://passt.top/passt/about/#pasta_2 (the one > on the left) > > and that's simply done like this: > https://passt.top/passt/tree/test/demo/pasta#n163 This looks like a script language, but I don't recognize it. How do I run it? > >> 8-10 % for the protocol splicer 'passst', which is used in KubeVirt Now at 20+ % > passt > >> containers. > Those are virtual machines in containers -- but other than KubeVirt, > passt is generally supported in libvirt (>= 9.2) with QEMU (>= 7.2) > >> Signed-off-by: Jon Maloy >> >> works with original msghdr >> >> Signed-off-by: Jon Maloy >> --- >> net/ipv4/tcp.c | 10 +++++++++- >> 1 file changed, 9 insertions(+), 1 deletion(-) >> >> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c >> index 33f559f491c8..1d89337e89b6 100644 >> --- a/net/ipv4/tcp.c >> +++ b/net/ipv4/tcp.c >> @@ -2428,6 +2428,7 @@ static int tcp_recvmsg_locked(struct sock *sk, struct msghdr *msg, size_t len, >> struct tcp_sock *tp = tcp_sk(sk); >> int copied = 0; >> u32 peek_seq; >> + u32 peek_offset; > Kernel networking code observes the reverse-Christmas tree notation (at > least for new additions), this would need to go after *tp: > > struct tcp_sock *tp = tcp_sk(sk); > u32 peek_offset; > >> u32 *seq; >> unsigned long used; >> int err; >> @@ -2435,7 +2436,6 @@ static int tcp_recvmsg_locked(struct sock *sk, struct msghdr *msg, size_t len, >> long timeo; >> struct sk_buff *skb, *last; >> u32 urg_hole = 0; >> - > Probably not intended. > >> err = -ENOTCONN; >> if (sk->sk_state == TCP_LISTEN) >> goto out; >> @@ -2469,6 +2469,14 @@ static int tcp_recvmsg_locked(struct sock *sk, struct msghdr *msg, size_t len, >> if (flags & MSG_PEEK) { >> peek_seq = tp->copied_seq; >> seq = &peek_seq; >> + if (msg->msg_iter.iov[0].iov_base == NULL) { >> + peek_offset = msg->msg_iter.iov[0].iov_len; >> + msg->msg_iter.iov = &msg->msg_iter.iov[1]; >> + msg->msg_iter.nr_segs -= 1; > Do you also need to make sure that nr_segs > 1 if iov[0].iov_base is > NULL? I'm not sure if we need to check explicitly that msg_iter.iov[1] > is valid here (but I haven't followed the whole path from the syscall > handler). Checked. This is taken care of by the generic code. ///jon > >> + msg->msg_iter.count -= peek_offset; >> + len -= peek_offset; >> + *seq += peek_offset; >> + } >> } >> >> target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);