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 3D063C83F22 for ; Thu, 17 Jul 2025 09:41:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CCF588D0009; Thu, 17 Jul 2025 05:41:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C7FA98D0001; Thu, 17 Jul 2025 05:41:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B475E8D0009; Thu, 17 Jul 2025 05:41:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A087B8D0001 for ; Thu, 17 Jul 2025 05:41:25 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4E3BABA992 for ; Thu, 17 Jul 2025 09:41:25 +0000 (UTC) X-FDA: 83673263730.19.B55E510 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by imf25.hostedemail.com (Postfix) with ESMTP id 920EFA000B for ; Thu, 17 Jul 2025 09:41:22 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=P0uEb8DR; spf=none (imf25.hostedemail.com: domain of yilun.xu@linux.intel.com has no SPF policy when checking 198.175.65.16) smtp.mailfrom=yilun.xu@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1752745283; 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=QeKtgFvne6CFOSPBGxY/cYiBy0q/8/cWQeO4uJZcuuM=; b=JFOHUGAftufoG2aXn5ARYtmvmYYcMMHLas359jrebe0Inw8k0bn9pDf4lStbjE/pFyPJqv /zPpCwX9YWu9EsTHgXQktvZtS3miheR54I+MGxcw/wXDBTWfh8A1qT2yjuqJ3AbmrAWZw3 jP3S8prdq+LRiBWsdksMry79ocGpqgQ= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=P0uEb8DR; spf=none (imf25.hostedemail.com: domain of yilun.xu@linux.intel.com has no SPF policy when checking 198.175.65.16) smtp.mailfrom=yilun.xu@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752745283; a=rsa-sha256; cv=none; b=53DqcxpTqxcPGE5ZlxeaCY+52yLgiTBFjCtAMGKM4Q4PduaOdEJgIbk/SWzSxK062g39kU 65F7VBMFAzEOEjxgAyFjlpNr3AJYUBkPXqO8HSSe1iZRdqecTQtmYsvz9qgFeueFsfFeCV WFDTs8idc3oKy//CV5G29v/SIuyhy+M= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752745282; x=1784281282; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=f158b21SAzsqoT29eGBt9+eUZ2LbMQkUBicROPZ4jXw=; b=P0uEb8DRJslL5eDmkZPZaI7JvsoEKATv89+ngr9t5l3RdLIdZldSVyEl 2OfPJ5+onn7VhFCRtC2Pu1QG+sqEQhPo5+8Lq1o+jo7KMJiJX8rNtps6P oy+6SYU7vqPF+Y5btHI3gHOyROk3eQkl3vAZQV2a5xikzyb73VvVYB8wR 2ZxzoDVMsli32SnlmehwXqcg99TVCtxsfhem9ImQAvHyleVbn8XBaBVVy q5cOlednkoA1/N6ecU+OzbyIcbdy8XHj701QsD41bVpldFnfgzMuAlyf3 q8dsFW5wEFZpkY/hB4njz6DqWFJVtsUYg1oX1/hVXOFL7YJTbV6MdOlRM Q==; X-CSE-ConnectionGUID: TxEIJ8XARvGqkXLU62MLPQ== X-CSE-MsgGUID: xiar6CNUQi+ol9l8Rl9CIw== X-IronPort-AV: E=McAfee;i="6800,10657,11493"; a="55162698" X-IronPort-AV: E=Sophos;i="6.16,318,1744095600"; d="scan'208";a="55162698" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jul 2025 02:41:20 -0700 X-CSE-ConnectionGUID: mGURc28dR2qraEFpNo381g== X-CSE-MsgGUID: UBWhswFOQou9MrnZsXvkkA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,318,1744095600"; d="scan'208";a="157818401" Received: from yilunxu-optiplex-7050.sh.intel.com (HELO localhost) ([10.239.159.165]) by orviesa007.jf.intel.com with ESMTP; 17 Jul 2025 02:41:00 -0700 Date: Thu, 17 Jul 2025 17:32:19 +0800 From: Xu Yilun To: Ackerley Tng Cc: Yan Zhao , Vishal Annapurve , Jason Gunthorpe , Alexey Kardashevskiy , Fuad Tabba , kvm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, x86@kernel.org, linux-fsdevel@vger.kernel.org, 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, 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, thomas.lendacky@amd.com, usama.arif@bytedance.com, vbabka@suse.cz, viro@zeniv.linux.org.uk, vkuznets@redhat.com, wei.w.wang@intel.com, will@kernel.org, willy@infradead.org, xiaoyao.li@intel.com, yilun.xu@intel.com, yuzenghui@huawei.com, zhiquan1.li@intel.com Subject: Re: [RFC PATCH v2 04/51] KVM: guest_memfd: Introduce KVM_GMEM_CONVERT_SHARED/PRIVATE ioctls Message-ID: References: <9502503f-e0c2-489e-99b0-94146f9b6f85@amd.com> <20250624130811.GB72557@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspam-User: X-Rspamd-Queue-Id: 920EFA000B X-Rspamd-Server: rspam06 X-Stat-Signature: cgizzprusdaxg9kksw9c8g7j74d6epz4 X-HE-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3GQM4p2zcESYg+19+Apn/EVq3ODOky7WeRKBG+n7rOydAkMWBuYYuOlUpmUuxMJE2NL0sgmcpSj4IDrsAWl5/RHA3g2T01TanW4cV7EF5/ZGG/6BEtqzahWdQG31tbcm+V/ohnjHxxeT0tsz+Lu4MaMXAlDGx2nCft/FhVgNXmkmY2zJzqWWCKgrRAzdfod698MBR3QX+wzVy/gasAkq/UvaS2YAgeWhHOBJCoGBrl3zayHlFR4+3iTfFTCrIgjyWllHWdke1vN7poAWdngqpz9sJApmdrZYgVD/K9Jj04yiN+JPWgOIlr31su1AxyN7tm2fnGmMcJUxPVirb5RaK61vmQ95YwoWDIBwlA== 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 Wed, Jul 16, 2025 at 03:22:06PM -0700, Ackerley Tng wrote: > Yan Zhao writes: > > > On Tue, Jun 24, 2025 at 07:10:38AM -0700, Vishal Annapurve wrote: > >> On Tue, Jun 24, 2025 at 6:08 AM Jason Gunthorpe wrote: > >> > > >> > On Tue, Jun 24, 2025 at 06:23:54PM +1000, Alexey Kardashevskiy wrote: > >> > > >> > > Now, I am rebasing my RFC on top of this patchset and it fails in > >> > > kvm_gmem_has_safe_refcount() as IOMMU holds references to all these > >> > > folios in my RFC. > >> > > > >> > > So what is the expected sequence here? The userspace unmaps a DMA > >> > > page and maps it back right away, all from the userspace? The end > >> > > result will be the exactly same which seems useless. And IOMMU TLB > >> > >> As Jason described, ideally IOMMU just like KVM, should just: > >> 1) Directly rely on guest_memfd for pinning -> no page refcounts taken > >> by IOMMU stack > > In TDX connect, TDX module and TDs do not trust VMM. So, it's the TDs to inform > > TDX module about which pages are used by it for DMAs purposes. > > So, if a page is regarded as pinned by TDs for DMA, the TDX module will fail the > > unmap of the pages from S-EPT. > > > > If IOMMU side does not increase refcount, IMHO, some way to indicate that > > certain PFNs are used by TDs for DMA is still required, so guest_memfd can > > reject the request before attempting the actual unmap. > > Otherwise, the unmap of TD-DMA-pinned pages will fail. > > > > Upon this kind of unmapping failure, it also doesn't help for host to retry > > unmapping without unpinning from TD. > > > > > > Yan, Yilun, would it work if, on conversion, > > 1. guest_memfd notifies IOMMU that a conversion is about to happen for a > PFN range It is the Guest fw call to release the pinning. By the time VMM get the conversion requirement, the page is already physically unpinned. So I agree with Jason the pinning doesn't have to reach to iommu from SW POV. > 2. IOMMU forwards the notification to TDX code in the kernel > 3. TDX code in kernel tells TDX module to stop thinking of any PFNs in > the range as pinned for DMA? TDX host can't stop the pinning. Actually this mechanism is to prevent host from unpin/unmap the DMA out of Guest expectation. Thanks, Yilun > > If the above is possible then by the time we get to unmapping from > S-EPTs, TDX module would already consider the PFNs in the range "not > pinned for DMA".