Once the Jailhouse is disabled, there is no one handling accesses to the
virtual shared memory devices anymore. So better remove them from Linux
before the actual disabling hypercall. To remain symmetric, we also pull
adding out of jailhouse_cell_register_root.

Signed-off-by: Jan Kiszka <[email protected]>
---
 driver/cell.c |  6 ------
 driver/main.c |  3 +++
 driver/pci.c  | 12 ++++++++++++
 driver/pci.h  | 10 ++++++++++
 4 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/driver/cell.c b/driver/cell.c
index 1873126..0b5ac38 100644
--- a/driver/cell.c
+++ b/driver/cell.c
@@ -135,18 +135,12 @@ int jailhouse_cell_prepare_root(const struct 
jailhouse_cell_desc *cell_desc)
 
 void jailhouse_cell_register_root(void)
 {
-       jailhouse_pci_do_all_devices(root_cell, JAILHOUSE_PCI_TYPE_IVSHMEM,
-                                    JAILHOUSE_PCI_ACTION_ADD);
-
        root_cell->id = 0;
        cell_register(root_cell);
 }
 
 void jailhouse_cell_delete_root(void)
 {
-       jailhouse_pci_do_all_devices(root_cell, JAILHOUSE_PCI_TYPE_IVSHMEM,
-                                    JAILHOUSE_PCI_ACTION_DEL);
-
        cell_delete(root_cell);
 }
 
diff --git a/driver/main.c b/driver/main.c
index d6834ef..2c6f1c7 100644
--- a/driver/main.c
+++ b/driver/main.c
@@ -341,6 +341,7 @@ static int jailhouse_cmd_enable(struct jailhouse_system 
__user *arg)
        release_firmware(hypervisor);
 
        jailhouse_cell_register_root();
+       jailhouse_pci_virtual_root_devices_add();
 
        jailhouse_enabled = true;
 
@@ -411,6 +412,8 @@ static int jailhouse_cmd_disable(void)
        if (err)
                goto unlock_out;
 
+       jailhouse_pci_virtual_root_devices_remove();
+
        error_code = 0;
 
        preempt_disable();
diff --git a/driver/pci.c b/driver/pci.c
index 14c21f6..9a95856 100644
--- a/driver/pci.c
+++ b/driver/pci.c
@@ -227,3 +227,15 @@ void jailhouse_pci_cell_cleanup(struct cell *cell)
 {
        vfree(cell->pci_devices);
 }
+
+void jailhouse_pci_virtual_root_devices_add(void)
+{
+       jailhouse_pci_do_all_devices(root_cell, JAILHOUSE_PCI_TYPE_IVSHMEM,
+                                    JAILHOUSE_PCI_ACTION_ADD);
+}
+
+void jailhouse_pci_virtual_root_devices_remove(void)
+{
+       jailhouse_pci_do_all_devices(root_cell, JAILHOUSE_PCI_TYPE_IVSHMEM,
+                                    JAILHOUSE_PCI_ACTION_DEL);
+}
diff --git a/driver/pci.h b/driver/pci.h
index d86a6b6..6b358c5 100644
--- a/driver/pci.h
+++ b/driver/pci.h
@@ -25,6 +25,8 @@ void jailhouse_pci_do_all_devices(struct cell *cell, unsigned 
int type,
 int jailhouse_pci_cell_setup(struct cell *cell,
                             const struct jailhouse_cell_desc *cell_desc);
 void jailhouse_pci_cell_cleanup(struct cell *cell);
+void jailhouse_pci_virtual_root_devices_add(void);
+void jailhouse_pci_virtual_root_devices_remove(void);
 int jailhouse_pci_register(void);
 void jailhouse_pci_unregister(void);
 
@@ -47,6 +49,14 @@ static inline void jailhouse_pci_cell_cleanup(struct cell 
*cell)
 {
 }
 
+static inline void jailhouse_pci_virtual_root_devices_add(void)
+{
+}
+
+static inline void jailhouse_pci_virtual_root_devices_remove(void)
+{
+}
+
 static inline int jailhouse_pci_register(void)
 {
        return 0;
-- 
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.

Reply via email to