From: Cyril Hrubis <chrubis@suse.cz>
To: Joerg.Vehlow@aox.de
Cc: kernel-team <kernel-team@android.com>, LTP List <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH v1] syscalls/signal06: add volatile to loop variable
Date: Fri, 19 Aug 2022 11:21:27 +0200 [thread overview]
Message-ID: <Yv9WF+Wri0M4GBQ9@yuki> (raw)
In-Reply-To: <18f40cb4-1641-4f96-4b0c-85bee0df9e1f@jv-coder.de>
Hi!
> > It's problem with the inline assembly in the body of the while loop, the
> > call to the syscall changes the register value that is used for the D
> > variable in the case of clang, so the loop exits prematurely. We have to
> > add cx register to the clobber list for that asm statement so that
> > compiler knows that it's changed by the assembly.
> >
> > Interfacing assembly with C is a bit tricky since you have to explain
> > to compiler which registers are changed from the assembly otherwise the
> > results are undefined.
> >
> > The patch should look like:
> >
> > diff --git a/testcases/kernel/syscalls/signal/signal06.c b/testcases/kernel/syscalls/signal/signal06.c
> > index 64f886ee3..78efd0fb9 100644
> > --- a/testcases/kernel/syscalls/signal/signal06.c
> > +++ b/testcases/kernel/syscalls/signal/signal06.c
> > @@ -73,7 +73,7 @@ void test(void)
> > /* 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");
> > + asm ("syscall" : : : "ax", "cx");
> Why is this even split up into two asm instructions?
> I guess there is nothing, that prevents the compiler from reordering the
> asm instructions, because it does not know, that they have side effects
> (they are not marked volatile).
>
> asm volatile ("syscall" : : "a"(__NR_tkill), "D"(pid), "S"(SIGHUP):
> "rax", "rcx", "r11");
>
>
> I am not sure if there is any good reason, to split this up into two asm
> instructions and if there is a good reason, to use the short names of
> the registers.
I was wondering too, I guess it's a direct copy of a reproducer from a
kernel commit see:
https://lore.kernel.org/lkml/1414436240-13879-8-git-send-email-kamal@canonical.com/
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2022-08-19 9:19 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-12 17:39 [LTP] [PATCH v1] syscalls/signal06: add volatile to loop variable Edward Liaw via ltp
2022-07-13 12:48 ` Petr Vorel
2022-07-19 10:20 ` Cyril Hrubis
2022-07-27 21:37 ` Edward Liaw via ltp
2022-08-11 15:24 ` Edward Liaw via ltp
2022-08-11 15:33 ` Cyril Hrubis
2022-08-16 12:43 ` Petr Vorel
2022-08-16 23:00 ` Edward Liaw via ltp
2022-08-17 9:12 ` Petr Vorel
2022-08-17 15:04 ` Edward Liaw via ltp
2022-08-18 21:18 ` Edward Liaw via ltp
2022-08-19 8:12 ` Petr Vorel
2022-08-19 8:41 ` Cyril Hrubis
2022-08-19 9:02 ` Cyril Hrubis
2022-08-19 9:14 ` Joerg Vehlow
2022-08-19 9:21 ` Cyril Hrubis [this message]
2022-08-19 10:40 ` Petr Vorel
2022-08-19 18:13 ` Edward Liaw via ltp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Yv9WF+Wri0M4GBQ9@yuki \
--to=chrubis@suse.cz \
--cc=Joerg.Vehlow@aox.de \
--cc=kernel-team@android.com \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).