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 425F2C0219E for ; Mon, 17 Feb 2025 11:22:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D035F6B00F2; Mon, 17 Feb 2025 06:22:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CB1F86B00F3; Mon, 17 Feb 2025 06:22:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B79FF280024; Mon, 17 Feb 2025 06:22:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9B4D86B010D for ; Mon, 17 Feb 2025 06:22:19 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 294CC4F156 for ; Mon, 17 Feb 2025 11:22:19 +0000 (UTC) X-FDA: 83129197998.28.11BFC84 Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) by imf07.hostedemail.com (Postfix) with ESMTP id 4F2BF40006 for ; Mon, 17 Feb 2025 11:22:17 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=MSnNVDTU; spf=pass (imf07.hostedemail.com: domain of tabba@google.com designates 209.85.160.172 as permitted sender) smtp.mailfrom=tabba@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739791337; a=rsa-sha256; cv=none; b=0sW9cLjb0HuCF6ivG54JMLKuTlG3CrS1TAGv1IDmh3PO/6yl2qLKRYx45oKER6HfNbS5d8 URuxO9ZIf7JLCU0UvADk2tr0qDRLBVE4olYStZlwG9R3qATQFlTGG1tf/u8PTx25TgpXll hkX8vIRpqvh+YNjhnAAk4MJiFuKZciQ= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=MSnNVDTU; spf=pass (imf07.hostedemail.com: domain of tabba@google.com designates 209.85.160.172 as permitted sender) smtp.mailfrom=tabba@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=1739791337; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2BNFct3UePzHwIotoHJ2GKRNF14AfZG/WsMOMMP2GWA=; b=dzbsthehCk/BsQlOwlKmYUb6eA4ou2L6r28JJemE7R1gw8yrKwuihzGTIwr+1OqK/iJjqn GQKWEEcVCDM0apqH7+goW5tJvaN2gSJwE4f5LwjBFKIgl/G+SDdnZ8WIEIMJxbOGAF+kLn nbl45ue42dwCl2myvhK9KA6dr6r8hCE= Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-4718aea0718so433031cf.0 for ; Mon, 17 Feb 2025 03:22:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1739791336; x=1740396136; darn=kvack.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=2BNFct3UePzHwIotoHJ2GKRNF14AfZG/WsMOMMP2GWA=; b=MSnNVDTUQkoR0MpX1iGFIoEgfopX4vGLfnOk+z4eWnNpCfE1KjZmpPGZW1Lo3W8vgL 4op6DpyaOcqBtnKjmdMTsLP9pb5kFTv0HEuQwJaiL9KO3dRZKcvwJ1vFNICno1uaZc/n e7ctiJBGkLD7xEQZIIIcxqkTxlTwNVu4cOk70+L++8Mj/2nNIjIFey1hmN+P5G59Es2s LtjooN3oH2YGbaLUfBSbl8XzmEFL66HcduJ1MQLLScoib16QWstN4mylqwIxA8s4TwCl TP3xAPZix1xhKLpuUhXMJifRc5NiE4sAJ1I5AELZZTuAKzT7Fhy7BaJ/L1YzUMeu7j4Y vGeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739791336; x=1740396136; h=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=2BNFct3UePzHwIotoHJ2GKRNF14AfZG/WsMOMMP2GWA=; b=rGcVh7A8q/BrqkXkppX8CiPBK5E6kqUNTvF55lyrxOrZGjVtlsbcU7s+74utbmb1u2 cPYX8zs1HgCCtxIU1nSzMOk6HeC8GGmgvX4YWf109lloLkT3TXwb2lYXxQeqnUx/CSqS WL2KGTPIEBmVUqTjWTBAOJvC96sZyH7q8KU2NtdQqZLQFv7GGqE8FK6fr726RrdPY28R aHo7Z4BZKOJpPLHrpObdU8mrvqB3p0T/o7MjH+/ubOb2xVoiuJ4tf6xsgFvC+K5Q+oDg stgxerjfO1oGvTR5v9KsNdHSzZoizflTf2XWvfrU+RodbAAKnVkPEj0YCKew9TLEMMUu 7kMA== X-Forwarded-Encrypted: i=1; AJvYcCWMWC5XLF+O32GOQ7X9KUMptDZ2UW0O+uLSrPQzQPfRh/nwmueMI0B5c3Ua1ZfFHtdfZSjQbErHkA==@kvack.org X-Gm-Message-State: AOJu0Yz33DU3+5b4y/lL77iTkhqqqHC0NUq29VBOLQMkf5M4uwIOW4HP KBejTgjcWil31jZ3uT/9Pem5LMKIZHD6lHdNf2tmiFlXNIsNIICETqoblEqzlsvwdPkymyzKAl3 Va084yiOFQcSrse5iEd1wM0tgLw5d3D7g0niB X-Gm-Gg: ASbGncs4NolIL1skGOwOqhWG5rcIicvvDECjebiNOAkhexXIfkx8lnIHES9SKLTAc7P nmQDINZJERaOMQc/kqPPxl2P+ap3GhkigI9Y34EnePhlYmGD2NVO3USpQCzr5Fx6DBCJ/3Jw= X-Google-Smtp-Source: AGHT+IGDUh34bmbyxSqWLPTSAJ5itWnJM39TpQStwZ9ZwHdgk/yvqH+R9kp7FeNsIeAxQHY19whrtQnqkUDlrS/JJKA= X-Received: by 2002:ac8:7d52:0:b0:466:9af1:5a35 with SMTP id d75a77b69052e-471dc776b3emr6184571cf.10.1739791336049; Mon, 17 Feb 2025 03:22:16 -0800 (PST) MIME-Version: 1.0 References: <20250211121128.703390-1-tabba@google.com> <20250211121128.703390-3-tabba@google.com> <4311493d-c709-485a-a36d-456e5c57c593@suse.cz> <5a2f8aaa-1664-48ee-8fb0-3fa80e2e8a23@suse.cz> In-Reply-To: <5a2f8aaa-1664-48ee-8fb0-3fa80e2e8a23@suse.cz> From: Fuad Tabba Date: Mon, 17 Feb 2025 11:21:39 +0000 X-Gm-Features: AWEUYZn1zu8baO-EPGcq1E5QUlaaFL8dKny9INkDAvKjV2vh7r75A7EttgWd8IM Message-ID: Subject: Re: [PATCH v3 02/11] KVM: guest_memfd: Handle final folio_put() of guest_memfd pages To: Vlastimil Babka Cc: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org, pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, willy@infradead.org, akpm@linux-foundation.org, xiaoyao.li@intel.com, yilun.xu@intel.com, chao.p.peng@linux.intel.com, jarkko@kernel.org, amoorthy@google.com, dmatlack@google.com, yu.c.zhang@linux.intel.com, isaku.yamahata@intel.com, mic@digikod.net, vannapurve@google.com, ackerleytng@google.com, mail@maciej.szmigiero.name, david@redhat.com, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com, suzuki.poulose@arm.com, steven.price@arm.com, quic_eberman@quicinc.com, quic_mnalajal@quicinc.com, quic_tsoni@quicinc.com, quic_svaddagi@quicinc.com, quic_cvanscha@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, catalin.marinas@arm.com, james.morse@arm.com, yuzenghui@huawei.com, oliver.upton@linux.dev, maz@kernel.org, will@kernel.org, qperret@google.com, keirf@google.com, roypat@amazon.co.uk, shuah@kernel.org, hch@infradead.org, jgg@nvidia.com, rientjes@google.com, jhubbard@nvidia.com, fvdl@google.com, hughd@google.com, jthoughton@google.com Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: ds6kmgeekzok1bzjzfkkn7qkm5ij5ksy X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4F2BF40006 X-Rspam-User: X-HE-Tag: 1739791337-266157 X-HE-Meta: U2FsdGVkX1/nSVuL8z0TFPL/oc2Ib6XWeHM4F6eFicDlAzLYD32OjPjMdjSEFfHG+ecFIUIXnN3r8hLZJVmW5dgYSYpbWR7fCFzZoc5oqduMDc2PDVJjukjXu9MbGpOq3nhkWSognvxCw09hVXvA6+32o82x8e/QJiDaQLUlIPpfx0iwULL2z+y+jTR4DzLeYLt7d4bhdR4hpTYPfbf1UVrxMNgOLFgq8kAAFGQqhlvDE/buqQRTeqD4tuYJ+5P7x/s0UIUbY/zmyEPl/BJ46ahJfld6XgG4S7NCsjRoc3anL+hCx+7IctOJkuBIoucmlx44TGGlW/9AUBgQt/27EccZ5Cs8RV2rb59RYDHtMkfNgxTS+sCYZNwsO/Kgb7RLr2Ux+EyuXzE39LMuUsP/etDty8hKyJJEv4Y2fHs2yeFIQmTiOOfUoMIJg9RTaFBhuDMSw4mt7FKSErx+YlGPeQSAxMd83iTBknxLFI2ixEsiT9cwNuFEnQunFYYflWZEh4SLYntKKhOvOjUoOqEdTwffuLCGRVCuWED3W/qzi+3s1p/Y5bz2+b/NYHB4t0JAZj+qVgx6TNhNI2xD5b/T23EYDIbO0SCGMu1xewlZFl1L7Zayiqn9oBppE+P/YdRO+PZNFjJi+JvA32pHkhUK6Aez26Wt/A/OgMHWYoXLiE4vvY2xAUILPNgzqIZrexXXh8APZPioI8KOjWhrkuO0jhLxj17vt0I+EhsKgTMUkcDpbXAzZ1zfe9jVp1yTx7ndAGnysysf3OtZb7KQamOHhJ/V7lqGbA/ZynRIl4G859QX8GO9tFsinCOxl2C9nl0qKvj6tGobwNzw1Za9orEQ9Fm7Uwq1+BrFhMXkvn8vSR2+zJsPkRXtfjtPWCD2jpGeMOI4F4gsqeeFeWr45XRL1LxhGudTC3o8Z1zx0NuTwxGIMSVFB5kAl+id2291WL3zExOvt88RX6b7lIWM/tg WnN0IlHo nvj1x7IxYhzS4dqZ5hIFFfeTFcmkq1V6XD2B+iEfiP347pcJ1r+li6cj4kVDudBsfoYcqHQ2TNeSH4arq8RpBHK+0xq7rxZ31ZjM9MpJDGILRgC35OkMNlpFCCtdxdPhooKePGWkNnTMJ8E7lNX3nFKo5qHLfv8c8MZCLWzFDwsfPlrG0VYSumZUFemCQIWa1cYnrh7ixc+sEypa1y5cgjEzlWByrxKYylT2qDY1Ul0SazaeIQTB3QiLZSk5s8UqhLF3yAnNoMJorX6/QkDw3AwigAbL07lfXsM2LdkeBKGST29R5KML8lUPWAUlDImOiS3Tw7F0x7saFYAg9h/vWRcIwITC/bsVcqeR36UoffJk8MyI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000016, 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 Mon, 17 Feb 2025 at 11:21, Vlastimil Babka wrote: > > On 2/17/25 11:12, Fuad Tabba wrote: > > Hi Vlastimil, > > > > On Mon, 17 Feb 2025 at 09:49, Vlastimil Babka wrote: > >> > >> On 2/11/25 13:11, Fuad Tabba wrote: > >> > Before transitioning a guest_memfd folio to unshared, thereby > >> > disallowing access by the host and allowing the hypervisor to > >> > transition its view of the guest page as private, we need to be > >> > sure that the host doesn't have any references to the folio. > >> > > >> > This patch introduces a new type for guest_memfd folios, which > >> > isn't activated in this series but is here as a placeholder and > >> > to facilitate the code in the next patch. This will be used in > >> > >> It's not clear to me how the code in the next page is facilitated as it > >> doesn't use any of this? > > > > I'm sorry about that, I'm missing the word "series". i.e., > > > >> > This patch introduces a new type for guest_memfd folios, which > >> > isn't activated in this series but is here as a placeholder and > >> > to facilitate the code in the next patch *series*. > > > > I'm referring to this series: > > https://lore.kernel.org/all/20250117163001.2326672-1-tabba@google.com/ > > > >> > the future to register a callback that informs the guest_memfd > >> > subsystem when the last reference is dropped, therefore knowing > >> > that the host doesn't have any remaining references. > >> > > >> > Signed-off-by: Fuad Tabba > >> > --- > >> > include/linux/kvm_host.h | 9 +++++++++ > >> > include/linux/page-flags.h | 17 +++++++++++++++++ > >> > mm/debug.c | 1 + > >> > mm/swap.c | 9 +++++++++ > >> > virt/kvm/guest_memfd.c | 7 +++++++ > >> > 5 files changed, 43 insertions(+) > >> > > >> > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > >> > index f34f4cfaa513..8b5f28f6efff 100644 > >> > --- a/include/linux/kvm_host.h > >> > +++ b/include/linux/kvm_host.h > >> > @@ -2571,4 +2571,13 @@ long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu, > >> > struct kvm_pre_fault_memory *range); > >> > #endif > >> > > >> > +#ifdef CONFIG_KVM_GMEM_SHARED_MEM > >> > +void kvm_gmem_handle_folio_put(struct folio *folio); > >> > +#else > >> > +static inline void kvm_gmem_handle_folio_put(struct folio *folio) > >> > +{ > >> > + WARN_ON_ONCE(1); > >> > +} > >> > >> Since the caller is guarded by CONFIG_KVM_GMEM_SHARED_MEM, do we need the > >> CONFIG_KVM_GMEM_SHARED_MEM=n variant at all? > > > > No. I'll remove it. > > > >> > +#endif > >> > + > >> > #endif > >> > diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h > >> > index 6dc2494bd002..734afda268ab 100644 > >> > --- a/include/linux/page-flags.h > >> > +++ b/include/linux/page-flags.h > >> > @@ -933,6 +933,17 @@ enum pagetype { > >> > PGTY_slab = 0xf5, > >> > PGTY_zsmalloc = 0xf6, > >> > PGTY_unaccepted = 0xf7, > >> > + /* > >> > + * guestmem folios are used to back VM memory as managed by guest_memfd. > >> > + * Once the last reference is put, instead of freeing these folios back > >> > + * to the page allocator, they are returned to guest_memfd. > >> > + * > >> > + * For now, guestmem will only be set on these folios as long as they > >> > + * cannot be mapped to user space ("private state"), with the plan of > >> > >> Might be a bit misleading as I don't think it's set yet as of this series. > >> But I guess we can keep it to avoid another update later. > > > > You're right, it's not in this series. But as you said, the idea is to > > have the least amount of churn in the core mm code. > > > >> > + * always setting that type once typed folios can be mapped to user > >> > + * space cleanly. > >> > + */ > >> > + PGTY_guestmem = 0xf8, > >> > > >> > PGTY_mapcount_underflow = 0xff > >> > }; > >> > @@ -1082,6 +1093,12 @@ FOLIO_TYPE_OPS(hugetlb, hugetlb) > >> > FOLIO_TEST_FLAG_FALSE(hugetlb) > >> > #endif > >> > > >> > +#ifdef CONFIG_KVM_GMEM_SHARED_MEM > >> > +FOLIO_TYPE_OPS(guestmem, guestmem) > >> > +#else > >> > +FOLIO_TEST_FLAG_FALSE(guestmem) > >> > +#endif > >> > + > >> > PAGE_TYPE_OPS(Zsmalloc, zsmalloc, zsmalloc) > >> > > >> > /* > >> > diff --git a/mm/debug.c b/mm/debug.c > >> > index 8d2acf432385..08bc42c6cba8 100644 > >> > --- a/mm/debug.c > >> > +++ b/mm/debug.c > >> > @@ -56,6 +56,7 @@ static const char *page_type_names[] = { > >> > DEF_PAGETYPE_NAME(table), > >> > DEF_PAGETYPE_NAME(buddy), > >> > DEF_PAGETYPE_NAME(unaccepted), > >> > + DEF_PAGETYPE_NAME(guestmem), > >> > }; > >> > > >> > static const char *page_type_name(unsigned int page_type) > >> > diff --git a/mm/swap.c b/mm/swap.c > >> > index 47bc1bb919cc..241880a46358 100644 > >> > --- a/mm/swap.c > >> > +++ b/mm/swap.c > >> > @@ -38,6 +38,10 @@ > >> > #include > >> > #include > >> > > >> > +#ifdef CONFIG_KVM_GMEM_SHARED_MEM > >> > +#include > >> > +#endif > >> > >> Do we need to guard the include? > > > > Yes, otherwise allnoconfig complains due to many of the x86 things it > > drags along if included but KVM isn't configured. I could put it in a > > different header that doesn't have this problem, but I couldn't think > > of a better header for this. > > Ok, you can add > Acked-by: Vlastimil Babka Thank you! /fuad