linux/tools/testing/selftests/kvm
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
..
aarch64 Merge tag 'kvmarm-5.20' of git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm into HEAD 2022-08-01 03:24:12 -04:00
include KVM: selftests: Skip tests that require EPT when it is not available 2022-09-27 07:58:03 -04:00
lib KVM: selftests: Implement memcmp(), memcpy(), and memset() for guest use 2022-09-30 06:38:02 -04:00
s390x KVM: selftests: Fix filename reporting in guest asserts 2022-07-13 18:14:08 -07:00
x86_64 KVM: selftests: Compare insn opcodes directly in fix_hypercall_test 2022-09-30 06:38:02 -04:00
.gitignore KVM: selftests: Verify VMX MSRs can be restored to KVM-supported values 2022-07-28 13:25:24 -04:00
access_tracking_perf_test.c KVM: selftests: replace assertion with warning in access_tracking_perf_test 2022-09-30 06:38:00 -04:00
config selftests: kvm: Adding config fragments 2019-08-09 16:52:38 +02:00
demand_paging_test.c KVM: selftests: Purge vm+vcpu_id == vcpu silliness 2022-06-11 11:47:22 -04:00
dirty_log_perf_test.c KVM: selftests: Add an option to run vCPUs while disabling dirty logging 2022-07-28 13:22:24 -04:00
dirty_log_test.c KVM: selftests: Add kvm_has_cap() to provide syntactic sugar 2022-06-11 11:47:28 -04:00
hardware_disable_test.c KVM: selftests: Move per-VM/per-vCPU nr pages calculation to __vm_create() 2022-06-11 11:47:26 -04:00
kvm_binary_stats_test.c selftests: KVM: Add exponent check for boolean stats 2022-08-01 08:01:23 -04:00
kvm_create_max_vcpus.c KVM: selftests: Add TEST_REQUIRE macros to reduce skipping copy+paste 2022-06-11 11:47:29 -04:00
kvm_page_table_test.c KVM: selftests: Drop @num_percpu_pages from __vm_create_with_vcpus() 2022-06-11 11:47:25 -04:00
Makefile KVM: selftests: Implement memcmp(), memcpy(), and memset() for guest use 2022-09-30 06:38:02 -04:00
max_guest_memory_test.c KVM: selftests: Open code and drop 'struct kvm_vm' accessors 2022-06-11 11:47:24 -04:00
memslot_modification_stress_test.c KVM: selftests: Open code and drop 'struct kvm_vm' accessors 2022-06-11 11:47:24 -04:00
memslot_perf_test.c KVM: selftests: Fix filename reporting in guest asserts 2022-07-13 18:14:08 -07:00
rseq_test.c selftests: kvm: Fix a compile error in selftests/kvm/rseq_test.c 2022-09-22 17:02:20 -04:00
set_memory_region_test.c KVM: selftests: Fix filename reporting in guest asserts 2022-07-13 18:14:08 -07:00
settings selftests: kvm: Raise the default timeout to 120 seconds 2021-02-09 08:17:08 -05:00
steal_time.c KVM: selftests: Use kvm_cpu_has() for KVM's PV steal time 2022-07-13 18:14:13 -07:00
system_counter_offset_test.c KVM: selftests: Fix filename reporting in guest asserts 2022-07-13 18:14:08 -07:00