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 D7634C73C66 for ; Thu, 19 Jun 2025 09:46:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 51D9D6B00AF; Thu, 19 Jun 2025 05:46:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F5926B00B1; Thu, 19 Jun 2025 05:46:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 40B436B00B3; Thu, 19 Jun 2025 05:46:18 -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 34D566B00AF for ; Thu, 19 Jun 2025 05:46:18 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C0116808F7 for ; Thu, 19 Jun 2025 09:46:17 +0000 (UTC) X-FDA: 83571669594.24.8EF032A Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by imf09.hostedemail.com (Postfix) with ESMTP id 09E35140006 for ; Thu, 19 Jun 2025 09:46:14 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=htRsY4te; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf09.hostedemail.com: domain of xiaoyao.li@intel.com designates 198.175.65.12 as permitted sender) smtp.mailfrom=xiaoyao.li@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750326375; a=rsa-sha256; cv=none; b=mNJ3MPIuUMckyGUmFD8HzUoxVMVuamRO0pHdwHMCzywUBlI2jAdPOdDCwNDNEHg8GJR0e0 +lKiiXXZUF6GEZPYB32NBeJFtfrAHa0BAqS5QwXJTJiptUYhqng2oZL5CcyU/6cmTW7zbS gOExxg73wanlnY4YXYwXn6QR3VVbJy0= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=htRsY4te; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf09.hostedemail.com: domain of xiaoyao.li@intel.com designates 198.175.65.12 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=1750326375; 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=JG21Tk0yUDKGZc1iLHKkgRpYFT9z5ljWtIZTdz6rrzg=; b=agUWWlZylAwJuBgH5kMvT1H2SOTFWeRP0MEXOr2vvLhaeh45xco6LRdHAg1QayRVtT9i1f vh0DUL64WT2ZlRSVHwimpcEkf1GAVHANTrJytCi6b4CsGjOhlHe2e35PNJ1YsWz6MM+01a 7D5Ni3wJ/H+Jz1fvBw1DKa9IoONuENA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1750326375; x=1781862375; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=UuLnT9fGW+15a+efSTXHXPlypCxXcrd7PtLcffPU4io=; b=htRsY4te5oIpRdL7zDIpa4EavV2p7obnnkjel+kGl1yJFGpvBcffSAwm h8xoUI/lDiYpuJc3zf0YQ0tc7UiKSp5hJUihyNzHHYMWQTWjnhj8ZHzgV 62xS4BySkSkK/pg07mTOEHRKuLxZqzquu4oqPB5rUAkgtxFn32QzaMujY HzojgfLMnsJReasg7wmUH+kycK1eaM4Iujfv7Tu3VwmTRkzsHdI6fnIJe NlfQHLFtN1FUbq2LN/0Z+ZERQi/FgzsZ1rwzQVfx45FrSysczKCsYf9Aa hBu46dshmFEx1iXhLPfunMoFfIVc9wrEjWBhF4BSGDbeaP9pnrbDcryeY w==; X-CSE-ConnectionGUID: jNOmmzNMTbirJl5KZ2nz5A== X-CSE-MsgGUID: +WSeVoBfTlWqJz8dzPB26g== X-IronPort-AV: E=McAfee;i="6800,10657,11468"; a="64004294" X-IronPort-AV: E=Sophos;i="6.16,248,1744095600"; d="scan'208";a="64004294" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2025 02:46:04 -0700 X-CSE-ConnectionGUID: VpU8txZkSyybrd7ZTLNPZg== X-CSE-MsgGUID: Hs2fzB2LQS6Ns2HLVkksCQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,248,1744095600"; d="scan'208";a="150370624" Received: from xiaoyaol-hp-g830.ccr.corp.intel.com (HELO [10.124.247.1]) ([10.124.247.1]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2025 02:45:41 -0700 Message-ID: <30965147-24af-4dc8-aec4-781ea401a3a9@intel.com> Date: Thu, 19 Jun 2025 17:45:38 +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 Cc: Ackerley Tng , 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: <9b55acfa-688e-49da-9599-f35aee351e3d@intel.com> Content-Language: en-US From: Xiaoyao Li In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Stat-Signature: znfephi6g37b5t18e9mbtw66nfwp8y6o X-Rspamd-Queue-Id: 09E35140006 X-Rsp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qI6jHzyM98B0lOB5HOOlT7VCv5tQOet6meXV9bgbXxP+Q8+5UR7/8DS80W+fUFUGiiZQR/Z/QSMY/EqjAAqXuhxm2DD9YeiaQC0YetoCnHbE4M1YNnQvyv5McuB18cYm3ZofMMrmuLk2CFcATeiPxkOvtKtzDmJ423/rgdJ3SAcYxC7pJnE8Pu17kYX3v2URFae9XoUrVZwq9t/PE+L0o28FPrHajmUAyKkkJuQ6+Amn3mMa7/hyzCyNdB4eFvecyxyf1+s+b5hxIbJmfU1UNJ54rBDoy4HvpuDDFwz9tzrxDZuqN7mFuo9Bjtw== 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 5:28 PM, Yan Zhao wrote: > On Thu, Jun 19, 2025 at 05:18:44PM +0800, Xiaoyao Li wrote: >> On 6/19/2025 4:59 PM, Xiaoyao Li wrote: >>> 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? > However, whenever there's a GUP in TDX to get the source page, there will be an > extra page refcount. The GUP in TDX happens after the gmem converts the page to private. In the view of TDX, the physical page is converted to private already and it contains the initial content. But the content is not usable for TDX until TDX calls in-place PAGE.ADD >>> 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. > The conversion request here will be declined therefore. > > >>> 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. >> >> And maybe a new flag for KVM_GMEM_CONVERT_PRIVATE for user space to >> explicitly request that the page range is converted to private and the >> content needs to be retained. So that TDX can identify which case needs to >> call in-place TDH.PAGE.ADD. >>