KVM: selftests: Test TPR / CR8 sync and interrupt masking
Sean Christopherson
maintainerPATCH v4 1/1 KVM: selftests: Test TPR / CR8 sync and interrupt masking
From: Maciej S. Szmigiero <[email protected]>
Add a few extra TPR / CR8 tests to x86's xapic_state_test to see if:
* TPR is 0 on reset,
* TPR, PPR and CR8 are equal inside the guest,
* TPR and CR8 read equal by the host after a VMExit
* TPR borderline values set by the host correctly mask interrupts in the guest.
These hopefully will catch the most obvious cases of improper TPR sync or interrupt masking.
Do these tests both in x2APIC and xAPIC modes.
The x2APIC mode uses SELF_IPI register to trigger interrupts to give it a bit of exercise too.
---
Maciej's TPR test. The only change relative to v3 (well, the only intended change :-D) is to move the testcase to its own test. IMO, it's cleaner for both this test and the existing xapic_state_test (which I plan on splitting up at some point).
tools/testing/selftests/kvm/Makefile.kvm | 1 + .../testing/selftests/kvm/include/x86/apic.h | 3 + .../selftests/kvm/x86/xapic_tpr_test.c | 276 ++++++++++++++++++ 3 files changed, 280 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86/xapic_tpr_test.c
tools/testing/selftests/kvm/Makefile.kvm +1 -0
@@ -124,6 +124,7 @@ TEST_GEN_PROGS_x86 += x86/vmx_set_nested_state_test TEST_GEN_PROGS_x86 += x86/apic_bus_clock_test TEST_GEN_PROGS_x86 += x86/xapic_ipi_test TEST_GEN_PROGS_x86 += x86/xapic_state_test +TEST_GEN_PROGS_x86 += x86/xapic_tpr_test TEST_GEN_PROGS_x86 += x86/xcr0_cpuid_test TEST_GEN_PROGS_x86 += x86/xss_msr_test TEST_GEN_PROGS_x86 += x86/debug_regs
tools/testing/selftests/kvm/include/x86/apic.h +3 -0
@@ -28,6 +28,8 @@#define GET_APIC_ID_FIELD (x) (((x) >> 24) & 0xFF)#define APIC_TASKPRI 0x80#define APIC_PROCPRI 0xA0 +#define GET_APIC_PRI (x) (((x) & GENMASK(7, 4)) >> 4) +#define SET_APIC_PRI (x, y) (((x) & ~GENMASK(7, 4)) | (y << 4))#define APIC_EOI 0xB0#define APIC_SPIV 0xF0#define APIC_SPIV_FOCUS_DISABLED (1 << 9)
@@ -67,6 +69,7 @@#define APIC_TMICT 0x380#define APIC_TMCCT 0x390#define APIC_TDCR 0x3E0 +#define APIC_SELF_IPI 0x3F0void apic_disable (void );void xapic_enable (void );
tools/testing/selftests/kvm/x86/xapic_tpr_test.c new file +276 -0
276 lines not on this page · raw message
base-commit: 5d3e2d9ba9ed68576c70c127e4f7446d896f2af2
Signature · 1 line
2.52.0.223.gf5cc29aaa4-goog
Quoted 20 lines · Sean Christopherson
From: Maciej S. Szmigiero <[email protected]>
Add a few extra TPR / CR8 tests to x86's
xapic_state_testto see if:
* TPR is 0 on reset,
* TPR, PPR and CR8 are equal inside the guest,
* TPR and CR8 read equal by the host after a VMExit
* TPR borderline values set by the host correctly mask interrupts in the guest.These hopefully will catch the most obvious cases of improper TPR sync or interrupt masking.
Do these tests both in x2APIC and xAPIC modes.
The x2APIC mode usesSELF_IPIregister to trigger interrupts to give it a bit of exercise too.Signed-off-by Maciej S. Szmigiero <[email protected]>[sean: put code in separate test]Signed-off-by Sean Christopherson <[email protected]>
Quoted 7 lines
---
Maciej's TPR test. The only change relative to v3 (well, the only intended change :-D) is to move the testcase to its own test. IMO, it's cleaner for both this test and the existing
xapic_state_test(which I plan on splitting up at some point).
Thanks Sean for the updated test.
I see that besides the TPR testcase being separated into its own test some things were renamed and also GUEST_SYNC() parameter meaning was inverted.
Anyway, I re-tested the separated test (including on a kernel that's un-fixed with respect to the AVIC TPR sync to make it fail) and the test still seems to do its job properly.
Thanks,
Maciej
Sean Christopherson
maintainerQuoted 8 lines · Sean Christopherson
Add a few extra TPR / CR8 tests to x86's
xapic_state_testto see if:
* TPR is 0 on reset,
* TPR, PPR and CR8 are equal inside the guest,
* TPR and CR8 read equal by the host after a VMExit
* TPR borderline values set by the host correctly mask interrupts in the guest.[...]
Applied to kvm-x86 selftests, thanks!
[1/1] KVM: selftests: Test TPR / CR8 sync and interrupt masking
https://github.com/kvm-x86/linux/commit/0b28194c4c8e