From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42E75C433E3 for ; Mon, 8 Jun 2020 04:41:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 07384206D5 for ; Mon, 8 Jun 2020 04:41:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="U11em5cJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 07384206D5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 89C086B005D; Mon, 8 Jun 2020 00:41:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 824B16B0062; Mon, 8 Jun 2020 00:41:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 715636B006C; Mon, 8 Jun 2020 00:41:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0214.hostedemail.com [216.40.44.214]) by kanga.kvack.org (Postfix) with ESMTP id 4EEDA6B005D for ; Mon, 8 Jun 2020 00:41:01 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1387C1BCAD for ; Mon, 8 Jun 2020 04:41:01 +0000 (UTC) X-FDA: 76904794722.13.kite95_360b6ee26db7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id E1D361817B77A for ; Mon, 8 Jun 2020 04:41:00 +0000 (UTC) X-HE-Tag: kite95_360b6ee26db7 X-Filterd-Recvd-Size: 5274 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Mon, 8 Jun 2020 04:41:00 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 64B12206D5; Mon, 8 Jun 2020 04:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591591259; bh=v3kA+M7pLm592RszvhPR/+kRBvgTHaTRrUHWNMEvbbg=; h=Date:From:To:Subject:In-Reply-To:From; b=U11em5cJKArf6Ri54f+PPGcy9gFDBLLWgIWFYLw+MkR4Xq/8onZl+MyrAYIpuMOau RB6NOMvalMazgXbuGsznXIQVm0pR5nvgT/2qaJj6Uszyp7KH9Au1IAqPtec30C2fA3 z45DJaZYOW9BCrHYzggtdNsPNU3gEV1ziqGHwNjE= Date: Sun, 07 Jun 2020 21:40:59 -0700 From: Andrew Morton To: akpm@linux-foundation.org, corbet@lwn.net, daniel@ffwll.ch, david@fromorbit.com, jack@suse.cz, jglisse@redhat.com, jhubbard@nvidia.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, torvalds@linux-foundation.org, vbabka@suse.cz Subject: [patch 17/54] mm/gup: update pin_user_pages.rst for "case 3" (mmu notifiers) Message-ID: <20200608044059.8aZSEkI9C%akpm@linux-foundation.org> In-Reply-To: <20200607212615.b050e41fac139a1e16fe00bd@linux-foundation.org> User-Agent: s-nail v14.8.16 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: E1D361817B77A X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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: =46rom: John Hubbard Subject: mm/gup: update pin_user_pages.rst for "case 3" (mmu notifiers) Update case 3 so that it covers the use of mmu notifiers, for hardware that does, or does not have replayable page faults. Also, elaborate case 4 slightly, as it was quite cryptic. Link: http://lkml.kernel.org/r/20200527194953.11130-1-jhubbard@nvidia.com Signed-off-by: John Hubbard Cc: Daniel Vetter Cc: J=C3=A9r=C3=B4me Glisse Cc: Vlastimil Babka Cc: Jan Kara Cc: Dave Chinner Cc: Jonathan Corbet Signed-off-by: Andrew Morton --- Documentation/core-api/pin_user_pages.rst | 29 +++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) --- a/Documentation/core-api/pin_user_pages.rst~mm-gup-update-pin_user_page= srst-for-case-3-mmu-notifiers +++ a/Documentation/core-api/pin_user_pages.rst @@ -148,23 +148,28 @@ NOTE: Some pages, such as DAX pages, can because DAX pages do not have a separate page cache, and so "pinning" impl= ies locking down file system blocks, which is not (yet) supported in that way. =20 -CASE 3: Hardware with page faulting support -------------------------------------------- -Here, a well-written driver doesn't normally need to pin pages at all. How= ever, -if the driver does choose to do so, it can register MMU notifiers for the = range, -and will be called back upon invalidation. Either way (avoiding page pinni= ng, or -using MMU notifiers to unpin upon request), there is proper synchronizatio= n with -both filesystem and mm (page_mkclean(), munmap(), etc). +CASE 3: MMU notifier registration, with or without page faulting hardware +------------------------------------------------------------------------- +Device drivers can pin pages via get_user_pages*(), and register for mmu +notifier callbacks for the memory range. Then, upon receiving a notifier +"invalidate range" callback , stop the device from using the range, and un= pin +the pages. There may be other possible schemes, such as for example explic= itly +synchronizing against pending IO, that accomplish approximately the same t= hing. =20 -Therefore, neither flag needs to be set. +Or, if the hardware supports replayable page faults, then the device drive= r can +avoid pinning entirely (this is ideal), as follows: register for mmu notif= ier +callbacks as above, but instead of stopping the device and unpinning in the +callback, simply remove the range from the device's page tables. =20 -In this case, ideally, neither get_user_pages() nor pin_user_pages() shoul= d be -called. Instead, the software should be written so that it does not pin pa= ges. -This allows mm and filesystems to operate more efficiently and reliably. +Either way, as long as the driver unpins the pages upon mmu notifier callb= ack, +then there is proper synchronization with both filesystem and mm +(page_mkclean(), munmap(), etc). Therefore, neither flag needs to be set. =20 CASE 4: Pinning for struct page manipulation only ------------------------------------------------- -Here, normal GUP calls are sufficient, so neither flag needs to be set. +If only struct page data (as opposed to the actual memory contents that a = page +is tracking) is affected, then normal GUP calls are sufficient, and neithe= r flag +needs to be set. =20 page_maybe_dma_pinned(): the whole point of pinning =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D _