So far, we created another ivshmem_data structure in case two devices matched by BDF but not by their shared memory regions. This did not make sense (ivshmem_find only returns the first BDF match) and it could leak the data structure when the device was destroyed again.
Change the policy so that we match on BDF but fail creating the second device in case of region mismatch. Signed-off-by: Jan Kiszka <[email protected]> --- hypervisor/ivshmem.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/hypervisor/ivshmem.c b/hypervisor/ivshmem.c index f8d4feb..f06622b 100644 --- a/hypervisor/ivshmem.c +++ b/hypervisor/ivshmem.c @@ -393,21 +393,24 @@ int ivshmem_init(struct cell *cell, struct pci_device *device) + device->info->shmem_region; ivp = ivshmem_find(device, NULL); if (ivp) { + if ((*ivp)->eps[1].device) + return trace_error(-EBUSY); + dev0 = (*ivp)->eps[0].device; mem0 = jailhouse_cell_mem_regions(dev0->cell->config) + dev0->info->shmem_region; + /* check that the regions of both peers match */ + if (mem0->phys_start != mem->phys_start || + mem0->size != mem->size) + return trace_error(-EINVAL); + /* we already have a datastructure, connect second endpoint */ - if ((mem0->phys_start == mem->phys_start) && - (mem0->size == mem->size)) { - if ((*ivp)->eps[1].device) - return trace_error(-EBUSY); - ivshmem_connect_cell(*ivp, device, mem, 1); - printk("Virtual PCI connection established " - "\"%s\" <--> \"%s\"\n", - cell->config->name, dev0->cell->config->name); - goto connected; - } + ivshmem_connect_cell(*ivp, device, mem, 1); + printk("Virtual PCI connection established " + "\"%s\" <--> \"%s\"\n", + cell->config->name, dev0->cell->config->name); + goto connected; } /* this is the first endpoint, allocate a new datastructure */ -- 2.1.4 -- You received this message because you are subscribed to the Google Groups "Jailhouse" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
