@@ -372,6 +372,8 @@
448 common process_mrelease sys_process_mrelease
449 common futex_waitv sys_futex_waitv
450 common set_mempolicy_home_node sys_set_mempolicy_home_node
+451 common mshare sys_mshare
+452 common mshare_unlink sys_mshare_unlink
#
# Due to a historical design error, certain syscalls are numbered differently
@@ -886,8 +886,13 @@ __SYSCALL(__NR_futex_waitv, sys_futex_waitv)
#define __NR_set_mempolicy_home_node 450
__SYSCALL(__NR_set_mempolicy_home_node, sys_set_mempolicy_home_node)
+#define __NR_mshare 451
+__SYSCALL(__NR_mshare, sys_mshare)
+#define __NR_mshare_unlink 452
+__SYSCALL(__NR_mshare_unlink, sys_mshare_unlink)
+
#undef __NR_syscalls
-#define __NR_syscalls 451
+#define __NR_syscalls 453
/*
* 32 bit systems traditionally used different
@@ -37,7 +37,7 @@ CFLAGS_init-mm.o += $(call cc-disable-warning, override-init)
CFLAGS_init-mm.o += $(call cc-disable-warning, initializer-overrides)
mmu-y := nommu.o
-mmu-$(CONFIG_MMU) := highmem.o memory.o mincore.o \
+mmu-$(CONFIG_MMU) := highmem.o memory.o mincore.o mshare.o \
mlock.o mmap.o mmu_gather.o mprotect.o mremap.o \
msync.o page_vma_mapped.o pagewalk.o \
pgtable-generic.o rmap.o vmalloc.o
new file mode 100644
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * mm/mshare.c
+ *
+ * Page table sharing code
+ *
+ *
+ * Copyright (C) 2021 Oracle Corp. All rights reserved.
+ * Authors: Khalid Aziz <khalid.aziz@oracle.com>
+ * Matthew Wilcox <willy@infradead.org>
+ */
+
+#include <linux/anon_inodes.h>
+#include <linux/fs.h>
+#include <linux/syscalls.h>
+
+static const struct file_operations mshare_fops = {
+};
+
+/*
+ * mshare syscall. Returns a file descriptor
+ */
+SYSCALL_DEFINE5(mshare, const char *, name, unsigned long, addr,
+ unsigned long, len, int, oflag, mode_t, mode)
+{
+ int fd;
+
+ /*
+ * Address range being shared must be aligned to pgdir
+ * boundary and its size must be a multiple of pgdir size
+ */
+ if ((addr | len) & (PGDIR_SIZE - 1))
+ return -EINVAL;
+
+ /*
+ * Allocate a file descriptor to return
+ *
+ * TODO: This code ignores the object name completely. Add
+ * support for that
+ */
+ fd = anon_inode_getfd("mshare", &mshare_fops, NULL, O_RDWR);
+
+ return fd;
+}
+
+/*
+ * mshare_unlink syscall. Close and remove the named mshare'd object
+ */
+SYSCALL_DEFINE1(mshare_unlink, const char *, name)
+{
+ int fd;
+
+ /*
+ * Delete the named object
+ *
+ * TODO: Mark mshare'd range for deletion
+ *
+ */
+ return 0;
+}