Subject: Re: TM Bad Thing exception easily raised from userspace

From: Segher Boessenkool <[email-masked]>
Date: Fri, 19 Aug 2016 15:23:31 -0500

Completely off-topic, but...

On Fri, Aug 19, 2016 at 07:21:44PM +0200, Laurent Dufour wrote:
>     asm __volatile__(
> 	"li		3,1		;"
> 	"tbegin.			;"
> 	"beq		1f		;"
> 	"li		3,0		;"
> 	"tsuspend.			;"
> 	"1:				;"
> 	"std		3, %[ret]	;"
> 	: [ret]"=m"(ret)
> 	:
> 	: "memory", "3");

This asm clobbers CR0, so you should add a "cc" or "cr0" clobber here.
When you use "m" you need "%X" as well, i.e.
	std%X[ret] 3,%[ret]

(Nowadays you only need "%U" if you use "m<>", but you still need "%X".
Come to think of it, the kernel supports really old GCC, right?  So you
need "std%U[ret]%X[ret] 3,%[ret]").

>     asm __volatile__(
> 	"tbegin.			;"
> 	"beq		1f		;"
> 	"li		3,0		;"
> 	"std		3,0(3)		;" /* Oups ! */
> 	"1:				;"
> 	"tend.				;"
> 	);

Here "cc" (or "cr0"), too.

Segher