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 90087C83F10 for ; Sat, 12 Jul 2025 17:33:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5FE86B00B8; Sat, 12 Jul 2025 13:33:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0F516B00BA; Sat, 12 Jul 2025 13:33:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D6E76B00BC; Sat, 12 Jul 2025 13:33:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 783396B00B8 for ; Sat, 12 Jul 2025 13:33:31 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E57F812B050 for ; Sat, 12 Jul 2025 17:33:30 +0000 (UTC) X-FDA: 83656309380.25.6CA4F62 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf01.hostedemail.com (Postfix) with ESMTP id 0767840010 for ; Sat, 12 Jul 2025 17:33:28 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=JdAZbVn4; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf01.hostedemail.com: domain of vannapurve@google.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=vannapurve@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752341609; a=rsa-sha256; cv=none; b=MxGH+wZd5Y32Q4DbOw4TiaemUoPD7fTHgy7d4W0+8hPGIxwl3duAbthv0ui/Sr7i7eBwzy dkMJvCYK9lsGsTlXKhlHnmdUDLgTCB6c+uthQslOOBjEDiEiYXwRt+Ax61TppF+U+HI2AH pYe7uS4Ody8TfkN7Bu3ue2+wYRXf/eo= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=JdAZbVn4; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf01.hostedemail.com: domain of vannapurve@google.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=vannapurve@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1752341609; 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=V7msmF5PY7ib+4ZMdkz9ddSo3sJ/jTEzwKLjkgSY+Dg=; b=XATZQ3uWCFObvqffikjlqQrGLz2/psnynye6d3099UKpIYZ3G4swZlmjt9/asjMZsAx1wu 7L0f1BG8eaJ1+K+nwQ/pSI8QtGeBTde6efwqm5aDxEKfGwq/gC6FO54zqoffLHefSK86wS 1mrRH5D31TLJHaAl2v9yf1MxhRZ0Gyw= Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-23dd9ae5aacso129305ad.1 for ; Sat, 12 Jul 2025 10:33:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752341608; x=1752946408; 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=V7msmF5PY7ib+4ZMdkz9ddSo3sJ/jTEzwKLjkgSY+Dg=; b=JdAZbVn4MB4WRQ8htd0/hV8lynjbqanLqEvsShtlhsuUh83B0BqpdlPGNHsF6bb2nn tqZzt7xJSUVjgz+YvamI/ywn1TBPEav3Ok7M4yP9YEFMX/f5Q/UfpOtm9BI56RP94cRy 85ZY9RfefmrIggPY4/qYSNbPFvITf9WdeMBfx4KiB+EKbMXTeWX+0LdZdelxcoeJ+1rV UmDPjeZfHbMJ7p18YrEKzL043HhVKeSlDAzLluSCHS5YnjpRGOpBeUdb0Df6/x95nkfC 2bqBMDJ4jenMbIUaBRQvUUl5Ks0K8K+3eHy/WPgw/4cwZm7qJIE7x8dvz7fa6VPrgkZg osrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752341608; x=1752946408; 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=V7msmF5PY7ib+4ZMdkz9ddSo3sJ/jTEzwKLjkgSY+Dg=; b=L9f9Hb4w7apS2V7n7skGI2n5SO98O4uUxagtTNwKMBFRVBpE9JTm8FkNKZA1aF7PsZ Lf+IpeiE6ERAj4WvN/tutCyPnMH+gGNma8RmvVMxQ5Uk6Xb1HYXzEqOkzQu149FyDbjR T9MvJVYP7TUSjuR0mE5GJ/iRkXtDcDJOmQnjsp+2qSTWwZjWrKHCyd/+W459RIgnpWbk ywKgYCJ1EUFE+mCqukHgtpK2W/Ely3YGHBK4cqcN7B3AX57j4FzrVYPc9SdqQ0Nc0YTG evVUEk8bcIovkwjyQW1dbdqwSRGz/sV9tXuTMBynshPeag5KGdCfFCuXn4TFOJZg5lph 2w6g== X-Forwarded-Encrypted: i=1; AJvYcCV8WAl0xMN88VSLPHVCzhRBHCKDSfl/gJuWTC9OR/WSUXs02NnTNiW+oLYBgSl92Y9cfdZARSDoJQ==@kvack.org X-Gm-Message-State: AOJu0YxuGtnX4Jc0vS4ucpvS7j7qW47uAxvIs4e6qsf/fiYSBx1Ez5mj ed33woaJy326Is9zlWYCReF7iA5NqGOnmtPThbWs4c58XXK5s0sIXchMXS2LQokwHai/Owg1JsZ OX28mrlHq6d700UmN1Abh5D7nbAJ76j+wR1w8Mf8X X-Gm-Gg: ASbGncsOXOvhkXdjPPem0e/nRCcc+z6djBeOCvD5LAwxlNTU6p4UI7dkPLjq0z94L/J pAEDbIJQ+gX4WKfahzDf+tsSiebNvaASpzU+fWgLYchjptYvWVAStDxBXafJu9dWFTMJcFqAli+ oSn+CHqJ8wnCi+WaLc5g2NAQJYD0bu1/e5XsTkdDYDqo0l8PADsm/oKFCm98tUmSz6rRSGAYvmt UTegrDdrnDT/2grkznbPJfXtpiUkFvT23dqmpeV X-Google-Smtp-Source: AGHT+IGOwmmOvHU5TdyUaaF7aTYL0i8GNBXrrhGyi3z4BA4euoatDzGCE8dL+1tDQ9wYfDVbsYBeS729UYvOHJmxrWU= X-Received: by 2002:a17:902:ec85:b0:22e:766f:d66e with SMTP id d9443c01a7336-23df6afcdb8mr1791365ad.12.1752341607051; Sat, 12 Jul 2025 10:33:27 -0700 (PDT) MIME-Version: 1.0 References: <5decd42b3239d665d5e6c5c23e58c16c86488ca8.camel@intel.com> In-Reply-To: From: Vishal Annapurve Date: Sat, 12 Jul 2025 10:33:12 -0700 X-Gm-Features: Ac12FXyZj5IyRrPeX-4vUKfdJIwXEzSvUSNEtsk0ttD7VXz_GmBFr4rl6viPRO0 Message-ID: Subject: Re: [RFC PATCH v2 00/51] 1G page support for guest_memfd To: Sean Christopherson Cc: Rick P Edgecombe , "pvorel@suse.cz" , "kvm@vger.kernel.org" , "catalin.marinas@arm.com" , Jun Miao , "palmer@dabbelt.com" , "pdurrant@amazon.co.uk" , "vbabka@suse.cz" , "peterx@redhat.com" , "x86@kernel.org" , "amoorthy@google.com" , "tabba@google.com" , "quic_svaddagi@quicinc.com" , "maz@kernel.org" , "vkuznets@redhat.com" , "anthony.yznaga@oracle.com" , "mail@maciej.szmigiero.name" , "quic_eberman@quicinc.com" , Wei W Wang , Fan Du , "Wieczor-Retman, Maciej" , Yan Y Zhao , "ajones@ventanamicro.com" , Dave Hansen , "paul.walmsley@sifive.com" , "quic_mnalajal@quicinc.com" , "aik@amd.com" , "usama.arif@bytedance.com" , "fvdl@google.com" , "jack@suse.cz" , "quic_cvanscha@quicinc.com" , Kirill Shutemov , "willy@infradead.org" , "steven.price@arm.com" , "anup@brainfault.org" , "thomas.lendacky@amd.com" , "keirf@google.com" , "mic@digikod.net" , "linux-kernel@vger.kernel.org" , "nsaenz@amazon.es" , "akpm@linux-foundation.org" , "oliver.upton@linux.dev" , "binbin.wu@linux.intel.com" , "muchun.song@linux.dev" , Zhiquan1 Li , "rientjes@google.com" , Erdem Aktas , "mpe@ellerman.id.au" , "david@redhat.com" , "jgg@ziepe.ca" , "hughd@google.com" , "jhubbard@nvidia.com" , Haibo1 Xu , Isaku Yamahata , "jthoughton@google.com" , "rppt@kernel.org" , "steven.sistare@oracle.com" , "jarkko@kernel.org" , "quic_pheragu@quicinc.com" , "chenhuacai@kernel.org" , Kai Huang , "shuah@kernel.org" , "bfoster@redhat.com" , "dwmw@amazon.co.uk" , Chao P Peng , "pankaj.gupta@amd.com" , Alexander Graf , "nikunj@amd.com" , "viro@zeniv.linux.org.uk" , "pbonzini@redhat.com" , "yuzenghui@huawei.com" , "jroedel@suse.de" , "suzuki.poulose@arm.com" , "jgowans@amazon.com" , Yilun Xu , "liam.merwick@oracle.com" , "michael.roth@amd.com" , "quic_tsoni@quicinc.com" , Xiaoyao Li , "aou@eecs.berkeley.edu" , Ira Weiny , "richard.weiyang@gmail.com" , "kent.overstreet@linux.dev" , "qperret@google.com" , "dmatlack@google.com" , "james.morse@arm.com" , "brauner@kernel.org" , "linux-fsdevel@vger.kernel.org" , "ackerleytng@google.com" , "pgonda@google.com" , "quic_pderrin@quicinc.com" , "roypat@amazon.co.uk" , "hch@infradead.org" , "will@kernel.org" , "linux-mm@kvack.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 0767840010 X-Stat-Signature: 1zu8n35p3xkdc3kbje8ipmczzxrim59t X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1752341608-507099 X-HE-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yVUW7FBFJ77c8KbQWNJWXI7sX4nPEyT4HICgH+9hbQ4cvAzbw2u/KXd3IwsbyHySigsppPrNFvu3yDSGLx8iF94GuUrywmkS464efCq7M9LF+Benbsr9G53Xs8X5AG3xyEae/zlAKAi3eC2d2bx7EP0wWSKO5Q0qYv1OTGOBpjdK8Oz0duoWbx4SeO2rLNJsLAr/wg5Y3GzCVFMfCfIuGeB4Q0cxqDaPJzVDr8KnYscYHg7evhW+LLDYGsQ+nU02DScxfgu1CxizlaFOiuH8gHQh/GUkNeSFCWQX1A== 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 Fri, Jul 11, 2025 at 2:18=E2=80=AFPM Vishal Annapurve wrote: > > On Wed, Jul 9, 2025 at 6:30=E2=80=AFPM Vishal Annapurve wrote: > > > > 3) KVM should ideally associate the lifetime of backing > > > > pagetables/protection tables/RMP tables with the lifetime of the > > > > binding of memslots with guest_memfd. > > > > > > Again, please align your indentation. > > > > > > > - Today KVM SNP logic ties RMP table entry lifetimes with = how > > > > long the folios are mapped in guest_memfd, which I think= should be > > > > revisited. > > > > > > Why? Memslots are ephemeral per-"struct kvm" mappings. RMP entries = and guest_memfd > > > inodes are tied to the Virtual Machine, not to the "struct kvm" insta= nce. > > > > IIUC guest_memfd can only be accessed through the window of memslots > > and if there are no memslots I don't see the reason for memory still > > being associated with "virtual machine". Likely because I am yet to > > completely wrap my head around 'guest_memfd inodes are tied to the > > Virtual Machine, not to the "struct kvm" instance', I need to spend > > more time on this one. > > > > I see the benefits of tying inodes to the virtual machine and > different guest_memfd files to different KVM instances. This allows us > to exercise intra-host migration usecases for TDX/SNP. But I think > this model doesn't allow us to reuse guest_memfd files for SNP VMs > during reboot. > > Reboot scenario assuming reuse of existing guest_memfd inode for the > next instance: > 1) Create a VM > 2) Create guest_memfd files that pin KVM instance > 3) Create memslots > 4) Start the VM > 5) For reboot/shutdown, Execute VM specific Termination (e.g. > KVM_TDX_TERMINATE_VM) > 6) if allowed, delete the memslots > 7) Create a new VM instance > 8) Link the existing guest_memfd files to the new VM -> which creates > new files for the same inode. > 9) Close the existing guest_memfd files and the existing VM > 10) Jump to step 3 > > The difference between SNP and TDX is that TDX memory ownership is > limited to the duration the pages are mapped in the second stage > secure EPT tables, whereas SNP/RMP memory ownership lasts beyond > memslots and effectively remains till folios are punched out from > guest_memfd filemap. IIUC CCA might follow the suite of SNP in this > regard with the pfns populated in GPT entries. > > I don't have a sense of how critical this problem could be, but this > would mean for every reboot all large memory allocations will have to > let go and need to be reallocated. For 1G support, we will be freeing > guest_memfd pages using a background thread which may add some delays > in being able to free up the memory in time. > > Instead if we did this: > 1) Support creating guest_memfd files for a certain VM type that > allows KVM to dictate the behavior of the guest_memfd. > 2) Tie lifetime of KVM SNP/TDX memory ownership with guest_memfd and > memslot bindings > - Each binding will increase a refcount on both guest_memfd file > and KVM, so both can't go away while the binding exists. I think if we can ensure that any guest_memfd initiated interaction with KVM is only for invalidation and is based on binding and under filemap_invalidate_lock then there is no need to pin KVM on each binding, as binding/unbinding should be protected using filemap_invalidate_lock and so KVM can't go away during invalidation. > 3) For SNP/CCA, pfns are invalidated from RMP/GPT tables during unbind > operations while for TDX, KVM will invalidate secure EPT entries. > > This can allow us to decouple memory lifecycle from VM lifecycle and > match the behavior with non-confidential VMs where memory can outlast > VMs. Though this approach will mean change in intrahost migration > implementation as we don't need to differentiate guest_memfd files and > inodes. > > That being said, I might be missing something here and I don't have > any data to back the criticality of this usecase for SNP and possibly > CCA VMs.