lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <87ecv9ojuh.fsf@DESKTOP-5N7EMDA>
Date: Tue, 24 Jun 2025 12:16:06 +0800
From: "Huang, Ying" <ying.huang@...ux.alibaba.com>
To: Shivank Garg <shivankg@....com>
Cc: <seanjc@...gle.com>,  <david@...hat.com>,  <vbabka@...e.cz>,
  <willy@...radead.org>,  <akpm@...ux-foundation.org>,  <shuah@...nel.org>,
  <pbonzini@...hat.com>,  <brauner@...nel.org>,  <viro@...iv.linux.org.uk>,
  <ackerleytng@...gle.com>,  <paul@...l-moore.com>,  <jmorris@...ei.org>,
  <serge@...lyn.com>,  <pvorel@...e.cz>,  <bfoster@...hat.com>,
  <tabba@...gle.com>,  <vannapurve@...gle.com>,  <chao.gao@...el.com>,
  <bharata@....com>,  <nikunj@....com>,  <michael.day@....com>,
  <yan.y.zhao@...el.com>,  <Neeraj.Upadhyay@....com>,
  <thomas.lendacky@....com>,  <michael.roth@....com>,  <aik@....com>,
  <jgg@...dia.com>,  <kalyazin@...zon.com>,  <peterx@...hat.com>,
  <jack@...e.cz>,  <rppt@...nel.org>,  <hch@...radead.org>,
  <cgzones@...glemail.com>,  <ira.weiny@...el.com>,  <rientjes@...gle.com>,
  <roypat@...zon.co.uk>,  <ziy@...dia.com>,  <matthew.brost@...el.com>,
  <joshua.hahnjy@...il.com>,  <rakie.kim@...com>,  <byungchul@...com>,
  <gourry@...rry.net>,  <kent.overstreet@...ux.dev>,  <apopple@...dia.com>,
  <chao.p.peng@...el.com>,  <amit@...radead.org>,  <ddutile@...hat.com>,
  <dan.j.williams@...el.com>,  <ashish.kalra@....com>,  <gshan@...hat.com>,
  <jgowans@...zon.com>,  <pankaj.gupta@....com>,  <papaluri@....com>,
  <yuzhao@...gle.com>,  <suzuki.poulose@....com>,
  <quic_eberman@...cinc.com>,  <aneeshkumar.kizhakeveetil@....com>,
  <linux-fsdevel@...r.kernel.org>,  <linux-mm@...ck.org>,
  <linux-kernel@...r.kernel.org>,  <linux-security-module@...r.kernel.org>,
  <kvm@...r.kernel.org>,  <linux-kselftest@...r.kernel.org>,
  <linux-coco@...ts.linux.dev>
Subject: Re: [RFC PATCH v8 5/7] KVM: guest_memfd: Add slab-allocated inode
 cache

Shivank Garg <shivankg@....com> writes:

> Add dedicated inode structure (kvm_gmem_inode_info) and slab-allocated
> inode cache for guest memory backing, similar to how shmem handles inodes.
>
> This adds the necessary allocation/destruction functions and prepares
> for upcoming guest_memfd NUMA policy support changes.
>
> Signed-off-by: Shivank Garg <shivankg@....com>
> ---
>  virt/kvm/guest_memfd.c | 51 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 51 insertions(+)
>
> diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
> index 159df462d193..5a1ce6f5e287 100644
> --- a/virt/kvm/guest_memfd.c
> +++ b/virt/kvm/guest_memfd.c
> @@ -17,6 +17,15 @@ struct kvm_gmem {
>  	struct list_head entry;
>  };
>  
> +struct kvm_gmem_inode_info {
> +	struct inode vfs_inode;
> +};
> +
> +static inline struct kvm_gmem_inode_info *KVM_GMEM_I(struct inode *inode)
> +{
> +	return container_of(inode, struct kvm_gmem_inode_info, vfs_inode);
> +}
> +
>  /**
>   * folio_file_pfn - like folio_file_page, but return a pfn.
>   * @folio: The folio which contains this index.
> @@ -392,8 +401,33 @@ static struct file_operations kvm_gmem_fops = {
>  	.fallocate	= kvm_gmem_fallocate,
>  };
>  
> +static struct kmem_cache *kvm_gmem_inode_cachep;
> +
> +static struct inode *kvm_gmem_alloc_inode(struct super_block *sb)
> +{
> +	struct kvm_gmem_inode_info *info;
> +
> +	info = alloc_inode_sb(sb, kvm_gmem_inode_cachep, GFP_KERNEL);
> +	if (!info)
> +		return NULL;
> +
> +	return &info->vfs_inode;
> +}
> +
> +static void kvm_gmem_destroy_inode(struct inode *inode)
> +{
> +}
> +
> +static void kvm_gmem_free_inode(struct inode *inode)
> +{
> +	kmem_cache_free(kvm_gmem_inode_cachep, KVM_GMEM_I(inode));
> +}
> +
>  static const struct super_operations kvm_gmem_super_operations = {
>  	.statfs		= simple_statfs,
> +	.alloc_inode	= kvm_gmem_alloc_inode,
> +	.destroy_inode	= kvm_gmem_destroy_inode,
> +	.free_inode	= kvm_gmem_free_inode,
>  };
>  
>  static int kvm_gmem_init_fs_context(struct fs_context *fc)
> @@ -426,10 +460,26 @@ static int kvm_gmem_init_mount(void)
>  	return 0;
>  }
>  
> +static void kvm_gmem_init_inode(void *foo)
> +{
> +	struct kvm_gmem_inode_info *info = foo;
> +
> +	inode_init_once(&info->vfs_inode);
> +}
> +
> +static void kvm_gmem_init_inodecache(void)
> +{
> +	kvm_gmem_inode_cachep = kmem_cache_create("kvm_gmem_inode_cache",
> +						  sizeof(struct kvm_gmem_inode_info),
> +						  0, SLAB_ACCOUNT,
> +						  kvm_gmem_init_inode);

Check the return value?

And, I'm not a big fan of (logically) one line function encapsulation.

> +}
> +
>  int kvm_gmem_init(struct module *module)
>  {
>  	kvm_gmem_fops.owner = module;
>  
> +	kvm_gmem_init_inodecache();
>  	return kvm_gmem_init_mount();

kmem_cache_destroy(kvm_gmem_inode_cachep) if kvm_gmem_init_mount()
return with error?

>  }
>  
> @@ -437,6 +487,7 @@ void kvm_gmem_exit(void)
>  {
>  	kern_unmount(kvm_gmem_mnt);
>  	kvm_gmem_mnt = NULL;
> +	kmem_cache_destroy(kvm_gmem_inode_cachep);
>  }
>  
>  static int kvm_gmem_migrate_folio(struct address_space *mapping,

---
Best Regards,
Huang, Ying

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ