linux/tools/testing/selftests/kvm
Yang Weijiang 98b0bf0273 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>
2020-08-17 13:45:22 -04:00
..
include KVM: selftests: do not substitute SVM/VMX check with KVM_CAP_NESTED_STATE check 2020-06-11 12:35:17 -04:00
lib KVM: selftests: do not substitute SVM/VMX check with KVM_CAP_NESTED_STATE check 2020-06-11 12:35:17 -04:00
s390x selftests: KVM: s390: check for registers to NOT change on reset 2020-03-16 17:59:09 +01:00
x86_64 selftests: kvm: Use a shorter encoding to clear RAX 2020-08-17 13:45:22 -04:00
.gitignore KVM: selftests: Add x86_64/debug_regs to .gitignore 2020-06-08 07:59:42 -04:00
clear_dirty_log_test.c kvm: selftests: Support dirty log initial-all-set test 2020-03-16 17:57:41 +01:00
config selftests: kvm: Adding config fragments 2019-08-09 16:52:38 +02:00
demand_paging_test.c KVM: selftests: Rework timespec functions and usage 2020-03-18 14:08:56 +01:00
dirty_log_test.c selftests: kvm: Uses TEST_FAIL in tests/utilities 2020-03-16 17:59:11 +01:00
kvm_create_max_vcpus.c KVM: selftests: Convert some printf's to pr_info's 2020-03-16 17:57:07 +01:00
Makefile KVM: selftests: Fix build with "make ARCH=x86_64" 2020-06-05 11:15:55 -04:00
set_memory_region_test.c selftests: kvm/set_memory_region_test: do not check RIP if the guest shuts down 2020-04-21 09:13:13 -04:00
steal_time.c KVM: selftests: Rework timespec functions and usage 2020-03-18 14:08:56 +01:00