From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andy Lutomirski Subject: Re: [PATCH 2/4] selftests/sigaltstack: Fix the sas test on old kernels Date: Sun, 8 May 2016 18:32:34 -0700 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: In-Reply-To: Sender: linux-api-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Stas Sergeev Cc: Thomas Gleixner , Denys Vlasenko , Shuah Khan , Pavel Emelyanov , Al Viro , Borislav Petkov , Andrew Morton , Brian Gerst , Linux API , Linus Torvalds , "linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" , Oleg Nesterov , "H. Peter Anvin" , X86 ML , Peter Zijlstra List-Id: linux-api@vger.kernel.org On May 7, 2016 8:02 AM, "Stas Sergeev" wrote: > > 03.05.2016 20:31, Andy Lutomirski =D0=BF=D0=B8=D1=88=D0=B5=D1=82: > >> The handling for old kernels was wrong. Fix it. >> >> Reported-by: Ingo Molnar >> Cc: Stas Sergeev >> Cc: Al Viro >> Cc: Andrew Morton >> Cc: Andy Lutomirski >> Cc: Borislav Petkov >> Cc: Brian Gerst >> Cc: Denys Vlasenko >> Cc: H. Peter Anvin >> Cc: Linus Torvalds >> Cc: Oleg Nesterov >> Cc: Pavel Emelyanov >> Cc: Peter Zijlstra >> Cc: Shuah Khan >> Cc: Thomas Gleixner >> Cc: linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org >> Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org >> Signed-off-by: Andy Lutomirski >> --- >> tools/testing/selftests/sigaltstack/sas.c | 21 ++++++++++++++-----= -- >> 1 file changed, 14 insertions(+), 7 deletions(-) >> >> diff --git a/tools/testing/selftests/sigaltstack/sas.c b/tools/testi= ng/selftests/sigaltstack/sas.c >> index 57da8bfde60b..a98c3ef8141f 100644 >> --- a/tools/testing/selftests/sigaltstack/sas.c >> +++ b/tools/testing/selftests/sigaltstack/sas.c >> @@ -15,6 +15,7 @@ >> #include >> #include >> #include >> +#include >> #ifndef SS_AUTODISARM >> #define SS_AUTODISARM (1 << 4) >> @@ -117,13 +118,19 @@ int main(void) >> stk.ss_flags =3D SS_ONSTACK | SS_AUTODISARM; >> err =3D sigaltstack(&stk, NULL); >> if (err) { >> - perror("[FAIL]\tsigaltstack(SS_ONSTACK | SS_AUTODISA= RM)"); >> - stk.ss_flags =3D SS_ONSTACK; >> - } >> - err =3D sigaltstack(&stk, NULL); >> - if (err) { >> - perror("[FAIL]\tsigaltstack(SS_ONSTACK)"); >> - return EXIT_FAILURE; >> + if (errno =3D=3D EINVAL) { >> + printf("[NOTE]\tThe running kernel doesn't s= upport SS_AUTODISARM\n"); >> + /* >> + * If test cases for the !SS_AUTODISARM vari= ant were >> + * added, we could still run them. We don't= have any >> + * test cases like that yet, so just exit an= d report >> + * success. >> + */ > > But that was the point, please see how it handles the > old kernels: > > $ ./sas > [FAIL] sigaltstack(SS_ONSTACK | SS_AUTODISARM): Invalid argument > [RUN] signal USR1 > [FAIL] ss_flags=3D1, should be SS_DISABLE > [RUN] switched to user ctx > [RUN] signal USR2 > [FAIL] sigaltstack re-used > [FAIL] Stack corrupted > [RUN] Aborting This is useful as a demonstration of why the feature is useful, but it doesn't indicate that anything is wrong with old kernels per she. That's why I changed it to simply report that the feature is missing.