Skip to content

Commit 98b0bf0

Browse files
yang-weijiangbonzini
authored andcommitted
selftests: kvm: Use a shorter encoding to clear RAX
If debug_regs.c is built with newer binutils, the resulting binary is "optimized" by the assembler: asm volatile("ss_start: " "xor %%rax,%%rax\n\t" "cpuid\n\t" "movl $0x1a0,%%ecx\n\t" "rdmsr\n\t" : : : "rax", "ecx"); is translated to : 000000000040194e <ss_start>: 40194e: 31 c0 xor %eax,%eax <----- rax->eax? 401950: 0f a2 cpuid 401952: b9 a0 01 00 00 mov $0x1a0,%ecx 401957: 0f 32 rdmsr As you can see rax is replaced with eax in target binary code. This causes a difference is the length of xor instruction (2 Byte vs 3 Byte), and makes the hard-coded instruction length check fail: /* Instruction lengths starting at ss_start */ int ss_size[4] = { 3, /* xor */ <-------- 2 or 3? 2, /* cpuid */ 5, /* mov */ 2, /* rdmsr */ }; Encode the shorter version directly and, while at it, fix the "clobbers" of the asm. Cc: [email protected] Signed-off-by: Yang Weijiang <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent e792415 commit 98b0bf0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tools/testing/selftests/kvm/x86_64/debug_regs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ static void guest_code(void)
4040

4141
/* Single step test, covers 2 basic instructions and 2 emulated */
4242
asm volatile("ss_start: "
43-
"xor %%rax,%%rax\n\t"
43+
"xor %%eax,%%eax\n\t"
4444
"cpuid\n\t"
4545
"movl $0x1a0,%%ecx\n\t"
4646
"rdmsr\n\t"
47-
: : : "rax", "ecx");
47+
: : : "eax", "ebx", "ecx", "edx");
4848

4949
/* DR6.BD test */
5050
asm volatile("bd_start: mov %%dr0, %%rax" : : : "rax");

0 commit comments

Comments
 (0)