kvm-unit-tests: VMX: Add test cases for PAT and EFER

Add test cases for ENT_LOAD_PAT, ENT_LOAD_EFER, EXI_LOAD_PAT,
EXI_SAVE_PAT, EXI_LOAD_EFER, EXI_SAVE_PAT flags in enter/exit
control fields.

Signed-off-by: Arthur Chunqi Li <yzt356@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
kvm-unit-tests: VMX: Add test cases for CR0/4 shadowing

Add testing for CR0/4 shadowing. Two types of flags in CR0/4 are
tested: flags owned and shadowed by L1. They are treated differently
in KVM. We test one flag of both types in CR0 (TS and MP) and CR4
(DE and TSD) with read through, read shadow, write through, write
shadow (same as and different from shadowed value).

Signed-off-by: Arthur Chunqi Li <yzt356@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
kvm-unit-tests: VMX: Add test cases for I/O bitmaps

Add test cases for I/O bitmaps, including corner cases.

Test includes: pass & trap, in & out, different I/O width, low & high
I/O bitmap, partial I/O pass, overrun (inl 0xFFFF).

Signed-off-by: Arthur Chunqi Li <yzt356@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
kvm-unit-tests: VMX: Add test cases for instruction interception

Add test cases for instruction interception, including four types:
1. Primary Processor-Based VM-Execution Controls (HLT/INVLPG/MWAIT/
RDPMC/RDTSC/MONITOR/PAUSE)
2. Secondary Processor-Based VM-Execution Controls (WBINVD)
3. No control flag, always trap (CPUID/INVD)
4. Instructions always pass

Signed-off-by: Arthur Chunqi Li <yzt356@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
kvm-unit-tests: VMX: The framework of EPT for nested VMX testing

The framework of EPT for nested VMX, including functions to build up
EPT paging structures, read/set EPT PTEs and setup a range of 1:1 map
EPT.

Signed-off-by: Arthur Chunqi Li <yzt356@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
kvm-unit-tests: VMX: Test cases for nested EPT

Some test cases for nested EPT features, including:
1. EPT basic framework tests: read, write and remap.
2. EPT misconfigurations test cases: page permission mieconfiguration
and memory type misconfiguration
3. EPT violations test cases: page permission violation and paging
structure violation

Signed-off-by: Arthur Chunqi Li <yzt356@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
kvm-unit-tests: VMX: Test suite for preemption timer

Test cases for preemption timer in nested VMX. Two aspects are tested:
1. Save preemption timer on VMEXIT if relevant bit set in EXIT_CONTROL
2. Test a relevant bug of KVM. The bug will not save preemption timer
value if exit L2->L0 for some reason and enter L0->L2. Thus preemption
timer will never trigger if the value is large enough.

Signed-off-by: Arthur Chunqi Li <yzt356@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
kvm-unit-tests: VMX: Fix two minor bugs in EPT framework

This patch just contains two minor changes to EPT framwork.
1. Reorder macro definition
2. Fix bug of setting CPU_EPT without check.

Signed-off-by: Arthur Chunqi Li <yzt356@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
kvm-unit-tests: VMX: Comments on the framework and writing test cases

Add some comments on the framework of nested VMX testing, and guides of
how to write new test cases.

Signed-off-by: Arthur Chunqi Li <yzt356@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
VMX preemption timer: Make test case more robust

If we both print from L2 and, on timer expiry, from L1, we risk a
deadlock in L1 on the printf lock that is held by L2 then. Avoid this
by only printing from L1.

Furthermore, if the timer fails to fire in time, disable it before
continuing to avoid that it fire later on in different contexts.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
nEPT: Fix test cases for 2M huge pages

If 2M pages are available with EPT, the test code creates its initial
identity map with such pages. But then it tries to remap two 4K pages in
that range which fails as their level 3 PTE is set up for huge pages.

Fix this up by ensuring that install_ept_entry always create non-large
page directory entries and by remapping the 2M area around those two
test pages in 4K chunks.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
nEPT: Fix logic for testing read access

We need to fail the test if MAGIC_VAL_1 cannot be found in either
data_page1 or data_page2.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Merge branch 'vmx' into master
[kvm-unit-tests] VMX: clean up switch statements for the "stage" state machine

See comments made during the original review of these tests, at
http://permalink.gmane.org/gmane.comp.emulators.kvm.devel/114001.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
VMX: Fix initialization of GDT, IDT and TR descriptors

We were loading the addresses of the descriptor pointers, not the
addresses they are pointing to. By declaring the pointers with the
proper type, we can also save some castings + struct descr.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
VMX: Drop redundant return statements

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
rmap_chain: Remove dead code

Fixes corresponding warning.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
emulator: Exclude test_lgdt_lidt from building

See commit 47c1461a5.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
init: Fix warning about returning without code

Main does not return, tell this the compiler.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
lib/x86/smp: Fix compiler warnings

Add missing include of desc.h for prototypes of setup_idt and
set_idt_entry and fix the declaration of ipi_data - the pointer is
volatile, not the pointed-to datum.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
[Correct the fix for ipi_data. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>