Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1905732rwd; Fri, 2 Jun 2023 01:43:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ52HVu5CGCi5TRBv86Geg3KWQnvkOaNB1KGk8fnLr15mhGpTBkIvOWk9Z9V8AeW/x3fsSwf X-Received: by 2002:a05:6a20:8f11:b0:10f:8528:38b3 with SMTP id b17-20020a056a208f1100b0010f852838b3mr4277234pzk.20.1685695432376; Fri, 02 Jun 2023 01:43:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685695432; cv=none; d=google.com; s=arc-20160816; b=b5etNGdTi0EsGj5C/xVXUr7Rd9GBxTAzlEtfGXSKv6XVbnS0TYpH9TrYhVquU+9NZl OO+GMzd5oVZDxmgkQU67gyhozLQ4fmn2ZDgtKaKm/ziRbt/CW0NuDL7UmayK56ywONsv ZSkx24oYFkU8YClet8kNUOo5RDK6p+mOs9F6NgTbY7zMvanC+W1tt33d6iLzz5ikYHzq ea5SDpTVyL2deteOaGiRqKqV72lsxy2GzRs5asvJ4zEjSBzT9o/4b42fa56UiZCuWEj9 IJJuTAH3H8bAA0GRT8QbxsMTh0AaMZQCGH9kR3PFb5a+ZaCGE/4xYEYTTg1ZdE1GbydL zkWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:content-transfer-encoding :content-id:mime-version:subject:cc:to:references:in-reply-to:from :organization:dkim-signature; bh=oD+X2kcKX6bzS0/GnmGAAZI7Di/1DIZrV3VWBtc6qTI=; b=gOTVaSpwMG31xvEsdcI8dcT5K/75WKvFcYrqZLTJaX/viAKPBhFESNWVBXXsNNZT4n E9gNfjl4AiuWF+R8+QP/MlPvrTABYKbDJZbppfVhC2PrmFh3u1GMsB+lbSX7RFaBAnMi i+08ycdYjIMo14wgAmTdx9RMgJe18xPXrK98+uqfcyZ5t0kDMAfUSSkUfi4SLkcEACdj 9u3I69FZckNOcWVJmWlFsRLUMLStsECTdhSmVXxACnePq66h6FcMJ9kdUQbGw83k3ovD Ewfd2vaU5SpeKIOnxjkeOl8YX7vGFvZWewfkwZ0XMKOQUVtbq2gEb694y7u3Y87Ek1+w Z2Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DETbqjQy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j4-20020a636e04000000b00541bf36f2d0si635058pgc.379.2023.06.02.01.43.40; Fri, 02 Jun 2023 01:43:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DETbqjQy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234152AbjFBIYj (ORCPT + 99 others); Fri, 2 Jun 2023 04:24:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233856AbjFBIYh (ORCPT ); Fri, 2 Jun 2023 04:24:37 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7722AEB for ; Fri, 2 Jun 2023 01:23:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685694230; 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=oD+X2kcKX6bzS0/GnmGAAZI7Di/1DIZrV3VWBtc6qTI=; b=DETbqjQyCqJ9NClCal0S7Fn3mr5+n4khSSET4W8ZJQb7XXuE8jSghFGiq2o/CZyrGRx+AX J2yZD8olxBSGCRcFR6nkHVAG2pyEbaRz6HZQjQbIs5oWFQB18Gg1qeozwuu09dNDsA+bVi pVyujfZcmOyjAWiEJhzUok+8/nJGUTc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-232-2PmVrOJmMwqg0KXeqP6pYw-1; Fri, 02 Jun 2023 04:23:45 -0400 X-MC-Unique: 2PmVrOJmMwqg0KXeqP6pYw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3C388185A78F; Fri, 2 Jun 2023 08:23:44 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02FB520296C6; Fri, 2 Jun 2023 08:23:40 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <20230601212043.720f85c2@kernel.org> References: <20230601212043.720f85c2@kernel.org> <20230524153311.3625329-1-dhowells@redhat.com> <20230524153311.3625329-10-dhowells@redhat.com> <20230526180844.73745d78@kernel.org> <499791.1685485603@warthog.procyon.org.uk> <832277.1685630048@warthog.procyon.org.uk> <909595.1685639680@warthog.procyon.org.uk> To: Jakub Kicinski Cc: dhowells@redhat.com, Linus Torvalds , netdev@vger.kernel.org, "David S. Miller" , Eric Dumazet , Paolo Abeni , Willem de Bruijn , David Ahern , Matthew Wilcox , Jens Axboe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chuck Lever , Boris Pismenny , John Fastabend , Christoph Hellwig Subject: Re: Bug in short splice to socket? MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <952876.1685694220.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Fri, 02 Jun 2023 09:23:40 +0100 Message-ID: <952877.1685694220@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jakub Kicinski wrote: > On Thu, 01 Jun 2023 18:14:40 +0100 David Howells wrote: > > The answer then might be to make TLS handle a zero-length send() > = > IDK. Eric added MSG_SENDPAGE_NOTLAST 11 years ago, to work around = > this exact problem. Your refactoring happens to break it and what > you're saying sounds to me more or less like "MSG_SENDPAGE_NOTLAST = > is unnecessary, it's user's fault". > = > A bit unconvincing. Maybe Eric would chime in, I'm not too familiar > with the deadly mess of the unchecked sendmsg()/sendpage() flags. Not so much the "user's fault" as we couldn't fulfill what the user asked = - so should we leave it to the user to work out how to clean it up rather than automatically allowing the socket to flush (if cancellation might be an op= tion instead)? The problem I have with NOTLAST is that it won't be asserted if the short = read only occupies a single pipe_buf. We don't know that we won't get some mor= e data on the next pass. An alternative way to maintain the current behaviour might be to have splice_direct_to_actor() call the actor with sd->total_len =3D=3D 0 if do_splice_to() returned 0 and SPLICE_F_MORE wasn't set by the caller (ie. !more). Attached is a change to do that. It becomes simpler if/once= my splice_to_socket() patches are applied - but I don't really want to push t= hat until all the protocols that support sendpage() support sendmsg() + MSG_SPLICE_PAGES as well[*]. [*] Though if you're okay having a small window where TLS copies data rath= er than splicing, I could push the splice_to_socket() patches *first*. T= CP and AF_UNIX splice already support MSG_SPLICE_PAGES so that would bump their efficiency. David --- diff --git a/fs/splice.c b/fs/splice.c index 3e06611d19ae..84e9ca06db47 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -643,6 +643,22 @@ static void splice_from_pipe_end(struct pipe_inode_in= fo *pipe, struct splice_des wakeup_pipe_writers(pipe); } = +/* + * Pass a zero-length record to the splice-write actor with SPLICE_F_MORE + * turned off to allow the network to see MSG_MORE deasserted. + */ +static ssize_t splice_from_pipe_zero(struct pipe_inode_info *pipe, + struct splice_desc *sd, + splice_actor *actor) +{ + struct pipe_buffer buf =3D { + .page =3D ZERO_PAGE(0), + .ops =3D &nosteal_pipe_buf_ops, + }; + + return actor(pipe, &buf, sd); +} + /** * __splice_from_pipe - splice data from a pipe to given actor * @pipe: pipe to splice from @@ -662,6 +678,9 @@ ssize_t __splice_from_pipe(struct pipe_inode_info *pip= e, struct splice_desc *sd, int ret; = splice_from_pipe_begin(sd); + if (!sd->total_len) + return splice_from_pipe_zero(pipe, sd, actor); + do { cond_resched(); ret =3D splice_from_pipe_next(pipe, sd); @@ -956,13 +975,17 @@ ssize_t splice_direct_to_actor(struct file *in, stru= ct splice_desc *sd, */ bytes =3D 0; len =3D sd->total_len; + + /* Don't block on output, we have to drain the direct pipe. */ flags =3D sd->flags; + sd->flags &=3D ~SPLICE_F_NONBLOCK; = /* - * Don't block on output, we have to drain the direct pipe. + * We signal MORE until we've read sufficient data to fulfill the + * request and we keep signalling it if the caller set it. */ - sd->flags &=3D ~SPLICE_F_NONBLOCK; more =3D sd->flags & SPLICE_F_MORE; + sd->flags |=3D SPLICE_F_MORE; = WARN_ON_ONCE(!pipe_empty(pipe->head, pipe->tail)); = @@ -971,21 +994,19 @@ ssize_t splice_direct_to_actor(struct file *in, stru= ct splice_desc *sd, loff_t pos =3D sd->pos, prev_pos =3D pos; = ret =3D do_splice_to(in, &pos, pipe, len, flags); - if (unlikely(ret <=3D 0)) + if (unlikely(ret < 0)) goto out_release; = read_len =3D ret; sd->total_len =3D read_len; = /* - * If more data is pending, set SPLICE_F_MORE - * If this is the last data and SPLICE_F_MORE was not set - * initially, clears it. + * If we now have sufficient data to fulfill the request then + * we clear SPLICE_F_MORE if it was not set initially. */ - if (read_len < len) - sd->flags |=3D SPLICE_F_MORE; - else if (!more) + if ((read_len =3D=3D 0 || read_len >=3D len) && !more) sd->flags &=3D ~SPLICE_F_MORE; + /* * NOTE: nonblocking mode only applies to the input. We * must not do the output in nonblocking mode as then we @@ -1005,6 +1026,8 @@ ssize_t splice_direct_to_actor(struct file *in, stru= ct splice_desc *sd, sd->pos =3D prev_pos + ret; goto out_release; } + if (read_len < 0) + goto out_release; } = done: diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index f63e4405cf34..5d48391da16c 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -995,6 +995,9 @@ static int tls_sw_sendmsg_locked(struct sock *sk, stru= ct msghdr *msg, } } = + if (!msg_data_left(msg) && eor) + goto copied; + while (msg_data_left(msg)) { if (sk->sk_err) { ret =3D -sk->sk_err;