From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C47DB80BEB for ; Tue, 19 Mar 2024 13:19:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710854386; cv=none; b=C7pYCMkzwMkvSenCOnPgsgaHfE2bRWyn/bNov/EZ06fIba5fza15CDcjcWWfkp3FnN9Z4j5MlgYqhj7NhjP8A3IC4F6sqmuVYzZCsuEi7j+PmqWs/AiYEp7NdwWUivSYLSdX/XPqHSdJtjafnHS32M1+rmwysFPGOci4eoaXcKY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710854386; c=relaxed/simple; bh=pqLK5r+6glGRViAulW3S3Y5ve9BzKiH6gJ4YPllNek0=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=ClzqGCg7VKwbgmqCrjPUAe1snzOBBBEnEsMa+XFjOlhSmlVNlMe8/DGvK2Kyn8dEnM0xjxCCQ1j6UCZxWooRRDSEccDmEA02CctfvUR8RJuFu2TggV8N3DVY+A2BC5J71TaYg9OEBbm5aMyC/L/rd+YW6813Ag/WLQJPdcWtG6U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=KsOg7gE+; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KsOg7gE+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710854383; 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=pUA4jyYPpyLWZ5GdB21IaWHY0bnpxN+yp5QXHB7m1nw=; b=KsOg7gE+qLcjxhdrb4iYVmNko7Gyqu129nTiTk8aDsjW8Y55RhaaZqjD5c1XBCJkUw+Vgj HwVft3vRsn8Pp6487oBVJxa222votxCXqfClpPD1bPPRNdEuhHK8trhyfy1pzvTG+5vdXq m8jJUSoYBfjXKpeuk11OqvXSKzmiqH0= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-203-16SGz9S1PVu-bVl4LIHIXQ-1; Tue, 19 Mar 2024 09:19:42 -0400 X-MC-Unique: 16SGz9S1PVu-bVl4LIHIXQ-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-40e53200380so26465425e9.3 for ; Tue, 19 Mar 2024 06:19:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710854381; x=1711459181; h=content-transfer-encoding:in-reply-to:organization:autocrypt :references:cc:to:from:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=pUA4jyYPpyLWZ5GdB21IaWHY0bnpxN+yp5QXHB7m1nw=; b=ECV4hFHwLdZ+b/JQ5M52Q7fKrDvdr/5js18wCi0MuemjyiML8j8aiPW2MM0MIlhsgC +4nmr1WVCobpBzVpoIpdvoxQ7FlEbly/f51yz1AtM94GinJuxvc9lhnYRZOuAUUN3HWM KNMopw8TDbhjaNY+5JVZnlixoLMlyFktPxVqo6a0s82JlE2N2tQg+9J/2pZK6UkZezi/ 2aEQVNs4klmua+1psqlvhCRVXdKQfp+hmRG0MqWe8I5WVwCX1mTXrRYPXXr4YUHQ4xpU itvZkDmL3lItAAmCEu54Jk9Iz3HnDT+jrMqhxR+bf4m4Gf8ZZ+d+rL883sVJ68+hsMtd m0hw== X-Forwarded-Encrypted: i=1; AJvYcCVIvD0PE1LaIazhWTC4enyps7UZyS8aXo29mo/Tbi225hKoLSu1JUksONenR/Mf8F7x8pisNkITA3dtIK9n10fJmhmHU3Qp X-Gm-Message-State: AOJu0Yxso6Xt5k1hM7m51mgOg9SIA2svj6YCi8lMxqvflgZDa4HTjxOO Dr0FDz6Oj5MaWLvko3kbk1OPVgJwKD1Ku6jkBptCA1U7M1wgxBfWOp7Cl+p8vUGD0uf7S1E+jUH q7vH0cjFz2wrVqTmapKP9uKM5YnHs12h7YPnuhpEmR54bHEQCB+Wb8A== X-Received: by 2002:a05:600c:1d0e:b0:413:3941:d9ae with SMTP id l14-20020a05600c1d0e00b004133941d9aemr10729831wms.31.1710854381205; Tue, 19 Mar 2024 06:19:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQggSEygSN3zjaUeleSU2az0Hn2tbOnGs4AaLWZpa++FmT1PitVXiZZMyXBncQjc3UEteHOA== X-Received: by 2002:a05:600c:1d0e:b0:413:3941:d9ae with SMTP id l14-20020a05600c1d0e00b004133941d9aemr10729813wms.31.1710854380767; Tue, 19 Mar 2024 06:19:40 -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 fj14-20020a05600c0c8e00b00413385ec7e6sm21514330wmb.47.2024.03.19.06.19.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Mar 2024 06:19:40 -0700 (PDT) Message-ID: <0b1e1054-012f-4cc3-9d25-1147fa8cd6f0@redhat.com> Date: Tue, 19 Mar 2024 14:19:37 +0100 Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: folio_mmapped From: David Hildenbrand 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> <40f82a61-39b0-4dda-ac32-a7b5da2a31e8@redhat.com> Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0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I9XQssfrf4Gusdqx8nPEpfOqCtbbwJMATbHyqLt7/oz/5deGuwxgb65pWIzufa N7eop7uh+6bezi+rugUI+w6DABEBAAHCwXwEGAEIACYCGwwWIQQb2cqtc1xMOkYN/MpN3hD3 AP+DWgUCXw7HsgUJEqkpoQAKCRBN3hD3AP+DWrrpD/4qS3dyVRxDcDHIlmguXjC1Q5tZTwNB boaBTPHSy/Nksu0eY7x6HfQJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+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: <40f82a61-39b0-4dda-ac32-a7b5da2a31e8@redhat.com> 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: 7bit >>> 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 ... Thought about that some more and some cases can also be tricky (avoiding fragmenting multiple 1 GiB pages ...). It's all tricky, especially once multiple (guest_)memfds are involved and we really want to avoid most waste. Knowing that large mappings for CoCo are rather "optional" and that the challenge is in "reusing" large pages is valuable, though. -- Cheers, David / dhildenb