SAFE_MACROS: Add SAFE_UNAME()
PATCH 1/2 SAFE_MACROS: Add SAFE_UNAME()
--- include/tst_safe_macros.h | 4 ++++ lib/safe_macros.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+)
include/tst_safe_macros.h +4 -0
@@ -24,6 +24,7 @@#include <sys/time.h> #include <sys/resource.h> #include <sys/stat.h> +#include <sys/utsname.h> #include <fcntl.h> #include <libgen.h> #include <signal.h>
@@ -430,4 +431,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_uname (const char *file,const int lineno,struct utsname *buf); +#define SAFE_UNAME (buf) safe_uname(__FILE__, __LINE__, (buf)) +#endif /* SAFE_MACROS_H__ */
lib/safe_macros.c +15 -0
@@ -6,6 +6,7 @@#include <sys/wait.h> #include <sys/mount.h> #include <sys/xattr.h> +#include <sys/utsname.h> #include <errno.h> #include <fcntl.h> #include <libgen.h>
@@ -888,3 +889,17 @@ int safe_fsync(const char *file, const int lineno, int fd)return rval; } + +int safe_uname (const char *file,const int lineno,struct utsname *buf) +{ +int rval; + + rval =uname (buf); + +if (rval) { +tst_brkm (TBROK |TERRNO ,NULL , +"%s:%d: uname(%p) failed" , file, lineno, buf); + } + +return rval; +}
Signature · 1 line
1.8.4.2
PATCH 2/2 controllers/memcg_test_3: Add new regression test
This kernel bug is about RHEL6 BZ1168185 and has been fixed in:
[PATCH RHEL6] [mm] memcg: fix crash in re-entrant cgroup_clear_css_refs()
--- runtest/controllers | 1 + testcases/kernel/controllers/memcg/.gitignore | 1 + .../controllers/memcg/regression/memcg_test_3.c | 124 +++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 testcases/kernel/controllers/memcg/regression/memcg_test_3.c
runtest/controllers +1 -0
@@ -1,6 +1,7 @@ #DESCRIPTION:Resource Management testing cgroup cgroup_regression_test.sh memcg_regression memcg_regression_test.sh +memcg_test_3 memcg_test_3 memcg_failcnt memcg_failcnt.sh memcg_force_empty memcg_force_empty.sh memcg_limit_in_bytes memcg_limit_in_bytes.sh
testcases/kernel/controllers/memcg/.gitignore +1 -0
@@ -2,5 +2,6 @@ /functional/memcg_process /regression/memcg_test_1 /regression/memcg_test_2 +/regression/memcg_test_3 /regression/memcg_test_4 /stress/memcg_process_stress
testcases/kernel/controllers/memcg/regression/memcg_test_3.c new file +124 -0
124 lines not on this page · raw message
Signature · 1 line
1.8.4.2
PATCH 2/2 controllers/memcg_test_3: Add new regression test
Hi!
Sorry, there are some typos, I will resend the patch, please ignore this one.
Best Regards,
Guangwen Feng
Quoted 166 lines · Guangwen Feng
This kernel bug is about RHEL6 BZ1168185 and has been fixed in:
[PATCH RHEL6] [mm] memcg: fix crash in re-entrant
cgroup_clear_css_refs()Signed-off-by Guangwen Feng <[email protected]>--- runtest/controllers | 1 + testcases/kernel/controllers/memcg/.gitignore | 1 + .../controllers/memcg/regression/memcg_test_3.c | 124 +++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 testcases/kernel/controllers/memcg/regression/memcg_test_3.cruntest/controllers +1
-0@@ -1,6 +1,7 @@ #DESCRIPTION:Resource Management testing cgroup cgroup_regression_test.sh memcg_regression memcg_regression_test.sh +memcg_test_3 memcg_test_3 memcg_failcnt memcg_failcnt.sh memcg_force_empty memcg_force_empty.sh memcg_limit_in_bytes memcg_limit_in_bytes.shtestcases/kernel/controllers/memcg/.gitignore +1
-0@@ -2,5 +2,6 @@ /functional/memcg_process /regression/memcg_test_1 /regression/memcg_test_2 +/regression/memcg_test_3 /regression/memcg_test_4 /stress/memcg_process_stresstestcases/kernel/controllers/memcg/regression/memcg_test_3.c new file +124
-0@@ -0,0 +1,124 @@ +/* +* Copyright (c) 2017 Fujitsu Ltd. +* Author: Guangwen Feng <[email protected]> +* +* 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 for a crash caused by memcg function +* reentrant on RHEL6. When doing rmdir(), a pending signal can +* interrupt the execution and lead to cgroup_clear_css_refs() +* being entered repeatedly, this results in a BUG_ON(). +* +* This bug is introduced by following RHEL6 patch on 2.6.32-488.el6: +* +* [mm] memcg: fix race condition between memcg teardown and swapin +* Bugzilla: 1001197 +* +* This test can crash the buggy kernel on RHEL6.6GA, and the bug +* has been fixed by following patch on 2.6.32-536.el6: +* +* [mm] memcg: fix crash in re-entrant cgroup_clear_css_refs() +* Bugzilla: 1168185 +*/ + +#include <errno.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/wait.h> +#include "tst_test.h" + +#define MNTPOINT "memcg" +#define SUBDIR "memcg/testdir" + +static int mount_flag; + +static struct tst_kern_exv kvers[] = { + {"RHEL6" ,"2.6.32-488" }, + {NULL ,NULL } +}; + +static void sighandler(int sig LTP_ATTRIBUTE_UNUSED) +{ + +} + +static void do_child (void ) +{ +while (1 ) +SAFE_KILL (getppid (),SIGUSR1 ); + +exit (0 ); +} + +static void do_test (void ) +{ +int i; +pid_t cpid =-1 ; + +SAFE_SIGNAL (SIGUSR1 , sighandler); + + cpid =SAFE_FORK (); +if (cpid ==0 ) +do_child (); + +for (i =0 ; i <10 ; i++) { +if (access (SUBDIR ,F_OK )) +SAFE_MKDIR (SUBDIR ,0644 ); +rmdir (SUBDIR ); + } + +SAFE_KILL (cpid,SIGKILL ); +SAFE_WAIT (NULL ); + +tst_res (TPASS ,"Bug not reproduced" ); +} + +static void setup (void ) +{ +struct utsname buf; + +SAFE_UNAME (&buf); +if (!strstr (buf.release,".el6" )) +tst_brk (TCONF ,"This test can only run on RHEL6" ); + +if (tst_kvercmp2 (2 ,6 ,24 , kvers) <0 ) +tst_brk (TCONF ,"This test requires kernel >= 2.6.32-488.el6" ); + +SAFE_MKDIR (MNTPOINT ,0644 ); + +SAFE_MOUNT ("memcg" ,MNTPOINT ,"cgroup" ,0 ,"memory" ); + mount_flag =1 ; +} + +static void cleanup (void ) +{ +if (!access (SUBDIR ,F_OK )) +SAFE_RMDIR (SUBDIR ); + +if (mount_flag) +tst_umount (MNTPOINT ); +} + +static struct tst_test test = { + .tid ="memcg_test_3" , + .needs_root =1 , + .needs_tmpdir =1 , + .forks_child =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = do_test, +};
PATCH v2 2/2 controllers/memcg_test_3: Add new regression test
This kernel bug is about RHEL6 BZ1168185 and has been fixed in:
[PATCH RHEL6] [mm] memcg: fix crash in re-entrant cgroup_clear_css_refs()
--- runtest/controllers | 1 + testcases/kernel/controllers/memcg/.gitignore | 1 + .../controllers/memcg/regression/memcg_test_3.c | 124 +++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 testcases/kernel/controllers/memcg/regression/memcg_test_3.c
runtest/controllers +1 -0
@@ -1,6 +1,7 @@ #DESCRIPTION:Resource Management testing cgroup cgroup_regression_test.sh memcg_regression memcg_regression_test.sh +memcg_test_3 memcg_test_3 memcg_failcnt memcg_failcnt.sh memcg_force_empty memcg_force_empty.sh memcg_limit_in_bytes memcg_limit_in_bytes.sh
testcases/kernel/controllers/memcg/.gitignore +1 -0
@@ -2,5 +2,6 @@ /functional/memcg_process /regression/memcg_test_1 /regression/memcg_test_2 +/regression/memcg_test_3 /regression/memcg_test_4 /stress/memcg_process_stress
testcases/kernel/controllers/memcg/regression/memcg_test_3.c new file +124 -0
124 lines not on this page · raw message
Signature · 1 line
1.8.4.2
PATCH v2 2/2 controllers/memcg_test_3: Add new regression test
Hi!
Quoted 10 lines
+/*
+ * This is a regression test for a crash caused by memcg function
+ * reentrant on RHEL6. When doingrmdir(), a pending signal can
+ * interrupt the execution and lead tocgroup_clear_css_refs()
+ * being entered repeatedly, this results in aBUG_ON().
+ *
+ * This bug was introduced by following RHEL6 patch on 2.6.32-488.el6:
+ *
+ * [mm] memcg: fix race condition between memcg teardown and swapin
+ * Bugzilla: 1001197
Can you rather add a link here instead? Just "Bugzilla:" is too vague.
Quoted 37 lines
+ * This test can crash the buggy kernel on RHEL6.6GA, and the bug
+ * was fixed by following patch on 2.6.32-536.el6:
+ *
+ * [mm] memcg: fix crash in re-entrantcgroup_clear_css_refs()
+ * Bugzilla: 1168185
+ */testcases/kernel/controllers/memcg/regression/memcg_test_3.c new file +31
-0+ +#include <errno.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/wait.h> +#include "tst_test.h" + +#define MNTPOINT "memcg" +#define SUBDIR "memcg/testdir" + +static int mount_flag; + +static struct tst_kern_exv kvers[] = { + {"RHEL6" ,"2.6.32-488" }, + {NULL ,NULL } +}; + +static void sighandler(int sig LTP_ATTRIBUTE_UNUSED) +{ + +} + +static void do_child (void ) +{ +while (1 ) +SAFE_KILL (getppid (),SIGUSR1 ); + +exit (0 ); +} +
testcases/kernel/controllers/memcg/regression/memcg_test_3.c line 76
Quoted 10 lines
testcases/kernel/controllers/memcg/regression/memcg_test_3.c new file +10
-0+static void do_test (void ) +{ +int i; +pid_t cpid =-1 ; + +SAFE_SIGNAL (SIGUSR1 , sighandler); + + cpid =SAFE_FORK (); +if (cpid ==0 ) +do_child ();
Shouldn't we wait here untill the child is actually running?
I think that with just 10 iteration in the code below we may as well finish the loop too fast.
So what about incrementing a counter in the signal handler and loop until it reaches some small value (50 or something)?
Quoted 12 lines
testcases/kernel/controllers/memcg/regression/memcg_test_3.c new file +12
-0+for (i =0 ; i <10 ; i++) { +if (access (SUBDIR ,F_OK )) +SAFE_MKDIR (SUBDIR ,0644 ); +rmdir (SUBDIR ); + } + +SAFE_KILL (cpid,SIGKILL ); +SAFE_WAIT (NULL ); + +tst_res (TPASS ,"Bug not reproduced" ); +} +
testcases/kernel/controllers/memcg/regression/memcg_test_3.c line 99
Quoted 10 lines
testcases/kernel/controllers/memcg/regression/memcg_test_3.c new file +10
-0+static void setup (void ) +{ +struct utsname buf; + +SAFE_UNAME (&buf); +if (!strstr (buf.release,".el6" )) +tst_brk (TCONF ,"This test can only run on RHEL6" ); + +if (tst_kvercmp2 (2 ,6 ,24 , kvers) <0 ) +tst_brk (TCONF ,"This test requires kernel >= 2.6.32-488.el6" );
Why do we skip this test on anything but RHEL6? It does not seem to me that the test actually does something that couldn't be tested on any other Linux distribution. We only have to check for memcg support here instead.
Quoted 32 lines
testcases/kernel/controllers/memcg/regression/memcg_test_3.c new file +24
-0+SAFE_MKDIR (MNTPOINT ,0644 ); + +SAFE_MOUNT ("memcg" ,MNTPOINT ,"cgroup" ,0 ,"memory" ); + mount_flag =1 ; +} + +static void cleanup (void ) +{ +if (!access (SUBDIR ,F_OK )) +SAFE_RMDIR (SUBDIR ); + +if (mount_flag) +tst_umount (MNTPOINT ); +} + +static struct tst_test test = { + .tid ="memcg_test_3" , + .needs_root =1 , + .needs_tmpdir =1 , + .forks_child =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = do_test, +};Signature · 7 lines
1.8.4.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 2/2 controllers/memcg_test_3: Add new regression test
Hi!
Thanks for your review, and sorry for the late reply.
Quoted 12 lines · Cyril Hrubis
Hi!
Quoted 10 lines
+/*
+ * This is a regression test for a crash caused by memcg function
+ * reentrant on RHEL6. When doingrmdir(), a pending signal can
+ * interrupt the execution and lead tocgroup_clear_css_refs()
+ * being entered repeatedly, this results in aBUG_ON().
+ *
+ * This bug was introduced by following RHEL6 patch on 2.6.32-488.el6:
+ *
+ * [mm] memcg: fix race condition between memcg teardown and swapin
+ * Bugzilla: 1001197
Quoted 2 lines
Can you rather add a link here instead? Just "Bugzilla:" is too vague.
OK, I will add a Bugzilla link instead, and add the patch url of ftp as well.
Quoted 50 lines
Quoted 37 lines
+ * This test can crash the buggy kernel on RHEL6.6GA, and the bug
+ * was fixed by following patch on 2.6.32-536.el6:
+ *
+ * [mm] memcg: fix crash in re-entrantcgroup_clear_css_refs()
+ * Bugzilla: 1168185
+ */testcases/kernel/controllers/memcg/regression/memcg_test_3.c new file +31
-0+ +#include <errno.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/wait.h> +#include "tst_test.h" + +#define MNTPOINT "memcg" +#define SUBDIR "memcg/testdir" + +static int mount_flag; + +static struct tst_kern_exv kvers[] = { + {"RHEL6" ,"2.6.32-488" }, + {NULL ,NULL } +}; + +static void sighandler(int sig LTP_ATTRIBUTE_UNUSED) +{ + +} + +static void do_child (void ) +{ +while (1 ) +SAFE_KILL (getppid (),SIGUSR1 ); + +exit (0 ); +} +testcases/kernel/controllers/memcg/regression/memcg_test_3.c line 76
Quoted 10 lines
testcases/kernel/controllers/memcg/regression/memcg_test_3.c new file +10
-0+static void do_test (void ) +{ +int i; +pid_t cpid =-1 ; + +SAFE_SIGNAL (SIGUSR1 , sighandler); + + cpid =SAFE_FORK (); +if (cpid ==0 ) +do_child ();Shouldn't we wait here untill the child is actually running?
Quoted 6 lines
I think that with just 10 iteration in the code below we may as well finish the loop too fast.
So what about incrementing a counter in the signal handler and loop until it reaches some small value (50 or something)?
Yes, we need to ensure the synchronization.
It is a good idea to use a counter in signal handler, but 50 or hundreds is too small, since I tested and found that the signal is triggered way much faster than the loop in parent.
I have tested that the value can be set to 50000, which makes sure 100% reproducible in buggy kernel and that the test can be done within 1 second when there is no bug.
Quoted 19 lines
Quoted 19 lines
testcases/kernel/controllers/memcg/regression/memcg_test_3.c new file +19
-0+for (i =0 ; i <10 ; i++) { +if (access (SUBDIR ,F_OK )) +SAFE_MKDIR (SUBDIR ,0644 ); +rmdir (SUBDIR ); + } + +SAFE_KILL (cpid,SIGKILL ); +SAFE_WAIT (NULL ); + +tst_res (TPASS ,"Bug not reproduced" ); +} + +static void setup (void ) +{ +struct utsname buf; + +SAFE_UNAME (&buf); +if (!strstr (buf.release,".el6" )) +tst_brk (TCONF ,"This test can only run on RHEL6" );
Quoted 9 lines
testcases/kernel/controllers/memcg/regression/memcg_test_3.c line 99
Quoted 3 lines
testcases/kernel/controllers/memcg/regression/memcg_test_3.c new file +3
-0+ +if (tst_kvercmp2 (2 ,6 ,24 , kvers) <0 ) +tst_brk (TCONF ,"This test requires kernel >= 2.6.32-488.el6" );Why do we skip this test on anything but RHEL6? It does not seem to me that the test actually does something that couldn't be tested on any other Linux distribution. We only have to check for memcg support here instead.
OK, I got it.
Best Regards,
Guangwen Feng
Quoted 33 lines
Quoted 32 lines
testcases/kernel/controllers/memcg/regression/memcg_test_3.c new file +24
-0+SAFE_MKDIR (MNTPOINT ,0644 ); + +SAFE_MOUNT ("memcg" ,MNTPOINT ,"cgroup" ,0 ,"memory" ); + mount_flag =1 ; +} + +static void cleanup (void ) +{ +if (!access (SUBDIR ,F_OK )) +SAFE_RMDIR (SUBDIR ); + +if (mount_flag) +tst_umount (MNTPOINT ); +} + +static struct tst_test test = { + .tid ="memcg_test_3" , + .needs_root =1 , + .needs_tmpdir =1 , + .forks_child =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = do_test, +};Signature · 7 lines
1.8.4.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/1 controllers/memcg_test_3: Add new regression test
This kernel bug is about RHEL6 BZ1168185 and has been fixed in:
[PATCH RHEL6] [mm] memcg: fix crash in re-entrant cgroup_clear_css_refs()
Patch: ftp://partners.redhat.com/1c5d859a/de6aafa8185ed8fd934f2debc72b79eb/kernel-individual-patch/rhel6/v2.6.32-to-kernel-2.6.32-536.el6.tar.bz2
35944-mm-memcg-fix-crash-in-re-entrant-cgroup_clear_css_r.patch
--- runtest/controllers | 1 + testcases/kernel/controllers/memcg/.gitignore | 1 + .../controllers/memcg/regression/memcg_test_3.c | 117 +++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 testcases/kernel/controllers/memcg/regression/memcg_test_3.c
runtest/controllers +1 -0
@@ -1,6 +1,7 @@ #DESCRIPTION:Resource Management testing cgroup cgroup_regression_test.sh memcg_regression memcg_regression_test.sh +memcg_test_3 memcg_test_3 memcg_failcnt memcg_failcnt.sh memcg_force_empty memcg_force_empty.sh memcg_limit_in_bytes memcg_limit_in_bytes.sh
testcases/kernel/controllers/memcg/.gitignore +1 -0
@@ -2,5 +2,6 @@ /functional/memcg_process /regression/memcg_test_1 /regression/memcg_test_2 +/regression/memcg_test_3 /regression/memcg_test_4 /stress/memcg_process_stress
testcases/kernel/controllers/memcg/regression/memcg_test_3.c new file +117 -0
117 lines not on this page · raw message
Signature · 1 line
1.8.4.2
PATCH v3 1/1 controllers/memcg_test_3: Add new regression test
Hi!
I just remembered that if we only check for memcg support, we should use the min_kver in tst_test struct instead of tst_kvercmp(), sorry, please ignore this one, I will send a v4.
Best Regards,
Guangwen Feng
Quoted 163 lines · Guangwen Feng
This kernel bug is about RHEL6 BZ1168185 and has been fixed in:
[PATCH RHEL6] [mm] memcg: fix crash in re-entrant
cgroup_clear_css_refs()Patch: ftp://partners.redhat.com/1c5d859a/de6aafa8185ed8fd934f2debc72b79eb/kernel-individual-patch/rhel6/v2.6.32-to-kernel-2.6.32-536.el6.tar.bz2
35944-mm-memcg-fix-crash-in-re-entrant-cgroup_clear_css_r.patchSigned-off-by Guangwen Feng <[email protected]>--- runtest/controllers | 1 + testcases/kernel/controllers/memcg/.gitignore | 1 + .../controllers/memcg/regression/memcg_test_3.c | 117 +++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 testcases/kernel/controllers/memcg/regression/memcg_test_3.cruntest/controllers +1
-0@@ -1,6 +1,7 @@ #DESCRIPTION:Resource Management testing cgroup cgroup_regression_test.sh memcg_regression memcg_regression_test.sh +memcg_test_3 memcg_test_3 memcg_failcnt memcg_failcnt.sh memcg_force_empty memcg_force_empty.sh memcg_limit_in_bytes memcg_limit_in_bytes.shtestcases/kernel/controllers/memcg/.gitignore +1
-0@@ -2,5 +2,6 @@ /functional/memcg_process /regression/memcg_test_1 /regression/memcg_test_2 +/regression/memcg_test_3 /regression/memcg_test_4 /stress/memcg_process_stresstestcases/kernel/controllers/memcg/regression/memcg_test_3.c new file +117
-0@@ -0,0 +1,117 @@ +/* +* Copyright (c) 2017 Fujitsu Ltd. +* Author: Guangwen Feng <[email protected]> +* +* 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 for a crash caused by memcg function +* reentrant on RHEL6. When doing rmdir(), a pending signal can +* interrupt the execution and lead to cgroup_clear_css_refs() +* being entered repeatedly, this results in a BUG_ON(). +* +* This bug was introduced by following RHEL6 patch on 2.6.32-488.el6: +* +* [mm] memcg: fix race condition between memcg teardown and swapin +* Link: https://bugzilla.redhat.com/show_bug.cgi?id=1001197 +* Patch: ftp://partners.redhat.com/1c5d859a/de6aafa8185ed8fd934f2debc72b79eb/kernel-individual-patch/rhel6/v2.6.32-to-kernel-2.6.32-488.el6.tar.bz2 +* 31675-mm-memcg-fix-race-condition-between-memcg-teardown-.patch +* +* This test can crash the buggy kernel on RHEL6.6GA, and the bug +* was fixed by following patch on 2.6.32-536.el6: +* +* [mm] memcg: fix crash in re-entrant cgroup_clear_css_refs() +* Link: https://bugzilla.redhat.com/show_bug.cgi?id=1168185 +* Patch: ftp://partners.redhat.com/1c5d859a/de6aafa8185ed8fd934f2debc72b79eb/kernel-individual-patch/rhel6/v2.6.32-to-kernel-2.6.32-536.el6.tar.bz2 +* 35944-mm-memcg-fix-crash-in-re-entrant-cgroup_clear_css_r.patch +*/ + +#include <errno.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/types.h> +#include "tst_test.h" + +#define MNTPOINT "memcg" +#define SUBDIR "memcg/testdir" + +static int mount_flag; +static volatile int sigcounter; + +static void sighandler(int sig LTP_ATTRIBUTE_UNUSED) +{ + sigcounter++; +} + +static void do_child (void ) +{ +while (1 ) +SAFE_KILL (getppid (),SIGUSR1 ); + +exit (0 ); +} + +static void do_test (void ) +{ +pid_t cpid =-1 ; + +SAFE_SIGNAL (SIGUSR1 , sighandler); + + cpid =SAFE_FORK (); +if (cpid ==0 ) +do_child (); + +while (sigcounter <50000 ) { +if (access (SUBDIR ,F_OK )) +SAFE_MKDIR (SUBDIR ,0644 ); +rmdir (SUBDIR ); + } + +SAFE_KILL (cpid,SIGKILL ); +SAFE_WAIT (NULL ); + +tst_res (TPASS ,"Bug not reproduced" ); +} + +static void setup (void ) +{ +if (tst_kvercmp (2 ,6 ,24 ) <0 ) +tst_brk (TCONF ,"This test can only run on kernels " +"that are 2.6.24 or higher" ); + +SAFE_MKDIR (MNTPOINT ,0644 ); + +SAFE_MOUNT ("memcg" ,MNTPOINT ,"cgroup" ,0 ,"memory" ); + mount_flag =1 ; +} + +static void cleanup (void ) +{ +if (!access (SUBDIR ,F_OK )) +SAFE_RMDIR (SUBDIR ); + +if (mount_flag) +tst_umount (MNTPOINT ); +} + +static struct tst_test test = { + .tid ="memcg_test_3" , + .needs_root =1 , + .needs_tmpdir =1 , + .forks_child =1 , + .setup = setup, + .cleanup = cleanup, + .test_all = do_test, +};
PATCH v4 1/1 controllers/memcg_test_3: Add new regression test
This kernel bug is about RHEL6 BZ1168185 and has been fixed in:
[PATCH RHEL6] [mm] memcg: fix crash in re-entrant cgroup_clear_css_refs()
Patch: ftp://partners.redhat.com/1c5d859a/de6aafa8185ed8fd934f2debc72b79eb/kernel-individual-patch/rhel6/v2.6.32-to-kernel-2.6.32-536.el6.tar.bz2
35944-mm-memcg-fix-crash-in-re-entrant-cgroup_clear_css_r.patch
--- runtest/controllers | 1 + testcases/kernel/controllers/memcg/.gitignore | 1 + .../controllers/memcg/regression/memcg_test_3.c | 114 +++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 testcases/kernel/controllers/memcg/regression/memcg_test_3.c
runtest/controllers +1 -0
@@ -1,6 +1,7 @@ #DESCRIPTION:Resource Management testing cgroup cgroup_regression_test.sh memcg_regression memcg_regression_test.sh +memcg_test_3 memcg_test_3 memcg_failcnt memcg_failcnt.sh memcg_force_empty memcg_force_empty.sh memcg_limit_in_bytes memcg_limit_in_bytes.sh
testcases/kernel/controllers/memcg/.gitignore +1 -0
@@ -2,5 +2,6 @@ /functional/memcg_process /regression/memcg_test_1 /regression/memcg_test_2 +/regression/memcg_test_3 /regression/memcg_test_4 /stress/memcg_process_stress
testcases/kernel/controllers/memcg/regression/memcg_test_3.c new file +114 -0
114 lines not on this page · raw message
Signature · 1 line
1.8.4.2
PATCH v4 1/1 controllers/memcg_test_3: Add new regression test
Hi!
Ping, thanks!
Best Regards,
Guangwen Feng
Quoted 160 lines · Guangwen Feng
This kernel bug is about RHEL6 BZ1168185 and has been fixed in:
[PATCH RHEL6] [mm] memcg: fix crash in re-entrant
cgroup_clear_css_refs()Patch: ftp://partners.redhat.com/1c5d859a/de6aafa8185ed8fd934f2debc72b79eb/kernel-individual-patch/rhel6/v2.6.32-to-kernel-2.6.32-536.el6.tar.bz2
35944-mm-memcg-fix-crash-in-re-entrant-cgroup_clear_css_r.patchSigned-off-by Guangwen Feng <[email protected]>--- runtest/controllers | 1 + testcases/kernel/controllers/memcg/.gitignore | 1 + .../controllers/memcg/regression/memcg_test_3.c | 114 +++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 testcases/kernel/controllers/memcg/regression/memcg_test_3.cruntest/controllers +1
-0@@ -1,6 +1,7 @@ #DESCRIPTION:Resource Management testing cgroup cgroup_regression_test.sh memcg_regression memcg_regression_test.sh +memcg_test_3 memcg_test_3 memcg_failcnt memcg_failcnt.sh memcg_force_empty memcg_force_empty.sh memcg_limit_in_bytes memcg_limit_in_bytes.shtestcases/kernel/controllers/memcg/.gitignore +1
-0@@ -2,5 +2,6 @@ /functional/memcg_process /regression/memcg_test_1 /regression/memcg_test_2 +/regression/memcg_test_3 /regression/memcg_test_4 /stress/memcg_process_stresstestcases/kernel/controllers/memcg/regression/memcg_test_3.c new file +114
-0@@ -0,0 +1,114 @@ +/* +* Copyright (c) 2017 Fujitsu Ltd. +* Author: Guangwen Feng <[email protected]> +* +* 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 for a crash caused by memcg function +* reentrant on RHEL6. When doing rmdir(), a pending signal can +* interrupt the execution and lead to cgroup_clear_css_refs() +* being entered repeatedly, this results in a BUG_ON(). +* +* This bug was introduced by following RHEL6 patch on 2.6.32-488.el6: +* +* [mm] memcg: fix race condition between memcg teardown and swapin +* Link: https://bugzilla.redhat.com/show_bug.cgi?id=1001197 +* Patch: ftp://partners.redhat.com/1c5d859a/de6aafa8185ed8fd934f2debc72b79eb/kernel-individual-patch/rhel6/v2.6.32-to-kernel-2.6.32-488.el6.tar.bz2 +* 31675-mm-memcg-fix-race-condition-between-memcg-teardown-.patch +* +* This test can crash the buggy kernel on RHEL6.6GA, and the bug +* was fixed by following patch on 2.6.32-536.el6: +* +* [mm] memcg: fix crash in re-entrant cgroup_clear_css_refs() +* Link: https://bugzilla.redhat.com/show_bug.cgi?id=1168185 +* Patch: ftp://partners.redhat.com/1c5d859a/de6aafa8185ed8fd934f2debc72b79eb/kernel-individual-patch/rhel6/v2.6.32-to-kernel-2.6.32-536.el6.tar.bz2 +* 35944-mm-memcg-fix-crash-in-re-entrant-cgroup_clear_css_r.patch +*/ + +#include <errno.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/types.h> +#include "tst_test.h" + +#define MNTPOINT "memcg" +#define SUBDIR "memcg/testdir" + +static int mount_flag; +static volatile int sigcounter; + +static void sighandler(int sig LTP_ATTRIBUTE_UNUSED) +{ + sigcounter++; +} + +static void do_child (void ) +{ +while (1 ) +SAFE_KILL (getppid (),SIGUSR1 ); + +exit (0 ); +} + +static void do_test (void ) +{ +pid_t cpid =-1 ; + +SAFE_SIGNAL (SIGUSR1 , sighandler); + + cpid =SAFE_FORK (); +if (cpid ==0 ) +do_child (); + +while (sigcounter <50000 ) { +if (access (SUBDIR ,F_OK )) +SAFE_MKDIR (SUBDIR ,0644 ); +rmdir (SUBDIR ); + } + +SAFE_KILL (cpid,SIGKILL ); +SAFE_WAIT (NULL ); + +tst_res (TPASS ,"Bug not reproduced" ); +} + +static void setup (void ) +{ +SAFE_MKDIR (MNTPOINT ,0644 ); + +SAFE_MOUNT ("memcg" ,MNTPOINT ,"cgroup" ,0 ,"memory" ); + mount_flag =1 ; +} + +static void cleanup (void ) +{ +if (!access (SUBDIR ,F_OK )) +SAFE_RMDIR (SUBDIR ); + +if (mount_flag) +tst_umount (MNTPOINT ); +} + +static struct tst_test test = { + .tid ="memcg_test_3" , + .needs_root =1 , + .needs_tmpdir =1 , + .forks_child =1 , + .min_kver ="2.6.24" , + .setup = setup, + .cleanup = cleanup, + .test_all = do_test, +};
PATCH v4 1/1 controllers/memcg_test_3: Add new regression test
In reply to Guangwen FengHi!
I've changed the setup to produce TCONF if mount returns with ENOENT (which means that cgroup support is not compiled in kenrnel) and pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 1/1 controllers/memcg_test_3: Add new regression test
Hi!
Quoted 3 lines · Cyril Hrubis
Hi!
I've changed the setup to produce TCONF if mount returns with ENOENT (which means that cgroup support is not compiled in kenrnel) and pushed,
Ah, I forgot this!
Thanks very much for the review!
Best Regards,
Guangwen Feng
Quoted 2 lines
thanks.