]> git.baikalelectronics.ru Git - kernel.git/commit
selftests: kvm: Use a shorter encoding to clear RAX
authorYang Weijiang <weijiang.yang@intel.com>
Fri, 14 Aug 2020 13:21:05 +0000 (21:21 +0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 17 Aug 2020 17:45:22 +0000 (13:45 -0400)
commitcb9f391ea8e8d39ae81adc741bc82f0ce0f4e439
treea4758c1841192d94ac12704a772b2879ab326e22
parent58eb6c3685edf11de8ec1d162457acac31c9dc61
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: stable@vger.kernel.org
Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/x86_64/debug_regs.c