* [LTP] [PATCH 1/4] syscalls/mlock01: Convert into new api
@ 2023-04-04 10:36 Yang Xu
2023-04-04 10:36 ` [LTP] [PATCH 2/4] syscalls/mlock02: " Yang Xu
` (3 more replies)
0 siblings, 4 replies; 14+ messages in thread
From: Yang Xu @ 2023-04-04 10:36 UTC (permalink / raw)
To: ltp
Also use safe macros and TST_EXP_PASS macro.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/mlock/mlock01.c | 159 +++++-----------------
1 file changed, 33 insertions(+), 126 deletions(-)
diff --git a/testcases/kernel/syscalls/mlock/mlock01.c b/testcases/kernel/syscalls/mlock/mlock01.c
index 2338d4d56..0b079f8be 100644
--- a/testcases/kernel/syscalls/mlock/mlock01.c
+++ b/testcases/kernel/syscalls/mlock/mlock01.c
@@ -1,145 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
- *
- * Copyright (c) International Business Machines Corp., 2002
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * NAME
- * mlock01.c
- *
- * DESCRIPTION
- * Test to see that mlock works
- *$
- * ALGORITHM
- * test 1:
- * Call mlock with various valid addresses and lengths. No
- * error should be returned
- *
- * USAGE: <for command-line>
- * -c n Run n copies concurrently
- * -e Turn on errno logging
- * -f Turn off functional testing
- * -h Show this help screen
- * -i n Execute test n times
- * -I x Execute test for x seconds
- * -p Pause for SIGUSR1 before starting
- * -P x Pause for x seconds between iterations
- * -t Turn on syscall timing
+ * Copyright (c) International Business Machines Corp., 2002
*
* HISTORY
* 06/2002 Written by Paul Larson
- *
- * RESTRICTIONS
- * None
*/
-#include <errno.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include "test.h"
-void setup();
-void setup1(int);
-void cleanup();
+/*\
+ * [Description]
+ *
+ * Test mlock with various valid addresses and lengths.
+ */
-char *TCID = "mlock01";
-int TST_TOTAL = 4;
+#include <stdlib.h>
+#include "tst_test.h"
-void *addr1;
+static void *addr;
-struct test_case_t {
- void **addr;
+static struct tcase {
+ char *msg;
int len;
- void (*setupfunc) ();
-} TC[] = {
- /* mlock should return ENOMEM when some or all of the address
- * range pointed to by addr and len are not valid mapped pages
- * in the address space of the process
- */
- {
- &addr1, 1, setup1}, {
- &addr1, 1024, setup1}, {
- &addr1, 1024 * 1024, setup1}, {
- &addr1, 1024 * 1024 * 10, setup1}
+} tcases[] = {
+ {"mlock 1 byte", 1},
+ {"mlock 1024 bytes", 1024},
+ {"mlock 1024 * 1024 bytes", 1024 * 1024},
+ {"mlock 1024 * 1024 * 10 bytes", 1024 * 1024 * 10}
};
-#if !defined(UCLINUX)
-
-int main(int ac, char **av)
-{
- int lc, i;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup();
-
- /*
- * FIXME (garrcoop): this should really test out whether or not the
- * process's mappable address space is indeed accessible by the
- * current user, instead of needing to be run by root all the time.
- */
- tst_require_root();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
-
- tst_count = 0;
-
- for (i = 0; i < TST_TOTAL; i++) {
-
- if (TC[i].setupfunc != NULL)
- TC[i].setupfunc(TC[i].len);
-
- TEST(mlock(*(TC[i].addr), TC[i].len));
-
- /* I'm confused -- given the description above this
- * should fail as designed, but this application
- * */
- if (TEST_RETURN == -1)
- tst_resm(TFAIL | TTERRNO, "mlock failed");
- else
- tst_resm(TPASS, "mlock passed");
- }
- }
-
- cleanup();
-
- tst_exit();
-}
-
-#else
-
-int main(void)
+static void do_mlock(unsigned int i)
{
- tst_brkm(TCONF, NULL, "test is not available on uClinux");
-}
-
-#endif /* if !defined(UCLINUX) */
+ struct tcase *tc = &tcases[i];
-void setup(void)
-{
- TEST_PAUSE;
+ tst_res(TINFO, "%s", tc->msg);
+ addr = SAFE_MALLOC(tc->len);
+ TST_EXP_PASS(mlock(addr, tc->len), "mlock(%p, %d)", addr, tc->len);
+ free(addr);
+ addr = NULL;
}
-void setup1(int len)
+static void cleanup(void)
{
- addr1 = malloc(len);
- if (addr1 == NULL)
- tst_brkm(TFAIL, cleanup, "malloc failed");
+ if (addr)
+ free(addr);
}
-void cleanup(void)
-{
-}
+static struct tst_test test = {
+ .needs_root = 1,
+ .test = do_mlock,
+ .tcnt = ARRAY_SIZE(tcases),
+ .cleanup = cleanup,
+};
--
2.39.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [LTP] [PATCH 2/4] syscalls/mlock02: Convert into new api
2023-04-04 10:36 [LTP] [PATCH 1/4] syscalls/mlock01: Convert into new api Yang Xu
@ 2023-04-04 10:36 ` Yang Xu
2023-04-19 11:22 ` Avinesh Kumar
2023-04-04 10:36 ` [LTP] [PATCH 3/4] syscalls/mlock03: " Yang Xu
` (2 subsequent siblings)
3 siblings, 1 reply; 14+ messages in thread
From: Yang Xu @ 2023-04-04 10:36 UTC (permalink / raw)
To: ltp
Also use safe_macro and TST_EXP_FAIL macro. And remove uclinux code.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/mlock/mlock02.c | 190 ++++++----------------
1 file changed, 51 insertions(+), 139 deletions(-)
diff --git a/testcases/kernel/syscalls/mlock/mlock02.c b/testcases/kernel/syscalls/mlock/mlock02.c
index 50ee31d1c..921ddeeae 100644
--- a/testcases/kernel/syscalls/mlock/mlock02.c
+++ b/testcases/kernel/syscalls/mlock/mlock02.c
@@ -1,109 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * Copyright (c) International Business Machines Corp., 2002
- * 06/2002 Written by Paul Larson
+ * Copyright (c) International Business Machines Corp., 2002
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * 06/2002 Written by Paul Larson
*/
-/*
- * Test Description:
- * Verify that,
- * 1. mlock() fails with -1 return value and sets errno to ENOMEM,
- * if some of the specified address range does not correspond to
- * mapped pages in the address space of the process.
- * 2. mlock() fails with -1 return value and sets errno to ENOMEM,
- * if (Linux 2.6.9 and later) the caller had a non-zero RLIMIT_MEMLOCK
- * soft resource limit, but tried to lock more memory than the limit
- * permitted. This limit is not enforced if the process is privileged
- * (CAP_IPC_LOCK).
- * 3. mlock() fails with -1 return value and sets errno to EPERM,
- * if (Linux 2.6.9 and later) the caller was not privileged (CAP_IPC_LOCK)
- * and its RLIMIT_MEMLOCK soft resource limit was 0.
+/*\
+ * [Description]
+ *
+ * Test for ENOMEM, EPERM errors.
+ *
+ * 1) mlock(2) fails with ENOMEM if some of the specified address range
+ * does not correspond to mapped pages in the address space of
+ * the process.
+ *
+ * 2) mlock(2) fails with ENOMEM if the caller had a non-zero RLIMIT_MEMLOCK
+ * soft resource limit, but tried to lock more memory than the limit
+ * permitted. This limit is not enforced if the process is
+ * privileged (CAP_IPC_LOCK).
+ *
+ * 3) mlock(2) fails with EPERM if the caller was not privileged (CAP_IPC_LOCK)
+ * and its RLIMIT_MEMLOCK soft resource limit was 0.
*/
-#include <errno.h>
#include <unistd.h>
#include <sys/mman.h>
+#include <sys/types.h>
#include <pwd.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-char *TCID = "mlock02";
-
-#if !defined(UCLINUX)
-
-static void setup(void);
-static void cleanup(void);
-static void test_enomem1(void);
-static void test_enomem2(void);
-static void test_eperm(void);
-static void mlock_verify(const void *, const size_t, const int);
+#include "tst_test.h"
static size_t len;
static struct rlimit original;
static struct passwd *ltpuser;
-static void (*test_func[])(void) = { test_enomem1, test_enomem2, test_eperm };
-
-int TST_TOTAL = ARRAY_SIZE(test_func);
-
-int main(int ac, char **av)
-{
- int lc, i;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- tst_count = 0;
- for (i = 0; i < TST_TOTAL; i++)
- (*test_func[i])();
- }
-
- cleanup();
- tst_exit();
-}
-
-static void setup(void)
-{
- tst_require_root();
-
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
- TEST_PAUSE;
-
- ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
-
- len = getpagesize();
-
- SAFE_GETRLIMIT(cleanup, RLIMIT_MEMLOCK, &original);
-}
-
static void test_enomem1(void)
{
void *addr;
- struct rlimit rl;
- addr = SAFE_MMAP(cleanup, NULL, len, PROT_READ,
+ addr = SAFE_MMAP(NULL, len, PROT_READ,
MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
-
- SAFE_MUNMAP(cleanup, addr, len);
-
- mlock_verify(addr, len, ENOMEM);
+ SAFE_MUNMAP(addr, len);
+ TST_EXP_FAIL(mlock(addr, len), ENOMEM, "mlock(%p, %lu)", addr, len);
}
static void test_enomem2(void)
@@ -113,20 +50,14 @@ static void test_enomem2(void)
rl.rlim_max = len - 1;
rl.rlim_cur = len - 1;
- SAFE_SETRLIMIT(cleanup, RLIMIT_MEMLOCK, &rl);
-
- addr = SAFE_MMAP(cleanup, NULL, len, PROT_READ,
+ SAFE_SETRLIMIT(RLIMIT_MEMLOCK, &rl);
+ addr = SAFE_MMAP(NULL, len, PROT_READ,
MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
-
- SAFE_SETEUID(cleanup, ltpuser->pw_uid);
-
- mlock_verify(addr, len, ENOMEM);
-
- SAFE_SETEUID(cleanup, 0);
-
- SAFE_MUNMAP(cleanup, addr, len);
-
- SAFE_SETRLIMIT(cleanup, RLIMIT_MEMLOCK, &original);
+ SAFE_SETEUID(ltpuser->pw_uid);
+ TST_EXP_FAIL(mlock(addr, len), ENOMEM, "mlock(%p, %lu)", addr, len);
+ SAFE_SETEUID(0);
+ SAFE_MUNMAP(addr, len);
+ SAFE_SETRLIMIT(RLIMIT_MEMLOCK, &original);
}
static void test_eperm(void)
@@ -136,51 +67,32 @@ static void test_eperm(void)
rl.rlim_max = 0;
rl.rlim_cur = 0;
- SAFE_SETRLIMIT(cleanup, RLIMIT_MEMLOCK, &rl);
-
- addr = SAFE_MMAP(cleanup, NULL, len, PROT_READ,
+ SAFE_SETRLIMIT(RLIMIT_MEMLOCK, &rl);
+ addr = SAFE_MMAP(NULL, len, PROT_READ,
MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
-
- SAFE_SETEUID(cleanup, ltpuser->pw_uid);
-
- mlock_verify(addr, len, EPERM);
-
- SAFE_SETEUID(cleanup, 0);
-
- SAFE_MUNMAP(cleanup, addr, len);
-
- SAFE_SETRLIMIT(cleanup, RLIMIT_MEMLOCK, &original);
+ SAFE_SETEUID(ltpuser->pw_uid);
+ TST_EXP_FAIL(mlock(addr, len), EPERM, "mlock(%p, %lu)", addr, len);
+ SAFE_SETEUID(0);
+ SAFE_MUNMAP(addr, len);
+ SAFE_SETRLIMIT(RLIMIT_MEMLOCK, &original);
}
-static void mlock_verify(const void *addr, const size_t len, const int error)
+static void run(void)
{
- TEST(mlock(addr, len));
-
- if (TEST_RETURN != -1) {
- tst_resm(TFAIL, "mlock succeeded unexpectedly");
- return;
- }
-
- if (TEST_ERRNO != error) {
- tst_resm(TFAIL | TTERRNO,
- "mlock didn't fail as expected; expected - %d : %s",
- error, strerror(error));
- } else {
- tst_resm(TPASS | TTERRNO, "mlock failed as expected");
- }
+ test_enomem1();
+ test_enomem2();
+ test_eperm();
}
-static void cleanup(void)
-{
-}
-
-#else
-
-int TST_TOTAL = 1;
-
-int main(void)
+static void setup(void)
{
- tst_brkm(TCONF, NULL, "test is not available on uClinux");
+ ltpuser = SAFE_GETPWNAM("nobody");
+ len = getpagesize();
+ SAFE_GETRLIMIT(RLIMIT_MEMLOCK, &original);
}
-#endif /* if !defined(UCLINUX) */
+static struct tst_test test = {
+ .needs_root = 1,
+ .setup = setup,
+ .test_all = run,
+};
--
2.39.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [LTP] [PATCH 3/4] syscalls/mlock03: Convert into new api
2023-04-04 10:36 [LTP] [PATCH 1/4] syscalls/mlock01: Convert into new api Yang Xu
2023-04-04 10:36 ` [LTP] [PATCH 2/4] syscalls/mlock02: " Yang Xu
@ 2023-04-04 10:36 ` Yang Xu
2023-04-19 11:45 ` Avinesh Kumar
2023-04-04 10:36 ` [LTP] [PATCH 4/4] syscalls/mlock04: Convert into new api Yang Xu
2023-04-19 11:21 ` [LTP] [PATCH 1/4] syscalls/mlock01: " Avinesh Kumar
3 siblings, 1 reply; 14+ messages in thread
From: Yang Xu @ 2023-04-04 10:36 UTC (permalink / raw)
To: ltp
Also remove tst_require_root. Test mlock/munlock instead of mlock by default.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/mlock/mlock03.c | 137 +++++++---------------
1 file changed, 43 insertions(+), 94 deletions(-)
diff --git a/testcases/kernel/syscalls/mlock/mlock03.c b/testcases/kernel/syscalls/mlock/mlock03.c
index 8bc65701c..0fc3fa8ed 100644
--- a/testcases/kernel/syscalls/mlock/mlock03.c
+++ b/testcases/kernel/syscalls/mlock/mlock03.c
@@ -1,119 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * Stack size mapping is decreased through mlock/munlock call.
- *
- * This is to test kernel if it has a problem with shortening [stack]
- * mapping through several loops of mlock/munlock of /proc/self/maps.
- *
- * From:
- * munlock 76KiB bfef2000-bff05000 rw-p 00000000 00:00 0 [stack]
- *
- * To:
- * munlock 44KiB bfefa000-bff05000 rw-p 00000000 00:00 0 [stack]
- *
- * with more iterations - could drop to 0KiB.
- *
* Copyright (C) 2010 Red Hat, Inc.
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it
- * is free of the rightful claim of any third person regarding
- * infringement or the like. Any license provided herein, whether
- * implied or otherwise, applies only to this software file. Patent
- * licenses, if any, provided herein do not apply to combinations of
- * this program with other software, or any other product whatsoever.
+ */
+
+/*\
+ * [Description]
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * This case is designed to test kernel whether met a problem with shortening
+ * [stack] mapping through several loops of mlock/munlock of /proc/self/maps.
*/
+
#include <sys/mman.h>
#include <stdio.h>
#include <string.h>
-#include "test.h"
+#include <pwd.h>
+#include "tst_test.h"
+#include "tst_safe_stdio.h"
#define KB 1024
-char *TCID = "mlock03";
-int TST_TOTAL = 1;
-
-static void setup(void);
-static void cleanup(void);
-
-int main(int argc, char *argv[])
+static void verify_mlock(void)
{
- int lc;
long from, to;
long first = -1, last = -1;
char b[KB];
FILE *fp;
- tst_parse_opts(argc, argv, NULL, NULL);
-
- setup();
+ fp = SAFE_FOPEN("/proc/self/maps", "r");
+ while (!feof(fp)) {
+ if (!fgets(b, KB - 1, fp))
+ break;
+ b[strlen(b) - 1] = '\0';
+ if (sscanf(b, "%lx-%lx", &from, &to) != 2) {
+ tst_res(TFAIL, "parse %s start and end address failed",
+ b);
+ continue;
+ }
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- fp = fopen("/proc/self/maps", "r");
- if (fp == NULL)
- tst_brkm(TBROK | TERRNO, cleanup, "fopen");
- while (!feof(fp)) {
- if (!fgets(b, KB - 1, fp))
- break;
- b[strlen(b) - 1] = '\0';
- sscanf(b, "%lx-%lx", &from, &to);
+ /* Record the initial stack size. */
+ if (strstr(b, "[stack]") != NULL)
+ first = (to - from) / KB;
- /* Record the initial stack size. */
- if (lc == 0 && strstr(b, "[stack]") != NULL)
- first = (to - from) / KB;
+ tst_res(TINFO, "mlock[%lx,%lx]", from, to);
+ if (mlock((const void *)from, to - from) == -1)
+ tst_res(TINFO | TERRNO, "mlock failed");
- switch (lc & 1) {
- case 0:
- if (mlock((const void *)from, to - from) == -1)
- tst_resm(TINFO | TERRNO,
- "mlock failed");
- break;
- case 1:
- if (munlock((void *)from, to - from) == -1)
- tst_resm(TINFO | TERRNO,
- "munlock failed");
- break;
- default:
- break;
- }
- tst_resm(TINFO, "%s from %lx to %0lx",
- (lc & 1) ? "munlock" : "mlock", from, to);
+ tst_res(TINFO, "munlock [%lx,%lx]", from, to);
+ if (munlock((void *)from, to - from) == -1)
+ tst_res(TINFO | TERRNO, "munlock failed");
- /* Record the final stack size. */
- if (strstr(b, "[stack]") != NULL)
- last = (to - from) / KB;
- }
- fclose(fp);
+ /* Record the final stack size. */
+ if (strstr(b, "[stack]") != NULL)
+ last = (to - from) / KB;
}
- tst_resm(TINFO, "starting stack size is %ld", first);
- tst_resm(TINFO, "final stack size is %ld", last);
+ SAFE_FCLOSE(fp);
+
+ tst_res(TINFO, "starting stack size is %ld", first);
+ tst_res(TINFO, "final stack size is %ld", last);
if (last < first)
- tst_resm(TFAIL, "stack size is decreased.");
+ tst_res(TFAIL, "stack size is decreased.");
else
- tst_resm(TPASS, "stack size is not decreased.");
-
- cleanup();
- tst_exit();
+ tst_res(TPASS, "stack size is not decreased.");
}
-void setup(void)
-{
- tst_require_root();
-
- tst_sig(FORK, DEF_HANDLER, cleanup);
- TEST_PAUSE;
-}
-
-void cleanup(void)
-{
-}
+static struct tst_test test = {
+ .test_all = verify_mlock,
+};
--
2.39.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [LTP] [PATCH 4/4] syscalls/mlock04: Convert into new api
2023-04-04 10:36 [LTP] [PATCH 1/4] syscalls/mlock01: Convert into new api Yang Xu
2023-04-04 10:36 ` [LTP] [PATCH 2/4] syscalls/mlock02: " Yang Xu
2023-04-04 10:36 ` [LTP] [PATCH 3/4] syscalls/mlock03: " Yang Xu
@ 2023-04-04 10:36 ` Yang Xu
2023-04-19 11:21 ` [LTP] [PATCH 1/4] syscalls/mlock01: " Avinesh Kumar
3 siblings, 0 replies; 14+ messages in thread
From: Yang Xu @ 2023-04-04 10:36 UTC (permalink / raw)
To: ltp
Also add linux tag and useful url.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/mlock/mlock04.c | 112 ++++++++--------------
1 file changed, 39 insertions(+), 73 deletions(-)
diff --git a/testcases/kernel/syscalls/mlock/mlock04.c b/testcases/kernel/syscalls/mlock/mlock04.c
index 8ac884583..c90cc3556 100644
--- a/testcases/kernel/syscalls/mlock/mlock04.c
+++ b/testcases/kernel/syscalls/mlock/mlock04.c
@@ -1,102 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * This is a reproducer copied from one of LKML patch submission,
+ * Copyright (C) 2010 Red Hat, Inc.
+ */
+
+/*\
+ * [Description]
+ *
+ * This is a reproducer copied from one of LKML patch submission
* which subject is
*
* [PATCH] mlock: revert the optimization for dirtying pages and triggering writeback.
+ * url see https://www.spinics.net/lists/kernel/msg1141090.html
*
- * "In 5ecfda0, we do some optimization in mlock, but it causes
+ * "In 5ecfda0, we do some optimization in mlock, but it causes
* a very basic test case(attached below) of mlock to fail. So
* this patch revert it with some tiny modification so that it
* apply successfully with the lastest 38-rc2 kernel."
*
- * Copyright (C) 2010 Red Hat, Inc.
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it
- * is free of the rightful claim of any third person regarding
- * infringement or the like. Any license provided herein, whether
- * implied or otherwise, applies only to this software file. Patent
- * licenses, if any, provided herein do not apply to combinations of
- * this program with other software, or any other product whatsoever.
+ * This bug was fixed by kernel
+ * commit fdf4c587a7 ("mlock: operate on any regions with protection != PROT_NONE")
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * As this case does, mmaps a file with PROT_WRITE permissions but without
+ * PROT_READ, so attempt to not unnecessarity break COW during mlock ended up
+ * causing mlock to fail with a permission problem on unfixed kernel.
*/
-#include "test.h"
-#include "safe_macros.h"
-#include "config.h"
-
-char *TCID = "mlock04";
-int TST_TOTAL = 1;
#include <sys/mman.h>
#include <stdio.h>
#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/types.h>
-
-int fd, file_len = 40960;
-char *testfile = "test_mlock";
+#include "tst_test.h"
+#include "tst_safe_macros.h"
-static void setup(void);
-static void cleanup(void);
+static int fd = -1, file_len = 40960;
+static char *testfile = "test_mlock";
-int main(void)
+static void verify_mlock(void)
{
char *buf;
- int lc;
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- buf = mmap(NULL, file_len, PROT_WRITE, MAP_SHARED, fd, 0);
-
- if (buf == MAP_FAILED)
- tst_brkm(TBROK | TERRNO, cleanup, "mmap");
- if (mlock(buf, file_len) == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "mlock");
-
- tst_resm(TINFO, "locked %d bytes from %p", file_len, buf);
-
- if (munlock(buf, file_len) == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "munlock");
-
- SAFE_MUNMAP(cleanup, buf, file_len);
- }
-
- tst_resm(TPASS, "test succeeded.");
-
- cleanup();
-
- tst_exit();
+ buf = SAFE_MMAP(NULL, file_len, PROT_WRITE, MAP_SHARED, fd, 0);
+ TST_EXP_PASS(mlock(buf, file_len), "mlock(%p, %d)", buf, file_len);
+ SAFE_MUNLOCK(buf, file_len);
+ SAFE_MUNMAP(buf, file_len);
}
static void setup(void)
{
- tst_tmpdir();
-
- fd = SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
-
- SAFE_FTRUNCATE(cleanup, fd, file_len);
-
- TEST_PAUSE;
+ fd = SAFE_OPEN(testfile, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
+ SAFE_FTRUNCATE(fd, file_len);
}
static void cleanup(void)
{
- close(fd);
-
- tst_rmdir();
+ if (fd > -1)
+ SAFE_CLOSE(fd);
}
+
+static struct tst_test test = {
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = verify_mlock,
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "fdf4c587a793"},
+ {}
+ }
+};
--
2.39.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH 1/4] syscalls/mlock01: Convert into new api
2023-04-04 10:36 [LTP] [PATCH 1/4] syscalls/mlock01: Convert into new api Yang Xu
` (2 preceding siblings ...)
2023-04-04 10:36 ` [LTP] [PATCH 4/4] syscalls/mlock04: Convert into new api Yang Xu
@ 2023-04-19 11:21 ` Avinesh Kumar
3 siblings, 0 replies; 14+ messages in thread
From: Avinesh Kumar @ 2023-04-19 11:21 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Reviewed-by: Avinesh Kumar <akumar@suse.de>
--
Regards,
Avinesh
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH 2/4] syscalls/mlock02: Convert into new api
2023-04-04 10:36 ` [LTP] [PATCH 2/4] syscalls/mlock02: " Yang Xu
@ 2023-04-19 11:22 ` Avinesh Kumar
2023-04-24 8:48 ` Yang Xu (Fujitsu)
0 siblings, 1 reply; 14+ messages in thread
From: Avinesh Kumar @ 2023-04-19 11:22 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Reviewed-by: Avinesh Kumar <akumar@suse.de>
--
Regards,
Avinesh
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH 3/4] syscalls/mlock03: Convert into new api
2023-04-04 10:36 ` [LTP] [PATCH 3/4] syscalls/mlock03: " Yang Xu
@ 2023-04-19 11:45 ` Avinesh Kumar
2023-04-24 8:19 ` Yang Xu (Fujitsu)
2023-04-27 5:44 ` [LTP] [PATCH v2 1/2] syscalls/mlock03:Remove meaningless case Yang Xu
0 siblings, 2 replies; 14+ messages in thread
From: Avinesh Kumar @ 2023-04-19 11:45 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi,
On Tuesday, April 4, 2023 4:06:33 PM IST Yang Xu wrote:
> Also remove tst_require_root. Test mlock/munlock instead of mlock by default.
>
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
> testcases/kernel/syscalls/mlock/mlock03.c | 137 +++++++---------------
> 1 file changed, 43 insertions(+), 94 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/mlock/mlock03.c b/testcases/kernel/syscalls/mlock/mlock03.c
> index 8bc65701c..0fc3fa8ed 100644
> --- a/testcases/kernel/syscalls/mlock/mlock03.c
> +++ b/testcases/kernel/syscalls/mlock/mlock03.c
> @@ -1,119 +1,68 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
Original test only has GPLv2
> /*
> - * Stack size mapping is decreased through mlock/munlock call.
> - *
> - * This is to test kernel if it has a problem with shortening [stack]
> - * mapping through several loops of mlock/munlock of /proc/self/maps.
> - *
> - * From:
> - * munlock 76KiB bfef2000-bff05000 rw-p 00000000 00:00 0 [stack]
> - *
> - * To:
> - * munlock 44KiB bfefa000-bff05000 rw-p 00000000 00:00 0 [stack]
> - *
> - * with more iterations - could drop to 0KiB.
> - *
> * Copyright (C) 2010 Red Hat, Inc.
> - * This program is free software; you can redistribute it and/or
> - * modify it under the terms of version 2 of the GNU General Public
> - * License as published by the Free Software Foundation.
> - *
> - * This program is distributed in the hope that it would be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> - *
> - * Further, this software is distributed without any warranty that it
> - * is free of the rightful claim of any third person regarding
> - * infringement or the like. Any license provided herein, whether
> - * implied or otherwise, applies only to this software file. Patent
> - * licenses, if any, provided herein do not apply to combinations of
> - * this program with other software, or any other product whatsoever.
> + */
> +
> +/*\
> + * [Description]
> *
> - * You should have received a copy of the GNU General Public License
> - * along with this program; if not, write the Free Software
> - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> - * 02110-1301, USA.
> + * This case is designed to test kernel whether met a problem with shortening
> + * [stack] mapping through several loops of mlock/munlock of /proc/self/maps.
I don't understand how shortening of stack by calling to mlock/munlock
for maps regions may work, so no comments on actual patch.
> */
> +
> #include <sys/mman.h>
> #include <stdio.h>
> #include <string.h>
> -#include "test.h"
> +#include <pwd.h>
> +#include "tst_test.h"
> +#include "tst_safe_stdio.h"
>
> #define KB 1024
>
> -char *TCID = "mlock03";
> -int TST_TOTAL = 1;
> -
> -static void setup(void);
> -static void cleanup(void);
> -
> -int main(int argc, char *argv[])
> +static void verify_mlock(void)
> {
> - int lc;
> long from, to;
> long first = -1, last = -1;
> char b[KB];
> FILE *fp;
>
> - tst_parse_opts(argc, argv, NULL, NULL);
> -
> - setup();
> + fp = SAFE_FOPEN("/proc/self/maps", "r");
> + while (!feof(fp)) {
> + if (!fgets(b, KB - 1, fp))
> + break;
> + b[strlen(b) - 1] = '\0';
> + if (sscanf(b, "%lx-%lx", &from, &to) != 2) {
> + tst_res(TFAIL, "parse %s start and end address failed",
> + b);
> + continue;
> + }
>
> - for (lc = 0; TEST_LOOPING(lc); lc++) {
> - fp = fopen("/proc/self/maps", "r");
> - if (fp == NULL)
> - tst_brkm(TBROK | TERRNO, cleanup, "fopen");
> - while (!feof(fp)) {
> - if (!fgets(b, KB - 1, fp))
> - break;
> - b[strlen(b) - 1] = '\0';
> - sscanf(b, "%lx-%lx", &from, &to);
> + /* Record the initial stack size. */
> + if (strstr(b, "[stack]") != NULL)
> + first = (to - from) / KB;
>
> - /* Record the initial stack size. */
> - if (lc == 0 && strstr(b, "[stack]") != NULL)
> - first = (to - from) / KB;
> + tst_res(TINFO, "mlock[%lx,%lx]", from, to);
> + if (mlock((const void *)from, to - from) == -1)
> + tst_res(TINFO | TERRNO, "mlock failed");
>
> - switch (lc & 1) {
> - case 0:
> - if (mlock((const void *)from, to - from) == -1)
> - tst_resm(TINFO | TERRNO,
> - "mlock failed");
> - break;
> - case 1:
> - if (munlock((void *)from, to - from) == -1)
> - tst_resm(TINFO | TERRNO,
> - "munlock failed");
> - break;
> - default:
> - break;
> - }
> - tst_resm(TINFO, "%s from %lx to %0lx",
> - (lc & 1) ? "munlock" : "mlock", from, to);
> + tst_res(TINFO, "munlock [%lx,%lx]", from, to);
> + if (munlock((void *)from, to - from) == -1)
> + tst_res(TINFO | TERRNO, "munlock failed");
>
> - /* Record the final stack size. */
> - if (strstr(b, "[stack]") != NULL)
> - last = (to - from) / KB;
> - }
> - fclose(fp);
> + /* Record the final stack size. */
> + if (strstr(b, "[stack]") != NULL)
> + last = (to - from) / KB;
> }
> - tst_resm(TINFO, "starting stack size is %ld", first);
> - tst_resm(TINFO, "final stack size is %ld", last);
> + SAFE_FCLOSE(fp);
> +
> + tst_res(TINFO, "starting stack size is %ld", first);
> + tst_res(TINFO, "final stack size is %ld", last);
> if (last < first)
> - tst_resm(TFAIL, "stack size is decreased.");
> + tst_res(TFAIL, "stack size is decreased.");
> else
> - tst_resm(TPASS, "stack size is not decreased.");
> -
> - cleanup();
> - tst_exit();
> + tst_res(TPASS, "stack size is not decreased.");
> }
>
> -void setup(void)
> -{
> - tst_require_root();
> -
> - tst_sig(FORK, DEF_HANDLER, cleanup);
> - TEST_PAUSE;
> -}
> -
> -void cleanup(void)
> -{
> -}
> +static struct tst_test test = {
> + .test_all = verify_mlock,
> +};
>
--
Regards,
Avinesh
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH 3/4] syscalls/mlock03: Convert into new api
2023-04-19 11:45 ` Avinesh Kumar
@ 2023-04-24 8:19 ` Yang Xu (Fujitsu)
2023-04-27 5:44 ` [LTP] [PATCH v2 1/2] syscalls/mlock03:Remove meaningless case Yang Xu
1 sibling, 0 replies; 14+ messages in thread
From: Yang Xu (Fujitsu) @ 2023-04-24 8:19 UTC (permalink / raw)
To: Avinesh Kumar; +Cc: ltp@lists.linux.it
Hi Avinesh
> Hi,
>
> On Tuesday, April 4, 2023 4:06:33 PM IST Yang Xu wrote:
>> Also remove tst_require_root. Test mlock/munlock instead of mlock by default.
>>
>> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
>> ---
>> testcases/kernel/syscalls/mlock/mlock03.c | 137 +++++++---------------
>> 1 file changed, 43 insertions(+), 94 deletions(-)
>>
>> diff --git a/testcases/kernel/syscalls/mlock/mlock03.c b/testcases/kernel/syscalls/mlock/mlock03.c
>> index 8bc65701c..0fc3fa8ed 100644
>> --- a/testcases/kernel/syscalls/mlock/mlock03.c
>> +++ b/testcases/kernel/syscalls/mlock/mlock03.c
>> @@ -1,119 +1,68 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
> Original test only has GPLv2
Good catch.
>
>> /*
>> - * Stack size mapping is decreased through mlock/munlock call.
>> - *
>> - * This is to test kernel if it has a problem with shortening [stack]
>> - * mapping through several loops of mlock/munlock of /proc/self/maps.
>> - *
>> - * From:
>> - * munlock 76KiB bfef2000-bff05000 rw-p 00000000 00:00 0 [stack]
>> - *
>> - * To:
>> - * munlock 44KiB bfefa000-bff05000 rw-p 00000000 00:00 0 [stack]
>> - *
>> - * with more iterations - could drop to 0KiB.
>> - *
>> * Copyright (C) 2010 Red Hat, Inc.
>> - * This program is free software; you can redistribute it and/or
>> - * modify it under the terms of version 2 of the GNU General Public
>> - * License as published by the Free Software Foundation.
>> - *
>> - * This program is distributed in the hope that it would be useful,
>> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>> - *
>> - * Further, this software is distributed without any warranty that it
>> - * is free of the rightful claim of any third person regarding
>> - * infringement or the like. Any license provided herein, whether
>> - * implied or otherwise, applies only to this software file. Patent
>> - * licenses, if any, provided herein do not apply to combinations of
>> - * this program with other software, or any other product whatsoever.
>> + */
>> +
>> +/*\
>> + * [Description]
>> *
>> - * You should have received a copy of the GNU General Public License
>> - * along with this program; if not, write the Free Software
>> - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
>> - * 02110-1301, USA.
>> + * This case is designed to test kernel whether met a problem with shortening
>> + * [stack] mapping through several loops of mlock/munlock of /proc/self/maps.
> I don't understand how shortening of stack by calling to mlock/munlock
> for maps regions may work, so no comments on actual patch.
It doesn't related to shortening [stack] mapping. I also see kernel org
that doesn't have similar bug.
Perhaps we can remove this case.
Best Regards
Yang Xu
>
>> */
>> +
>> #include <sys/mman.h>
>> #include <stdio.h>
>> #include <string.h>
>> -#include "test.h"
>> +#include <pwd.h>
>> +#include "tst_test.h"
>> +#include "tst_safe_stdio.h"
>>
>> #define KB 1024
>>
>> -char *TCID = "mlock03";
>> -int TST_TOTAL = 1;
>> -
>> -static void setup(void);
>> -static void cleanup(void);
>> -
>> -int main(int argc, char *argv[])
>> +static void verify_mlock(void)
>> {
>> - int lc;
>> long from, to;
>> long first = -1, last = -1;
>> char b[KB];
>> FILE *fp;
>>
>> - tst_parse_opts(argc, argv, NULL, NULL);
>> -
>> - setup();
>> + fp = SAFE_FOPEN("/proc/self/maps", "r");
>> + while (!feof(fp)) {
>> + if (!fgets(b, KB - 1, fp))
>> + break;
>> + b[strlen(b) - 1] = '\0';
>> + if (sscanf(b, "%lx-%lx", &from, &to) != 2) {
>> + tst_res(TFAIL, "parse %s start and end address failed",
>> + b);
>> + continue;
>> + }
>>
>> - for (lc = 0; TEST_LOOPING(lc); lc++) {
>> - fp = fopen("/proc/self/maps", "r");
>> - if (fp == NULL)
>> - tst_brkm(TBROK | TERRNO, cleanup, "fopen");
>> - while (!feof(fp)) {
>> - if (!fgets(b, KB - 1, fp))
>> - break;
>> - b[strlen(b) - 1] = '\0';
>> - sscanf(b, "%lx-%lx", &from, &to);
>> + /* Record the initial stack size. */
>> + if (strstr(b, "[stack]") != NULL)
>> + first = (to - from) / KB;
>>
>> - /* Record the initial stack size. */
>> - if (lc == 0 && strstr(b, "[stack]") != NULL)
>> - first = (to - from) / KB;
>> + tst_res(TINFO, "mlock[%lx,%lx]", from, to);
>> + if (mlock((const void *)from, to - from) == -1)
>> + tst_res(TINFO | TERRNO, "mlock failed");
>>
>> - switch (lc & 1) {
>> - case 0:
>> - if (mlock((const void *)from, to - from) == -1)
>> - tst_resm(TINFO | TERRNO,
>> - "mlock failed");
>> - break;
>> - case 1:
>> - if (munlock((void *)from, to - from) == -1)
>> - tst_resm(TINFO | TERRNO,
>> - "munlock failed");
>> - break;
>> - default:
>> - break;
>> - }
>> - tst_resm(TINFO, "%s from %lx to %0lx",
>> - (lc & 1) ? "munlock" : "mlock", from, to);
>> + tst_res(TINFO, "munlock [%lx,%lx]", from, to);
>> + if (munlock((void *)from, to - from) == -1)
>> + tst_res(TINFO | TERRNO, "munlock failed");
>>
>> - /* Record the final stack size. */
>> - if (strstr(b, "[stack]") != NULL)
>> - last = (to - from) / KB;
>> - }
>> - fclose(fp);
>> + /* Record the final stack size. */
>> + if (strstr(b, "[stack]") != NULL)
>> + last = (to - from) / KB;
>> }
>> - tst_resm(TINFO, "starting stack size is %ld", first);
>> - tst_resm(TINFO, "final stack size is %ld", last);
>> + SAFE_FCLOSE(fp);
>> +
>> + tst_res(TINFO, "starting stack size is %ld", first);
>> + tst_res(TINFO, "final stack size is %ld", last);
>> if (last < first)
>> - tst_resm(TFAIL, "stack size is decreased.");
>> + tst_res(TFAIL, "stack size is decreased.");
>> else
>> - tst_resm(TPASS, "stack size is not decreased.");
>> -
>> - cleanup();
>> - tst_exit();
>> + tst_res(TPASS, "stack size is not decreased.");
>> }
>>
>> -void setup(void)
>> -{
>> - tst_require_root();
>> -
>> - tst_sig(FORK, DEF_HANDLER, cleanup);
>> - TEST_PAUSE;
>> -}
>> -
>> -void cleanup(void)
>> -{
>> -}
>> +static struct tst_test test = {
>> + .test_all = verify_mlock,
>> +};
>>
>
> --
> Regards,
> Avinesh
>
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH 2/4] syscalls/mlock02: Convert into new api
2023-04-19 11:22 ` Avinesh Kumar
@ 2023-04-24 8:48 ` Yang Xu (Fujitsu)
0 siblings, 0 replies; 14+ messages in thread
From: Yang Xu (Fujitsu) @ 2023-04-24 8:48 UTC (permalink / raw)
To: Avinesh Kumar; +Cc: ltp@lists.linux.it
Hi Avinesh
> Reviewed-by: Avinesh Kumar <akumar@suse.de>
Thanks for your review, I have merged the 1/4 and 2/4 patch.
Best Regards
Yang Xu
>
> --
> Regards,
> Avinesh
>
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* [LTP] [PATCH v2 1/2] syscalls/mlock03:Remove meaningless case
2023-04-19 11:45 ` Avinesh Kumar
2023-04-24 8:19 ` Yang Xu (Fujitsu)
@ 2023-04-27 5:44 ` Yang Xu
2023-04-27 5:44 ` [LTP] [PATCH v2 2/2] syscalls/mlock04: Convert into new api Yang Xu
2023-05-02 12:03 ` [LTP] [PATCH v2 1/2] syscalls/mlock03:Remove meaningless case Cyril Hrubis
1 sibling, 2 replies; 14+ messages in thread
From: Yang Xu @ 2023-04-27 5:44 UTC (permalink / raw)
To: ltp
This case is used to read start address and end address
from /proc/self/maps. Then check stack range whether be shorten.
AFAIK, kernel doesn't have this similar bug and man-pages
also doesn't mention it.
So let's remove this meaningful case.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
runtest/syscalls | 1 -
testcases/kernel/syscalls/mlock/.gitignore | 1 -
testcases/kernel/syscalls/mlock/mlock03.c | 119 ---------------------
3 files changed, 121 deletions(-)
delete mode 100644 testcases/kernel/syscalls/mlock/mlock03.c
diff --git a/runtest/syscalls b/runtest/syscalls
index 9c23a4248..b58a58c74 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -765,7 +765,6 @@ mknodat02 mknodat02
mlock01 mlock01
mlock02 mlock02
-mlock03 mlock03 -i 20
mlock04 mlock04
mlock201 mlock201
diff --git a/testcases/kernel/syscalls/mlock/.gitignore b/testcases/kernel/syscalls/mlock/.gitignore
index 306574bbc..566f0cfcc 100644
--- a/testcases/kernel/syscalls/mlock/.gitignore
+++ b/testcases/kernel/syscalls/mlock/.gitignore
@@ -1,4 +1,3 @@
/mlock01
/mlock02
-/mlock03
/mlock04
diff --git a/testcases/kernel/syscalls/mlock/mlock03.c b/testcases/kernel/syscalls/mlock/mlock03.c
deleted file mode 100644
index 8bc65701c..000000000
--- a/testcases/kernel/syscalls/mlock/mlock03.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Stack size mapping is decreased through mlock/munlock call.
- *
- * This is to test kernel if it has a problem with shortening [stack]
- * mapping through several loops of mlock/munlock of /proc/self/maps.
- *
- * From:
- * munlock 76KiB bfef2000-bff05000 rw-p 00000000 00:00 0 [stack]
- *
- * To:
- * munlock 44KiB bfefa000-bff05000 rw-p 00000000 00:00 0 [stack]
- *
- * with more iterations - could drop to 0KiB.
- *
- * Copyright (C) 2010 Red Hat, Inc.
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it
- * is free of the rightful claim of any third person regarding
- * infringement or the like. Any license provided herein, whether
- * implied or otherwise, applies only to this software file. Patent
- * licenses, if any, provided herein do not apply to combinations of
- * this program with other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- */
-#include <sys/mman.h>
-#include <stdio.h>
-#include <string.h>
-#include "test.h"
-
-#define KB 1024
-
-char *TCID = "mlock03";
-int TST_TOTAL = 1;
-
-static void setup(void);
-static void cleanup(void);
-
-int main(int argc, char *argv[])
-{
- int lc;
- long from, to;
- long first = -1, last = -1;
- char b[KB];
- FILE *fp;
-
- tst_parse_opts(argc, argv, NULL, NULL);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- fp = fopen("/proc/self/maps", "r");
- if (fp == NULL)
- tst_brkm(TBROK | TERRNO, cleanup, "fopen");
- while (!feof(fp)) {
- if (!fgets(b, KB - 1, fp))
- break;
- b[strlen(b) - 1] = '\0';
- sscanf(b, "%lx-%lx", &from, &to);
-
- /* Record the initial stack size. */
- if (lc == 0 && strstr(b, "[stack]") != NULL)
- first = (to - from) / KB;
-
- switch (lc & 1) {
- case 0:
- if (mlock((const void *)from, to - from) == -1)
- tst_resm(TINFO | TERRNO,
- "mlock failed");
- break;
- case 1:
- if (munlock((void *)from, to - from) == -1)
- tst_resm(TINFO | TERRNO,
- "munlock failed");
- break;
- default:
- break;
- }
- tst_resm(TINFO, "%s from %lx to %0lx",
- (lc & 1) ? "munlock" : "mlock", from, to);
-
- /* Record the final stack size. */
- if (strstr(b, "[stack]") != NULL)
- last = (to - from) / KB;
- }
- fclose(fp);
- }
- tst_resm(TINFO, "starting stack size is %ld", first);
- tst_resm(TINFO, "final stack size is %ld", last);
- if (last < first)
- tst_resm(TFAIL, "stack size is decreased.");
- else
- tst_resm(TPASS, "stack size is not decreased.");
-
- cleanup();
- tst_exit();
-}
-
-void setup(void)
-{
- tst_require_root();
-
- tst_sig(FORK, DEF_HANDLER, cleanup);
- TEST_PAUSE;
-}
-
-void cleanup(void)
-{
-}
--
2.39.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [LTP] [PATCH v2 2/2] syscalls/mlock04: Convert into new api
2023-04-27 5:44 ` [LTP] [PATCH v2 1/2] syscalls/mlock03:Remove meaningless case Yang Xu
@ 2023-04-27 5:44 ` Yang Xu
2023-05-02 12:13 ` Cyril Hrubis
2023-05-02 12:03 ` [LTP] [PATCH v2 1/2] syscalls/mlock03:Remove meaningless case Cyril Hrubis
1 sibling, 1 reply; 14+ messages in thread
From: Yang Xu @ 2023-04-27 5:44 UTC (permalink / raw)
To: ltp
Also add linux tag and useful url.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/mlock/mlock04.c | 110 ++++++++--------------
1 file changed, 38 insertions(+), 72 deletions(-)
diff --git a/testcases/kernel/syscalls/mlock/mlock04.c b/testcases/kernel/syscalls/mlock/mlock04.c
index 8ac884583..f25460ba1 100644
--- a/testcases/kernel/syscalls/mlock/mlock04.c
+++ b/testcases/kernel/syscalls/mlock/mlock04.c
@@ -1,102 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0
/*
- * This is a reproducer copied from one of LKML patch submission,
+ * Copyright (C) 2010 Red Hat, Inc.
+ */
+
+/*\
+ * [Description]
+ *
+ * This is a reproducer copied from one of LKML patch submission
* which subject is
*
* [PATCH] mlock: revert the optimization for dirtying pages and triggering writeback.
+ * url see https://www.spinics.net/lists/kernel/msg1141090.html
*
* "In 5ecfda0, we do some optimization in mlock, but it causes
* a very basic test case(attached below) of mlock to fail. So
* this patch revert it with some tiny modification so that it
* apply successfully with the lastest 38-rc2 kernel."
*
- * Copyright (C) 2010 Red Hat, Inc.
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it
- * is free of the rightful claim of any third person regarding
- * infringement or the like. Any license provided herein, whether
- * implied or otherwise, applies only to this software file. Patent
- * licenses, if any, provided herein do not apply to combinations of
- * this program with other software, or any other product whatsoever.
+ * This bug was fixed by kernel
+ * commit fdf4c587a7 ("mlock: operate on any regions with protection != PROT_NONE")
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * As this case does, mmaps a file with PROT_WRITE permissions but without
+ * PROT_READ, so attempt to not unnecessarity break COW during mlock ended up
+ * causing mlock to fail with a permission problem on unfixed kernel.
*/
-#include "test.h"
-#include "safe_macros.h"
-#include "config.h"
-
-char *TCID = "mlock04";
-int TST_TOTAL = 1;
#include <sys/mman.h>
#include <stdio.h>
#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/types.h>
-
-int fd, file_len = 40960;
-char *testfile = "test_mlock";
+#include "tst_test.h"
+#include "tst_safe_macros.h"
-static void setup(void);
-static void cleanup(void);
+static int fd = -1, file_len = 40960;
+static char *testfile = "test_mlock";
-int main(void)
+static void verify_mlock(void)
{
char *buf;
- int lc;
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- buf = mmap(NULL, file_len, PROT_WRITE, MAP_SHARED, fd, 0);
-
- if (buf == MAP_FAILED)
- tst_brkm(TBROK | TERRNO, cleanup, "mmap");
- if (mlock(buf, file_len) == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "mlock");
-
- tst_resm(TINFO, "locked %d bytes from %p", file_len, buf);
-
- if (munlock(buf, file_len) == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "munlock");
-
- SAFE_MUNMAP(cleanup, buf, file_len);
- }
-
- tst_resm(TPASS, "test succeeded.");
-
- cleanup();
-
- tst_exit();
+ buf = SAFE_MMAP(NULL, file_len, PROT_WRITE, MAP_SHARED, fd, 0);
+ TST_EXP_PASS(mlock(buf, file_len), "mlock(%p, %d)", buf, file_len);
+ SAFE_MUNLOCK(buf, file_len);
+ SAFE_MUNMAP(buf, file_len);
}
static void setup(void)
{
- tst_tmpdir();
-
- fd = SAFE_OPEN(cleanup, testfile, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
-
- SAFE_FTRUNCATE(cleanup, fd, file_len);
-
- TEST_PAUSE;
+ fd = SAFE_OPEN(testfile, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
+ SAFE_FTRUNCATE(fd, file_len);
}
static void cleanup(void)
{
- close(fd);
-
- tst_rmdir();
+ if (fd > -1)
+ SAFE_CLOSE(fd);
}
+
+static struct tst_test test = {
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = verify_mlock,
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "fdf4c587a793"},
+ {}
+ }
+};
--
2.39.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH v2 1/2] syscalls/mlock03:Remove meaningless case
2023-04-27 5:44 ` [LTP] [PATCH v2 1/2] syscalls/mlock03:Remove meaningless case Yang Xu
2023-04-27 5:44 ` [LTP] [PATCH v2 2/2] syscalls/mlock04: Convert into new api Yang Xu
@ 2023-05-02 12:03 ` Cyril Hrubis
2023-05-08 2:32 ` Yang Xu (Fujitsu)
1 sibling, 1 reply; 14+ messages in thread
From: Cyril Hrubis @ 2023-05-02 12:03 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi!
This test seems to be a regression test for:
https://bugzilla.redhat.com/show_bug.cgi?id=643426
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH v2 2/2] syscalls/mlock04: Convert into new api
2023-04-27 5:44 ` [LTP] [PATCH v2 2/2] syscalls/mlock04: Convert into new api Yang Xu
@ 2023-05-02 12:13 ` Cyril Hrubis
0 siblings, 0 replies; 14+ messages in thread
From: Cyril Hrubis @ 2023-05-02 12:13 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi!
Pushed, thanks.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH v2 1/2] syscalls/mlock03:Remove meaningless case
2023-05-02 12:03 ` [LTP] [PATCH v2 1/2] syscalls/mlock03:Remove meaningless case Cyril Hrubis
@ 2023-05-08 2:32 ` Yang Xu (Fujitsu)
0 siblings, 0 replies; 14+ messages in thread
From: Yang Xu (Fujitsu) @ 2023-05-08 2:32 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp@lists.linux.it
Hi Cyril
> Hi!
> This test seems to be a regression test for:
>
> https://bugzilla.redhat.com/show_bug.cgi?id=643426
Yes, it is only a regression test just for RHEL5.6 and it seems a
backport bug.
I donwload a kernel-2.6.18-238.el5.src.rpm and search for 643426, then
found
linux-2.6-mm-backport-upstream-stack-guard-page-proc-reporting.patch.
The upstream 39aa3cb fix this bug.
I will add a url for this case and send a v3.
ps: To avoid this bug exists on distribution kernel or upstream kernel
again, I think we should keep this old case.
Best Regards
Yang Xu
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2023-05-08 2:33 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-04 10:36 [LTP] [PATCH 1/4] syscalls/mlock01: Convert into new api Yang Xu
2023-04-04 10:36 ` [LTP] [PATCH 2/4] syscalls/mlock02: " Yang Xu
2023-04-19 11:22 ` Avinesh Kumar
2023-04-24 8:48 ` Yang Xu (Fujitsu)
2023-04-04 10:36 ` [LTP] [PATCH 3/4] syscalls/mlock03: " Yang Xu
2023-04-19 11:45 ` Avinesh Kumar
2023-04-24 8:19 ` Yang Xu (Fujitsu)
2023-04-27 5:44 ` [LTP] [PATCH v2 1/2] syscalls/mlock03:Remove meaningless case Yang Xu
2023-04-27 5:44 ` [LTP] [PATCH v2 2/2] syscalls/mlock04: Convert into new api Yang Xu
2023-05-02 12:13 ` Cyril Hrubis
2023-05-02 12:03 ` [LTP] [PATCH v2 1/2] syscalls/mlock03:Remove meaningless case Cyril Hrubis
2023-05-08 2:32 ` Yang Xu (Fujitsu)
2023-04-04 10:36 ` [LTP] [PATCH 4/4] syscalls/mlock04: Convert into new api Yang Xu
2023-04-19 11:21 ` [LTP] [PATCH 1/4] syscalls/mlock01: " Avinesh Kumar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).