From: Thomas Huth <thuth@redhat.com>
To: kvm@vger.kernel.org, lvivier@redhat.com
Cc: kvm-ppc@vger.kernel.org, pbonzini@redhat.com, drjones@redhat.com
Subject: Re: [kvm-unit-tests PATCH] powerpc: Add emulator test for the lswi instruction
Date: Thu, 14 Apr 2016 11:02:07 +0000 [thread overview]
Message-ID: <570F78AF.2060102@redhat.com> (raw)
In-Reply-To: <1460575886-12569-1-git-send-email-thuth@redhat.com>
On 13.04.2016 21:31, Thomas Huth wrote:
> This test checks some special cases of the lswi instruction. Test
> works fine on real hardware, but in QEMU, this reveals a bug with
> the final "don't overwrite RA" test (RA gets destroyed since the
> check in QEMU is still wrong).
> The code is based on the lswx test by Laurent Vivier.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> powerpc/emulator.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 128 insertions(+)
...
> + /* check wrap around doesn't break RA */
> + asm volatile ("mr r28,r1\n"
> + "mr r29,r2\n"
> + "li r31,-1\n"
> + "mr r2,r31\n"
Ugh, I just had to discover that overwriting r2 is a bad idea here: The
exception vector code in cstart64.S depends on r2 pointing to the GOT
(when doing the "LOAD_REG_ADDR(r0, call_handler)"), so when an
(expected) exception occurs during lswi, the handler crashes in an
endless loop :-/
So please ignore this patch, I'll send a new version.
> + "mr r0,r31\n"
> + "mr r1, %[addr]\n"
> + ".long 0x7fe184aa\n" /* lswi r31, r1, 16 */
> + "std r31, 0*8(%[regs])\n"
> + "std r0, 1*8(%[regs])\n"
> + "std r1, 2*8(%[regs])\n"
> + "std r2, 3*8(%[regs])\n"
> + "mr r1,r28\n"
> + "mr r2,r29\n"
> + ::
> + [addr] "r" (addr),
> + [regs] "r" (regs)
> + :
> + /* loading four registers from r31 wraps around to r2,
> + * r1 is saved to r29, as adding it to the clobber
> + * list doesn't protect it
> + */
> + "r31", "r0", "r28", "r29", "memory");
> +
> + /* doc says it is invalid, real proc stops when it comes to
> + * overwrite the register.
> + * In all the cases, the register must stay untouched
> + */
> + report("Don't overwrite RA", regs[2] = (uint64_t)addr);
> +
> + report_prefix_pop();
> +}
> +
> /*
> * lswx: Load String Word Indexed X-form
> *
> @@ -234,6 +361,7 @@ int main(int argc, char **argv)
>
> test_64bit();
> test_illegal();
> + test_lswi();
> test_lswx();
>
> report_prefix_pop();
>
WARNING: multiple messages have this Message-ID (diff)
From: Thomas Huth <thuth@redhat.com>
To: kvm@vger.kernel.org, lvivier@redhat.com
Cc: kvm-ppc@vger.kernel.org, pbonzini@redhat.com, drjones@redhat.com
Subject: Re: [kvm-unit-tests PATCH] powerpc: Add emulator test for the lswi instruction
Date: Thu, 14 Apr 2016 13:02:07 +0200 [thread overview]
Message-ID: <570F78AF.2060102@redhat.com> (raw)
In-Reply-To: <1460575886-12569-1-git-send-email-thuth@redhat.com>
On 13.04.2016 21:31, Thomas Huth wrote:
> This test checks some special cases of the lswi instruction. Test
> works fine on real hardware, but in QEMU, this reveals a bug with
> the final "don't overwrite RA" test (RA gets destroyed since the
> check in QEMU is still wrong).
> The code is based on the lswx test by Laurent Vivier.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> powerpc/emulator.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 128 insertions(+)
...
> + /* check wrap around doesn't break RA */
> + asm volatile ("mr r28,r1\n"
> + "mr r29,r2\n"
> + "li r31,-1\n"
> + "mr r2,r31\n"
Ugh, I just had to discover that overwriting r2 is a bad idea here: The
exception vector code in cstart64.S depends on r2 pointing to the GOT
(when doing the "LOAD_REG_ADDR(r0, call_handler)"), so when an
(expected) exception occurs during lswi, the handler crashes in an
endless loop :-/
So please ignore this patch, I'll send a new version.
> + "mr r0,r31\n"
> + "mr r1, %[addr]\n"
> + ".long 0x7fe184aa\n" /* lswi r31, r1, 16 */
> + "std r31, 0*8(%[regs])\n"
> + "std r0, 1*8(%[regs])\n"
> + "std r1, 2*8(%[regs])\n"
> + "std r2, 3*8(%[regs])\n"
> + "mr r1,r28\n"
> + "mr r2,r29\n"
> + ::
> + [addr] "r" (addr),
> + [regs] "r" (regs)
> + :
> + /* loading four registers from r31 wraps around to r2,
> + * r1 is saved to r29, as adding it to the clobber
> + * list doesn't protect it
> + */
> + "r31", "r0", "r28", "r29", "memory");
> +
> + /* doc says it is invalid, real proc stops when it comes to
> + * overwrite the register.
> + * In all the cases, the register must stay untouched
> + */
> + report("Don't overwrite RA", regs[2] == (uint64_t)addr);
> +
> + report_prefix_pop();
> +}
> +
> /*
> * lswx: Load String Word Indexed X-form
> *
> @@ -234,6 +361,7 @@ int main(int argc, char **argv)
>
> test_64bit();
> test_illegal();
> + test_lswi();
> test_lswx();
>
> report_prefix_pop();
>
next prev parent reply other threads:[~2016-04-14 11:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-13 19:31 [kvm-unit-tests PATCH] powerpc: Add emulator test for the lswi instruction Thomas Huth
2016-04-13 19:31 ` Thomas Huth
2016-04-14 11:02 ` Thomas Huth [this message]
2016-04-14 11:02 ` Thomas Huth
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=570F78AF.2060102@redhat.com \
--to=thuth@redhat.com \
--cc=drjones@redhat.com \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.