mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-11-26 03:25:25 +00:00
kvm tools: Fix PCI masking on probes
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@dancer.ca.sandia.gov> Signed-off-by: Sasha Levin <levinsasha928@gmail.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
@@ -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);
|
||||
|
||||
+3
-1
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user