x86: Drop has_modrm from mmio_parse

We only support instructions with modrm byte for now and in the
foreseeable future.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
x86: Drop double initialization in mmio_parse

Already initialized along with declaration.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
x86: Decode opcode bytes via single union

Stick struct modrm and struct sib into a union that shall help to decode
all supported variants of opcode bytes.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
x86: Rework REX prefix parsing

Decode the REX prefix via union opcode, rejecting REX.X and REX.B but
now accepting (over-reading) REX.W.

Based on original patch by Ivan Kolchin.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
x86: Extend ModR/M support

This adds support for all rm modes except 5 (32-bit displacement /
RIP-relative addressing) in mod 0.

Based on patch by Ivan Kolchin.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
x86: Filter out unsupported ModR/M + SIB in mod 2

We don't handle this case, so bail out instead of misinterpreting the
opcode.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
core: Add support for a guest to access memory-mapped PCI configuration space

This patch is continuation of PIO support to request PCI config space.
Now it can be reached via MMIO. So, filtering logics is pretty similar.
Read accesses to PCI config is allowed just for devices which are owned.
Write accesses are regulated in accordance with white-list.

There are some limitations though as follows:
- Just 4-bytes operations are supported
- Guest must use only instructions 0x6b and 0x89 (read/write through intermediate
registers)
- All-1's write not supported

Signed-off-by: Ivan Kolchin <ivan.kolchin@siemens.com>
[Jan: style adjustments]
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
core: Avoid exposing register set to pci_mmio_access_handler

This handler is generic and should not assume anything about how
registers can be accessed. At this chance, replace the open-coded MMIO
accesses with the appropriate helpers.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
core: Report access violations from pci_mmio_access_handler

Write accesses to unowned devices or blocked config space registers are
violations that shall be reported.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
x86: Advance guest EIP only on successful vmexit handling

Otherwise we will report the wrong EIP value in the panic dump.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
x86: Clear general purpose registers outside of vmx_cpu_reset

We will reuse vmx_cpu_reset - without the need to reset the general
purpose registers, and without a reference to them.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
x86: Reset virtual CPU before parking it

We may bring the vCPU in an invalid state by setting HLT condition,
namely when SS.DPL != 0. Instead of fix this case and risking to miss
another, simply do a full reset which brings the vCPU to a known-good
state.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
driver: Catch invalid configurations during cell load

In case a target memory region for image loading is either not loadable
or writable, avoid trying this - and crashing Linux.

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