From patchwork Wed May 24 15:33:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13254204 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 8175BC7EE2D for ; Wed, 24 May 2023 15:34:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE0F7900019; Wed, 24 May 2023 11:33:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B696D900007; Wed, 24 May 2023 11:33:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2F31900019; Wed, 24 May 2023 11:33:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 946E9900007 for ; Wed, 24 May 2023 11:33:58 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 17675160A45 for ; Wed, 24 May 2023 15:33:58 +0000 (UTC) X-FDA: 80825544156.28.5F64568 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 217298001D for ; Wed, 24 May 2023 15:33:55 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HjdFC6t2; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684942436; 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=hDpyQQ1JedFG6lTxY3chHyZphdbNgdYt0GxXfK9/WHk=; b=8laJjx5HVeCVmNqS2epjjgyqcgn69byQgHDC3Nrvb5rELnVgeXhjkORwDqq8A0AErJA9mV GhZeQYeMtwwtMkzy8v07BOUkXhYaBTva1/rJJhndzBiJFNX1ib3u3X3gqQ9Dn2WCXSWVGR caomsJx8YBuPtaxkpFiws+95vR3hdN4= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HjdFC6t2; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684942436; a=rsa-sha256; cv=none; b=crFU6Z8UBxp9NGtMrcLDxKSA46m8LBUuCYajXK5ZeT/YvxGz52qysRUWBbaXLbthaM4pfO 5ptefto8dWojRv7u2YF27nvtDbhWkscZ6RwTF2fqjlXY3349TgHSoG5mkI/VYPjH/BVIsv 3INUTuGInkd0Q6eU0yQcZvBvCstulQ8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684942435; 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=hDpyQQ1JedFG6lTxY3chHyZphdbNgdYt0GxXfK9/WHk=; b=HjdFC6t2VP1aiwLsb2DMW0wim/+RCY5hWVK/NLATyj8Xf2OiEcKJL6HXAgpk/27gYVdRgM 3C7WQsBfQHDuBBlcWmqb5680fhxtuHzJsV/fxybz894VZKqkDqeabcVlTV5i1sirS2sz2c A1fY1oybZtzfKjTU8DuqyOfyzGFZGZY= 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-164-4pleeuJrPNyai-iLRApvog-1; Wed, 24 May 2023 11:33:49 -0400 X-MC-Unique: 4pleeuJrPNyai-iLRApvog-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 9A7B73849528; Wed, 24 May 2023 15:33:48 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B045C164ED; Wed, 24 May 2023 15:33:46 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , David Ahern , Matthew Wilcox , Jens Axboe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chuck Lever , Boris Pismenny , John Fastabend Subject: [PATCH net-next 09/12] tls/sw: Support MSG_SPLICE_PAGES Date: Wed, 24 May 2023 16:33:08 +0100 Message-Id: <20230524153311.3625329-10-dhowells@redhat.com> In-Reply-To: <20230524153311.3625329-1-dhowells@redhat.com> References: <20230524153311.3625329-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Queue-Id: 217298001D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 1c7jqejjbibymwp3qktnmecuhkiekwn4 X-HE-Tag: 1684942435-699510 X-HE-Meta: U2FsdGVkX1/8nmj7w+4Qm62144FmrXTIuBFohtwr9PYdEoop/kIOKiHuOauShXIzqLGTa61Ar10UAYBlkqm+tLxNXVcnyrF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SxGFCWgvuvgTCd+C7I5+PHzdXop0KjuSiM9m2GS3BoKKn18gvWe6s3+97zYRboVpzDuuxKMeol7sqBUuHlFlPwk+Fwn+Ef0jfZ2UbDmxE+gQnT1T0CD4DTwyjIJ4zPX7ciBCtJaecTc3BsEj0YGlawvOUQ8tiGc0nFJk0dwefSyLRGZU6mrwWAQh22H2bFq01lptP9vNulQdVPZgu2N1NK7+2TPsDTyr64367fr1nEfcRD74KCQGggqIwbrVxHr9xV334UG/xuoj7SfgxwVvNh4pJgXL1s35iCs4tfLGF+facAIJco7v6IQTMB4lEBJ6g7xzJ4q4bQoGm954BHnC5elNA3Q3lNkd0dA0lY3WE8gU3tG4GfCetNg== 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 and copied the data if not. 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 --- net/tls/tls_sw.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index 635b8bf6b937..0ccef8aa9951 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -929,6 +929,49 @@ static int tls_sw_push_pending_record(struct sock *sk, int flags) &copied, flags); } +static int rls_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 (!sendpage_ok(page)) { + const void *p = kmap_local_page(page); + void *q; + + q = page_frag_memdup(NULL, p + off, part, + sk->sk_allocation, ULONG_MAX); + kunmap_local(p); + if (!q) { + iov_iter_revert(&msg->msg_iter, part); + return -ENOMEM; + } + page = virt_to_page(q); + off = offset_in_page(q); + put = true; + } + + 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); @@ -1018,6 +1061,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 = rls_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; @@ -1080,8 +1134,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,