[LTP] [PATCH v3] signal: add new testcase signal06.c

Jan Stancek jstancek@redhat.com
Thu Nov 12 09:52:03 CET 2015





----- Original Message -----
> From: "Li Wang" <liwang@redhat.com>
> To: jstancek@redhat.com
> Cc: ltp@lists.linux.it
> Sent: Wednesday, 11 November, 2015 2:13:45 PM
> Subject: [PATCH v3] signal: add new testcase signal06.c
> 
> v2 --> v3
> 	1. add filename to .gitignore
> 	2. use TEST() macro in someplace
> 
> the comments from Oleg's patch:
> 
> save_xstate_sig()->drop_init_fpu() doesn't look right. setup_rt_frame()
> can fail after that, in this case the next setup_rt_frame() triggered
> by SIGSEGV won't save fpu simply because the old state was lost. This
> obviously mean that fpu won't be restored after sys_rt_sigreturn() from
> SIGSEGV handler.
> 
> this issue was fixed on kernel v3.17-rc3-3:
> 
>         commit df24fb859a4e200d9324e2974229fbb7adf00aef
>   		Author: Oleg Nesterov <oleg@redhat.com>
>   		Date:   Tue Sep 2 19:57:17 2014 +0200
> 
>         commit 66463db4fc5605d51c7bb81d009d5bf30a783a2c
>                 Author: Oleg Nesterov <oleg@redhat.com>
>                 Date:   Tue Sep 2 19:57:13 2014 +0200
> 
> Signed-off-by: Li Wang <liwang@redhat.com>
> ---
>  runtest/ltplite                             |   1 +
>  runtest/stress.part3                        |   1 +
>  runtest/syscalls                            |   1 +
>  testcases/kernel/syscalls/.gitignore        |   1 +
>  testcases/kernel/syscalls/signal/Makefile   |   2 +
>  testcases/kernel/syscalls/signal/signal06.c | 169
>  ++++++++++++++++++++++++++++
>  6 files changed, 175 insertions(+)
>  create mode 100644 testcases/kernel/syscalls/signal/signal06.c

Pushed with changes described below.

Regards,
Jan

> 
> diff --git a/runtest/ltplite b/runtest/ltplite
> index aaa5c73..f2c9dcf 100644
> --- a/runtest/ltplite
> +++ b/runtest/ltplite
> @@ -840,6 +840,7 @@ signal02 signal02
>  signal03 signal03
>  signal04 signal04
>  signal05 signal05
> +signal06 signal06
>  
>  sigpending02 sigpending02
>  
> diff --git a/runtest/stress.part3 b/runtest/stress.part3
> index 63505ec..36bb16f 100644
> --- a/runtest/stress.part3
> +++ b/runtest/stress.part3
> @@ -744,6 +744,7 @@ signal02 signal02
>  signal03 signal03
>  signal04 signal04
>  signal05 signal05
> +signal06 signal06
>  
>  sigpending02 sigpending02
>  
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 958f66e..cfbcbea 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -1143,6 +1143,7 @@ signal02 signal02
>  signal03 signal03
>  signal04 signal04
>  signal05 signal05
> +signal06 signal06
>  
>  signalfd01 signalfd01
>  
> diff --git a/testcases/kernel/syscalls/.gitignore
> b/testcases/kernel/syscalls/.gitignore
> index 6e4894a..8b36869 100644
> --- a/testcases/kernel/syscalls/.gitignore
> +++ b/testcases/kernel/syscalls/.gitignore
> @@ -908,6 +908,7 @@
>  /signal/signal03
>  /signal/signal04
>  /signal/signal05
> +/signal/signal06
>  /signalfd/signalfd01
>  /signalfd4/signalfd4_01
>  /signalfd4/signalfd4_02
> diff --git a/testcases/kernel/syscalls/signal/Makefile
> b/testcases/kernel/syscalls/signal/Makefile
> index bd617d8..dad2a7d 100644
> --- a/testcases/kernel/syscalls/signal/Makefile
> +++ b/testcases/kernel/syscalls/signal/Makefile
> @@ -21,3 +21,5 @@ top_srcdir		?= ../../../..
>  include $(top_srcdir)/include/mk/testcases.mk
>  
>  include $(top_srcdir)/include/mk/generic_leaf_target.mk
> +
> +signal06: CFLAGS+=-pthread
> diff --git a/testcases/kernel/syscalls/signal/signal06.c
> b/testcases/kernel/syscalls/signal/signal06.c
> new file mode 100644
> index 0000000..479522b
> --- /dev/null
> +++ b/testcases/kernel/syscalls/signal/signal06.c
> @@ -0,0 +1,169 @@
> +/*
> + * Copyright (c) 2015   Author: Oleg Nesterov <oleg@redhat.com>
> + *                      Modify: Li Wang <liwang@redhat.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of version 2 of the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it would be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + * you should have received a copy of the GNU General Public License along
> + * with this program; if not, write the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> + */
> +
> +/*
> + * Description:
> + *
> + *      save_xstate_sig()->drop_init_fpu() doesn't look right.
> setup_rt_frame()
> + *      can fail after that, in this case the next setup_rt_frame()
> triggered
> + *      by SIGSEGV won't save fpu simply because the old state was lost.
> This
> + *      obviously mean that fpu won't be restored after sys_rt_sigreturn()
> from
> + *      SIGSEGV handler.
> + *
> + *      These commits fix the issue on v3.17-rc3-3 stable kernel:
> + *
> + *      commit df24fb859a4e200d9324e2974229fbb7adf00aef
> + * 		Author: Oleg Nesterov <oleg@redhat.com>
> + * 		Date:   Tue Sep 2 19:57:17 2014 +0200
> + *
> + *      commit 66463db4fc5605d51c7bb81d009d5bf30a783a2c
> + *               Author: Oleg Nesterov <oleg@redhat.com>
> + *               Date:   Tue Sep 2 19:57:13 2014 +0200
> + *
> + * Reproduce:
> + *	Test-case (needs -O2).
> + */
> +
> +#include <stdio.h>
> +#include <signal.h>
> +#include <unistd.h>
> +#include <sys/syscall.h>
> +#include <sys/mman.h>
> +#include <pthread.h>
> +#include <assert.h>
> +#include <errno.h>
> +
> +#include "test.h"
> +#include "linux_syscall_numbers.h"
> +
> +char *TCID = "signal06";
> +int TST_TOTAL = 5;
> +
> +#if __x86_64__
> +
> +#define LOOPS 10000
> +
> +volatile double D;
> +volatile int FLAGE;
> +
> +char altstack[4096 * 10] __attribute__((aligned(4096)));
> +
> +void test(double d)
> +{
> +	int loop = 0;
> +	int pid = getpid();
> +
> +	D = d;
> +	while (D == d && loop < LOOPS) {
> +		/* sys_tkill(pid, SIGHUP); asm to avoid save/reload
> +		 * fp regs around c call */
> +		asm ("" : : "a"(__NR_tkill), "D"(pid), "S"(SIGHUP));
> +		asm ("syscall" : : : "ax");
> +
> +		loop++;
> +	}
> +
> +	FLAGE = 1;
> +	tst_resm(TINFO, "loop = %d", loop);
> +
> +	if (loop == LOOPS) {
> +		tst_resm(TPASS, "%s call succeeded", TCID);
> +	} else {
> +		tst_resm(TFAIL, "Bug Reproduced!");
> +		tst_exit();
> +	}
> +}
> +
> +void sigh(int sig LTP_ATTRIBUTE_UNUSED)
> +{
> +}
> +
> +void *tfunc(void *arg LTP_ATTRIBUTE_UNUSED)
> +{
> +	FLAGE = 0;

^^ I moved this below to main loop, because you can get into situation, where test()
completes before tfunc() and then test just hangs (spins in tfunc() forever)

> +
> +	for (; ;) {
> +		TEST(mprotect(altstack, sizeof(altstack), PROT_READ));
> +		if (TEST_RETURN == -1)
> +			tst_brkm(TBROK | TRERRNO, NULL, "mprotect failed");

TRERRNO makes sense only for APIs like pthread_, which don't store
error code to errno, but return it directly.

#define TERRNO  0x100   /* Append errno information to output */
#define TTERRNO 0x200   /* Append TEST_ERRNO information to output */
#define TRERRNO 0x400   /* Capture errno information from TEST_RETURN to
                           output;

Regards,
Jan

> +
> +		TEST(mprotect(altstack, sizeof(altstack), PROT_READ|PROT_WRITE));
> +		if (TEST_RETURN == -1)
> +			tst_brkm(TBROK | TRERRNO, NULL, "mprotect failed");
> +
> +		if (FLAGE == 1)
> +			return NULL;
> +	}
> +}
> +
> +int main(int ac, char **av)
> +{
> +	int i, lc;
> +	pthread_t pt;
> +
> +	tst_parse_opts(ac, av, NULL, NULL);
> +
> +	stack_t st = {
> +		.ss_sp = altstack,
> +		.ss_size = sizeof(altstack),
> +		.ss_flags = SS_ONSTACK,
> +	};
> +
> +	struct sigaction sa = {
> +		.sa_handler = sigh,
> +	};
> +
> +	TEST(sigaction(SIGSEGV, &sa, NULL));
> +	if (TEST_RETURN == -1)
> +		tst_brkm(TBROK | TRERRNO, NULL,
> +				"SIGSEGV signal setup failed");
> +	sigaltstack(&st, NULL);
> +	sa.sa_flags = SA_ONSTACK;
> +
> +	TEST(sigaction(SIGHUP, &sa, NULL));
> +	if (TEST_RETURN == -1)
> +		tst_brkm(TBROK | TRERRNO, NULL,
> +				"SIGHUP signal setup failed");
> +
> +	for (lc = 0; TEST_LOOPING(lc); lc++) {
> +		tst_count = 0;
> +
> +		for (i = 0; i < TST_TOTAL; i++) {
> +
> +			TEST(pthread_create(&pt, NULL, tfunc, NULL));
> +			if (TEST_RETURN)
> +				tst_brkm(TBROK | TRERRNO, NULL,
> +						"pthread_create failed");
> +
> +			test(123.456);
> +
> +			TEST(pthread_join(pt, NULL));
> +			if (TEST_RETURN)
> +				tst_brkm(TBROK | TRERRNO, NULL,
> +						"pthread_join failed");
> +		}
> +	}
> +
> +	tst_exit();
> +}
> +
> +#else
> +int main(void)
> +{
> +	tst_brkm(TCONF, NULL, "Only test on x86_64.");
> +}
> +#endif
> --
> 1.8.3.1
> 
> 


More information about the Ltp mailing list