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 E7E2CC77B7C for ; Wed, 2 Jul 2025 14:32:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 75A476B00A4; Wed, 2 Jul 2025 10:32:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 738A66B00A5; Wed, 2 Jul 2025 10:32:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 620EE6B00A7; Wed, 2 Jul 2025 10:32:54 -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 519A26B00A4 for ; Wed, 2 Jul 2025 10:32:54 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id F344DBA031 for ; Wed, 2 Jul 2025 14:32:53 +0000 (UTC) X-FDA: 83619566226.09.E58DAA8 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf05.hostedemail.com (Postfix) with ESMTP id 1F8B1100011 for ; Wed, 2 Jul 2025 14:32:51 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Zttz6fcn; spf=pass (imf05.hostedemail.com: domain of vannapurve@google.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=vannapurve@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751466772; 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=ZqqnRujRE2SdSp3Ji3lnU4lMv7Si9SLf3Ig6FroSxIY=; b=G2n0QWAnU3xhRZu2btSwYsgURxQkVydYEDwrSB3hmC5PcFtXusQ2c1BC8eJDeUPfhnGMgN mdVXk8643CEvPG1ExKzaZgbO6MAJmrWFpiznpR/lAopXIjoJ+KXCDT7Tqme6WTRuKXh8DR MpaVGl7KruCiXOYR+urwVVUvCD8feTI= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Zttz6fcn; spf=pass (imf05.hostedemail.com: domain of vannapurve@google.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=vannapurve@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751466772; a=rsa-sha256; cv=none; b=qPdl3yK7Qh8GqOwiuGBMj/UBqTnuqtM6l3XjwOxF8HJjsMhz0ROxW0wDE2Ev+T3J64BWyJ PVUuGUaAsxM4bi3qGmFuuJsFH12Bc9795zc5Z0Xq9EkQ1EH2jP3wunwUz49bSfGKiIXLpe i1aQoJ4+2PaG6RmqDyK9+6Iv7y/c360= Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-237f18108d2so424975ad.0 for ; Wed, 02 Jul 2025 07:32:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751466771; x=1752071571; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ZqqnRujRE2SdSp3Ji3lnU4lMv7Si9SLf3Ig6FroSxIY=; b=Zttz6fcnJsUGPZQ83LRLrE7nxNaO31spNdyqsCxqX+aNvlvxu26jU7Niazv5+ANEqk F3FqsjZaRgiDaJjo0GkUSSt84rDjMlRTxeJFnzfbDcFV5wbCDWc02CSidamp+HnAA88B waTrmfGM76PjVQQzjdS3eTFzXFrqvJlxdX1H6DOfLEZx4yEbWvNh8M+Mmx1qdSAv9o1L QrK50CCyMsTKbC0EmdPQzl8+G549Jkq1T/x7bIS/dTgkXpCD4dO3ECWuoHtJlPLb2pKc 5+GGHGhUH+1/7DnV7NC9ZWdV7q8PsazJ9WpwjxrgdwxuCixGC0fRgXYGNwv4eRwlse5H +fnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751466771; x=1752071571; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZqqnRujRE2SdSp3Ji3lnU4lMv7Si9SLf3Ig6FroSxIY=; b=EblI7c3K6OpTpFtk1bxxQJPyVlwHS6a6fWj8uOgAzkbn9/+pgqOe223Cp3kMQX2SLy oXXwFteh8zJd9mJAoBxbb27uushNdTjxEusFJf6gHZH8KNiyz9k5SKdryA4GGeg8qnPM whYCmniNIeE6716HdZ+bKJc3JsVBHWOcS3DFF+ZlPwksAHPhWFaSeben+FrsIOTEl16+ 6/f8Br11U5pou+CURNqAdvUJCYg6dNGxhc74TlUiutdl9Pm37WZaBnRhpR5fv7Wm0feW nIz6DA14oZem5f0owuKWwEUumik3FxR7o6PnSaQGA+o5QuBKg4Jjyor6QRznanhnJKNj sPSA== X-Forwarded-Encrypted: i=1; AJvYcCUCgxo4iLYIeYkXQbEzflaF9XmIBTVp3QI9uWrVV5ydTW8sGRUAQ1QJKqGuS8yJxzeaA5plCabMUg==@kvack.org X-Gm-Message-State: AOJu0Yy3DWW+muUHJ866G01VWC+OlyFRBFTO8kWOxv2Hy/IUdXIAIwsp DTrlKG0DA4C7K0ARS4s1sz87cE05Ky20j9MGz128hLAjF+GEk/a1/uRZvYBAdAgWPx4/BkiaWz4 gKbh5xe6VtijHknbeMF+TxVFNuSr9kdxNKj+wVKQd X-Gm-Gg: ASbGncvYhxJesILKRNp42UpEAYu0hYTGjM+mCzfNne7c9JnGCfA2i+Debr9tJRjx5GN KQYAHEYfxkNXYiBN/Z9zuUJZnXsquuRRE3FLObtx+Bld7mLdTOKCaZfx+wCeftkbZFvJZLPa7tN t4Bc+k7pBxoj1sbhJf4wkBPr7CD6Z/HV86FX2XosI7UlEBqxZt6QzdvpyFuDzvgthea+ND4hgfn WwZ X-Google-Smtp-Source: AGHT+IGoIHXKMSNgSYMoVATe9zftjUbnEF1aXjzvZLi/NINKt4JogRrvHG2G1VAsWUCf6cD0R3CJCF3RSOi1f9/p6D4= X-Received: by 2002:a17:902:c407:b0:215:42a3:e844 with SMTP id d9443c01a7336-23c5ffbdd35mr6602435ad.17.1751466769703; Wed, 02 Jul 2025 07:32:49 -0700 (PDT) MIME-Version: 1.0 References: <9502503f-e0c2-489e-99b0-94146f9b6f85@amd.com> <20250624130811.GB72557@ziepe.ca> <20250702141321.GC904431@ziepe.ca> In-Reply-To: <20250702141321.GC904431@ziepe.ca> From: Vishal Annapurve Date: Wed, 2 Jul 2025 07:32:36 -0700 X-Gm-Features: Ac12FXxsJnd1Ik5yTb-XA10TvLxSoUfxXWhX4Ea1BvmrwrYFJWzxZ35OP06jBy4 Message-ID: Subject: Re: [RFC PATCH v2 04/51] KVM: guest_memfd: Introduce KVM_GMEM_CONVERT_SHARED/PRIVATE ioctls To: Jason Gunthorpe Cc: 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: tizmankaeyq9we68za5r71wqz4j8jdcu X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 1F8B1100011 X-Rspam-User: X-HE-Tag: 1751466771-679649 X-HE-Meta: U2FsdGVkX1/FeyMZ11JVQ3KoExw2B0S1alYkmipVmt68sa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3WYbj3VtVZnMIfRGuFtucIxSnyByscVyvnvqT3PwWap5c1qSpBVdsS8Gz3H4CpTYAP2T5tz4H6379pLhYuurfjTQ9yhCkcwpJc3OW4p/tcvJQ2HcMu5fOH8YtRIMC11aAhWgetTiDoKHvLZSSeVyDGtMmLQMwlvC+dlw5aQUI19Ml53fBSukwPx2d5bHnGtvApdDuOfDiCI/3B5CN6AM6Lb 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 2, 2025 at 7:13=E2=80=AFAM Jason Gunthorpe wrote= : > > On Wed, Jul 02, 2025 at 06:54:10AM -0700, Vishal Annapurve wrote: > > On Wed, Jul 2, 2025 at 1:38=E2=80=AFAM Yan Zhao = wrote: > > > > > > On Tue, Jun 24, 2025 at 07:10:38AM -0700, Vishal Annapurve wrote: > > > > On Tue, Jun 24, 2025 at 6:08=E2=80=AFAM Jason Gunthorpe wrote: > > > > > > > > > > On Tue, Jun 24, 2025 at 06:23:54PM +1000, Alexey Kardashevskiy wr= ote: > > > > > > > > > > > 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 t= hese > > > > > > folios in my RFC. > > > > > > > > > > > > So what is the expected sequence here? The userspace unmaps a D= MA > > > > > > page and maps it back right away, all from the userspace? The e= nd > > > > > > 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 ta= ken > > > > 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 wi= ll 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=3D1 iommu inside the TDX module but > it won't have an IOAS for it since the VMM does not control the > translation. > > The discussion here is for the T=3D0 iommu which is controlled by > iommufd and does have an IOAS. It should be popoulated with all the > shared pages from the guestmemfd. > > > > 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_memf= d can > > > reject the request before attempting the actual unmap. > > This has to be delt with between the TDX module and KVM. When KVM > gives pages to become secure it may not be able to get them back.. > > This problem has nothing to do with iommufd. > > But generally I expect that the T=3D1 iommu follows the S-EPT entirely > and there is no notion of pages "locked for dma". If DMA is ongoing > and a page is made non-secure then the DMA fails. > > 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. Yes, guest_memfd ensures that all the faulted-in pages (irrespective of shared or private ranges) are not migratable. We already have a similar restriction with CPU accesses to encrypted memory ranges that need arch specific protocols to migrate memory contents. > > Maybe this needs to be an integral functionality in guestmemfd? > > Jason