From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8788321ABCB for ; Tue, 8 Jul 2025 18:55:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752000952; cv=none; b=cnLc3sk/Iv/6g0mUUPZYmErJWTCzYO9cMWQg+BYJbdhZ0cFFdrZB4tl03pAHkcS/r8P93VyZnwmsvnqUkrWoFU9XKcMtC8TUBAEuML53f4G5biGrIlVbYq12m+KfkFHI7IHo1zZ4VW/dszPbao4UNGJNceYA+TyQpL1BZr3xsZo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752000952; c=relaxed/simple; bh=xTGNfOSJzth56pNWxhRD7XWCKofNAfL+zE0LKJHwAuo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=R28mpwC3Qjou0eS9sCf0RcatdXLDM5DjvlwCF9rjyts3zJyuR+9aV76kaaPGSsT8x5k+eaMdXQ9+PlqQJXvxL3lnH4c1g/E2Hu4pyTudalyJ1nRWQfvozOM9xA1SDHbCll6kqVHU7LO1gAxG3ZU/ZbqBtvamuYSA/U1lmhEiLO0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NO16XS0f; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NO16XS0f" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-235f6b829cfso32553405ad.2 for ; Tue, 08 Jul 2025 11:55:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752000950; x=1752605750; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=fi49isHjUbTCoTuN9wAATX2asE3D5qC38lugMILs33w=; b=NO16XS0fALieVZluKdWnyv2SEPSWuDlWxvyZnDRrGzIpRnRoI8Y1FX6ohHPYUwGy3E +moVkwULXPLg9Sb13LFQFHI/z3jN8Bi/TegB0HdkBFYHMnkI8Op5tmLZyPr7CzXxyeRf qH0QvrtwXcjZrOkpclmN0Y6oBB2YQfDvlqF9hlk49Q41VY1Ja0ovQ9y45IGoGFhmUuT7 BxLZnhXXWbk8mLph1bq4OIgcKQhkxp5tJKh8br92Hnt9CZOWOex8KuUIvZ6bMXSwNVUA WiA2DnpzPJQnTFAIPm6+er6XrJJLHb+wFL5qqa2cAc8y7dGtK0pFn0uIvNF23/Um1Rsl 597Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752000950; x=1752605750; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=fi49isHjUbTCoTuN9wAATX2asE3D5qC38lugMILs33w=; b=Uoz7XLgokIylK8xnA+/TACQyzIBgOlozWTivmfCxKQhCdUnGpUVaE0hdT/brU3VfYU rN5F6FsfkgWXjax7JT8NdjBXpq6UcCzmuLlr8uzMqvL3XhHhPCMxuJGv4jPAFCVHqdA3 +rxXHVqqERon96OIH3wevvuKw49PIWuXsBZOQO99HrwKJ0H7L/s1cYaeiKjrsTM1BKcL sgrehNGnvkHI4LWzalu+FHDE0xBjl8N8e6+EYbwErX2cYTzWc0Ets11v6rqJ/CNkLmWe qNmZz0ulDxFxDuvjaTiEntOT+f856uZGzK4hPgUvXGf7nfAsCGYKTCubkCx+Tqt0qtSt N1Hg== X-Forwarded-Encrypted: i=1; AJvYcCXADgNussPzXuGVSsAAG42cu4ksRzAnpEZ0oEMgSgAvG7On9qjS0GpHvdKmbwUvL884wR9tbWIBJxXLnYs=@vger.kernel.org X-Gm-Message-State: AOJu0Yw5gDKjbTg8VvbX4rD0ucNU8Sv15jE77ASe2AsVod44wniYPDmd XYF8t8Y/gJsNY+dH6v5knn/RKKFNKcjVg9CCwnBJb6kleNDGFtsd/8Jmjoom6uwJCUAJQFAq1+L mHmogcg== X-Google-Smtp-Source: AGHT+IEFMwD1SUZ6NWjUN/Oq62lH5zXOf8LQ57ZZYUcKAc0E0p/gulNYcvCDjCJG+mP3axWJpVjPcEFNH7M= X-Received: from pjtd3.prod.google.com ([2002:a17:90b:43:b0:312:18d4:6d5e]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:c88e:b0:31a:bc78:7fe1 with SMTP id 98e67ed59e1d1-31c2ee7d9dbmr289595a91.18.1752000948847; Tue, 08 Jul 2025 11:55:48 -0700 (PDT) Date: Tue, 8 Jul 2025 11:55:47 -0700 In-Reply-To: <5decd42b3239d665d5e6c5c23e58c16c86488ca8.camel@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <006899ccedf93f45082390460620753090c01914.camel@intel.com> <5decd42b3239d665d5e6c5c23e58c16c86488ca8.camel@intel.com> Message-ID: Subject: Re: [RFC PATCH v2 00/51] 1G page support for guest_memfd From: Sean Christopherson To: Rick P Edgecombe Cc: "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" , Vishal Annapurve , "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 On Tue, Jul 08, 2025, Rick P Edgecombe wrote: > On Tue, 2025-07-08 at 11:03 -0700, Sean Christopherson wrote: > > > I think there is interest in de-coupling it? > >=20 > > No? >=20 > I'm talking about the intra-host migration/reboot optimization stuff. And= not > doing a good job, sorry. >=20 > > =C2=A0 Even if we get to a point where multiple distinct VMs can bind t= o a single > > guest_memfd, e.g. for inter-VM shared memory, there will still need to = be a > > sole > > owner of the memory.=C2=A0 AFAICT, fully decoupling guest_memfd from a = VM would add > > non-trivial complexity for zero practical benefit. >=20 > I'm talking about moving a gmem fd between different VMs or something usi= ng > KVM_LINK_GUEST_MEMFD [0]. Not advocating to try to support it. But trying= to > feel out where the concepts are headed. It kind of allows gmem fds (or ju= st > their source memory?) to live beyond a VM lifecycle. I think the answer is that we want to let guest_memfd live beyond the "stru= ct kvm" instance, but not beyond the Virtual Machine. From a past discussion on th= is topic[*]. : No go. Because again, the inode (physical memory) is coupled to the vir= tual machine : as a thing, not to a "struct kvm". Or more concretely, the inode is cou= pled to an : ASID or an HKID, and there can be multiple "struct kvm" objects associat= ed with a : single ASID. And at some point in the future, I suspect we'll have mult= iple KVM : objects per HKID too. :=20 : The current SEV use case is for the migration helper, where two KVM obje= cts share : a single ASID (the "real" VM and the helper). I suspect TDX will end up= with : similar behavior where helper "VMs" can use the HKID of the "real" VM. = For KVM, : that means multiple struct kvm objects being associated with a single HK= ID. :=20 : To prevent use-after-free, KVM "just" needs to ensure the helper instanc= es can't : outlive the real instance, i.e. can't use the HKID/ASID after the owning= virtual : machine has been destroyed. :=20 : To put it differently, "struct kvm" is a KVM software construct that _us= ually_, : but not always, is associated 1:1 with a virtual machine. :=20 : And FWIW, stashing the pointer without holding a reference would not be = a complete : solution, because it couldn't guard against KVM reusing a pointer. E.g.= if a : struct kvm was unbound and then freed, KVM could reuse the same memory f= or a new : struct kvm, with a different ASID/HKID, and get a false negative on the = rebinding : check. Exactly what that will look like in code is TBD, but the concept/logic hold= s up. [*] https://lore.kernel.org/all/ZOO782YGRY0YMuPu@google.com > [0] https://lore.kernel.org/all/cover.1747368092.git.afranji@google.com/ > https://lore.kernel.org/kvm/cover.1749672978.git.afranji@google.com/