From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (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 9530C2DFA3E for ; Tue, 8 Jul 2025 15:39:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751989145; cv=none; b=TPrmF9Po6QBKG3blELwGTYw/SPTgkY4EuzAsrwLx7RiKksrxqMJhynz7CbE4o58ebswPHzeKJrFqf2hIGVcyWVXWTQAuqo9Iha3W61hc5mFgsL6zFPgdnfifudHaqQwhaqUXJmYw1la9tGA17lBcPGP+SoD3k6KxIt4DyY57x8Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751989145; c=relaxed/simple; bh=ay6a3q8ckTPpxsDcQsPqS7Qt5vS8hnlo8TH9PCcpMBY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=R6CSLFYloRhUMezxZthU4vGT5N+NkIIP8xRwSeZO9zEf22tELsI519FI7zsKtxy/VFpE3Rt1copq0pR3epwPX8ZdQuFVO+xOOHT0MN/imCcqvMKAOO6GluyMODJowHrNQPsgT6WF5RoO19PfrPbMQjA+UdW54qc2Zr+I2zXkkxs= 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=lLFm8dNI; arc=none smtp.client-ip=209.85.210.201 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="lLFm8dNI" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-747ddba7c90so3364227b3a.0 for ; Tue, 08 Jul 2025 08:39:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751989143; x=1752593943; 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=fJ6Trmj44z6pMJddwVQzuI+dtUG3teA4UW/36PaybfA=; b=lLFm8dNIcn48xcNpxryCk91Jy3hZfBJzgSa7rk8Smy8St1K8OA/IsITwtlaZ8mpHA8 WCMJuu52xBApDHikBm92hsuwspGJScGqBSTjAYbI5mVrZeTKFeJNRWNN2KNIZsrFobQa 9pF4camFheCB5hcaByl31PeH5j8DcPXiBsF0NtSBvA1jVDPIz4hi3MmrIC0pPeqMOKOe U225Zje90EfSqyy9avi7s+GPtRkSDMhXEJjJ837v8sD7+5S+sWtvt62NR9bHX/zyXgJ4 JaEbixW+RwO81UpvIL1Kk2e3ngZyOpO6AF1VImxgkQNYTQ7NsK8MKd2rHxUGFU6uELiR WrYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751989143; x=1752593943; 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=fJ6Trmj44z6pMJddwVQzuI+dtUG3teA4UW/36PaybfA=; b=w1mC9b1laD6GocN0AOEcTZTCXcIjoqVSH3GPITb8iRkX+ttYtRnAMmq5Ed57jBynJE O+gJ5PdRYOitZOb/zjC1LjB+hGlZo1RVPzNE8EOf6ithTOLxzsHgvvJpo6aAcic20O7s 7tkd5igDH28yUqxfuGCsdlvIzrUr4G0ol71+R5gzh6rbkXEO2sBCMK5kB7Qe/P2nip4m 4X7yMHCP43bRvaJRCkX4X3nhO3zPlEG96OxY1hRVyUGl4B9O4OhZIe34usC5+dJTjb/T Dn67GPEM/KIkqCXqkdFC3A95brB6Oopz6xHE6RzkTaVMaSBZ4XjHPMdY56FTYFGAJBeM oTjw== X-Forwarded-Encrypted: i=1; AJvYcCUpASnQJem150HbqJmAyZA7wcw9fcmngGPJhwgzQiosgSexmGmN55Tz9b3zsi1Z/eMgbrwBBvYlG2QFLgc=@vger.kernel.org X-Gm-Message-State: AOJu0YxbDjuStB1hHeJUZ+BMQFyy1MmrkWtYbb7iik3/hKvgPlXG1TH+ ABtKEA5qWVWGiw6IQGlMlK72RG8jSSpt4oPuEMjA4kHJ089yeV3g51Htv5/wqc1OnPoEVCw2AbE dOyCyCw== X-Google-Smtp-Source: AGHT+IEVTH1cDHrDrkBM9ANruotfYiflC/Rn/GMmhs6k3Qn6zxl4FY9ZL04L/ybWIyiK/dNj58MjPa3dDVo= X-Received: from pfbfi39.prod.google.com ([2002:a05:6a00:39a7:b0:747:b682:5cc0]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:929e:b0:742:8d52:62f1 with SMTP id d2e1a72fcca58-74ce6419a9emr28472954b3a.8.1751989142330; Tue, 08 Jul 2025 08:39:02 -0700 (PDT) Date: Tue, 8 Jul 2025 08:38:55 -0700 In-Reply-To: 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> Message-ID: Subject: Re: [RFC PATCH v2 00/51] 1G page support for guest_memfd From: Sean Christopherson To: Vishal Annapurve Cc: Rick P Edgecombe , "pvorel@suse.cz" , "kvm@vger.kernel.org" , "catalin.marinas@arm.com" , Jun Miao , Kirill Shutemov , "pdurrant@amazon.co.uk" , "vbabka@suse.cz" , "peterx@redhat.com" , "x86@kernel.org" , "amoorthy@google.com" , "jack@suse.cz" , "quic_svaddagi@quicinc.com" , "keirf@google.com" , "palmer@dabbelt.com" , "vkuznets@redhat.com" , "mail@maciej.szmigiero.name" , "anthony.yznaga@oracle.com" , Wei W Wang , "tabba@google.com" , "Wieczor-Retman, Maciej" , Yan Y Zhao , "ajones@ventanamicro.com" , "willy@infradead.org" , "rppt@kernel.org" , "quic_mnalajal@quicinc.com" , "aik@amd.com" , "usama.arif@bytedance.com" , Dave Hansen , "fvdl@google.com" , "paul.walmsley@sifive.com" , "bfoster@redhat.com" , "nsaenz@amazon.es" , "anup@brainfault.org" , "quic_eberman@quicinc.com" , "linux-kernel@vger.kernel.org" , "thomas.lendacky@amd.com" , "mic@digikod.net" , "oliver.upton@linux.dev" , "akpm@linux-foundation.org" , "quic_cvanscha@quicinc.com" , "steven.price@arm.com" , "binbin.wu@linux.intel.com" , "hughd@google.com" , Zhiquan1 Li , "rientjes@google.com" , "mpe@ellerman.id.au" , Erdem Aktas , "david@redhat.com" , "jgg@ziepe.ca" , "jhubbard@nvidia.com" , Haibo1 Xu , Fan Du , "maz@kernel.org" , "muchun.song@linux.dev" , Isaku Yamahata , "jthoughton@google.com" , "steven.sistare@oracle.com" , "quic_pheragu@quicinc.com" , "jarkko@kernel.org" , "chenhuacai@kernel.org" , Kai Huang , "shuah@kernel.org" , "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" , "hch@infradead.org" , "linux-mm@kvack.org" , "will@kernel.org" , "roypat@amazon.co.uk" Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Tue, Jul 08, 2025, Vishal Annapurve wrote: > On Tue, Jul 8, 2025 at 7:52=E2=80=AFAM Edgecombe, Rick P > wrote: > > > > On Tue, 2025-07-08 at 07:20 -0700, Sean Christopherson wrote: > > > > For TDX if we don't zero on conversion from private->shared we will= be > > > > dependent > > > > on behavior of the CPU when reading memory with keyid 0, which was > > > > previously > > > > encrypted and has some protection bits set. I don't *think* the beh= avior is > > > > architectural. So it might be prudent to either make it so, or zero= it in > > > > the > > > > kernel in order to not make non-architectual behavior into userspac= e ABI. > > > > > > Ya, by "vendor specific", I was also lumping in cases where the kerne= l would > > > need to zero memory in order to not end up with effectively undefined > > > behavior. > > > > Yea, more of an answer to Vishal's question about if CC VMs need zeroin= g. And > > the answer is sort of yes, even though TDX doesn't require it. But we a= ctually > > don't want to zero memory when reclaiming memory. So TDX KVM code needs= to know > > that the operation is a to-shared conversion and not another type of pr= ivate > > zap. Like a callback from gmem, or maybe more simply a kernel internal = flag to > > set in gmem such that it knows it should zero it. >=20 > If the answer is that "always zero on private to shared conversions" > for all CC VMs, pKVM VMs *are* CoCo VMs. Just because pKVM doesn't rely on third party fir= mware to provide confidentiality and integrity doesn't make it any less of a CoCo= VM. > > > : And maybe a new flag for KVM_GMEM_CONVERT_PRIVATE for user space t= o > > > : explicitly request that the page range is converted to private and= the > > > : content needs to be retained. So that TDX can identify which case = needs > > > : to call in-place TDH.PAGE.ADD. > > > > > > If so, I agree with that idea, e.g. add a PRESERVE flag or whatever. = That way > > > userspace has explicit control over what happens to the data during > > > conversion, > > > and KVM can reject unsupported conversions, e.g. PRESERVE is only all= owed for > > > shared =3D> private and only for select VM types. > > > > Ok, we should POC how it works with TDX. >=20 > I don't think we need a flag to preserve memory as I mentioned in [2]. II= UC, > 1) Conversions are always content-preserving for pKVM. No? Perserving contents on private =3D> shared is a security vulnerability= waiting to happen. > 2) Shared to private conversions are always content-preserving for all > VMs as far as guest_memfd is concerned. There is no "as far as guest_memfd is concerned". Userspace doesn't care w= hether code lives in guest_memfd.c versus arch/xxx/kvm, the only thing that matter= s is the behavior that userspace sees. I don't want to end up with userspace AB= I that is vendor/VM specific. > 3) Private to shared conversions are not content-preserving for CC VMs > as far as guest_memfd is concerned, subject to more discussions. >=20 > [2] https://lore.kernel.org/lkml/CAGtprH-Kzn2kOGZ4JuNtUT53Hugw64M-_XMmhz_= gCiDS6BAFtQ@mail.gmail.com/