From patchwork Wed Jun 7 14:05:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13270780 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 16532C7EE23 for ; Wed, 7 Jun 2023 14:31:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5A2A8E0002; Wed, 7 Jun 2023 10:31:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E2C28E0001; Wed, 7 Jun 2023 10:31:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 835A58E0002; Wed, 7 Jun 2023 10:31:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6C8C08E0001 for ; Wed, 7 Jun 2023 10:31:30 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 40DCA1201D0 for ; Wed, 7 Jun 2023 14:31:30 +0000 (UTC) X-FDA: 80876189940.18.8D7CD1C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf09.hostedemail.com (Postfix) with ESMTP id E761E140036 for ; Wed, 7 Jun 2023 14:31:14 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YJsEne3M; spf=pass (imf09.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=1686148275; 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=fFpvHzgaRY/5j/9ELb8QxJWBpaTq1Vb8GSt760xxeFM=; b=ubjIooI7oVHuzLYOFghjHh3TwHvybmH4CIWF7fXdBVWNPpb46qT/fUyfdfZFcpBqndCIHF 3GbbWyQlHd7B5VIzTEg3aya7XYXcgTrZPZbKDn2qTSNCHqoQJ92Lg5/mdg+/gGVyk7gC7+ NKFwACUEqIL2IEvzVPUkUexAiKybukA= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YJsEne3M; spf=pass (imf09.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=1686148275; a=rsa-sha256; cv=none; b=xkjh5P7ZN0V2a1xe+xCFrwoyHfsRF2KsY7Z34ngU+ScNAG3XurFLe4HZHDIG6gF7gy1hXA Wn95N0FAEixavnSfPaUI1QcEWsBOqTY00hRCOU9s4w2q0+cIi4wHKbqtvqixGss8+9EXgT JGLsffwQqSM0/DjzQqnW6Lp/Kp7Kxsc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686148273; 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=fFpvHzgaRY/5j/9ELb8QxJWBpaTq1Vb8GSt760xxeFM=; b=YJsEne3MlLK2tezWQAr5WW4Hl8iGYofxwPfV3lySr54Rwr0bQ/IrHJsZ+GyVXrzPZ4LMMa kk288qQMrE/787/S1QqY6Toql7pxZXZQgQLieavBrVaasmPXVqm7eBAQQeTZLV+lvSyA1z lFLsuRWOszi/FsCnoK2OToxZ8yL6z8w= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [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-442-0ndtglCKMsqgcKb-RlBYPQ-1; Wed, 07 Jun 2023 10:06:31 -0400 X-MC-Unique: 0ndtglCKMsqgcKb-RlBYPQ-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 382973C02195; Wed, 7 Jun 2023 14:06:30 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1BF922166B25; Wed, 7 Jun 2023 14:06:27 +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 v5 06/14] tls/device: Use splice_eof() to flush Date: Wed, 7 Jun 2023 15:05:51 +0100 Message-ID: <20230607140559.2263470-7-dhowells@redhat.com> In-Reply-To: <20230607140559.2263470-1-dhowells@redhat.com> References: <20230607140559.2263470-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspamd-Queue-Id: E761E140036 X-Rspam-User: X-Stat-Signature: 4oderhxajdekne17wt98gqtrxxgsizqq X-Rspamd-Server: rspam01 X-HE-Tag: 1686148274-524130 X-HE-Meta: U2FsdGVkX1/OPRWSzqRGM/xvN3ycyS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WTikC/5D7km1eMEmjFWKShpKPrK8Af7L374ylKLXO8xSMx9PEt/Ok7nz0ZXE19G1oPbojuaj5+fojGtnSG0s7pW7q56ddzGfKNIlNhDrmkp67WZCNx28wEunOTBAFYXDyAC6sSz32y7e7+/2ylUu9Kfx0d/QRf9wKg0+sPaSZFmeIFdDgYslbxp/f+pRjm6c7gHEQBRthCHeOE3WXMKHb77tB/TIYz988eQ70dkfYITjlF0DmkwBnhHbSK+ftDcIXZYdbXOkB2vuAn+vfhC3WaCzdE3Z0bcVPi8vBCmEPx9l3lRR4iX7NR03xuIulHcEclDDs7M331sSJuJ5gVKmYP5NVsKLSsvw8brcceTJkMLfOeCC2yOGoko55jgeEiIN1voQkTlq1g7itATo/5VT12ufqVv4vX/mL6HPygWlo3VU1JWcdcDBYKMBSlCYxdNdhELrlbons/kkwJXhHk89IYlzhRMalmvksViC44nQebsPfizljQRUyZUm/pgM/OHvR23DFTDzw== 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 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 Reviewed-by: Jakub Kicinski --- 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];