From patchwork Wed Jun 7 14:05:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13270783 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 47F5BC7EE23 for ; Wed, 7 Jun 2023 14:32:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CA3858E0005; Wed, 7 Jun 2023 10:32:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C2C538E0001; Wed, 7 Jun 2023 10:32:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ACD028E0005; Wed, 7 Jun 2023 10:32:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 98F5D8E0001 for ; Wed, 7 Jun 2023 10:32:58 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6B8961A026E for ; Wed, 7 Jun 2023 14:32:58 +0000 (UTC) X-FDA: 80876193636.22.E3FE79E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 2C84D40026 for ; Wed, 7 Jun 2023 14:32:55 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=J07mOMpy; spf=pass (imf12.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=1686148376; a=rsa-sha256; cv=none; b=DMUfVi/UzT3wL6PGKdRBJ0cI+jYWHotMa670hAOvJ+8DFHNsobRNPotIjaRGqgEqO2Qg9q cj7VGT0E6g2uiuxIJZTKukqP/TcOEdfOhmHY20H4yMLN8i+gqgkmMDnBME6HhGZyjyfGMZ wbcqkDn34QORxaMzrDNousqSDfsfvLk= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=J07mOMpy; spf=pass (imf12.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=1686148376; 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=mOKXaftBBhMTIlFKfwLIH8NhxIpiz+rLzmWYl6SoU0k=; b=YCPQ4vmv6yX0f6RkVBlq1lyPy3JFjB3Sa2CBI2fMu1xyNffqqplMbd4Wo74vgUL7XtbG7K aYfkTyeIwC5uaa/JKsveQbVJfo+W+mYfLh0InBClWMxclVLuTFj+FdYjDBRxsMwtNCO+YY hOfmbUJumUHL/qy1ztzkCkqa2QlBMkg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686148375; 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=mOKXaftBBhMTIlFKfwLIH8NhxIpiz+rLzmWYl6SoU0k=; b=J07mOMpyq8B20fZrjMWuPZiMnNzRVsyeLEBl2HnYKVri9doRqd6TPf73pH+WUmKvkeHpce QB1Kx4lQoFBYQgADIhlThtpb3n9wgGsGMX40uC9T3WA8v8N1L+oxGD63FL6OuiR5pXflkj niXQtbRp3Y0STjngD4mZwsok0YZOjRk= 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-581-691rPYokOqqZ4ufsxb1e3w-1; Wed, 07 Jun 2023 10:06:51 -0400 X-MC-Unique: 691rPYokOqqZ4ufsxb1e3w-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E32302999B2E; Wed, 7 Jun 2023 14:06:50 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91F90140E954; Wed, 7 Jun 2023 14:06:48 +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 11/14] tls/sw: Support MSG_SPLICE_PAGES Date: Wed, 7 Jun 2023 15:05:56 +0100 Message-ID: <20230607140559.2263470-12-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.7 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 2C84D40026 X-Stat-Signature: cm7jfqaefescfkdk1wtf174tmhi77oux X-Rspam-User: X-HE-Tag: 1686148375-244976 X-HE-Meta: U2FsdGVkX19a3WnPlviukEV/zSUVzQHaYhUQCS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YSsWUeM9i8BeNnEKC8+Me8otoBfWl5mwAHXk2uc6B4a0li7keOLPWJSF0SqnbGU4/azAf1wMJVTr/Jukv6D8nm3aTXwjhI4IV/fTuOdfvA6rZsouyX9MUMSOD7YUz6pMDNCcRzLx3ISJEJ0BNVVqaW8gGMMDWhhbKCH9Pet9UFYV5gNCv9KYz2COxZTxPoDeT9QbQFvKgp+koSR2znGEvDTSSYB+vy9OrKGLJg9PYJoInIBKCvlQW9bprgRn6GSAPSj3Z6USoV9OktOamecanol/vqhSZIecMstKiyXbNLRMxKFCL+KC15kwvJBIrJSsuvqoMm8dEJWcEJjOCvyKXXx0J0Vg2MafaR5miuTJ3E29MRANQsboZrzasPuDt7qPoTlDGTyZeNH73aPEl/CpsXBB1Xvd0vw/lLkey9W1VsYxTPRkXOI0jjxBfXXg== 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: Make TLS's sendmsg() support MSG_SPLICE_PAGES. This causes pages to be spliced from the source iterator if possible. This allows ->sendpage() to be replaced by something that can handle multiple multipage folios in a single transaction. 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 --- Notes: ver #2) - "rls_" should be "tls_". net/tls/tls_sw.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index a2fb0256ff1c..fcbaf594c300 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -931,6 +931,38 @@ static int tls_sw_push_pending_record(struct sock *sk, int flags) &copied, flags); } +static int tls_sw_sendmsg_splice(struct sock *sk, struct msghdr *msg, + struct sk_msg *msg_pl, size_t try_to_copy, + ssize_t *copied) +{ + struct page *page = NULL, **pages = &page; + + do { + ssize_t part; + size_t off; + bool put = false; + + part = iov_iter_extract_pages(&msg->msg_iter, &pages, + try_to_copy, 1, 0, &off); + if (part <= 0) + return part ?: -EIO; + + if (WARN_ON_ONCE(!sendpage_ok(page))) { + iov_iter_revert(&msg->msg_iter, part); + return -EIO; + } + + sk_msg_page_add(msg_pl, page, part, off); + sk_mem_charge(sk, part); + if (put) + put_page(page); + *copied += part; + try_to_copy -= part; + } while (try_to_copy && !sk_msg_full(msg_pl)); + + return 0; +} + int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) { long timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); @@ -1020,6 +1052,17 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) full_record = true; } + if (try_to_copy && (msg->msg_flags & MSG_SPLICE_PAGES)) { + ret = tls_sw_sendmsg_splice(sk, msg, msg_pl, + try_to_copy, &copied); + if (ret < 0) + goto send_end; + tls_ctx->pending_open_record_frags = true; + if (full_record || eor || sk_msg_full(msg_pl)) + goto copied; + continue; + } + if (!is_kvec && (full_record || eor) && !async_capable) { u32 first = msg_pl->sg.end; @@ -1082,8 +1125,9 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) /* Open records defined only if successfully copied, otherwise * we would trim the sg but not reset the open record frags. */ - tls_ctx->pending_open_record_frags = true; copied += try_to_copy; +copied: + tls_ctx->pending_open_record_frags = true; if (full_record || eor) { ret = bpf_exec_tx_verdict(msg_pl, sk, full_record, record_type, &copied,