Re: [kvm-unit-tests PATCH] powerpc: Add emulator test for the lswi instruction

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
> ---
>  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();
> 

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux