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 3987ECDB47E for ; Fri, 13 Oct 2023 17:06:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84BA78D0168; Fri, 13 Oct 2023 13:06:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7FB648D0015; Fri, 13 Oct 2023 13:06:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 675798D0168; Fri, 13 Oct 2023 13:06:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4F4F58D0015 for ; Fri, 13 Oct 2023 13:06:23 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 10F02B521C for ; Fri, 13 Oct 2023 17:06:23 +0000 (UTC) X-FDA: 81341066646.04.A061751 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 98F6910002C for ; Fri, 13 Oct 2023 17:06:20 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PlF6LIUj; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697216780; 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:in-reply-to:references:references:dkim-signature; bh=4anTAcj47QphqCTa0VlpuuQqLbvMYpkABh/3zdt7Xbg=; b=TMUF+6HmYv8Yodw/04Ckclp6jgK+4ee8nh4QfG2ktxk/h+MmssjdTWBY8KnO7nlgYdbtqI PMYoj5SCnvIM7j2PLIgMdeeF571kaU4JmXmnTaiD16JaQj+Hw684aWnJ2+MXZknIiNFDWx 6wXiGOK9wDTlsU8+N7EaDaznGJy23zQ= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PlF6LIUj; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697216780; a=rsa-sha256; cv=none; b=gd44ReatIQkOtO9wpQz1yjLLmCbs1qm5d7md8xRjTtG4pF5Um9xIJ+LrHXmmftaXfN7kBJ Khrut6JkeDa18xGGzCKYwZpGubm1ZpLdJn+pVXrcy/Z0qrzaukhpeNEdn0MM5hN8I6qEe9 S6jRNsyNJ2Rhczu4r0y9wmvwJVHB36g= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697216778; 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=4anTAcj47QphqCTa0VlpuuQqLbvMYpkABh/3zdt7Xbg=; b=PlF6LIUjwqOvmH4w7DRMbOiZlS2ImAtzHdDKiT7kqXCUCYSoNGyX2aISvxaRZygxUHIy4q yqorrN7ns79dndWyPNUeaRK+LtUWiQot4U6LO7kZvtJ8ttg5J4UK204xb3QcLUsVjLRWMz kzXf1bg8Q3Ba0jVKydAA/IZ9ZRKUBC4= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-570-CykUoCJmPSSvQiuzcB1-Vw-1; Fri, 13 Oct 2023 13:06:14 -0400 X-MC-Unique: CykUoCJmPSSvQiuzcB1-Vw-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-637948b24bdso4253806d6.1 for ; Fri, 13 Oct 2023 10:06:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697216774; x=1697821574; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4anTAcj47QphqCTa0VlpuuQqLbvMYpkABh/3zdt7Xbg=; b=qks8V5RExTRSj0cVTa97OG6HzD3EdyJ52TUTVlKZAYRlUTpOXUxiy3R/Vh85fqEudR k0g+eBiYU2zW1P4Sqs+A1g2iQiV67IdenPZIwytR9gcIxeukX4rrw4yYVYfZ3Y/ukoPO OqZa04ddCjxoZCvBuCpRx6FpQmcnBP7Hjw/qusXFdRt+bInnGRvTD7u3u1JeoJTPDVxR 3Q8rHIyFs8mITnNq4Z+ofegHjzhsGzw1MnNnWE1YLUYpDzZcYFALuHsxNG53EGUwEOXR ZxdiEuK3HmJJwCgUYYEsPUtW5vGf3CDAr39/AF+D5+omitWqblbjhfkWKIMjTXTyPUDV pZ3Q== X-Gm-Message-State: AOJu0YxBaXDPIPm8TzTdGVm7qfMusd4Z9N60lqnh2EzqWptXS+VVD9rq 4avburkYOMeY0HrRJf7vBhT0CkVPy+vjfGouIeeFme+yfsfjEb2d9EVbkFxghvit3rv0AQaQ631 D3DYQ8LEMDZE= X-Received: by 2002:a05:6214:519b:b0:65d:482:9989 with SMTP id kl27-20020a056214519b00b0065d04829989mr29618073qvb.5.1697216773824; Fri, 13 Oct 2023 10:06:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFRH784LNJizEjykvGovSKOhkhcLbazKwKyVKKk+ujLDPqfsEAe8jFxGjwEXZeiVmuU0mCpCg== X-Received: by 2002:a05:6214:519b:b0:65d:482:9989 with SMTP id kl27-20020a056214519b00b0065d04829989mr29618034qvb.5.1697216773382; Fri, 13 Oct 2023 10:06:13 -0700 (PDT) Received: from x1n (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id j12-20020a0ce00c000000b0065b1f90ff8csm812307qvk.40.2023.10.13.10.06.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 10:06:13 -0700 (PDT) Date: Fri, 13 Oct 2023 13:05:55 -0400 From: Peter Xu To: Lokesh Gidra Cc: David Hildenbrand , Suren Baghdasaryan , akpm@linux-foundation.org, viro@zeniv.linux.org.uk, brauner@kernel.org, shuah@kernel.org, aarcange@redhat.com, hughd@google.com, mhocko@suse.com, axelrasmussen@google.com, rppt@kernel.org, willy@infradead.org, Liam.Howlett@oracle.com, jannh@google.com, zhangpeng362@huawei.com, bgeffon@google.com, kaleshsingh@google.com, ngeoffray@google.com, jdduke@google.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH v3 2/3] userfaultfd: UFFDIO_MOVE uABI Message-ID: References: <20231009064230.2952396-1-surenb@google.com> <20231009064230.2952396-3-surenb@google.com> <214b78ed-3842-5ba1-fa9c-9fa719fca129@redhat.com> <478697aa-f55c-375a-6888-3abb343c6d9d@redhat.com> <205abf01-9699-ff1c-3e4e-621913ada64e@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Rspam-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eyC0Znr2m8ZCJC5Yx2rkd42m 8lWIVQmm KP+fIsFRFns8bT/xq+oM6bEiRB8X8H/Q8aZHfiVoNDiVW4rabzcUMltvGwO9xFbGghi95y6EmZfqwqY+G7ptjDgI6CUGks6jlG5PvBzT1Bas6Y3EwVnYp7DtXgVdkLhUoY5zekjuRq361Hdqk9NDdbllGBs1gP+or3ZABb09kZ8QbgX7L7P1/xQopozHBO4/7R6G+ES/wOd4NhWZz/WVP6DWQeR/VgIIbDEig/6xgCo7jBzmSZDkd3zMyD+/86LnFdIRxHBqwQgCFInuYLZ72qmOZ7pB6qQj7btTFXgI+RKzrEzFfHqqsAA3d7M+ukPGaQJQ6m3hfAYkwu8UI9DOFSRUR3j1gb/JuTGq2ylu710oJe91XhV3ueIzw3UV86HvnkFFn1HCGY/+Oo3johgG/gUIvIPDTGJdc0nlA1FBgpnUjaLf5UoVbKsXPxw== 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, Oct 13, 2023 at 09:49:10AM -0700, Lokesh Gidra wrote: > On Fri, Oct 13, 2023 at 9:08 AM Peter Xu wrote: > > > > On Fri, Oct 13, 2023 at 11:56:31AM +0200, David Hildenbrand wrote: > > > Hi Peter, > > > > Hi, David, > > > > > > > > > I used to have the same thought with David on whether we can simplify the > > > > design to e.g. limit it to single mm. Then I found that the trickiest is > > > > actually patch 1 together with the anon_vma manipulations, and the problem > > > > is that's not avoidable even if we restrict the api to apply on single mm. > > > > > > > > What else we can benefit from single mm? One less mmap read lock, but > > > > probably that's all we can get; IIUC we need to keep most of the rest of > > > > the code, e.g. pgtable walks, double pgtable lockings, etc. > > > > > > No existing mechanisms move anon pages between unrelated processes, that > > > naturally makes me nervous if we're doing it "just because we can". > > > > IMHO that's also the potential, when guarded with userfaultfd descriptor > > being shared between two processes. > > > > See below with more comment on the raised concerns. > > > > > > > > > > > > > Actually, even though I have no solid clue, but I had a feeling that there > > > > can be some interesting way to leverage this across-mm movement, while > > > > keeping things all safe (by e.g. elaborately requiring other proc to create > > > > uffd and deliver to this proc). > > > > > > Okay, but no real use cases yet. > > > > I can provide a "not solid" example. I didn't mention it because it's > > really something that just popped into my mind when thinking cross-mm, so I > > never discussed with anyone yet nor shared it anywhere. > > > > Consider VM live upgrade in a generic form (e.g., no VFIO), we can do that > > very efficiently with shmem or hugetlbfs, but not yet anonymous. We can do > > extremely efficient postcopy live upgrade now with anonymous if with REMAP. > > > > Basically I see it a potential way of moving memory efficiently especially > > with thp. > > > > > > > > > > > > > Considering Andrea's original version already contains those bits and all > > > > above, I'd vote that we go ahead with supporting two MMs. > > > > > > You can do nasty things with that, as it stands, on the upstream codebase. > > > > > > If you pin the page in src_mm and move it to dst_mm, you successfully broke > > > an invariant that "exclusive" means "no other references from other > > > processes". That page is marked exclusive but it is, in fact, not exclusive. > > > > It is still exclusive to the dst mm? I see your point, but I think you're > > taking exclusiveness altogether with pinning, and IMHO that may not be > > always necessary? > > > > > > > > Once you achieved that, you can easily have src_mm not have MMF_HAS_PINNED, > > > > (I suppose you meant dst_mm here) > > > > > so you can just COW-share that page. Now you successfully broke the > > > invariant that COW-shared pages must not be pinned. And you can even trigger > > > VM_BUG_ONs, like in sanity_check_pinned_pages(). > > > > Yeah, that's really unfortunate. But frankly, I don't think it's the fault > > of this new feature, but the rest. > > > > Let's imagine if the MMF_HAS_PINNED wasn't proposed as a per-mm flag, but > > per-vma, which I don't see why we can't because it's simply a hint so far. > > Then if we apply the same rule here, UFFDIO_REMAP won't even work for > > single-mm as long as cross-vma. Then UFFDIO_REMAP as a whole feature will > > be NACKed simply because of this.. > > > > And I don't think anyone can guarantee a per-vma MMF_HAS_PINNED can never > > happen, or any further change to pinning solution that may affect this. So > > far it just looks unsafe to remap a pin page to me. > > > > I don't have a good suggestion here if this is a risk.. I'd think it risky > > then to do REMAP over pinned pages no matter cross-mm or single-mm. It > > means probably we just rule them out: folio_maybe_dma_pinned() may not even > > be enough to be safe with fast-gup. We may need page_needs_cow_for_dma() > > with proper write_protect_seq no matter cross-mm or single-mm? > > > > > > > > Can it all be fixed? Sure, with more complexity. For something without clear > > > motivation, I'll have to pass. > > > > I think what you raised is a valid concern, but IMHO it's better fixed no > > matter cross-mm or single-mm. What do you think? > > > > In general, pinning lose its whole point here to me for an userspace either > > if it DONTNEEDs it or REMAP it. What would be great to do here is we unpin > > it upon DONTNEED/REMAP/whatever drops the page, because it loses its > > coherency anyway, IMHO. > > > > > > > > Once there is real demand, we can revisit it and explore what else we would > > > have to take care of (I don't know how memcg behaves when moving between > > > completely unrelated processes, maybe that works as expected, I don't know > > > and I have no time to spare on reviewing features with no real use cases) > > > and announce it as a new feature. > > > > Good point. memcg is probably needed.. > > > > So you reminded me to do a more thorough review against zap/fault paths, I > > think what's missing are (besides page pinning): > > > > - mem_cgroup_charge()/mem_cgroup_uncharge(): > > > > (side note: I think folio_throttle_swaprate() is only for when > > allocating new pages, so not needed here) > > > > - check_stable_address_space() (under pgtable lock) > > > > - tlb flush > > > > Hmm???????????????? I can't see anywhere we did tlb flush, batched or > > not, either single-mm or cross-mm should need it. Is this missing? > > > IIUC, ptep_clear_flush() flushes tlb entry. So I think we are doing > unbatched flushing. Possibly a nice performance improvement later on > would be to try doing it batched. Suren can throw more light on it. Oh yeah.. thanks. > > One thing I was wondering is don't we need cache flush for the src > pages? mremap's move_page_tables() does it. IMHO, it's required here > as well. I commented in my reply, I also think it's needed. Otherwise for some arches I think we can have page containing stall data if not fully flushed before the movement. x86 is probably fine, though. > > > > > > > > > > Note: that (with only reading the documentation) it also kept me wondering > > > how the MMs are even implied from > > > > > > struct uffdio_move { > > > __u64 dst; /* Destination of move */ > > > __u64 src; /* Source of move */ > > > __u64 len; /* Number of bytes to move */ > > > __u64 mode; /* Flags controlling behavior of move */ > > > __s64 move; /* Number of bytes moved, or negated error */ > > > }; > > > > > > That probably has to be documented as well, in which address space dst and > > > src reside. > > > > Agreed, some better documentation will never hurt. Dst should be in the mm > > address space that was bound to the userfault descriptor. Src should be in > > the current mm address space. > > > > Thanks, > > > > -- > > Peter Xu > > > -- Peter Xu