Message ID | 167391058954.2311931.2012230616335750882.stgit@warthog.procyon.org.uk |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1450699wrn; Mon, 16 Jan 2023 15:21:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXubySp5x6EbWR2vxyWWjc1V6ay6RNhZFP6ai/lFr06quoAOAkZ9tUvQenzsM2EVrZKO1g6Q X-Received: by 2002:a17:907:80cd:b0:7c1:3472:5e75 with SMTP id io13-20020a17090780cd00b007c134725e75mr887930ejc.29.1673911309397; Mon, 16 Jan 2023 15:21:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673911309; cv=none; d=google.com; s=arc-20160816; b=DM835tQ4aBknpjRj6KmxH4PnV5p0IGN734Ths8bjKgfYdHSM/NfexB9FWUB8h62oL/ T2fAwr5Z25c+MHt+3C43RWBUUcE1o0sQCutSkviK77cNywvR1TNXgvEIGDk2WMkOCcgz bzkuiK7HTauoUTsuElMYh/C+eXY5FXR5pgabBWRSJXYZzIf7+nekYtafhjQ7XyhapOMV pOG1Fa07kMh9EUKIlqv1GVRF72HWunu3WKd6TZ6TKtKyC0lrVv+1fgDs0WElwUTTdQ1g G0bxiAnARFwy26V+QlH41BAkv3s6BH7p7oIRR1NAzVOYP1SKgl0t9X2uEg386vOU6ur9 OxKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:dkim-signature; bh=kKmnjesqbVcK16NFYaezZHmG2fXFwkY2y+msB04GC+4=; b=FWowu1JJJIR/JEHUBpa8YkSXm+X4xIAsEuwfnfmVlMusdLOTXpwbBkBw25TixzwA9l nKGgUEgc1njNhgBBLDxTt6AacbMlUmIRurtyOZtYz8ygrwcaug9pNUOlK1++3YtL2R21 ugWGB/rp93M8xsCdUPKKF1ewSq8LhsjbxV1VAkSfVSmfPE1V+qCqNbk7601UDtYbTxMP +EEmlqjC0u5hPU9QA4R7mdMd62Ycc5p5khC+K6Q9hJ5bxtTXh3BRoe70Q3eL0frkx4M8 gJHSYDrh1+9C47FmsmB2EXfcv0tQ5jptAnF/iJZEV9WE/8R/kakYl37MAWY8toNtb7+A 9zGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=X5pJx92R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga42-20020a1709070c2a00b007ae2b7df929si33046639ejc.72.2023.01.16.15.21.24; Mon, 16 Jan 2023 15:21:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=X5pJx92R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232782AbjAPXNM (ORCPT <rfc822;stefanalexe802@gmail.com> + 99 others); Mon, 16 Jan 2023 18:13:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235370AbjAPXM2 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 16 Jan 2023 18:12:28 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F3032B61A for <linux-kernel@vger.kernel.org>; Mon, 16 Jan 2023 15:09:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673910597; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kKmnjesqbVcK16NFYaezZHmG2fXFwkY2y+msB04GC+4=; b=X5pJx92RUSqw7kr5bZAYndiyfuO1A1PwqxrwqJlvSAvM9JfFNDvICYXbrFYlpB/r4IiYs/ BkdRWiUNOmhMD04HZoenxdE2n7Zbgrh5At2nrbEW80VUcCUGiUv2V13/4ImhO3bHNHJFvm sFrYo/4UXb5UFbnIBmSg55rW+2hrKoo= 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-523-Dg-7CkFxNXKEqeYPM6L_Fg-1; Mon, 16 Jan 2023 18:09:52 -0500 X-MC-Unique: Dg-7CkFxNXKEqeYPM6L_Fg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7ADA62A59560; Mon, 16 Jan 2023 23:09:51 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 181692026D4B; Mon, 16 Jan 2023 23:09:50 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH v6 15/34] af_alg: Pin pages rather than ref'ing if appropriate From: David Howells <dhowells@redhat.com> To: Al Viro <viro@zeniv.linux.org.uk> Cc: Herbert Xu <herbert@gondor.apana.org.au>, linux-crypto@vger.kernel.org, dhowells@redhat.com, Christoph Hellwig <hch@infradead.org>, Matthew Wilcox <willy@infradead.org>, Jens Axboe <axboe@kernel.dk>, Jan Kara <jack@suse.cz>, Jeff Layton <jlayton@kernel.org>, Logan Gunthorpe <logang@deltatee.com>, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 16 Jan 2023 23:09:49 +0000 Message-ID: <167391058954.2311931.2012230616335750882.stgit@warthog.procyon.org.uk> In-Reply-To: <167391047703.2311931.8115712773222260073.stgit@warthog.procyon.org.uk> References: <167391047703.2311931.8115712773222260073.stgit@warthog.procyon.org.uk> User-Agent: StGit/1.5 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755223225134159554?= X-GMAIL-MSGID: =?utf-8?q?1755223225134159554?= |
Series |
iov_iter: Improve page extraction (ref, pin or just list)
|
|
Commit Message
David Howells
Jan. 16, 2023, 11:09 p.m. UTC
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 | 9 ++++++---
include/crypto/if_alg.h | 1 +
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/crypto/af_alg.c b/crypto/af_alg.c index 7a68db157fae..c99e09fce71f 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c @@ -534,15 +534,18 @@ static const struct net_proto_family alg_family = { int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len, unsigned int gup_flags) { + struct page **pages = sgl->pages; size_t off; ssize_t n; int npages, i; - n = iov_iter_get_pages(iter, sgl->pages, len, ALG_MAX_PAGES, &off, - gup_flags); + n = iov_iter_extract_pages(iter, &pages, len, ALG_MAX_PAGES, + gup_flags, &off); if (n < 0) return n; + sgl->cleanup_mode = iov_iter_extract_mode(iter, gup_flags); + npages = DIV_ROUND_UP(off + n, PAGE_SIZE); if (WARN_ON(npages == 0)) return -EINVAL; @@ -576,7 +579,7 @@ void af_alg_free_sg(struct af_alg_sgl *sgl) int i; for (i = 0; i < sgl->npages; i++) - put_page(sgl->pages[i]); + page_put_unpin(sgl->pages[i], sgl->cleanup_mode); } EXPORT_SYMBOL_GPL(af_alg_free_sg); diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h index 12058ab6cad9..95b3b7517d3f 100644 --- a/include/crypto/if_alg.h +++ b/include/crypto/if_alg.h @@ -61,6 +61,7 @@ struct af_alg_sgl { struct scatterlist sg[ALG_MAX_PAGES + 1]; struct page *pages[ALG_MAX_PAGES]; unsigned int npages; + unsigned int cleanup_mode; }; /* TX SGL entry */