Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5590416rwd; Mon, 5 Jun 2023 06:03:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7oidrJck3wTVtRfVVKNuyvsYt0ThA8cB4sb3f1F9ryhOKVZOEBOe/YBtKEjKBU2D1ZCHxc X-Received: by 2002:a17:90a:eac9:b0:258:de21:f237 with SMTP id ev9-20020a17090aeac900b00258de21f237mr3048365pjb.9.1685970189548; Mon, 05 Jun 2023 06:03:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685970189; cv=none; d=google.com; s=arc-20160816; b=UAhwI7VSblwhCnhsZT1Xm1G4lc6u3IbNd84X/cbnxuxRA5Q9uIggY5JAZXo2o0FeDA ryzFxz7gufDp9W2uTCCCO3Re/IKuNKJkJJxRFRs0S6Rr6ZDGYWXiRU9SDn4nVJxHAXf5 qNtnBLO/pRPMwoNKRkF6hGq0DxRLnNqgKeg7JcX//EfPNpJHyCIgsJzrF2ChTrrRL+pk VpS9Sl2GxfKbP/n2llRIKq7wpaX1bAx6RSNAGEHrjqL56Ilc1jdDfCkF/h59Gs2jEgFw UgHJaShDsgdZkumCGvoilD2OrDg5XoPgCmDHPO8n0CKIWZSobUsl7EtN2NBH4d5hJKzP M8Ow== 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=/RO1yxPz5vv1zCyaq/Wi9xLZBTYHqYC8FIFy+4PrNrg=; b=PKZpkhNo5NnElSBnOo+h3VyBAQD5A8IukPpI+YcDUJpUZsYart6mH4cVXx0hDRN1LG +O/8zmXtr4gRCGR+5/8zd9+vlroo3ZIysP27GLodUHoiaR3g44wcbeP67UrmOhPMg5Kz 84NEYyv4hEh56Zken2BdYC0Q2pxkkIrXHWfvQb7T/8+pPmjGa9GyV4GkXEzCdvVDnNdi 57CyRVoQ8QY8CwSl0mFZ4vUUHnl2rifFN5WdjF980fgpEAU7bc2tjEmQuKJNYu/Hmxff 43l+ARruV8G0Pwi8lbdtPlke2QH+O6OxZNMIw3HXKLEl5tRJygxUwa0o0wEWGdrS9kBW jZCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HuItWBqq; 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 123-20020a630181000000b005303c3dedc2si5458835pgb.419.2023.06.05.06.02.43; Mon, 05 Jun 2023 06:03:09 -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=HuItWBqq; 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 S233799AbjFEMro (ORCPT + 99 others); Mon, 5 Jun 2023 08:47:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233692AbjFEMrZ (ORCPT ); Mon, 5 Jun 2023 08:47:25 -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 872FBEA for ; Mon, 5 Jun 2023 05:46:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685969202; 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=HuItWBqqcmi8V1eZ49EJ/UODFJNLjMDtLynE+CgjA5ad3PsM8JwFzqO/SApvOLG0ZadZjF ZXCys4h918alAR2/h2twBCokwuQEl2RspaoG7ph4CV9iSYZvkqtRYmxoSVJSrJmcWIp2c/ 53Qx5NVyf3Ktr3jK2213UROfr7R+3uI= 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-280-n91873ZbOZGlKJe05F1TyQ-1; Mon, 05 Jun 2023 08:46:36 -0400 X-MC-Unique: n91873ZbOZGlKJe05F1TyQ-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 BBF8285A5A8; Mon, 5 Jun 2023 12:46:35 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0877140E954; Mon, 5 Jun 2023 12:46:33 +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 v4 10/11] tls/device: Support MSG_SPLICE_PAGES Date: Mon, 5 Jun 2023 13:45:59 +0100 Message-ID: <20230605124600.1722160-11-dhowells@redhat.com> In-Reply-To: <20230605124600.1722160-1-dhowells@redhat.com> References: <20230605124600.1722160-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 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=unavailable 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 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);