Message ID | 20230329141354.516864-22-dhowells@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 0046DC761AF for <linux-mm@archiver.kernel.org>; Wed, 29 Mar 2023 14:15:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C27C36B0096; Wed, 29 Mar 2023 10:15:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BD8126B0098; Wed, 29 Mar 2023 10:15:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2B006B0099; Wed, 29 Mar 2023 10:15:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 91D456B0096 for <linux-mm@kvack.org>; Wed, 29 Mar 2023 10:15:04 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2C0FB40CAB for <linux-mm@kvack.org>; Wed, 29 Mar 2023 14:15:04 +0000 (UTC) X-FDA: 80622132528.15.688E269 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id B08624002A for <linux-mm@kvack.org>; Wed, 29 Mar 2023 14:15:01 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LepUYK+k; spf=pass (imf12.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=1680099301; 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=yzXpQhTxTxrOyN4QfDXBN8fe/pZE0zPIgWzTS/9cMoE=; b=nVu5lVdll2ahtO6f2JdWrNnPmXiq0cNiX004z77IazzF4H0g1ru+jJCx6zTaMKV3Yj8ukC j/9mf8Z0xHeIKafKpdZC17WA6GL/YYXBB6wtNkAI4AWkdjLV8oEimSgzD1063Gr2OhtpK7 JJGSEq4sycJXmrpsjQn6Y9qwefPgMXs= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LepUYK+k; spf=pass (imf12.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=1680099301; a=rsa-sha256; cv=none; b=oE9y1WQcbk3uf7NVnuFMSjQbW1XSJYWQrUatIQucZEp+5WIXb8KCJgLzUuHHEvTin5T4gb D9I5EKHg+9iyGszViWI3wBp3OKzIRM1lDU6VWZhAd4ACLIWjIeI1R+wST2ZJmE7iXNOBgy 0Vy8keHEMjqRY9cx7s4zF8G7sQmtl7k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680099301; 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=yzXpQhTxTxrOyN4QfDXBN8fe/pZE0zPIgWzTS/9cMoE=; b=LepUYK+kPQDXpRhkKeiZRAWqf+5w3cbZsmcWeIiJJ2cqw3zaMYmbfI53q+bjS8baUB+LUk 17SNmNnBjc9AAUHnfju3fnJ2V5Z8mbJ31Ukc7DcKzlAlkrifMyrv5pm0ieBmoqJukW4YD9 JwrQr2pVW6Ra4ejJ8TXRvZBXwRQ5L6o= 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-445-ZVu3CVMuPAy5XfxUPzoW4A-1; Wed, 29 Mar 2023 10:14:58 -0400 X-MC-Unique: ZVu3CVMuPAy5XfxUPzoW4A-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 B9DA11C07588; Wed, 29 Mar 2023 14:14:56 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id A725B1121331; Wed, 29 Mar 2023 14:14:54 +0000 (UTC) From: David Howells <dhowells@redhat.com> To: Matthew Wilcox <willy@infradead.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com> Cc: David Howells <dhowells@redhat.com>, Al Viro <viro@zeniv.linux.org.uk>, Christoph Hellwig <hch@infradead.org>, Jens Axboe <axboe@kernel.dk>, Jeff Layton <jlayton@kernel.org>, Christian Brauner <brauner@kernel.org>, Chuck Lever III <chuck.lever@oracle.com>, Linus Torvalds <torvalds@linux-foundation.org>, netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Herbert Xu <herbert@gondor.apana.org.au>, linux-crypto@vger.kernel.org Subject: [RFC PATCH v2 21/48] crypto: af_alg: Pin pages rather than ref'ing if appropriate Date: Wed, 29 Mar 2023 15:13:27 +0100 Message-Id: <20230329141354.516864-22-dhowells@redhat.com> In-Reply-To: <20230329141354.516864-1-dhowells@redhat.com> References: <20230329141354.516864-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B08624002A X-Rspam-User: X-Stat-Signature: bghkcs3gcjjtz9r5mt1xpdjakuemizrd X-HE-Tag: 1680099301-905799 X-HE-Meta: U2FsdGVkX1/g3RvSsyuIYxIOBfgJ0HBKZCmUun2sDO/lgCHTvVpcoBHqPAtXjbgWrHEj33xTucee538A0qOGjaLBovVmlDCHEPaz88l9u+5M43UM+s5f0CCSqkds6oIbeM8D50NNe5o2OOmoXPq2kGoZk7nJZ4HizhkKVYSCBD0BBXeWKvQbtVKAR3RPkzHp1acmCLoFCyepZ5+Bpl0dqnYnWLBqcLlzg9LjzSXCdXnNq+ya5FXJMjmapgiSvIw57sZwydzIiFYS7GUiwkPoaMVcXcPhyPcv3ZACoMaP0r51JyZG7QCJsztKt1mV3BEuqe3K/pFJwpJE2Ie3voKhZuIhtLNSean4MNYGo3J7q6QAH9H4jlEF4mbohmYYsl1prdiL9Dn34Br4pOcfJ/eEFwhtb49TyhqegKHzZAalXJq30ctYfZ+U7oXL9a2u5qrgXgpEWAuzxN7dTpBssBGNC5xLfDhfmcklbZK/6ZxygIK/qmZ9kzxfMfIl6YTSahenpiYruDe3arQTkgVIwRauNkNhiQidQM7k1oJi6hFD6zrJHOija4RiRHgxmNAyOXYgcpoNMbICvAgTBKOJzPYH07WPPocw8KlIb2bOTtQQau3M9QsgJJXpGOo6bGo2l/uPjO+n/osb6NyHqqyd3/jTX0epeeCsBItn7Aokv3mt67cT24Cx0yJKg/oiFrwCIgXTGQw1FzewOHiEOti1rS8Bx/Ufhx9ewFeCF2rZDUriaDEklQsd0Sc+cH6u9/9VbQ2lfCMJr5xuuRBqxUqDfZp/DYojzyXjyEatu47r40hZUeXlVUQtC73sB/K+wtQm2QMhdDMiPzJDqa3NLXMw8eo8VEKvjOAPF292qYt+jMvlM/B7T8cFSOuH8HjHv7b2ORwsZNcncbBAzxRHcebmgWoySLvP9fqwTTgXU2sozLAzt0UURquJ7aVtmL1plSMrjljEalHRl0pcreTaiG6cHIA ZDEUfQri 5H1gd9lLTh140QYIagnPWlehLOI6azqRObAWFokSDaYxcczFYL02dKF+jZeZTsvJPPWU9TScnEMywlAQSWgHjE/3f3mywP4i5fOHgOsxMJLdxnH+kwKh6AHDfm97o2clJwACW446B2AX68z/ZcQsFbWX+ow7uobay97naG2mGdtRlDYe9EQzc/rqoQIRpt0imbY/5gjjOldg4HkN/lCCcK7skoXzuHwv9K8thGLUcE++rMFOIBeOLnH4ngV+UReuFpiVf+1rRXPfpRfV5L3XVMXZgsnFCiIK053BpET7h7JgiWQJ0nWdDhP41vhW1uJSKiXPy8vlQ4TYB3G/harXRYa+UxokNV0jIYmpeldE+pnIat/I= 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: <linux-mm.kvack.org> |
Series |
splice, net: Replace sendpage with sendmsg(MSG_SPLICE_PAGES)
|
expand
|
diff --git a/crypto/af_alg.c b/crypto/af_alg.c index 5f7252a5b7b4..7caff10df643 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c @@ -533,14 +533,17 @@ static const struct net_proto_family alg_family = { int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len) { + struct page **pages = sgl->pages; size_t off; ssize_t n; int npages, i; - n = iov_iter_get_pages2(iter, sgl->pages, len, ALG_MAX_PAGES, &off); + n = iov_iter_extract_pages(iter, &pages, len, ALG_MAX_PAGES, 0, &off); if (n < 0) return n; + sgl->need_unpin = iov_iter_extract_will_pin(iter); + npages = DIV_ROUND_UP(off + n, PAGE_SIZE); if (WARN_ON(npages == 0)) return -EINVAL; @@ -573,8 +576,9 @@ void af_alg_free_sg(struct af_alg_sgl *sgl) { int i; - for (i = 0; i < sgl->npages; i++) - put_page(sgl->pages[i]); + if (sgl->need_unpin) + for (i = 0; i < sgl->npages; i++) + unpin_user_page(sgl->pages[i]); } EXPORT_SYMBOL_GPL(af_alg_free_sg); diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h index 7e76623f9ec3..46494b33f5bc 100644 --- a/include/crypto/if_alg.h +++ b/include/crypto/if_alg.h @@ -59,6 +59,7 @@ struct af_alg_sgl { struct scatterlist sg[ALG_MAX_PAGES + 1]; struct page *pages[ALG_MAX_PAGES]; unsigned int npages; + bool need_unpin; }; /* TX SGL entry */
Convert AF_ALG to use iov_iter_extract_pages() instead of iov_iter_get_pages(). This will pin pages or leave them unaltered rather than getting a ref on them as appropriate to the iterator. The pages need to be pinned for DIO-read rather than having refs taken on them to prevent VM copy-on-write from malfunctioning during a concurrent fork() (the result of the I/O would otherwise end up only visible to the child process and not the parent). Signed-off-by: David Howells <dhowells@redhat.com> cc: Herbert Xu <herbert@gondor.apana.org.au> cc: linux-crypto@vger.kernel.org --- crypto/af_alg.c | 10 +++++++--- include/crypto/if_alg.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-)