git: 4ad4ddca0818 - main - bhyve: Reject unsupported checkpoints before saving RAM
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 17 Nov 2026 00:42:01 UTC
The branch main has been updated by hayzam:
URL: https://cgit.FreeBSD.org/src/commit/?id=4ad4ddca08186d6a986655e4845bf0e29f93a961
commit 4ad4ddca08186d6a986655e4845bf0e29f93a961
Author: Hayzam Sherif <hayzam@FreeBSD.org>
AuthorDate: 2026-11-16 23:28:45 +0000
Commit: Hayzam Sherif <hayzam@FreeBSD.org>
CommitDate: 2026-11-17 00:34:01 +0000
bhyve: Reject unsupported checkpoints before saving RAM
pci_snapshot() rejects devices without a pe_snapshot callback, but
vm_checkpoint() reaches that check only after truncating checkpoint
files, pausing the VM, and saving RAM and kernel state.
Check for unsupported PCI devices at the start of vm_checkpoint(),
before creating files or pausing the VM. This preserves existing
checkpoint files when the request cannot succeed. Add
pci_can_snapshot() so that the new check and pci_snapshot() use the
same test.
Reviewed by: markj, kevans
Approved by: markj (mentor)
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D61003
---
usr.sbin/bhyve/pci_emul.c | 9 ++++++++-
usr.sbin/bhyve/pci_emul.h | 1 +
usr.sbin/bhyve/snapshot.c | 21 +++++++++++++++++++++
3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/usr.sbin/bhyve/pci_emul.c b/usr.sbin/bhyve/pci_emul.c
index 1ce9478bdebc..d9a0ef0ce3ee 100644
--- a/usr.sbin/bhyve/pci_emul.c
+++ b/usr.sbin/bhyve/pci_emul.c
@@ -2603,6 +2603,13 @@ done:
return (ret);
}
+bool
+pci_can_snapshot(const struct pci_devinst *pdi)
+{
+
+ return (pdi->pi_d->pe_snapshot != NULL);
+}
+
int
pci_snapshot(struct vm_snapshot_meta *meta)
{
@@ -2615,7 +2622,7 @@ pci_snapshot(struct vm_snapshot_meta *meta)
pdi = meta->dev_data;
pde = pdi->pi_d;
- if (pde->pe_snapshot == NULL)
+ if (!pci_can_snapshot(pdi))
return (ENOTSUP);
ret = pci_snapshot_pci_dev(meta);
diff --git a/usr.sbin/bhyve/pci_emul.h b/usr.sbin/bhyve/pci_emul.h
index d536e53d01e3..fca96dbbae0f 100644
--- a/usr.sbin/bhyve/pci_emul.h
+++ b/usr.sbin/bhyve/pci_emul.h
@@ -267,6 +267,7 @@ int pci_bus_configured(int bus);
#ifdef BHYVE_SNAPSHOT
struct pci_devinst *pci_next(const struct pci_devinst *cursor);
+bool pci_can_snapshot(const struct pci_devinst *pdi);
int pci_snapshot(struct vm_snapshot_meta *meta);
void pci_restore_prepare(void);
int pci_pause(struct pci_devinst *pdi);
diff --git a/usr.sbin/bhyve/snapshot.c b/usr.sbin/bhyve/snapshot.c
index 067b05622e68..9f35ba3d5efa 100644
--- a/usr.sbin/bhyve/snapshot.c
+++ b/usr.sbin/bhyve/snapshot.c
@@ -1085,6 +1085,23 @@ vm_snapshot_device(vm_snapshot_dev_cb func, const char *dev_name,
return (0);
}
+static bool
+vm_can_snapshot_devices(void)
+{
+ struct pci_devinst *pdi;
+
+ pdi = NULL;
+ while ((pdi = pci_next(pdi)) != NULL) {
+ if (!pci_can_snapshot(pdi)) {
+ EPRINTLN("%s does not support checkpointing",
+ pdi->pi_name);
+ return (false);
+ }
+ }
+
+ return (true);
+}
+
static int
vm_snapshot_devices(int data_fd, xo_handle_t *xop)
{
@@ -1227,6 +1244,10 @@ vm_checkpoint(struct vmctx *ctx, int fddir, const char *checkpoint_file,
char *kdata_filename = NULL;
FILE *meta_file = NULL;
+ /* Reject unsupported devices before creating files or touching RAM. */
+ if (!vm_can_snapshot_devices())
+ return (ENOTSUP);
+
kdata_filename = strcat_extension(checkpoint_file, ".kern");
if (kdata_filename == NULL) {
fprintf(stderr, "Failed to construct kernel data filename.\n");