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 35B84C8303C for ; Fri, 11 Jul 2025 04:40:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CA23E6B008A; Fri, 11 Jul 2025 00:40:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C79796B0092; Fri, 11 Jul 2025 00:40:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8F026B0093; Fri, 11 Jul 2025 00:40:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id AD9316B008A for ; Fri, 11 Jul 2025 00:40:43 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 263FE161C92 for ; Fri, 11 Jul 2025 04:40:43 +0000 (UTC) X-FDA: 83650733166.07.E478DB2 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by imf13.hostedemail.com (Postfix) with ESMTP id 513ED2000D for ; Fri, 11 Jul 2025 04:40:40 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=dMfaT9bp; spf=none (imf13.hostedemail.com: domain of yilun.xu@linux.intel.com has no SPF policy when checking 192.198.163.7) 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=1752208840; 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=R/znoVT5mTB7mNhJZPrMFel4AcrJrAgB6tqpnT6eVmQ=; b=DiYe8so/a6d8JC3Mx661iQ//LZv3bknzVkuIKijkK2kJvTZ8+8CcBRN0Nl8hjVkHsot7A1 +yQ9ENQelzQrnMyEWPIBGJW97gt9Ntktcyo9L4rELqMpqReL57lmTqPED3WK2uy9WS48jm HCKsE8gRiRjuY9zdZlgvELTElN18sfc= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=dMfaT9bp; spf=none (imf13.hostedemail.com: domain of yilun.xu@linux.intel.com has no SPF policy when checking 192.198.163.7) 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=1752208840; a=rsa-sha256; cv=none; b=iuN7PLJvJaCHtSiGUWfSMqcrPFFBWxFziDzBpJVeg7ogcgWvPsoKAg6RTxidnH53B0b5OZ pdT+n9pLEbPOkHwk+ZNzb03X8jJjIE9icxQan1MVJSFe7MwuZHm4hUY47aUk6e+qgVXHoO Y9V8MJPgRMxssg16n7wHkYntZpzte/o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1752208840; x=1783744840; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=R0JRR0jPdWQFsnHeDQicLF6rapHJfa6O3V7xWIsXrEc=; b=dMfaT9bp6HdiW/xd4wPYjOF7dgP8Jc2DU2n2aGJEmOp9XuO0KRWKi/1/ KBKFaRbSW5L02+DStsInx8kIKA5wFMWBB0JJQlWKO1zxnowlV+TUqLQPc QgtAy+58vPCT+8TKMBVNKymgvXOgHxt07xQXOkySSlLcJWJRLWHvVwxe8 ckqM+UoPoZ3nMFmF0cWA3W5DvglOma3ca+dlXiKg0MR7bamslvCZdxl+D WIXWHsR+bmIrcEmcUISRHeetAQASvRZT7R1pv/+ieGctVySfbMBTDooAR k3R7OhXA3k+iZdc8f1Z4M9RXuIi67Qr6bOEkU3dvqdmGT3+FdMBGZaFj7 w==; X-CSE-ConnectionGUID: q0hTyp0ZRrimQL73D3SgyA== X-CSE-MsgGUID: iaFEU0WTQjO4ZYJl/yoaFw== X-IronPort-AV: E=McAfee;i="6800,10657,11490"; a="79934962" X-IronPort-AV: E=Sophos;i="6.16,302,1744095600"; d="scan'208";a="79934962" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jul 2025 21:40:38 -0700 X-CSE-ConnectionGUID: klaS2TZATH+2blf4tv6DUQ== X-CSE-MsgGUID: uYwPD74pRiG2cr/33/gDWQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,302,1744095600"; d="scan'208";a="155685771" Received: from yilunxu-optiplex-7050.sh.intel.com (HELO localhost) ([10.239.159.165]) by orviesa010.jf.intel.com with ESMTP; 10 Jul 2025 21:40:19 -0700 Date: Fri, 11 Jul 2025 12:31:56 +0800 From: Xu Yilun To: Jason Gunthorpe Cc: Vishal Annapurve , Yan Zhao , Alexey Kardashevskiy , Fuad Tabba , Ackerley Tng , 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> <20250702141321.GC904431@ziepe.ca> <20250710175449.GA1870174@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20250710175449.GA1870174@ziepe.ca> X-Rspamd-Queue-Id: 513ED2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92GIg Ko81VgfTJpGg1AjlzFemj9/fCExV7CjK4wq+RMnLG/7yJrL4qWuGWxRwHtxRbOjkiteA5AIpmYQ2582PuRpq/0hOBbehCpndrPB7txTFBV3BIdVkl0Xbex+ea/PwVIXAo2QkwwVRdBfAmIZzaiePNQPdjEnXd5F92rIVZ4YgEGdukr82nKxVH+kwFv0kEvcdpvd3N+t50ttVcELQe8RxVePFIbsQ3mSwRWouUXMwTp36AyD1rWI/hquzZkmNHMT9oAj7Ca5Jb74IzydBPcJICT9pq9HcT7UKHPFb8zlNaVDecMG/lMIKYrn/dHV0QHSn1cM71J4JhosTnsdtTPmCSdkfYK6Dx1anmejZfgfy/NyCOrrbEDVENbjSaXad6YQavgja2vOiVekBvcZiDchSJZV+HTw== 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 Thu, Jul 10, 2025 at 02:54:49PM -0300, Jason Gunthorpe wrote: > On Thu, Jul 10, 2025 at 06:50:09PM +0800, Xu Yilun wrote: > > On Wed, Jul 02, 2025 at 07:32:36AM -0700, Vishal Annapurve wrote: > > > On Wed, Jul 2, 2025 at 7:13 AM Jason Gunthorpe wrote: > > > > > > > > On Wed, Jul 02, 2025 at 06:54:10AM -0700, Vishal Annapurve wrote: > > > > > On Wed, Jul 2, 2025 at 1:38 AM Yan Zhao wrote: > > > > > > > > > > > > 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. > > > > > > > > I don't see this as having much to do with iommufd. > > > > > > > > iommufd will somehow support the T=1 iommu inside the TDX module but > > > > it won't have an IOAS for it since the VMM does not control the > > > > translation. > > > > I partially agree with this. > > > > This is still the DMA Silent drop issue for security. The HW (Also > > applicable to AMD/ARM) screams out if the trusted DMA path (IOMMU > > mapping, or access control table like RMP) is changed out of TD's > > expectation. So from HW POV, it is the iommu problem. > > I thought the basic idea was that the secure world would sanity check > what the insecure is doing and if it is not OK then it blows up. So if Yes. The secure world checks. But it let alone the unexpected change on CPU path cause CPU is synchronous and VM just pends on the fault, no security concern. While DMA is asynchronous and the secure world must blow up. > the DMA fails because the untrusted world revoked sharability when it > should not have then this is correct and expected? OK. From secure world POV the failing is correct & expected. > > > For SW, if we don't blame iommu, maybe we rephrase as gmemfd can't > > invalidate private pages unless TD agrees. > > I think you mean guestmemfd in the kernel cannot autonomously change > 'something' unless instructed to explicitly by userspace. > > The expectation is the userspace will only give such instructions > based on the VM telling it to do a shared/private change. > > If userspace gives an instruction that was not agreed with the guest > then the secure world can police the error and blow up. Yes. > > > Just to be clear. With In-place conversion, it is not KVM gives pages > > to become secure, it is gmemfd. Or maybe you mean gmemfd is part of KVM. > > Yeah, I mean part of. > > > > > Obviously in a mode where there is a vPCI device we will need all the > > > > pages to be pinned in the guestmemfd to prevent any kind of > > > > migrations. Only shared/private conversions should change the page > > > > around. > > > > Only *guest permitted* conversion should change the page. I.e only when > > VMM is dealing with the KVM_HC_MAP_GPA_RANGE hypercall. Not sure if we > > could just let QEMU ensure this or KVM/guestmemfd should ensure this. > > I think it should not be part of the kernel, no need. From a kernel > perspective userspace has requested a shared/private conversion and if > it wasn't agreed with the VM then it will explode. I'm OK with it now. It's simple if we don't try to recover from the explosion. Although I see the after explosion processing in kernel is complex and not sure how it will advance. Thanks, Yilun > > Jason