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 CD85A27A46A for ; Thu, 5 Jun 2025 17:15:58 +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=1749143760; cv=none; b=GntAMZHx5HTIzWxwhBb008ucrBx+TopAmgji64erPPapLIvQE8ohFYKvZbKVlLNzJHtidoP61kBhheC9g3fgxsjZcz/Lfo48UULcYBBfgzXLvDvRphelbb7t77lypiKsaVnOK2ZTfJxei+8Dr3qtT7PV/Mi0QWwyHxmpVMNYxW4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749143760; c=relaxed/simple; bh=owWI8WAYAlFsjJvXIyvYSUNXCshP/5FGhM730a1ama8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Ndm8rSZnyhYcWJ5xC3KoVJ57xh+V8Cg5xCNmZvPRdfxxruPd149cMhSsHCmrWJwVQl1n4WiwRzzBhzOpu4SD2bGriq/MX3Ael5Z8ubCLa8G52n/Xb9eJW0hyraW7nYoMeLLByn368F65yIUPgR1WCF91LB6BQOwfu7kNZSlhQ7M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ackerleytng.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=tiXXATfE; 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--ackerleytng.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tiXXATfE" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-742a969a4d0so1170616b3a.2 for ; Thu, 05 Jun 2025 10:15:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749143758; x=1749748558; 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=1BvVogHbLCy3WniKJnzNXayCUjBrxVyVRH9sGv66360=; b=tiXXATfEMA7Cv0bGj0LDF6x1n/TjkXBr4rFmaofyFnxiC8SMk92R22yxPaG7WZoPkW ERxg/mD/oLRTVX1JDgUq3N0DobXZGuAKBrtrk/TylVBnUMn8azm93tC2Imwv2neIbxJT ktU0n/UnhrM7zM69AllYiIE1r2vM3dCAQHr1Ro4YpHnxgCVw1qSPAKXHTrLjQPahDwDJ KIOndle5g3Wali2zbkcnHOupiZO+yoedawczAyp1i1rB1qK5Km1bnAYrDA/jRw4nHd1+ Tv81yZ1HryL5+CJE9Lv+3n85hV3oNO7FuNg4avPeC1/ZOqPgivtLsauRBlhq0HcvSPvK 9eHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749143758; x=1749748558; 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=1BvVogHbLCy3WniKJnzNXayCUjBrxVyVRH9sGv66360=; b=kAqNBA7NeVMjTzjIbah4hpzngnZy+UEBHn6t4SXHUdM1g9ZIjT1eQ+dTZzyJRYh1Yw o0nomofio180JgVy5vFQOZjHw4QL4qF7ilm2+FICwhF68zfxgQ3KbypPpDnPsh9gO6Kd ReKGCJjTOQLYGaRyzNWGbbavp2Y5yIt+ckCUondQsUDS/NZtb/voEeIFPSw75sTkv05K kX7oKtUP3nFKpCcstUP/P/WDdYFAJC5TggIlM5L7oTnalQw/Gbq0tNWsbAJD4Tb9vNL3 JmbBd9jWLeNIott7Cu6+7gRItzZO5x9eQGeeBaNAwJwYTkOnDlHgotgcJ7qB7lJv7OED EfTQ== X-Forwarded-Encrypted: i=1; AJvYcCVl4Ccsx0k2f5HLp9QWc7SLSmUt+M5DouA3u/mpG9BY8U2wKFcRG5YHepUF9p4tPAkq6VKSEpduDFYQAgU=@vger.kernel.org X-Gm-Message-State: AOJu0Yx3xOXPvTuBV1zZRWT/aslj2DnsepjBGWdLtAzcsh/SDOlJtynY +OKkLwd65rseyLs4EswJB5Dme5P13G1Ec+xVNxIUyzxPQbtLD7UKeCJf+bieDJ180et8xUDRwoU 39IdWMM0Ki4iTPaQldW5lSmYdrw== X-Google-Smtp-Source: AGHT+IHR3VOIiMaXef3dSyiefFvR0BSAkbNXMc/PNNBHc5HJZyLp7dkRgDqMefJVOModcnjrV8QSGFx91L6zxAGgtw== X-Received: from pfef13.prod.google.com ([2002:a05:6a00:228d:b0:746:301b:10ca]) (user=ackerleytng job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:6ca3:b0:736:34a2:8a23 with SMTP id d2e1a72fcca58-74827f10b6bmr586610b3a.15.1749143757947; Thu, 05 Jun 2025 10:15:57 -0700 (PDT) Date: Thu, 05 Jun 2025 10:15:56 -0700 In-Reply-To: <85ae7dc691c86a1ae78d56d413a1b13b444b57cd.camel@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <7753dc66229663fecea2498cf442a768cb7191ba.1747264138.git.ackerleytng@google.com> <85ae7dc691c86a1ae78d56d413a1b13b444b57cd.camel@intel.com> Message-ID: Subject: Re: [RFC PATCH v2 38/51] KVM: guest_memfd: Split allocator pages for guest_memfd use From: Ackerley Tng To: "Edgecombe, Rick P" , "kvm@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , "x86@kernel.org" Cc: "palmer@dabbelt.com" , "pvorel@suse.cz" , "catalin.marinas@arm.com" , "Miao, Jun" , "Shutemov, Kirill" , "pdurrant@amazon.co.uk" , "steven.price@arm.com" , "peterx@redhat.com" , "vbabka@suse.cz" , "jack@suse.cz" , "amoorthy@google.com" , "maz@kernel.org" , "keirf@google.com" , "vkuznets@redhat.com" , "quic_eberman@quicinc.com" , "mail@maciej.szmigiero.name" , "hughd@google.com" , "anthony.yznaga@oracle.com" , "Wang, Wei W" , "Du, Fan" , "Wieczor-Retman, Maciej" , "quic_svaddagi@quicinc.com" , "Hansen, Dave" , "ajones@ventanamicro.com" , "paul.walmsley@sifive.com" , "nsaenz@amazon.es" , "aik@amd.com" , "usama.arif@bytedance.com" , "quic_mnalajal@quicinc.com" , "fvdl@google.com" , "rppt@kernel.org" , "quic_cvanscha@quicinc.com" , "bfoster@redhat.com" , "willy@infradead.org" , "anup@brainfault.org" , "thomas.lendacky@amd.com" , "tabba@google.com" , "mic@digikod.net" , "oliver.upton@linux.dev" , "akpm@linux-foundation.org" , "Zhao, Yan Y" , "binbin.wu@linux.intel.com" , "muchun.song@linux.dev" , "Li, Zhiquan1" , "rientjes@google.com" , "mpe@ellerman.id.au" , "Aktas, Erdem" , "david@redhat.com" , "jgg@ziepe.ca" , "Annapurve, Vishal" , "Xu, Haibo1" , "jhubbard@nvidia.com" , "Yamahata, Isaku" , "jthoughton@google.com" , "will@kernel.org" , "steven.sistare@oracle.com" , "jarkko@kernel.org" , "quic_pheragu@quicinc.com" , "chenhuacai@kernel.org" , "Huang, Kai" , "shuah@kernel.org" , "dwmw@amazon.co.uk" , "pankaj.gupta@amd.com" , "Peng, Chao P" , "nikunj@amd.com" , "Graf, Alexander" , "viro@zeniv.linux.org.uk" , "pbonzini@redhat.com" , "yuzenghui@huawei.com" , "jroedel@suse.de" , "suzuki.poulose@arm.com" , "jgowans@amazon.com" , "Xu, Yilun" , "liam.merwick@oracle.com" , "michael.roth@amd.com" , "quic_tsoni@quicinc.com" , "richard.weiyang@gmail.com" , "Weiny, Ira" , "aou@eecs.berkeley.edu" , "Li, Xiaoyao" , "qperret@google.com" , "kent.overstreet@linux.dev" , "dmatlack@google.com" , "james.morse@arm.com" , "brauner@kernel.org" , "pgonda@google.com" , "quic_pderrin@quicinc.com" , "hch@infradead.org" , "roypat@amazon.co.uk" , "seanjc@google.com" Content-Type: text/plain; charset="UTF-8" "Edgecombe, Rick P" writes: > On Wed, 2025-05-14 at 16:42 -0700, Ackerley Tng wrote: >> + >> +static pgoff_t kvm_gmem_compute_invalidate_bound(struct inode *inode, >> + pgoff_t bound, bool start) >> +{ >> + size_t nr_pages; >> + void *priv; >> + >> + if (!kvm_gmem_has_custom_allocator(inode)) > > General comment - It's a bit unfortunate how kvm_gmem_has_custom_allocator() is > checked all over the place across this series. There are only two allocators > after this, right? So one is implemented with callbacks presumably designed to > fit other allocators, and one has special case logic in guest_memfd.c. > > Did you consider designing struct guestmem_allocator_operations so that it could > encapsulate the special logic for both the existing and new > allocators? I did, yes. I believe it is definitely possible to make standard 4K pages become another allocator too. I would love to clean this up. Not sure if that will be a new series after this one, or part of this one though. > If it > didn't work well, could we expect that a next allocator would actually fit > struct guestmem_allocator_operations? > This was definitely designed to support allocators beyond guestmem_hugetlb, though I won't promise that it will be a perfect fit for future allocators. This is internal to the kernel and this interface can be updated for future allocators though. >> + return bound; >> + >> + priv = kvm_gmem_allocator_private(inode); >> + nr_pages = kvm_gmem_allocator_ops(inode)->nr_pages_in_folio(priv); >> + >> + if (start) >> + return round_down(bound, nr_pages); >> + else >> + return round_up(bound, nr_pages); >> +} >> + >> +static pgoff_t kvm_gmem_compute_invalidate_start(struct inode *inode, >> + pgoff_t bound) >> +{ >> + return kvm_gmem_compute_invalidate_bound(inode, bound, true); >> +} >> + >> +static pgoff_t kvm_gmem_compute_invalidate_end(struct inode *inode, >> + pgoff_t bound) >> +{ >> + return kvm_gmem_compute_invalidate_bound(inode, bound, false); >> +} >> +