From patchwork Wed Dec 21 21:24:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13079176 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 19243C4332F for ; Wed, 21 Dec 2022 21:25:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E9528E0002; Wed, 21 Dec 2022 16:25:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 399F48E0001; Wed, 21 Dec 2022 16:25:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 239858E0002; Wed, 21 Dec 2022 16:25:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 13B468E0001 for ; Wed, 21 Dec 2022 16:25:04 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B8EC21C6376 for ; Wed, 21 Dec 2022 21:25:03 +0000 (UTC) X-FDA: 80267593686.15.A24644C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id EB5F540006 for ; Wed, 21 Dec 2022 21:25:00 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YFQdS3WR; spf=pass (imf27.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=1671657901; 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=5wS/gm7GekOfIR+wCAs6z2JkNPYybqoFi4Z29S4Sns0=; b=8bRJqk3D8TEHqZUQD9L/qGbkRmhNfh8kbrv0yY6Rr7niuHmPLXBITvLJV7Z04KJn+O4a+J cvyNkpUl8G5LUrXyqFYO/Viwxm36PPyYo5wyyrDz/THkGesLKhOk68kkFUBTh9sy9q3gkl wJEyUZ6UAtPSNo6V0sXjQ15NTmPbFw0= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YFQdS3WR; spf=pass (imf27.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=1671657901; a=rsa-sha256; cv=none; b=f460dLK1h/LyM6Xx37SP2HsZR9HjSxtOPMM2ISB/Q1mXkodeofAdXh/Le3m4UnZovC4g+K nfHzSItjKEDwe2f9QgL8X+mwwWhJR1F9kHg5VCoVNNeisS1spZSnK4VdReM+xZFA94HmrA 0iB5jq/q+smizUdapxGbr/AiJYGQ98Y= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671657900; 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=5wS/gm7GekOfIR+wCAs6z2JkNPYybqoFi4Z29S4Sns0=; b=YFQdS3WR8pUluGXa9TsVu9xpu5AZIXnmWv6O6T0p5UFSpxYNxxzIPR60iD1dXJiXTu6LJY UBHGK2+Nxwrdhr3YIveJ3PDigdUi63Mm7i1owX4B8cy05bUamfoJaoZBA3BsqzAfCZLEYl JXxXLgQsoI1TYYA01+IcYO/jQ62Ls5Y= 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-648-tdaIpi-qN2WzZhb36U7Yjw-1; Wed, 21 Dec 2022 16:24:56 -0500 X-MC-Unique: tdaIpi-qN2WzZhb36U7Yjw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5E8E81C06ED7; Wed, 21 Dec 2022 21:24:56 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id E32A3C16029; Wed, 21 Dec 2022 21:24:54 +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 From: David Howells To: Andrew Morton cc: dhowells@redhat.com, Matthew Wilcox , John Hubbard , Christoph Hellwig , Jeff Layton , Logan Gunthorpe , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: Move FOLL_* defs to mm_types.h MIME-Version: 1.0 Content-ID: <2161257.1671657894.1@warthog.procyon.org.uk> Date: Wed, 21 Dec 2022 21:24:54 +0000 Message-ID: <2161258.1671657894@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: EB5F540006 X-Stat-Signature: jf6ensta6kih8669if61btbukewsi6en X-HE-Tag: 1671657900-18299 X-HE-Meta: U2FsdGVkX18aN2r8e02LQp1CF0ecxB61ZaxSpLefWWZnD25AWjhfGa5LN2Xf2ZBb3Dm7fUawvFaT3xw+nGnELk7soFvITa4Ftovnul6RvY5TcLwcn6wVZQd8HbnzFLLp4FPxfrakIyjTQgTdkF/Umet43nvYA71wdMw0+HBjRBBP4zpuFKZcFG4VY10A6Pz+ZZIMw60jy8iibQ81UIZTWzVdevkfWU9oQnwRjobzsNiqHYRq4OFbE9aSJjtzVZpS4pMTmXzROOH/l6g9rU0FPBRfb8lXNAaDwkMe5nPrPAmJDyKO7AeiygYJ/SyuoKJcq72SLf+TXPWy1+/Xl4BZ6ukLAyWld9D+6rI8oUynlv2H7bsQ3sjLqbiFbv2xPyx61iuc512lSW3TsKiN55Ess7+tXlfaE/phPAs64nZqCnc8rSy8up1xPyKFuComWYQdxq/U9+F+Cki00jMYZU99+NcV4K6I4sa5Pjn1G6Qpm0sPqBufmxfkKiygOt7M9/F/6ijcMnfsjxH61zk1NBH2tJ12OSG/mQMaKHJL+rJJrfPvMYVimOU6DuBeTP7a+4/9+4Z3/lhGGg8R2lc2HP5Ox7IN4U5xQFSdXfp3nmYh1milPkGWVBbvfmeBt5kUqoFZ4rvaxRvd3yRe2bDwCAwPeTAW9Nv1YOSSZfXDX7KoHCK7pOgZJ7SGA+RZ1ARYl444wYfBFeNjxVAHgIstU9I7Dqb0+/KK9QXFuem9rCFUC+VAk8Rwx1M0CEGF/MJhMnpJ3qCJr4I7A246xRT7PR1+D+ZURak96W5EvL9P8S2TA+itU7bUgL/Qw33xcFtA5+lw5lOcnxVVB510Xv4WUyEJCdf6hunBYp8zKhykv1pLAKSzN9WgKaXF/HaUQCsXgGNaibgauSwqzsFTyCs+khGe+28NsXkVeMfpoLQI3bibazs= 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 Andrew, Is it too late to ask you to add this to the current merge window? It just moves the FOLL_* flags between headers, flipping the order of the banner comment and the defs. It did have the following attributions: Reviewed-by: John Hubbard Reviewed-by: Christoph Hellwig but the FOLL_* flagset got altered during the merge window, so I redid the patch. Thanks, David Reviewed-by: John Hubbard --- mm: Move FOLL_* defs to mm_types.h Move FOLL_* definitions to linux/mm_types.h to make them more accessible without having to drag in all of linux/mm.h and everything that drags in too[1]. Suggested-by: Matthew Wilcox Signed-off-by: David Howells cc: John Hubbard cc: Christoph Hellwig cc: Matthew Wilcox cc: Al Viro cc: linux-mm@kvack.org cc: linux-fsdevel@vger.kernel.org Link: https://lore.kernel.org/linux-fsdevel/Y1%2FhSO+7kAJhGShG@casper.infradead.org/ [1] Link: https://lore.kernel.org/r/166732025009.3186319.3402781784409891214.stgit@warthog.procyon.org.uk/ # rfc Link: https://lore.kernel.org/r/166869688542.3723671.10243929000823258622.stgit@warthog.procyon.org.uk/ # rfc Link: https://lore.kernel.org/r/166920902968.1461876.15991975556984309489.stgit@warthog.procyon.org.uk/ # v2 Link: https://lore.kernel.org/r/166997420723.9475.3907844523056304049.stgit@warthog.procyon.org.uk/ # v3 --- include/linux/mm.h | 75 ----------------------------------------------- include/linux/mm_types.h | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 75 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index f3f196e4d66d..be5edc0770ea 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3071,81 +3071,6 @@ static inline vm_fault_t vmf_error(int err) struct page *follow_page(struct vm_area_struct *vma, unsigned long address, unsigned int foll_flags); -#define FOLL_WRITE 0x01 /* check pte is writable */ -#define FOLL_TOUCH 0x02 /* mark page accessed */ -#define FOLL_GET 0x04 /* do get_page on page */ -#define FOLL_DUMP 0x08 /* give error on hole if it would be zero */ -#define FOLL_FORCE 0x10 /* get_user_pages read/write w/o permission */ -#define FOLL_NOWAIT 0x20 /* if a disk transfer is needed, start the IO - * and return without waiting upon it */ -#define FOLL_NOFAULT 0x80 /* do not fault in pages */ -#define FOLL_HWPOISON 0x100 /* check page is hwpoisoned */ -#define FOLL_TRIED 0x800 /* a retry, previous pass started an IO */ -#define FOLL_REMOTE 0x2000 /* we are working on non-current tsk/mm */ -#define FOLL_ANON 0x8000 /* don't do file mappings */ -#define FOLL_LONGTERM 0x10000 /* mapping lifetime is indefinite: see below */ -#define FOLL_SPLIT_PMD 0x20000 /* split huge pmd before returning */ -#define FOLL_PIN 0x40000 /* pages must be released via unpin_user_page */ -#define FOLL_FAST_ONLY 0x80000 /* gup_fast: prevent fall-back to slow gup */ -#define FOLL_PCI_P2PDMA 0x100000 /* allow returning PCI P2PDMA pages */ -#define FOLL_INTERRUPTIBLE 0x200000 /* allow interrupts from generic signals */ - -/* - * FOLL_PIN and FOLL_LONGTERM may be used in various combinations with each - * other. Here is what they mean, and how to use them: - * - * FOLL_LONGTERM indicates that the page will be held for an indefinite time - * period _often_ under userspace control. This is in contrast to - * iov_iter_get_pages(), whose usages are transient. - * - * FIXME: For pages which are part of a filesystem, mappings are subject to the - * lifetime enforced by the filesystem and we need guarantees that longterm - * users like RDMA and V4L2 only establish mappings which coordinate usage with - * the filesystem. Ideas for this coordination include revoking the longterm - * pin, delaying writeback, bounce buffer page writeback, etc. As FS DAX was - * added after the problem with filesystems was found FS DAX VMAs are - * specifically failed. Filesystem pages are still subject to bugs and use of - * FOLL_LONGTERM should be avoided on those pages. - * - * FIXME: Also NOTE that FOLL_LONGTERM is not supported in every GUP call. - * Currently only get_user_pages() and get_user_pages_fast() support this flag - * and calls to get_user_pages_[un]locked are specifically not allowed. This - * is due to an incompatibility with the FS DAX check and - * FAULT_FLAG_ALLOW_RETRY. - * - * In the CMA case: long term pins in a CMA region would unnecessarily fragment - * that region. And so, CMA attempts to migrate the page before pinning, when - * FOLL_LONGTERM is specified. - * - * FOLL_PIN indicates that a special kind of tracking (not just page->_refcount, - * but an additional pin counting system) will be invoked. This is intended for - * anything that gets a page reference and then touches page data (for example, - * Direct IO). This lets the filesystem know that some non-file-system entity is - * potentially changing the pages' data. In contrast to FOLL_GET (whose pages - * are released via put_page()), FOLL_PIN pages must be released, ultimately, by - * a call to unpin_user_page(). - * - * FOLL_PIN is similar to FOLL_GET: both of these pin pages. They use different - * and separate refcounting mechanisms, however, and that means that each has - * its own acquire and release mechanisms: - * - * FOLL_GET: get_user_pages*() to acquire, and put_page() to release. - * - * FOLL_PIN: pin_user_pages*() to acquire, and unpin_user_pages to release. - * - * FOLL_PIN and FOLL_GET are mutually exclusive for a given function call. - * (The underlying pages may experience both FOLL_GET-based and FOLL_PIN-based - * calls applied to them, and that's perfectly OK. This is a constraint on the - * callers, not on the pages.) - * - * FOLL_PIN should be set internally by the pin_user_pages*() APIs, never - * directly by the caller. That's in order to help avoid mismatches when - * releasing pages: get_user_pages*() pages must be released via put_page(), - * while pin_user_pages*() pages must be released via unpin_user_page(). - * - * Please see Documentation/core-api/pin_user_pages.rst for more information. - */ - static inline int vm_fault_to_errno(vm_fault_t vm_fault, int foll_flags) { if (vm_fault & VM_FAULT_OOM) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 3b8475007734..4e1031626403 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -1085,4 +1085,79 @@ enum fault_flag { typedef unsigned int __bitwise zap_flags_t; +/* + * FOLL_PIN and FOLL_LONGTERM may be used in various combinations with each + * other. Here is what they mean, and how to use them: + * + * FOLL_LONGTERM indicates that the page will be held for an indefinite time + * period _often_ under userspace control. This is in contrast to + * iov_iter_get_pages(), whose usages are transient. + * + * FIXME: For pages which are part of a filesystem, mappings are subject to the + * lifetime enforced by the filesystem and we need guarantees that longterm + * users like RDMA and V4L2 only establish mappings which coordinate usage with + * the filesystem. Ideas for this coordination include revoking the longterm + * pin, delaying writeback, bounce buffer page writeback, etc. As FS DAX was + * added after the problem with filesystems was found FS DAX VMAs are + * specifically failed. Filesystem pages are still subject to bugs and use of + * FOLL_LONGTERM should be avoided on those pages. + * + * FIXME: Also NOTE that FOLL_LONGTERM is not supported in every GUP call. + * Currently only get_user_pages() and get_user_pages_fast() support this flag + * and calls to get_user_pages_[un]locked are specifically not allowed. This + * is due to an incompatibility with the FS DAX check and + * FAULT_FLAG_ALLOW_RETRY. + * + * In the CMA case: long term pins in a CMA region would unnecessarily fragment + * that region. And so, CMA attempts to migrate the page before pinning, when + * FOLL_LONGTERM is specified. + * + * FOLL_PIN indicates that a special kind of tracking (not just page->_refcount, + * but an additional pin counting system) will be invoked. This is intended for + * anything that gets a page reference and then touches page data (for example, + * Direct IO). This lets the filesystem know that some non-file-system entity is + * potentially changing the pages' data. In contrast to FOLL_GET (whose pages + * are released via put_page()), FOLL_PIN pages must be released, ultimately, by + * a call to unpin_user_page(). + * + * FOLL_PIN is similar to FOLL_GET: both of these pin pages. They use different + * and separate refcounting mechanisms, however, and that means that each has + * its own acquire and release mechanisms: + * + * FOLL_GET: get_user_pages*() to acquire, and put_page() to release. + * + * FOLL_PIN: pin_user_pages*() to acquire, and unpin_user_pages to release. + * + * FOLL_PIN and FOLL_GET are mutually exclusive for a given function call. + * (The underlying pages may experience both FOLL_GET-based and FOLL_PIN-based + * calls applied to them, and that's perfectly OK. This is a constraint on the + * callers, not on the pages.) + * + * FOLL_PIN should be set internally by the pin_user_pages*() APIs, never + * directly by the caller. That's in order to help avoid mismatches when + * releasing pages: get_user_pages*() pages must be released via put_page(), + * while pin_user_pages*() pages must be released via unpin_user_page(). + * + * Please see Documentation/core-api/pin_user_pages.rst for more information. + */ + +#define FOLL_WRITE 0x01 /* check pte is writable */ +#define FOLL_TOUCH 0x02 /* mark page accessed */ +#define FOLL_GET 0x04 /* do get_page on page */ +#define FOLL_DUMP 0x08 /* give error on hole if it would be zero */ +#define FOLL_FORCE 0x10 /* get_user_pages read/write w/o permission */ +#define FOLL_NOWAIT 0x20 /* if a disk transfer is needed, start the IO + * and return without waiting upon it */ +#define FOLL_NOFAULT 0x80 /* do not fault in pages */ +#define FOLL_HWPOISON 0x100 /* check page is hwpoisoned */ +#define FOLL_TRIED 0x800 /* a retry, previous pass started an IO */ +#define FOLL_REMOTE 0x2000 /* we are working on non-current tsk/mm */ +#define FOLL_ANON 0x8000 /* don't do file mappings */ +#define FOLL_LONGTERM 0x10000 /* mapping lifetime is indefinite: see below */ +#define FOLL_SPLIT_PMD 0x20000 /* split huge pmd before returning */ +#define FOLL_PIN 0x40000 /* pages must be released via unpin_user_page */ +#define FOLL_FAST_ONLY 0x80000 /* gup_fast: prevent fall-back to slow gup */ +#define FOLL_PCI_P2PDMA 0x100000 /* allow returning PCI P2PDMA pages */ +#define FOLL_INTERRUPTIBLE 0x200000 /* allow interrupts from generic signals */ + #endif /* _LINUX_MM_TYPES_H */