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 9DF04C2D0CD for ; Wed, 21 May 2025 15:51:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 045CC6B0085; Wed, 21 May 2025 11:51:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 01E7A6B0089; Wed, 21 May 2025 11:51:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E75B86B008A; Wed, 21 May 2025 11:51:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C6AC96B0085 for ; Wed, 21 May 2025 11:51:41 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 62D95BCCFD for ; Wed, 21 May 2025 15:51:41 +0000 (UTC) X-FDA: 83467355202.04.123DA6D Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf05.hostedemail.com (Postfix) with ESMTP id 6AA69100017 for ; Wed, 21 May 2025 15:51:39 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="MixQ/SxU"; spf=pass (imf05.hostedemail.com: domain of vannapurve@google.com designates 209.85.214.172 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=1747842699; 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=yWPZpU6WFSpfS6hmxyh7KpM+vXuIKyk4x1JorSsjETc=; b=JDjSGKJQ+cXhchTPAGaM0c4BciCeXyvG+rYqaiw3ukxtwoYXokRSCc74Oi1nVO8jjSxyOT s+azQjR0bjVZDr1aZrUntp3IE0cM0ZkMQp9tPXUWdjiAd851ZnxHVCYZtYiiPQnK0fWlSR IJiPy7SXZRbGCK+EY5A9aLwBboZGeWg= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="MixQ/SxU"; spf=pass (imf05.hostedemail.com: domain of vannapurve@google.com designates 209.85.214.172 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=1747842699; a=rsa-sha256; cv=none; b=TEhlDOtU1gKaDK77yWxc1tN4jx3reYYy3G1OU2eKKwn8jKQx3O4uoIERpVUwXhalHBB7VW 5Asyso0AUarrhzoiSQ85y2YiSooD4nci6eN6wWcqwHYOAtLUbKgs9jpzQlYg8m55KCDnW+ EeMPELLED6IYwJKqj7kbEIIF+3fVqZk= Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-231f6c0b692so782645ad.0 for ; Wed, 21 May 2025 08:51:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1747842698; x=1748447498; 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=yWPZpU6WFSpfS6hmxyh7KpM+vXuIKyk4x1JorSsjETc=; b=MixQ/SxUO/jHP/5huMdOMdJiNOwtw/Cogg1kcaaIf20grQemXr82OYCDHbwqm3uVqU Ac6AQg6j/ygQTuCoKXxNqXS9RwpSijv0b03jsZds+tQ2ePGIFBOrG3CNbSIuYhnuzIE3 HW3oXAilTxG1NuxN7DnAbEn9ocNkm0q/QvIxad4w6iTDjfG2UtEiYBraii2Abrjsthhs T7yvEd53T4ugilkdOd8jHsCduIb2vWj3utYYttWsW4UKEGuviTv6LRVuHikSN6os0HBR p9UEPqkvj/WD8WPuBSJPnl2wTMv8jImhfQ+DfRvW7KZW1vB1sqkaGwTrhZVkUc86ISq7 P6iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747842698; x=1748447498; 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=yWPZpU6WFSpfS6hmxyh7KpM+vXuIKyk4x1JorSsjETc=; b=NmOLMsHSKyItZpkUhsfpkO7tuJ3uMmSpBOLPJggeu9N4b+pDDUKlqTDn8wQ0TTSmcu zMyYXN/wQMSaNKa9AGIBvOdResDHXmdT5Bz6nNdpI+A5b1NKag1NzC9J2h6hsmc3X0Rh 9kT7FXMznDchB/lylPsZZZuOHmSOd1JlXfNjlJ0iDNJKh6806z8p/WOXnTgylCE2XlkP Qpm5UM/wmY6k9P8xWihpSgOWMZB+LbOtjefz072vkIDN7LFxztpZKsQoqXXipHdMjoGX lk6VHksVShWy7T/gLnKJHs/Hh03MV/ab5qPB1iLt1DgjwYzrb8qP253Ze+dmEw6d8T/m 4BlA== X-Forwarded-Encrypted: i=1; AJvYcCVpHN3lMl3qBq2z2DqAoimUytWH7jXbzyBQ2TRJ1fpTAxhZposxxurRcfiZx/v9VqukdcysEfiOrA==@kvack.org X-Gm-Message-State: AOJu0Yz5z8hT1SMeOt9jsiW+3WY1duptS7MSVcTUChFa8/1gRN7v/DVz OMpBmnAqT372wGHhjV+AhaNvNn4ENuID7ix/oIwlOti5gjnSwHOwNTFytRLimgDVNtF1FCz0CVy OavWtkln9n5jaMxQBzOVoyOEjKCFQoRMxG41YIeE3 X-Gm-Gg: ASbGncvT8zl/3tKeqHyPwXk1hUYuqVJBpZq/dcTuW09Uc+ymmVjbiMI+wuhU00U3Ud0 oAtxE+MMw6dPbM5xkCNUM8ckegBNvYhRuX/mkmKRF3Yzyj025EqoUW+zvxz0UJSjl6Jf4YdZfxQ crNzdOGQi/mgEMgalpqDhsku4w0txg5eAmSa7BS4DoVC0V5/Fd0xarecbjA03DwQfa5GNHztmp8 kA= X-Google-Smtp-Source: AGHT+IFSOrNxCp8s0BP2r14v02zKIVmyd2WKvXsGYKjroHCU10VHEe96vUn3gv/Pkk2x5Yo5Ut2ufH8Ox+PjEmVUtJY= X-Received: by 2002:a17:902:da85:b0:223:7f8f:439b with SMTP id d9443c01a7336-23204175c4fmr11681965ad.29.1747842697619; Wed, 21 May 2025 08:51:37 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Vishal Annapurve Date: Wed, 21 May 2025 08:51:25 -0700 X-Gm-Features: AX0GCFv_OcRDXXTTFCAqZtA9lE-fYkL67Fg0315KprRAbyvEL7EBvd9v52zlvyg Message-ID: Subject: Re: [RFC PATCH v2 04/51] KVM: guest_memfd: Introduce KVM_GMEM_CONVERT_SHARED/PRIVATE ioctls To: Fuad Tabba Cc: Ackerley Tng , kvm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, x86@kernel.org, linux-fsdevel@vger.kernel.org, aik@amd.com, 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, jgg@ziepe.ca, 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, yan.y.zhao@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-Rspam-User: X-Rspamd-Queue-Id: 6AA69100017 X-Rspamd-Server: rspam09 X-Stat-Signature: d9scwdtdib6qrcnk8z16c44pjpcct1k3 X-HE-Tag: 1747842699-781596 X-HE-Meta: U2FsdGVkX19sYET2dx5mBez9Z3szKAn+sHdZ7bu+PkG6OKMfxPgZY+jAuxCiqRPCG/omrUj02AsgOQeb459MooaLPBx4QIlVNSeOEa+ZIdVb0Cj/DizqUXdHO6oQluhGtTTu+biR8kFBwhiFex8Gi8Ad7aAgNkodzZbnycIRk80gWo/5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4eAwVp5dlCuA2fBYtlOn/+F47SP8E++saXPdwfNXQ5FG+zJ8hfe9uafsmDbKZMjnlZYIN8d679tMyou8Q== 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, May 21, 2025 at 8:22=E2=80=AFAM Fuad Tabba wrote= : > > Hi Vishal, > > On Wed, 21 May 2025 at 15:42, Vishal Annapurve wr= ote: > > > > On Wed, May 21, 2025 at 5:36=E2=80=AFAM Fuad Tabba w= rote: > > > .... > > > > When rebooting, the memslots may not yet be bound to the guest_memf= d, > > > > but we want to reset the guest_memfd's to private. If we use > > > > KVM_SET_MEMORY_ATTRIBUTES to convert, we'd be forced to first bind,= then > > > > convert. If we had a direct ioctl, we don't have this restriction. > > > > > > > > If we do the conversion via vcpu_run() we would be forced to handle > > > > conversions only with a vcpu_run() and only the guest can initiate = a > > > > conversion. > > > > > > > > On a guest boot for TDX, the memory is assumed to be private. If th= e we > > > > gave it memory set as shared, we'd just have a bunch of > > > > KVM_EXIT_MEMORY_FAULTs that slow down boot. Hence on a guest reboot= , we > > > > will want to reset the guest memory to private. > > > > > > > > We could say the firmware should reset memory to private on guest > > > > reboot, but we can't force all guests to update firmware. > > > > > > Here is where I disagree. I do think that this is the CoCo guest's > > > responsibility (and by guest I include its firmware) to fix its own > > > state after a reboot. How would the host even know that a guest is > > > rebooting if it's a CoCo guest? > > > > There are a bunch of complexities here, reboot sequence on x86 can be > > triggered using multiple ways that I don't fully understand, but few > > of them include reading/writing to "reset register" in MMIO/PCI config > > space that are emulated by the host userspace directly. Host has to > > know when the guest is shutting down to manage it's lifecycle. > > In that case, I think we need to fully understand these complexities > before adding new IOCTLs. It could be that once we understand these > issues, we find that we don't need these IOCTLs. It's hard to justify > adding an IOCTL for something we don't understand. > I don't understand all the ways x86 guest can trigger reboot but I do know that x86 CoCo linux guest kernel triggers reset using MMIO/PCI config register write that is emulated by host userspace. > > x86 CoCo VM firmwares don't support warm/soft reboot and even if it > > does in future, guest kernel can choose a different reboot mechanism. > > So guest reboot needs to be emulated by always starting from scratch. > > This sequence needs initial guest firmware payload to be installed > > into private ranges of guest_memfd. > > > > > > > > Either the host doesn't (or cannot even) know that the guest is > > > rebooting, in which case I don't see how having an IOCTL would help. > > > > Host does know that the guest is rebooting. > > In that case, that (i.e., the host finding out that the guest is > rebooting) could trigger the conversion back to private. No need for > an IOCTL. In the reboot scenarios, it's the host userspace finding out that the guest kernel wants to reboot. > > > > Or somehow the host does know that, i.e., via a hypercall that > > > indicates that. In which case, we could have it so that for that type > > > of VM, we would reconvert its pages to private on a reboot. > > > > This possibly could be solved by resetting the ranges to private when > > binding with a memslot of certain VM type. But then Google also has a > > usecase to support intrahost migration where a live VM and associated > > guest_memfd files are bound to new KVM VM and memslots. > > > > Otherwise, we need an additional contract between userspace/KVM to > > intercept/handle guest_memfd range reset. > > Then this becomes a migration issue to be solved then, not a huge page > support issue. If such IOCTLs are needed for migration, it's too early > to add them now. The guest_memfd ioctl is not needed for migration but to change/reset guest_memfd range attributes. I am saying that migration usecase can conflict with some ways that we can solve resetting guest_memfd range attributes without adding a new IOCTL as migration closely resembles reboot scenario as both of them can/need reusing the same guest memory files but one needs to preserve guest memory state. Reiterating my understanding here, guest memfd ioctl can be used by host userspace to - 1) Change guest memfd range attributes during memory conversion - This can be handled by KVM hypercall exits in theory as you are suggesting but Ackerley and me are still thinking that this is a memory operation that goes beyond vcpu scope and will involve interaction with IOMMU backend as well, it's cleaner to have a separate guest memfd specific ioctl for this operation as the impact is even beyond KVM. 2) Reset guest memfd range attributes during guest reboot to allow reusing the same guest memfd files. - This helps reset the range state to private as needed inline with initial shared/private configuration chosen at the guest memfd creation. - This also helps reconstitute all the huge pages back to their original state that may have gotten split during the runtime of the guest. This is a host initiated request for guest memfd memory conversion that we should not be overloading with other KVM interactions in my opinion. > > Cheers, > /fuad