git: e52aaa644ce1 - stable/13 - bhyve: Handle snapshots of unconfigured virtio-net devices

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Sun, 06 Nov 2022 15:18:30 UTC
The branch stable/13 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=e52aaa644ce186b6f0f38302ad432ddbdf38620a

commit e52aaa644ce186b6f0f38302ad432ddbdf38620a
Author:     Vitaliy Gusev <gusev.vitaliy@gmail.com>
AuthorDate: 2022-10-23 18:47:56 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-11-06 15:18:05 +0000

    bhyve: Handle snapshots of unconfigured virtio-net devices
    
    In case of device reset or not configured - features_negotiated is not
    set, calling calling pci_vtnet_neg_features is wrong and resume gets
    "Segmentation fault".
    
    Reviewed by:    markj
    Sponsored by:   vStack
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D36244
    
    (cherry picked from commit 3b5e5ce87bc885f35100d77b31ac81d3f98342bf)
---
 usr.sbin/bhyve/pci_virtio_net.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/usr.sbin/bhyve/pci_virtio_net.c b/usr.sbin/bhyve/pci_virtio_net.c
index 5c3f885fc5ae..3714b34c5066 100644
--- a/usr.sbin/bhyve/pci_virtio_net.c
+++ b/usr.sbin/bhyve/pci_virtio_net.c
@@ -786,9 +786,11 @@ pci_vtnet_snapshot(void *vsc, struct vm_snapshot_meta *meta)
 	 */
 
 	SNAPSHOT_VAR_OR_LEAVE(sc->vsc_features, meta, ret, done);
+	SNAPSHOT_VAR_OR_LEAVE(sc->features_negotiated, meta, ret, done);
 
 	/* Force reapply negociated features at restore time */
-	if (meta->op == VM_SNAPSHOT_RESTORE) {
+	if (meta->op == VM_SNAPSHOT_RESTORE &&
+	    sc->features_negotiated) {
 		pci_vtnet_neg_features(sc, sc->vsc_features);
 		netbe_rx_enable(sc->vsc_be);
 	}