Skip to contentSkip to conversation

Fix rt_sigtimedwait ordering test

PATCH In review Will Deacon 2 participants 4 messages Feb 7, 2011 – Feb 25, 2011 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix rt_sigtimedwait ordering test

The rt_sigtimedwait test invokes test_masked_matching_rt, which spawns two children who send consecutive RT signals to the parent. The test then checks (via sigwaitinfo) that the RT signals are delivered in the correct order: namely that the lower signal is taken first.

This test can fail due to a race condition where the parent issues the sigwaitinfo syscall before the first child has signalled the parent but after the second child has (due to context switching). This results in the signals being received in the reverse order.

This patch inserts waitpid syscalls to the parent thread so that the sigwaitinfo call is only issued after the children have exited.

---
 .../kernel/syscalls/sigwaitinfo/sigwaitinfo01.c    |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c +6 -1
index c0e0241..439dfb3 100644
@@ -232,6 +232,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;
 
@@ -250,6 +251,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 && si.si_signo==signo, "Struct siginfo mismatch");
 
@@ -434,4 +439,4 @@ int main(int argc, char** argv)
 
 	cleanup();
 	tst_exit();
-}
\ No newline at end of file
+}
Signature · 14 lines
1.7.0.4



------------------------------------------------------------------------------
The modern datacenter depends on network connectivity to access resources
and provide services. The best practices for maximizing a physical server's
connectivity to a physical network are well understood - see how these
rules translate into the virtual world? 
http://p.sf.net/sfu/oracle-sfdevnlfb
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw

Hello,

Quoted 11 lines

The rt_sigtimedwait test invokes test_masked_matching_rt, which spawns two children who send consecutive RT signals to the parent. The test then checks (via sigwaitinfo) that the RT signals are delivered in the correct order: namely that the lower signal is taken first.

This test can fail due to a race condition where the parent issues the sigwaitinfo syscall before the first child has signalled the parent but after the second child has (due to context switching). This results in the signals being received in the reverse order.

Quoted 7 lines

This patch inserts waitpid syscalls to the parent thread so that the sigwaitinfo call is only issued after the children have exited.

---
 .../kernel/syscalls/sigwaitinfo/sigwaitinfo01.c    |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

I've not heard anything further on this, but it does fix a real issue on the platform I'm using. Do you need anything more from me for this to be considered for committing?

Cheers,

Will

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#3 lore raw
In reply to a message not in the archive

qOn Wed, Feb 16, 2011 at 8:43 AM, Will Deacon <[email protected]> wrote:

...

Quoted 3 lines

I've not heard anything further on this, but it does fix a real issue on the platform I'm using. Do you need anything more from me for this to be considered for committing?

Kind of odd that only doing it there would fix the entire testcase
as that's not the only pattern of

create_sig_proc(...)

that isn't handled with a wait/waitpid.
It just seems like there are tons of bugs lurking under the scenes
with this create_sig_proc deal because it doesn't wait, and if the parent doesn't wait, then you're just creating a ton of races potentially if not handled properly.
FWIW some more synchronization may need to be added in
create_sig_proc (like blocking I/O with a pipe for instance, mq_*, sem_*? mq_* and sem_* are kind of undesirable though because those APIs are buggy on different architectures / versions of Linux, and pipes are generally simple enough to express synchronization), in order to ensure that things are deterministically ordered and the results of the test are sane.
Thanks,
-Garrett

------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in Real-Time with Splunk. Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. http://p.sf.net/sfu/splunk-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#4 lore raw

Hi Garrett,

Quoted 10 lines
Quoted 3 lines

I've not heard anything further on this, but it does fix a real issue on the platform I'm using. Do you need anything more from me for this to be considered for committing?

Kind of odd that only doing it there would fix the entire testcase
as that's not the only pattern of

create_sig_proc(...)

that isn't handled with a wait/waitpid.

It's not that strange because, in this testcase at least, we call sigwaitinfo either with a timeout or a sigset_t in the parent. In the latter case this will block until the signal is delivered so the race between child and parent isn't a problem.

Quoted 4 lines

It just seems like there are tons of bugs lurking under the scenes
with this create_sig_proc deal because it doesn't wait, and if the parent doesn't wait, then you're just creating a ton of races potentially if not handled properly.

The issue is when you have multiple children and the test relies on a specific ordering of signal delivery (as is the case for RT signals).

Quoted 7 lines

FWIW some more synchronization may need to be added in
create_sig_proc (like blocking I/O with a pipe for instance, mq_*, sem_*? mq_* and sem_* are kind of undesirable though because those APIs are buggy on different architectures / versions of Linux, and pipes are generally simple enough to express synchronization), in order to ensure that things are deterministically ordered and the results of the test are sane.

I'm not sure this is necessary because it restricts the concurrency for testcases where the race shouldn't matter.

Will

------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in Real-Time with Splunk. Collect, index and harness all the fast moving IT data generated by your applications, servers and devices whether physical, virtual or in the cloud. Deliver compliance at lower cost and gain new business insights. http://p.sf.net/sfu/splunk-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list