]> rtime.felk.cvut.cz Git - jailhouse.git/log
jailhouse.git
9 years agotools: Add copyright information to jailhouse-completion.bash
Jan Kiszka [Fri, 20 Feb 2015 11:24:19 +0000 (12:24 +0100)]
tools: Add copyright information to jailhouse-completion.bash

This file was contributed under the default license of Jailhouse.
Better state this explicitly.

CC: Benjamin Block <bebl@mageta.org>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Benjamin Block <bebl@mageta.org>
9 years agodriver: Avoid deprecated usage of cpumask API
Jan Kiszka [Sat, 25 Apr 2015 07:02:28 +0000 (09:02 +0200)]
driver: Avoid deprecated usage of cpumask API

We used the legacy API so far, and that will be removed in 4.1.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Do not call vmload/vmsave on every VM exit
Jan Kiszka [Sun, 5 Apr 2015 09:55:07 +0000 (11:55 +0200)]
x86: Do not call vmload/vmsave on every VM exit

Benchmarks indicate that we can gain about 160 cycles per VM exit &
reentry by only saving/restoring MSR_GS_BASE. We don't touch the other
states that vmload/vmsave deals with.

Specifically, we don't depend on a valid TR/TSS while in root mode
because Jailhouse has neither in userspace nor uses the IST for
interrupts or exceptions, thus does not try to access the TSS.

We still need to perform vmload on handover (actually, we only need to
load MSR_GS_BASE, but vmload is simpler) and after VCPU reset. And as we
no longer save the full state, also for shutdown, we need to pull the
missing information for arch_cpu_restore directly from the registers.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Make FS_BASE MSR restoration VMX-specific
Jan Kiszka [Sun, 5 Apr 2015 08:52:32 +0000 (10:52 +0200)]
x86: Make FS_BASE MSR restoration VMX-specific

SVM does not touch this MSR on VM exit, thus does not require the
restoration done in arch_cpu_restore so far. Make it VMX-specific so
that we can drop a few lines of code.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove write-only linux_sysenter_* fields
Jan Kiszka [Sun, 5 Apr 2015 07:21:36 +0000 (09:21 +0200)]
x86: Remove write-only linux_sysenter_* fields

The vendor code reads the state directly from the MSRs during setup.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Make SYSENTER MSR restoration VMX-specific
Jan Kiszka [Sun, 5 Apr 2015 07:19:33 +0000 (09:19 +0200)]
x86: Make SYSENTER MSR restoration VMX-specific

SVM does not overwrite these MSRs on VM exit, thus does not require the
restoration done in arch_cpu_restore so far. Make them VMX-specific so
that we can drop a few lines of code.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove unneeded MSR restoring from SVM's vcpu_deactivate_vmm
Jan Kiszka [Sun, 5 Apr 2015 06:58:30 +0000 (08:58 +0200)]
x86: Remove unneeded MSR restoring from SVM's vcpu_deactivate_vmm

None of these MSRs is modified by Jailhouse after VM exit, thus they
still contain the state the Linux guest left behind.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Refactor SVM version of vcpu_activate_vmm
Jan Kiszka [Sat, 4 Apr 2015 11:27:59 +0000 (13:27 +0200)]
x86: Refactor SVM version of vcpu_activate_vmm

We can reduce the assembly required in vcpu_activate_vmm by reordering
svm_vmexit to svm_vmentry, i.e. pulling the VM entry logic to the front.
Moreover, RAX can be loaded directly. There is furthermore no need to
declare clobbered variables as we won't return from the assembly block,
which is already declared via __builtin_unreachable.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Simplify error exit of svm_parse_mov_to_cr and svm_handle_cr
Jan Kiszka [Sun, 5 Apr 2015 14:03:34 +0000 (16:03 +0200)]
x86: Simplify error exit of svm_parse_mov_to_cr and svm_handle_cr

No need to maintain a return code variable when we can simply return
false directly.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Drop constant return values from SVM functions
Jan Kiszka [Sun, 5 Apr 2015 13:58:41 +0000 (15:58 +0200)]
x86: Drop constant return values from SVM functions

vmcb writing cannot fail on AMD, thus neither vmcb_setup nor
svm_set_cell_config can. Simply remove the error codes and related
handling.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Simplify descriptor reset in svm_vcpu_reset
Jan Kiszka [Sun, 5 Apr 2015 07:55:59 +0000 (09:55 +0200)]
x86: Simplify descriptor reset in svm_vcpu_reset

Reduce boilerplate code by using constants for common reset states.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Simplify set_svm_segment_from_dtr
Jan Kiszka [Sun, 5 Apr 2015 07:45:17 +0000 (09:45 +0200)]
x86: Simplify set_svm_segment_from_dtr

By using set_svm_segment_from_segment for ldtr, we can remove the
condition from set_svm_segment_from_dtr.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Simplify set_svm_segment_from_segment
Jan Kiszka [Sun, 5 Apr 2015 07:36:44 +0000 (09:36 +0200)]
x86: Simplify set_svm_segment_from_segment

No need to complain: segment.access_rights is generic as it simply holds
bits 8..23 of the second descriptor dword. The additional invalid bit
used by VMX only can be ignored by SVM - and it is already, even when
leaving out the explicit test.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Drop PERCPU_VMCB and VMCB_RAX
Jan Kiszka [Sat, 4 Apr 2015 21:19:13 +0000 (23:19 +0200)]
x86: Drop PERCPU_VMCB and VMCB_RAX

We can calculate PERCPU_VMCB_RAX directly and save the two intermediate
steps.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Drop local guest_regs variable from SVM version of vcpu_handle_exit
Jan Kiszka [Sat, 4 Apr 2015 15:51:51 +0000 (17:51 +0200)]
x86: Drop local guest_regs variable from SVM version of vcpu_handle_exit

No need to cache it. It can be derived from cpu_data now.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove guest registers parameter from svm_handle_msr_write
Jan Kiszka [Sat, 4 Apr 2015 15:50:44 +0000 (17:50 +0200)]
x86: Remove guest registers parameter from svm_handle_msr_write

We can retrieve them from the per-cpu data structure now.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Pass vmcb instead of cpu_data to some internal SVM functions
Jan Kiszka [Sat, 4 Apr 2015 15:32:14 +0000 (17:32 +0200)]
x86: Pass vmcb instead of cpu_data to some internal SVM functions

update_efer, svm_parse_mov_to_cr and svm_handle_apic_access have no use
for cpu_data and rather convert it into a vmcb reference directly. So
pass that one instead to save some statements.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Rename x86_parse_mov_to_cr to svm_parse_mov_to_cr
Jan Kiszka [Sat, 4 Apr 2015 15:29:00 +0000 (17:29 +0200)]
x86: Rename x86_parse_mov_to_cr to svm_parse_mov_to_cr

This functions is SVM-specific.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Cache vmcb instead of cpu_data in SVM's vcpu_vendor_get_execution_state
Jan Kiszka [Sat, 4 Apr 2015 15:24:08 +0000 (17:24 +0200)]
x86: Cache vmcb instead of cpu_data in SVM's vcpu_vendor_get_execution_state

Easier to read.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove guest registers parameter from svm_handle_cr
Jan Kiszka [Sat, 4 Apr 2015 15:22:11 +0000 (17:22 +0200)]
x86: Remove guest registers parameter from svm_handle_cr

We can retrieve them from the per-cpu data structure now.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove traces of cpuid interception from SVM
Jan Kiszka [Sat, 4 Apr 2015 12:57:39 +0000 (14:57 +0200)]
x86: Remove traces of cpuid interception from SVM

There is no foreseeable need to intercept cpuid on AMD. On Intel, we
are not asked if we want to, so we have to execute it on behalf of the
cell.But here we can simple let it happen.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Drop some unneeded local variables from SVM functions
Jan Kiszka [Fri, 3 Apr 2015 10:08:01 +0000 (12:08 +0200)]
x86: Drop some unneeded local variables from SVM functions

No need to maintain cpu_data or even vmcb as local variable if they are
only used once.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Drop local guest_regs variable from VMX version of vcpu_handle_exit
Jan Kiszka [Sat, 4 Apr 2015 11:46:40 +0000 (13:46 +0200)]
x86: Drop local guest_regs variable from VMX version of vcpu_handle_exit

No need to cache it. It can be derived from cpu_data now.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Factor out vmx_handle_cpuid
Jan Kiszka [Sat, 4 Apr 2015 11:45:48 +0000 (13:45 +0200)]
x86: Factor out vmx_handle_cpuid

Shortens vcpu_handle_exit and improves readability.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove parameters from vmx_handle_cr
Jan Kiszka [Sat, 4 Apr 2015 11:38:30 +0000 (13:38 +0200)]
x86: Remove parameters from vmx_handle_cr

Guest registers can be retrieved inline.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove guest registers parameter from vcpu_handle_msr_read/write
Jan Kiszka [Sat, 4 Apr 2015 06:22:49 +0000 (08:22 +0200)]
x86: Remove guest registers parameter from vcpu_handle_msr_read/write

The function only works against the current CPU, thus should avoid to
take the misleading parameter. The necessary reference can be obtained
from the per-cpu data structure now.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove guest registers parameter from vcpu_handle_mmio_access
Jan Kiszka [Sat, 4 Apr 2015 06:20:33 +0000 (08:20 +0200)]
x86: Remove guest registers parameter from vcpu_handle_mmio_access

The function only works against the current CPU, thus should avoid to
take the misleading parameter. The necessary reference can be obtained
from the per-cpu data structure now.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove unused guest registers parameter from vcpu_handle_io_access
Jan Kiszka [Sat, 4 Apr 2015 06:14:21 +0000 (08:14 +0200)]
x86: Remove unused guest registers parameter from vcpu_handle_io_access

All filter functions obtain the reference themselves now.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove guest registers and cell parameters from x86_pci_config_handler
Jan Kiszka [Sat, 4 Apr 2015 06:02:21 +0000 (08:02 +0200)]
x86: Remove guest registers and cell parameters from x86_pci_config_handler

The function only works against the current CPU, thus should avoid to
take the misleading parameters. Guest registers are no long er required,
and the cell reference can be obtained inline.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Rework RAX register accessors of PCI layer
Jan Kiszka [Sat, 4 Apr 2015 05:53:18 +0000 (07:53 +0200)]
x86: Rework RAX register accessors of PCI layer

Stop requiring that the guest registers are passed down to the
accessors. Access handlers always work over the issuing CPU, thus can
obtain the register state themselves. Rename the accessors to make it
clear that they work against guest registers.

This allows to drop the guest_regs parameters from
data_port_in/out_handler.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove guest registers parameter from i8042_access_handler
Jan Kiszka [Fri, 3 Apr 2015 18:04:44 +0000 (20:04 +0200)]
x86: Remove guest registers parameter from i8042_access_handler

The function only works against the current CPU, thus should avoid to
take the misleading parameter. The necessary reference can be obtained
from the per-cpu data structure now.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove guest registers and cpu_data parameters from apic_mmio_access
Jan Kiszka [Fri, 3 Apr 2015 17:58:25 +0000 (19:58 +0200)]
x86: Remove guest registers and cpu_data parameters from apic_mmio_access

The function only works on the current CPU, thus should avoid to take
misleading parameters. The necessary references can be obtained inline.

With the parameters no longer needed, the callers
svm/vmx_handle_apic_access can drop some of them as well.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove parameters from x2apic_handle_read/write
Jan Kiszka [Fri, 3 Apr 2015 13:33:25 +0000 (15:33 +0200)]
x86: Remove parameters from x2apic_handle_read/write

The function only works against the current CPU, thus should avoid to
take the misleading parameters. We can retrieve the per-cpu data
structure and the guest registers in the function now.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove guest registers parameter from vcpu_handle_xsetbv
Jan Kiszka [Mon, 6 Apr 2015 18:19:34 +0000 (20:19 +0200)]
x86: Remove guest registers parameter from vcpu_handle_xsetbv

The function only works against the current CPU, thus should avoid to
take the misleading parameter. The necessary reference can be obtained
from the per-cpu data structure now.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove guest registers parameter from vcpu_handle_hypercall
Jan Kiszka [Fri, 3 Apr 2015 13:03:22 +0000 (15:03 +0200)]
x86: Remove guest registers parameter from vcpu_handle_hypercall

The function only works against the current CPU, thus should avoid to
take the misleading parameter. The necessary reference can be obtained
from the per-cpu data structure now.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove guest registers parameter from vcpu_deactivate_vmm
Jan Kiszka [Fri, 3 Apr 2015 13:02:19 +0000 (15:02 +0200)]
x86: Remove guest registers parameter from vcpu_deactivate_vmm

The function only works against the current CPU, thus should avoid to
take the misleading parameter. The necessary reference can be obtained
from the per-cpu data structure now.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove guest registers parameter from vcpu_reset
Jan Kiszka [Fri, 3 Apr 2015 12:47:52 +0000 (14:47 +0200)]
x86: Remove guest registers parameter from vcpu_reset

The function only works against the current CPU, thus should avoid to
take the misleading parameter. The necessary reference can be obtained
from the per-cpu data structure now.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove guest registers parameter from vcpu_handle_exit
Jan Kiszka [Fri, 3 Apr 2015 12:44:43 +0000 (14:44 +0200)]
x86: Remove guest registers parameter from vcpu_handle_exit

We can retrieve them from the per-cpu data structure now.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Enable direct access to per-cpu guest registers
Jan Kiszka [Fri, 3 Apr 2015 12:26:08 +0000 (14:26 +0200)]
x86: Enable direct access to per-cpu guest registers

Now that the guest registers are saved at the same location on the
per-cpu stack for both Intel and AMD, we can enable direct access via
the per-cpu data structure. This will allow to drop the guest registers
parameter from most functions.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Reorder stack layout in svm_vmexit
Jan Kiszka [Fri, 3 Apr 2015 11:46:28 +0000 (13:46 +0200)]
x86: Reorder stack layout in svm_vmexit

Push the guest registers first so that they end up at the same location
on the stack as on Intel. This will allow to address them generically
via the per_cpu structure.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Allow index-based guest register access without type casts
Jan Kiszka [Fri, 3 Apr 2015 17:21:32 +0000 (19:21 +0200)]
x86: Allow index-based guest register access without type casts

Convert struct registers into a union and provide a by_index array for
index-based access. This is used by various handlers that parse guest
instructions and so far use a blunt type case on the structure.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Factor out vcpu_handle_xsetbv
Jan Kiszka [Fri, 3 Apr 2015 13:04:33 +0000 (15:04 +0200)]
x86: Factor out vcpu_handle_xsetbv

The handling logic is fully shared between AMD and Intel CPUs.
Consolidate it.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Retrieve vcpu_mmio_intercept from vcpu_handle_mmio_access
Jan Kiszka [Sat, 4 Apr 2015 11:07:03 +0000 (13:07 +0200)]
x86: Retrieve vcpu_mmio_intercept from vcpu_handle_mmio_access

Analogously to vcpu_handle_io_access, define the vendor callback
vcpu_vendor_get_mmio_intercept and call it from vcpu_handle_mmio_access
instead of passing it to the handler. For consistency reasons, rename
vcpu_pf_intercept to vcpu_mmio_intercept.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Rename vcpu_handle_pt_violation to vcpu_handle_mmio_access
Jan Kiszka [Sat, 4 Apr 2015 10:30:25 +0000 (12:30 +0200)]
x86: Rename vcpu_handle_pt_violation to vcpu_handle_mmio_access

This describes more accurately what the handler does and aligns us with
vcpu_handle_io_access.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Rename parameter of vcpu_vendor_get_io_intercept
Jan Kiszka [Sat, 4 Apr 2015 10:27:18 +0000 (12:27 +0200)]
x86: Rename parameter of vcpu_vendor_get_io_intercept

This aligns the internal names with those used externally. No functional
changes.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Retrieve vcpu_io_intercept from vcpu_handle_io_access
Jan Kiszka [Sat, 4 Apr 2015 10:23:09 +0000 (12:23 +0200)]
x86: Retrieve vcpu_io_intercept from vcpu_handle_io_access

Convert the vendor-specific functions into vcpu_vendor_get_io_intercept
and invoke that one from vcpu_handle_io_access. That offloads this
burden from the callers of vcpu_handle_io_access and takes us further
towards consistent vendor callbacks for such purposes.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Obtain execution state inside vcpu_handle_hypercall
Jan Kiszka [Sat, 4 Apr 2015 06:39:00 +0000 (08:39 +0200)]
x86: Obtain execution state inside vcpu_handle_hypercall

This simplifies the invocation of the handler and aligns it with
vcpu_handle_pt_violation.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove cpu_data parameter from vcpu_park
Jan Kiszka [Fri, 3 Apr 2015 17:51:51 +0000 (19:51 +0200)]
x86: Remove cpu_data parameter from vcpu_park

The function only works against the current CPU, thus should avoid to
take the misleading parameter. The implementations can obtain the
reference inline as needed.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Update apic_handle_icr_write signature
Jan Kiszka [Fri, 3 Apr 2015 13:26:16 +0000 (15:26 +0200)]
x86: Update apic_handle_icr_write signature

apic_handle_icr_write became locally used only by 3da0bd91d9, and we
also no longer use the cpu_data parameter.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove cpu_data parameter from apic_send_[logical_dest_]ipi
Jan Kiszka [Fri, 3 Apr 2015 13:19:20 +0000 (15:19 +0200)]
x86: Remove cpu_data parameter from apic_send_[logical_dest_]ipi

The function only works against the current CPU, thus should avoid to
take the misleading parameter. The necessary reference can be obtained
inline.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove unused parameter from apic_valid_ipi_mode
Jan Kiszka [Fri, 3 Apr 2015 13:17:11 +0000 (15:17 +0200)]
x86: Remove unused parameter from apic_valid_ipi_mode

No use case in sight.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove cpu_data parameter from apic_clear
Jan Kiszka [Fri, 3 Apr 2015 13:15:11 +0000 (15:15 +0200)]
x86: Remove cpu_data parameter from apic_clear

The function only works against the current CPU, thus should avoid to
take the misleading parameter. The necessary reference can be obtained
inline.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove local cpu_data variable from vcpu_handle_hypercall
Jan Kiszka [Fri, 3 Apr 2015 13:07:30 +0000 (15:07 +0200)]
x86: Remove local cpu_data variable from vcpu_handle_hypercall

Only used once.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove local cpu_data variable from vcpu_handle_io_access
Jan Kiszka [Fri, 10 Apr 2015 07:00:07 +0000 (09:00 +0200)]
x86: Remove local cpu_data variable from vcpu_handle_io_access

Only used once.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Block write access to MTRR registers
Jan Kiszka [Fri, 3 Apr 2015 09:06:54 +0000 (11:06 +0200)]
x86: Block write access to MTRR registers

Linux does not try to rewrite them on CPU hotplug if they are identical
to other CPUs' registers, and our non-root cells have no business in
touching them as well. This effectively freezes MTRRs after handover
ensures consistent states for both the hypervisor and all cells across
all CPUs.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Emulate MTRR enable/disable
Jan Kiszka [Fri, 3 Apr 2015 08:48:19 +0000 (10:48 +0200)]
x86: Emulate MTRR enable/disable

We assume that cells will only flip the enabled flag of
IA32_MTRR_DEF_TYPE, leaving the rest of the register in default state
(the one found during handover). SVM already implemented this but
emulated the disabled state by modifying the host PAT.

This approach works less invasively by only changing the effective guest
PAT to 0 in case MTRRs are off. And it provides this for Intel as well.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Maintain PAT shadow
Jan Kiszka [Thu, 2 Apr 2015 08:15:40 +0000 (10:15 +0200)]
x86: Maintain PAT shadow

For emulating the MTRR-disabled state, we will have to modify the
effective guest PAT state soon. This prepares for it by keeping PAT in
a shadow per-cpu field and intercept access to the MSR.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Introduce vcpu_reset
Jan Kiszka [Thu, 2 Apr 2015 08:14:54 +0000 (10:14 +0200)]
x86: Introduce vcpu_reset

So far this just encapsulates the general purpose register reset, but
more will follow.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Factor out set_rdmsr_value and get_wrmsr_value
Jan Kiszka [Fri, 3 Apr 2015 14:14:01 +0000 (16:14 +0200)]
x86: Factor out set_rdmsr_value and get_wrmsr_value

This improves readability of the code and scales better with more MSRs
being intercepted.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Factor out vcpu_handle_msr_read/write
Jan Kiszka [Thu, 2 Apr 2015 07:28:02 +0000 (09:28 +0200)]
x86: Factor out vcpu_handle_msr_read/write

This will simplify the emulation of MTRR_DEF_TYPE. It already allows to
consolidate filtering for x2APIC MSRs and error reporting.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Refactor svm_handle_msr_read/write
Jan Kiszka [Sun, 29 Mar 2015 17:28:02 +0000 (19:28 +0200)]
x86: Refactor svm_handle_msr_read/write

Convert to switch-case and simplify the exit path of the write handler.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Switch between host and guest PAT
Jan Kiszka [Sun, 29 Mar 2015 10:19:47 +0000 (12:19 +0200)]
x86: Switch between host and guest PAT

Do not allow the guest to mess with the PAT MSR in a was that also
affects the host. This may cause the host to run in uncached mode,
slowing it down, or - even worse- access MMIO with caches enabled which
will cause inconsistencies.

On Intel, we have to require and enable the related save/restore
feature. On AMD, we need to intercept the MSR accesses and map them on
the g_pat field of the VMCB.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Validate EFER save/restore feature on Intel
Jan Kiszka [Sun, 29 Mar 2015 10:48:01 +0000 (12:48 +0200)]
x86: Validate EFER save/restore feature on Intel

This feature practically comes with unrestricted guest mode, but the
spec does not guarantee this.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Improve readability of VMX constants
Jan Kiszka [Sun, 29 Mar 2015 10:36:25 +0000 (12:36 +0200)]
x86: Improve readability of VMX constants

Convert from magic number to shifted value to improve readability.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Prevent interference by Intel perf counters
Jan Kiszka [Sat, 28 Mar 2015 11:02:04 +0000 (12:02 +0100)]
x86: Prevent interference by Intel perf counters

Make it simple but safe: Disable perf counters during setup and prevent
that cells can modify the corresponding MSR. This avoids that we have
to switch the MSR during vmentry/exit, but it also blocks perf & friends
while Jailhouse is active.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Adjust output of SVM's dump_guest_regs
Jan Kiszka [Sun, 5 Apr 2015 09:50:56 +0000 (11:50 +0200)]
x86: Adjust output of SVM's dump_guest_regs

Aligns us with VMX.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Stop printing PCI address port in vcpu_handle_io_access
Jan Kiszka [Sat, 4 Apr 2015 06:15:22 +0000 (08:15 +0200)]
x86: Stop printing PCI address port in vcpu_handle_io_access

This information is provided by x86_pci_config_handler since b1be672359.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Consolidate cpuid helpers
Jan Kiszka [Fri, 3 Apr 2015 17:46:18 +0000 (19:46 +0200)]
x86: Consolidate cpuid helpers

cpuid() is not used outside of the CPUID_REG macro, only __cpuid. Let's
get rid of the former and reuse its name for the latter.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Remove obsolete comment from struct per_cpu
Jan Kiszka [Mon, 30 Mar 2015 22:15:46 +0000 (00:15 +0200)]
x86: Remove obsolete comment from struct per_cpu

The "defines above" were removed by 68be464005.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Clear high-order bits in RAX/RDX on x2APIC MSR read
Jan Kiszka [Fri, 3 Apr 2015 13:58:57 +0000 (15:58 +0200)]
x86: Clear high-order bits in RAX/RDX on x2APIC MSR read

The Intel SDM explicitly states that the higher 32 bits of RAX and RDX
are cleared by rdmsr.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agocore: Fix documentation of paging_get_guest_pages
Jan Kiszka [Sat, 4 Apr 2015 10:18:19 +0000 (12:18 +0200)]
core: Fix documentation of paging_get_guest_pages

We neglected the difference between pg_structs being NULL and non-NULL.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agotools: config create: do not break up ROM memory region
Henning Schild [Fri, 20 Mar 2015 13:37:12 +0000 (14:37 +0100)]
tools: config create: do not break up ROM memory region

Just take the ROM memory region as one, that avoids creating unalligned
memory regions on some systems.

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agoconfigs: Tune qemu config for X mode changes
Jan Kiszka [Thu, 19 Mar 2015 08:31:22 +0000 (09:31 +0100)]
configs: Tune qemu config for X mode changes

X triggers accesses to the QEMU VBE ports and some non-existent port
402. Allow both to (re-)enable graphic mode changes.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agoci: Test CONFIG_TRACE_ERROR in specific targets
Jan Kiszka [Thu, 19 Mar 2015 07:24:14 +0000 (08:24 +0100)]
ci: Test CONFIG_TRACE_ERROR in specific targets

Make sure we test both CONFIG_TRACE_ERROR enabled and disabled by
leaving it off for the Banana Pi, and also test it on both
architectures.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agocore: Simplify error reporting of paging_init
Jan Kiszka [Wed, 18 Mar 2015 07:59:41 +0000 (08:59 +0100)]
core: Simplify error reporting of paging_init

If -ENOMEM shows up at the user, this always means we ran out of pages.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Instrument relevant return paths for error tracing
Jan Kiszka [Wed, 18 Mar 2015 07:56:49 +0000 (08:56 +0100)]
x86: Instrument relevant return paths for error tracing

Add trace_error to return paths so that the origin of important errors
can be tracked down.

CC: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agocore: Instrument relevant return paths for error tracing
Jan Kiszka [Wed, 18 Mar 2015 07:50:25 +0000 (08:50 +0100)]
core: Instrument relevant return paths for error tracing

This instruments return paths so that the origin of important errors can
be tracked down. Two so far explicit error outputs are replaced with
trace_error.

We do not instrument -ENOMEM cases unless they relate to allocations
from the remapping pool. All other -ENOMEM cases boil down to a too
small hypervisor region.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agocore: Introduce error return code tracing
Jan Kiszka [Wed, 18 Mar 2015 07:43:50 +0000 (08:43 +0100)]
core: Introduce error return code tracing

A number of errors that can be reported during setup or while
reconfiguring cells are hard to trace down to their detailed reasons
because of the limited number of error codes available through POSIX.
This Introduces a non-invasive mechanism to instrument error return
paths in the hypervisor and report the origin of a specific error code
in the form

hypervisor/arch/x86/vmx.c:592: returning error -ENODEV

This can then be matched against the source code to find out which check
on the hardware, the system state or the configuration data failed
precisely.

The feature is off by default, requiring CONFIG_TRACE_ERROR to be set in
config.h.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Bring host CR4 into well-defined state during setup
Jan Kiszka [Wed, 18 Mar 2015 07:39:19 +0000 (08:39 +0100)]
x86: Bring host CR4 into well-defined state during setup

Analogously to CR0: Avoid any uncertainty about the state of CR4 left
behind by Linux: check for unexpectedly set reserved bits or required-1
bits, and otherwise set our own state.

A side effect of this change is the VMX's vcpu_exit will no longer clear
VMXE in CR4 but only in the cached Linux state that arch_cpu_restore
will write back.

CC: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Check for availability of xsetbv before executing it for the guest
Jan Kiszka [Fri, 20 Mar 2015 07:07:16 +0000 (08:07 +0100)]
x86: Check for availability of xsetbv before executing it for the guest

Practically, this feature is also available on VMX-capable CPUs, but we
should not rely on it.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Sort and document feature bits
Jan Kiszka [Fri, 20 Mar 2015 07:03:05 +0000 (08:03 +0100)]
x86: Sort and document feature bits

Sort feature bit constants according to their leafs and document their
locations.

CC: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Reformat and cleanup CR4 constants
Jan Kiszka [Wed, 18 Mar 2015 07:11:34 +0000 (08:11 +0100)]
x86: Reformat and cleanup CR4 constants

Encode CR0 constants in an easier readable form, add soon required XSAVE
feature bit and remove unused PGE. Also add a mask of the reserved bits
that need to be left as-is on modifications.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Bring host CR0 into well-defined state during setup
Jan Kiszka [Mon, 16 Mar 2015 08:21:58 +0000 (09:21 +0100)]
x86: Bring host CR0 into well-defined state during setup

Avoid any uncertainty about the state of CR0 left behind by Linux: check
for unexpectedly set reserved bits or required-1 bits, and otherwise set
our own state.

CC: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Rename SVM_CR0_CLEARED_BITS to SVM_CR0_ALLOWED_BITS
Jan Kiszka [Fri, 20 Mar 2015 09:12:53 +0000 (10:12 +0100)]
x86: Rename SVM_CR0_CLEARED_BITS to SVM_CR0_ALLOWED_BITS

Clarifies the semantic.

CC: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Rework CR0/CR4 restriction handling for VMX
Jan Kiszka [Tue, 17 Mar 2015 09:34:59 +0000 (10:34 +0100)]
x86: Rework CR0/CR4 restriction handling for VMX

First of all, we want to reuse the restrictions also for setting the
host CRx values. And then the current implementation would benefit from
more documentation, caching of those static values and checking their
consistency across all CPUs.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Reformat and extend CR0 constants
Jan Kiszka [Mon, 16 Mar 2015 08:18:56 +0000 (09:18 +0100)]
x86: Reformat and extend CR0 constants

Encode CR0 constants in an easier readable form and add some bits we
will need soon. Also add a mask of the reserved bits that need to be
left as-is on modifications.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Drop redundant stgi from SVM's vcpu_deactivate_vmm
Jan Kiszka [Mon, 16 Mar 2015 10:12:56 +0000 (11:12 +0100)]
x86: Drop redundant stgi from SVM's vcpu_deactivate_vmm

Already done via arch_cpu_restore -> vcpu_exit.

CC: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Fix comment wording
Jan Kiszka [Mon, 16 Mar 2015 07:10:14 +0000 (08:10 +0100)]
x86: Fix comment wording

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Add MSR whitelisting to to-do list
Jan Kiszka [Mon, 16 Mar 2015 07:07:05 +0000 (08:07 +0100)]
x86: Add MSR whitelisting to to-do list

We currently allow access to almost all MSRs (except for APIC-related
ones). This has to be changed into a whitelist approach to avoid that
the cell manipulates a CPU state in a way we didn't validate as safe.

CC: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agoconfigs: Update F2A88XM-HD3 config
Valentine Sinitsyn [Wed, 11 Mar 2015 19:36:15 +0000 (00:36 +0500)]
configs: Update F2A88XM-HD3 config

Add single IOMMU entry that covers all built-in peripherals.
Also, include all missing bits of configuration data (mostly
PCI-related anyway).

Signed-off-by: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agotools: Implement ACPI IVRS table parser
Valentine Sinitsyn [Thu, 12 Mar 2015 19:42:24 +0000 (00:42 +0500)]
tools: Implement ACPI IVRS table parser

Add parse_ivrs() function that extracts relevant bits of information
from ACPI IVRS table which describes AMD IOMMU units found in the system.

As VT-d and AMD-Vi impose slightly different requirements on PCI devices
configuration (eg PCI root complex), move sanity checks to corresponding
functions to account for these discrepancies.

Signed-off-by: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agocore: Adapt config structures for non-Intel IOMMU
Valentine Sinitsyn [Wed, 11 Mar 2015 19:36:13 +0000 (00:36 +0500)]
core: Adapt config structures for non-Intel IOMMU

Rename dmar_units_base to iommu_base, and JAILHOUSE_MAX_DMAR_UNITS to
JAILHOUSE_MAX_IOMMU_UNITS.

Update configuration files and root cell config template to account for
new cell definition parameters names.

Signed-off-by: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agoREADME/configs: Improve Jetson TK1 documentation
Jan Kiszka [Wed, 11 Mar 2015 07:31:19 +0000 (08:31 +0100)]
README/configs: Improve Jetson TK1 documentation

Add the board to the list of supported targets and document the required
kernel command line extension.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agoci: Add Coverity model for kmalloc
Jan Kiszka [Thu, 12 Mar 2015 07:00:32 +0000 (08:00 +0100)]
ci: Add Coverity model for kmalloc

kmalloc can actually sanitize a tained size parameter if given the right
GFP flags, namely GFP_USER (to properly tag the request origin) and
__GFP_NOWARN (to avoid WARN_ON when hitting the kmalloc limit). Model
this for Coverity so that it no longer complains about the correct
pattern we use in jailhouse_cmd_cell_create.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agodriver: Correctly tag kmalloc allocation on behalf of user space
Jan Kiszka [Wed, 11 Mar 2015 06:39:43 +0000 (07:39 +0100)]
driver: Correctly tag kmalloc allocation on behalf of user space

When the provided config size if beyond kmalloc limits, it may raise a
WARN_ON. Avoid this by tagging the allocation with __GFP_NOWARN. Also
properly tag it as GFP_USER instead of GFP_KERNEL.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agodriver: Improve input validation to make code scanners happier
Jan Kiszka [Tue, 10 Mar 2015 06:27:43 +0000 (07:27 +0100)]
driver: Improve input validation to make code scanners happier

We trust the configuration files passed down to the driver already
because they define the isolation set up by the hypervisor and can
therefore screw up the system in various ways.

Nevertheless, we can and should improve basic consistency checks of
config fields that influences allocations and copy operations. This will
detect some corruptions/inconsistencies earlier and also satisfies the
Coverity scanner.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agodriver: Silence sparse warnings about incompatible address spaces
Jan Kiszka [Tue, 10 Mar 2015 13:26:55 +0000 (14:26 +0100)]
driver: Silence sparse warnings about incompatible address spaces

All conversion cases are harmless, just ensure that sparse is told this.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Address sparse warnings about missing UL tags for constants
Jan Kiszka [Tue, 10 Mar 2015 13:09:23 +0000 (14:09 +0100)]
x86: Address sparse warnings about missing UL tags for constants

Automatic type conversion saved us in all these cases so far, but better
avoid surprises in the future and another finding turned out to be a bug
in fact.

JAILHOUSE_BASE requires special wrapping as it is also used in assembly
(the linker script) where the UL tag is not understood.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agoarm: Make target_cpu_map static
Jan Kiszka [Mon, 9 Mar 2015 22:38:42 +0000 (23:38 +0100)]
arm: Make target_cpu_map static

No user outside of this file.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agoarm: Remove spurious inline tags from function prototypes
Jan Kiszka [Mon, 9 Mar 2015 22:33:12 +0000 (23:33 +0100)]
arm: Remove spurious inline tags from function prototypes

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>