linux/tools/testing/selftests/kvm/lib
Sean Christopherson 6b6f71484b KVM: selftests: Implement memcmp(), memcpy(), and memset() for guest use
Implement memcmp(), memcpy(), and memset() to override the compiler's
built-in versions in order to guarantee that the compiler won't generate
out-of-line calls to external functions via the PLT.  This allows the
helpers to be safely used in guest code, as KVM selftests don't support
dynamic loading of guest code.

Steal the implementations from the kernel's generic versions, sans the
optimizations in memcmp() for unaligned accesses.

Put the utilities in a separate compilation unit and build with
-ffreestanding to fudge around a gcc "feature" where it will optimize
memset(), memcpy(), etc... by generating a recursive call.  I.e. the
compiler optimizes itself into infinite recursion.  Alternatively, the
individual functions could be tagged with
optimize("no-tree-loop-distribute-patterns"), but using "optimize" for
anything but debug is discouraged, and Linus NAK'd the use of the flag
in the kernel proper[*].

https://lore.kernel.org/lkml/CAHk-=wik-oXnUpfZ6Hw37uLykc-_P0Apyn2XuX-odh-3Nzop8w@mail.gmail.com

Cc: Andrew Jones <andrew.jones@linux.dev>
Cc: Anup Patel <anup@brainfault.org>
Cc: Atish Patra <atishp@atishpatra.org>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Janosch Frank <frankja@linux.ibm.com>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20220928233652.783504-2-seanjc@google.com>
Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2022-09-30 06:38:02 -04:00
..
aarch64 Merge remote-tracking branch 'kvm/next' into kvm-next-5.20 2022-08-01 03:21:00 -04:00
riscv KVM: selftests: Purge vm+vcpu_id == vcpu silliness 2022-06-11 11:47:22 -04:00
s390x KVM: selftests: Add kvm_has_cap() to provide syntactic sugar 2022-06-11 11:47:28 -04:00
x86_64 KVM: selftests: Skip tests that require EPT when it is not available 2022-09-27 07:58:03 -04:00
assert.c KVM: selftests: Gracefully handle empty stack traces 2022-09-30 06:38:00 -04:00
elf.c KVM: selftests: Get rid of kvm_util_internal.h 2022-06-11 11:46:19 -04:00
guest_modes.c KVM: selftests: Sanity check input to ioctls() at build time 2022-06-11 11:48:09 -04:00
io.c selftests: kvm: Uses TEST_FAIL in tests/utilities 2020-03-16 17:59:11 +01:00
kvm_util.c KVM: selftests: Cache CPUID in struct kvm_vcpu 2022-07-13 18:14:15 -07:00
perf_test_util.c KVM: selftests: Drop @num_percpu_pages from __vm_create_with_vcpus() 2022-06-11 11:47:25 -04:00
rbtree.c KVM: selftests: Keep track of memslots more efficiently 2021-05-27 07:45:54 -04:00
sparsebit.c kvm: selftests: Fix spelling mistake "missmatch" -> "mismatch" 2021-09-30 04:27:08 -04:00
string_override.c KVM: selftests: Implement memcmp(), memcpy(), and memset() for guest use 2022-09-30 06:38:02 -04:00
test_util.c KVM: selftests: Assert mmap HVA is aligned when using HugeTLB 2021-11-16 07:43:25 -05:00