Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7081708rwd; Tue, 6 Jun 2023 06:12:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6zC4WdICrACuoiPHW8p/wsYxWtUAhMrXA/trCz1SC9bdwjI1EvIJ8MZeyw3K0b2bK+dWF6 X-Received: by 2002:a05:620a:244b:b0:75b:23a1:82a2 with SMTP id h11-20020a05620a244b00b0075b23a182a2mr2290185qkn.3.1686057164815; Tue, 06 Jun 2023 06:12:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686057164; cv=none; d=google.com; s=arc-20160816; b=iXl2EWAabqQXwDPbimur3U7ek5p/HWn3JpOg87icCSDXsCwAWxnRvwXGJlns9IDNLa wXxDkQeMXoS2RYGoAz15bVx8WPNxB9HhvcU2y+/k/xyWoTbrXsSn6hCBDFh1obE1wabv TN0CJ3vQuP6ZhQOGyHudMfYGJc5RPzC5gQhyCIpeRN/BW/CY6JHhRhP1QptG/LZTKcyX loGF3LntIttOrh1oCa/vN9ShFznDsp9b320TogA1iuEi13HrO/8cgPUvONpmqJF1usYS vtMhQqjJ9s4jsiqQMYaJSRenwWl+6/OfMVuJfsayQqD2oXBasaD+1LuGS3Cv0iLD7orB G+ww== 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=fy2ggJLQIWe53H9p3VJNg7LWC+KUVOljTaVR6c617po=; b=FKUHxe/+8c/gUBgVjhN9stzszKDrTY8hSzoVkHRf2dkTTjr6UWQ3CkWYVg+i/thZuJ AAT7wmwsGLG03l32ltkIT2v524cmL0bAGpOb/D04gpWYigfXjO0v6qpCukV6smMW56eE S1W45iNlaZ4rFYqSHUqxiPUOUYeUT9OdahZRaDC90T1uHKD+fSn2VajLdCaq+QSB2Ge4 hE8E9ugR8EK2Qx740bl3/0vGhIhQEM8wrrYGlxjAVchEZXvLBB0zd3CTndmXK9WPoqIl UqwmjWe5Sj/su+gKF0DD1h9VadDo/4K222xwAyVOuFBxKOwjZFIJWv9smAf1IbH7FIcA ueZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QOmcBDGm; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 im6-20020a056214246600b0061e800b4fdasi6149267qvb.367.2023.06.06.06.12.14; Tue, 06 Jun 2023 06:12:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=QOmcBDGm; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-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 S238244AbjFFNLy (ORCPT + 99 others); Tue, 6 Jun 2023 09:11:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238200AbjFFNLP (ORCPT ); Tue, 6 Jun 2023 09:11:15 -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 6CCB41731 for ; Tue, 6 Jun 2023 06:10:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686056986; 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=fy2ggJLQIWe53H9p3VJNg7LWC+KUVOljTaVR6c617po=; b=QOmcBDGmvarbaZ06OcKm7BVEg7pj9AHYjzbtjwYqmCV9Bpkm9yRVNnkXBbRAFueQpvigRg W7ZACQ8HE/SOsLWKMcwRb3DAQCejwSlD40svAQsiJd6LyPrTpDNysL2wkCY5Rwj1itjttF 26gzoJz/bwhoo9bgpJDkPWHjVl6h/Nk= 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-630-LDioG1ZoO5yPnQdoqqJwpg-1; Tue, 06 Jun 2023 09:09:43 -0400 X-MC-Unique: LDioG1ZoO5yPnQdoqqJwpg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 302A78037AD; Tue, 6 Jun 2023 13:09:42 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id A110F492B00; Tue, 6 Jun 2023 13:09:39 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , Herbert Xu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , David Ahern , Matthew Wilcox , Jens Axboe , linux-crypto@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v3 09/10] crypto: af_alg: Convert af_alg_sendpage() to use MSG_SPLICE_PAGES Date: Tue, 6 Jun 2023 14:08:55 +0100 Message-ID: <20230606130856.1970660-10-dhowells@redhat.com> In-Reply-To: <20230606130856.1970660-1-dhowells@redhat.com> References: <20230606130856.1970660-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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=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-crypto@vger.kernel.org Convert af_alg_sendpage() to use sendmsg() with MSG_SPLICE_PAGES rather than directly splicing in the pages itself. This allows ->sendpage() to be replaced by something that can handle multiple multipage folios in a single transaction. Signed-off-by: David Howells cc: Herbert Xu cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: linux-crypto@vger.kernel.org cc: netdev@vger.kernel.org --- crypto/af_alg.c | 52 ++++++++----------------------------------------- 1 file changed, 8 insertions(+), 44 deletions(-) diff --git a/crypto/af_alg.c b/crypto/af_alg.c index 9c12530d604a..3cf734835ccb 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c @@ -1114,53 +1114,17 @@ EXPORT_SYMBOL_GPL(af_alg_sendmsg); ssize_t af_alg_sendpage(struct socket *sock, struct page *page, int offset, size_t size, int flags) { - struct sock *sk = sock->sk; - struct alg_sock *ask = alg_sk(sk); - struct af_alg_ctx *ctx = ask->private; - struct af_alg_tsgl *sgl; - int err = -EINVAL; + struct bio_vec bvec; + struct msghdr msg = { + .msg_flags = flags | MSG_SPLICE_PAGES, + }; if (flags & MSG_SENDPAGE_NOTLAST) - flags |= MSG_MORE; - - lock_sock(sk); - if (!ctx->more && ctx->used) - goto unlock; - - if (!size) - goto done; - - if (!af_alg_writable(sk)) { - err = af_alg_wait_for_wmem(sk, flags); - if (err) - goto unlock; - } - - err = af_alg_alloc_tsgl(sk); - if (err) - goto unlock; - - ctx->merge = 0; - sgl = list_entry(ctx->tsgl_list.prev, struct af_alg_tsgl, list); - - if (sgl->cur) - sg_unmark_end(sgl->sg + sgl->cur - 1); - - sg_mark_end(sgl->sg + sgl->cur); - - get_page(page); - sg_set_page(sgl->sg + sgl->cur, page, size, offset); - sgl->cur++; - ctx->used += size; - -done: - ctx->more = flags & MSG_MORE; - -unlock: - af_alg_data_wakeup(sk); - release_sock(sk); + msg.msg_flags |= MSG_MORE; - return err ?: size; + bvec_set_page(&bvec, page, size, offset); + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, size); + return sock_sendmsg(sock, &msg); } EXPORT_SYMBOL_GPL(af_alg_sendpage);