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 55A95C54E5D for ; Tue, 19 Mar 2024 10:26:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9CB2F6B0082; Tue, 19 Mar 2024 06:26:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9A12B6B0083; Tue, 19 Mar 2024 06:26:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F36B6B0085; Tue, 19 Mar 2024 06:26:15 -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 67DD86B0082 for ; Tue, 19 Mar 2024 06:26:15 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 25417141054 for ; Tue, 19 Mar 2024 10:26:15 +0000 (UTC) X-FDA: 81913408710.23.A7BB858 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id A50BE16001B for ; Tue, 19 Mar 2024 10:26:12 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="I0UxxGY/"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of david@redhat.com designates 170.10.129.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=1710843972; 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=i6ZOSJeD43/crSFjue1PMzcUp2KbsGxaPoBQotC5eFo=; b=qv/TgKw2mgNMoIbJ8qhs/jK8XqRCGdDOafdA92oBF4FYGcyjxfU3n7ys3soLdJtCZ8R60g wGQMdz2e4NLXXap5t2CAkMkCnS94INfpLHh3YdpDKpz5rmst1Pap5/zfFu0KMHPnBpOEG7 GM2piTwLFtik7mGHJNMxqUf9sBlWey0= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="I0UxxGY/"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710843972; a=rsa-sha256; cv=none; b=jzSLMnKmoiXEQFagJklzt3WihCHuZAFAxQKNf354If5Jd/vvJPrvn0jzyecOsXfUKYeqce 8paKSi2pQetCqRHupN8KXgmVJ+poKgPiRLPqbZbmOV5ndZTmrjvKM/77MkHHUEWrNt/u63 5+O242fhviCKG7LkCj42npKBSP+wFIU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710843971; 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=i6ZOSJeD43/crSFjue1PMzcUp2KbsGxaPoBQotC5eFo=; b=I0UxxGY/pBn63nl9FXBmAZ3B+/MuXyYjZLjley/jTkpp07YbDCl9E5Rn1+mBoY77trwjmk co9wkrGiMQcEb/ARRkQY5XdM2O2rikGWAOtF/IfJZEePAYE9ydhl+EhvJ2Ycs62mtRUBZD e6C4YuRM2M2EXdQhmPmkTGufdsgo254= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-581-zsS5bZU7NE-mZOlODhBvtg-1; Tue, 19 Mar 2024 06:26:10 -0400 X-MC-Unique: zsS5bZU7NE-mZOlODhBvtg-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-33ed2555b61so1985836f8f.3 for ; Tue, 19 Mar 2024 03:26:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710843969; x=1711448769; 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=i6ZOSJeD43/crSFjue1PMzcUp2KbsGxaPoBQotC5eFo=; b=cHH9kLKauVF6RWrCF8N34s1aH2iBYPRg1vRNMmcJPFxyL+2k5dmyIHo2TqdLLVKCjV pXM9yC6Vo5B0NiiNmQhXT15qk4D6M287p/aoKWkdW7MFD3g+Zhm1yLptucPcLzqZHn5R dw4w7uK0bEDHeqe37ar5/rDonR+tX54eZClj88a4mAhBmrZhmDf8foRnYRgxLGDxYPH+ IwCJwAsedzyNzjkWV35i7tcp/Ls1xop8I6FlFWZPwvf4uvuBzFOqzQpVBpYV9LmBRQoK uIm5KawGL+7ZDWpgZ08+BQMec06XQr09V593JhEC6gju+Asgt8DXpFeo/KyVzbS0uhPj EU5w== X-Forwarded-Encrypted: i=1; AJvYcCWwJIUC/KmdbhAEkWEqc6P6ss6pXed9KGgqOarKR1+Qk458ZB4TuNKry1JNNUHXIkQX0qSMDkOaY4zZ5Ntmk5gT+6Y= X-Gm-Message-State: AOJu0YxO5UEdn6AVq9Qsu1F4jRo+lkcsMeDeYDgotTNUwTaxreJDc8ZL 8gunjV/VVK4lr/IFbOFxwVsBPWr0/jyJ8Z7CK6Lfuh2OL00cmfCxC8Zava/Q6TrVHeG9KvICB2S Hny2CGG56CxBLvcI3dsWMbb+h7fD7YX99Gv+ImNO3sxFZ3ujx X-Received: by 2002:adf:eb11:0:b0:33d:2472:eb8c with SMTP id s17-20020adfeb11000000b0033d2472eb8cmr9078558wrn.19.1710843969162; Tue, 19 Mar 2024 03:26:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG6i9XKzjcNwRUudCNtCW8g4HygSmm4PSLFFzmEOE/2MUnyb9ygsA4MHE3BJYL+kdOVIwDJdA== X-Received: by 2002:adf:eb11:0:b0:33d:2472:eb8c with SMTP id s17-20020adfeb11000000b0033d2472eb8cmr9078522wrn.19.1710843968572; Tue, 19 Mar 2024 03:26:08 -0700 (PDT) Received: from ?IPV6:2003:cb:c741:2200:2adc:9a8d:ae91:2e9f? (p200300cbc74122002adc9a8dae912e9f.dip0.t-ipconnect.de. [2003:cb:c741:2200:2adc:9a8d:ae91:2e9f]) by smtp.gmail.com with ESMTPSA id i18-20020adffc12000000b0033e786abf84sm12044137wrr.54.2024.03.19.03.26.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Mar 2024 03:26:08 -0700 (PDT) Message-ID: <40f82a61-39b0-4dda-ac32-a7b5da2a31e8@redhat.com> Date: Tue, 19 Mar 2024 11:26:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: folio_mmapped To: Sean Christopherson , Vishal Annapurve Cc: 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: <99a94a42-2781-4d48-8b8c-004e95db6bb5@redhat.com> <7470390a-5a97-475d-aaad-0f6dfb3d26ea@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/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ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oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+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-Rspamd-Queue-Id: A50BE16001B X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: qat3owkhmpegdo84wyi1uqmpy7gr5cy5 X-HE-Tag: 1710843972-354857 X-HE-Meta: U2FsdGVkX19LhK7Sa2tvzfNXOR6sPK553ugYdg2IYrH/+eEPSWWuSG0hZWKH/oQUx0ZzXG7K8RMWojB/giPaa0mD3R/A2BoKgThhnwR20dLqcB4TC88OJMFEk5/wyCXE/QQWLAmL6xtFO3D7lreUCv2nCTiREzQxXIEDRXiQjn4zsgUf+FOEPIGsONvqrANBW8nPZ5A0ZoM9SBka623fza8WrvXSAej9cKa7PhYE/t2S2eb7TMT589kfPPZTHE9xk3wcYR1r+BAaQq82iiBbrT5NBH5MWWHr29L7OmxVqg+dYX4xiA0wMGlkrZ6rrX22AP6Sn0/LxCJShx7Rwo0OEov7kbZBUh+JSmc8Cch5VBVv/EVE5n0agmg51cbTsH7JS38b9tCeeLzRnMLbuJDnWUv0a2GXhbBUyC1PnXfmV4jqCN39xQiM3EcYo3Lzo9E16xTZjWiXnPZcX+1k0vpUGb9UFidc8Lv4DaPMBAhr3MMJ2P7jyi1T9d9r1+PlKgxY0IuS7cQTaBocdrWwyfLG+26nNI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osity: Ham, tests=bogofilter, spamicity=0.000044, 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 19.03.24 01:10, Sean Christopherson wrote: > On Mon, Mar 18, 2024, Vishal Annapurve wrote: >> On Mon, Mar 18, 2024 at 3:02 PM David Hildenbrand wrote: >>> 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. > > +1. I am not completely opposed to letting SNP and TDX effectively convert > pages between private and shared, but I also completely agree that letting > anything gup() guest_memfd memory is likely to end in tears. Yes. Avoid it right from the start, if possible. People wanted guest_memfd to *not* have to mmap guest memory ("even for ordinary VMs"). Now people are saying we have to be able to mmap it in order to GUP it. It's getting tiring, really. > >> I need to dig into past discussions around this, but agree that >> passing guest memfds to VFIO drivers in addition to HVAs seems worth >> exploring. This may be required anyways for devices supporting TDX >> connect [1]. >> >> If we are talking about the same file catering to both private and >> shared memory, there has to be some way to keep track of references on >> the shared memory from both host userspace and IOMMU. >> >>> >>> 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. > > I don't disagree, but the fundamental problem is that we have no guarantees as to > what that guest will or will not do. We can certainly make very educated guesses, > and probably be right 99.99% of the time, but being wrong 0.01% of the time > probably means a lot of broken VMs, and a lot of unhappy customers. > Right, then don't use huge/gigantic pages. Because it doesn't make any sense. You have no guarantees about memory waste. You have no guarantee about performance. Then just don't use huge/gigantic pages. Use them where reasonable, they are an expensive resource. See below. >> I had started a discussion for this [2] using an RFC series. > > David is talking about the host side of things, AFAICT you're talking about the > guest side... > >> challenge here remain: >> 1) Unifying all the conversions under one layer >> 2) Ensuring shared memory allocations are huge page aligned at boot >> time and runtime. >> >> Using any kind of unified shared memory allocator (today this part is >> played by SWIOTLB) will need to support huge page aligned dynamic >> increments, which can be only guaranteed by carving out enough memory >> at boot time for CMA area and using CMA area for allocation at >> runtime. >> - Since it's hard to come up with a maximum amount of shared memory >> needed by VM, especially with GPUs/TPUs around, it's difficult to come >> up with CMA area size at boot time. > > ...which is very relevant as carving out memory in the guest is nigh impossible, > but carving out memory in the host for systems whose sole purpose is to run VMs > is very doable. > >> I think it's arguable that even if a VM converts 10 % of its memory to >> shared using 4k granularity, we still have fewer page table walks on >> the rest of the memory when using 1G/2M pages, which is a significant >> portion. > > Performance is a secondary concern. If this were _just_ about guest performance, > I would unequivocally side with David: the guest gets to keep the pieces if it > fragments a 1GiB page. > > The main problem we're trying to solve is that we want to provision a host such > that the host can serve 1GiB pages for non-CoCo VMs, and can also simultaneously > run CoCo VMs, with 100% fungibility. I.e. a host could run 100% non-CoCo VMs, > 100% CoCo VMs, or more likely, some sliding mix of the two. Ideally, CoCo VMs > would also get the benefits of 1GiB mappings, that's not the driving motiviation > for this discussion. Supporting 1 GiB mappings there sounds like unnecessary complexity and opening a big can of worms, especially if "it's not the driving motivation". If I understand you correctly, the scenario is (1) We have free 1 GiB hugetlb pages lying around (2) We want to start a CoCo VM (3) We don't care about 1 GiB mappings for that CoCo VM, but hguetlb pages is all we have. (4) We want to be able to use the 1 GiB hugetlb page in the future. With hugetlb, it's possible to reserve a CMA area from which to later allocate 1 GiB pages. While not allocated, they can be used for movable allocations. So in the scenario above, free the hugetlb pages back to CMA. Then, consume them as 4K pages for the CoCo VM. When wanting to start a non-CoCo VM, re-allocate them from CMA. One catch with that is that (a) CMA pages cannot get longterm-pinned: for obvious reasons, we wouldn't be able to migrate them in order to free up the 1 GiB page. (b) guest_memfd pages are not movable and cannot currently end up on CMA memory. But maybe that's not actually required in this scenario and we'd like to have slightly different semantics: if you were to give the CoCo VM the 1 GiB pages, they would similarly be unusable until that VM quit and freed up the memory! So it might be acceptable to get "selected" unmovable allocations (from guest_memfd) on selected (hugetlb) CMA area, that the "owner" will free up when wanting to re-allocate that memory. Otherwise, the CMA allocation will simply fail. If we need improvements in that area to support this case, we can talk. Just an idea to avoid HGM and friends just to make it somehow work with 1 GiB pages ... > > As HugeTLB exists today, supporting that use case isn't really feasible because > there's no sane way to convert/free just a sliver of a 1GiB page (and reconstitute > the 1GiB when the sliver is converted/freed back). > > Peeking ahead at my next comment, I don't think that solving this in the guest > is a realistic option, i.e. IMO, we need to figure out a way to handle this in > the host, without relying on the guest to cooperate. Luckily, we haven't added > hugepage support of any kind to guest_memfd, i.e. we have a fairly blank slate > to work with. > > The other big advantage that we should lean into is that we can make assumptions > about guest_memfd usage that would never fly for a general purpose backing stores, > e.g. creating a dedicated memory pool for guest_memfd is acceptable, if not > desirable, for (almost?) all of the CoCo use cases. > > I don't have any concrete ideas at this time, but my gut feeling is that this > won't be _that_ crazy hard to solve if commit hard to guest_memfd _not_ being > general purposes, and if we we account for conversion scenarios when designing > hugepage support for guest_memfd. I'm hoping guest_memfd won't end up being the wild west of hacky MM ideas ;) > >>> 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". >> >> Yeah, agree with this point, it's difficult to get a clean solution >> here, but the host side solution might be easier to deploy (not >> necessarily easier to implement) and possibly cleaner than attempts to >> regulate the guest side. > > I think we missed the opportunity to regulate the guest side by several years. > To be able to rely on such a scheme, e.g. to deploy at scale and not DoS customer > VMs, KVM would need to be able to _enforce_ the scheme. And while I am more than > willing to put my foot down on things where the guest is being blatantly ridiculous, > wanting to convert an arbitrary 4KiB chunk of memory between private and shared > isn't ridiculous (likely inefficient, but not ridiculous). I.e. I'm not willing > to have KVM refuse conversions that are legal according to the SNP and TDX specs > (and presumably the CCA spec, too). > > That's why I think we're years too late; this sort of restriction needs to go in > the "hardware" spec, and that ship has sailed. Once could consider extend the spec and glue huge+gigantic page support to new hardware. But ideally, we could just avoid any partial conversion / HGM just to support a scenario where we might not actually want 1 GiB pages, but somehow want to make it work with 1 GiB pages. -- Cheers, David / dhildenb