From patchwork Thu Mar 16 15:26:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13177814 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 0DAA7C7618D for ; Thu, 16 Mar 2023 15:27:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B48094000D; Thu, 16 Mar 2023 11:27:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 93CC194000A; Thu, 16 Mar 2023 11:27:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B71794000D; Thu, 16 Mar 2023 11:27:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 699ED94000A for ; Thu, 16 Mar 2023 11:27:10 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 442CD404C4 for ; Thu, 16 Mar 2023 15:27:10 +0000 (UTC) X-FDA: 80575139820.04.75C93F2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 6B8254001F for ; Thu, 16 Mar 2023 15:27:08 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Vn2guJKd; spf=pass (imf07.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678980428; 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=t96KWWuCikizvNC1y3JF3FIfjq2ZpnpzfAnEQzXudzo=; b=oHTpm+b1ATfWvvri6rZ/Qg/25dE0zSUgq9tmdOBQ5UQ6PrM1YQmVuZqGs5tykKL657lj/s GoCy/k5e9Ez7wOcWJNAWM9WqcIDUplTottgPf3oat25Arh4L1TcIDTCdmosfoqPCuO4zky 41K1IiZFAIVH/1SLD/D5fSkMQD8U3xw= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Vn2guJKd; spf=pass (imf07.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678980428; a=rsa-sha256; cv=none; b=y8e3MJ5dYt8CCrwBdI1HbbBFTwtvKjtKMp6L5khoZcMaU2jWczxuBGa7gzd8IBv6CUhGg4 q0EybL9vcSrz+UzczSut7lj2vd5iuc62GmNI+ddOfZYORInqwwwMPHylZoQoosAYXS3cWG kBS67Z05VeUmb5dh4NjV9scv7OdKHs8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678980427; 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=t96KWWuCikizvNC1y3JF3FIfjq2ZpnpzfAnEQzXudzo=; b=Vn2guJKd3tx2oyLb7btA2qRRF7Chji2NqCvIHWps6cnSwHEekofUTrM+jmlStFOxGu8f0W mzZ9a/t2o49u34uWn+EUrkUjt2c/XLMCTsnrVvFou+LqgpIIfSW9dxdHCF0QW1lHLe0b0a q687woUJM2OGD8veQ2PleUQJK0bh5zU= 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-638-J7ghSUrYNvWcgXhEzMBmmA-1; Thu, 16 Mar 2023 11:27:03 -0400 X-MC-Unique: J7ghSUrYNvWcgXhEzMBmmA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A60961C09044; Thu, 16 Mar 2023 15:27:02 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id A9D8E40C6E67; Thu, 16 Mar 2023 15:27:00 +0000 (UTC) From: David Howells To: Matthew Wilcox , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: David Howells , Al Viro , Christoph Hellwig , Jens Axboe , Jeff Layton , Christian Brauner , Linus Torvalds , netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Herbert Xu , linux-crypto@vger.kernel.org Subject: [RFC PATCH 15/28] crypto: af_alg: Convert af_alg_sendpage() to use MSG_SPLICE_PAGES Date: Thu, 16 Mar 2023 15:26:05 +0000 Message-Id: <20230316152618.711970-16-dhowells@redhat.com> In-Reply-To: <20230316152618.711970-1-dhowells@redhat.com> References: <20230316152618.711970-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: yw6rxw41czgw7wohd757cbkepq569eo3 X-Rspamd-Queue-Id: 6B8254001F X-HE-Tag: 1678980428-385558 X-HE-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3FMWTsFroDaFNikETv91w9+8Uzw28HfPmS/hu+giVwVwJo3HJc0EESrkrVYSI/oBlVvCxB2QW7D274XlV0LCyJE+pEdecBQrlZYgvByqle9YPjXX2OE6QoLxQd5oORjwNQY22kP3LW61A4gDxuvhQXs318OHfctwIr4t0rDAHx3KJoFlotHGlJH85Vxw2fM1Xe1OPjfhDn7o+KgMpLYW9M1Oer3NzU1k+quf11Fh1/sluEooKyIBrNSMFEem4IF+q/JETvZLzer++iL2r5FEUmaPVartKI0Tz0MjxdYOkgooWpw/spCwlvaz/GrIqDKeLWBqW5HPYB4N0hLMtZCkDxgPMZTMXv+jvnYPAWVuoytb8lwBv49TAkR/8cCT3WpxEUUcBpRhqYMuGnz1xK7grwfTQ== 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: 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. [!] Note that this makes use of netfs_extract_iter_to_sg() from netfslib. This probably needs moving to core code somewhere. 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 | 53 +++++++++---------------------------------------- 1 file changed, 9 insertions(+), 44 deletions(-) diff --git a/crypto/af_alg.c b/crypto/af_alg.c index 80ab4f6e018c..0e77fce60876 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c @@ -1148,53 +1148,18 @@ 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; - - 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); + struct bio_vec bvec; + struct msghdr msg = { + .msg_flags = flags | MSG_SPLICE_PAGES, + }; - sg_mark_end(sgl->sg + sgl->cur); + bvec_set_page(&bvec, page, size, offset); + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, size); - 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); + if (flags & MSG_SENDPAGE_NOTLAST) + msg.msg_flags |= MSG_MORE; - return err ?: size; + return sock_sendmsg(sock, &msg); } EXPORT_SYMBOL_GPL(af_alg_sendpage);