[PATCH 02/20] mm/mshare: pre-populate msharefs with information file

From: Anthony Yznaga
Date: Fri Jan 24 2025 - 18:57:01 EST


From: Khalid Aziz <khalid@xxxxxxxxxx>

Users of mshare need to know the size and alignment requirement
for shared regions. Pre-populate msharefs with a file, mshare_info,
that provides this information. For now, pagetable sharing is
hardcoded to be at the PUD level.

Signed-off-by: Khalid Aziz <khalid@xxxxxxxxxx>
Signed-off-by: Anthony Yznaga <anthony.yznaga@xxxxxxxxxx>
---
mm/mshare.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 75 insertions(+), 2 deletions(-)

diff --git a/mm/mshare.c b/mm/mshare.c
index 49d32e0c20d2..6d3760d1af8e 100644
--- a/mm/mshare.c
+++ b/mm/mshare.c
@@ -17,18 +17,74 @@
#include <linux/fs_context.h>
#include <uapi/linux/magic.h>

+const unsigned long mshare_align = P4D_SIZE;
+
static const struct file_operations msharefs_file_operations = {
.open = simple_open,
};

+struct msharefs_info {
+ struct dentry *info_dentry;
+};
+
+static ssize_t
+mshare_info_read(struct file *file, char __user *buf, size_t nbytes,
+ loff_t *ppos)
+{
+ char s[80];
+
+ sprintf(s, "%ld\n", mshare_align);
+ return simple_read_from_buffer(buf, nbytes, ppos, s, strlen(s));
+}
+
+static const struct file_operations mshare_info_ops = {
+ .read = mshare_info_read,
+ .llseek = noop_llseek,
+};
+
static const struct super_operations mshare_s_ops = {
.statfs = simple_statfs,
};

+static int
+msharefs_create_mshare_info(struct super_block *sb)
+{
+ struct msharefs_info *info = sb->s_fs_info;
+ struct dentry *root = sb->s_root;
+ struct dentry *dentry;
+ struct inode *inode;
+ int ret;
+
+ ret = -ENOMEM;
+ inode = new_inode(sb);
+ if (!inode)
+ goto out;
+
+ inode->i_ino = 2;
+ simple_inode_init_ts(inode);
+ inode_init_owner(&nop_mnt_idmap, inode, NULL, S_IFREG | 0444);
+ inode->i_fop = &mshare_info_ops;
+
+ dentry = d_alloc_name(root, "mshare_info");
+ if (!dentry)
+ goto out;
+
+ info->info_dentry = dentry;
+ d_add(dentry, inode);
+
+ return 0;
+out:
+ iput(inode);
+
+ return ret;
+}
+
static int
msharefs_fill_super(struct super_block *sb, struct fs_context *fc)
{
+ struct msharefs_info *info;
struct inode *inode;
+ int ret;

sb->s_blocksize = PAGE_SIZE;
sb->s_blocksize_bits = PAGE_SHIFT;
@@ -36,6 +92,12 @@ msharefs_fill_super(struct super_block *sb, struct fs_context *fc)
sb->s_op = &mshare_s_ops;
sb->s_time_gran = 1;

+ info = kzalloc(sizeof(*info), GFP_KERNEL);
+ if (!info)
+ return -ENOMEM;
+
+ sb->s_fs_info = info;
+
inode = new_inode(sb);
if (!inode)
return -ENOMEM;
@@ -51,7 +113,9 @@ msharefs_fill_super(struct super_block *sb, struct fs_context *fc)
if (!sb->s_root)
return -ENOMEM;

- return 0;
+ ret = msharefs_create_mshare_info(sb);
+
+ return ret;
}

static int
@@ -71,10 +135,19 @@ mshare_init_fs_context(struct fs_context *fc)
return 0;
}

+static void
+msharefs_kill_super(struct super_block *sb)
+{
+ struct msharefs_info *info = sb->s_fs_info;
+
+ kfree(info);
+ kill_litter_super(sb);
+}
+
static struct file_system_type mshare_fs = {
.name = "msharefs",
.init_fs_context = mshare_init_fs_context,
- .kill_sb = kill_litter_super,
+ .kill_sb = msharefs_kill_super,
};

static int __init
--
2.43.5