Skip to content

x86: cleanups, fixes and new tests

Mathias Krause kvm 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest16 patches 6 repliesIn review

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/16x86: Drop types.hlib/x86/processor.h x86/cmpxchg8b.c x86/emulator.c +5 more+7 -270 replies
2/16x86: Use symbolic names in exception_mnemonic()lib/x86/desc.c lib/x86/processor.h+22 -180 replies
3/16x86: Add vendor specific exception vectorslib/x86/desc.c lib/x86/processor.h+9 -00 replies
4/16x86/cet: Use symbolic name for #CPx86/cet.c+1 -10 replies
5/16x86/access: Use 'bool' type as defined via libcflat.hx86/access.c+4 -70 replies
6/16x86/run_in_user: Change type of code labellib/x86/usermode.c+2 -24 replies
7/16x86/run_in_user: Preserve exception handlerlib/x86/usermode.c+7 -30 replies
8/16x86/run_in_user: Relax register constraints of inline asmlib/x86/usermode.c+8 -120 replies
9/16x86/run_in_user: Reload SS after successful returnlib/x86/usermode.c+8 -00 replies
10/16x86/fault_test: Preserve exception handlerlib/x86/fault_test.c+3 -10 replies
11/16x86/emulator64: Relax register constraints for usr_gs_mov()x86/emulator64.c+1 -10 replies
12/16x86/emulator64: Switch test_sreg() to ASM_TRY()x86/emulator64.c+4 -140 replies
13/16x86/emulator64: Add non-null selector testx86/emulator64.c+7 -00 replies
14/16x86/emulator64: Switch test_jmp_noncanonical() to ASM_TRY()x86/emulator64.c+4 -110 replies
15/16x86/emulator64: Switch test_mmx_movq_mf() to ASM_TRY()x86/emulator64.c+16 -230 replies
16/16x86/emulator64: Test non-canonical memory access exceptionsx86/emulator64.c+28 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [kvm-unit-tests PATCH v2 00/16] x86: cleanups, fixes and new tests

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

This is v2 of the "non-canonical memory access" test. It evolved into a small series, bringing cleanups and fixes along the way.

I integrated Sean's feedback and changed the test to make use of ASM_TRY() instead of using the hand-rolled exception handler. I also switched all other users in emulator64.c to ASM_TRY() and was able to drop the one-off exception handler all together.

Sean, this should be a solid ground to refine it further when [1] lands?

[1] https://lkml.kernel.org/r/[email protected]

As for the fixes, run_in_user() didn't restore the exception handler it overwrites, which leads to interesting bugs when the handler fires again for an unrelated exception -- that longjmp() won't do the right thing in this case ;)

I fixed fault_test() as well, as it has the same behaviour.

For new tests, I added the non-canonical memory access exception test of v1 and added another SS segment register load test to check non-NULL selectors as well, as I stumbled over the bugs in run_in_user() while switching test_sreg() over to TRY_ASM().

Be aware that the types.h removal (first patch) has an unfortunate side effect. It breaks compilation in already build trees, as the dependency files (.*.d) don't get regenerated / cleaned if a source file changes. This leads to stale references to types.h which can only be solved by a 'make clean'. :(

We really should change the dependency file generation to avoid that problem, as the current state is kinda awkward. Tho, I didn't had the time to look into it further myself.

Please apply!

Thanks,
Mathias

PS: I'm on holidays for three weeks from Saturday on, so won't respond to feedback any time soon.

Mathias Krause (16):
x86: Drop types.h
x86: Use symbolic names in exception_mnemonic()
x86: Add vendor specific exception vectors x86/cet: Use symbolic name for #CP
x86/access: Use 'bool' type as defined via libcflat.h x86/run_in_user: Change type of code label x86/run_in_user: Preserve exception handler x86/run_in_user: Relax register constraints of inline asm x86/run_in_user: Reload SS after successful return x86/fault_test: Preserve exception handler x86/emulator64: Relax register constraints for usr_gs_mov() x86/emulator64: Switch test_sreg() to ASM_TRY() x86/emulator64: Add non-null selector test x86/emulator64: Switch test_jmp_noncanonical() to ASM_TRY() x86/emulator64: Switch test_mmx_movq_mf() to ASM_TRY() x86/emulator64: Test non-canonical memory access exceptions

 lib/x86/processor.h  |  13 ++++++
 lib/x86/desc.c       |  43 ++++++++++--------
 lib/x86/fault_test.c |   4 +-
 lib/x86/usermode.c   |  42 ++++++++++-------
 x86/types.h          |  21 ---------
 x86/access.c         |  11 ++---
 x86/cet.c            |   2 +-
 x86/cmpxchg8b.c      |   1 -
 x86/emulator.c       |   1 -
 x86/emulator64.c     | 105 ++++++++++++++++++++++++-------------------
 x86/pmu_pebs.c       |   1 -
 x86/svm.c            |   1 -
 x86/svm_tests.c      |   1 -
 x86/vmx_tests.c      |   1 -
 14 files changed, 129 insertions(+), 118 deletions(-)
 delete mode 100644 x86/types.h
Signature · 1 line
2.39.2