From patchwork Wed Jun 7 18:19:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13271086 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 A829DC7EE23 for ; Wed, 7 Jun 2023 18:19:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B17BB8E0001; Wed, 7 Jun 2023 14:19:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC6F76B0074; Wed, 7 Jun 2023 14:19:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98F038E0001; Wed, 7 Jun 2023 14:19:35 -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 87B386B0072 for ; Wed, 7 Jun 2023 14:19:35 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3DC2E1C79C5 for ; Wed, 7 Jun 2023 18:19:35 +0000 (UTC) X-FDA: 80876764710.21.D3F95EB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 851A01C0021 for ; Wed, 7 Jun 2023 18:19:32 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=g4iUDqW3; spf=pass (imf20.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=1686161972; a=rsa-sha256; cv=none; b=zLqFEKvMa5ifjzmqt79plTkwzeIcaQ81wbQl/U4ikNQ1cTIsXSRkeQNxbtFOyPzDtxQgbf QXqj0RGhhJ1BQspg4bDT2YM0PAVpDI5V3lTDII7Av+IWo/MoNHxr6zHDrP+qy+s5wvPMdv MD+Rm5iZQ+Qfo9nvOcz+TxWQDgfHWgE= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=g4iUDqW3; spf=pass (imf20.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=1686161972; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=zjBZGOWeC2+j8rdZ1VNcBc7uMi5724ZRd7M0xAXNpHw=; b=xh4B8zUMZqckTdEUW4DUJ9ZfU43BWnHkYTL5XNA2uPpszr15LU4mg+3LtAaiVAvtNCHkI4 rx/L3FWVYfxnjCT6oMQR4RxFdioYq0y4W0AcC9pIhDdyOuqMbm3OIkmOJ4sLRuHTPTpttt 2Hf+7fAcU40GCgjVg603OAxCDzlvu9g= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686161970; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=zjBZGOWeC2+j8rdZ1VNcBc7uMi5724ZRd7M0xAXNpHw=; b=g4iUDqW3oWYF1loonFFnquoaTYBuRC5bA0Yk68vH0cDq9RZN+bRLSzDX6y/g5E0flS4Njk uJ6ZyMRVNFsvVywYYu5HQ5x3rIKonH1lR4mc3cS8rPbYTwWoaXmy7erI2sMQKwN+DUw7M/ QJNX3W7ZPX9vC3YhqwjA9jvgUlyFsXA= 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-659-whvtqlXhPLWtG6JzyDFNIw-1; Wed, 07 Jun 2023 14:19:26 -0400 X-MC-Unique: whvtqlXhPLWtG6JzyDFNIw-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 7AFAA101A53A; Wed, 7 Jun 2023 18:19:25 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40E7C2166B25; Wed, 7 Jun 2023 18:19:23 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org, Linus Torvalds Cc: David Howells , Chuck Lever , Boris Pismenny , John Fastabend , Jakub Kicinski , "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 Subject: [PATCH net-next v6 00/14] splice, net: Rewrite splice-to-socket, fix SPLICE_F_MORE and handle MSG_SPLICE_PAGES in AF_TLS Date: Wed, 7 Jun 2023 19:19:06 +0100 Message-ID: <20230607181920.2294972-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 851A01C0021 X-Stat-Signature: yspp3s1i4149g19zz95zeigik8xxyf5b X-Rspam-User: X-HE-Tag: 1686161972-683355 X-HE-Meta: U2FsdGVkX19JSO/Pn4j2gwuQI2/k+DrcPfY/cOfMfNLXvpzhezikpXf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Je59D3egg0d/0aXhlx1vSN/tc96HITUiJK6VBFrYehrbVTk3DW47ze0Hx0SCs3NbospOebpEPT+ENw5YAOzWbOpRE9SwXHQwuSeMFAPzdTyX0E3lz4qdctv5ReASrHodfmJkJPk2CrtvTg+O1sP8i9oLq2YHFfZ/MA8QG6yDrqtfpK2DJDa3iZGv1vLiOXGKYQh3HVRm96pNQBGkMymDSoxN2+MPoVYL8lUQXZTaUayf9+TkSpShjU/4R+aSv2TrZh5xQ5CgV4ie5D8syjbJA0bVEeGkoA== 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: Here are patches to do the following: (1) Block MSG_SENDPAGE_* flags from leaking into ->sendmsg() from userspace, whilst allowing splice_to_socket() to pass them in. (2) Allow MSG_SPLICE_PAGES to be passed into tls_*_sendmsg(). Until support is added, it will be ignored and a splice-driven sendmsg() will be treated like a normal sendmsg(). TCP, UDP, AF_UNIX and Chelsio-TLS already handle the flag in net-next. (3) Replace a chain of functions to splice-to-sendpage with a single function to splice via sendmsg() with MSG_SPLICE_PAGES. This allows a bunch of pages to be spliced from a pipe in a single call using a bio_vec[] and pushes the main processing loop down into the bowels of the protocol driver rather than repeatedly calling in with a page at a time. (4) Provide a ->splice_eof() op[2] that allows splice to signal to its output that the input observed a premature EOF and that the caller didn't flag SPLICE_F_MORE, thereby allowing a corked socket to be flushed. This attempts to maintain the current behaviour. It is also not called if we didn't manage to read any data and so didn't called the actor function. This needs routing though several layers to get it down to the network protocol. [!] Note that I chose not to pass in any flags - I'm not sure it's particularly useful to pass in the splice flags; I also elected not to return any error code - though we might actually want to do that. (5) Provide tls_{device,sw}_splice_eof() to flush a pending TLS record if there is one. (6) Provide splice_eof() for UDP, TCP, Chelsio-TLS and AF_KCM. AF_UNIX doesn't seem to pay attention to the MSG_MORE or MSG_SENDPAGE_NOTLAST flags. (7) Alter the behaviour of sendfile() and fix SPLICE_F_MORE/MSG_MORE signalling[1] such SPLICE_F_MORE is always signalled until we have read sufficient data to finish the request. If we get a zero-length before we've managed to splice sufficient data, we now leave the socket expecting more data and leave it to userspace to deal with it. (8) Make AF_TLS handle the MSG_SPLICE_PAGES internal sendmsg flag. MSG_SPLICE_PAGES is an internal hint that tells the protocol that it should splice the pages supplied if it can. Its sendpage implementations are then turned into wrappers around that. I've pushed the patches here also: https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=sendpage-2-tls David Changes ======= ver #6) - In inet_splice_eof(), use prot after deref of sk->sk_prot. - In udpv6_splice_eof(), use udp_v6_push_pending_frames(). - In udpv6_splice_eof(), don't check for AF_INET. - In kcm_splice_eof(), use skb_queue_empty_lockless(). - In tls_sw_sendmsg_splice(), remove unused put_page. - In tls_sw_sendmsg(), don't set pending_open_record_frags twice. ver #5) - In splice_to_socket(), preclear ret in case len == 0. - Provide ->splice_eof() for UDP, TCP, Chelsio-TLS and AF_KCM. ver #4) - Switch to using ->splice_eof() to signal premature EOF to the splice output[2]. ver #3) - Include the splice-to-socket rewrite patch. - Fix SPLICE_F_MORE/MSG_MORE signalling. - Allow AF_TLS to accept sendmsg() with MSG_SPLICE_PAGES before it is handled. - Allow a zero-length send() to a TLS socket to flush an outstanding record. - Address TLS kselftest failure. ver #2) - Dropped the slab data copying. - "rls_" should be "tls_". - Attempted to fix splice_direct_to_actor(). - Blocked MSG_SENDPAGE_* from being set by userspace. Link: https://lore.kernel.org/r/499791.1685485603@warthog.procyon.org.uk/ [1] Link: https://lore.kernel.org/r/CAHk-=wh=V579PDYvkpnTobCLGczbgxpMgGmmhqiTyE34Cpi5Gg@mail.gmail.com/ [2] Link: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=51c78a4d532efe9543a4df019ff405f05c6157f6 # part 1 Link: https://lore.kernel.org/r/20230524153311.3625329-1-dhowells@redhat.com/ # v1 David Howells (14): net: Block MSG_SENDPAGE_* from being passed to sendmsg() by userspace tls: Allow MSG_SPLICE_PAGES but treat it as normal sendmsg splice, net: Use sendmsg(MSG_SPLICE_PAGES) rather than ->sendpage() splice, net: Add a splice_eof op to file-ops and socket-ops tls/sw: Use splice_eof() to flush tls/device: Use splice_eof() to flush ipv4, ipv6: Use splice_eof() to flush chelsio/chtls: Use splice_eof() to flush kcm: Use splice_eof() to flush splice, net: Fix SPLICE_F_MORE signalling in splice_direct_to_actor() tls/sw: Support MSG_SPLICE_PAGES tls/sw: Convert tls_sw_sendpage() to use MSG_SPLICE_PAGES tls/device: Support MSG_SPLICE_PAGES tls/device: Convert tls_device_sendpage() to use MSG_SPLICE_PAGES .../chelsio/inline_crypto/chtls/chtls.h | 1 + .../chelsio/inline_crypto/chtls/chtls_io.c | 9 + .../chelsio/inline_crypto/chtls/chtls_main.c | 1 + fs/splice.c | 207 ++++++++++++--- include/linux/fs.h | 3 +- include/linux/net.h | 1 + include/linux/socket.h | 4 +- include/linux/splice.h | 3 + include/net/inet_common.h | 1 + include/net/sock.h | 1 + include/net/tcp.h | 1 + include/net/udp.h | 1 + net/ipv4/af_inet.c | 18 ++ net/ipv4/tcp.c | 16 ++ net/ipv4/tcp_ipv4.c | 1 + net/ipv4/udp.c | 16 ++ net/ipv6/af_inet6.c | 1 + net/ipv6/tcp_ipv6.c | 1 + net/ipv6/udp.c | 15 ++ net/kcm/kcmsock.c | 15 ++ net/socket.c | 36 +-- net/tls/tls.h | 2 + net/tls/tls_device.c | 110 ++++---- net/tls/tls_main.c | 4 + net/tls/tls_sw.c | 248 +++++++++--------- 25 files changed, 478 insertions(+), 238 deletions(-)