]> rtime.felk.cvut.cz Git - jailhouse.git/commitdiff
x86: Make vtd_remove_device_from_cell more robust against non-existent devices
authorJan Kiszka <jan.kiszka@siemens.com>
Fri, 6 Jun 2014 16:58:53 +0000 (18:58 +0200)
committerJan Kiszka <jan.kiszka@siemens.com>
Sat, 14 Jun 2014 17:06:50 +0000 (19:06 +0200)
Do not crash if we call vtd_remove_device_from_cell for a device that is
not added to a cell, and there is even no corresponding context table.
This allows to use vtd_remove_device_from_cell e.g. for rollbacks of
half-done configurations after an error occurred.

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

index ca6fe92f52316ed1f749e17caa88ad728db76928..3018d504cdd1515246aa59ddf8361d4f3541e9eb 100644 (file)
@@ -397,11 +397,16 @@ vtd_remove_device_from_cell(struct cell *cell,
                            const struct jailhouse_pci_device *device)
 {
        u64 root_entry_lo = root_entry_table[device->bus].lo_word;
-       struct vtd_entry *context_entry_table =
-               page_map_phys2hvirt(root_entry_lo & PAGE_MASK);
-       struct vtd_entry *context_entry = &context_entry_table[device->devfn];
+       struct vtd_entry *context_entry_table;
+       struct vtd_entry *context_entry;
        unsigned int n;
 
+       if (!(root_entry_lo & VTD_ROOT_PRESENT))
+               return;
+
+       context_entry_table = page_map_phys2hvirt(root_entry_lo & PAGE_MASK);
+       context_entry = &context_entry_table[device->devfn];
+
        if (!(context_entry->lo_word & VTD_CTX_PRESENT))
                return;