From patchwork Fri May 26 14:30:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13256959 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 B8090C7EE2E for ; Fri, 26 May 2023 14:31:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EEA8C6B0078; Fri, 26 May 2023 10:31:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E27246B007B; Fri, 26 May 2023 10:31:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C50B5900002; Fri, 26 May 2023 10:31:29 -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 B4C836B0078 for ; Fri, 26 May 2023 10:31:29 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1772A80ED7 for ; Fri, 26 May 2023 14:31:28 +0000 (UTC) X-FDA: 80832644298.17.FF66392 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf21.hostedemail.com (Postfix) with ESMTP id AB6191C0018 for ; Fri, 26 May 2023 14:31:26 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Nlk7HVaS; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1685111486; 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=MH5xcseSRT0N9WZzXiPsIlJzafJZHEMG8tIivW/OY1jr80o6UmWgwnrT/YXNSfLSIGNBwM VY7ngHJM9ycfu7PmQVm982mSVWDBkuoLEgjSaKPgs6dtS2s7w4IMbxFSdmVl2RV9Q3WBAv NjKBa9oqRcRCxl48UaUP9qK5T2tHYkQ= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Nlk7HVaS; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685111486; a=rsa-sha256; cv=none; b=ryc6IwyHrXF6EBAEAguyfQ90YU3dOdP9n5LpOgi7iZl2P2HNFq+VrA9bQAFY07m8mph2Sc 66beyzQ37vfM6SkhKu9GYNtnoW5k69JmkWifqmfq8MFGV+XiQIjstm0Q1HvpUNL+/92wPM 4/8QD15p0H62kmiG0wopbuvTmuvp36Q= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685111485; 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=Nlk7HVaS7Ojsw59gG+Indrde5s5LkTPXDUgDBSXV+KeuDwDEfDnrDpYbjjMETU/8Jl7znT oylTY9Kj3m8X8yKH3mGHL6jlpZkSei8ad9xBNuSzCXdDJVdGPCf78mJV7Oau2s7FWRdTrM SVzzwuSr0yKnyWEjEJa1RtS+zpBmjks= 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-29-Ivy8e833NRWSYrtoVTgS-g-1; Fri, 26 May 2023 10:31:21 -0400 X-MC-Unique: Ivy8e833NRWSYrtoVTgS-g-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 8A6DD811E92; Fri, 26 May 2023 14:31:19 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id A4D0C140E961; Fri, 26 May 2023 14:31:17 +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 3/8] crypto: af_alg: Pin pages rather than ref'ing if appropriate Date: Fri, 26 May 2023 15:30:59 +0100 Message-Id: <20230526143104.882842-4-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.7 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: AB6191C0018 X-Stat-Signature: 3ro6dduzgi16w4515wmfibt53bo3ambx X-Rspam-User: X-HE-Tag: 1685111486-654245 X-HE-Meta: U2FsdGVkX1/2R9XBUXtUX5wWLRVpmWq2Ld5/4cKJsN99puRkP3Gpj9RI+4Nf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y83MjpD2WDVv3Nj5oniWCKxNbv8/LT/RJNwOlYwaCp13m3tk81C7dQylWc045QB8P0COlsFpBmbFlofyPs5JATQU1gHD8Q/IHivUpqayFax+CYA+t7YYdHP9OvWsB6eresW9YCctsNrFVQEylx+YEYq7+hcW/fxbpXI88CYjY/S7dMr1NuKmmnba5IJHJdVthZ+qA0MDd/7xGV2K1+HdVNr8dpmcYBxUj7aGl+zaGE0Gc0GxggvMMVzZHMwyw1yF8UswZupw1jpOnCgYRQGEAYR0tdkv9cM7Uc44ssIVL+TSE7j00YVmNpUpA5PbOwrCMBg7ei0EmmrBlIVojSBLk7dmDUzrALP2RIJb+W5qwf0CHwPMrh3/KOqqSNdcORrEMKvNazACKZ13bZsXKwCkqRq5iVxUoYQc= 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 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 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 | 10 +++++++--- include/crypto/if_alg.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) 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 */