Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1134931rwd; Thu, 1 Jun 2023 10:55:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4dEN8ldNgJb5WruEPw6S3FoXf2Aw2fsKnxb355F40MLTzuID+l9DyPcjm2fCSmxcKmCfix X-Received: by 2002:a05:6a20:3c91:b0:ee:f290:5b5e with SMTP id b17-20020a056a203c9100b000eef2905b5emr8019653pzj.43.1685642145160; Thu, 01 Jun 2023 10:55:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685642145; cv=none; d=google.com; s=arc-20160816; b=dVzLt9ELFhgFU8mB5qhd+CBcw95vI7MI6mWhz+QlQkUp29CyGVl59rD0D2NtyORext pZXcOvzMXymOvZFfONifDrkX3Zz9j/ARDnIB7kaQmOFuA2H//zwFgGJmLxdVWMCMlWtS SyoFwaLy+0ylAAV4RrwayqD2IJe7azWHLQumz3WgtUq6NqSBUMDqIEI0+RKPn8hFxWg0 gDV9lpVsAmwauLpzfexFxc1kQOalEDZWurvtRGd/CAnhjJ6dQpFlQeyHxfGlx5yNo26l xhfp5QtcN8ZMUr9OxJc1sCCB9tWOlPU2IG7NoNLL4kZdUv+NuhgyOqKI9oR4wfRwPpY8 Zu2A== 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=M7UAbNml4oAWGP++9AqxwAaw9U/MQwWhNaY462tBqx4=; b=MZ6bFs0AMiUV4+79kiUzoPThB8FGxyrUlrh4Isp5kbbGJXuJeftDFDIHRk+7aePiYL aSQQ8/xYAA8M2IgzRM8EsPFgbMxaohU7hZvfsECHWgeED4mwiQ7mvLMb1LsZ+65ReegE hoC5H96EkXmDD/XP7Upy2HhQAwN9xxk8NCoNzLMhOsdsbQ+xeeR1FkCbTWrQtHqKq28D bjaJPGlQap+XAezBX6opbnyo7Hc8eOJp9N2zkJ3yxF3cUGxGfZqfdoT/rE5CjIUxqEDK Qom0B+Pqi3vLu/yXlziGAQESlE/4iZHVt4mLb0hsAz2yzfB2VVTw2gh5XrhNtJJFYogD I8/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=igR2KjXg; 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 m9-20020a654389000000b00519ffeb6d43si1103861pgp.188.2023.06.01.10.55.31; Thu, 01 Jun 2023 10:55:45 -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=igR2KjXg; 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 S232692AbjFARPi (ORCPT + 99 others); Thu, 1 Jun 2023 13:15:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232659AbjFARP2 (ORCPT ); Thu, 1 Jun 2023 13:15:28 -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 C9198E2 for ; Thu, 1 Jun 2023 10:14:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685639686; 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=M7UAbNml4oAWGP++9AqxwAaw9U/MQwWhNaY462tBqx4=; b=igR2KjXgb3/16k3aIHz3+9LB/T4aTtlMbYh/s124YsfjrfakAP0mbmpXaPidbNuhIjlQic D0krDZJWtcWpx5Yj7HLJe+Qg5t+CssTJD+Omk5XzfE8BP+9gKlml1v5dlDcNYzojl9P+qN 9bzMpul5TOVhhJiCnt/2PBn+rT/NsZQ= 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-324-Dzf09lmbM7i9aB3uYBIKvQ-1; Thu, 01 Jun 2023 13:14:44 -0400 X-MC-Unique: Dzf09lmbM7i9aB3uYBIKvQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6338385A5A8; Thu, 1 Jun 2023 17:14:43 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3AD31C154D7; Thu, 1 Jun 2023 17:14:41 +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: References: <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> To: Linus Torvalds Cc: dhowells@redhat.com, Jakub Kicinski , 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: <909594.1685639680.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Thu, 01 Jun 2023 18:14:40 +0100 Message-ID: <909595.1685639680@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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=unavailable 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 Linus Torvalds wrote: > > However, this might well cause a malfunction in UDP, for example. > > MSG_MORE corks the current packet, so if I ask sendfile() say shove 32= K > > into a packet, if, say, 16K is read from the source and entirely > > transcribed into the packet, > = > If you use splice() for UDP, I don't think you would normally expect > to get all that well-defined packet boundaries. Actually, it will. Attempting to overfill a UDP packet with splice will g= et you -EMSGSIZE. It won't turn a splice into more than one UDP packet. I wonder if the right solution actually is to declare that the problem is userspace's. If you ask it to splice Z amount of data and it can't manage that because the source dries up prematurely, then make it so that you ass= ume it always passed MSG_MORE and returns a short splice to userspace. Usersp= ace can retry the splice/sendfile or do an empty sendmsg() to cap the message = (or cancel it). Perhaps flushing a short message is actually a *bad* idea. The answer then might be to make TLS handle a zero-length send() and fix t= he test cases. Would the attached changes then work for you? David --- diff --git a/fs/splice.c b/fs/splice.c index 3e06611d19ae..237688b0700b 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -956,13 +956,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)); = @@ -978,14 +982,12 @@ ssize_t splice_direct_to_actor(struct file *in, stru= ct splice_desc *sd, 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 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 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; diff --git a/tools/testing/selftests/net/tls.c b/tools/testing/selftests/n= et/tls.c index e699548d4247..7df31583f2a4 100644 --- a/tools/testing/selftests/net/tls.c +++ b/tools/testing/selftests/net/tls.c @@ -377,7 +377,7 @@ static void chunked_sendfile(struct __test_metadata *_= metadata, char buf[TLS_PAYLOAD_MAX_LEN]; uint16_t test_payload_size; int size =3D 0; - int ret; + int ret =3D 0; char filename[] =3D "/tmp/mytemp.XXXXXX"; int fd =3D mkstemp(filename); off_t offset =3D 0; @@ -398,6 +398,9 @@ static void chunked_sendfile(struct __test_metadata *_= metadata, size -=3D ret; } = + if (ret < chunk_size) + EXPECT_EQ(send(self->fd, "", 0, 0), 0); + EXPECT_EQ(recv(self->cfd, buf, test_payload_size, MSG_WAITALL), test_payload_size); =