From patchwork Wed Jun 7 14:05:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13270945 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 313FCC7EE23 for ; Wed, 7 Jun 2023 16:25:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A08506B0072; Wed, 7 Jun 2023 12:25:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 96A148E0002; Wed, 7 Jun 2023 12:25:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80A948E0001; Wed, 7 Jun 2023 12:25:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6DEBE6B0072 for ; Wed, 7 Jun 2023 12:25:47 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3B16F1C7802 for ; Wed, 7 Jun 2023 16:25:47 +0000 (UTC) X-FDA: 80876477934.25.52A3243 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 376D7C0027 for ; Wed, 7 Jun 2023 16:25:44 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=atsy9MJ+; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1686155144; 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=/RO1yxPz5vv1zCyaq/Wi9xLZBTYHqYC8FIFy+4PrNrg=; b=r+PTAiB/4e/pvWSLaXRJhaGer3n0cjz+d76iy06XKG45eImEyU96tC0O8v3UcgQv5kRmUT MIo+5vnO/EPVSwfpsL9hl/XUNgu44/7ELzj+FKoWL+mfC7fOGxzGoFKLql5BODTMbVn2bt CFsBMnP7G0vA/L9/wZgoAs4PTe1pqaI= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=atsy9MJ+; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686155144; a=rsa-sha256; cv=none; b=VUEDC3swgvRMXnxgLZ0QNV+yKwxWyHoOG08DGlrFVILC2AKW/8KBiaUKrRNzFK9h3oqfWe b7/w/1UC+n8hSan4ZteTidI7u9d3qtz3uCiDMEU7qZlFiYYUcLdzUOstOMcnnB2aixJBqu 6srjJ8qqy7AipAPVJBTjMxTf4Gy7Nkw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686155143; 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=/RO1yxPz5vv1zCyaq/Wi9xLZBTYHqYC8FIFy+4PrNrg=; b=atsy9MJ+JprhZDs5eXZTLGhfM7c+OPKEuWCcYmIKx37kUkY+IfQV4MdDFa5Q984CwUnavL SaDwsKOuR+X0CQloXHT7CzqFVW3qfx3VIE9oweyDtBPHy1UZvOeJnBXfzXm6ksbg19E2dp RPR9aHamhw+KXfdX3fdy8d6I6lPtBmU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-646-2UqzVZS9PQ2uhUjL3YSU2g-1; Wed, 07 Jun 2023 10:06:59 -0400 X-MC-Unique: 2UqzVZS9PQ2uhUjL3YSU2g-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 C3ABF811E7C; Wed, 7 Jun 2023 14:06:58 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C5992166B25; Wed, 7 Jun 2023 14:06:55 +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 13/14] tls/device: Support MSG_SPLICE_PAGES Date: Wed, 7 Jun 2023 15:05:58 +0100 Message-ID: <20230607140559.2263470-14-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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 376D7C0027 X-Stat-Signature: hk1nod1o5rjpq7zobd49zidwnuoy61gu X-HE-Tag: 1686155144-891968 X-HE-Meta: U2FsdGVkX18TcDb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oKCkcnP4D5Xs18WLUM/yG65NZiedDdlPZNxB202OeOryTRitdcp1cGbMxNQaHiFhdkx+r59Pb7ofSEIuVd78qkb67O50YlJ22eyFu7uuobg6r/PZ9R8nIlmMVZxnbZOYonrdbEgOUAWIJ2YOdSjxrhot9umIDsiEEkBAfYUxGFTVASxFzElScXWOnzhu9WSnP+S4660gLJffS8qTaRKx8IwXDN0J2ID7fqyHRWJZ2MHSaf8/2gtULdfRAEkgG8Xru9dyvFKomfmSakSoxMQgbQWPguycfiiw4PaaDk0OBO2HL9eoXb4KoI+lgbevOLquf9UtlKmjJove75gb+b1Vm+iDurV5axmN2RIgIZqt1FNOjrS52g30cCGYYMIAZKkv+x7aDOb+/ZfvjDwG44dgSUuVCnPeL4+6kTlCCSP5JHrnBwYoSmrEKpALMI7nrAEdnojGpI7xyynuWEDavhPtB/2Q== 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 device 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 Reviewed-by: Jakub Kicinski --- net/tls/tls_device.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index 439be833dcf9..bb3bb523544e 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -509,6 +509,29 @@ static int tls_push_data(struct sock *sk, tls_append_frag(record, &zc_pfrag, copy); iter_offset.offset += copy; + } else if (copy && (flags & MSG_SPLICE_PAGES)) { + struct page_frag zc_pfrag; + struct page **pages = &zc_pfrag.page; + size_t off; + + rc = iov_iter_extract_pages(iter_offset.msg_iter, + &pages, copy, 1, 0, &off); + if (rc <= 0) { + if (rc == 0) + rc = -EIO; + goto handle_error; + } + copy = rc; + + if (WARN_ON_ONCE(!sendpage_ok(zc_pfrag.page))) { + iov_iter_revert(iter_offset.msg_iter, copy); + rc = -EIO; + goto handle_error; + } + + zc_pfrag.offset = off; + zc_pfrag.size = copy; + tls_append_frag(record, &zc_pfrag, copy); } else if (copy) { copy = min_t(size_t, copy, pfrag->size - pfrag->offset); @@ -572,6 +595,9 @@ int tls_device_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) union tls_iter_offset iter; int rc; + if (!tls_ctx->zerocopy_sendfile) + msg->msg_flags &= ~MSG_SPLICE_PAGES; + mutex_lock(&tls_ctx->tx_lock); lock_sock(sk);