]> rtime.felk.cvut.cz Git - jailhouse.git/commitdiff
x86: Guard vtd_add_device_to_cell against addition of existing devices
authorJan Kiszka <jan.kiszka@siemens.com>
Thu, 5 Jun 2014 14:36:42 +0000 (16:36 +0200)
committerJan Kiszka <jan.kiszka@siemens.com>
Sat, 14 Jun 2014 17:09:29 +0000 (19:09 +0200)
Avoid that we add an already registered device to a cell, specifically
that we report this to the console. This case can happen soon when
rolling back failed cell creations.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
hypervisor/arch/x86/vtd.c

index 98ac834ec9f74fdf82dcdc630b370a995ddadc1c..04416b4890395b9b10df197c1f00e18e19c4947e 100644 (file)
@@ -308,10 +308,6 @@ static bool vtd_add_device_to_cell(struct cell *cell,
        u64 root_entry_lo = root_entry_table[device->bus].lo_word;
        struct vtd_entry *context_entry_table, *context_entry;
 
-       printk("Adding PCI device %02x:%02x.%x to cell \"%s\"\n",
-              device->bus, device->devfn >> 3, device->devfn & 7,
-              cell->config->name);
-
        if (root_entry_lo & VTD_ROOT_PRESENT) {
                context_entry_table =
                        page_map_phys2hvirt(root_entry_lo & PAGE_MASK);
@@ -326,6 +322,13 @@ static bool vtd_add_device_to_cell(struct cell *cell,
        }
 
        context_entry = &context_entry_table[device->devfn];
+       if (context_entry->lo_word & VTD_CTX_PRESENT)
+               return true;
+
+       printk("Adding PCI device %02x:%02x.%x to cell \"%s\"\n",
+              device->bus, device->devfn >> 3, device->devfn & 7,
+              cell->config->name);
+
        context_entry->lo_word = VTD_CTX_PRESENT | VTD_CTX_TTYPE_MLP_UNTRANS |
                page_map_hvirt2phys(cell->vtd.pg_structs.root_table);
        context_entry->hi_word =