From patchwork Fri May 26 14:31:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13256964 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 C28E5C7EE23 for ; Fri, 26 May 2023 14:31:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 43C086B0081; Fri, 26 May 2023 10:31:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 412556B0082; Fri, 26 May 2023 10:31:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2DB41900002; Fri, 26 May 2023 10:31:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 1F12D6B0081 for ; Fri, 26 May 2023 10:31:49 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 01F78AEC32 for ; Fri, 26 May 2023 14:31:48 +0000 (UTC) X-FDA: 80832645138.29.C30A80F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 3E88540034 for ; Fri, 26 May 2023 14:31:34 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bIbshqlD; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685111495; 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=dc/SuOpUlYqAq5ekNpSzLieNRD28aCzVtUAi8o3Unyg=; b=FSyOB5XnhAPSxh/VovgAZBZ2dxpE8KEdbUx0p2LpaQW+V8JaTd/SwqB0JxhVmcok/FTJGa k0BzNNJELCvmO2pgBjX4NO4Iz6hr2IjJoB2hqwgFy076CD2LyQy3XCeU+GkoplHh0gMD3b 1ZvSmKCoounQuUGvKGznH82ASp70vfk= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bIbshqlD; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685111495; a=rsa-sha256; cv=none; b=vKBfYIL2oaO3OkJ6JGmqFLgTit03wSF7d+2w1acEzkzTFn31JoywbRDFETXflxOdegvvt0 omR/yOePOWKRTUUTGSZyrKXOBAJt1kXrjNGCQu1otcHeuyTuDJKfgt+T/+RZuN6mebC+TJ Uw7vMnAEScIYmhwpgTz+TbqRkha3gWk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685111494; 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=dc/SuOpUlYqAq5ekNpSzLieNRD28aCzVtUAi8o3Unyg=; b=bIbshqlD48gMmLdHWEfV/vk04aQSk5ZvM+2I4p3lmJ317Af+eHQgXqCU9/IYIxSAhGzt4s EboLzTsuyfpVAym1OmrybRiWTirGrGp9Va/RT/nOCHLi9Etqxkl7NYakvlp8ZzswKh4/Wl zMb8IT77pDxAgZhq7yJti+9Qa2gg/L4= 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-570-ERCJ1r-zM0q7W6bBwBEpZg-1; Fri, 26 May 2023 10:31:31 -0400 X-MC-Unique: ERCJ1r-zM0q7W6bBwBEpZg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 576643855566; Fri, 26 May 2023 14:31:30 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 756352166B2B; Fri, 26 May 2023 14:31:28 +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 7/8] crypto: af_alg: Convert af_alg_sendpage() to use MSG_SPLICE_PAGES Date: Fri, 26 May 2023 15:31:03 +0100 Message-Id: <20230526143104.882842-8-dhowells@redhat.com> In-Reply-To: <20230526143104.882842-1-dhowells@redhat.com> References: <20230526143104.882842-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 3E88540034 X-Stat-Signature: bphumatmqpqqcf6rz797cm7akghharka X-Rspam-User: X-HE-Tag: 1685111494-567523 X-HE-Meta: U2FsdGVkX19m++RFkHpsWZ1DXzUIATOBQ/9S7sivRw9GkfB+MwnkmLPCpIuUoS3W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nF6Y+6t754v0ThwUARTHglZqzupo2/43be0gfJwIj3P79vvKznh2nLCYnYEjQrS3fcXGj0ZvjWgMHWxLX4KQiqpcYEGlkrBoCqOX8uvQMFxR1L6j083JxwOQ/nasdcYGUsVv1EXapPastUsf4OBRk7sjU/smychDcjbHmWujKCILTfSL4xGdTEiJA+EYAXyB/CZQV/SK48VSw+aD+LjG9QQTZNYmkSY/BdOS6Y4AOSJt504ViCeuKigXbD5gxdhnNlNZiFun3Xi6RfJzWKQvzX6VYskwjN3RKXzPUhWq/t6cvaHzGTVIsbS8pRXV4wYo5PGNHcdMBEXshCd/A7hhEJg9GkssZ0BOQ+hW49uYfLLFMPdsPIBoFrk/PIAFNsdxQt272rLB+xZwvpxvCdX8= 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 979033600185..105afd77a064 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c @@ -1117,53 +1117,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);