]> rtime.felk.cvut.cz Git - jailhouse.git/log
jailhouse.git
9 years agoBump version number
Jan Kiszka [Mon, 11 May 2015 15:14:59 +0000 (17:14 +0200)]
Bump version number

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agoconfig-collect: fix filename typo
Henning Schild [Mon, 11 May 2015 10:58:00 +0000 (12:58 +0200)]
config-collect: fix filename typo

Signed-off-by: Henning Schild <henning.schild@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agodriver: Fix image loading at unaligned addresses
Jan Kiszka [Sun, 10 May 2015 13:27:08 +0000 (15:27 +0200)]
driver: Fix image loading at unaligned addresses

Make sure that images are loaded at the correct location if the target
address is not aligned on a page boundary.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agoarm: Clean up hypervisor stage 1 memory attributes
Jan Kiszka [Sat, 9 May 2015 06:00:41 +0000 (08:00 +0200)]
arm: Clean up hypervisor stage 1 memory attributes

Of the many attributes defined, some probably wrong, only 3 are actually
used: normal memory, device and non-cacheable. Validate those and drop
the rest. We can re-add more as needed.

See ARM ARM B4.1.104.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agoarm: Fix stage 2 memory attributes
Jan Kiszka [Sat, 9 May 2015 05:54:53 +0000 (07:54 +0200)]
arm: Fix stage 2 memory attributes

The definition of memory attributes for stage 2 translations was wrong.
This attributes consist only of 4 bits, but the defines covered 8. Set
the proper values for those two types we use: normal memory and devices.

See ARM ARM B3.6.2 and B3.8.5 for details.

This fixes the enforcement of read-only or write-only cell memory
regions.

Reported-and-tested-by: Philipp Rosenberger <ilu@linutronix.de>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Update CPUID vmexit counter in vmx_handle_cpuid
Jan Kiszka [Thu, 7 May 2015 18:43:13 +0000 (20:43 +0200)]
x86: Update CPUID vmexit counter in vmx_handle_cpuid

Forgotten so far.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agocore: Make field structs of pci_msix_registers and pci_msix_vector anonymous
Jan Kiszka [Thu, 7 May 2015 17:34:01 +0000 (19:34 +0200)]
core: Make field structs of pci_msix_registers and pci_msix_vector anonymous

"field" provides no additional information to the reader, and all
affected sub-fields have unique names, so remove this.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agocore: Disable non-root PCI devices on shutdown
Jan Kiszka [Thu, 7 May 2015 17:27:12 +0000 (19:27 +0200)]
core: Disable non-root PCI devices on shutdown

We already disable PCI devices that are removed when a cell is
destroyed but we should also do this on hypervisor shutdown to avoid
that those device later on annoy Linux with unexpected activities.

The change is bigger as it re-indents the shutdown loop to maintain
readability.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agocore: Do not program MSI-X vectors that are masked
Jan Kiszka [Thu, 7 May 2015 17:10:20 +0000 (19:10 +0200)]
core: Do not program MSI-X vectors that are masked

Test for both function-level and vector-level masking before updating a
MSI-X interrupt mapping. Otherwise, we risk to let cells stumble over
stall but masked vector entries.

All accesses to a vector table entry now cause a mapping update. The
vector control dword is always cached to simplify testing it.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agocore: Break up pci_msix_vector control field
Jan Kiszka [Thu, 7 May 2015 17:08:02 +0000 (19:08 +0200)]
core: Break up pci_msix_vector control field

Avoid testing the masked bit via a magic value.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Fix vtd int-remap region release
Jan Kiszka [Thu, 7 May 2015 16:14:53 +0000 (18:14 +0200)]
x86: Fix vtd int-remap region release

Tiny mistake, but it had the effect of only releasing the first MSI or
MSI-X vector of a PCI device on removal. The succeeding ones remained
both active for vtd and occupied for vtd_reserve_int_remap_region.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Reject xAPIC accesses while in x2APIC mode
Jan Kiszka [Wed, 6 May 2015 07:12:05 +0000 (09:12 +0200)]
x86: Reject xAPIC accesses while in x2APIC mode

If the APIC is in x2APIC mode, accesses via MMIO are not working (APIC
behaves like disabled). If Jailhouse executes them, it can be tricked to
access x2APIC registers that are invalid, causing a hypervisor-side #GP.
Prevent this by bailing out early.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agoinmates: x86: Enable MTRRs during start to avoid disable caches
Jan Kiszka [Wed, 6 May 2015 05:43:47 +0000 (07:43 +0200)]
inmates: x86: Enable MTRRs during start to avoid disable caches

Since fe8fac80d7, emulation of the MTRR enable bit works. That has no
effect on KVM so far, but we effectively run with hand break put on over
real hardware.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Allow access to Focus Processor Checking bit in APIC SVR
Jan Kiszka [Fri, 1 May 2015 13:04:27 +0000 (15:04 +0200)]
x86: Allow access to Focus Processor Checking bit in APIC SVR

The Intel manual says: "In Pentium 4 and Intel Xeon processors, this bit
is reserved and should be cleared to 0." It apparently refers to the
first Xeon series here, not newer ones that support IA32e. Linux sets
this bit on x86-64 unconditionally for more than a decade. There are no
availability restrictions mentioned for AMD at all.

So let's release this bit to the cells because it cannot cause any harm
to the system or the hypervisor.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Hand over the APIC in soft-disabled state
Jan Kiszka [Sat, 2 May 2015 10:34:39 +0000 (12:34 +0200)]
x86: Hand over the APIC in soft-disabled state

This brings the Spurious-Interrupt Vector Register into its well-defined
reset state before handing the APIC over. Avoids surprises for cells and
the need for additional explanations.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Enable APIC for clearing
Jan Kiszka [Sat, 2 May 2015 10:24:21 +0000 (12:24 +0200)]
x86: Enable APIC for clearing

The cell may have turned it off, and then our attempts to clear pending
interrupts will be in vain.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agoRevert "x86: Make FS_BASE MSR restoration VMX-specific"
Jan Kiszka [Wed, 6 May 2015 05:28:52 +0000 (07:28 +0200)]
Revert "x86: Make FS_BASE MSR restoration VMX-specific"

This reverts commit ee283bcf1818076662d897d489260f09d2b46c6c.

Loading the FS selector with 0 in arch_cpu_restore clears the base on
real hardware. Thus we have to reload it and can't apply this
optimization.

This bug caused crashes of the jailhouse tool.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agocore: Add BSD 2-Clause license to hypercall headers
Jan Kiszka [Fri, 20 Feb 2015 08:51:42 +0000 (09:51 +0100)]
core: Add BSD 2-Clause license to hypercall headers

This allows to use our types, inline functions etc. for interacting with
the hypervisor from within differently licensed cells.

Contributions came from Valentine, Jean-Philippe, Henning and me. I'm
signing off for Henning as well in the name of Siemens.

CC: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
CC: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
Signed-off-by: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
9 years agoarm: Remove ancient compiler bug test via __asmeq
Jan Kiszka [Mon, 4 May 2015 17:38:37 +0000 (19:38 +0200)]
arm: Remove ancient compiler bug test via __asmeq

This macro was once copied in from the Linux kernel. There it tries to
catch buggy gcc 3.x versions that didn't follow the specified register
assignments (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=15089).

This bug is now 10 years old, fixed, and affected compilers that weren't
even aware of the virt extensions for ARMv7 that we depend on anyway. So
let's remove it.

This also removes a GPL'ed line of code, thus enables a dual-licensing
of the file.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agocore: Add BSD 2-Clause license to configuration format header
Jan Kiszka [Fri, 20 Feb 2015 08:46:32 +0000 (09:46 +0100)]
core: Add BSD 2-Clause license to configuration format header

This avoids having to distribute configuration files for target systems
under GPL terms. It also allows to process those files with differently
licensed management tools.

Contributions came from Valentine, Henning and me. I'm signing off for
Henning as well in the name of Siemens.

CC: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
9 years agotools: Add BSD 2-Clause license to configuration file template
Jan Kiszka [Fri, 20 Feb 2015 08:34:56 +0000 (09:34 +0100)]
tools: Add BSD 2-Clause license to configuration file template

This avoids having to distribute configuration files for target systems
under GPL terms.

Contributions came from Valentine, Henning and me. I'm signing off for
Henning as well in the name of Siemens.

CC: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
9 years agodriver: Add BSD 2-Clause license to user space interface header
Jan Kiszka [Fri, 20 Feb 2015 08:30:59 +0000 (09:30 +0100)]
driver: Add BSD 2-Clause license to user space interface header

This enables the development of alternatively licensed management
front-ends.

Contributions came from me only.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agoImprove documentation of license application
Jan Kiszka [Tue, 14 Apr 2015 05:44:34 +0000 (07:44 +0200)]
Improve documentation of license application

This prepares for deviations from our GPLv2 default license and explains
both the why and the how better.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: clarify svm.h origins
Valentine Sinitsyn [Tue, 5 May 2015 19:24:44 +0000 (00:24 +0500)]
x86: clarify svm.h origins

Add specific file and copyrights for data structures in svm.h
headers file.

Signed-off-by: Valentine Sinitsyn <valentine.sinitsyn@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
9 years agox86: Add copyright information to files with Linux roots
Jan Kiszka [Mon, 23 Feb 2015 15:35:00 +0000 (16:35 +0100)]
x86: Add copyright information to files with Linux roots

Some x86 headers and a Makefile have more or less significant roots in
the Linux kernel without declaring this properly so far. Fix it.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
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>