From patchwork Tue May 30 22:26:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13261182 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74B64C77B7A for ; Tue, 30 May 2023 22:26:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 06F67280001; Tue, 30 May 2023 18:26:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 020A96B0074; Tue, 30 May 2023 18:26:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E2991280001; Tue, 30 May 2023 18:26:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CFB9F6B0072 for ; Tue, 30 May 2023 18:26:52 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7FBD8C0366 for ; Tue, 30 May 2023 22:26:52 +0000 (UTC) X-FDA: 80848357464.08.1632C09 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 15D8240017 for ; Tue, 30 May 2023 22:26:49 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hf6khNLP; spf=pass (imf12.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685485610; a=rsa-sha256; cv=none; b=ViBb4eC6e+WOJiuHnXCbzbrFn0EWKUzr96cL7VbA2IIuotcAq60L/SpQH6cXtlq0cNF9u0 BOzw8hyALvohzDnjm0sXJkyuA43/3Gk675aiW1j25XaO+ZVPnFexvXJ0ERatY3X/910lH/ 2HsTddFVFF+ApugwdVdcKFP2BlpcNH0= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hf6khNLP; spf=pass (imf12.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685485610; h=from:from:sender: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:dkim-signature; bh=tNYdArI3imuxwPg8NiyNMfN64svKTcTa3/gSVgtKOkI=; b=FXC7V1Lh18mTE/8+i5swv98yXOuvLvwUkA05BaUZw2fKNlFAB+2eOuLvpDBMXEEWg29WKH VW8mj266f6rl98kax9Zea9ChehWEfHuzcv0neAygdP5JX8ciPwOx5ig+dlpbtQGEq4zwL1 I4xd61wcd0hI+3lmIUamq+i1Xa+Snxs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685485609; 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=tNYdArI3imuxwPg8NiyNMfN64svKTcTa3/gSVgtKOkI=; b=hf6khNLPqUu5IVCjiNzIhqhIopNIhyaMK9XLaDXRHz70377E4JKVNnNg9GaacdBAO3IkJp zokDOrp/UcdjBL7a1mPLyQzA2jyjlhNNMqPuagG7zeYEA7e6pf19lSwbt8MmnSPi1FC23n /e5mTvvY9WJusqfbToFDcTVXgXW7XKs= 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-355-WlHwnQMoPa6At32JsJXk0Q-1; Tue, 30 May 2023 18:26:47 -0400 X-MC-Unique: WlHwnQMoPa6At32JsJXk0Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C447D800969; Tue, 30 May 2023 22:26:46 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id ACFE92166B25; Tue, 30 May 2023 22:26:44 +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: <20230526180844.73745d78@kernel.org> References: <20230526180844.73745d78@kernel.org> <20230524153311.3625329-1-dhowells@redhat.com> <20230524153311.3625329-10-dhowells@redhat.com> To: Jakub Kicinski Cc: dhowells@redhat.com, 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 , Linus Torvalds Subject: Bug in short splice to socket? MIME-Version: 1.0 Content-ID: <499790.1685485603.1@warthog.procyon.org.uk> Date: Tue, 30 May 2023 23:26:43 +0100 Message-ID: <499791.1685485603@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspamd-Server: rspam08 X-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bPV72F9xprq82WLpAO22KAUtndXGrYWQ2Blk6nryJwoR/qFw30LSAjEEOaj6VqD3cZ/XTTIPZ7HgPQTNemj7RkZadY5FXWfxT/G+4OxLdOhGz7UqT0uSUUue4ZPUsNU/uDjNgKdxT3CxOnw6B/YOOdtrWordqjsEaZWfGSG/YxE/OHoCmYgMjg3sfKbjzay5A4+rBXpsnPFJWZXsa1dUUwpAAJtZrxxD5FCWoWV/56ewi9Ppl1EnPln+WtiurtkoRtt9AKqSLiyp/M5vcxchXqTC9QPvbkstXWbnWf6OteMOoY4LSHWGAkqxtQT1j0QJKODgzzigij1I7dQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Jakub Kicinski wrote: > Will the TLS selftests under tools/.../net/tls.c exercise this? Interesting. Now that you've pointed me at it, I've tried running it. Mostly it passes, but I'm having some problems with the multi_chunk_sendfile tests that time out. I think that splice_direct_to_actor() has a bug. The problem is this bit of code: /* * 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 (read_len < len) sd->flags |= SPLICE_F_MORE; else if (!more) sd->flags &= ~SPLICE_F_MORE; When used with sendfile(), it sets SPLICE_F_MORE (which causes MSG_MORE to be passed to the network protocol) if we haven't yet read everything that the user requested and clears it if we fulfilled what the user requested. This has the weird effect that MSG_MORE gets kind of inverted. It's never seen by the actor if we can read the entire request into the pipe - except if we hit the EOF first. If we hit the EOF before we fulfil the entire request, we get a short read and SPLICE_F_MORE and thus MSG_MORE *is* set. The upstream TLS code ignores it - but I'm changing this with my patches as sendmsg() then uses it to mark the EOR. I think we probably need to fix this in some way to check the size of source file - which may not be a regular file:-/ With the attached change, all tests pass; without it, a bunch of tests fail with timeouts. David diff --git a/fs/splice.c b/fs/splice.c index 3e06611d19ae..a7cf216c02a7 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -982,10 +982,21 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd, * If this is the last data and SPLICE_F_MORE was not set * initially, clears it. */ - if (read_len < len) - sd->flags |= SPLICE_F_MORE; - else if (!more) + if (read_len < len) { + struct inode *ii = in->f_mapping->host; + + if (ii->i_fop->llseek != noop_llseek && + pos >= i_size_read(ii)) { + if (!more) + sd->flags &= ~SPLICE_F_MORE; + } else { + sd->flags |= SPLICE_F_MORE; + } + + } else if (!more) { sd->flags &= ~SPLICE_F_MORE; + } + /* * NOTE: nonblocking mode only applies to the input. We * must not do the output in nonblocking mode as then we