Page MenuHomeFreeBSD

D60235.id188422.diff
No OneTemporary

D60235.id188422.diff

diff --git a/usr.sbin/bhyve/pci_emul.h b/usr.sbin/bhyve/pci_emul.h
--- a/usr.sbin/bhyve/pci_emul.h
+++ b/usr.sbin/bhyve/pci_emul.h
@@ -266,6 +266,7 @@
#ifdef BHYVE_SNAPSHOT
struct pci_devinst *pci_next(const struct pci_devinst *cursor);
int pci_snapshot(struct vm_snapshot_meta *meta);
+void pci_restore_prepare(void);
int pci_pause(struct pci_devinst *pdi);
int pci_resume(struct pci_devinst *pdi);
#endif
diff --git a/usr.sbin/bhyve/pci_emul.c b/usr.sbin/bhyve/pci_emul.c
--- a/usr.sbin/bhyve/pci_emul.c
+++ b/usr.sbin/bhyve/pci_emul.c
@@ -2494,6 +2494,48 @@
#endif
#ifdef BHYVE_SNAPSHOT
+/*
+ * Register or unregister the regions of the BARs that the device decodes.
+ */
+static void
+pci_restore_register_bars(struct pci_devinst *pi, int registration)
+{
+ int decode, i;
+
+ for (i = 0; i <= PCI_BARMAX; i++) {
+ switch (pi->pi_bar[i].type) {
+ case PCIBAR_IO:
+ decode = porten(pi);
+ break;
+ case PCIBAR_MEM32:
+ case PCIBAR_MEM64:
+ decode = memen(pi);
+ break;
+ default:
+ continue;
+ }
+ if (decode && pi->pi_bar[i].size != 0)
+ modify_bar_registration(pi, i, registration);
+ }
+}
+
+/*
+ * To be called before the devices are restored. The regions of the BARs are
+ * registered at the addresses pci_emul_alloc_bar() chose; the restore of a
+ * device registers them at the addresses the guest had given them. All
+ * devices give up their regions first, because a restored BAR may be where
+ * the BAR of another device is now.
+ */
+void
+pci_restore_prepare(void)
+{
+ struct pci_devinst *pi;
+
+ pi = NULL;
+ while ((pi = pci_next(pi)) != NULL)
+ pci_restore_register_bars(pi, 0);
+}
+
/*
* Saves/restores PCI device emulated state. Returns 0 on success.
*/
@@ -2528,6 +2570,8 @@
SNAPSHOT_VAR_OR_LEAVE(pi->pi_bar[i].size, meta, ret, done);
SNAPSHOT_VAR_OR_LEAVE(pi->pi_bar[i].addr, meta, ret, done);
}
+ if (meta->op == VM_SNAPSHOT_RESTORE)
+ pci_restore_register_bars(pi, 1);
/* Restore MSI-X table. */
for (i = 0; i < pi->pi_msix.table_count; i++) {
diff --git a/usr.sbin/bhyve/snapshot.c b/usr.sbin/bhyve/snapshot.c
--- a/usr.sbin/bhyve/snapshot.c
+++ b/usr.sbin/bhyve/snapshot.c
@@ -876,6 +876,8 @@
int ret;
struct pci_devinst *pdi = NULL;
+ pci_restore_prepare();
+
while ((pdi = pci_next(pdi)) != NULL) {
ret = vm_restore_device(rstate, pci_snapshot, pdi->pi_name, pdi);
if (ret)

File Metadata

Mime Type
text/plain
Expires
Sun, Oct 4, 12:22 AM (2 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40138819
Default Alt Text
D60235.id188422.diff (2 KB)

Event Timeline