Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5601822rwd; Mon, 5 Jun 2023 06:10:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4MeSQ4vBm1tR2J4NYmVc9L5G/pzqdkP3l/CPHw5ssrl5D4Yse9trOJRtT61XTsXLtUKJ5v X-Received: by 2002:a05:6a20:1451:b0:10a:ba3a:42dd with SMTP id a17-20020a056a20145100b0010aba3a42ddmr8341728pzi.44.1685970605064; Mon, 05 Jun 2023 06:10:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685970605; cv=none; d=google.com; s=arc-20160816; b=qdgVhpJfFJbxjGLNhXuO4XHwne8VDqZ4+Ii+0nkEeyYCIpZoVwFZoeRX77dsGIe7l8 6CWyyNcIBApwAJo4F+iUy4eWx3NSaO5efk4bBOX1Vbf3zpbhrNIumZ6FXHKR7wTwiCWE kHTe5yp3f3Z213cYJJSIJhM23dNLebxLDtJGHBI0/J5OXKHW6uTNlrgVi7QJkjbG3m11 539DKmRf9rbO3Urv1Q1ncK6WKCWtbW8M1C7LXAWhScC4yl0ozbE84xNXVZhO+kgO1SRF nwPDx7eRm2liSaiuMiVhDc+2GSuSkyXCjNoMLeQ2SS9w1fbW/raujwRO3qF+yJj3nwig 0iAQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uXvpsAJrK5w03LYiEcU7w+tO1rfwJo4A6Bo4opbn2SA=; b=YtxMfdAuCf+hyw5VVyue4umfVJcIBQUijxrI2pK2A7WRLcq5cUAXAabNDlp5hgRmot KxVxfbHwQjZTo9ocpHXFkmcM0nweJ+vp7F2xwShzAr2lD3xuHnv+DfI6S9ZR+X3k6CHT JO8JZKsJ4ylhAXzBZkb2Ip4bvk4KbCW/J3W4T7tNcWN5/LU5NCCtpeS+51Wy7U6/aZF2 4yJ2tV8OOoWlzGLacVHe32TP4E44XWtG/f5XVdLMSO7atUi5tu8dvjvNMgcLo8sqlAp6 Rd/LH53EN3zXFKvhLfqVJmTQLumNPchBv0Iv/Q8a/1uPCVNOidHjzJX6MMdq2V3zSofA +1xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XnB9Lj+f; 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 b66-20020a62cf45000000b0063b872934a4si5328769pfg.340.2023.06.05.06.09.43; Mon, 05 Jun 2023 06:10:05 -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=XnB9Lj+f; 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 S229725AbjFEMv3 (ORCPT + 99 others); Mon, 5 Jun 2023 08:51:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232237AbjFEMvW (ORCPT ); Mon, 5 Jun 2023 08:51:22 -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 78119F3 for ; Mon, 5 Jun 2023 05:50:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685969416; 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: in-reply-to:in-reply-to:references:references; bh=uXvpsAJrK5w03LYiEcU7w+tO1rfwJo4A6Bo4opbn2SA=; b=XnB9Lj+fZPCLK8aJdCPZh4KVFMtM1X+Ova7lPJ2Ky4huynMYQ0ynLvxom8CNOp/CtGdCAd qtVgGG5/gRow8Kfdt7fKZnbqPGQh0k1YQhUNSJjoK9ISxt+WzK8PHTnK7l8UDmuAFoYGXG Inz+fVcCg7JiEH+SBF+rgTijbi8YmL4= 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-407-n2hFhH1TMHWqAqgk0i2fyg-1; Mon, 05 Jun 2023 08:48:53 -0400 X-MC-Unique: n2hFhH1TMHWqAqgk0i2fyg-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 112E1101B040; Mon, 5 Jun 2023 12:46:23 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0EDA1C154D1; Mon, 5 Jun 2023 12:46:20 +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 06/11] tls/device: Use splice_eof() to flush Date: Mon, 5 Jun 2023 13:45:55 +0100 Message-ID: <20230605124600.1722160-7-dhowells@redhat.com> In-Reply-To: <20230605124600.1722160-1-dhowells@redhat.com> References: <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=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 Allow splice to end a TLS record after prematurely ending a splice/sendfile due to getting an EOF condition (->splice_read() returned 0) after splice had called TLS with a sendmsg() with MSG_MORE set when the user didn't set MSG_MORE. Suggested-by: Linus Torvalds Link: https://lore.kernel.org/r/CAHk-=wh=V579PDYvkpnTobCLGczbgxpMgGmmhqiTyE34Cpi5Gg@mail.gmail.com/ Signed-off-by: David Howells cc: Chuck Lever cc: Boris Pismenny cc: John Fastabend cc: Jakub Kicinski cc: Eric Dumazet cc: "David S. Miller" cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: netdev@vger.kernel.org --- net/tls/tls.h | 1 + net/tls/tls_device.c | 23 +++++++++++++++++++++++ net/tls/tls_main.c | 2 ++ 3 files changed, 26 insertions(+) diff --git a/net/tls/tls.h b/net/tls/tls.h index 4922668fefaa..d002c3af1966 100644 --- a/net/tls/tls.h +++ b/net/tls/tls.h @@ -116,6 +116,7 @@ ssize_t tls_sw_splice_read(struct socket *sock, loff_t *ppos, size_t len, unsigned int flags); int tls_device_sendmsg(struct sock *sk, struct msghdr *msg, size_t size); +void tls_device_splice_eof(struct socket *sock); int tls_device_sendpage(struct sock *sk, struct page *page, int offset, size_t size, int flags); int tls_tx_records(struct sock *sk, int flags); diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index 9ef766e41c7a..439be833dcf9 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -590,6 +590,29 @@ int tls_device_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) return rc; } +void tls_device_splice_eof(struct socket *sock) +{ + struct sock *sk = sock->sk; + struct tls_context *tls_ctx = tls_get_ctx(sk); + union tls_iter_offset iter; + struct iov_iter iov_iter = {}; + + if (!tls_is_partially_sent_record(tls_ctx)) + return; + + mutex_lock(&tls_ctx->tx_lock); + lock_sock(sk); + + if (tls_is_partially_sent_record(tls_ctx)) { + iov_iter_bvec(&iov_iter, ITER_SOURCE, NULL, 0, 0); + iter.msg_iter = &iov_iter; + tls_push_data(sk, iter, 0, 0, TLS_RECORD_TYPE_DATA, NULL); + } + + release_sock(sk); + mutex_unlock(&tls_ctx->tx_lock); +} + int tls_device_sendpage(struct sock *sk, struct page *page, int offset, size_t size, int flags) { diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c index 83fa15e52af6..113f3ff91d6c 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -1009,10 +1009,12 @@ static void build_protos(struct proto prot[TLS_NUM_CONFIG][TLS_NUM_CONFIG], #ifdef CONFIG_TLS_DEVICE prot[TLS_HW][TLS_BASE] = prot[TLS_BASE][TLS_BASE]; prot[TLS_HW][TLS_BASE].sendmsg = tls_device_sendmsg; + prot[TLS_HW][TLS_BASE].splice_eof = tls_device_splice_eof; prot[TLS_HW][TLS_BASE].sendpage = tls_device_sendpage; prot[TLS_HW][TLS_SW] = prot[TLS_BASE][TLS_SW]; prot[TLS_HW][TLS_SW].sendmsg = tls_device_sendmsg; + prot[TLS_HW][TLS_SW].splice_eof = tls_device_splice_eof; prot[TLS_HW][TLS_SW].sendpage = tls_device_sendpage; prot[TLS_BASE][TLS_HW] = prot[TLS_BASE][TLS_SW];