Skip to content

KVM: selftests: Fix "fix hypercall test" build errors

Sean Christopherson kvm lkml llvm 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest7 patches 3 repliesIn review
  2. v15 patches 13 repliesSuperseded

Changes in v2 from the cover letter

- Revert a patch that avoided memset(). [Jim]
- Collect reviews. [Oliver]
- Rename kvm_string.c => string_overrides.c. [David]
- Tweak the "fix hypercall" test to verify that the original opcode is preserved exactly. [Oliver]
- Further dedup code in the "fix hypercall" test.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7KVM: selftests: Implement memcmp(), memcpy(), and memset() for guest usetools/testing/selftests/kvm/Makefile tools/testing/selftests/kvm/lib/string_override.c+49 -12 replies
2/7KVM: selftests: Compare insn opcodes directly in fix_hypercall_testtools/testing/selftests/kvm/x86_64/fix_hypercall_test.c+16 -180 replies
3/7KVM: selftests: Remove unnecessary register shuffling in fix_hypercall_testtools/testing/selftests/kvm/x86_64/fix_hypercall_test.c+8 -140 replies
4/7KVM: selftests: Hardcode VMCALL/VMMCALL opcodes in "fix hypercall" testtools/testing/selftests/kvm/x86_64/fix_hypercall_test.c+16 -270 replies
5/7KVM: selftests: Explicitly verify KVM doesn't patch hypercall if quirk==offtools/testing/selftests/kvm/x86_64/fix_hypercall_test.c+18 -80 replies
6/7KVM: selftests: Dedup subtests of fix_hypercall_testtools/testing/selftests/kvm/x86_64/fix_hypercall_test.c+13 -320 replies
7/7Revert "KVM: selftests: Fix nested SVM tests when built with clang"tools/testing/selftests/kvm/lib/x86_64/svm.c+1 -131 reply

Reviews trailers per patch

5 of 7 patches have a Reviewed-by or Acked-by.

PatchOliver UptonJim MattsonAndrew Jones
1/7R-b
2/7R-b
3/7R-b
4/7
5/7
6/7R-b
7/7R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v2 thread

Cover letter [PATCH v2 0/7] KVM: selftests: Fix "fix hypercall test" build errors

After a toolchain upgrade, the x86 fix_hypercall_test started throwing warnings due to -Werror=array-bounds rightly complaining that the test is generating an out-of-bounds array access.

The "obvious" fix is to replace the memcpy() with a memcmp() and compare only the exact size of the hypercall instruction. That worked, until I fiddled with the code a bit more and suddenly the test started jumping into the weeds due to gcc generating a call to the external memcmp() through the PLT, which isn't supported in the selftests.

To fix that mess, which has been a pitfall for quite some time, provide implementations of memcmp(), memcpy(), and memset() to effectively override the compiler built-ins. My thought is to start with the helpers that are most likely to be used in guest code, and then add more as needed.

v2:
- Revert a patch that avoided memset(). [Jim]
- Collect reviews. [Oliver]
- Rename kvm_string.c => string_overrides.c. [David]
- Tweak the "fix hypercall" test to verify that the original opcode is preserved exactly. [Oliver]
- Further dedup code in the "fix hypercall" test.

v1: https://lore.kernel.org/all/[email protected]

Sean Christopherson (7):
KVM: selftests: Implement memcmp(), memcpy(), and memset() for guest
use
KVM: selftests: Compare insn opcodes directly in fix_hypercall_test
KVM: selftests: Remove unnecessary register shuffling in
fix_hypercall_test
KVM: selftests: Hardcode VMCALL/VMMCALL opcodes in "fix hypercall"
test
KVM: selftests: Explicitly verify KVM doesn't patch hypercall if

    quirk==off

KVM: selftests: Dedup subtests of fix_hypercall_test Revert "KVM: selftests: Fix nested SVM tests when built with clang"

 tools/testing/selftests/kvm/Makefile          |  11 +-
 .../selftests/kvm/lib/string_override.c       |  39 +++++
 tools/testing/selftests/kvm/lib/x86_64/svm.c  |  14 +-
 .../selftests/kvm/x86_64/fix_hypercall_test.c | 134 +++++++-----------
 4 files changed, 103 insertions(+), 95 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/lib/string_override.c

base-commit: c59fb127583869350256656b7ed848c398bef879

Signature · 1 line
2.37.3.998.g577e59143f-goog