Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5604700rwd; Mon, 5 Jun 2023 06:12:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7mleuUJ+aQDSrov8dz6NHmydTMliTby+j8H0o9k1/v29Jryx8+hhSQ4P1CeQFcJmO00GMQ X-Received: by 2002:a17:902:e5c4:b0:1b0:3742:e732 with SMTP id u4-20020a170902e5c400b001b03742e732mr9439191plf.23.1685970720879; Mon, 05 Jun 2023 06:12:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685970720; cv=none; d=google.com; s=arc-20160816; b=M+a+RgRkii0gU1QNMzDT4UqvwUGZGwj7BNKVzGouPh5kMXQtM5esRLxthdwHWU3HtF yfOBnqPdpn5z88QhVji7z7bFJVM2iPseF9bRCLYIFo42A1y71bM5DGUSxY79TAl+sBur /ulHrZz6hcGEoptJcmHsM+WiNj9apVlBPI8Yz62pRVI1c/TceePmcm3IONoEjTkFtsQq /nx33tdwrt1slQebyFSA+mj+AfWhMAVHIjwQyQuax6mjzVwJitq4HLrYxtllslCr+RgO UYty2Uua6pM9O1hu5n95xTrAk1HGabAIlKqfe/Hs7Mb4jxC8vpbgRi+XRIBN+x1JPY4t 5bDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=3oNyiHHcuQenXH0USNfKt5/XNQyrParESad6JGCD/rQ=; b=CUAFETaI3QlwNxWoIjU+XFEEHRnhomKnspiWgDEyjdPUJMKy0udGc9rPNNfWrn79zV NDsXzfsulbinAuA1U3YNY7dhiC8gyoK1uAqJVtfRDVPqc/hlAlyZG/H5S4QZdDEFQkWu zoCKMd7/WI47r7GZ18baCVrsDfORlMJ0tOAAq8sHxpXF4o4QH3hrt2pj9nE+4YJyfDTF 8n14UoEjJve2xTRBSQsvGjvMO1bmJNbVSJeJNZKx4e6jSd6iO58TsY5SEAb+jiIO+FOS o2xwrqRdLtDk4xRTuu1gpvNSg+/nK9JkuAhabysxwbMx6llTNY8xI6ZNfshR2ygJDP5B WzxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=doCYBj4n; 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 bc3-20020a170902930300b001b066c922d3si5387318plb.314.2023.06.05.06.11.38; Mon, 05 Jun 2023 06:12:00 -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=doCYBj4n; 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 S231213AbjFEMqz (ORCPT + 99 others); Mon, 5 Jun 2023 08:46:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbjFEMqy (ORCPT ); Mon, 5 Jun 2023 08:46:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D078DB for ; Mon, 5 Jun 2023 05:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685969169; 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=3oNyiHHcuQenXH0USNfKt5/XNQyrParESad6JGCD/rQ=; b=doCYBj4ng2wyjsmh964byLEkQmsRbNE6bfRk99hGYGoo8Ffy463cnotEyhPzl3kkOMu9rD CxoHnB7wtEoFMSMzsiOhTOpGxPkBcLKYfUn7yRp6zND6prPow5QzHiLF1oVn3BbEgoKZv1 K7FW0ZH6Zn+ACZcFkpgym3n8gn9fc5w= 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-417-b6RIPDzwNMy32mVe6queRw-1; Mon, 05 Jun 2023 08:46:06 -0400 X-MC-Unique: b6RIPDzwNMy32mVe6queRw-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 ACBDE8030D3; Mon, 5 Jun 2023 12:46:05 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id A748DC1603B; Mon, 5 Jun 2023 12:46:03 +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 v4 00/11] splice, net: Rewrite splice-to-socket, fix SPLICE_F_MORE and handle MSG_SPLICE_PAGES in AF_TLS Date: Mon, 5 Jun 2023 13:45:49 +0100 Message-ID: <20230605124600.1722160-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Spam-Status: No, score=-2.1 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 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) 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. (7) 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 #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 (11): 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 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 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/sock.h | 1 + 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 | 253 ++++++++++++++++++++++------------------- 11 files changed, 385 insertions(+), 239 deletions(-)