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 AA581C02185 for ; Mon, 20 Jan 2025 09:27:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3EE526B0088; Mon, 20 Jan 2025 04:27:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C3E0280002; Mon, 20 Jan 2025 04:27:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2173C280001; Mon, 20 Jan 2025 04:27:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 013116B0088 for ; Mon, 20 Jan 2025 04:27:02 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A30F71C9F3B for ; Mon, 20 Jan 2025 09:27:02 +0000 (UTC) X-FDA: 83027301084.19.BA8CB75 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf19.hostedemail.com (Postfix) with ESMTP id 2822F1A0013 for ; Mon, 20 Jan 2025 09:26:59 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=sdbXDw5m; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=USaH9ikl; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=sdbXDw5m; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=USaH9ikl; dmarc=none; spf=pass (imf19.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737365220; a=rsa-sha256; cv=none; b=k8k/KKnnbqezVUCyZxqyVatZLhqw6QjDSr2t37ka4z904cAe/0bOvIeAqkMgGBfgVY4tUV O+xlcjMgsneUV8D6rYslmg4c9uS10MuWOuNj1w75YQT2OxZYkbQJTflal3V+oVs3bHnfa2 0mnIvPjKS2Ne6RykjT9OFMrXuBUl7dI= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=sdbXDw5m; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=USaH9ikl; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=sdbXDw5m; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=USaH9ikl; dmarc=none; spf=pass (imf19.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737365220; 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=bv6KB66AQ+hDsgqF2IhGJ+tldjMx6QQt1nxuy0Q52+w=; b=KqbRIAO52dJE5Z2AjN2+GR2eZ7VjXh8fGO/eJnLqIoWmm5pAWkemf3JzR7/75RcgBolts1 84iEjvXogAAeew2jfwOaWGMqp4heeUWUlJAFHeHxmeszrL+bPEYosym8ne96WEN3rVK9aF Yf0d9PvK3KKYlTUNUUHi+55b3vXhGwQ= Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1B5E51F7A5; Mon, 20 Jan 2025 09:26:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1737365218; h=from:from:reply-to: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=bv6KB66AQ+hDsgqF2IhGJ+tldjMx6QQt1nxuy0Q52+w=; b=sdbXDw5mVVlck7Fyr8xDAw8Pg426CrkvDWcb+S05GLUXdq2wMM1tdVqx4Ueg/8/6armRYs z2/MOuOREa4KYz0knsrXCjezUJAWBtro/vpGH/1zaiAJn0C6NyXfLbYFjTUNQknNMS0r+s S/QMU+iaylh6QaZ/2WuuCE0VLhBF4r8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1737365218; h=from:from:reply-to: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=bv6KB66AQ+hDsgqF2IhGJ+tldjMx6QQt1nxuy0Q52+w=; b=USaH9iklyq1L1vL7LVhOtwTNtEXFrf/PXsAe/YCSpq8dr2omufIQY5GupxIc1jD8plv08z Eqw6k7rBa4Jk/TDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1737365218; h=from:from:reply-to: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=bv6KB66AQ+hDsgqF2IhGJ+tldjMx6QQt1nxuy0Q52+w=; b=sdbXDw5mVVlck7Fyr8xDAw8Pg426CrkvDWcb+S05GLUXdq2wMM1tdVqx4Ueg/8/6armRYs z2/MOuOREa4KYz0knsrXCjezUJAWBtro/vpGH/1zaiAJn0C6NyXfLbYFjTUNQknNMS0r+s S/QMU+iaylh6QaZ/2WuuCE0VLhBF4r8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1737365218; h=from:from:reply-to: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=bv6KB66AQ+hDsgqF2IhGJ+tldjMx6QQt1nxuy0Q52+w=; b=USaH9iklyq1L1vL7LVhOtwTNtEXFrf/PXsAe/YCSpq8dr2omufIQY5GupxIc1jD8plv08z Eqw6k7rBa4Jk/TDA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 954B21393E; Mon, 20 Jan 2025 09:26:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id P8j8I+EWjmeQFgAAD6G6ig (envelope-from ); Mon, 20 Jan 2025 09:26:57 +0000 Message-ID: Date: Mon, 20 Jan 2025 10:26:57 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v4 00/14] KVM: Restricted mapping of guest_memfd at the host and arm64 support To: Fuad Tabba , Ackerley Tng Cc: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org, pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, willy@infradead.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, vannapurve@google.com, mail@maciej.szmigiero.name, david@redhat.com, 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_eberman@quicinc.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, qperret@google.com, keirf@google.com, roypat@amazon.co.uk, shuah@kernel.org, hch@infradead.org, jgg@nvidia.com, rientjes@google.com, jhubbard@nvidia.com, fvdl@google.com, hughd@google.com, jthoughton@google.com References: From: Vlastimil Babka Content-Language: en-US Autocrypt: addr=vbabka@suse.cz; keydata= xsFNBFZdmxYBEADsw/SiUSjB0dM+vSh95UkgcHjzEVBlby/Fg+g42O7LAEkCYXi/vvq31JTB KxRWDHX0R2tgpFDXHnzZcQywawu8eSq0LxzxFNYMvtB7sV1pxYwej2qx9B75qW2plBs+7+YB 87tMFA+u+L4Z5xAzIimfLD5EKC56kJ1CsXlM8S/LHcmdD9Ctkn3trYDNnat0eoAcfPIP2OZ+ 9oe9IF/R28zmh0ifLXyJQQz5ofdj4bPf8ecEW0rhcqHfTD8k4yK0xxt3xW+6Exqp9n9bydiy tcSAw/TahjW6yrA+6JhSBv1v2tIm+itQc073zjSX8OFL51qQVzRFr7H2UQG33lw2QrvHRXqD Ot7ViKam7v0Ho9wEWiQOOZlHItOOXFphWb2yq3nzrKe45oWoSgkxKb97MVsQ+q2SYjJRBBH4 8qKhphADYxkIP6yut/eaj9ImvRUZZRi0DTc8xfnvHGTjKbJzC2xpFcY0DQbZzuwsIZ8OPJCc LM4S7mT25NE5kUTG/TKQCk922vRdGVMoLA7dIQrgXnRXtyT61sg8PG4w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KGVxHrqD39XSw8hxK61pw8p90pg4G /N3iuWEvyt+t0SxDDkClnGsDyRhlUyEWYFEoBrrCizbmahOUwqkJbNMfzj5Y7n7OIJOxNRkB IBOjPdF26dMP69BwePQao1M8Acrrex9sAHYjQGyVmReRjVEtv9iG4DoTsnIR3amKVk6si4Ea X/mrapJqSCcBUVYUFH8M7bsm4CSxier5ofy8jTEa/CfvkqpKThTMCQPNZKY7hke5qEq1CBk2 wxhX48ZrJEFf1v3NuV3OimgsF2odzieNABEBAAHCwXwEGAEKACYCGwwWIQSpQNQ0mSwujpkQ PVAiT6fnzIKmZAUCZAUSmwUJDK5EZgAKCRAiT6fnzIKmZOJGEACOKABgo9wJXsbWhGWYO7mD 8R8mUyJHqbvaz+yTLnvRwfe/VwafFfDMx5GYVYzMY9TWpA8psFTKTUIIQmx2scYsRBUwm5VI EurRWKqENcDRjyo+ol59j0FViYysjQQeobXBDDE31t5SBg++veI6tXfpco/UiKEsDswL1WAr tEAZaruo7254TyH+gydURl2wJuzo/aZ7Y7PpqaODbYv727Dvm5eX64HCyyAH0s6sOCyGF5/p eIhrOn24oBf67KtdAN3H9JoFNUVTYJc1VJU3R1JtVdgwEdr+NEciEfYl0O19VpLE/PZxP4wX PWnhf5WjdoNI1Xec+RcJ5p/pSel0jnvBX8L2cmniYnmI883NhtGZsEWj++wyKiS4NranDFlA HdDM3b4lUth1pTtABKQ1YuTvehj7EfoWD3bv9kuGZGPrAeFNiHPdOT7DaXKeHpW9homgtBxj 8aX/UkSvEGJKUEbFL9cVa5tzyialGkSiZJNkWgeHe+jEcfRT6pJZOJidSCdzvJpbdJmm+eED w9XOLH1IIWh7RURU7G1iOfEfmImFeC3cbbS73LQEFGe1urxvIH5K/7vX+FkNcr9ujwWuPE9b 1C2o4i/yZPLXIVy387EjA6GZMqvQUFuSTs/GeBcv0NjIQi8867H3uLjz+mQy63fAitsDwLmR EP+ylKVEKb0Q2A== In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Enc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phSmMQKD2n7S78AKO4Q/pUSL6VZumr Ob7AxKxB 2t/gm58P9bmbEAroLV+Ux7PkkPdsnZNfP5u5P2rL6Bj0uoMCbaBQ3JjIHVojo38A0gZ4jjGtLRnnMM3NlYh2vhIq7+VRl5cH9L0g6VP2Osb0XMbkqTMIZXG1GNPPUXXeBMTnXcW9U9vUvKfterijovPbdxH9lh4UH2tKOuFlnbOSNZYBBtmRrB+osQ1yCM+ocBcWyIRlF52nxQnyGyx/+AHj03Xr3xBQ2H0ZoffchgDR3NRTRd9fe+5jqVH2oXkJCqZ/fUNPSHFNybQ598mFufB/nU+7bOqAcZXfYSy+bDkQnH5zGqwbnp/CTpsfIdGKIR9BKTIWtRjFJz6oRVnWVnv/dQnJly9LDh15RxwpSaQiDragOyie/n+/t7FtoK7QbQuhTRp8PTjMYyd5tNQ2CSQe/WeAA64x0arjh9torfnPrYsucFGWfUqKDPM096zenzVVJLUMTEPzZveR6L1ys8Jcuo0Eu9uB+WjoUZlcOZmpGC2ORQizz0Tz+3JMjyy4dLVWG3Ys7mfg/FpZTkrAQzM0iMqhLiVMAik+nA2zGBPf/twzGKZEIjgrQ56ZhAzG4sNo+PlWZC67ov4ma+cVRy/ZWnA== 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 1/16/25 10:19, Fuad Tabba wrote: > Hi Ackerley, > > On Thu, 16 Jan 2025 at 00:35, Ackerley Tng wrote: >> >> Registration of the folio_put() callback only happens if the VMM >> actually tries to do vcpu_run(). For 4K folios I think this is okay >> since the 4K folio can be freed via the transition state K -> state I, >> but for hugetlb folios that have been split for sharing with userspace, >> not getting a folio_put() callback means never putting the hugetlb folio >> together. Hence, relying on vcpu_run() to add the folio_put() callback >> leaves a way that hugetlb pages can be removed from the system. >> >> I think we should try and find a path forward that works for both 4K and >> hugetlb folios. > > I agree, this could be an issue, but we could find other ways to > trigger the callback for huge folios. The important thing I was trying > to get to is how to have the callback and be able to register it. > >> IIUC page._mapcount and page.page_type works as a union because >> page_type is only set for page types that are never mapped to userspace, >> like PGTY_slab, PGTY_offline, etc. > > In the last guest_memfd sync, David Hildenbrand mentioned that that > would be a temporary restriction since the two structures would > eventually be decoupled, work being done by Matthew Wilcox I believe. Note the "temporary" might be few years still, it's a long-term project. >> Technically PGTY_guest_memfd is only set once the page can never be >> mapped to userspace, but PGTY_guest_memfd can only be set once mapcount >> reaches 0. Since mapcount is added in the faulting process, could gmem >> perhaps use some kind of .unmap/.unfault callback, so that gmem gets >> notified of all unmaps and will know for sure that the mapcount gets to >> 0? > > I'm not sure if there is such a callback. If there were, I'm not sure > what that would buy us really. The main pain point is the refcount > going down to zero. The mapcount part is pretty straightforard and > likely to be only temporary as mentioned, i.e., when it get decoupled, > we could register the callback earlier and simplify the transition > altogether. > >> Alternatively, I took a look at the folio_is_zone_device() >> implementation, and page.flags is used to identify the page's type. IIUC >> a ZONE_DEVICE page also falls in the intersection of needing a >> folio_put() callback and can be mapped to userspace. Could we use a >> similar approach, using page.flags to identify a page as a guest_memfd >> page? That way we don't need to know when unmapping happens, and will >> always be able to get a folio_put() callback. > > Same as above, with this being temporary, adding a new page flag might > not be something that the rest of the community might be too excited > about :) Yeah, adding a page flag is very difficult these days. Also while it's technically true that being a ZONE_DEVICE page is recorded in the page flags field, it's not really a separate flag - just that some bits of the flags field encode the zonenum. But zonenum is a number, not independent flags - i.e. there can be up to 8 zones, using up to 3 flag bits. And page's zonenum also has to match the zone's pfn range, so we couldn't just change the zone of a page to some hypothetical ZONE_MEMFD when it becomes used for memfd. > Thanks for your comments! > /fuad > >> [1] https://lpc.events/event/18/contributions/1758/attachments/1457/3699/Guestmemfd%20folio%20state%20page_type.pdf >> [2] https://android-kvm.googlesource.com/linux/+/764360863785ba16d974253a572c87abdd9fdf0b%5E%21/#F0 >> >> > This patch series doesn't necessarily impose all these transitions, >> > many of them would be a matter of policy. This just happens to be the >> > current way I've done it with pKVM/arm64. >> > >> > Cheers, >> > /fuad >> > >> > On Fri, 13 Dec 2024 at 16:48, Fuad Tabba wrote: >> >> >> >> This series adds restricted mmap() support to guest_memfd, as >> >> well as support for guest_memfd on arm64. It is based on Linux >> >> 6.13-rc2. Please refer to v3 for the context [1]. >> >> >> >> Main changes since v3: >> >> - Added a new folio type for guestmem, used to register a >> >> callback when a folio's reference count reaches 0 (Matthew >> >> Wilcox, DavidH) [2] >> >> - Introduce new mappability states for folios, where a folio can >> >> be mappable by the host and the guest, only the guest, or by no >> >> one (transient state) >> >> - Rebased on Linux 6.13-rc2 >> >> - Refactoring and tidying up >> >> >> >> Cheers, >> >> /fuad >> >> >> >> [1] https://lore.kernel.org/all/20241010085930.1546800-1-tabba@google.com/ >> >> [2] https://lore.kernel.org/all/20241108162040.159038-1-tabba@google.com/ >> >> >> >> Ackerley Tng (2): >> >> KVM: guest_memfd: Make guest mem use guest mem inodes instead of >> >> anonymous inodes >> >> KVM: guest_memfd: Track mappability within a struct kvm_gmem_private >> >> >> >> Fuad Tabba (12): >> >> mm: Consolidate freeing of typed folios on final folio_put() >> >> KVM: guest_memfd: Introduce kvm_gmem_get_pfn_locked(), which retains >> >> the folio lock >> >> KVM: guest_memfd: Folio mappability states and functions that manage >> >> their transition >> >> KVM: guest_memfd: Handle final folio_put() of guestmem pages >> >> KVM: guest_memfd: Allow host to mmap guest_memfd() pages when shared >> >> KVM: guest_memfd: Add guest_memfd support to >> >> kvm_(read|/write)_guest_page() >> >> KVM: guest_memfd: Add KVM capability to check if guest_memfd is host >> >> mappable >> >> KVM: guest_memfd: Add a guest_memfd() flag to initialize it as >> >> mappable >> >> KVM: guest_memfd: selftests: guest_memfd mmap() test when mapping is >> >> allowed >> >> KVM: arm64: Skip VMA checks for slots without userspace address >> >> KVM: arm64: Handle guest_memfd()-backed guest page faults >> >> KVM: arm64: Enable guest_memfd private memory when pKVM is enabled >> >> >> >> Documentation/virt/kvm/api.rst | 4 + >> >> arch/arm64/include/asm/kvm_host.h | 3 + >> >> arch/arm64/kvm/Kconfig | 1 + >> >> arch/arm64/kvm/mmu.c | 119 +++- >> >> include/linux/kvm_host.h | 75 +++ >> >> include/linux/page-flags.h | 22 + >> >> include/uapi/linux/kvm.h | 2 + >> >> include/uapi/linux/magic.h | 1 + >> >> mm/debug.c | 1 + >> >> mm/swap.c | 28 +- >> >> tools/testing/selftests/kvm/Makefile | 1 + >> >> .../testing/selftests/kvm/guest_memfd_test.c | 64 +- >> >> virt/kvm/Kconfig | 4 + >> >> virt/kvm/guest_memfd.c | 579 +++++++++++++++++- >> >> virt/kvm/kvm_main.c | 229 ++++++- >> >> 15 files changed, 1074 insertions(+), 59 deletions(-) >> >> >> >> >> >> base-commit: fac04efc5c793dccbd07e2d59af9f90b7fc0dca4 >> >> -- >> >> 2.47.1.613.gc27f4b7a9f-goog >> >>