From patchwork Fri Dec 2 09:43:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13062495 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 BD0D1C4332F for ; Fri, 2 Dec 2022 09:43:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB7076B0071; Fri, 2 Dec 2022 04:43:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C66B76B0074; Fri, 2 Dec 2022 04:43:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B55DE6B0075; Fri, 2 Dec 2022 04:43:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A73736B0071 for ; Fri, 2 Dec 2022 04:43:27 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6A86C160351 for ; Fri, 2 Dec 2022 09:43:27 +0000 (UTC) X-FDA: 80196878454.19.DA1778D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf20.hostedemail.com (Postfix) with ESMTP id B98CC1C000D for ; Fri, 2 Dec 2022 09:43:24 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RsX4IsUJ; spf=pass (imf20.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=1669974206; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=JPL3HeqWrrSKDJIfWXlo82sdG8gZ+m15F8/peAepuFE=; b=CL2LI8pxCMgrHZqk7r4L/hIZk7SkO6H9cBLlXVFjtOk9fxdnpFaAM0uODt0olnOHCUR7d9 oeaST6WzsDlDzOeCYZ4idFcFD5gySbavkGI2c0Oopqym92C8BeZ7KEwUdV84jhf8+EjHxO 5i2X7vmQvMYz+oolB/uJVvH4K9bMD/o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669974206; a=rsa-sha256; cv=none; b=I6yyJXkQSeoVqiJEczCxowXMsUzrpH1fa1Ou3rjDUggu129AkqOdCWjmM694tLpT3M/sQ+ Nbv9cpWdImAVNpTZR8K67b6tA5IAlWqyQQRPgkfkasw9Q+m7kCUZFmfEqKp6ibx50JIw8C SufO5Y0saLWq81EXzGCssZxUNIfEpM0= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RsX4IsUJ; spf=pass (imf20.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669974204; 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; bh=JPL3HeqWrrSKDJIfWXlo82sdG8gZ+m15F8/peAepuFE=; b=RsX4IsUJSTjkd+4IMPIEgXnEpUEyAmkFEp4TmhNXLBn+zjQMwA+rI/vTPNChEPWtY3zbFz gk1vJZVrfBz4zHVwE9MhTexnqnHoU7hIqGHRcePMw7Sd0CVMfl9Cot+V8E35snrN0aZPso cTnmBQ3xvjrIgg+bTIhDBOrfVzMsSt8= 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-348-6efNmvdpPW2mpW2TiorUrg-1; Fri, 02 Dec 2022 04:43:22 -0500 X-MC-Unique: 6efNmvdpPW2mpW2TiorUrg-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 0DD0338173CB; Fri, 2 Dec 2022 09:43:22 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A55E2028E96; Fri, 2 Dec 2022 09:43:19 +0000 (UTC) Subject: [PATCH v3 0/4] iov_iter: Add extraction helpers From: David Howells To: Al Viro Cc: linux-fsdevel@vger.kernel.org, Shyam Prasad N , Christoph Hellwig , linux-cachefs@redhat.com, linux-cifs@vger.kernel.org, linux-mm@kvack.org, Steve French , Rohith Surabattula , Matthew Wilcox , John Hubbard , Jeff Layton , dhowells@redhat.com, Christoph Hellwig , Matthew Wilcox , Jeff Layton , Logan Gunthorpe , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 02 Dec 2022 09:43:16 +0000 Message-ID: <166997419665.9475.15014699817597102032.stgit@warthog.procyon.org.uk> User-Agent: StGit/1.5 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspam-User: X-Rspamd-Queue-Id: B98CC1C000D X-Stat-Signature: up5hssp66phufaicdsb61wdh8bdicqub X-Rspamd-Server: rspam01 X-Spamd-Result: default: False [-1.40 / 9.00]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; SUBJECT_HAS_UNDERSCORES(1.00)[]; DMARC_POLICY_ALLOW(-0.50)[redhat.com,none]; R_SPF_ALLOW(-0.20)[+ip4:170.10.133.0/24]; R_DKIM_ALLOW(-0.20)[redhat.com:s=mimecast20190719]; MIME_GOOD(-0.10)[text/plain]; RCVD_NO_TLS_LAST(0.10)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_TWELVE(0.00)[19]; FROM_EQ_ENVFROM(0.00)[]; DKIM_TRACE(0.00)[redhat.com:+]; RCVD_COUNT_THREE(0.00)[4]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_SOME(0.00)[]; TAGGED_RCPT(0.00)[]; ARC_NA(0.00)[] X-HE-Tag: 1669974204-480202 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: Hi Al, Here are four patches to provide support for extracting pages from an iov_iter, where such a thing makes sense, if you could take a look? [!] NOTE that I've switched the functions to be exported GPL-only at Christoph's request[1]. They are, however, intended as a replacement for iov_iter_get_pages*(), which is not marked _GPL - so that functionality will probably become unavailable to non-GPL 3rd party modules in future. The first couple of patches provide iov_iter general stuff: (1) Move the FOLL_* flags to linux/mm_types.h so that linux/uio.h can make use of them. (2) Add a function to list-only, get or pin pages from an iterator as a future replacement for iov_iter_get_pages*(). Pointers to the pages are placed into an array (which will get allocated if not provided) and, depending on the iterator type and direction, the pages will have a ref or a pin get on them, or left untouched (on the assumption that the caller manages their lifetime). The determination is: UBUF/IOVEC + READ -> pin UBUF/IOVEC + WRITE -> get PIPE + READ -> list-only BVEC/XARRAY -> list-only Anything else -> EFAULT The function also returns an indication of which of "list only, get or pin" the extraction function did to aid in cleaning up (returning 0, FOLL_GET or FOLL_PIN as appropriate). Then there are a couple of patches that add stuff to netfslib that I want to use there as well as in cifs: (3) Add a netfslib function to use (2) to extract pages from an ITER_IOBUF or ITER_UBUF iterator into an ITER_BVEC iterator. This will get or pin the pages as appropriate. (4) Add a netfslib function to extract pages from an iterator that's of type ITER_UBUF/IOVEC/BVEC/KVEC/XARRAY and add them to a scatterlist. The function in (2) is used for a UBUF and IOVEC iterators, so those need cleaning up afterwards. BVEC and XARRAY iterators are ungot and unpinned and may be rendered into elements that span multiple pages, for example if large folios are present. Changes: ======== ver #3) - Switch to using EXPORT_SYMBOL_GPL to prevent indirect 3rd-party access to get/pin_user_pages_fast()[1]. ver #2) - Rolled the extraction cleanup mode query function into the extraction function, returning the indication through the argument list. - Fixed patch 4 (extract to scatterlist) to actually use the new extraction API. I've pushed the patches here also: https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=iov-extract David Link: https://lore.kernel.org/r/Y3zFzdWnWlEJ8X8/@infradead.org/ [1] Link: https://lore.kernel.org/r/166697254399.61150.1256557652599252121.stgit@warthog.procyon.org.uk/ # rfc Link: https://lore.kernel.org/r/166722777223.2555743.162508599131141451.stgit@warthog.procyon.org.uk/ # rfc Link: https://lore.kernel.org/r/166732024173.3186319.18204305072070871546.stgit@warthog.procyon.org.uk/ # rfc Link: https://lore.kernel.org/r/166869687556.3723671.10061142538708346995.stgit@warthog.procyon.org.uk/ # rfc --- David Howells (4): mm: Move FOLL_* defs to mm_types.h iov_iter: Add a function to extract a page list from an iterator netfs: Add a function to extract a UBUF or IOVEC into a BVEC iterator netfs: Add a function to extract an iterator into a scatterlist fs/netfs/Makefile | 1 + fs/netfs/iterator.c | 367 +++++++++++++++++++++++++++++++++++++++ include/linux/mm.h | 74 -------- include/linux/mm_types.h | 73 ++++++++ include/linux/netfs.h | 7 + include/linux/uio.h | 4 + lib/iov_iter.c | 350 +++++++++++++++++++++++++++++++++++++ mm/vmalloc.c | 1 + 8 files changed, 803 insertions(+), 74 deletions(-) create mode 100644 fs/netfs/iterator.c