qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Ilya Leoshkevich <iii@linux.ibm.com>
To: David Hildenbrand <david@redhat.com>,
	Richard Henderson <richard.henderson@linaro.org>,
	Laurent Vivier <laurent@vivier.eu>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>,
	qemu-s390x@nongnu.org, qemu-devel@nongnu.org,
	Andreas Krebbel <krebbel@linux.ibm.com>
Subject: Re: [PATCH 2/2] tests/tcg/s390x: Test SIGILL handling
Date: Fri, 21 May 2021 12:42:49 +0200	[thread overview]
Message-ID: <cc4379ffbf73eb10ee29d91e28384b0bd2dd088b.camel@linux.ibm.com> (raw)
In-Reply-To: <6470e715-60d5-992c-e5db-1b54d61ef92e@redhat.com>

On Fri, 2021-05-21 at 09:54 +0200, David Hildenbrand wrote:
> On 21.05.21 05:01, Ilya Leoshkevich wrote:
> > Verify that s390x-specific uc_mcontext.psw.addr is reported
> > correctly.
> > 
> > Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> > ---
> >   tests/tcg/s390x/Makefile.target |  1 +
> >   tests/tcg/s390x/sigill.c        | 41
> > +++++++++++++++++++++++++++++++++
> >   2 files changed, 42 insertions(+)
> >   create mode 100644 tests/tcg/s390x/sigill.c
> > 
> > diff --git a/tests/tcg/s390x/Makefile.target
> > b/tests/tcg/s390x/Makefile.target
> > index 241ef28f61..8699d829a5 100644
> > --- a/tests/tcg/s390x/Makefile.target
> > +++ b/tests/tcg/s390x/Makefile.target
> > @@ -8,3 +8,4 @@ TESTS+=exrl-trtr
> >   TESTS+=pack
> >   TESTS+=mvo
> >   TESTS+=mvc
> > +TESTS+=sigill
> > diff --git a/tests/tcg/s390x/sigill.c b/tests/tcg/s390x/sigill.c
> > new file mode 100644
> > index 0000000000..f8021dc6af
> > --- /dev/null
> > +++ b/tests/tcg/s390x/sigill.c
> > @@ -0,0 +1,41 @@
> > +#include <assert.h>
> > +#include <signal.h>
> > +#include <string.h>
> > +#include <ucontext.h>
> > +#include <unistd.h>
> > +
> > +extern char expected_si_addr[];
> > +extern char expected_psw_addr[];
> 
> Why "extern" ? For the magic inline asm below to work?

Yes - it cannot be static, because AFAIK there is no such thing as
static variable declaration (one can only define static variables).

> > +
> > +static void handle_signal(int sig, siginfo_t *info, void
> > *ucontext)
> > +{
> > +    if (sig != SIGILL) {
> > +        _exit(1);
> > +    }
> > +
> > +    if (info->si_addr != expected_si_addr) {
> > +        _exit(2);
> > +    }
> > +
> > +    if (((ucontext_t *)ucontext)->uc_mcontext.psw.addr !=
> > +            (unsigned long)expected_psw_addr) {
> > +        _exit(3);
> > +    }
> > +}
> > +
> > +int main(void)
> > +{
> > +    struct sigaction act;
> > +
> > +    memset(&act, 0, sizeof(act));
> > +    act.sa_sigaction = handle_signal;
> > +    act.sa_flags = SA_SIGINFO;
> > +
> > +    int ret = sigaction(SIGILL, &act, NULL);
> 
> Mixing code and declaration.

Ouch, will fix.

> > +    assert(ret == 0);
> > +
> > +    asm volatile("expected_si_addr:\t.byte\t0x00,0x00\n"
> > +                 "expected_psw_addr:");
> 
> At least I am confused how the right values actually end up in 
> expected_si_addr and expected_psw_addr.
> 
> Can we maybe add a comment? This looks quite hacky ;)

This whole construction is roughly the same as having sigill.s file
with:

.globl expected_si_addr
expected_si_addr: .byte 0,0
.globl expected_psw_addr
expected_psw_addr: br 14

and sigill.h file with:

void expected_si_addr(void);
extern char expected_psw_addr[];

Doing it this way would complicate the build, so I thought it would be
better to just put everything into a single file.



  reply	other threads:[~2021-05-21 10:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-21  3:01 [PATCH 0/2] Fix SIGILL psw.addr reporting Ilya Leoshkevich
2021-05-21  3:01 ` [PATCH 1/2] target/s390x: " Ilya Leoshkevich
2021-05-21  7:49   ` David Hildenbrand
2021-05-21  3:01 ` [PATCH 2/2] tests/tcg/s390x: Test SIGILL handling Ilya Leoshkevich
2021-05-21  7:54   ` David Hildenbrand
2021-05-21 10:42     ` Ilya Leoshkevich [this message]
2021-05-21  3:09 ` [PATCH 0/2] Fix SIGILL psw.addr reporting no-reply
2021-05-21  7:42 ` David Hildenbrand
2021-05-21 10:45   ` Ilya Leoshkevich
2021-05-21 10:59     ` Cornelia Huck

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=cc4379ffbf73eb10ee29d91e28384b0bd2dd088b.camel@linux.ibm.com \
    --to=iii@linux.ibm.com \
    --cc=borntraeger@de.ibm.com \
    --cc=david@redhat.com \
    --cc=krebbel@linux.ibm.com \
    --cc=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /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).