[PATCH] Added empty sys_ememz

York Jasper Niebuhr posted 1 patch 2 years, 1 month ago
arch/x86/entry/syscalls/syscall_32.tbl |  1 +
arch/x86/entry/syscalls/syscall_64.tbl |  1 +
include/linux/syscalls.h               |  1 +
include/uapi/asm-generic/unistd.h      |  5 ++++-
kernel/sys_ni.c                        |  3 +++
mm/Kconfig                             |  7 +++++++
mm/ememz.c                             | 18 ++++++++++++++++++
7 files changed, 35 insertions(+), 1 deletion(-)
create mode 100644 mm/ememz.c
[PATCH] Added empty sys_ememz
Posted by York Jasper Niebuhr 2 years, 1 month ago
---
 arch/x86/entry/syscalls/syscall_32.tbl |  1 +
 arch/x86/entry/syscalls/syscall_64.tbl |  1 +
 include/linux/syscalls.h               |  1 +
 include/uapi/asm-generic/unistd.h      |  5 ++++-
 kernel/sys_ni.c                        |  3 +++
 mm/Kconfig                             |  7 +++++++
 mm/ememz.c                             | 18 ++++++++++++++++++
 7 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 mm/ememz.c

diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl
index 2d0b1bd866ea..7803b2303da4 100644
--- a/arch/x86/entry/syscalls/syscall_32.tbl
+++ b/arch/x86/entry/syscalls/syscall_32.tbl
@@ -457,3 +457,4 @@
 450	i386	set_mempolicy_home_node		sys_set_mempolicy_home_node
 451	i386	cachestat		sys_cachestat
 452	i386	fchmodat2		sys_fchmodat2
+453	i386	ememz			sys_ememz
diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl
index 1d6eee30eceb..39530de435e1 100644
--- a/arch/x86/entry/syscalls/syscall_64.tbl
+++ b/arch/x86/entry/syscalls/syscall_64.tbl
@@ -375,6 +375,7 @@
 451	common	cachestat		sys_cachestat
 452	common	fchmodat2		sys_fchmodat2
 453	64	map_shadow_stack	sys_map_shadow_stack
+454	common	ememz			sys_ememz
 
 #
 # Due to a historical design error, certain syscalls are numbered differently
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 22bc6bc147f8..4127689798e2 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -940,6 +940,7 @@ asmlinkage long sys_cachestat(unsigned int fd,
 		struct cachestat_range __user *cstat_range,
 		struct cachestat __user *cstat, unsigned int flags);
 asmlinkage long sys_map_shadow_stack(unsigned long addr, unsigned long size, unsigned int flags);
+asmlinkage long sys_ememz(int flags);
 
 /*
  * Architecture-specific system calls
diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h
index abe087c53b4b..63ec7611af63 100644
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
@@ -823,8 +823,11 @@ __SYSCALL(__NR_cachestat, sys_cachestat)
 #define __NR_fchmodat2 452
 __SYSCALL(__NR_fchmodat2, sys_fchmodat2)
 
+#define __NR_ememz 453
+__SYSCALL(__NR_ememz, sys_ememz)
+
 #undef __NR_syscalls
-#define __NR_syscalls 453
+#define __NR_syscalls 454
 
 /*
  * 32 bit systems traditionally used different
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
index e137c1385c56..108ff4c6113c 100644
--- a/kernel/sys_ni.c
+++ b/kernel/sys_ni.c
@@ -253,6 +253,9 @@ COND_SYSCALL(pkey_free);
 /* memfd_secret */
 COND_SYSCALL(memfd_secret);
 
+/* ememz */
+COND_SYSCALL(ememz);
+
 /*
  * Architecture specific weak syscall entries.
  */
diff --git a/mm/Kconfig b/mm/Kconfig
index 264a2df5ecf5..dd4d505cf52e 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -1260,4 +1260,11 @@ config LOCK_MM_AND_FIND_VMA
 
 source "mm/damon/Kconfig"
 
+config EMEMZ_SYSCALL
+        bool "Ememz syscall" if EXPERT
+        default y
+        help
+          sys_ememz is a system call to flag a process' memory to be filled
+          with zeros on exit.
+
 endmenu
diff --git a/mm/ememz.c b/mm/ememz.c
new file mode 100644
index 000000000000..d7765375122a
--- /dev/null
+++ b/mm/ememz.c
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/syscalls.h>
+
+#ifdef CONFIG_EMEMZ_SYSCALL
+/*
+ * Set task_struct flag to fill any memory associated with process on
+ * exit to zero.
+ */
+SYSCALL_DEFINE1(ememz, int, flags)
+{
+	if (flags & ~(0))
+		return -EINVAL;
+
+	// Set flag atomically
+	return 0;
+}
+#endif
-- 
2.34.1

Hi,
I am looking for a more fine grained alternative with less system
overhead to CONFIG_INIT_ON_FREE_DEFAULT_ON. My idea was to add a system
call (ememz) to set a flag in the task_struct that causes initialization
of all a process' pages on exit. Are there already any other
alternatives I should consider and is this the proper way to go on with
it? Any suggestions are welcome.

Signed-off-by: York Jasper Niebuhr <yjnworkstation@gmail.com>
Re: [PATCH] Added empty sys_ememz
Posted by kernel test robot 2 years, 1 month ago
Hi York,

kernel test robot noticed the following build warnings:

[auto build test WARNING on akpm-mm/mm-everything]
[also build test WARNING on tip/x86/asm linus/master v6.6-rc7]
[cannot apply to arnd-asm-generic/master next-20231027]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/York-Jasper-Niebuhr/Added-empty-sys_ememz/20231029-044215
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20231028204046.11258-1-yjnworkstation%40gmail.com
patch subject: [PATCH] Added empty sys_ememz
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20231029/202310291059.qzvihDY2-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231029/202310291059.qzvihDY2-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202310291059.qzvihDY2-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> <stdin>:1573:2: warning: #warning syscall ememz not implemented [-Wcpp]
--
>> <stdin>:1573:2: warning: #warning syscall ememz not implemented [-Wcpp]
--
   scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr]
   scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr]
   scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
>> <stdin>:1573:2: warning: #warning syscall ememz not implemented [-Wcpp]

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki