From patchwork Tue May 30 14:16:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13260173 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 C1EAAC7EE2C for ; Tue, 30 May 2023 14:17:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C5256B007D; Tue, 30 May 2023 10:17:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 128C1280004; Tue, 30 May 2023 10:17:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D5C496B0080; Tue, 30 May 2023 10:17:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C20896B007D for ; Tue, 30 May 2023 10:17:53 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7F6361A0224 for ; Tue, 30 May 2023 14:17:53 +0000 (UTC) X-FDA: 80847125226.02.D3BE17B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf27.hostedemail.com (Postfix) with ESMTP id AD77F4001D for ; Tue, 30 May 2023 14:17:51 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="MnXe2/o8"; spf=pass (imf27.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1685456271; a=rsa-sha256; cv=none; b=eZ5SlJtZZQMxfTdmyARIXXXLHz8qkwuyJWZS9rzJpVcN9MTxXprcpy3ft8LmeQLaA7Wikh B6c6YUqiToPX68P1crVP9ajxDv6XI2POeo1eNlEaEjiaMgc4VIH66/vO0MWtBrIAJrRw1S pzbfL2Cw/dzdSXijfvWThJM7felramg= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="MnXe2/o8"; spf=pass (imf27.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1685456271; 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=MjSSqX/syLjzwTkjbRl9f0Ha+hyqgimWwPgJCeougMc=; b=0XNf5uasf90S7cgIfdwRqPC2FEX4/kjULn9y/v2odPwNRQa1Cw1qRnT5/w67uHy7eZ3xsT NdyHf3Tv5GlaMafyEbTq2K9Y/iLoW2m73bfi1Xa3euVW7vbKRlKF8MKtmZj8gsRrv6K+91 VIi+DIit3NURlYEKQLYJ2U18ybXjvjg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685456270; 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=MjSSqX/syLjzwTkjbRl9f0Ha+hyqgimWwPgJCeougMc=; b=MnXe2/o86glsA54L7vCadvYqG9V5k5CeDbOEqMmRzg87M0eVXvvL/g2cfnOOYUvnsHY29Y O7EUHRRtCnj9p+6wnluvF0QeRCa/tH4UN3JRIYRzact/HP7XO1cPLqnmOvuzjyEqWI4Kfg hWpoT+f9FSz0fNnGWr4O/vjXndW3tZQ= 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-591-tTDWSCdgPwaguFY00P7trQ-1; Tue, 30 May 2023 10:17:47 -0400 X-MC-Unique: tTDWSCdgPwaguFY00P7trQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8744D280BC43; Tue, 30 May 2023 14:17:46 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 576C8112132C; Tue, 30 May 2023 14:17:43 +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 v2 09/10] crypto: af_alg: Convert af_alg_sendpage() to use MSG_SPLICE_PAGES Date: Tue, 30 May 2023 15:16:33 +0100 Message-ID: <20230530141635.136968-10-dhowells@redhat.com> In-Reply-To: <20230530141635.136968-1-dhowells@redhat.com> References: <20230530141635.136968-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: AD77F4001D X-Stat-Signature: gxchim4b4p1j9kk4ety7f9etkfpezef5 X-Rspam-User: X-HE-Tag: 1685456271-589693 X-HE-Meta: U2FsdGVkX1+OrXAPJxK2yngDY5dLfhA5AhNEaeMXkPKz6MhLz9tkGBvO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q877BQ+Z/Ysq4oNNJgWyQz1zY/VvzAPDqqqTOZE8SRWugK73RkzIZwbyCr0N3O1IwlfVTh5nZeHZlLOyguOmZv7Twhm5iAUZTWM80EzyXH+cb+11Tgv37Be52hzp42aV2OfRUleGcueu0B3hbk+LMwBpxjKneNhbuEKsGMRZvu/GHSmioQp2xJHHXFuxKQqQJ0MeYRJYckOlLt5cRQ7rFVoI9esw8ieWYLKb2+f8Qcl6E0gzBPVo2x0lQMd9sq1i9f3MAsevsTegNV9rZeETtUDLpkca6fW3GUWM84bPnqpVqTHPaTSv4KsR+EAL0sfl+g1KhmDEpML9STGIp+VB5fsYbG0/GSLJxxYE9245e5X0Bp+ZKm1frf1+ZweunZQgqexEHjKyFDhQahuJHTGjPpo= 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. 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 62f4205d42e3..e2fc9051ba39 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c @@ -1118,53 +1118,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);