Skip to contentSkip to conversation

lapi/syscalls: Add syscall numbers for mlock2

PATCH New Xiao Yang 2 participants 16 messages Aug 21, 2018 – Sep 4, 2018 Library code

lore
Share & tools
lore

Xiao Yang

author
#0 lore raw

PATCH 1/4 lapi/syscalls: Add syscall numbers for mlock2

---
 include/lapi/syscalls/aarch64.in   | 1 +
 include/lapi/syscalls/arm.in       | 1 +
 include/lapi/syscalls/hppa.in      | 1 +
 include/lapi/syscalls/i386.in      | 1 +
 include/lapi/syscalls/ia64.in      | 1 +
 include/lapi/syscalls/powerpc.in   | 1 +
 include/lapi/syscalls/powerpc64.in | 1 +
 include/lapi/syscalls/s390.in      | 1 +
 include/lapi/syscalls/s390x.in     | 1 +
 include/lapi/syscalls/sh.in        | 1 +
 include/lapi/syscalls/sparc.in     | 1 +
 include/lapi/syscalls/sparc64.in   | 1 +
 include/lapi/syscalls/x86_64.in    | 1 +
 13 files changed, 13 insertions(+)
include/lapi/syscalls/aarch64.in +1 -0
index 2c8c589..9ac7f99 100644
@@ -256,5 +256,6 @@ sendmmsg 269
 kcmp 272
 getrandom 278
 memfd_create 279
+mlock2 284
 copy_file_range 285
 _sysctl 1078
include/lapi/syscalls/arm.in +1 -0
index c44adcd..774e1c7 100644
@@ -341,4 +341,5 @@ renameat2 (__NR_SYSCALL_BASE+382)
 getrandom (__NR_SYSCALL_BASE+384)
 memfd_create (__NR_SYSCALL_BASE+385)
 execveat (__NR_SYSCALL_BASE+387)
+mlock2 (__NR_SYSCALL_BASE+390)
 copy_file_range (__NR_SYSCALL_BASE+391)
include/lapi/syscalls/hppa.in +1 -0
index 92aee9f..3db9780 100644
@@ -17,4 +17,5 @@ splice 291
 tee 293
 vmsplice 294
 memfd_create 340
+mlock2 345
 copy_file_range 346
include/lapi/syscalls/i386.in +1 -0
index 19f0148..6a72b43 100644
@@ -341,4 +341,5 @@ renameat2 354
 getrandom 355
 memfd_create 356
 execveat 358
+mlock2 376
 copy_file_range 377
include/lapi/syscalls/ia64.in +1 -0
index a3abc99..2788193 100644
@@ -296,4 +296,5 @@ prlimit64 1325
 renameat2 1338
 getrandom 1339
 memfd_create 1340
+mlock2 1346
 copy_file_range 1347
include/lapi/syscalls/powerpc.in +1 -0
index 11ddca3..54c1941 100644
@@ -347,4 +347,5 @@ sched_getattr 356
 renameat2 357
 getrandom 359
 memfd_create 360
+mlock2 378
 copy_file_range 379
include/lapi/syscalls/powerpc64.in +1 -0
index 11ddca3..54c1941 100644
@@ -347,4 +347,5 @@ sched_getattr 356
 renameat2 357
 getrandom 359
 memfd_create 360
+mlock2 378
 copy_file_range 379
include/lapi/syscalls/s390.in +1 -0
index d95b282..47a04de 100644
@@ -332,4 +332,5 @@ renameat2 347
 getrandom 349
 memfd_create 350
 execveat 354
+mlock2 374
 copy_file_range 375
include/lapi/syscalls/s390x.in +1 -0
index 98c861f..83732ff 100644
@@ -331,4 +331,5 @@ sched_getattr 346
 renameat2 347
 getrandom 349
 memfd_create 350
+mlock2 374
 copy_file_range 375
include/lapi/syscalls/sh.in +1 -0
index c605b14..407be7a 100644
@@ -364,4 +364,5 @@ fanotify_mark 368
 prlimit64 369
 kcmp 378
 memfd_create 385
+mlock2 390
 copy_file_range 391
include/lapi/syscalls/sparc.in +1 -0
index 296d694..2b06a79 100644
@@ -336,4 +336,5 @@ kcmp 341
 renameat2 345
 getrandom 347
 memfd_create 348
+mlock2 356
 copy_file_range 357
include/lapi/syscalls/sparc64.in +1 -0
index 169347a..8c8a866 100644
@@ -312,4 +312,5 @@ kcmp 341
 renameat2 345
 getrandom 347
 memfd_create 348
+mlock2 356
 copy_file_range 357
include/lapi/syscalls/x86_64.in +1 -0
index 7907c31..dec9d3b 100644
@@ -308,4 +308,5 @@ renameat2 316
 getrandom 318
 memfd_create 319
 execveat 322
+mlock2 325
 copy_file_range 326
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 2/4 safe_macros: Add SAFE_MLOCK() and SAFE_MUNLOCK() macros

---
 include/tst_safe_macros.h |  8 ++++++++
 lib/safe_macros.c         | 28 ++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
include/tst_safe_macros.h +8 -0
index a754399..dc6c1f7 100644
@@ -482,6 +482,14 @@ int safe_mknod(const char *file, const int lineno, const char *pathname,
 #define SAFE_MKNOD(pathname, mode, dev) \
 	safe_mknod(__FILE__, __LINE__, (pathname), (mode), (dev))
 
+int safe_mlock(const char *file, const int lineno, const char *addr,
+	size_t len);
+#define SAFE_MLOCK(addr, len) safe_mlock(__FILE__, __LINE__, (addr), (len))
+
+int safe_munlock(const char *file, const int lineno, const char *addr,
+	size_t len);
+#define SAFE_MUNLOCK(addr, len) safe_munlock(__FILE__, __LINE__, (addr), (len))
+
 int safe_fanotify_init(const char *file, const int lineno,
 	unsigned int flags, unsigned int event_f_flags);
 #define SAFE_FANOTIFY_INIT(fan, mode)  \
lib/safe_macros.c +28 -0
index 03bd7aa..fa92a6f 100644
@@ -1006,3 +1006,31 @@ int safe_mknod(const char *file, const int lineno, const char *pathname,
 
 	return rval;
 }
+
+int safe_mlock(const char *file, const int lineno, const void *addr,
+	size_t len)
+{
+	int rval;
+
+	rval = mlock(addr, len);
+	if (rval == -1) {
+		tst_brkm(TBROK | TERRNO, NULL,
+			 "%s:%d: mlock() failed", file, lineno);
+	}
+
+	return rval;
+}
+
+int safe_munlock(const char *file, const int lineno, const void *addr,
+	size_t len)
+{
+	int rval;
+
+	rval = munlock(addr, len);
+	if (rval == -1) {
+		tst_brkm(TBROK | TERRNO, NULL,
+			 "%s:%d: munlock() failed", file, lineno);
+	}
+
+	return rval;
+}
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/4 safe_macros: Add SAFE_MLOCK() and SAFE_MUNLOCK() macros

----- Original Message -----

Quoted 5 lines
---
 include/tst_safe_macros.h |  8 ++++++++
 lib/safe_macros.c         | 28 ++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

ACK

author
#3 lore raw

PATCH 3/4 syscalls/mlock201: Add new testcase

In reply to Xiao Yang

Check the basic functionality of mlock2(2) since kernel v2.6.9.

---
 include/lapi/mlock2.h                       |  16 +++++
 runtest/ltplite                             |   2 +
 runtest/stress.part3                        |   2 +
 runtest/syscalls                            |   2 +
 testcases/kernel/syscalls/mlock2/.gitignore |   1 +
 testcases/kernel/syscalls/mlock2/Makefile   |   8 +++
 testcases/kernel/syscalls/mlock2/mlock201.c | 103 ++++++++++++++++++++++++++++
 7 files changed, 134 insertions(+)
 create mode 100644 include/lapi/mlock2.h
 create mode 100644 testcases/kernel/syscalls/mlock2/.gitignore
 create mode 100644 testcases/kernel/syscalls/mlock2/Makefile
 create mode 100644 testcases/kernel/syscalls/mlock2/mlock201.c
include/lapi/mlock2.h new file +16 -0
new file mode 100644
index 0000000..fa2b2de
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Author: Xiao Yang <[email protected]>
+ */
+
+#ifndef LAPI_MLOCK2_H__
+# define LAPI_MLOCK2_H__
+
+#include <linux/mman.h>
+
+#ifndef MLOCK_ONFAULT
+# define MLOCK_ONFAULT	0x01
+#endif
+
+#endif /* LAPI_MLOCK2_H__ */
runtest/ltplite +2 -0
index 9ca6c42..270c649 100644
@@ -443,6 +443,8 @@ mknod09 mknod09
 mlock01 mlock01
 mlock02 mlock02
 
+mlock201 mlock201
+
 qmm01 mmap001 -m 1
 mmap01 mmap01
 mmap02 mmap02
runtest/stress.part3 +2 -0
index ec18dcf..6850572 100644
@@ -369,6 +369,8 @@ mknod09 mknod09
 mlock01 mlock01
 mlock02 mlock02
 
+mlock201 mlock201
+
 qmm01 mmap001 -m 1
 mmap01 mmap01
 mmap02 mmap02
runtest/syscalls +2 -0
index 3161d91..5d84d48 100644
@@ -633,6 +633,8 @@ mlock02 mlock02
 mlock03 mlock03 -i 20
 mlock04 mlock04
 
+mlock201 mlock201
+
 qmm01 mmap001 -m 1
 mmap01 mmap01
 mmap02 mmap02
testcases/kernel/syscalls/mlock2/.gitignore new file +1 -0
new file mode 100644
index 0000000..431eff8
@@ -0,0 +1 @@
+/mlock201
testcases/kernel/syscalls/mlock2/Makefile new file +8 -0
new file mode 100644
index 0000000..427df06
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+# Author: Xiao Yang <[email protected]>
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/mlock2/mlock201.c new file +103 -0

103 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#4 lore raw

PATCH 3/4 syscalls/mlock201: Add new testcase

----- Original Message -----

Quoted 4 lines

Check the basic functionality of mlock2(2) since kernel v2.6.9.

Quoted 8 lines

+ * Description:
+ * Check the basic functionality of the mlock2(2) since kernel v2.6.9:
+ * 1) Use mlock2(2) without MLOCK_ONFAULT to lock memory in the specified
+ * range that is multiples of page size or not, and the VmLck from
+ * /proc/PID/status shows correct size of memory that is locked by PID.
+ * 2) Use mlock2(2) with MLOCK_ONFAULT to lock memory in the specified
+ * range that is multiples of page size or not, and the VmLck from
+ * /proc/PID/status show correct size of memory that is locked by PID.

Can we also check if MLOCK_ONFAULT doesn't make non-present pages present, but it still locks present pages? (mincore(2) or /proc/pid/pagemap)

Regards,
Jan

#5 lore raw

PATCH 3/4 syscalls/mlock201: Add new testcase

----- Original Message -----

Quoted 3 lines

----- Original Message -----

Quoted 1 line

Check the basic functionality of mlock2(2) since kernel v2.6.9.

Missed this one:
mlock2() is available since Linux 4.4.

Quoted 21 lines
Quoted 11 lines

+ * Description:
+ * Check the basic functionality of the mlock2(2) since kernel v2.6.9:
+ * 1) Use mlock2(2) without MLOCK_ONFAULT to lock memory in the specified
+ * range that is multiples of page size or not, and the VmLck from
+ * /proc/PID/status shows correct size of memory that is locked by PID.
+ * 2) Use mlock2(2) with MLOCK_ONFAULT to lock memory in the specified
+ * range that is multiples of page size or not, and the VmLck from
+ * /proc/PID/status show correct size of memory that is locked by PID.

Can we also check if MLOCK_ONFAULT doesn't make non-present pages present, but it still locks present pages? (mincore(2) or /proc/pid/pagemap)

Regards,
Jan

--
Mailing list info: https://lists.linux.it/listinfo/ltp

author
#6 lore raw

PATCH 3/4 syscalls/mlock201: Add new testcase

Quoted 5 lines · Jan Stancek

----- Original Message -----

Quoted 2 lines

----- Original Message -----

Quoted 1 line

Check the basic functionality of mlock2(2) since kernel v2.6.9.

Missed this one:
mlock2() is available since Linux 4.4.

Hi Jan,

Thanks for your review.

It seems that mlock2() has been backported by some distros(e.g. RHEL7.6), so i use tst_syscall()
instead of .min_kver to check if mlock2() is supported.

From mlock2() manpage:
Before Linux 2.6.8, a process must be privileged (CAP_IPC_LOCK) in order to lock memory and the
RLIMIT_MEMLOCK soft resource limit defines a limit on how much memory the process may lock.
Since Linux 2.6.9, no limits are placed on the amount of memory that a privileged process can lock
and the RLIMIT_MEMLOCK soft resource limit instead defines a limit on how much memory an unprivileged\
process may lock.

I just check the behavior of mlock2() since Linux 2.6.9.

Quoted 11 lines
Quoted 11 lines
Quoted 9 lines

+ * Description:
+ * Check the basic functionality of the mlock2(2) since kernel v2.6.9:
+ * 1) Use mlock2(2) without MLOCK_ONFAULT to lock memory in the specified
+ * range that is multiples of page size or not, and the VmLck from
+ * /proc/PID/status shows correct size of memory that is locked by PID.
+ * 2) Use mlock2(2) with MLOCK_ONFAULT to lock memory in the specified
+ * range that is multiples of page size or not, and the VmLck from
+ * /proc/PID/status show correct size of memory that is locked by PID.

Can we also check if MLOCK_ONFAULT doesn't make non-present pages present, but it still locks present pages? (mincore(2) or /proc/pid/pagemap)

I will try to check this point as you suggested.

Thanks,
Xiao Yang

Quoted 8 lines
Quoted 6 lines

Regards,
Jan

--
Mailing list info: https://lists.linux.it/listinfo/ltp

author
#7 lore raw

PATCH v2 3/4 syscalls/mlock201: Add new testcase

In reply to Jan Stancek

1) Add SAFE_MINCORE() macro
2) Check the basic functionality of mlock2(2).

Note:
1) We use tst_syscall() to check if mlock2() is supported.
2) since kernel v2.6.9, the limits and permissions of mlock2() changed, so we just check mlock2() since the version.

---
 include/lapi/mlock2.h                       |  16 ++++
 include/tst_safe_macros.h                   |   5 +
 lib/safe_macros.c                           |  14 +++
 runtest/ltplite                             |   2 +
 runtest/stress.part3                        |   2 +
 runtest/syscalls                            |   2 +
 testcases/kernel/syscalls/mlock2/.gitignore |   1 +
 testcases/kernel/syscalls/mlock2/Makefile   |   8 ++
 testcases/kernel/syscalls/mlock2/mlock201.c | 144 ++++++++++++++++++++++++++++
 9 files changed, 194 insertions(+)
 create mode 100644 include/lapi/mlock2.h
 create mode 100644 testcases/kernel/syscalls/mlock2/.gitignore
 create mode 100644 testcases/kernel/syscalls/mlock2/Makefile
 create mode 100644 testcases/kernel/syscalls/mlock2/mlock201.c
include/lapi/mlock2.h new file +16 -0
new file mode 100644
index 0000000..fa2b2de
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Author: Xiao Yang <[email protected]>
+ */
+
+#ifndef LAPI_MLOCK2_H__
+# define LAPI_MLOCK2_H__
+
+#include <linux/mman.h>
+
+#ifndef MLOCK_ONFAULT
+# define MLOCK_ONFAULT	0x01
+#endif
+
+#endif /* LAPI_MLOCK2_H__ */
include/tst_safe_macros.h +5 -0
index dc6c1f7..03657a4 100644
@@ -490,6 +490,11 @@ int safe_munlock(const char *file, const int lineno, const char *addr,
 	size_t len);
 #define SAFE_MUNLOCK(addr, len) safe_munlock(__FILE__, __LINE__, (addr), (len))
 
+int safe_mincore(const char *file, const int lineno, void *start,
+	size_t length, unsigned char *vec);
+#define SAFE_MINCORE(start, length, vec) \
+	safe_mincore(__FILE__, __LINE__, (start), (length), (vec))
+
 int safe_fanotify_init(const char *file, const int lineno,
 	unsigned int flags, unsigned int event_f_flags);
 #define SAFE_FANOTIFY_INIT(fan, mode)  \
lib/safe_macros.c +14 -0
index fa92a6f..5cc80d0 100644
@@ -1034,3 +1034,17 @@ int safe_munlock(const char *file, const int lineno, const void *addr,
 
 	return rval;
 }
+
+int safe_mincore(const char *file, const int lineno, void *start,
+	size_t length, unsigned char *vec)
+{
+	int rval;
+
+	rval = mincore(start, length, vec);
+	if (rval == -1) {
+		tst_brkm(TBROK | TERRNO, NULL,
+			 "%s:%d: mincore() failed", file, lineno);
+	}
+
+	return rval;
+}
runtest/ltplite +2 -0
index 9ca6c42..270c649 100644
@@ -443,6 +443,8 @@ mknod09 mknod09
 mlock01 mlock01
 mlock02 mlock02
 
+mlock201 mlock201
+
 qmm01 mmap001 -m 1
 mmap01 mmap01
 mmap02 mmap02
runtest/stress.part3 +2 -0
index ec18dcf..6850572 100644
@@ -369,6 +369,8 @@ mknod09 mknod09
 mlock01 mlock01
 mlock02 mlock02
 
+mlock201 mlock201
+
 qmm01 mmap001 -m 1
 mmap01 mmap01
 mmap02 mmap02
runtest/syscalls +2 -0
index 3161d91..5d84d48 100644
@@ -633,6 +633,8 @@ mlock02 mlock02
 mlock03 mlock03 -i 20
 mlock04 mlock04
 
+mlock201 mlock201
+
 qmm01 mmap001 -m 1
 mmap01 mmap01
 mmap02 mmap02
testcases/kernel/syscalls/mlock2/.gitignore new file +1 -0
new file mode 100644
index 0000000..431eff8
@@ -0,0 +1 @@
+/mlock201
testcases/kernel/syscalls/mlock2/Makefile new file +8 -0
new file mode 100644
index 0000000..427df06
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+# Author: Xiao Yang <[email protected]>
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/mlock2/mlock201.c new file +144 -0

144 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#8 lore raw

PATCH v2 3/4 syscalls/mlock201: Add new testcase

----- Original Message -----

Quoted 9 lines

1) Add SAFE_MINCORE() macro
2) Check the basic functionality of mlock2(2).

Note:
1) We use tst_syscall() to check if mlock2() is supported.
2) since kernel v2.6.9, the limits and permissions of mlock2() changed, so we just check mlock2() since the version.

Looks good to me, some nits below (no need to re-post)

Quoted 13 lines
testcases/kernel/syscalls/mlock2/mlock201.c new file +13 -0
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <linux/mman.h>
+
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/mlock2.h"
+
+#define PAGES	8
+#define HPAGES	(PAGES / 2)

testcases/kernel/syscalls/mlock2/mlock201.c line 40

Quoted 10 lines
testcases/kernel/syscalls/mlock2/mlock201.c new file +10 -0
+
+static size_t pgsz;
+static unsigned char *vec;
+
+static struct tcase {
+	size_t pop_pgs;
+	size_t lock_pgs;
+	size_t offset;
+	size_t exp_vmlcks;
+	size_t exp_pgs;

Some of these could be more descriptive or have comments.

<snip>

testcases/kernel/syscalls/mlock2/mlock201.c line 128

Quoted 4 lines
testcases/kernel/syscalls/mlock2/mlock201.c new file +4 -0
+static void setup(void)
+{
+	pgsz = getpagesize();
+	vec = SAFE_MALLOC((PAGES * pgsz + pgsz - 1) / pgsz);

This value is known at compile time, so malloc isn't needed.

Quoted 5 lines
testcases/kernel/syscalls/mlock2/mlock201.c new file +5 -0
+}
+
+static void cleanup(void)
+{
+	if (vec)

testcases/kernel/syscalls/mlock2/mlock201.c line 143

Quoted 10 lines
testcases/kernel/syscalls/mlock2/mlock201.c new file +10 -0
+		free(vec);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_mlock2,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.min_kver = "2.6.9",

Ok, "syscall can be backported to older kernels" is valid argument.

Thanks,
Jan

author
#9 lore raw

PATCH v2 4/4 syscalls/mlock202: Add new testcase

In reply to Xiao Yang

Check various errnos for mlock2(2) since kernel v2.6.9.

Note:
1) We use tst_syscall() to check if mlock2() is supported.
2) since kernel v2.6.9, the limits and permissions of mlock2() changed, so we just check mlock2() since the version.

---
 runtest/ltplite                             |   1 +
 runtest/stress.part3                        |   1 +
 runtest/syscalls                            |   1 +
 testcases/kernel/syscalls/mlock2/.gitignore |   1 +
 testcases/kernel/syscalls/mlock2/mlock202.c | 113 ++++++++++++++++++++++++++++
 5 files changed, 117 insertions(+)
 create mode 100644 testcases/kernel/syscalls/mlock2/mlock202.c
runtest/ltplite +1 -0
index 270c649..7ebe632 100644
@@ -444,6 +444,7 @@ mlock01 mlock01
 mlock02 mlock02
 
 mlock201 mlock201
+mlock202 mlock202
 
 qmm01 mmap001 -m 1
 mmap01 mmap01
runtest/stress.part3 +1 -0
index 6850572..0804172 100644
@@ -370,6 +370,7 @@ mlock01 mlock01
 mlock02 mlock02
 
 mlock201 mlock201
+mlock202 mlock202
 
 qmm01 mmap001 -m 1
 mmap01 mmap01
runtest/syscalls +1 -0
index 5d84d48..2615254 100644
@@ -634,6 +634,7 @@ mlock03 mlock03 -i 20
 mlock04 mlock04
 
 mlock201 mlock201
+mlock202 mlock202
 
 qmm01 mmap001 -m 1
 mmap01 mmap01
testcases/kernel/syscalls/mlock2/.gitignore +1 -0
index 431eff8..8daf0f9 100644
@@ -1 +1,2 @@
 /mlock201
+/mlock202
testcases/kernel/syscalls/mlock2/mlock202.c new file +113 -0

113 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#10 lore raw

PATCH v2 4/4 syscalls/mlock202: Add new testcase

----- Original Message -----

Quoted 8 lines

Check various errnos for mlock2(2) since kernel v2.6.9.

Note:
1) We use tst_syscall() to check if mlock2() is supported.
2) since kernel v2.6.9, the limits and permissions of mlock2() changed, so we just check mlock2() since the version.

Ack

#11 lore raw

PATCH v2 4/4 syscalls/mlock202: Add new testcase

----- Original Message -----

Quoted 5 lines

----- Original Message -----

Quoted 2 lines

Check various errnos for mlock2(2) since kernel v2.6.9.

Quoted 8 lines
Quoted 6 lines

Note:
1) We use tst_syscall() to check if mlock2() is supported.
2) since kernel v2.6.9, the limits and permissions of mlock2() changed, so we just check mlock2() since the version.

Ack

Series pushed with few tweaks to 3/4:
- couple variables renamed
- added comments
- vec allocated statically, dropped cleanup()

Thanks,
Jan

author
#12 lore raw

PATCH 4/4 syscalls/mlock202: Add new testcase

In reply to Xiao Yang

Check various errnos for mlock2(2) since kernel v2.6.9.

---
 runtest/ltplite                             |   1 +
 runtest/stress.part3                        |   1 +
 runtest/syscalls                            |   1 +
 testcases/kernel/syscalls/mlock2/.gitignore |   1 +
 testcases/kernel/syscalls/mlock2/mlock202.c | 110 ++++++++++++++++++++++++++++
 5 files changed, 114 insertions(+)
 create mode 100644 testcases/kernel/syscalls/mlock2/mlock202.c
runtest/ltplite +1 -0
index 270c649..7ebe632 100644
@@ -444,6 +444,7 @@ mlock01 mlock01
 mlock02 mlock02
 
 mlock201 mlock201
+mlock202 mlock202
 
 qmm01 mmap001 -m 1
 mmap01 mmap01
runtest/stress.part3 +1 -0
index 6850572..0804172 100644
@@ -370,6 +370,7 @@ mlock01 mlock01
 mlock02 mlock02
 
 mlock201 mlock201
+mlock202 mlock202
 
 qmm01 mmap001 -m 1
 mmap01 mmap01
runtest/syscalls +1 -0
index 5d84d48..2615254 100644
@@ -634,6 +634,7 @@ mlock03 mlock03 -i 20
 mlock04 mlock04
 
 mlock201 mlock201
+mlock202 mlock202
 
 qmm01 mmap001 -m 1
 mmap01 mmap01
testcases/kernel/syscalls/mlock2/.gitignore +1 -0
index 431eff8..8daf0f9 100644
@@ -1 +1,2 @@
 /mlock201
+/mlock202
testcases/kernel/syscalls/mlock2/mlock202.c new file +110 -0

110 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#13 lore raw

PATCH 4/4 syscalls/mlock202: Add new testcase

----- Original Message -----

Quoted 1 line

Check various errnos for mlock2(2) since kernel v2.6.9.

mlock2() is available since Linux 4.4.

testcases/kernel/syscalls/mlock2/mlock202.c line 39

Quoted 6 lines
testcases/kernel/syscalls/mlock2/mlock202.c new file +6 -0
+static struct tcase {
+	char **taddr;
+	int flag;
+	unsigned long *max_size;
+	/* 1: nobody expected  0: root expected */
+	int exp_user;

I'd drop the "expected" prefix here, this isn't something syscall provides as "output".

Quoted 8 lines
testcases/kernel/syscalls/mlock2/mlock202.c new file +8 -0
+	int exp_err;
+} tcases[] = {
+	{&addr, -1, NULL, 0, EINVAL},
+	{&addr, 0, &max_sz1, 1, ENOMEM},
+	{&addr, 0, &max_sz2, 1, EPERM},
+	{&unmapped_addr, 0, NULL, 0, ENOMEM},
+};
+

..

testcases/kernel/syscalls/mlock2/mlock202.c line 92

Quoted 10 lines
testcases/kernel/syscalls/mlock2/mlock202.c new file +10 -0
+static void setup(void)
+{
+	pgsz = getpagesize();
+	nobody = SAFE_GETPWNAM("nobody");
+
+	addr = SAFE_MMAP(NULL, pgsz, PROT_WRITE,
+			 MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+	unmapped_addr = SAFE_MMAP(NULL, pgsz, PROT_READ,
+				  MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+	SAFE_MUNMAP(unmapped_addr, pgsz);

I suggest larger map here (couple M) and pick address in middle. Single page can easily be mapped by glibc for some buffer.

testcases/kernel/syscalls/mlock2/mlock202.c line 96

Quoted 4 lines
testcases/kernel/syscalls/mlock2/mlock202.c new file +4 -0
+
+	max_sz1 = pgsz - 1;
+}
+

Regards,
Jan

author
#14 lore raw

PATCH 4/4 syscalls/mlock202: Add new testcase

Quoted 11 lines · Jan Stancek

----- Original Message -----

Quoted 1 line

Check various errnos for mlock2(2) since kernel v2.6.9.

mlock2() is available since Linux 4.4.

testcases/kernel/syscalls/mlock2/mlock202.c line 39

Quoted 6 lines
testcases/kernel/syscalls/mlock2/mlock202.c new file +6 -0
+static struct tcase {
+	char **taddr;
+	int flag;
+	unsigned long *max_size;
+	/* 1: nobody expected  0: root expected */
+	int exp_user;

I'd drop the "expected" prefix here, this isn't something syscall provides as "output".

Hi Jan,

OK, I will drop it.

Quoted 9 lines
Quoted 8 lines
testcases/kernel/syscalls/mlock2/mlock202.c new file +8 -0
+	int exp_err;
+} tcases[] = {
+	{&addr, -1, NULL, 0, EINVAL},
+	{&addr, 0,&max_sz1, 1, ENOMEM},
+	{&addr, 0,&max_sz2, 1, EPERM},
+	{&unmapped_addr, 0, NULL, 0, ENOMEM},
+};
+

..

Quoted 12 lines

testcases/kernel/syscalls/mlock2/mlock202.c line 92

Quoted 10 lines
testcases/kernel/syscalls/mlock2/mlock202.c new file +10 -0
+static void setup(void)
+{
+	pgsz = getpagesize();
+	nobody = SAFE_GETPWNAM("nobody");
+
+	addr = SAFE_MMAP(NULL, pgsz, PROT_WRITE,
+			 MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+	unmapped_addr = SAFE_MMAP(NULL, pgsz, PROT_READ,
+				  MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+	SAFE_MUNMAP(unmapped_addr, pgsz);

I suggest larger map here (couple M) and pick address in middle. Single page can easily be mapped by glibc for some buffer.

OK, i will map a larger one and pick address in middle.

Thanks,
Xiao Yang

Quoted 9 lines

testcases/kernel/syscalls/mlock2/mlock202.c line 96

Quoted 4 lines
testcases/kernel/syscalls/mlock2/mlock202.c new file +4 -0
+
+	max_sz1 = pgsz - 1;
+}
+

Regards,
Jan

#15 lore raw

PATCH 1/4 lapi/syscalls: Add syscall numbers for mlock2

In reply to Xiao Yang

----- Original Message -----

Quoted 16 lines
---
 include/lapi/syscalls/aarch64.in   | 1 +
 include/lapi/syscalls/arm.in       | 1 +
 include/lapi/syscalls/hppa.in      | 1 +
 include/lapi/syscalls/i386.in      | 1 +
 include/lapi/syscalls/ia64.in      | 1 +
 include/lapi/syscalls/powerpc.in   | 1 +
 include/lapi/syscalls/powerpc64.in | 1 +
 include/lapi/syscalls/s390.in      | 1 +
 include/lapi/syscalls/s390x.in     | 1 +
 include/lapi/syscalls/sh.in        | 1 +
 include/lapi/syscalls/sparc.in     | 1 +
 include/lapi/syscalls/sparc64.in   | 1 +
 include/lapi/syscalls/x86_64.in    | 1 +
 13 files changed, 13 insertions(+)

ACK