@@ -303,6 +303,7 @@ Code Seq# Include File Comments
'v' 20-27 arch/powerpc/include/uapi/asm/vas-api.h VAS API
'v' C0-FF linux/meye.h conflict!
'w' all CERN SCI driver
+'x' 00-1F linux/msharefs.h msharefs filesystem
'y' 00-1F packet based user level communications
<mailto:zapman@interlan.net>
'z' 00-3F CAN bus card conflict!
new file mode 100644
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * msharefs defines a memory region that is shared across processes.
+ * ioctl is used on files created under msharefs to set various
+ * attributes on these shared memory regions
+ *
+ *
+ * Copyright (C) 2024 Oracle Corp. All rights reserved.
+ * Author: Khalid Aziz <khalid@kernel.org>
+ */
+
+#ifndef _UAPI_LINUX_MSHAREFS_H
+#define _UAPI_LINUX_MSHAREFS_H
+
+#include <linux/ioctl.h>
+#include <linux/types.h>
+
+/*
+ * msharefs specific ioctl commands
+ */
+#define MSHAREFS_GET_SIZE _IOR('x', 0, struct mshare_info)
+#define MSHAREFS_SET_SIZE _IOW('x', 1, struct mshare_info)
+
+struct mshare_info {
+ __u64 start;
+ __u64 size;
+};
+
+#endif
@@ -10,24 +10,91 @@
*
* Copyright (C) 2024 Oracle Corp. All rights reserved.
* Author: Khalid Aziz <khalid@kernel.org>
+ * Author: Matthew Wilcox <willy@infradead.org>
*
*/
#include <linux/fs.h>
#include <linux/fs_context.h>
+#include <linux/spinlock_types.h>
#include <uapi/linux/magic.h>
+#include <uapi/linux/msharefs.h>
const unsigned long mshare_align = P4D_SIZE;
struct mshare_data {
struct mm_struct *mm;
+ spinlock_t m_lock;
+ struct mshare_info minfo;
};
+static long
+msharefs_set_size(struct mm_struct *host_mm, struct mshare_data *m_data,
+ struct mshare_info *minfo)
+{
+ /*
+ * Validate alignment for start address and size
+ */
+ if (!minfo->size || ((minfo->start | minfo->size) & (mshare_align - 1))) {
+ spin_unlock(&m_data->m_lock);
+ return -EINVAL;
+ }
+
+ host_mm->mmap_base = minfo->start;
+ host_mm->task_size = minfo->size;
+
+ m_data->minfo.start = host_mm->mmap_base;
+ m_data->minfo.size = host_mm->task_size;
+ spin_unlock(&m_data->m_lock);
+
+ return 0;
+}
+
+static long
+msharefs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
+{
+ struct mshare_data *m_data = filp->private_data;
+ struct mm_struct *host_mm = m_data->mm;
+ struct mshare_info minfo;
+
+ switch (cmd) {
+ case MSHAREFS_GET_SIZE:
+ spin_lock(&m_data->m_lock);
+ minfo = m_data->minfo;
+ spin_unlock(&m_data->m_lock);
+
+ if (copy_to_user((void __user *)arg, &minfo, sizeof(minfo)))
+ return -EFAULT;
+
+ return 0;
+
+ case MSHAREFS_SET_SIZE:
+ if (copy_from_user(&minfo, (struct mshare_info __user *)arg,
+ sizeof(minfo)))
+ return -EFAULT;
+
+ /*
+ * If this mshare region has been set up once already, bail out
+ */
+ spin_lock(&m_data->m_lock);
+ if (m_data->minfo.size != 0) {
+ spin_unlock(&m_data->m_lock);
+ return -EINVAL;
+ }
+
+ return msharefs_set_size(host_mm, m_data, &minfo);
+
+ default:
+ return -ENOTTY;
+ }
+}
+
static const struct inode_operations msharefs_dir_inode_ops;
static const struct inode_operations msharefs_file_inode_ops;
static const struct file_operations msharefs_file_operations = {
.open = simple_open,
+ .unlocked_ioctl = msharefs_ioctl,
};
static int
@@ -51,6 +118,7 @@ msharefs_fill_mm(struct inode *inode)
goto err_free;
}
m_data->mm = mm;
+ spin_lock_init(&m_data->m_lock);
inode->i_private = m_data;
return 0;