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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE753EEB58C for ; Sat, 9 Sep 2023 11:18:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 330656B011D; Sat, 9 Sep 2023 07:18:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2BA086B011E; Sat, 9 Sep 2023 07:18:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15A656B011F; Sat, 9 Sep 2023 07:18:45 -0400 (EDT) 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 F36196B011D for ; Sat, 9 Sep 2023 07:18:44 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C50ACB3B91 for ; Sat, 9 Sep 2023 11:18:44 +0000 (UTC) X-FDA: 81216811368.18.CD94F6B Received: from verein.lst.de (verein.lst.de [213.95.11.211]) by imf14.hostedemail.com (Postfix) with ESMTP id ECABD100018 for ; Sat, 9 Sep 2023 11:18:40 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=none; spf=none (imf14.hostedemail.com: domain of hch@lst.de has no SPF policy when checking 213.95.11.211) smtp.mailfrom=hch@lst.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694258321; 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: in-reply-to:in-reply-to:references:references; bh=rpfyh4e1MVZaISYm0PQnbRauN04bvUl9gF86VrCKggY=; b=zi3U204DGpoRxTyOu8jr1UDJCBCYz0DrloXPfw0ju5uXm8GmVPw0GfeIcoqnoSL1NpdtRg FWYztzVbqAzcF4pB8j7V31yaU/aGPW/AtgB/EGnvecTYjw5QBCZIwwfYUioCCtG/8Ql0mR 4w8iBAC1oLyfqGniJy7A0PyOo6cYuNY= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=none; spf=none (imf14.hostedemail.com: domain of hch@lst.de has no SPF policy when checking 213.95.11.211) smtp.mailfrom=hch@lst.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694258321; a=rsa-sha256; cv=none; b=8fot1smH8egVvWtSVWVe1WDDtEzubKRsiYqlgS8ps49DsiS848/yM3+Gvmwcs7/SPNB8RM xgADSlozfCfYt7gG3lSgYGasKXlm0nLsQfzUNcisCoQb2VvSIO6f4D61vWqn1Rmzi3h2BC Nm6B5alIPhcNEaSZFqy241PXQiBhvPQ= Received: by verein.lst.de (Postfix, from userid 2407) id 54BCD6732D; Sat, 9 Sep 2023 13:18:35 +0200 (CEST) Date: Sat, 9 Sep 2023 13:18:34 +0200 From: Christoph Hellwig To: David Hildenbrand Cc: Christoph Hellwig , Jan Kara , David Howells , Peter Xu , Lei Huang , miklos@szeredi.hu, Xiubo Li , Ilya Dryomov , Jeff Layton , Trond Myklebust , Anna Schumaker , Latchesar Ionkov , Dominique Martinet , Christian Schoenebeck , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , John Fastabend , Jakub Sitnicki , Boris Pismenny , linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, ceph-devel@vger.kernel.org, linux-mm@kvack.org, v9fs@lists.linux.dev, netdev@vger.kernel.org Subject: Re: getting rid of the last memory modifitions through gup(FOLL_GET) Message-ID: <20230909111834.GA11859@lst.de> References: <20230905141604.GA27370@lst.de> <0240468f-3cc5-157b-9b10-f0cd7979daf0@redhat.com> <20230908081544.GB8240@lst.de> <8698ba1f-fc5d-a82e-842b-100dc8957f2f@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8698ba1f-fc5d-a82e-842b-100dc8957f2f@redhat.com> User-Agent: Mutt/1.5.17 (2007-11-01) X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: ECABD100018 X-Stat-Signature: amt7rx7uoq9xrsp7ci8y4t64xow9pjgk X-Rspam-User: X-HE-Tag: 1694258320-278660 X-HE-Meta: U2FsdGVkX1+uCFhIDOLHVVE5CeMM45qjUT2zQJVd8TDknweVcxwkXVZz9K7HMfGARsrnnsTTfyT8rOqJwkk+8Of1IW6hr97kOX3ibCCBKgLhhf8MAo+2Q31bxNyFZVknojkorRJyW5Zz0SMvtzEz3DqI8LbowqNuV2g8p3k7sI/X8J47YWLpR5ySzZaYmLt5RVUoudxW4gyUSAgMT5H01a6mfKzrB1PS18UmMArVopemC4o09tW2oYfNTnid4KiYK1ylDVH61eSCpJNAKISu5bgxytn0IFn4CDFwarta87DKW6C6kuKJ1ITnZeqIUdBN51mmnBOHfIOsaVY9C8AGAuOIOqp9/hgu5EIOAgc/ve+m/NrgYHStVOMp3OQ4xNKGBYTW8B/J5/51Jieg1VSLt9YwgH1jM14qI8MhsW+xdZUnzrOXdEYcMVqS2htMkPP0vCAaJn40prYBtkwOD025dfzx38tiQhVH9aD/RjrpMr/w+TZK/XkgoVZOk5vhG2GTCPyDrKNl5n5FvL1aEQyqgNBhtNA+kSBPWtq4kZ7wswfQcFG5YEGK9+RGc2a7SJYngUImaMaNl77Yy237HLAgVMy7074ZNZIPYjbVFd0j0S9sHIJjhJ6ukOBpOoycpkOVB33XOGkAPzrmenwmZZyIjxa+Nkp6wEUqnO3pNKmRB3z68LYcq6ikpdQWRwORTZRcdlKdUBvOrGtIRkYzcWLz64szI2M1c6vGbgIPblIK69mph/08Bz/2lOo0QUJ4dbFNaqyZrTJLpcS+WQDPLKLGTMXH+OkG8ayOt0XOxoD+uk+97u95bLwl3W93NOFILkFBYyUHke9AT58uydJeq2/WwS/wVwqNi6L2bk2uobpZFIuJHg2cDIo4W9rDsCNvCUt6dIM1tWS6WK3+l55+WryKY8ruLZBN7o7MNb7eWvN2znbrm/Eg9BC3t3hpVXdF4ZEousEMKh0h4S/+b9wtUAZ UfFLCwGY mFpVI4gtg7DISlkaagpD++hTm+kovloXwrgVX0A1E2aL+VcRAT8eXJUt5ydnEIYvdfQiViA7f34I6WaN1BnuYAPsQxK5TQrE3hQ5NrMOsrvPxXfKXYqge7attoa8bUg4bDVH8hf5Ae1XWus+4NXh78VKiNOb611UWiiT+jN3PRhPsTuMfVI4OMjC81nCX2VUQdMS/Di+nu3BxDMKDmu00l4Ntyk11J30PmjhL7OppcqyqRuumRQLjvc9mFDnN9MirWEaD 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: On Fri, Sep 08, 2023 at 06:48:05PM +0200, David Hildenbrand wrote: > vmsplice_to_pipe() -> iter_to_pipe() -> iov_iter_get_pages2() > > So it ends up calling get_user_pages_fast() > > ... and not using FOLL_PIN|FOLL_LONGTERM > > Why FOLL_LONGTERM? Because it's a longterm pin, where unprivileged users > can grab a reference on a page for all eternity, breaking CMA and memory > hotunplug (well, and harming compaction). > > Why FOLL_PIN? Well FOLL_LONGTERM only applies to FOLL_PIN. But for > anonymous memory, this will also take care of the last remaining hugetlb > COW test (trigger COW unsharing) as commented back in: > > https://lore.kernel.org/all/02063032-61e7-e1e5-cd51-a50337405159@redhat.com/ Well, I'm not against it. It just isn't required for deadling with file system writeback vs GUP modification race this thread was started for. >> Can KVM page tables use file backed shared mappings? > > Yes, usually shmem and hugetlb. But with things like emulated > NVDIMMs/virtio-pmem for VMs, easily also ordinary files. > > But it's really not ordinary write access through GUP. It's write access > via a secondary page table (secondary MMU), that's synchronized to the > process page table -- just like if the CPU would be writing to the page > using the process page tables (primary MMU). Writing through the process page tables takes a write faul when first writing, which calls into ->page_mkwrite in the file system. Does the synchronization take care of that? If not we need to add or emulate it. > ptrace will find the pagecache page writable in the page table (PTE write > bit set), if it intends to write to the page (FOLL_WRITE). If it is not > writable, it will trigger a page fault that informs the file system. Yes, that case is (mostly) fine. > > With an FS that wants writenotify, we will not map a page writable (PTE > write bit not set) unless it is dirty (PTE dirty bit set) IIRC. > > So are we concerned about a race between the filesystem removing the PTE > write bit (to catch next write access before it gets dirtied again) and > ptrace marking the page dirty? Yes. This is the race that we've run into with various GUP users. > Yes. However, secondary MMU users (like KVM) would need some way to keep > making use of that; ideally, using a proper separate interface instead of > (ab)using plain GUP and confusing people :) I'mm all for that.