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 DFA2CC54E58 for ; Mon, 18 Mar 2024 22:02:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4FF318D0003; Mon, 18 Mar 2024 18:02:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B1038D0001; Mon, 18 Mar 2024 18:02:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 32A198D0003; Mon, 18 Mar 2024 18:02:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 227868D0001 for ; Mon, 18 Mar 2024 18:02:30 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E1FE1120C02 for ; Mon, 18 Mar 2024 22:02:29 +0000 (UTC) X-FDA: 81911534418.22.27C2E46 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 903E014002C for ; Mon, 18 Mar 2024 22:02:26 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WmteSL20; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf09.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710799346; 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=558BlsrQU8bWToq/MP7ME6ElVXXDjRwjdLMSKlPG+J0=; b=crZcQcPa75hows3ODzFy4zsX1Ujv+hFg5EZHHDY87sClTvVVBJ0ZywszYmpre/kct7XC0B nD/5x2+STo5aFKOfUceVwECBU5+16gJjDKD5abk7aHPBMC8OjcND3Mr++/AcaUtz+vJ1R8 c44gz1FAyp/xez4IAcirhGQMkvtryd4= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WmteSL20; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf09.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710799346; a=rsa-sha256; cv=none; b=Rc4Vqns/woNTsRePditB5mLQXDZ61QWJ0bTz7+ZG6aR0ip/rQZx3M2daOy85xrA+Dx7SIZ eksG6s+L0B+R+cwQjPvPbOinjAzjjOJF1qWJdMuOraXIpSa7tschjMy1sr/wcCo5+vRPY5 43UvhtnLPTZzWYDtH41SkqQjHrMTjTE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710799345; 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=558BlsrQU8bWToq/MP7ME6ElVXXDjRwjdLMSKlPG+J0=; b=WmteSL20y24d3VsF+lOiBuCmAcuVi9iCnsd6MsnzP1gfcNtFeehy6Wvgq8r+OWxNsiaPWI VNHJJ18w3SitYheSMmp+X1KBQNKqioIDmuUu6IvOWHefhwXei7r/23G1T29x0XHpLaFLvQ pSgJDfVo9Q0U5oPmph9nWMlfW8Ca3SY= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-52-f65gwYJyP2Gl93On77xYEA-1; Mon, 18 Mar 2024 18:02:22 -0400 X-MC-Unique: f65gwYJyP2Gl93On77xYEA-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-40e40126031so32826325e9.0 for ; Mon, 18 Mar 2024 15:02:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710799341; x=1711404141; 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=558BlsrQU8bWToq/MP7ME6ElVXXDjRwjdLMSKlPG+J0=; b=tpf4jMhFZZJqu2D0jfjD+yEyYHu9xZbG9JXO6/IuJSKGfRhP0zzjQMQ0n3jqaIt3Do yWAF4JA4JZIKHRp/lixNPG7+RxihM/nxED7Pag9nGREm2/trfXB9PkhiGUD3pAu/OtCg fRDEP3psQAZOTNkOXmk+XeSeWWgplIQ2jzSoJQ4LzA1k/Q6qJIXB2z7+nlr36/b+6JOQ IfO+JLdtzuFxuWnFUvJKxKs+vmYHPF49um7yPUDDG8U1dQuF8/YIVjE3rhbMq2gTu6nj ZSWeC9uNP9CWr+LO9QwJ6A/8adnUJE/BbF+MUXRNO6NUBguWb+yjSgCFSjApvBI0+NiY Pemg== X-Forwarded-Encrypted: i=1; AJvYcCV67XJXqvuYcI+be2vUd8ugMht9y5NrjMI8JeK5Rar1FItJ5kpg3e3ZtEswTzBinwxW2/HyOB/BOtMmCWx51Exmz2o= X-Gm-Message-State: AOJu0YwNF71R36cC/5cCSKcKWI2et9OIhKrT632LJ7S8qTQdc0n94NNR 5LPPggGdx2Rq0piNesHSHV+wmCTSCZwWsTeMcIXdOUwhRSrHVKYfn42qNW49A471mF4FbWg7ek/ dOULDXBhLpm17TkbGIsR2m7DM3htdp7G+ASiLM/g6+SEg8exi X-Received: by 2002:a05:600c:35c8:b0:413:feed:b309 with SMTP id r8-20020a05600c35c800b00413feedb309mr7314829wmq.6.1710799341148; Mon, 18 Mar 2024 15:02:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEGzQsQ2eeXECfnQ2qVVS8wQk/77pmqPtziULZ4wJM+/ieeO8zwTifNOEPyWmxkgY6V8FqR5A== X-Received: by 2002:a05:600c:35c8:b0:413:feed:b309 with SMTP id r8-20020a05600c35c800b00413feedb309mr7314781wmq.6.1710799340608; Mon, 18 Mar 2024 15:02:20 -0700 (PDT) Received: from ?IPV6:2003:cb:c737:1f00:94ff:246b:30d0:686b? (p200300cbc7371f0094ff246b30d0686b.dip0.t-ipconnect.de. [2003:cb:c737:1f00:94ff:246b:30d0:686b]) by smtp.gmail.com with ESMTPSA id fa21-20020a05600c519500b004140f9f6f5bsm4998717wmb.25.2024.03.18.15.02.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Mar 2024 15:02:20 -0700 (PDT) Message-ID: <7470390a-5a97-475d-aaad-0f6dfb3d26ea@redhat.com> Date: Mon, 18 Mar 2024 23:02:17 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: folio_mmapped To: Vishal Annapurve Cc: Sean Christopherson , Quentin Perret , Matthew Wilcox , Fuad Tabba , kvm@vger.kernel.org, kvmarm@lists.linux.dev, pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, viro@zeniv.linux.org.uk, brauner@kernel.org, akpm@linux-foundation.org, xiaoyao.li@intel.com, yilun.xu@intel.com, chao.p.peng@linux.intel.com, jarkko@kernel.org, amoorthy@google.com, dmatlack@google.com, yu.c.zhang@linux.intel.com, isaku.yamahata@intel.com, mic@digikod.net, vbabka@suse.cz, ackerleytng@google.com, mail@maciej.szmigiero.name, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com, suzuki.poulose@arm.com, steven.price@arm.com, quic_mnalajal@quicinc.com, quic_tsoni@quicinc.com, quic_svaddagi@quicinc.com, quic_cvanscha@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, catalin.marinas@arm.com, james.morse@arm.com, yuzenghui@huawei.com, oliver.upton@linux.dev, maz@kernel.org, will@kernel.org, keirf@google.com, linux-mm@kvack.org References: <40a8fb34-868f-4e19-9f98-7516948fc740@redhat.com> <20240226105258596-0800.eberman@hu-eberman-lv.qualcomm.com> <925f8f5d-c356-4c20-a6a5-dd7efde5ee86@redhat.com> <755911e5-8d4a-4e24-89c7-a087a26ec5f6@redhat.com> <99a94a42-2781-4d48-8b8c-004e95db6bb5@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 WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJC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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: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspam-User: X-Stat-Signature: q4hmbxn11k4mz5zktpdbo4dypediow13 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 903E014002C X-HE-Tag: 1710799346-324212 X-HE-Meta: U2FsdGVkX18ilXI12pbK9im7eA4pIEJcYwSTz2hJHSgI4jUY5mOZPSmzj9eE5dk9Wu1GSkMFf+EtaWAtvBgbSBZTAkYcxeSrLtLWPFsWGUJUPr0k27esioz+DQvggcvytmnuDDkvv/jeUDW7zAnialJwPnkp7Gke8v10hr9EZ3DLanm8YcJIfViqtataQyCWcnidM4Dj/L5/gxSwBHYpE2UjR7ziHy50moA1jyndWhuxrKpQJrkcZMeTACvm6i/fbrn/MJ9FVy8+1WpUXzEdDbeKd0PlS2DK12KlvnKzPJSii8gugFh0Jvy45qIpAKTDgdQUpreESQTUjBIAlAXklrQ5QmyhJRdjvAPz+iWQTYDl6Vwxtxn0LgPJG1xiuuEjFNLBGNlgSLUgGoUHhbes1jtDksBGpv8WfcfOSEg38tLp8wymGBFkajRMteOcYgqck3tq1FQStF6SbwdwxeO7Ugsj2uUtQccb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2RaYg5Z0IpHWjnD8n0woOD96GQCVM7jtID++XJw== 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: List-Subscribe: List-Unsubscribe: On 18.03.24 18:06, Vishal Annapurve wrote: > On Mon, Mar 4, 2024 at 12:17 PM David Hildenbrand wrote: >> >> On 04.03.24 20:04, Sean Christopherson wrote: >>> On Mon, Mar 04, 2024, Quentin Perret wrote: >>>>> As discussed in the sub-thread, that might still be required. >>>>> >>>>> One could think about completely forbidding GUP on these mmap'ed >>>>> guest-memfds. But likely, there might be use cases in the future where you >>>>> want to use GUP on shared memory inside a guest_memfd. >>>>> >>>>> (the iouring example I gave might currently not work because >>>>> FOLL_PIN|FOLL_LONGTERM|FOLL_WRITE only works on shmem+hugetlb, and >>>>> guest_memfd will likely not be detected as shmem; 8ac268436e6d contains some >>>>> details) >>>> >>>> Perhaps it would be wise to start with GUP being forbidden if the >>>> current users do not need it (not sure if that is the case in Android, >>>> I'll check) ? We can always relax this constraint later when/if the >>>> use-cases arise, which is obviously much harder to do the other way >>>> around. >>> >>> +1000. At least on the KVM side, I would like to be as conservative as possible >>> when it comes to letting anything other than the guest access guest_memfd. >> >> So we'll have to do it similar to any occurrences of "secretmem" in >> gup.c. We'll have to see how to marry KVM guest_memfd with core-mm code >> similar to e.g., folio_is_secretmem(). >> >> IIRC, we might not be able to de-reference the actual mapping because it >> could get free concurrently ... >> >> That will then prohibit any kind of GUP access to these pages, including >> reading/writing for ptrace/debugging purposes, for core dumping purposes >> etc. But at least, you know that nobody was able to optain page >> references using GUP that might be used for reading/writing later. >> > > There has been little discussion about supporting 1G pages with > guest_memfd for TDX/SNP or pKVM. I would like to restart this > discussion [1]. 1G pages should be a very important usecase for guest > memfd, especially considering large VM sizes supporting confidential > GPU/TPU workloads. > > Using separate backing stores for private and shared memory ranges is > not going to work effectively when using 1G pages. Consider the > following scenario of memory conversion when using 1G pages to back > private memory: > * Guest requests conversion of 4KB range from private to shared, host > in response ideally does following steps: > a) Updates the guest memory attributes > b) Unbacks the corresponding private memory > c) Allocates corresponding shared memory or let it be faulted in > when guest accesses it > > Step b above can't be skipped here, otherwise we would have two > physical pages (1 backing private memory, another backing the shared > memory) for the same GPA range causing "double allocation". > > With 1G pages, it would be difficult to punch KBs or even MBs sized > hole since to support that: > 1G page would need to be split (which hugetlbfs doesn't support today > because of right reasons), causing - > - loss of vmemmap optimization [3] > - losing ability to reconstitute the huge page again, > especially as private pages in CVMs are not relocatable today, > increasing overall fragmentation over time. > - unless a smarter algorithm is devised for memory > reclaim to reconstitute large pages for unmovable memory. > > With the above limitations in place, best thing could be to allow: > - single backing store for both shared and private memory ranges > - host userspace to mmap the guest memfd (as this series is trying to do) > - allow userspace to fault in memfd file ranges that correspond to > shared GPA ranges > - pagetable mappings will need to be restricted to shared memory > ranges causing higher granularity mappings (somewhat similar to what > HGM series from James [2] was trying to do) than 1G. > - Allow IOMMU also to map those pages (pfns would be requested using > get_user_pages* APIs) to allow devices to access shared memory. IOMMU > management code would have to be enlightened or somehow restricted to > map only shared regions of guest memfd. > - Upon conversion from shared to private, host will have to ensure > that there are no mappings/references present for the memory ranges > being converted to private. > > If the above usecase sounds reasonable, GUP access to guest memfd > pages should be allowed. To say it with nice words: "Not a fan". First, I don't think only 1 GiB will be problematic. Already 2 MiB ones will be problematic and so far it is even unclear how guest_memfd will consume them in a way acceptable to upstream MM. Likely not using hugetlb from what I recall after the previous discussions with Mike. Second, we should find better ways to let an IOMMU map these pages, *not* using GUP. There were already discussions on providing a similar fd+offset-style interface instead. GUP really sounds like the wrong approach here. Maybe we should look into passing not only guest_memfd, but also "ordinary" memfds. Third, I don't think we should be using huge pages where huge pages don't make any sense. Using a 1 GiB page so the VM will convert some pieces to map it using PTEs will destroy the whole purpose of using 1 GiB pages. It doesn't make any sense. A direction that might make sense is either (A) enlighting the VM about the granularity in which memory can be converted (but also problematic for 1 GiB pages) and/or (B) physically restricting the memory that can be converted. For example, one could create a GPA layout where some regions are backed by gigantic pages that cannot be converted/can only be converted as a whole, and some are backed by 4k pages that can be converted back and forth. We'd use multiple guest_memfds for that. I recall that physically restricting such conversions/locations (e.g., for bounce buffers) in Linux was already discussed somewhere, but I don't recall the details. It's all not trivial and not easy to get "clean". Concluding that individual pieces of a 1 GiB / 2 MiB huge page should not be converted back and forth might be a reasonable. Although I'm sure people will argue the opposite and develop hackish solutions in desperate ways to make it work somehow. Huge pages, and especially gigantic pages, are simply a bad fit if the VM will convert individual 4k pages. But to answer your last question: we might be able to avoid GUP by using a different mapping API, similar to the once KVM now provides. -- Cheers, David / dhildenb