Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3268313rdg; Tue, 17 Oct 2023 09:16:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEotFrqYrrb4hzrBLgPxZC1+BMW7Dr1ir0tJbw5Wy3Aw4iLsb2i9xqB62xS4JfhhHFLrvd9 X-Received: by 2002:a05:6871:468d:b0:1ea:69f6:fe09 with SMTP id ni13-20020a056871468d00b001ea69f6fe09mr3051579oab.10.1697559396059; Tue, 17 Oct 2023 09:16:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697559396; cv=none; d=google.com; s=arc-20160816; b=CSewSL8J2lOTc75W+pY5STzRZ9YArJv0AAvxoEQtCyX2pj1DNpGaMjdp7+zNGVjHDN wUOcHV6J9HhVnDpJvXP2inOMah8r7jPJvaby+0YDlT6OwBQAdokgoeBlLIFqkFGsIYQA d3DKpTJ2JoQz5t1F+xAkApSZc0BApTnrCTNRFWur3q+OxHG99phdrd1fa9xFDtViubm1 PBfF7eP6Yj9TW48iYOn0++8jCPHiQNizCVt1jlH/puqq5Q2q5sAKBCsoI5TuBn0rVOPt FcjtopXFwd2vBABSvPiI8Z6Ch4E3WDzw54917Lv7Zn60l/SDYo5L4CdAeXT1OmlPM0mk TdmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:autocrypt:from:references:cc:to:content-language :subject:user-agent:mime-version:date:message-id:dkim-signature; bh=lczccd5vGYHNveSJtrvYvza5KZbdNK74xDRFaP3BLsU=; fh=DF6IzoS/d82hvLmWh7wD8eqUJ9CUirRGB+KPPUNJ1FU=; b=0sW41YACC6r5Vph7Md+O+N/m4/lTW7DOMQP8yoGZr4TMt+lfQK8f0WBeV+MNUlezig za5Ev6xLBZGmieu0Ajn/QhoedtOtjmQDaNHb/IvtqdIN66k11wwPebSIeL47nzuqss3Q 3tOr+VGZ/aD0fMIqvrUxSi1X+w6TWjQOmSL/ukP1/epoimUPirYgA9Yiy2yvzzdQKJMk vEShUsox8aRJTUzyKrI/A3fBrXbHuYL8lpxhXVA3llXDvu/sI1DWcIWaj5ZuKhQyfsXj lYetcHAEkkhIwjdNCK/WeszblxQWo3TqTjYlFxsC8MQXBpirnAPBCz93hIuiZZ8NR4fk rFwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Gjg+DaQd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id k184-20020a6384c1000000b005acf0458523si84929pgd.612.2023.10.17.09.16.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 09:16:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Gjg+DaQd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id F0F9E8044304; Tue, 17 Oct 2023 09:16:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234843AbjJQQPz (ORCPT + 99 others); Tue, 17 Oct 2023 12:15:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343945AbjJQP4D (ORCPT ); Tue, 17 Oct 2023 11:56:03 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99726101 for ; Tue, 17 Oct 2023 08:55:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697558115; 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:autocrypt:autocrypt; bh=lczccd5vGYHNveSJtrvYvza5KZbdNK74xDRFaP3BLsU=; b=Gjg+DaQdAiUCDa35eCGBZ7R+Bhirl9EirT9CaV6TAGzZ5Yv+MF7rPtCgFu0Rp2c17gCz0q /E0w4kjL3BfnZ6oImxF7B8/iXI113U6ngyECb2UnuV73syuyObrXDWx658cE2EcpbMrsI+ 1ePrfh4n79NIEwzvEVYNhOdmJQv02TQ= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-682-pwwuWRicOzCtt6IAcub-4w-1; Tue, 17 Oct 2023 11:55:14 -0400 X-MC-Unique: pwwuWRicOzCtt6IAcub-4w-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3231fceb811so3576151f8f.2 for ; Tue, 17 Oct 2023 08:55:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697558113; x=1698162913; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=lczccd5vGYHNveSJtrvYvza5KZbdNK74xDRFaP3BLsU=; b=G9OCZSbCLcqR6BcrbvrBr3lMyU3L1ivQjLAOmn2lIXQ6viCUrTMx8WdEZP4Uq8kVTs 6lUbxidYFWml8WA2Z7tCZbjT94+0R0hX3t5DtOiHIuiAdKk4O9ITjoA91QB6+ttTerEv YONoUGX6A40Q8atiiAk1DLxRw4aw9OjPwX2hlS3YQCr1cIkj1DZvIvnbC+r1KXUVihdk kXMJKuWYfQSI2vjJMd9cJY/qOp3LixLg6PXW92vCEAKa0l4bAkomLH/QgdquLWHDB1vP xbbm63rGOFwdrmGmTYg5QlQK5sq1ujUKZWdUkqEHdrGRGLkALohWda3jX9z2ic9jllNk 6iYQ== X-Gm-Message-State: AOJu0YzwU8UhPREMdKBVHOlzE6VLAJ294e1UDJcUYqMLwHOSQufVKDer BOPi1eKJta9QSJaG7pruNYF0q/vwzbCAf+K55jQwSmbrIjLbFHPwkFxqk3PXIgxTHuUJO8lFgEv 8JvrNz5njrYgNKKUyuYLRRnpw X-Received: by 2002:a5d:4e90:0:b0:32d:a4c4:f700 with SMTP id e16-20020a5d4e90000000b0032da4c4f700mr2378804wru.38.1697558113291; Tue, 17 Oct 2023 08:55:13 -0700 (PDT) X-Received: by 2002:a5d:4e90:0:b0:32d:a4c4:f700 with SMTP id e16-20020a5d4e90000000b0032da4c4f700mr2378780wru.38.1697558112865; Tue, 17 Oct 2023 08:55:12 -0700 (PDT) Received: from ?IPV6:2003:cb:c743:5100:93b1:f654:ad11:cd81? (p200300cbc743510093b1f654ad11cd81.dip0.t-ipconnect.de. [2003:cb:c743:5100:93b1:f654:ad11:cd81]) by smtp.gmail.com with ESMTPSA id b17-20020a05600010d100b003197869bcd7sm65944wrx.13.2023.10.17.08.55.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Oct 2023 08:55:12 -0700 (PDT) Message-ID: <8d187891-f131-4912-82d8-13112125b210@redhat.com> Date: Tue, 17 Oct 2023 17:55:10 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 2/3] userfaultfd: UFFDIO_MOVE uABI Content-Language: en-US To: Peter Xu Cc: Lokesh Gidra , 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 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> <12588295-2616-eb11-43d2-96a3c62bd181@redhat.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBE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ZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 17 Oct 2023 09:16:17 -0700 (PDT) On 16.10.23 21:01, Peter Xu wrote: > David, Hi Peter, >>> Basically I see it a potential way of moving memory efficiently especially >>> with thp. >> >> It's an interesting use case indeed. The questions would be if this is (a) a >> use case we want to support; (b) why we need to make that decision now and >> add that feature. > > I would like to support that if nothing stops it from happening, but that's > what we're discussing though.. > > For (b), I wanted to avoid UFFD_FEATURE_MOVE_CROSS_MM feature flag just for > this, if they're already so close, not to mention current code already > contains cross-mm support. Yeah, but that implementation is apparently not sufficiently correct yet. Don't get me wrong, but this feature is already complicated enough that we should really think twice if we want to make this even more complicated and harder to maintain -- because once it's in we all know it's hard to remove and we can easily end up with a maintenance nightmare without sufficiently good use cases. > > If to support that live upgrade use case, I'd probably need to rework tlb > flushing too to do the batching (actually tlb flush is not even needed for > upgrade scenario..). I'm not sure whether Lokesh's use case would move > large chunks, it'll be perfect if Suren did it altogether. But that one is > much easier if transparent to userapps. Cross-mm is not transparent and > need another feature knob, which I want to avoid if possible. And for me it's the other way around: the kernel doesn't have to support each and every use case. So we better think twice before we do something we can no longer undo easily. Further, as we see, this feature without cross-mm capabilities is perfectly usable for other use cases. So even limited initialy support is extremely valuable on its own. > >> >> One question is if this kind of "moving memory between processes" really >> should be done, because intuitively SHMEM smells like the right thing to use >> here (two processes wanting to access the same memory). > > That's the whole point, IMHO, where shmem cannot be used. As you said, on > when someone cannot use file memory for some reason like ksm. Right, but as I explore below KSM will at least prohibit remapping the KSM pages, taking some of the benefit away again. > >> >> The downsides of shmem are lack of the shared zeropage and KSM. The shared >> zeropage is usually less of a concern for VMs, but KSM is. However, KSM will >> also disallow moving pages here. But all non-deduplicated ones could be >> moved. >> >> [I wondered whether moving KSM pages (rmap items) could be done; probably in >> some limited form with some more added complexity] > > Yeah we can leave that complexity for later when really needed. Here > cross-mm support, OTOH, isn't making it so complicated, IMHO. > > Btw, we don't even necessarily need to be able to migrate KSM pages for a > VM live upgrade use case: we can unmerge the pages, upgrade, and wait for > KSM to scan & merge again on the new binary / mmap. Userspace can have > that control easily, afaiu, via existing madvise(). MADV_POPULATE_WRITE would do, yes. BTW, wasn't there a way to do VM live-upgrade using fork() and replacing the binary? I recall that there was at some time either an implementation in QEMU or a proposal for an implementation; but I don't know how VM memory was provided. It's certainly harder to move VM memory using fork(). [...] >> >> single-mm should at least not cause harm, but the semantics are >> questionable. cross-mm could, especially with malicious user space that >> wants to find ways of harming the kernel. > > For kernel, I think we're discussing to see whether it's safe to do so from > kernel pov, e.g., whether to exclude pinned pages is part of that. > > For the user app, the dest process has provided the uffd descriptor on its > own willingness, or be a child of the UFFDIO_MOVE issuer when used with > EVENT_FORK, I assume that's already some form of safety check because it > cannot be any process, but ones that are proactively in close cooperative > with the issuer process. Is that and will that remain the case? I know people have been working on transparent user-space swapping using monitor processes using uffd. I thought there would have been ways to achieve that without any corporation of the dst. > >> >> I'll note that mremap with pinned pages works. > > But that's not "by design", am I right? IOW, do we have any real pin user > that rely on mremap() allowing pages to be moved? If in doubt, usually "probably yes". Hard to tell if the "remap" in mremap indicates that we are simply remapping pages , and not moving data. > > I don't see any word guarantee at least from man page that mremap() will > make sure the PFN won't change after the movement.. even though it seems to > be what happening now. If you managed to support page pinning with migration the exact PFN doesn't matter. Likely nobody would implement that due to the tracking complexity. > > Neither do I think when designing MMF_HAS_PINNED we kept that in mind that > it won't be affected by someone mremap() pinned pages and we want to keep > it working.. > > All of it just seems to be an accident.. Not necessarily my opinion, but doesn't really matter here. It's working. At least It's reasonable to have part of a THP pinned and mremapping the other part of the THP. That makes things more tricky ... because you only know that the THP is pinned. > > One step back, we're free to define UFFDIO_MOVE anyway, and we don't > necessarily need to always follow mremap(). E.g., mremap() also supports > ksm pages, but IIUC we already decide to not support that for now on > UFFDIO_MOVE. UFFDIO_MOVE seems all fine to make it clear on failing at > pinned pages from the 1st day if that satisfies our goals, too. Yes. -- Cheers, David / dhildenb