Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2382445rwd; Fri, 2 Jun 2023 08:40:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7gxM/ZOlD3II3nKQSDACNJRQ6fkSCvtPB0j2ydzS8yG/UOgSfijsReK5i1CEnAL2dr4vrF X-Received: by 2002:a05:6a20:12c7:b0:111:366:ee9f with SMTP id v7-20020a056a2012c700b001110366ee9fmr14816793pzg.48.1685720408347; Fri, 02 Jun 2023 08:40:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685720408; cv=none; d=google.com; s=arc-20160816; b=Dmw5zkANYBANU/H0zPODyNNuMV99jtBrN2tHJI/zyqmZzBkyMzrs6jZAiJrB02VXj1 VfOWKvDpDV3/XSi92BTuZViq/XQpA8wL47FDKWbiTxmdOvust0KcRW0kUZYP9aYYN/ec JLaTBjpyeP2XEr61JbYq8bCW3mXmvIQ9FLPq6lvPbzLYkps3n6Np4JOWUUR2Zo4HV3Ek qUGrvyQSTyT2/gZWmk0VOkwF7ZWPV8nukoENTP1Mh00bz0liiStzi7MsTfd/voXenSr8 k/6flODN/+YqFAjV+Ss77YK/+FnJKLauglegJv9c4Wo+wu8/TdEw7v5+D6BNx0eWHhpd M3+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=i1bosU+FfxRloSp1wkQbe5FyZjgR/CpUzjqQmhn8VOU=; b=e4g6XCMMIbaSXgDP4wdrxqcy+/qQgYFJDUr59Y4yJ+JSWr0GoL2QokGOaTcTTdiTEb DQJOASnl0joatn9Z9QNkA/pIyrSDpuAppbpSPz2t4Ta+iWqHrjoEWV+wHkjBOBxY1Pgi IpD5tKShTBC4L/+JQnnWSDHYGfnk/vcnsQG+dARqV/8csanqt8Q1jogNvShRdWvQy1/P pJai6iWrnHJqWzHRICijwcw1LU5vU1huEqBd9gt6vZb8sBHgc2JDf1bjlPU20CuCK5Ku P0n8qy4i/giCDWd36VQ50OfcRYdaFNuC4I/r2X5quwkuHIm4ndOcIOBHl3hJRyF2Fldr q0Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XSK5j4vA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k62-20020a636f41000000b0053feb93b539si1171596pgc.330.2023.06.02.08.39.56; Fri, 02 Jun 2023 08:40:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XSK5j4vA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236496AbjFBPJw (ORCPT + 99 others); Fri, 2 Jun 2023 11:09:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236485AbjFBPJf (ORCPT ); Fri, 2 Jun 2023 11:09:35 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53AD0E41 for ; Fri, 2 Jun 2023 08:08:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685718524; 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=i1bosU+FfxRloSp1wkQbe5FyZjgR/CpUzjqQmhn8VOU=; b=XSK5j4vASOImozX0qe4hzxcz/uK711ej2eOOYUvLPorXWnzfvrjm2/H6gZPd+1pUk/mhq4 3TM6gXr4JjzwBqvLndNFc3mmmNgIWc2Y/jA+kXXxV6KsShIk26mryVROjXPm8sS1NNoG0z TGdTkp4BPsku9ypYK26VBu6ahaaX8So= 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-618-i_fo6rKYNaiI2OVO_0s6fw-1; Fri, 02 Jun 2023 11:08:41 -0400 X-MC-Unique: i_fo6rKYNaiI2OVO_0s6fw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A77CA8028B2; Fri, 2 Jun 2023 15:08:40 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 785D0492B0C; Fri, 2 Jun 2023 15:08:37 +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 v3 09/11] tls/device: Support MSG_SPLICE_PAGES Date: Fri, 2 Jun 2023 16:07:50 +0100 Message-ID: <20230602150752.1306532-10-dhowells@redhat.com> In-Reply-To: <20230602150752.1306532-1-dhowells@redhat.com> References: <20230602150752.1306532-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 9ef766e41c7a..f2f1aff19e4a 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);