Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1139948rwd; Wed, 7 Jun 2023 11:34:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6/hx9rdQslh7YEaKOrn4bZxGX8P/lh97AGtUxm59Jpxwnq1T6C9A9BPauFUBp7Beu4asHU X-Received: by 2002:a17:902:ead5:b0:1a2:6257:36b9 with SMTP id p21-20020a170902ead500b001a2625736b9mr5977296pld.31.1686162845017; Wed, 07 Jun 2023 11:34:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686162845; cv=none; d=google.com; s=arc-20160816; b=Y/iOwd59VhwgpztLlUDoldxUcwc/ff1IzUnaYEkR39F97y+TrWWX6tn0XPqk5qtJEE WEY47fNzYQ+lWa/qgiEerp//Yq59jsMMo/iCvSIti0wvYMOQBrfxApzf16qMYqX1yl2n tEh8/nwvOqhGgrUZG3k7Wd9W/EWEDkg0W6/JMg2kWI7le6RuUmCXFiQoBb28PDzp0rtI wZi30vrt5jhXkQYGk+d5Oaxb9CJJNAPipejrHyVmt31aCzyUld21M+Q4wxhGQQZCg0mT Zm4tAe2GJRMd8d78wpxhqwq/dzdWq6blcIea5dT/RHQHVQr60ws6RzoB4LccVC6KcHLP UdYQ== 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=IkTAZr7FImbpw2xGK0s50kcwLgB1Jva9F8sfMs3my/4=; b=TH/rJk429a0pxG5DGUJBE2VOyiZrs1sH0t6a7CU1UawD0v0nuBg4xi3pUrf36UBnjB mSh2hzsuu6LEPNCz/kctEr20Zz528khoipYwjJyClr91ekcW4ZzquE8MO6z7FaCAqbRh AHT9n6XOJFnlQrk7StgbXomJbjywUNBMN51ttMoBcfx5mleWS8LngtS+hgoxWpeBabCV mtgc8tUr3ybcLh7ykpFUKtXrHmRHi7NkrXAh3o+zPE/6KcBUjZpfHxFfhO8f+lgwl3+1 suHBINTPKGKOz2YIK50piCIxQFbM8xlBlMsQLWbz72Hbe8guc6LF2s6qhGsw79rgScD3 EFnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ioAUqIfG; 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 y4-20020a17090322c400b001ae001e8bc9si9465284plg.188.2023.06.07.11.33.49; Wed, 07 Jun 2023 11:34:04 -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=ioAUqIfG; 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 S229925AbjFGSWE (ORCPT + 99 others); Wed, 7 Jun 2023 14:22:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbjFGSVO (ORCPT ); Wed, 7 Jun 2023 14:21:14 -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 4D0441FDB for ; Wed, 7 Jun 2023 11:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686162027; 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=IkTAZr7FImbpw2xGK0s50kcwLgB1Jva9F8sfMs3my/4=; b=ioAUqIfG4h4zxyH8Cb+PFoSyJwFhiQ6Sdn1OuIZdQfT5A22FMzguHPfsuvhyXj4UffFxcA p5qsukxaYB94sk8mypg/gIPQ/5WZZdAYd1HkyJtl/AxLU9Z2BCVWehQgugw+TqivtIX1Xq OuMmmKxUwMEaQa7DXwWY45MuZ4D9FQ8= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-389-fnwzd9GMNVGNYa4DGCVeZg-1; Wed, 07 Jun 2023 14:20:09 -0400 X-MC-Unique: fnwzd9GMNVGNYa4DGCVeZg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 89E833806704; Wed, 7 Jun 2023 18:20:03 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 692A51121314; Wed, 7 Jun 2023 18:20:00 +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 06/14] tls/device: Use splice_eof() to flush Date: Wed, 7 Jun 2023 19:19:12 +0100 Message-ID: <20230607181920.2294972-7-dhowells@redhat.com> In-Reply-To: <20230607181920.2294972-1-dhowells@redhat.com> References: <20230607181920.2294972-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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 Reviewed-by: Jakub Kicinski cc: Chuck Lever cc: Boris Pismenny cc: John Fastabend 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 82ec5c654f32..7b9c83dd7de2 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -1044,10 +1044,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];