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 2A04C279904 for ; Thu, 5 Jun 2025 17:16:20 +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=1749143783; cv=none; b=EjZp/AasUvEzPXf+6hCqFPgAIgDudQlW9s0urZAtmVL0Kpb/a7+oDsBhuGNu0m5PUFXHrXpPUwzonU1c0oJkmLL2NqTsb5Fw/ttDcOOiwpKbmW1Apenzv00K8S1TlsVsHLczP690sEPuNWMHeCYBa5NRgrx3ZgnhCEkj0qZiL/o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749143783; c=relaxed/simple; bh=owWI8WAYAlFsjJvXIyvYSUNXCshP/5FGhM730a1ama8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RW4XJiTgticMM9W71vf8Iw0gJAfnXdTSyAwEa3bH7nFmoxEUSI/OfpZa//lnNEtfnsrkqFQT8xKP+gvlJ+9SkYWqerw/3N8NPdLu16BPuH4cWNM92/ik6WCO/2Nq8M1Ic+Rzgs+CLDG6PYleS0dm4CBY1f/RjZtjLbDzPpK5Nt8= 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=HXhGNoaM; 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--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="HXhGNoaM" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-747d84fe5f8so713757b3a.3 for ; Thu, 05 Jun 2025 10:16:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749143780; x=1749748580; 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=HXhGNoaMCx/06PTy7ZzJ94h1q3GbAMqkz3lxdB9Pz9xY08lx/J9fImFQiAfE2xC0g7 hTqJ41j3sYEEvTCTGhLxCfBhBvMKzZQmUSbfmH0xHwRTLCkznus6fAci8fe09zAZPmH2 wWTazphl7n115ZpmYrBaIHYJKgX9kBmF208OIVxxFKu0ifTNSNHL87EsNhkfWfy3hu2K hDAaLI47s3ONRyXOQkmyID4AgNL8ntqfAz8p5nU/U+3TrcZZIigzMk1a/XW76QPwX1bM b0tJIasRcmileJ56MFKPBoZ91h3KEApX4aUWew3eR0UYynEYAe6J7Rcae8M2/bvwQ9PW m7JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749143780; x=1749748580; 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=W3xEkrH6957h5JWbTP7B9UVHFbPwE62uCd6cHbXD4rixMpkSWit8T75h/xfzTYGKAp LkZ/yuO273qh4I2nl4z/c6nVQvqk9xC+krljcTCvSfLryot/odCD6ZuQVmLrOAmG33O2 jv04pNNRv5w3dDsk5t0vxyeKITYDAGvCjj4Odk7Ej8ZlkB0dJ86whLJoXhbU1RQ3LUZK Gm7ObshJ7MKVyORYWuKvSqUm5VrKJ8GrZtWllfjo4sjV0+f2uHy3RSihtMlgC5jicxMr 97b3hMyKLCCPl+FNhnv14jgFfDui6P0VMszLEBOxD8BxwrV/M9F/J4twITNXPPXbsXpi 6iew== X-Forwarded-Encrypted: i=1; AJvYcCUmtQ2dtVI0XfHXKUK23a6EXUF7ohzfFBflyKpxXkGx4NBbXyvduZVZmcDoj/VqRfuygl7T9xbTa/4k1F8=@vger.kernel.org X-Gm-Message-State: AOJu0YzHMMz59T+g82sDA2+2sTeSSjxSQ/zHfEfjUSEZZRcfBoN+0ROZ n9idozpNMDFJ4j18H3tRF7MuFvXYMoIwHVUu9uGaueMA570yXSn9N5Ce4nAny/uJhv3r/DHNjaC Enwn/LK6WVF9GdaTCyz/82bkInw== X-Google-Smtp-Source: AGHT+IHrHrufhfOgqsSZMYYGmnf8by8Ce09NkloD1+JcTL5IynPrkehej7WsZeM9qeq9p5D9AWLP4i2IXr0GIs1k+Q== X-Received: from pfko22.prod.google.com ([2002:a05:6a00:2156:b0:746:30f0:9b33]) (user=ackerleytng job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:218e:b0:73e:30af:f479 with SMTP id d2e1a72fcca58-74828067b30mr550569b3a.19.1749143780316; Thu, 05 Jun 2025 10:16:20 -0700 (PDT) Date: Thu, 05 Jun 2025 10:16:18 -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); >> +} >> +