linux/tools/testing/selftests/kvm/x86_64
Sean Christopherson 394265079b KVM: selftests: Compare insn opcodes directly in fix_hypercall_test
Directly compare the expected versus observed hypercall instructions when
verifying that KVM patched in the native hypercall (FIX_HYPERCALL_INSN
quirk enabled).  gcc rightly complains that doing a 4-byte memcpy() with
an "unsigned char" as the source generates an out-of-bounds accesses.

Alternatively, "exp" and "obs" could be declared as 3-byte arrays, but
there's no known reason to copy locally instead of comparing directly.

In function ‘assert_hypercall_insn’,
    inlined from ‘guest_main’ at x86_64/fix_hypercall_test.c:91:2:
x86_64/fix_hypercall_test.c:63:9: error: array subscript ‘unsigned int[0]’
 is partly outside array bounds of ‘unsigned char[1]’ [-Werror=array-bounds]
   63 |         memcpy(&exp, exp_insn, sizeof(exp));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
x86_64/fix_hypercall_test.c: In function ‘guest_main’:
x86_64/fix_hypercall_test.c:42:22: note: object ‘vmx_hypercall_insn’ of size 1
   42 | extern unsigned char vmx_hypercall_insn;
      |                      ^~~~~~~~~~~~~~~~~~
x86_64/fix_hypercall_test.c:25:22: note: object ‘svm_hypercall_insn’ of size 1
   25 | extern unsigned char svm_hypercall_insn;
      |                      ^~~~~~~~~~~~~~~~~~
In function ‘assert_hypercall_insn’,
    inlined from ‘guest_main’ at x86_64/fix_hypercall_test.c:91:2:
x86_64/fix_hypercall_test.c:64:9: error: array subscript ‘unsigned int[0]’
 is partly outside array bounds of ‘unsigned char[1]’ [-Werror=array-bounds]
   64 |         memcpy(&obs, obs_insn, sizeof(obs));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
x86_64/fix_hypercall_test.c: In function ‘guest_main’:
x86_64/fix_hypercall_test.c:25:22: note: object ‘svm_hypercall_insn’ of size 1
   25 | extern unsigned char svm_hypercall_insn;
      |                      ^~~~~~~~~~~~~~~~~~
x86_64/fix_hypercall_test.c:42:22: note: object ‘vmx_hypercall_insn’ of size 1
   42 | extern unsigned char vmx_hypercall_insn;
      |                      ^~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [../lib.mk:135: tools/testing/selftests/kvm/x86_64/fix_hypercall_test] Error 1

Fixes: 6c2fa8b20d ("selftests: KVM: Test KVM_X86_QUIRK_FIX_HYPERCALL_INSN")
Cc: Oliver Upton <oliver.upton@linux.dev>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Oliver Upton <oliver.upton@linux.dev>
Message-Id: <20220928233652.783504-3-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2022-09-30 06:38:02 -04:00
..
amx_test.c KVM: selftests: Clean up requirements for XFD-aware XSAVE features 2022-07-13 18:14:24 -07:00
cpuid_test.c KVM: selftests: Set input function/index in raw CPUID helper(s) 2022-07-13 18:14:21 -07:00
cr4_cpuid_sync_test.c KVM: selftests: Use this_cpu_has() in CR4/CPUID sync test 2022-07-13 18:14:21 -07:00
debug_regs.c KVM: selftests: Add TEST_REQUIRE macros to reduce skipping copy+paste 2022-06-11 11:47:29 -04:00
emulator_error_test.c KVM: selftests: Add and use helper to set vCPU's CPUID maxphyaddr 2022-07-13 18:14:17 -07:00
evmcs_test.c KVM: selftests: Use kvm_cpu_has() for nested VMX checks 2022-07-13 18:14:10 -07:00
fix_hypercall_test.c KVM: selftests: Compare insn opcodes directly in fix_hypercall_test 2022-09-30 06:38:02 -04:00
get_msr_index_features.c KVM: selftests: Add TEST_REQUIRE macros to reduce skipping copy+paste 2022-06-11 11:47:29 -04:00
hyperv_clock.c KVM: selftests: Fix filename reporting in guest asserts 2022-07-13 18:14:08 -07:00
hyperv_cpuid.c KVM: selftests: Make get_supported_cpuid() returns "const" 2022-07-13 18:14:20 -07:00
hyperv_features.c KVM: selftests: Use vCPU's CPUID directly in Hyper-V test 2022-07-13 18:14:18 -07:00
hyperv_svm_test.c KVM: selftests: Use kvm_cpu_has() for nested SVM checks 2022-07-13 18:14:10 -07:00
kvm_clock_test.c KVM: selftests: Fix filename reporting in guest asserts 2022-07-13 18:14:08 -07:00
kvm_pv_test.c KVM: selftests: Use vcpu_get_cpuid_entry() in PV features test (sort of) 2022-07-13 18:14:18 -07:00
max_vcpuid_cap_test.c KVM: selftests: Rename vm_create() => vm_create_barebones(), drop param 2022-06-11 11:46:33 -04:00
mmio_warning_test.c KVM: selftests: Sanity check input to ioctls() at build time 2022-06-11 11:48:09 -04:00
monitor_mwait_test.c KVM: selftests: Use vcpu_clear_cpuid_feature() in monitor_mwait_test 2022-07-13 18:14:17 -07:00
nx_huge_pages_test.c KVM: selftests: Test disabling NX hugepages on a VM 2022-06-24 04:51:51 -04:00
nx_huge_pages_test.sh KVM: selftests: Test disabling NX hugepages on a VM 2022-06-24 04:51:51 -04:00
platform_info_test.c KVM: selftests: Add TEST_REQUIRE macros to reduce skipping copy+paste 2022-06-11 11:47:29 -04:00
pmu_event_filter_test.c KVM: selftests: Drop unnecessary use of kvm_get_supported_cpuid_index() 2022-07-13 18:14:22 -07:00
set_boot_cpu_id.c KVM: selftests: Fix filename reporting in guest asserts 2022-07-13 18:14:08 -07:00
set_sregs_test.c KVM: selftests: Add framework to query KVM CPUID bits 2022-07-13 18:14:09 -07:00
sev_migrate_tests.c KVM: selftests: Use kvm_cpu_has() in the SEV migration test 2022-07-13 18:14:09 -07:00
smm_test.c KVM: selftests: Use this_cpu_has() to detect SVM support in L1 2022-07-13 18:14:22 -07:00
state_test.c KVM: selftests: Use this_cpu_has() to detect SVM support in L1 2022-07-13 18:14:22 -07:00
svm_int_ctl_test.c KVM: selftests: Use kvm_cpu_has() for nested SVM checks 2022-07-13 18:14:10 -07:00
svm_nested_soft_inject_test.c KVM: selftests: Use kvm_cpu_has() for nSVM soft INT injection test 2022-07-13 18:14:13 -07:00
svm_vmcall_test.c KVM: selftests: Use kvm_cpu_has() for nested SVM checks 2022-07-13 18:14:10 -07:00
sync_regs_test.c KVM: selftests: Add TEST_REQUIRE macros to reduce skipping copy+paste 2022-06-11 11:47:29 -04:00
triple_fault_event_test.c KVM: selftests: Use kvm_cpu_has() for nested VMX checks 2022-07-13 18:14:10 -07:00
tsc_msrs_test.c KVM: selftests: Fix filename reporting in guest asserts 2022-07-13 18:14:08 -07:00
tsc_scaling_sync.c KVM: selftests: Add TEST_REQUIRE macros to reduce skipping copy+paste 2022-06-11 11:47:29 -04:00
ucna_injection_test.c KVM: selftests: Add a self test for CMCI and UCNA emulations. 2022-06-24 04:52:04 -04:00
userspace_io_test.c KVM: selftests: Fix filename reporting in guest asserts 2022-07-13 18:14:08 -07:00
userspace_msr_exit_test.c KVM: selftests: Fix filename reporting in guest asserts 2022-07-13 18:14:08 -07:00
vmx_apic_access_test.c KVM: selftests: Use kvm_cpu_has() for nested VMX checks 2022-07-13 18:14:10 -07:00
vmx_close_while_nested_test.c KVM: selftests: Use kvm_cpu_has() for nested VMX checks 2022-07-13 18:14:10 -07:00
vmx_dirty_log_test.c KVM: selftests: Use kvm_cpu_has() for nested VMX checks 2022-07-13 18:14:10 -07:00
vmx_exception_with_invalid_guest_state.c KVM: selftests: Add TEST_REQUIRE macros to reduce skipping copy+paste 2022-06-11 11:47:29 -04:00
vmx_invalid_nested_guest_state.c KVM: selftests: Use kvm_cpu_has() for nested VMX checks 2022-07-13 18:14:10 -07:00
vmx_msrs_test.c KVM: selftests: Verify VMX MSRs can be restored to KVM-supported values 2022-07-28 13:25:24 -04:00
vmx_nested_tsc_scaling_test.c KVM: selftests: Use kvm_cpu_has() for nested VMX checks 2022-07-13 18:14:10 -07:00
vmx_pmu_caps_test.c KVM: selftests: Test all possible "invalid" PERF_CAPABILITIES.LBR_FMT vals 2022-08-10 15:08:29 -04:00
vmx_preemption_timer_test.c KVM: selftests: Use kvm_cpu_has() for nested VMX checks 2022-07-13 18:14:10 -07:00
vmx_set_nested_state_test.c KVM: selftests: Use vcpu_{set,clear}_cpuid_feature() in nVMX state test 2022-07-13 18:14:19 -07:00
vmx_tsc_adjust_test.c KVM: selftests: Use kvm_cpu_has() for nested VMX checks 2022-07-13 18:14:10 -07:00
xapic_ipi_test.c KVM: selftests: Purge vm+vcpu_id == vcpu silliness 2022-06-11 11:47:22 -04:00
xapic_state_test.c KVM: selftests: Use vcpu_clear_cpuid_feature() to clear x2APIC 2022-07-13 18:14:20 -07:00
xen_shinfo_test.c KVM: selftests: Fix filename reporting in guest asserts 2022-07-13 18:14:08 -07:00
xen_vmcall_test.c KVM: selftests: Fix filename reporting in guest asserts 2022-07-13 18:14:08 -07:00
xss_msr_test.c KVM: selftests: Use kvm_cpu_has() for XSAVES in XSS MSR test 2022-07-13 18:14:11 -07:00