From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.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 4DF622BD013 for ; Fri, 3 Oct 2025 16:05:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759507560; cv=none; b=ELb2LCHZOb4SMXJdGXM41Wv5axiQyLXD+OKTvCSFp3v5/dwdjjpO1OZ/nuYYJkXkByc/4Jx4zhg4z1oFR++et3Yqs42aHlUVt6I4tnZ2RtkKFXc/cqAL32a+Dj0Oln935bcqlbAFRJb6cS+6yU/Ckpd4iL27AQRTVLo8cTTH5a4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759507560; c=relaxed/simple; bh=DTBd9BA1usFwsidcGi2Him6mYDP+NXsirmy/wzo3TNc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XIN6hcOeqUwEUMI8+OpEtTDLcKpuBcQ5wAsF4Gob+D63CzruTPlAeFDjrNqoufg5lt7jEdcvYJVfVWOOelpPtBjJht96oGiIMhX5P/rmoISZrFzMRpQSwurkUUIiWZLlknPq290GTmlAWyEFwPpD+TYfUkH0RfCXJ2HqMtjzWqw= 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=GGbVIeJ+; arc=none smtp.client-ip=209.85.210.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="GGbVIeJ+" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-781253de15aso4329635b3a.2 for ; Fri, 03 Oct 2025 09:05:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1759507558; x=1760112358; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Rr9Zgpsr/95Zre8MDjbJaLg4HUOz/eRCvS4su6KFtWM=; b=GGbVIeJ+vE7oLl3nM4aFJxtZeiVigNAZo5SXEoASC2hi2+6uG9rQ5rju9ctEBKh1CP 8WqwNT3ZVB6kJQJIZ997bsx3axb35sQ+KqY6Ck2DE4z/MJOtm2fD53gA5R3mtvUnRh7x Uw03A+o7JHCyGhiD/9yCKXSDiWbpVyd9hNjjim5UAEJvVoSU5g+dBtQk0niU8SwxgRhL P9md2oCHp/CYJLykveHKZsESBxjAyWlWW8IuXIRibPaUyI1L1A5njME3qfADIkKQw9sh 3Ej8ChselCtkl/LX7bYr2LzhORKWJiWwSQudvWPg6WtN22azb1Mh7rf4TATxNpNIp/j3 YDow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759507559; x=1760112359; h=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=Rr9Zgpsr/95Zre8MDjbJaLg4HUOz/eRCvS4su6KFtWM=; b=tMoVl1/TgFEjiAfZogSzY5ZQozpfM7YkTqhTunL+tp8Ovunr2cPCtszhiflCcoxIxC FWadSajgTQ2CewZjXsBmpDeL4ymdL15RVPij7f8uPWm/6vS1HViemaB9p1zCD7wCOvN2 nscSG6VvetnRdpyAbyKb+RbTsdqx7vjsN8mJvKIqYnBoZNXlxzY69ZewF80n7I01uxcn rBqSFYafKfdPwuXLcIacUhv2gQBvJYSi83ID9galCJ2fewOGrQU7xvaPBer27lbEuuo8 qh3P8wqkxT/dHcmRbXBD0CeHbKohi4uAS2mmMsxH8+nuOf2SfFtx4kehNfdX/c6UJfvd P/EQ== X-Forwarded-Encrypted: i=1; AJvYcCVNYpflt8o7y9mQ6cSCiMjehJZK4w4YZ2Ym9zlFknjrV+PlYOHGpLZ3zDZB4AyQppG8Hsfkk+Fo7uuSkkY=@vger.kernel.org X-Gm-Message-State: AOJu0YyBVE3/ltnZ8JGfF4bThWo9CB1cjMy0/fuYcp9vv28uIX+S8QN2 q4+T31WbNpvatmqyw8+s/LWCq/NhanGX09uzZb9hwcgGbINmSoZ62/H2EQBo40Eetr2bIdmFPiT yY20+vg== X-Google-Smtp-Source: AGHT+IGkAn/LwerysZuGwJxYNVKUT2Gz4Ib8pIhMx4SKsJOPx+xTCSenhBS2G7GLP8kza9/oaz73nVHnf4c= X-Received: from pgct2.prod.google.com ([2002:a05:6a02:5282:b0:b55:135:7cb9]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:3ca8:b0:245:fb85:ef69 with SMTP id adf61e73a8af0-32b620cbda2mr5197670637.40.1759507558303; Fri, 03 Oct 2025 09:05:58 -0700 (PDT) Date: Fri, 3 Oct 2025 09:05:56 -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: Message-ID: Subject: Re: [RFC PATCH v2 29/51] mm: guestmem_hugetlb: Wrap HugeTLB as an allocator for guest_memfd From: Sean Christopherson To: Ackerley Tng Cc: 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, shuah@kernel.org, steven.price@arm.com, steven.sistare@oracle.com, suzuki.poulose@arm.com, tabba@google.com, thomas.lendacky@amd.com, usama.arif@bytedance.com, vannapurve@google.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="us-ascii" On Fri, Oct 03, 2025, Sean Christopherson wrote: > On Wed, May 14, 2025, Ackerley Tng wrote: > > guestmem_hugetlb is an allocator for guest_memfd. It wraps HugeTLB to > > provide huge folios for guest_memfd. > > > > This patch also introduces guestmem_allocator_operations as a set of > > operations that allocators for guest_memfd can provide. In a later > > patch, guest_memfd will use these operations to manage pages from an > > allocator. > > > > The allocator operations are memory-management specific and are placed > > in mm/ so key mm-specific functions do not have to be exposed > > unnecessarily. > > This code doesn't have to be put in mm/, all of the #includes are to . > Unless I'm missing something, what you actually want to avoid is _exporting_ mm/ > APIs, and for that all that is needed is ensure the code is built-in to the kernel > binary, not to kvm.ko. > > diff --git a/virt/kvm/Makefile.kvm b/virt/kvm/Makefile.kvm > index d047d4cf58c9..c18c77e8a638 100644 > --- a/virt/kvm/Makefile.kvm > +++ b/virt/kvm/Makefile.kvm > @@ -13,3 +13,5 @@ kvm-$(CONFIG_HAVE_KVM_IRQ_ROUTING) += $(KVM)/irqchip.o > kvm-$(CONFIG_HAVE_KVM_DIRTY_RING) += $(KVM)/dirty_ring.o > kvm-$(CONFIG_HAVE_KVM_PFNCACHE) += $(KVM)/pfncache.o > kvm-$(CONFIG_KVM_GUEST_MEMFD) += $(KVM)/guest_memfd.o > + > +obj-$(subst m,y,$(CONFIG_KVM_GUEST_MEMFD)) += $(KVM)/guest_memfd_hugepages.o > \ No newline at end of file > > People may want the code to live in mm/ for maintenance and ownership reasons > (or not, I haven't followed the discussions on hugepage support), but that's a > very different justification than what's described in the changelog. > > And if the _only_ user is guest_memfd, putting this in mm/ feels quite weird. > And if we anticipate other users, the name guestmem_hugetlb is weird, because > AFAICT there's nothing in here that is in any way guest specific, it's just a > few APIs for allocating and accounting hugepages. > > Personally, I don't see much point in trying to make this a "generic" library, > in quotes because the whole guestmem_xxx namespace makes it anything but generic. > I don't see anything in mm/guestmem_hugetlb.c that makes me go "ooh, that's nasty, > I'm glad this is handled by a library". But if we want to go straight to a > library, it should be something that is really truly generic, i.e. not "guest" > specific in any way. Ah, the complexity and the mm-internal dependencies come along in the splitting and merging patch. Putting that code in mm/ makes perfect sense, but I'm still not convinced that putting _all_ of this code in mm/ is the correct split. As proposed, this is a weird combination of being an extension of guest_memfd, a somewhat generic library, _and_ a subsystem (e.g. the global workqueue and stash). _If_ we need a library, then IMO it should be a truly generic library. Any pieces that are guest_memfd specific belong in KVM. And any subsystem-like things should should probably be implemented as an extension to HugeTLB itself, which is already it's own subsytem. Emphasis on "if", because it's not clear to me that that a library is warranted. AFAICT, the novelty here is the splitting and re-merging of hugetlb folios, and that seems like it should be explicitly an extension of the hugetlb subsystem. E.g. that behavior needs to take hugetlb_lock, interact with global vmemmap state like hugetlb_optimize_vmemmap_key, etc. If that's implemented as something like hugetlb_splittable.c or whatever, and wired up to be explicitly configured via hugetlb_init(), then there may not be much left for a library.