xemu/hw
Konrad Rzeszutek Wilk 2e87512ecc xen/pt: Sync up the dev.config and data values.
For a passthrough device we maintain a state of emulated
registers value contained within d->config. We also consult
the host registers (and apply ro and write masks) whenever
the guest access the registers. This is done in xen_pt_pci_write_config
and xen_pt_pci_read_config.

Also in this picture we call pci_default_write_config which
updates the d->config and if the d->config[PCI_COMMAND] register
has PCI_COMMAND_MEMORY (or PCI_COMMAND_IO) acts on those changes.

On startup the d->config[PCI_COMMAND] are the host values, not
what the guest initial values should be, which is exactly what
we do _not_ want to do for 64-bit BARs when the guest just wants
to read the size of the BAR. Huh you say?

To get the size of 64-bit memory space BARs,  the guest has
to calculate ((BAR[x] & 0xFFFFFFF0) + ((BAR[x+1] & 0xFFFFFFFF) << 32))
which means it has to do two writes of ~0 to BARx and BARx+1.

prior to this patch and with XSA120-addendum patch (Linux kernel)
the PCI_COMMAND register is copied from the host it can have
PCI_COMMAND_MEMORY bit set which means that QEMU will try to
update the hypervisor's P2M with BARx+1 value to ~0 (0xffffffff)
(to sync the guest state to host) instead of just having
xen_pt_pci_write_config and xen_pt_bar_reg_write apply the
proper masks and return the size to the guest.

To thwart this, this patch syncs up the host values with the
guest values taking into account the emu_mask (bit set means
we emulate, PCI_COMMAND_MEMORY and PCI_COMMAND_IO are set).
That is we copy the host values - masking out any bits which
we will emulate. Then merge it with the initial emulation register
values. Lastly this value is then copied both in
dev.config _and_ XenPTReg->data field.

There is also reg->size accounting taken into consideration
that ends up being used in patch.
 xen/pt: Check if reg->init function sets the 'data' past the reg->size

This fixes errors such as these:

(XEN) memory_map:add: dom2 gfn=fffe0 mfn=fbce0 nr=20
(DEBUG) 189 pci dev 04:0 BAR16 wrote ~0.
(DEBUG) 200 pci dev 04:0 BAR16 read 0x0fffe0004.
(XEN) memory_map:remove: dom2 gfn=fffe0 mfn=fbce0 nr=20
(DEBUG) 204 pci dev 04:0 BAR16 wrote 0x0fffe0004.
(DEBUG) 217 pci dev 04:0 BAR16 read upper 0x000000000.
(XEN) memory_map:add: dom2 gfn=ffffffff00000 mfn=fbce0 nr=20
(XEN) p2m.c:883:d0v0 p2m_set_entry failed! mfn=ffffffffffffffff rc:-22
(XEN) memory_map:fail: dom2 gfn=ffffffff00000 mfn=fbce0 nr=20 ret:-22
(XEN) memory_map:remove: dom2 gfn=ffffffff00000 mfn=fbce0 nr=20
(XEN) p2m.c:920:d0v0 gfn_to_mfn failed! gfn=ffffffff00000 type:4
(XEN) p2m.c:920:d0v0 gfn_to_mfn failed! gfn=ffffffff00001 type:4
..
(XEN) memory_map: error -22 removing dom2 access to [fbce0,fbcff]
(DEBUG) 222 pci dev 04:0 BAR16 read upper 0x0ffffffff.
(XEN) memory_map:remove: dom2 gfn=ffffffff00000 mfn=fbce0 nr=20
(XEN) memory_map: error -22 removing dom2 access to [fbce0,fbcff]

[The DEBUG is to illustate what the hvmloader was doing]

Also we swap from xen_host_pci_long to using xen_host_pci_get_[byte,word,long].

Otherwise we get:

xen_pt_config_reg_init: Offset 0x0004 mismatch! Emulated=0x0000, host=0x2300017, syncing to 0x2300014.
xen_pt_config_reg_init: Error: Offset 0x0004:0x2300014 expands past register size(2)!

which is not surprising. We read the value as an 32-bit (from host),
then operate it as a 16-bit - and the remainder is left unchanged.

We end up writing the value as 16-bit (so 0014) to dev.config
(as we use proper xen_set_host_[byte,word,long] so we don't spill
to other registers) but in XenPTReg->data it is as 32-bit (0x2300014)!

It is harmless as the read/write functions end up using an size mask
and never modify the bits past 16-bit (reg->size is 2).

This patch fixes the warnings by reading the value using the
proper size.

Note that the check for size is still left in-case the developer
sets bits past the reg->size in the ->init routines. The author
tried to fiddle with QEMU_BUILD_BUG to make this work but failed.

Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Reported-by: Sander Eikelenboom <linux@eikelenboom.it>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
2015-09-10 16:47:03 +00:00
..
9pfs virtio: get_features() can fail 2015-07-27 18:11:53 +03:00
acpi hw/acpi/ich9: clean up stale comment about KVM not supporting SMM 2015-07-27 22:44:47 +03:00
alpha hw/alpha/typhoon.c: Fix misusing qemu_allocate_irqs for single irq 2015-06-03 14:21:24 +03:00
arm arm/virt: Add full-sized CPU affinity handling 2015-09-07 10:39:31 +01:00
audio gus: clean up MemoryRegionPortio 2015-04-27 18:24:18 +02:00
block hw/block/nvme.c: Use pow2ceil() rather than hand-calculation 2015-09-07 14:19:00 +01:00
bt bt-sdp: fix broken uuids power-of-2 calculation 2015-04-28 15:36:08 +02:00
char i.MX: KZM: use standalone i.MX31 SOC support 2015-09-07 10:39:30 +01:00
core xen, gfx passthrough: basic graphics passthrough support 2015-09-10 12:04:28 +00:00
cpu hw/cpu/a15mpcore: Wire up hyp and secure physical timer interrupts 2015-08-13 11:26:22 +01:00
cris cris: memory: Replace memory_region_init_ram with memory_region_allocate_system_memory 2015-04-11 20:03:57 +10:00
display arm: Use g_new() & friends where that makes obvious sense 2015-09-07 10:39:27 +01:00
dma arm: Use g_new() & friends where that makes obvious sense 2015-09-07 10:39:27 +01:00
gpio arm: Use g_new() & friends where that makes obvious sense 2015-09-07 10:39:27 +01:00
i2c i.MX: Add I2C controller emulator 2015-09-07 10:39:30 +01:00
i386 xen, gfx passthrough: register host bridge specific to passthrough 2015-09-10 12:04:29 +00:00
ide Fix release_drive on unplugged devices (pci_piix3_xen_ide_unplug) 2015-08-03 14:27:12 +00:00
input arm: Use g_new() & friends where that makes obvious sense 2015-09-07 10:39:27 +01:00
intc s390x/kvm: make setting of in-kernel irq routes more efficient 2015-09-07 16:10:43 +02:00
ipack pci: Trivial device model conversions to realize 2015-02-26 12:42:16 +01:00
isa ich9: implement strap SPKR pin logic 2015-07-08 10:09:55 +03:00
lm32 hw/lm32/milkymist.c: Fix misusing qemu_allocate_irqs for single irq 2015-06-03 14:21:24 +03:00
m68k m68k: implement more ColdFire 5208 interrupt controller functionality 2015-06-22 14:43:25 +01:00
mem numa,pc-dimm: Store pc-dimm memory information in numa_info 2015-07-03 17:47:58 -03:00
microblaze microblaze: boot: Use cpu_set_pc() 2015-07-09 15:20:40 +02:00
mips target-mips: add Unified Hosting Interface (UHI) support 2015-06-26 09:08:50 +01:00
misc arm: Use g_new() & friends where that makes obvious sense 2015-09-07 10:39:27 +01:00
moxie memory: add parameter errp to memory_region_init_ram 2014-09-09 13:41:43 +02:00
net i.MX: Add FEC Ethernet Emulator 2015-09-07 10:39:30 +01:00
nvram spapr: Merge sPAPREnvironment into sPAPRMachineState 2015-07-07 17:44:50 +02:00
openrisc hw/core/loader: implement address translation in uimage loader 2014-11-03 00:59:10 +03:00
pci hw/pci: Use pow2ceil() rather than hand-calculation 2015-09-07 14:19:00 +01:00
pci-bridge hw/pci-bridge: format special OFW unit address for PXB host 2015-06-23 22:58:36 +02:00
pci-host piix: create host bridge to passthrough 2015-09-10 12:04:09 +00:00
pcmcia hmp: Remove "info pcmcia" 2014-10-24 12:19:11 +01:00
ppc pci: allow 0 address for PCI IO/MEM regions 2015-08-13 14:08:29 +03:00
s390x s390/sclp: simplify calculation of rnmax 2015-09-07 16:10:44 +02:00
scsi scsi-generic: identify AIO callbacks more clearly 2015-08-14 23:40:32 +02:00
sd arm: Use g_new() & friends where that makes obvious sense 2015-09-07 10:39:27 +01:00
sh4 sh4/r2d: convert to new MMIO accessor style 2015-06-12 12:02:48 +02:00
smbios smbios: add smbios 3.0 support 2015-09-07 10:39:28 +01:00
sparc fw_cfg: fix FW_CFG_BOOT_DEVICE update on ppc and sparc 2015-06-10 08:00:37 +02:00
sparc64 fw_cfg: fix FW_CFG_BOOT_DEVICE update on ppc and sparc 2015-06-10 08:00:37 +02:00
ssi arm: Use g_new() & friends where that makes obvious sense 2015-09-07 10:39:27 +01:00
timer i.MX: KZM: use standalone i.MX31 SOC support 2015-09-07 10:39:30 +01:00
tpm qerror: Move #include out of qerror.h 2015-06-22 18:20:40 +02:00
tricore target-tricore: check return value before using it 2014-11-02 10:04:34 +03:00
unicore32 hw/unicore32/puv3.c: Fix misusing qemu_allocate_irqs for single irq 2015-06-03 14:21:24 +03:00
usb usbnet: Drop usbnet_can_receive 2015-07-27 14:12:18 +01:00
vfio vfio/pci: Fix bootindex 2015-07-22 14:56:01 -06:00
virtio hw/virtio/virtio-pci: Use pow2ceil() rather than hand-calculation 2015-09-07 14:19:00 +01:00
watchdog watchdog/diag288: correctly register for system reset requests 2015-07-14 19:10:03 +02:00
xen xen/pt: Sync up the dev.config and data values. 2015-09-10 16:47:03 +00:00
xenpv hw: Convert from BlockDriverState to BlockBackend, mostly 2014-10-20 14:02:25 +02:00
xtensa xtensa: Remove superfluous '\n' around error_report() 2015-03-10 08:15:33 +03:00
Makefile.objs smbios: move smbios code into a common folder 2015-08-13 14:08:30 +03:00