3

My assembly code raises Illegal Instruction when calls xbegin.

Is there any problem?

Here is my code.

main.c

if ( rtm_begin() == 0 ) {
    //do something.
}

rtm.S

rtm_begin:   
   xbegin 1f   
   mov $0, %rax      
   retq

1:
   mov $-1, %rax
   retq

   .globl rtm_end
   .type rtm_end, @function
   .section .text
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
karoha
  • 73
  • 3

1 Answers1

3

First you need to check whether your version of assembler supports the TSX instructions or not.

Then it could be that your CPU doesn't have TSX feature. As per Intel® 64 and IA-32 architectures software developer’s manual, ch.16.3.1.2 Detection of RTM Support:

A processor supports RTM execution if CPUID.07H.EBX.RTM [bit 11] = 1. An application must check if the processor supports RTM before it uses the RTM instructions (XBEGI N, XEND, XABORT). These instructions will generate a #UD exception when used on a processor that does not support RTM.

Also to mitigate Zombieload 2 vulnerability, TSX could be disabled by the OS (related info for Windows, for Linux)

Renat
  • 7,718
  • 2
  • 20
  • 34
  • Both your Zombieload 2 links are for Windows. – Peter Cordes Dec 06 '19 at 08:56
  • 2
    Thank you for the link; as I expected it has much more detail about the mitigation strategy, e.g. the CPUID feature bit can still show as set even though microcode updates unconditionally disable the HLE part. (/sigh can't we ever have nice things? Intel had to disable TSX twice in HSW and in BDW after finding bugs, now having to (optionally) disable it again for security bugs. I haven't looked yet but hopefully a simple HW fix like for Meltdown (squashing faulty load results to `0` or something) can let TSX be enabled.) – Peter Cordes Dec 06 '19 at 09:05