Skip to contentSkip to conversation

Collection of fixes

PATCH Superseded Punit Agrawal 2 participants 33 messages Oct 26, 2017 – Nov 14, 2017

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Collection of fixes

Hi,

This series collects fixes for issues encountered when running ltp on internal test platforms. The fixes touch a variety of tests - I've grouped patches touching related tests togther.

The patches fix issue with missing kernel feature detection, improper synchronisation in certain scenarios, and executing on systems with minimal userspace such as busybox.

Although the problems were encountered on internal platforms the patches improve the robustness of the tests and are applicable in wide ranging test scenarios.

Please consider merging them.

Thanks,
Punit

James Morse (2):
hotplug/cpu_hotplug: Repopulate cgroup:cpusets after testing hotplug hotplug/cpu_hotplug: Remove bashism disown from kill_pid()

Lorenzo Pieralisi (1):
hugeshmget02: add missing SHM_HUGETLB flag on segment creation

Mark Rutland (2):
inotify: fix inotify.h breakage
ioctl: fix stty usage for busybox

Punit Agrawal (1):
Move check_hugepage() helper to mem/lib

Suzuki K. Poulose (5):
hugeshmctl01: Fix synchronisation with child processes
hugeshmctl01: Fix synchronization issue in parent process
hugeshmctl02: Fix allocation size for odd number of hugepages
getdtablesize01: Handle ENFILE errno
perf_event_open: Handle absence of PMU gracefully

Will Deacon (7):
thp: ensure THP/hugetlbfs is available
vma03: accept ENOMEM return value from mremap
creat08: ensure test directories are created in /tmp/
kill05: fix race on getpwnam
sigwaitinfo01: fix race between sending and dequeueing RT signals
sigwaitinfo: catch SEGV and report success for bad_address2 testcase syscalls/mount03: Copy setuid_test to execute instead of 'TEST FILE'

 .../cpu_hotplug/include/cpuhotplug_hotplug.sh      | 36 ++++++++++++
 .../cpu_hotplug/include/cpuhotplug_testsuite.sh    |  1 -
 .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c   | 64 ++++++++--------------
 .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c   |  2 +-
 .../kernel/mem/hugetlb/hugeshmget/hugeshmget02.c   |  3 +-
 testcases/kernel/mem/hugetlb/lib/hugetlb.c         |  6 --
 testcases/kernel/mem/hugetlb/lib/hugetlb.h         |  1 -
 testcases/kernel/mem/include/mem.h                 |  2 +
 testcases/kernel/mem/lib/mem.c                     |  6 ++
 testcases/kernel/mem/thp/thp01.c                   |  3 +
 testcases/kernel/mem/thp/thp02.c                   |  2 +
 testcases/kernel/mem/thp/thp03.c                   |  2 +
 testcases/kernel/mem/vma/vma03.c                   |  2 +-
 testcases/kernel/syscalls/creat/creat08.c          |  4 +-
 .../syscalls/getdtablesize/getdtablesize01.c       | 17 +++---
 testcases/kernel/syscalls/inotify/inotify.h        |  8 +--
 testcases/kernel/syscalls/ioctl/test_ioctl         |  2 +-
 testcases/kernel/syscalls/kill/kill05.c            |  7 ++-
 testcases/kernel/syscalls/mount/mount03.c          |  4 +-
 .../syscalls/perf_event_open/perf_event_open01.c   |  3 +-
 .../syscalls/perf_event_open/perf_event_open02.c   |  4 +-
 .../kernel/syscalls/sigwaitinfo/sigwaitinfo01.c    | 36 +++++++++++-
 22 files changed, 141 insertions(+), 74 deletions(-)
Signature · 1 line
2.14.2
#1 lore raw

PATCH 1/18 Move check_hugepage() helper to mem/lib

Move the check_hugepage() helper to mem/lib to be more widely available to testcases. Specifically, it will be used in a subsequent commit to check for the presence of hugepage support when running the thp tests.

---
 testcases/kernel/mem/hugetlb/lib/hugetlb.c | 6 ------
 testcases/kernel/mem/hugetlb/lib/hugetlb.h | 1 -
 testcases/kernel/mem/include/mem.h         | 2 ++
 testcases/kernel/mem/lib/mem.c             | 6 ++++++
 4 files changed, 8 insertions(+), 7 deletions(-)
testcases/kernel/mem/hugetlb/lib/hugetlb.c +0 -6
index 7afc7d4b4..2f86e3558 100644
@@ -40,12 +40,6 @@
 #include <pwd.h>
 #include "hugetlb.h"
 
-void check_hugepage(void)
-{
-	if (access(PATH_HUGEPAGES, F_OK))
-		tst_brk(TCONF, "Huge page is not supported.");
-}
-
 /*
  * getipckey() - generates and returns a message key used by the "get"
  *		 calls to create an IPC resource.
testcases/kernel/mem/hugetlb/lib/hugetlb.h +0 -1
index c6d2016b7..f4a1a75d7 100644
@@ -45,7 +45,6 @@
  * from shmid_ds.ipc_perm.mode
  */
 #define MODE_MASK	0x01FF
-#define PATH_HUGEPAGES	"/sys/kernel/mm/hugepages/"
 
 key_t shmkey;			/* an IPC key generated by ftok() */
 
testcases/kernel/mem/include/mem.h +2 -0
index 287f8b3f6..95d0bda72 100644
@@ -56,8 +56,10 @@ void test_ksm_merge_across_nodes(unsigned long nr_pages);
 
 /* HUGETLB */
 
+#define PATH_HUGEPAGES		"/sys/kernel/mm/hugepages/"
 #define PATH_SHMMAX		"/proc/sys/kernel/shmmax"
 
+void check_hugepage(void);
 void write_memcg(void);
 
 /* cpuset/memcg */
testcases/kernel/mem/lib/mem.c +6 -0
index dd82b08d2..9ac3160ac 100644
@@ -346,6 +346,12 @@ static void verify(char **memory, char value, int proc,
 	free(s);
 }
 
+void check_hugepage(void)
+{
+	if (access(PATH_HUGEPAGES, F_OK))
+		tst_brk(TCONF, "Huge page is not supported.");
+}
+
 void write_memcg(void)
 {
 	SAFE_FILE_PRINTF(MEMCG_LIMIT, "%ld", TESTMEM);
Signature · 1 line
2.14.2
#2 lore raw

PATCH 1/18 Move check_hugepage() helper to mem/lib

Hi!

testcases/kernel/mem/hugetlb/lib/hugetlb.h line 49

Quoted 11 lines
testcases/kernel/mem/hugetlb/lib/hugetlb.h +0 -1
index c6d2016b7..f4a1a75d7 100644
@@ -45,7 +45,6 @@
  * from shmid_ds.ipc_perm.mode
  */
 #define MODE_MASK	0x01FF
-#define PATH_HUGEPAGES	"/sys/kernel/mm/hugepages/"
 
 key_t shmkey;			/* an IPC key generated by ftok() */

We should remove the check_hugepage() prototype from this header as well, otherwise it's fine.

Signature · 2 lines
Cyril Hrubis
[email protected]
#3 lore raw

PATCH 1/18 Move check_hugepage() helper to mem/lib

Hi Cyril,

Quoted 11 lines · Cyril Hrubis

Hi!

Quoted 10 lines
testcases/kernel/mem/hugetlb/lib/hugetlb.h +0 -1
index c6d2016b7..f4a1a75d7 100644
@@ -45,7 +45,6 @@
  * from shmid_ds.ipc_perm.mode
  */
 #define MODE_MASK	0x01FF
-#define PATH_HUGEPAGES	"/sys/kernel/mm/hugepages/"
 
Quoted 4 lines

testcases/kernel/mem/hugetlb/lib/hugetlb.h line 49

Quoted 1 line
testcases/kernel/mem/hugetlb/lib/hugetlb.h +0 -0
 key_t shmkey;			/* an IPC key generated by ftok() */

We should remove the check_hugepage() prototype from this header as well, otherwise it's fine.

Fixed locally.

Thanks for reviewing the patches (hopefully you can reach the end of the series :) ). Some of your suggestions are straight forward but others will take some time.

I am about to disappear for a few days and will aim to act on your suggestions once I'm back.

Thanks,
Punit

#4 lore raw

PATCH 2/18 thp: ensure THP/hugetlbfs is available

In reply to Punit Agrawal

From: Will Deacon <[email protected]>

The THP tests can't pass if THP is unavailable or disabled. Add the missing detection to thp01.c.

Also add tests for the presence of hugetlbfs for tests relying on this kernel feature.

---
 testcases/kernel/mem/thp/thp01.c | 3 +++
 testcases/kernel/mem/thp/thp02.c | 2 ++
 testcases/kernel/mem/thp/thp03.c | 2 ++
 3 files changed, 7 insertions(+)
testcases/kernel/mem/thp/thp01.c +3 -0
index 2f2bb2bdb..939c01b98 100644
@@ -116,6 +116,9 @@ static void setup(void)
 	int i;
 	long arg_len, arg_count;
 
+	if (access(PATH_THP, F_OK) == -1)
+		tst_brk(TCONF, "THP not enabled in kernel?");
+
 	bst = SAFE_MMAP(NULL, sizeof(*bst),
 			   PROT_READ | PROT_WRITE,
 			   MAP_SHARED | MAP_ANONYMOUS, -1, 0);
testcases/kernel/mem/thp/thp02.c +2 -0
index acc70e215..6502210e5 100644
@@ -90,6 +90,8 @@ static void setup(void)
 	if (access(PATH_THP, F_OK) == -1)
 		tst_brk(TCONF, "THP not enabled in kernel?");
 
+	check_hugepage();
+
 	ps = sysconf(_SC_PAGESIZE);
 	hps = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 	size = hps * 4;
testcases/kernel/mem/thp/thp03.c +2 -0
index 19db44944..c6062505f 100644
@@ -82,6 +82,8 @@ static void setup(void)
 	if (access(PATH_THP, F_OK) == -1)
 		tst_brk(TCONF, "THP not enabled in kernel?");
 
+	check_hugepage();
+
 	hugepage_size = SAFE_READ_MEMINFO("Hugepagesize:") * KB;
 	unaligned_size = hugepage_size * 4 - 1;
 	page_size = SAFE_SYSCONF(_SC_PAGESIZE);
Signature · 1 line
2.14.2
#5 lore raw

PATCH 3/18 hugeshmctl01: Fix synchronisation with child processes

In reply to Punit Agrawal

From: "Suzuki K. Poulose" <[email protected]>

hugeshmctl01 spawns child processes to perform shm operations and uses signal (SIGUSR1) to communicate the completion of test 1, to the children waiting at sigprocmask(). However, there is no guarantee that a child has reached sigprocmask() before the parent issues a SIGUSR1 and things go wrong.

This patch fixes this issue by 'stopping' the children, waiting for all of them and then issuing SIGCONT to communicate the completion.

While we are at it, also handle unknown signals as a hint to exit the test with TBROK.

---
 .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c   | 56 +++++++---------------
 1 file changed, 16 insertions(+), 40 deletions(-)
testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c +16 -40
index ad7a80d70..37a8a0d6f 100644
@@ -141,6 +141,7 @@ void *set_shmat(void)
  */
 static void stat_setup(void)
 {
+	int status;
 	int i, rval;
 	void *test;
 	pid_t pid;
@@ -150,10 +151,10 @@ static void stat_setup(void)
 	memset (&sa, '\0', sizeof(sa));
 	sa.sa_handler = sighandler;
 	sa.sa_flags = 0;
-	TEST(sigaction(SIGUSR1, &sa, NULL));
+	TEST(sigaction(SIGCONT, &sa, NULL));
 	if (TEST_RETURN == -1)
 		tst_brk(TBROK | TRERRNO,
-				"SIGSEGV signal setup failed");
+				"SIGCONT signal setup failed");
 	/*
 	 * The first time through, let the children attach the memory.
 	 * The second time through, attach the memory first and let
@@ -168,21 +169,6 @@ static void stat_setup(void)
 		set_shared = set_shmat();
 	}
 
-	/*
-	 * Block SIGUSR1 before children pause for a signal
-	 * Doing so to avoid the risk that the parent cleans up
-	 * children by calling stat_cleanup() before children call
-	 * call pause() so that children sleep forever(this is a
-	 * side effect of the arbitrary usleep time below).
-	 * In FIRST, children call shmat. If children sleep forever,
-	 * those attached shm can't be released so some other shm
-	 * tests will fail a lot.
-	 */
-	sigemptyset(&newmask);
-	sigaddset(&newmask, SIGUSR1);
-	if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
-		tst_brk(TBROK | TERRNO, "block SIGUSR1 error");
-
 	for (i = 0; i < N_ATTACH; i++) {
 		switch (pid = SAFE_FORK()) {
 		case 0:
@@ -191,22 +177,8 @@ static void stat_setup(void)
 			/* do an assignement for fun */
 			*(int *)test = i;
 
-			/*
-			 * sigsuspend until we get a signal from stat_cleanup()
-			 * use sigsuspend instead of pause to avoid children
-			 * infinite sleep without getting SIGUSR1 from parent
-			 */
-			rval = sigsuspend(&oldmask);
-			if (rval != -1)
-				tst_brk(TBROK | TERRNO, "sigsuspend");
-
-			/*
-			 * don't have to block SIGUSR1 any more,
-			 * recover the mask
-			 */
-			if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
-				tst_brk(TBROK | TERRNO,
-					 "child sigprocmask");
+			/* Wait until the parent cleans up after the first test */
+			raise(SIGSTOP);
 
 			/* now we're back - detach the memory and exit */
 			if (shmdt(test) == -1)
@@ -219,11 +191,15 @@ static void stat_setup(void)
 		}
 	}
 
-	/* parent doesn't have to block SIGUSR1, recover the mask */
-	if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
-		tst_brk(TBROK, "parent sigprocmask");
-
-	usleep(250000);
+	/*
+	 * Wait for the children process to stop after they have touched
+	 * shm.
+	 */
+	for (i = 0; i < N_ATTACH; i++) {
+		SAFE_WAITPID(pid_arr[i], &status, WUNTRACED);
+		if (!WIFSTOPPED(status))
+			tst_brk(TBROK, "pid %d didn't stop", pid_arr[i]);
+	}
 }
 
 /*
@@ -287,7 +263,7 @@ static void stat_cleanup(void)
 
 	/* wake up the childern so they can detach the memory and exit */
 	for (i = 0; i < N_ATTACH; i++)
-		SAFE_KILL(pid_arr[i], SIGUSR1);
+		SAFE_KILL(pid_arr[i], SIGCONT);
 
 	/* remove the parent's shared memory the second time through */
 	if (stat_time == SECOND)
@@ -298,7 +274,7 @@ static void stat_cleanup(void)
 
 static void sighandler(int sig)
 {
-	if (sig != SIGUSR1)
+	if (sig != SIGCONT)
 		tst_res(TFAIL, "received unexpected signal %d", sig);
 }
 
Signature · 1 line
2.14.2
#6 lore raw

PATCH 3/18 hugeshmctl01: Fix synchronisation with child processes

Hi!

Quoted 11 lines

hugeshmctl01 spawns child processes to perform shm operations and uses signal (SIGUSR1) to communicate the completion of test 1, to the children waiting at sigprocmask(). However, there is no guarantee that a child has reached sigprocmask() before the parent issues a SIGUSR1 and things go wrong.

This patch fixes this issue by 'stopping' the children, waiting for all of them and then issuing SIGCONT to communicate the completion.

While we are at it, also handle unknown signals as a hint to exit the test with TBROK.

We do have a checkpoint synchronization primitives in the test library exactly for this kind of synchronization. Can you, pretty please, use them instead?

https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#229-fork-and-parent-child-synchronization

Signature · 2 lines
Cyril Hrubis
[email protected]
#7 lore raw

PATCH 4/18 hugeshmctl01: Fix synchronization issue in parent process

In reply to Punit Agrawal

From: "Suzuki K. Poulose" <[email protected]>

Wait for the children from the first test to detach and exit, before proceeding to the next round. Otherwise we could have incorrect references on the shm_id lying around from the previous run.

---
 testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c +7 -1
index 37a8a0d6f..ea249d1b6 100644
@@ -260,10 +260,16 @@ fail:
 static void stat_cleanup(void)
 {
 	int i;
+	int status;
 
 	/* wake up the childern so they can detach the memory and exit */
-	for (i = 0; i < N_ATTACH; i++)
+	for (i = 0; i < N_ATTACH; i++) {
 		SAFE_KILL(pid_arr[i], SIGCONT);
+		/* Wait for the child to exit */
+		if (waitpid(pid_arr[i], &status, 0) != pid_arr[i] &&
+			!WIFEXITED(status))
+			tst_brk(TBROK | TERRNO, "waitpid for exit");
+	}
 
 	/* remove the parent's shared memory the second time through */
 	if (stat_time == SECOND)
Signature · 1 line
2.14.2
#8 lore raw

PATCH 4/18 hugeshmctl01: Fix synchronization issue in parent process

Hi!

testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c fail: · line 270

Quoted 3 lines
testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c +3 -0
+		/* Wait for the child to exit */
+		if (waitpid(pid_arr[i], &status, 0) != pid_arr[i] &&
+			!WIFEXITED(status))

Please use SAFE_WAITPID() here, otherwise it's fine.

Signature · 2 lines
Cyril Hrubis
[email protected]
#9 lore raw

PATCH 5/18 hugeshmctl02: Fix allocation size for odd number of hugepages

In reply to Punit Agrawal

From: "Suzuki K. Poulose" <[email protected]>

The test tries to allocate 2 * (half the number of available hugepages). If we have odd number hugepages, the calculated allocation size is not page-aligned and allocation fails.

e.g, (use -s option to trigger it manually)

$ hugeshmctl02 -s 7 -i 5
hugeshmctl02    0  TINFO  :  set nr_hugepages to 7
hugeshmctl02    1  TBROK  :  hugeshmctl02.c:153: shmget #2: errno=ENOMEM(12): Cannot allocate memory
hugeshmctl02    2  TBROK  :  hugeshmctl02.c:153: Remaining cases broken
hugeshmctl02    0  TINFO  :  set nr_hugepages to 0

Align the size to hugepage_size.

---
 testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c +1 -1
index 6079d9937..82964a327 100644
@@ -101,7 +101,7 @@ static void setup(void)
 	set_sys_tune("nr_hugepages", hugepages, 1);
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 
-	shm_size = hpage_size * hugepages / 2;
+	shm_size = hpage_size * (hugepages / 2);
 	update_shm_size(&shm_size);
 	shmkey = getipckey();
 
Signature · 1 line
2.14.2
#10 lore raw

PATCH 5/18 hugeshmctl02: Fix allocation size for odd number of hugepages

Hi!

Quoted 6 lines

The test tries to allocate 2 * (half the number of available hugepages). If we have odd number hugepages, the calculated allocation size is not page-aligned and allocation fails.

e.g, (use -s option to trigger it manually)

Quoted 7 lines
$ hugeshmctl02 -s 7 -i 5
hugeshmctl02    0  TINFO  :  set nr_hugepages to 7
hugeshmctl02    1  TBROK  :  hugeshmctl02.c:153: shmget #2: errno=ENOMEM(12): Cannot allocate memory
hugeshmctl02    2  TBROK  :  hugeshmctl02.c:153: Remaining cases broken
hugeshmctl02    0  TINFO  :  set nr_hugepages to 0

Align the size to hugepage_size.

This one is obviously OK.

Signature · 2 lines
Cyril Hrubis
[email protected]
#11 lore raw

PATCH 6/18 hugeshmget02: add missing SHM_HUGETLB flag on segment creation

In reply to Punit Agrawal

From: Lorenzo Pieralisi <[email protected]>

On test setup, hugeshmget02 detects the number of huge pages available and uses that number to size a shared memory segment that is allocated to carry out subsequent syscalls checks.

The setup() function detects the number of huge pages available so that it can size the share memory segment to allocate with a reasonable size value, but fails to pass the SHM_HUGETLB on shared memory segment creation which defeats the whole purpose of detecting the available number of huge pages before creating the segment.

This omission can result in test failures, eg:

hugeshmget02    0  TINFO  :  set nr_hugepages to 128
hugeshmget02    0  TINFO  :  Using 21 hugepages
hugeshmget02    1  TBROK  :  hugeshmget02.c:155: shmget #setup:
errno=ENOMEM(12): Cannot allocate memory
hugeshmget02    2  TBROK  :  hugeshmget02.c:155: Remaining cases broken
hugeshmget02    0  TINFO  :  set nr_hugepages to 0

This patch adds the missing SHM_HUGETLB flag to the shmget call in the setup() function.

---
 testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c +2 -1
index 7db8b4ede..0abd1aaf8 100644
@@ -99,7 +99,8 @@ void setup(void)
 
 	shmkey = getipckey();
 	shmkey2 = shmkey + 1;
-	shm_id_1 = shmget(shmkey, shm_size, IPC_CREAT | IPC_EXCL | SHM_RW);
+	shm_id_1 = shmget(shmkey, shm_size,
+			  SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW);
 	if (shm_id_1 == -1)
 		tst_brk(TBROK | TERRNO, "shmget #setup");
 }
Signature · 1 line
2.14.2
#12 lore raw

PATCH 7/18 vma03: accept ENOMEM return value from mremap

In reply to Punit Agrawal

From: Will Deacon <[email protected]>

Attempting to map a wrapping region with mremap should fail (that's the whole point of this test). Accept ENOMEM as well as EINVAL.

---
 testcases/kernel/mem/vma/vma03.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/mem/vma/vma03.c +1 -1
index 4b34ab0a0..5f231e5bb 100644
@@ -100,7 +100,7 @@ int main(int argc, char *argv[])
 
 		remap = mremap(map, pgsz, 2 * pgsz, 0);
 		if (remap == MAP_FAILED) {
-			if (errno == EINVAL)
+			if (errno == EINVAL || errno == ENOMEM)
 				tst_resm(TPASS, "mremap failed as expected.");
 			else
 				tst_resm(TFAIL | TERRNO, "mremap");
Signature · 1 line
2.14.2
#13 lore raw

PATCH 7/18 vma03: accept ENOMEM return value from mremap

Hi!

Quoted 2 lines

Attempting to map a wrapping region with mremap should fail (that's the whole point of this test). Accept ENOMEM as well as EINVAL.

I'm missing any background info here about the specific conditions where this happens. The test is supposed to run only on 32bit kernel, so I suppose that there is some older board with 32bit ARM that is able to execute this test and that we get a different errno there, but that is only speculation. Can you, pretty please, elaborate more on that?

Quoted 25 lines
---
 testcases/kernel/mem/vma/vma03.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/mem/vma/vma03.c +1 -1
index 4b34ab0a0..5f231e5bb 100644
@@ -100,7 +100,7 @@ int main(int argc, char *argv[])
 
 		remap = mremap(map, pgsz, 2 * pgsz, 0);
 		if (remap == MAP_FAILED) {
-			if (errno == EINVAL)
+			if (errno == EINVAL || errno == ENOMEM)
 				tst_resm(TPASS, "mremap failed as expected.");
 			else
 				tst_resm(TFAIL | TERRNO, "mremap");
Signature · 5 lines
2.14.2


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
#14 lore raw

PATCH 7/18 vma03: accept ENOMEM return value from mremap

Hi Cyril,

Picking up where I'd left off after the previous posting.

Quoted 9 lines · Cyril Hrubis

Hi!

Quoted 2 lines

Attempting to map a wrapping region with mremap should fail (that's the whole point of this test). Accept ENOMEM as well as EINVAL.

I'm missing any background info here about the specific conditions where this happens. The test is supposed to run only on 32bit kernel, so I suppose that there is some older board with 32bit ARM that is able to execute this test and that we get a different errno there, but that is only speculation. Can you, pretty please, elaborate more on that?

After digging into the patch history I've failed to find an explanation for why we are carrying the patch. Looks like the details of the issue it was fixing have been lost.

The unpatched version of the test passes on TC2 (a 32bit big.LITTLE ARM Platform).

I'll drop this patch from the next version.

Thanks,
Punit

Quoted 26 lines
Quoted 26 lines
---
 testcases/kernel/mem/vma/vma03.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/mem/vma/vma03.c +1 -1
index 4b34ab0a0..5f231e5bb 100644
@@ -100,7 +100,7 @@ int main(int argc, char *argv[])
 
 		remap = mremap(map, pgsz, 2 * pgsz, 0);
 		if (remap == MAP_FAILED) {
-			if (errno == EINVAL)
+			if (errno == EINVAL || errno == ENOMEM)
 				tst_resm(TPASS, "mremap failed as expected.");
 			else
 				tst_resm(TFAIL | TERRNO, "mremap");
Signature · 5 lines
2.14.2


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#15 lore raw

PATCH 8/18 creat08: ensure test directories are created in /tmp/

In reply to Punit Agrawal

From: Will Deacon <[email protected]>

runltp runs tests in the ${LTP_ROOT}/bin directory. If this is NFS mounted, we can run into problems that need to use setgid. Fix this by ensuring that creat08 creates directories in /tmp/

---
 testcases/kernel/syscalls/creat/creat08.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/creat/creat08.c +2 -2
index 284ae5f1a..bd8368e28 100644
@@ -63,8 +63,8 @@ int local_flag;
 
 #define MODE_RWX        (S_IRWXU|S_IRWXG|S_IRWXO)
 #define MODE_SGID       (S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
-#define DIR_A_TEMP	"testdir.A.%d"
-#define DIR_B_TEMP	"testdir.B.%d"
+#define DIR_A_TEMP	"/tmp/testdir.A.%d"
+#define DIR_B_TEMP	"/tmp/testdir.B.%d"
 #define SETGID		"setgid"
 #define NOSETGID	"nosetgid"
 #define ROOT_SETGID	"root_setgid"
Signature · 1 line
2.14.2
#16 lore raw

PATCH 8/18 creat08: ensure test directories are created in /tmp/

Hi!

Quoted 3 lines

runltp runs tests in the ${LTP_ROOT}/bin directory. If this is NFS mounted, we can run into problems that need to use setgid. Fix this by ensuring that creat08 creates directories in /tmp/

The test setup calls tst_tmpdir() which creates temporary directory in /tmp/ and changes $PWD to point into it. So these directories has to be created in /tmp/. If that is not the case something is wrong with the test.

Signature · 2 lines
Cyril Hrubis
[email protected]
#17 lore raw

PATCH 8/18 creat08: ensure test directories are created in /tmp/

Quoted 9 lines · Cyril Hrubis

Hi!

Quoted 3 lines

runltp runs tests in the ${LTP_ROOT}/bin directory. If this is NFS mounted, we can run into problems that need to use setgid. Fix this by ensuring that creat08 creates directories in /tmp/

The test setup calls tst_tmpdir() which creates temporary directory in /tmp/ and changes $PWD to point into it. So these directories has to be created in /tmp/. If that is not the case something is wrong with the test.

Hah.. it looks like we are carrying this one around since before tst_tmpdir() was used. Another reason to try and track upstream as closely as we can.

I'll drop this from the next version after confirming that it is no longer needed.

#18 lore raw

PATCH 9/18 kill05: fix race on getpwnam

In reply to Punit Agrawal

From: Will Deacon <[email protected]>

Two threads doing getpwnam to a static struct in the library, sometimes end up using the same UID. Fix this.

---
 testcases/kernel/syscalls/kill/kill05.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/kill/kill05.c +4 -3
index ccef5afd6..2ae046130 100644
@@ -174,15 +174,16 @@ void do_master_child(char **av)
 		do_child();
 #endif
 	}
+
+	/* wait until child sets its euid (and has finished with the static getpwnam result struct) */
+	wait_for_flag(1);
+
 	ltpuser2 = SAFE_GETPWNAM(NULL, user2name);
 	if (setreuid(ltpuser2->pw_uid, ltpuser2->pw_uid) == -1) {
 		perror("seteuid failed");
 		exit(1);
 	}
 
-	/* wait until child sets its euid */
-	wait_for_flag(1);
-
 	TEST(kill(pid1, TEST_SIG));
 
 	/* signal the child that we're done */
Signature · 1 line
2.14.2
#19 lore raw

PATCH 9/18 kill05: fix race on getpwnam

Hi!

Quoted 2 lines

Two threads doing getpwnam to a static struct in the library, sometimes end up using the same UID. Fix this.

Hmm these getpwnam() calls are done from different processes, so I suppose that this happens on uClinux, or do I miss something?

Also we should move these calls to the test setup anyways.

Quoted 37 lines
---
 testcases/kernel/syscalls/kill/kill05.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/kill/kill05.c +4 -3
index ccef5afd6..2ae046130 100644
@@ -174,15 +174,16 @@ void do_master_child(char **av)
 		do_child();
 #endif
 	}
+
+	/* wait until child sets its euid (and has finished with the static getpwnam result struct) */
+	wait_for_flag(1);
+
 	ltpuser2 = SAFE_GETPWNAM(NULL, user2name);
 	if (setreuid(ltpuser2->pw_uid, ltpuser2->pw_uid) == -1) {
 		perror("seteuid failed");
 		exit(1);
 	}
 
-	/* wait until child sets its euid */
-	wait_for_flag(1);
-
 	TEST(kill(pid1, TEST_SIG));
 
 	/* signal the child that we're done */
Signature · 5 lines
2.14.2


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
#20 lore raw

PATCH 9/18 kill05: fix race on getpwnam

Quoted 6 lines · Cyril Hrubis

Hi!

Quoted 2 lines

Two threads doing getpwnam to a static struct in the library, sometimes end up using the same UID. Fix this.

Hmm these getpwnam() calls are done from different processes, so I suppose that this happens on uClinux, or do I miss something?

This is another patch we've been carrying for long enough to have lost context around it's origin.

I don't see a reasonable explanation for why the change makes sense, especially as it was done on a non-uClinux stack.

I'll drop this patch from the next posting.

Quoted 40 lines

Also we should move these calls to the test setup anyways.

Quoted 37 lines
---
 testcases/kernel/syscalls/kill/kill05.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/kill/kill05.c +4 -3
index ccef5afd6..2ae046130 100644
@@ -174,15 +174,16 @@ void do_master_child(char **av)
 		do_child();
 #endif
 	}
+
+	/* wait until child sets its euid (and has finished with the static getpwnam result struct) */
+	wait_for_flag(1);
+
 	ltpuser2 = SAFE_GETPWNAM(NULL, user2name);
 	if (setreuid(ltpuser2->pw_uid, ltpuser2->pw_uid) == -1) {
 		perror("seteuid failed");
 		exit(1);
 	}
 
-	/* wait until child sets its euid */
-	wait_for_flag(1);
-
 	TEST(kill(pid1, TEST_SIG));
 
 	/* signal the child that we're done */
Signature · 5 lines
2.14.2


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#21 lore raw

PATCH 10/18 sigwaitinfo01: fix race between sending and dequeueing RT signals

In reply to Punit Agrawal

From: Will Deacon <[email protected]>

Although RT signals are dequeued in order, there is a race where only the higher signal may have been sent and will therefore be dequeued first, leading to a false failure.

This patch waits on the signal sending tasks so that we can be sure both of the signals have been sent before dequeuing them.

---
 testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c | 5 +++++
 1 file changed, 5 insertions(+)
testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c +5 -0
index 35acd67c4..16b5096b8 100644
@@ -249,6 +249,7 @@ void test_masked_matching_rt(swi_func sigwaitinfo, int signo)
 	sigset_t sigs, oldmask;
 	siginfo_t si;
 	pid_t child[2];
+	int status;
 
 	signo = SIGRTMIN + 1;
 
@@ -268,6 +269,10 @@ void test_masked_matching_rt(swi_func sigwaitinfo, int signo)
 	child[0] = create_sig_proc(0, signo, 1);
 	child[1] = create_sig_proc(0, signo + 1, 1);
 
+	/* Ensure that the signals have been sent */
+	waitpid(child[0], &status, 0);
+	waitpid(child[1], &status, 0);
+
 	TEST(sigwaitinfo(&sigs, &si, NULL));
 	REPORT_SUCCESS_COND(signo, 0, si.si_pid == child[0]
 			    && si.si_code == SI_USER
Signature · 1 line
2.14.2
#22 lore raw

PATCH 11/18 sigwaitinfo: catch SEGV and report success for bad_address2 testcase

In reply to Punit Agrawal

From: Will Deacon <[email protected]>

The bad_address2 testcase passes (void *)1 as a sigset pointer to the sigwaitinfo syscall. Unsurprisingly, this segfaults in libc rather than returning -1 (errno = EFAULT) as LTP expects.

This patch registers a SIGSEGV handler to catch any SEGV's generated by the sigwaitinfo syscall and treat them as success.

---
 .../kernel/syscalls/sigwaitinfo/sigwaitinfo01.c    | 31 +++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c +30 -1
index 16b5096b8..44aa849af 100644
@@ -23,6 +23,8 @@
 #include "test.h"
 #include <errno.h>
 #include <signal.h>
+#include <sys/ucontext.h>
+#include <setjmp.h>
 #include "../utils/include_j_h.h"
 #include "../utils/common_j_h.c"
 #include <limits.h>
@@ -361,9 +363,36 @@ void test_bad_address(swi_func sigwaitinfo, int signo)
 	kill(child, SIGTERM);
 }
 
+sigjmp_buf jmpbuf;
+
+static void segv_handler(int signal, siginfo_t *info, struct ucontext *ut)
+{
+	if (signal == SIGSEGV)
+		longjmp(jmpbuf, 1);
+
+	fprintf(stderr, "caught unexpected signal - %d --- exiting\n", signal);
+	_exit(-1);
+}
+
 void test_bad_address2(swi_func sigwaitinfo, int signo)
 {
-	TEST(sigwaitinfo((void *)1, NULL, NULL));
+	struct sigaction sigptr, oldact;
+
+	sigptr.sa_sigaction = segv_handler;
+	sigfillset(&sigptr.sa_mask);
+	sigdelset(&sigptr.sa_mask, SIGSEGV);
+	sigptr.sa_flags = SA_SIGINFO;
+
+	SUCCEED_OR_DIE(sigaction, "sigaction failed", SIGSEGV, &sigptr, &oldact);
+
+	if (setjmp(jmpbuf) == 0) {
+		TEST(sigwaitinfo((void*)1, NULL, NULL));
+	} else {
+		TEST_RETURN = -1;
+		TEST_ERRNO = EFAULT;
+	}
+
+	SUCCEED_OR_DIE(sigaction, "sigaction failed", SIGSEGV, &oldact, NULL);
 	REPORT_SUCCESS(-1, EFAULT);
 }
 
Signature · 1 line
2.14.2
#23 lore raw

PATCH 11/18 sigwaitinfo: catch SEGV and report success for bad_address2 testcase

Hi!

Quoted 6 lines

The bad_address2 testcase passes (void *)1 as a sigset pointer to the sigwaitinfo syscall. Unsurprisingly, this segfaults in libc rather than returning -1 (errno = EFAULT) as LTP expects.

This patch registers a SIGSEGV handler to catch any SEGV's generated by the sigwaitinfo syscall and treat them as success.

Can we, pretty please, rather run the test in a child process and catch the SEGFAULT using the waitpid()?

The whole longjmp() stuff is overcomplicated solution for the problem.

Signature · 2 lines
Cyril Hrubis
[email protected]
#24 lore raw

PATCH 12/18 inotify: fix inotify.h breakage

In reply to Punit Agrawal

From: Mark Rutland <[email protected]>

359980f68b: "rename syscall() macro to ltp_syscall()" renamed syscall() to ltp_syscall, but didn't update all callers. This had the side effect of making some callers refer to syscall.h's definition of syscall() instead. This caused some tests to start failing unexpectedly.

This patch fixes up inotify.h to use ltp_syscall.

---
 testcases/kernel/syscalls/inotify/inotify.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
testcases/kernel/syscalls/inotify/inotify.h +4 -4
index ac731bcb2..a364e1472 100644
@@ -32,16 +32,16 @@
 
 #if __NR_inotify_init != __LTP__NR_INVALID_SYSCALL
 #define	myinotify_init() \
-	syscall(__NR_inotify_init)
+	ltp_syscall(__NR_inotify_init)
 #else
 #define	myinotify_init() \
-	syscall(__NR_inotify_init1, 0)
+	ltp_syscall(__NR_inotify_init1, 0)
 #endif
 
 #define	myinotify_add_watch(fd, pathname, mask)	\
-	syscall(__NR_inotify_add_watch, fd, pathname, mask)
+	ltp_syscall(__NR_inotify_add_watch, fd, pathname, mask)
 
 #define	myinotify_rm_watch(fd, wd) \
-	syscall(__NR_inotify_rm_watch, fd, wd)
+	ltp_syscall(__NR_inotify_rm_watch, fd, wd)
 
 #endif /* _INOTIFY_H */
Signature · 1 line
2.14.2
#26 lore raw

PATCH 13/18 syscalls/mount03: Copy setuid_test to execute instead of 'TEST FILE'

In reply to Punit Agrawal

From: Will Deacon <[email protected]>

When testing the MS_NOSUID mount flag, mount03 forgets to copy setuid_test into the new filesystem. Instead it writes 'TEST FILE' into a new file and attempts to execute it with S_ISUID. This fails, but not for the reasons ltp expects.

[Added commit message, changed to use tst_resource_copy()]
---
 testcases/kernel/syscalls/mount/mount03.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/mount/mount03.c +3 -1
index bf78c797f..abdef80fd 100644
@@ -261,8 +261,10 @@ int test_rwflag(int i, int cnt)
 	case 5:
 		/* Validate MS_NOSUID flag of mount call */
 
+		tst_resource_copy(__FILE__, __LINE__, cleanup, "setuid_test",
+				  path_name);
+
 		snprintf(file, PATH_MAX, "%ssetuid_test", path_name);
-		SAFE_FILE_PRINTF(cleanup, file, "TEST FILE");
 
 		SAFE_STAT(cleanup, file, &file_stat);
 
Signature · 1 line
2.14.2
#27 lore raw

PATCH 14/18 ioctl: fix stty usage for busybox

In reply to Punit Agrawal

From: Mark Rutland <[email protected]>

The ioctl tests rely on stty to test if a tty is usable, and use the long form "--file=" flag to tell stty which tty to test. Busybox doesn't understand the long "--file=" flag, and this causes the LTP test harness to skip tests:

Quoted 2 lines

stty: invalid argument '--file=/dev/tty0'
ioctl01_02 0 TINFO : Skipping ioctl01 with /dev/tty0

Luckily, both busybox stty and GNU stty understand the equivalent "-F" flag. This patch makes LTP use this more common option.

---
 testcases/kernel/syscalls/ioctl/test_ioctl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/syscalls/ioctl/test_ioctl +1 -1
index 1151b55eb..923275433 100755
@@ -26,7 +26,7 @@ export TST_COUNT=0
 has_tty()
 {
     if command -v stty >/dev/null 2>&1; then
-        stty --file=$1 > /dev/null
+        stty -F $1 > /dev/null
         if [ $? -ne 0 ]; then
             return 0
         fi
Signature · 1 line
2.14.2
#29 lore raw

PATCH 15/18 getdtablesize01: Handle ENFILE errno

In reply to Punit Agrawal

From: "Suzuki K. Poulose" <[email protected]>

getdtablesize01 testcase attempts to open RLIMIT_NOFILE-1 (Maximum open files for a process) file descriptors. However if we hit an ENFILE (system wide limit of maximum number of open files) we should break the test, rather than failing. This is more relevant for runs on VMs where the rootfs could be a 9p fs or any other emulated fs.

---
 .../kernel/syscalls/getdtablesize/getdtablesize01.c     | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
testcases/kernel/syscalls/getdtablesize/getdtablesize01.c +10 -7
index 7ee231adf..eecf44b18 100644
@@ -54,7 +54,7 @@ int TST_TOTAL = 1;
 
 int main(void)
 {
-	int table_size, loop, fd, count = 0;
+	int table_size, loop, fd = 0, count = 0;
 	int max_val_opfiles;
 	struct rlimit rlp;
 
@@ -82,24 +82,27 @@ int main(void)
 		 "Checking Max num of files that can be opened by a process.Should be: RLIMIT_NOFILE - 1");
 	for (loop = 1; loop <= max_val_opfiles; loop++) {
 		fd = open("/etc/hosts", O_RDONLY);
+
+		if (fd == -1)
+			break;
+		count = fd;
 #ifdef DEBUG
 		printf("Opened file num %d\n", fd);
 #endif
-		if (fd == -1)
-			break;
-		else
-			count = fd;
 	}
 
 //Now the max files opened should be RLIMIT_NOFILE - 1 , why ? read getdtablesize man page
 
-	if (count > 0)
-		close(count);
 	if (count == (max_val_opfiles - 1))
 		tst_resm(TPASS, "%d = %d", count, (max_val_opfiles - 1));
+	else if (fd < 0 && errno == ENFILE)
+		tst_brkm(TBROK, cleanup, "Reached maximum number of open files for the system");
 	else
 		tst_resm(TFAIL, "%d != %d", count, (max_val_opfiles - 1));
 
+	if (count > 0)
+		close(count);
+
 	cleanup();
 	tst_exit();
 }
Signature · 1 line
2.14.2
#30 lore raw

PATCH 16/18 perf_event_open: Handle absence of PMU gracefully

In reply to Punit Agrawal

From: "Suzuki K. Poulose" <[email protected]>

The perf_event_open0{1,2} syscall tests fail for an absence of a PMU (which returns ENODEV). Handle the return code gracefully as we check for ENOENT.

Without the patch:

$ perf_event_open01
perf_event_open01    1  TFAIL  :  perf_event_open01.c:162: perf_event_open \
		failed unexpectedly: TEST_ERRNO=ENODEV(19): No such device

With the patch:

$ perf_event_open01
perf_event_open01    1  TCONF  :  perf_event_open01.c:159: perf_event_open for PERF_COUNT_HW_INSTRUCTIONS : No such device
perf_event_open01    2  TCONF  :  perf_event_open01.c:159: perf_event_open for PERF_COUNT_HW_CACHE_REFERENCES : No such device
perf_event_open01    3  TCONF  :  perf_event_open01.c:159: perf_event_open for PERF_COUNT_HW_CACHE_MISSES : No such device
perf_event_open01    4  TCONF  :  perf_event_open01.c:159: perf_event_open for PERF_COUNT_HW_BRANCH_INSTRUCTIONS : No such file or directory
perf_event_open01    5  TCONF  :  perf_event_open01.c:159: perf_event_open for PERF_COUNT_HW_BRANCH_MISSES : No such device
perf_event_open01    0  TINFO  :  read event counter succeeded, value: 833765520
perf_event_open01    6  TPASS  :  test PERF_TYPE_HARDWARE: PERF_COUNT_SW_CPU_CLOCK succeeded
perf_event_open01    0  TINFO  :  read event counter succeeded, value: 833967380
perf_event_open01    7  TPASS  :  test PERF_TYPE_HARDWARE: PERF_COUNT_SW_TASK_CLOCK succeeded
---
 testcases/kernel/syscalls/perf_event_open/perf_event_open01.c | 3 ++-
 testcases/kernel/syscalls/perf_event_open/perf_event_open02.c | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/perf_event_open/perf_event_open01.c +2 -1
index 5c814b60c..5568035d9 100644
@@ -149,7 +149,8 @@ static void verify(struct test_case_t *tc)
 
 	TEST(perf_event_open(&pe, 0, -1, -1, 0));
 	if (TEST_RETURN == -1) {
-		if (TEST_ERRNO == ENOENT || TEST_ERRNO == EOPNOTSUPP) {
+		if (TEST_ERRNO == ENOENT || TEST_ERRNO == EOPNOTSUPP ||
+		    TEST_ERRNO == ENODEV) {
 			tst_resm(TCONF | TTERRNO,
 			         "perf_event_open for %s not supported",
 			         tc->config_name);
testcases/kernel/syscalls/perf_event_open/perf_event_open02.c +2 -2
index 7d54cbd52..13a17948a 100644
@@ -160,8 +160,8 @@ static int count_hardware_counters(void)
 	for (i = 0; i < MAX_CTRS; i++) {
 		fdarry[i] = perf_event_open(&hw_event, 0, -1, -1, 0);
 		if (fdarry[i] == -1) {
-			if (errno == ENOENT) {
-				tst_brkm(TCONF, cleanup,
+			if (errno == ENOENT || errno == ENODEV) {
+				tst_brkm(TCONF | TERRNO, cleanup,
 				         "PERF_COUNT_HW_INSTRUCTIONS not supported");
 			}
 			tst_brkm(TBROK | TERRNO, cleanup,
Signature · 1 line
2.14.2
#31 lore raw

PATCH 17/18 hotplug/cpu_hotplug: Repopulate cgroup:cpusets after testing hotplug

In reply to Punit Agrawal

From: James Morse <[email protected]>

When LTP is started over ssh, systemd will use cgroups to group all the tasks started by this session. LTPs cpuhotplug04 will remove all but one CPU as part of its test.

In the kernel cpuset_hotplug_workfn() is documented thus: "Non-root cpusets are only affected by offlining". This means cpuhotplug04 will cause all future tasks to only have one available CPU. cpuhotplug04 effectively looses those CPUs for all users until the next reboot.

This problem has been reported, and was fixed for the unified hierarchy by be4c9dd7aee5 ("cpuset: enable onlined cpu/node in effective masks"). Since v3.17, this behaviour could be selected by passing '-o __DEVEL__sane_behavior' to the cgroup mount. Linux v4.4 grouped all the ABI breakage together into a new filesystem: cgroup2, removing the __DEVEL__sane_behavior flag.

With v226 Systemd can be forced to use cgroup2 by passing 'systemd.unified_cgroup_hierarchy=1' on the kernel command line.

Ubuntu 15.04 ships with systemd v219.

LTP tests that online CPUs must test for the legacy cgroup hierarchy and update the cpusets for all users/sessions. Add this code the cpu_online() helper.

---
 .../cpu_hotplug/include/cpuhotplug_hotplug.sh      | 36 ++++++++++++++++++++++
 1 file changed, 36 insertions(+)
testcases/kernel/hotplug/cpu_hotplug/include/cpuhotplug_hotplug.sh +36 -0
index 9f856e554..35ec7c86b 100644
@@ -58,6 +58,39 @@ set_affinity()
     return $?
 }
 
+# repopulate_cpusets()
+#
+# If the legacy cgroup hierarchy is in use, and cpuset is mounted, copy
+# the permitted cpus from the root group, which always has all available
+# cpus and memory, into the other hierarchy nodes. This prevents hotplug
+# tests from losing CPUs, and affecting the results of later tests.
+#
+CPUSET="/sys/fs/cgroup/cpuset"
+repopulate_cpusets()
+{
+	# Only if we have cpusets
+	if [ ! -d ${CPUSET} ] ; then
+		return;
+	fi
+
+	# And then only legacy cpusets
+	if grep --quiet "/sys/fs/cgroup/cpuset[ ]*cgroup2" /proc/mounts ; then
+		return;
+	fi
+
+	# Copy root cpus into system and user slices
+	cat ${CPUSET}/cpuset.cpus > ${CPUSET}/system.slice/cpuset.cpus
+	cat ${CPUSET}/cpuset.cpus > ${CPUSET}/user.slice/cpuset.cpus
+
+	# Fix each session of each user
+	for TUSER in ${CPUSET}/user.slice/user-*.slice ; do
+		cat ${CPUSET}/cpuset.cpus > ${TUSER}/cpuset.cpus
+		for SESSION in ${TUSER}/session-*.scope; do
+			cat ${CPUSET}/cpuset.cpus > ${SESSION}/cpuset.cpus
+		done
+	done
+}
+
 # online_cpu(CPU)
 #
 #  Onlines the given CPU.  Returns a true value if it was able
@@ -77,6 +110,9 @@ online_cpu()
 
     $TIME echo 1 > /sys/devices/system/cpu/cpu${CPU}/online
     RC=$?
+
+    repopulate_cpusets
+
     report_timing "Online cpu ${CPU}"
     return $RC
 }
Signature · 1 line
2.14.2
#32 lore raw

PATCH 18/18 hotplug/cpu_hotplug: Remove bashism disown from kill_pid()

In reply to Punit Agrawal

From: James Morse <[email protected]>

disown is a bashism not present in dash. kill_pid() already sends the process SIGKILL.

Remove the "disown" to allow running in shells that don't support disown.

---
 testcases/kernel/hotplug/cpu_hotplug/include/cpuhotplug_testsuite.sh | 1 -
 1 file changed, 1 deletion(-)
testcases/kernel/hotplug/cpu_hotplug/include/cpuhotplug_testsuite.sh +0 -1
index 2d0166cc6..7dd0ebaae 100644
@@ -74,7 +74,6 @@ pid_is_valid()
 kill_pid()
 {
     PID=$1
-    disown $PID
     kill -9 $PID > /dev/null 2>&1
 }
 
Signature · 1 line
2.14.2