This patch adds a missing check of mask during probing of PCI BARs. The missing check manifested in wrong address values for the BARs after the initial probe. Reported-by: David Evensky <evensky@xxxxxxxxxxxxxxxxxxxx> Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx> --- tools/kvm/hw/vesa.c | 1 + tools/kvm/include/kvm/pci.h | 4 +++- tools/kvm/pci.c | 11 ++++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tools/kvm/hw/vesa.c b/tools/kvm/hw/vesa.c index 032e630..2af08df 100644 --- a/tools/kvm/hw/vesa.c +++ b/tools/kvm/hw/vesa.c @@ -56,6 +56,7 @@ struct framebuffer *vesa__init(struct kvm *kvm) vesa_pci_device.irq_line = line; vesa_base_addr = ioport__register(IOPORT_EMPTY, &vesa_io_ops, IOPORT_SIZE, NULL); vesa_pci_device.bar[0] = vesa_base_addr | PCI_BASE_ADDRESS_SPACE_IO; + vesa_pci_device.bar_size[0] = VESA_MEM_SIZE; pci__register(&vesa_pci_device, dev); mem = mmap(NULL, VESA_MEM_SIZE, PROT_RW, MAP_ANON_NORESERVE, -1, 0); diff --git a/tools/kvm/include/kvm/pci.h b/tools/kvm/include/kvm/pci.h index 27fa349..2ab5291 100644 --- a/tools/kvm/include/kvm/pci.h +++ b/tools/kvm/include/kvm/pci.h @@ -36,7 +36,7 @@ struct msix_cap { u8 next; u16 table_size; u32 table_offset; - struct msix_table table[3 * PCI_MSIX_ENTRY_SIZE]; + struct msix_table table[3]; }; struct pci_device_header { @@ -63,6 +63,8 @@ struct pci_device_header { u8 min_gnt; u8 max_lat; struct msix_cap msix; + u8 empty[136]; /* Rest of PCI config space */ + u32 bar_size[6]; }; void pci__init(void); diff --git a/tools/kvm/pci.c b/tools/kvm/pci.c index 3b92ea4..fd19b73 100644 --- a/tools/kvm/pci.c +++ b/tools/kvm/pci.c @@ -95,20 +95,25 @@ static bool pci_config_data_out(struct ioport *ioport, struct kvm *kvm, u16 port offset = start + (pci_config_address.register_number << 2); if (offset < sizeof(struct pci_device_header)) { void *p = pci_devices[dev_num]; + u8 bar = offset - PCI_BAR_OFFSET(0); u32 sz = PCI_IO_SIZE; + if (bar < 6 && pci_devices[dev_num]->bar_size[bar]) + sz = pci_devices[dev_num]->bar_size[bar]; + /* * If the kernel masks the BAR it would expect to find the * size of the BAR there next time it reads from it. * When the kernel got the size it would write the address * back. */ - if (*(u32 *)(p + offset)) { + if (ioport__read32(p + offset)) { /* See if kernel tries to mask one of the BARs */ if ((offset >= PCI_BAR_OFFSET(0)) && - (offset <= PCI_BAR_OFFSET(6))) + (offset <= PCI_BAR_OFFSET(6)) && + (ioport__read32(data) == 0xFFFFFFFF)) memcpy(p + offset, &sz, sizeof(sz)); - else + else memcpy(p + offset, data, size); } } -- 1.7.6 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html