Message ID | 20230331160914.1608208-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 D0EE0C761A6 for <linux-mm@archiver.kernel.org>; Fri, 31 Mar 2023 16:10:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E6C86B009E; Fri, 31 Mar 2023 12:10:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 997506B009F; Fri, 31 Mar 2023 12:10:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 838166B00A0; Fri, 31 Mar 2023 12:10:29 -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 708946B009E for <linux-mm@kvack.org>; Fri, 31 Mar 2023 12:10:29 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EEA60120DE7 for <linux-mm@kvack.org>; Fri, 31 Mar 2023 16:10:27 +0000 (UTC) X-FDA: 80629680894.14.DFF07AA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 0CCFEC001F for <linux-mm@kvack.org>; Fri, 31 Mar 2023 16:10:25 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=anD6L70s; spf=pass (imf22.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=1680279026; 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=jPGukvQXP4Tai7PUqcbnIswr++Y11hB7rT1QDpn/afo=; b=4c10YoFbObNYUB6yameqQvQ4WDg0NPQ4gFlKpeJAjDnpxP7ifxDZEQGmAfZAVuw6ZWqDlT Id7DJGuAucuIQJM9CU3dPzpLk8l0KT2Iq/ib6THNsUeLO+d49qMKidVAGfjKXAihl+Fboq 4OeBS+6oGc6tRk55S5A+wVNqtczn6XI= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=anD6L70s; spf=pass (imf22.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=1680279026; a=rsa-sha256; cv=none; b=i1IQqtckz3ZIa6PdDpgdgr8WdyU+vHWayapD9zjiTV8NdcNz+ImXZFqzyc3lXPv4DLG5qg VG2Ef+XQqlbRwqV/f9RJd1n/0IidYpSUmZR1eVHOBSnTNfszyzsyCq5x8/VUToVRPbMpAT 83tp2lL9mPdpwkVsWJIW2PBjmfgb5vw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680279025; 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=jPGukvQXP4Tai7PUqcbnIswr++Y11hB7rT1QDpn/afo=; b=anD6L70sne4EL7ZtHVNQ17VAFjA1ywyRnHFq487kMqxtCrl1QXX7yW1TsWV6q9bHlSTOrn wTUKBBGDlc5rcvR49aiEkIuA+R49XnCaFpCKSqr/e2DAK6xfbtaX0BiLnLnSDtN2/eo6ua +FM8mzQg6HTFBpfJQBXzJ0hti1qd+Wo= 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-570-w91nJgUEPQ-xufIcE0rgFg-1; Fri, 31 Mar 2023 12:10:23 -0400 X-MC-Unique: w91nJgUEPQ-xufIcE0rgFg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CC107886063; Fri, 31 Mar 2023 16:10:19 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id B7DEB14171B6; Fri, 31 Mar 2023 16:10:17 +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: [PATCH v3 21/55] crypto: af_alg: Pin pages rather than ref'ing if appropriate Date: Fri, 31 Mar 2023 17:08:40 +0100 Message-Id: <20230331160914.1608208-22-dhowells@redhat.com> In-Reply-To: <20230331160914.1608208-1-dhowells@redhat.com> References: <20230331160914.1608208-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Stat-Signature: axziuiybrbcjuunthugkccghmmswdbx4 X-Rspam-User: X-Rspamd-Queue-Id: 0CCFEC001F X-Rspamd-Server: rspam06 X-HE-Tag: 1680279025-47605 X-HE-Meta: U2FsdGVkX1/edr9uwgpI8QIywr/IwNQVe/UefQa6j5e6Yb0mUnV5Zu+aiI2jHRwUyLQw2C+S9iFPmkTu7MDHreXBm6F8u/pGFX9P/DJZl40CspnBOhlCPKvxS5xvJ2O5X2upVdeRUESBoPg5HRyDz1TKEw+bIFvrhcWuE7WzCpdJ23Jmjd6rGktK+e+P0/RCotk6Oe5rLAIZLtcNwEVSj/Xs9T1psFtrtDR6qTgONcK5AY2neUatjCwHof/qDg3rwnx5VBlPNAT+wTrI2lHYrv9HRpgPtH5spn5C8NMxKj9XtQ2Us/GS+ZLF6TsCmjD6G3zAguh15XDhzC2pzhJ/25H/eZnlQGWQtwL6WCBIRv3EXCmhut4sKTkB+DxxHIfCPoektGSWiErxq/2m6uCcxGD8bRkL2PvFshGh94oPZ7co+vb2GANdUGYmu8QRxGbSxJlQ37NqIkV36LrulDG/vxgf5k6MQnfyUBaDKL1XD0lhhaORthLiHPVtUFSnsQNmk/KcyBdrQvxBh5kPkud+rsfmY4QBxMxeDAAAqbwvJ08iI4rPXM8Oul2I093irb/+EFU+wcP1c/JiGAG35+N5Kb7GtFqiimz+7dz+IHpZSVVTsyHM/rcFDPO6erZI1duu/vnxgM088ExxoN3OPJQKOQmH8sTccEgFWBHTQ2+k7+5w0Y4ZEbekkfB1OMI9bzuOn10r9OzDsedChr7TiLcUZGnORAArubNn33yfNRs6JaVgQdR1rd224H49VgpNprGt15lRZJOWaspg3D/PYyDTtIXcg7xzJrk5nLBbrDiN0VjbhNWnAmauXPzWSA8ePpw/ApgyoSn/LZbEKbvYgTGf88iY4v4RDLfygw5wMGItqX3C6FR/kY9OAzcDizfUCm/LcQ/yzNmcE/1vf7lm8OScdFf5PT44YIb+j7qF+HH3M7kFDLN4RUuvVDZ54TbCqj9NvTS9MGRzLEtP1jYobTG lB0E3zdm AEfxfCFf8ull2QhpfCNLuZn6BHb0vh0Kd2C0DIn4p4YGvgX58PJU9ZYAYXA6oygL4RLqHymx/Om6zaLOFf307IRNBsQY7UEOFzC9BXBj0XB+PNRtyRfr+3QZKxXaVpEm/AKbn3CbqgtGzZ6VsjNZSWa+ATJik8q8FglHZ7nM1kb7ipbeZ6lJhEPMO8+wBZja0xFh4duHQYY+BKE3KVGvOIUfHZpLRxjNZaeRGYT9C3VDvzhoccn6UQSjf9SU1i9N7nBoDms2e/IlMf/q4OfM44IDEIU3ns97R0m5Kj7TIYZ257K2uXx3URv4j+yoXKog6cUFPbj+EuCpOwmb6SgFrtumCz/e1jYNHX3vqIBX/ZLz/z2C6halgaH+FzXDE0peVSfDnt5Xw9p0CTO/g8awEeeXmicJ+XFLUA7I90aUS9/IHOFxCOhAWNDOH9pORObm3gDqLyPmX28vNp7qqrbBvG8T2wAGCi4bG0jIDYeMv+SfEIy0y8de3nYueOw== 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: "David S. Miller" <davem@davemloft.net> cc: Eric Dumazet <edumazet@google.com> cc: Jakub Kicinski <kuba@kernel.org> cc: Paolo Abeni <pabeni@redhat.com> cc: Jens Axboe <axboe@kernel.dk> cc: Matthew Wilcox <willy@infradead.org> cc: linux-crypto@vger.kernel.org cc: netdev@vger.kernel.org --- crypto/af_alg.c | 10 +++++++--- include/crypto/if_alg.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-)