From patchwork Wed Jun 7 18:19:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13271098 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 95F0DC7EE2E for ; Wed, 7 Jun 2023 18:20:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A545390000B; Wed, 7 Jun 2023 14:20:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9DFAB900004; Wed, 7 Jun 2023 14:20:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 794CE90000B; Wed, 7 Jun 2023 14:20:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 63422900004 for ; Wed, 7 Jun 2023 14:20:30 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 28535A034B for ; Wed, 7 Jun 2023 18:20:30 +0000 (UTC) X-FDA: 80876767020.28.8F8C960 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 4B93C40018 for ; Wed, 7 Jun 2023 18:20:28 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ioAUqIfG; spf=pass (imf04.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=1686162028; 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:in-reply-to:references:references:dkim-signature; bh=IkTAZr7FImbpw2xGK0s50kcwLgB1Jva9F8sfMs3my/4=; b=g3tsY6J9jCpkF8WBPj4HyOrlnGQIbUxOSHa4E+QFc5QVQ7fJy38Scbq9lvCcqbQQuuxPqB +gTdIgAJKpWs/+VNoAm1Znsj0eGVKtzVbEShR3KgKL2xSI1qT4NQBehEdymOlJIGnfNGyg YbRX/QtnkbLZ40bDDzlaGoYc5u+U66A= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686162028; a=rsa-sha256; cv=none; b=eISXSijfLIscRPgVQobpOKDbof+wi+6Hnchgd9KH5n4J4nnNiLKqniqClb8j08wDPSFXB8 TxlA0G41yz/f4w2yzoEiwTUTJQNrj6UIrtSkjJH/yHgzFwMrcd4aWMXxpAVUgb1V4hcz9Y GSZOK6Z+5+3fNStzp43DsODOkrYkNnk= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ioAUqIfG; spf=pass (imf04.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 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 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspamd-Queue-Id: 4B93C40018 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: i99nzdkpm9mhnefgi8umtzp6tr969ju9 X-HE-Tag: 1686162028-462596 X-HE-Meta: U2FsdGVkX18Vjo2brBU42UX8OtiEPkdk6gDs2EhPJ5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0SdnAbwGZ2ugR/bSvHaf8ioAuTyXGg1P7n2GvvC46Ob3cwFvmxZVwA0fMHfZ0LctCn8pU6IKR2FNzarL9UMEkxmqKunBBmHxsLPJYNOV72Mv/0SbU5c+0GTjwyc107bJRhGojFyKDwAyYMoxDgKTNovem18adL0NojInxaQA1kY1nPnDL6a4051neOBOfzDC12sK9eFYBDG8PX+qFisi/qC5BP4fJ3SoBjqNnLPisee5fC+WSbE5JWikGS2+RUhdnxuH9gVlK82pmkIP7BPQYKt33WymB/E/SdBOWZtVPqW4iBIe2M/xmBopPCNTpjidFTWn7P+7y1R3GGspcKzqzITQl2uHf7IaEYbwBKjirEQRgdKqQzp7cAD6GcaKyPo5H52Pkcsg4GsLybOT9AbdnHm1+b5LDnRodtC3VUJt4JVL0m9w0mzWiWhzI8cJGlioMYEI8niBgqUOWP26lVrLjSBX2mpsX2acUx4IQX/vZe3OE85qjmQM8qcJw== 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: 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];