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 6FAC4C7115E for ; Thu, 19 Jun 2025 08:59:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F6806B009E; Thu, 19 Jun 2025 04:59:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0CE366B009F; Thu, 19 Jun 2025 04:59:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F26656B00A0; Thu, 19 Jun 2025 04:59:50 -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 E1F036B009E for ; Thu, 19 Jun 2025 04:59:50 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 96AC3C0735 for ; Thu, 19 Jun 2025 08:59:50 +0000 (UTC) X-FDA: 83571552540.17.F295311 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) by imf09.hostedemail.com (Postfix) with ESMTP id EFE5C140003 for ; Thu, 19 Jun 2025 08:59:47 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=mb2hwxsN; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf09.hostedemail.com: domain of xiaoyao.li@intel.com designates 198.175.65.18 as permitted sender) smtp.mailfrom=xiaoyao.li@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750323588; a=rsa-sha256; cv=none; b=TFCJgCO/IWI1ILjf6VoR2y2hY8FPffnAEHfEnp48P4drxwRYB1ncfKK3YIjU31OZZDvKyb xwiVuahIb/9MByh2kYNHg57a1pvM9e66g6Ph1zskpQ1fyVQUdev49jI6iY54jrB6MtYvcb JyX1q2Dp5gvaSvSBN29gxecJXSMAXdw= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=mb2hwxsN; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf09.hostedemail.com: domain of xiaoyao.li@intel.com designates 198.175.65.18 as permitted sender) smtp.mailfrom=xiaoyao.li@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750323588; 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=lXOaYQL0GEBiXSKJU48VI9JhKxLPVSLXibLCfWCHFvo=; b=GahdsSsyeZq0sgOdOYts63EmGtJlC3il4wcJSGXywn3O9zDfcBoaOUx5rX5CA/rLFO/PT0 A2sNekhHkvy/bUlys5WE6P8oo0eZjEsa6l3w5+0x17AY7NEnp2IYE09zDXXcKsEYVS7wGi HzFCW+yCuQBdCnzrmhRw/0KMoJpigto= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750323588; x=1781859588; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=owe3gMkwVpAp73v4z8nNbjH8PCrNzNGNQ+hew74iJyA=; b=mb2hwxsNdvtTWIcknsKOzfFVDbkjjm9KEUXYAyXa8VQGaJKlWa9HSv2o uOQbexo7Zl1Tp5D6SgNtGw3e9E8BH0xBjeq/PDdj0XXgOnlP4Tr2a8kU3 OWlkn7aDCqW6I2CQ4YDHqUxsup0MFrD6AreQwpsetDEvRb4eaCypWT17J oOFq/sH5axvNPMWPCVif+yohr+GHrTfpGNJavL9WnisvML6eeRn1nK5al 66e5OI+FlN1/ZdI0hyCHGvvG9tyAHWe+y1tViRzknvOazziTTfsRkEQZQ 1s0119Xavw3FtKGXLbTsntjCgOpi9ASxVviKCZ8Ytfgo2MFqaVMz7oWqD g==; X-CSE-ConnectionGUID: XzW0AijZQBCvurVMZd8KeA== X-CSE-MsgGUID: 98zZSlqWRb2SXewO33rO9w== X-IronPort-AV: E=McAfee;i="6800,10657,11468"; a="52714155" X-IronPort-AV: E=Sophos;i="6.16,248,1744095600"; d="scan'208";a="52714155" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2025 01:59:46 -0700 X-CSE-ConnectionGUID: SrKtsgwhSnyhIqix8wJeYQ== X-CSE-MsgGUID: fD3NT5bGTWueX+jxB4MOdA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,248,1744095600"; d="scan'208";a="181616708" Received: from xiaoyaol-hp-g830.ccr.corp.intel.com (HELO [10.124.247.1]) ([10.124.247.1]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2025 01:59:17 -0700 Message-ID: Date: Thu, 19 Jun 2025 16:59:14 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v2 00/51] 1G page support for guest_memfd To: Yan Zhao , Ackerley Tng Cc: kvm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, x86@kernel.org, linux-fsdevel@vger.kernel.org, aik@amd.com, ajones@ventanamicro.com, akpm@linux-foundation.org, amoorthy@google.com, anthony.yznaga@oracle.com, anup@brainfault.org, aou@eecs.berkeley.edu, bfoster@redhat.com, binbin.wu@linux.intel.com, brauner@kernel.org, catalin.marinas@arm.com, chao.p.peng@intel.com, chenhuacai@kernel.org, dave.hansen@intel.com, david@redhat.com, dmatlack@google.com, dwmw@amazon.co.uk, erdemaktas@google.com, fan.du@intel.com, fvdl@google.com, graf@amazon.com, haibo1.xu@intel.com, hch@infradead.org, hughd@google.com, ira.weiny@intel.com, isaku.yamahata@intel.com, jack@suse.cz, james.morse@arm.com, jarkko@kernel.org, jgg@ziepe.ca, jgowans@amazon.com, jhubbard@nvidia.com, jroedel@suse.de, jthoughton@google.com, jun.miao@intel.com, kai.huang@intel.com, keirf@google.com, kent.overstreet@linux.dev, kirill.shutemov@intel.com, liam.merwick@oracle.com, maciej.wieczor-retman@intel.com, mail@maciej.szmigiero.name, maz@kernel.org, mic@digikod.net, michael.roth@amd.com, mpe@ellerman.id.au, muchun.song@linux.dev, nikunj@amd.com, nsaenz@amazon.es, oliver.upton@linux.dev, palmer@dabbelt.com, pankaj.gupta@amd.com, paul.walmsley@sifive.com, pbonzini@redhat.com, pdurrant@amazon.co.uk, peterx@redhat.com, pgonda@google.com, pvorel@suse.cz, qperret@google.com, quic_cvanscha@quicinc.com, quic_eberman@quicinc.com, quic_mnalajal@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, quic_svaddagi@quicinc.com, quic_tsoni@quicinc.com, richard.weiyang@gmail.com, rick.p.edgecombe@intel.com, rientjes@google.com, roypat@amazon.co.uk, rppt@kernel.org, seanjc@google.com, shuah@kernel.org, steven.price@arm.com, steven.sistare@oracle.com, suzuki.poulose@arm.com, tabba@google.com, thomas.lendacky@amd.com, usama.arif@bytedance.com, vannapurve@google.com, vbabka@suse.cz, viro@zeniv.linux.org.uk, vkuznets@redhat.com, wei.w.wang@intel.com, will@kernel.org, willy@infradead.org, yilun.xu@intel.com, yuzenghui@huawei.com, zhiquan1.li@intel.com References: Content-Language: en-US From: Xiaoyao Li In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Stat-Signature: bsbsx1tiz4y3mfr3qmsbzwo3ejknd1ek X-Rspamd-Queue-Id: EFE5C140003 X-Rspamd-Server: rspam02 X-HE-Tag: 1750323587-222872 X-HE-Meta: U2FsdGVkX1+byo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G61k0oKt+oVFZLZbJyZWqYxWwLp7cZOAhVvb2t4qNKK1RzIRRfXDOJPhitbX6FX1ytG0LkggGTm3J+EGkcfs0MdCYgpbhvziG8BJZ6KC5tRtohIcVjrIVdTDNxG8ytlmni5iAYjFZ2ZyTivl92f6PQ5m0qftpnmNrOP5+K+Cd1X1uGbzHlUW9lhfxim92167CUlJ7GZQXygRlzXTyjv2VFAklzOPMVhxoZBcz3gp4VSSZ6ogAV+iMULp6llsywKvsEfGibQ== 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 6/19/2025 4:13 PM, Yan Zhao wrote: > On Wed, May 14, 2025 at 04:41:39PM -0700, Ackerley Tng wrote: >> Hello, >> >> This patchset builds upon discussion at LPC 2024 and many guest_memfd >> upstream calls to provide 1G page support for guest_memfd by taking >> pages from HugeTLB. >> >> This patchset is based on Linux v6.15-rc6, and requires the mmap support >> for guest_memfd patchset (Thanks Fuad!) [1]. >> >> For ease of testing, this series is also available, stitched together, >> at https://github.com/googleprodkernel/linux-cc/tree/gmem-1g-page-support-rfc-v2 > > Just to record a found issue -- not one that must be fixed. > > In TDX, the initial memory region is added as private memory during TD's build > time, with its initial content copied from source pages in shared memory. > The copy operation requires simultaneous access to both shared source memory > and private target memory. > > Therefore, userspace cannot store the initial content in shared memory at the > mmap-ed VA of a guest_memfd that performs in-place conversion between shared and > private memory. This is because the guest_memfd will first unmap a PFN in shared > page tables and then check for any extra refcount held for the shared PFN before > converting it to private. I have an idea. If I understand correctly, the KVM_GMEM_CONVERT_PRIVATE of in-place conversion unmap the PFN in shared page tables while keeping the content of the page unchanged, right? So KVM_GMEM_CONVERT_PRIVATE can be used to initialize the private memory actually for non-CoCo case actually, that userspace first mmap() it and ensure it's shared and writes the initial content to it, after it userspace convert it to private with KVM_GMEM_CONVERT_PRIVATE. For CoCo case, like TDX, it can hook to KVM_GMEM_CONVERT_PRIVATE if it wants the private memory to be initialized with initial content, and just do in-place TDH.PAGE.ADD in the hook. > Currently, we tested the initial memory region using the in-place conversion > version of guest_memfd as backend by modifying QEMU to add an extra anonymous > backend to hold the source initial content in shared memory. The extra anonymous > backend is freed after finishing ading the initial memory region. > > This issue is benign for TDX, as the initial memory region can also utilize the > traditional guest_memfd, which only allows 4KB mappings. This is acceptable for > now, as the initial memory region typically involves a small amount of memory, > and we may not enable huge pages for ranges covered by the initial memory region > in the near future.