All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] SAFE_MACROS: Add SAFE_SETSID()
@ 2017-06-15  9:57 Guangwen Feng
  2017-06-15  9:57 ` [LTP] [PATCH 2/2] sched/autogroup01: Add new regression test Guangwen Feng
  0 siblings, 1 reply; 5+ messages in thread
From: Guangwen Feng @ 2017-06-15  9:57 UTC (permalink / raw)
  To: ltp

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 include/tst_safe_macros.h |  3 +++
 lib/safe_macros.c         | 13 +++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index a25a4f0..09745c1 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -430,4 +430,7 @@ int safe_removexattr(const char *file, const int lineno, const char *path,
 int safe_fsync(const char *file, const int lineno, int fd);
 #define SAFE_FSYNC(fd) safe_fsync(__FILE__, __LINE__, (fd))
 
+int safe_setsid(const char *file, const int lineno);
+#define SAFE_SETSID() safe_setsid(__FILE__, __LINE__)
+
 #endif /* SAFE_MACROS_H__ */
diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index a6b4ff7..3ef9266 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -895,3 +895,16 @@ int safe_fsync(const char *file, const int lineno, int fd)
 
 	return rval;
 }
+
+pid_t safe_setsid(const char *file, const int lineno)
+{
+	pid_t rval;
+
+	rval = setsid();
+	if (rval == -1) {
+		tst_brkm(TBROK | TERRNO, NULL,
+			 "%s:%d: setsid() failed", file, lineno);
+	}
+
+	return rval;
+}
-- 
1.8.4.2




^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH 2/2] sched/autogroup01: Add new regression test
  2017-06-15  9:57 [LTP] [PATCH 1/2] SAFE_MACROS: Add SAFE_SETSID() Guangwen Feng
@ 2017-06-15  9:57 ` Guangwen Feng
  2017-06-15 14:31   ` Cyril Hrubis
  0 siblings, 1 reply; 5+ messages in thread
From: Guangwen Feng @ 2017-06-15  9:57 UTC (permalink / raw)
  To: ltp

Fixed by:
commit 18f649ef344127ef6de23a5a4272dbe2fdb73dde
Author: Oleg Nesterov <oleg@redhat.com>
Date:   Mon Nov 14 19:46:09 2016 +0100

  sched/autogroup: Fix autogroup_move_group() to never skip sched_move_task()

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 runtest/sched                                  |  2 +
 testcases/kernel/sched/autogroup/.gitignore    |  1 +
 testcases/kernel/sched/autogroup/Makefile      | 23 +++++++
 testcases/kernel/sched/autogroup/autogroup01.c | 95 ++++++++++++++++++++++++++
 4 files changed, 121 insertions(+)
 create mode 100644 testcases/kernel/sched/autogroup/.gitignore
 create mode 100644 testcases/kernel/sched/autogroup/Makefile
 create mode 100644 testcases/kernel/sched/autogroup/autogroup01.c

diff --git a/runtest/sched b/runtest/sched
index 89398df..774d11f 100644
--- a/runtest/sched
+++ b/runtest/sched
@@ -16,3 +16,5 @@ sched_getattr02 sched_getattr02
 sched_cli_serv run_sched_cliserv.sh
 # Run this stress test for 2 minutes
 sched_stress sched_stress.sh
+
+autogroup01 autogroup01
diff --git a/testcases/kernel/sched/autogroup/.gitignore b/testcases/kernel/sched/autogroup/.gitignore
new file mode 100644
index 0000000..bcc7453
--- /dev/null
+++ b/testcases/kernel/sched/autogroup/.gitignore
@@ -0,0 +1 @@
+/autogroup01
diff --git a/testcases/kernel/sched/autogroup/Makefile b/testcases/kernel/sched/autogroup/Makefile
new file mode 100644
index 0000000..6cc7782
--- /dev/null
+++ b/testcases/kernel/sched/autogroup/Makefile
@@ -0,0 +1,23 @@
+#
+#  Copyright (c) 2017 Fujitsu Ltd.
+#  Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
+#
+#  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, see <http://www.gnu.org/licenses/>.
+#
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/sched/autogroup/autogroup01.c b/testcases/kernel/sched/autogroup/autogroup01.c
new file mode 100644
index 0000000..3b08e42
--- /dev/null
+++ b/testcases/kernel/sched/autogroup/autogroup01.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2017 Fujitsu Ltd.
+ * Ported: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * This is a regression test about the race in autogroup, this test
+ * can crash the buggy kernel, and the bug has been fixed in:
+ *
+ *   commit 18f649ef344127ef6de23a5a4272dbe2fdb73dde
+ *   Author: Oleg Nesterov <oleg@redhat.com>
+ *   Date:   Mon Nov 14 19:46:09 2016 +0100
+ *
+ *   sched/autogroup: Fix autogroup_move_group() to never skip sched_move_task()
+ */
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "tst_test.h"
+
+#define LOOPS	1000
+#define PATH_AUTOGROUP	"/proc/sys/kernel/sched_autogroup_enabled"
+
+static int orig_autogroup = -1;
+
+static void do_test(void)
+{
+	int i;
+
+	if (!SAFE_FORK()) {
+		SAFE_FILE_PRINTF(PATH_AUTOGROUP, "%d", 1);
+		SAFE_SETSID();
+
+		if (SAFE_FORK()) {
+			pause();
+			exit(0);
+		}
+
+		SAFE_KILL(getppid(), SIGKILL);
+		usleep(1000);
+
+		SAFE_FILE_PRINTF(PATH_AUTOGROUP, "%d", 0);
+		SAFE_SETSID();
+
+		for (i = 0; i < LOOPS; i++)
+			usleep(10);
+
+		TST_CHECKPOINT_WAKE(0);
+
+		exit(0);
+	}
+
+	SAFE_WAIT(NULL);
+
+	TST_CHECKPOINT_WAIT(0);
+
+	tst_res(TPASS, "Bug not reproduced");
+}
+
+static void setup(void)
+{
+	if (access(PATH_AUTOGROUP, F_OK))
+		tst_brk(TCONF, "autogroup not supported");
+
+	SAFE_FILE_SCANF(PATH_AUTOGROUP, "%d", &orig_autogroup);
+}
+
+static void cleanup(void)
+{
+	if (orig_autogroup != -1)
+		SAFE_FILE_PRINTF(PATH_AUTOGROUP, "%d", orig_autogroup);
+}
+
+static struct tst_test test = {
+	.forks_child = 1,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = do_test,
+};
-- 
1.8.4.2




^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH 2/2] sched/autogroup01: Add new regression test
  2017-06-15  9:57 ` [LTP] [PATCH 2/2] sched/autogroup01: Add new regression test Guangwen Feng
@ 2017-06-15 14:31   ` Cyril Hrubis
  2017-06-16  1:43     ` [LTP] [PATCH v2] " Guangwen Feng
  0 siblings, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2017-06-15 14:31 UTC (permalink / raw)
  To: ltp

Hi!
> +static void do_test(void)
> +{
> +	int i;
> +
> +	if (!SAFE_FORK()) {
> +		SAFE_FILE_PRINTF(PATH_AUTOGROUP, "%d", 1);
> +		SAFE_SETSID();
> +
> +		if (SAFE_FORK()) {
> +			pause();
> +			exit(0);

                     Do we really reach this exit(0)?

		     We are sending SIGKILL to this process after all...

> +		}
> +
> +		SAFE_KILL(getppid(), SIGKILL);
> +		usleep(1000);
> +
> +		SAFE_FILE_PRINTF(PATH_AUTOGROUP, "%d", 0);
> +		SAFE_SETSID();
> +
> +		for (i = 0; i < LOOPS; i++)
> +			usleep(10);
> +
> +		TST_CHECKPOINT_WAKE(0);
> +
> +		exit(0);
> +	}
> +
> +	SAFE_WAIT(NULL);
> +
> +	TST_CHECKPOINT_WAIT(0);
> +
> +	tst_res(TPASS, "Bug not reproduced");
> +}

Otherwise it looks fine. We may as well include the comments that were
present in the original reproducer as that makes the code a bit easier
to understand.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v2] sched/autogroup01: Add new regression test
  2017-06-15 14:31   ` Cyril Hrubis
@ 2017-06-16  1:43     ` Guangwen Feng
  2017-06-19 17:45       ` Cyril Hrubis
  0 siblings, 1 reply; 5+ messages in thread
From: Guangwen Feng @ 2017-06-16  1:43 UTC (permalink / raw)
  To: ltp

Fixed by:
commit 18f649ef344127ef6de23a5a4272dbe2fdb73dde
Author: Oleg Nesterov <oleg@redhat.com>
Date:   Mon Nov 14 19:46:09 2016 +0100

  sched/autogroup: Fix autogroup_move_group() to never skip sched_move_task()

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 runtest/sched                                  |  2 +
 testcases/kernel/sched/autogroup/.gitignore    |  1 +
 testcases/kernel/sched/autogroup/Makefile      | 23 +++++++
 testcases/kernel/sched/autogroup/autogroup01.c | 95 ++++++++++++++++++++++++++
 4 files changed, 121 insertions(+)
 create mode 100644 testcases/kernel/sched/autogroup/.gitignore
 create mode 100644 testcases/kernel/sched/autogroup/Makefile
 create mode 100644 testcases/kernel/sched/autogroup/autogroup01.c

diff --git a/runtest/sched b/runtest/sched
index 89398df..774d11f 100644
--- a/runtest/sched
+++ b/runtest/sched
@@ -16,3 +16,5 @@ sched_getattr02 sched_getattr02
 sched_cli_serv run_sched_cliserv.sh
 # Run this stress test for 2 minutes
 sched_stress sched_stress.sh
+
+autogroup01 autogroup01
diff --git a/testcases/kernel/sched/autogroup/.gitignore b/testcases/kernel/sched/autogroup/.gitignore
new file mode 100644
index 0000000..bcc7453
--- /dev/null
+++ b/testcases/kernel/sched/autogroup/.gitignore
@@ -0,0 +1 @@
+/autogroup01
diff --git a/testcases/kernel/sched/autogroup/Makefile b/testcases/kernel/sched/autogroup/Makefile
new file mode 100644
index 0000000..6cc7782
--- /dev/null
+++ b/testcases/kernel/sched/autogroup/Makefile
@@ -0,0 +1,23 @@
+#
+#  Copyright (c) 2017 Fujitsu Ltd.
+#  Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
+#
+#  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, see <http://www.gnu.org/licenses/>.
+#
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/sched/autogroup/autogroup01.c b/testcases/kernel/sched/autogroup/autogroup01.c
new file mode 100644
index 0000000..9c4e911
--- /dev/null
+++ b/testcases/kernel/sched/autogroup/autogroup01.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2017 Fujitsu Ltd.
+ * Ported: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * This is a regression test about the race in autogroup, this test
+ * can crash the buggy kernel, and the bug has been fixed in:
+ *
+ *   commit 18f649ef344127ef6de23a5a4272dbe2fdb73dde
+ *   Author: Oleg Nesterov <oleg@redhat.com>
+ *   Date:   Mon Nov 14 19:46:09 2016 +0100
+ *
+ *   sched/autogroup: Fix autogroup_move_group() to never skip sched_move_task()
+ */
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "tst_test.h"
+
+#define LOOPS	1000
+#define PATH_AUTOGROUP	"/proc/sys/kernel/sched_autogroup_enabled"
+
+static int orig_autogroup = -1;
+
+static void do_test(void)
+{
+	int i;
+
+	if (!SAFE_FORK()) {
+		SAFE_FILE_PRINTF(PATH_AUTOGROUP, "%d", 1);
+		SAFE_SETSID();
+
+		if (SAFE_FORK())
+			pause();
+
+		SAFE_KILL(getppid(), SIGKILL);
+		usleep(1000);
+
+		// The child has gone, the grandchild runs with kref == 1
+		SAFE_FILE_PRINTF(PATH_AUTOGROUP, "%d", 0);
+		SAFE_SETSID();
+
+		// runs with the freed ag/tg
+		for (i = 0; i < LOOPS; i++)
+			usleep(10);
+
+		TST_CHECKPOINT_WAKE(0);
+
+		exit(0);
+	}
+
+	SAFE_WAIT(NULL); // destroy the child's ag/tg
+
+	TST_CHECKPOINT_WAIT(0);
+
+	tst_res(TPASS, "Bug not reproduced");
+}
+
+static void setup(void)
+{
+	if (access(PATH_AUTOGROUP, F_OK))
+		tst_brk(TCONF, "autogroup not supported");
+
+	SAFE_FILE_SCANF(PATH_AUTOGROUP, "%d", &orig_autogroup);
+}
+
+static void cleanup(void)
+{
+	if (orig_autogroup != -1)
+		SAFE_FILE_PRINTF(PATH_AUTOGROUP, "%d", orig_autogroup);
+}
+
+static struct tst_test test = {
+	.forks_child = 1,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = do_test,
+};
-- 
1.8.4.2




^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v2] sched/autogroup01: Add new regression test
  2017-06-16  1:43     ` [LTP] [PATCH v2] " Guangwen Feng
@ 2017-06-19 17:45       ` Cyril Hrubis
  0 siblings, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2017-06-19 17:45 UTC (permalink / raw)
  To: ltp

Hi!
Both patches pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-06-19 17:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-15  9:57 [LTP] [PATCH 1/2] SAFE_MACROS: Add SAFE_SETSID() Guangwen Feng
2017-06-15  9:57 ` [LTP] [PATCH 2/2] sched/autogroup01: Add new regression test Guangwen Feng
2017-06-15 14:31   ` Cyril Hrubis
2017-06-16  1:43     ` [LTP] [PATCH v2] " Guangwen Feng
2017-06-19 17:45       ` Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.