Skip to contentSkip to conversation

clone08: don't treat EWOULDBLOCK as failure

PATCH New Jan Stancek 2 participants 3 messages Oct 20, 2017 – Oct 26, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clone08: don't treat EWOULDBLOCK as failure

futex() and clone() are racing in test_clone_thread(). If clone() changes ctid first, then futex() reports EWOULDBLOCK and test treats that as failure.

We don't need to eliminate the race, since all we care about is that ctid is changed/cleared by clone().

Also fix a small warning from unused variable.

---
 testcases/kernel/syscalls/clone/clone08.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
testcases/kernel/syscalls/clone/clone08.c +17 -8
index 58f9be0e20bf..a228b2f73762 100644
@@ -133,9 +133,7 @@ static int child_clone_parent(void *arg LTP_ATTRIBUTE_UNUSED)
 
 static void test_clone_tid(int t)
 {
-	pid_t child;
-
-	child = clone_child(&test_cases[t]);
+	clone_child(&test_cases[t]);
 	tst_reap_children();
 }
 
@@ -206,11 +204,22 @@ static void test_clone_thread(int t)
 
 		clone_child(&test_cases[t]);
 
-		if (syscall(SYS_futex, &ctid, FUTEX_WAIT, -1, &timeout))
-			tst_res(TFAIL | TERRNO, "futex failed");
-		else
-			tst_res(TPASS, "futex exit on ctid change");
-
+		if (syscall(SYS_futex, &ctid, FUTEX_WAIT, -1, &timeout)) {
+			/*
+			 * futex here is racing with clone() above.
+			 * Which means we can get EWOULDBLOCK if
+			 * ctid has been already changed by clone()
+			 * before we make the call. As long as ctid
+			 * changes we should not report error when
+			 * futex returns EWOULDBLOCK.
+			 */
+			if (errno != EWOULDBLOCK || ctid == -1) {
+				tst_res(TFAIL | TERRNO,
+					"futex failed, ctid: %d", ctid);
+				_exit(0);
+			}
+		}
+		tst_res(TPASS, "futex exit on ctid change, ctid: %d", ctid);
 		_exit(0);
 	}
 
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 clone08: don't treat EWOULDBLOCK as failure

Quoted 7 lines · Jan Stancek

futex() and clone() are racing in test_clone_thread(). If clone() changes ctid first, then futex() reports EWOULDBLOCK and test treats that as failure.

We don't need to eliminate the race, since all we care about is that ctid is changed/cleared by clone().

Quoted 6 lines

Also fix a small warning from unused variable.

---
 testcases/kernel/syscalls/clone/clone08.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

Looks good to me, thanks!

#2 lore raw

PATCH 1/1 clone08: don't treat EWOULDBLOCK as failure

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

Quoted 8 lines · Jan Stancek
Quoted 7 lines

futex() and clone() are racing in test_clone_thread(). If clone() changes ctid first, then futex() reports EWOULDBLOCK and test treats that as failure.

We don't need to eliminate the race, since all we care about is that ctid is changed/cleared by clone().

Quoted 9 lines
Quoted 6 lines

Also fix a small warning from unused variable.

---
 testcases/kernel/syscalls/clone/clone08.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

Looks good to me, thanks!

Pushed.

Regards,
Jan