git: 683ea4d22bbc - main - vmm: MTRR should be saved/restored

From: Robert Wing <rew_at_FreeBSD.org>
Date: Fri, 29 Dec 2023 18:14:44 UTC
The branch main has been updated by rew:

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

commit 683ea4d22bbcc892ac7c5bb996d1b134831dfdc3
Author:     Vitaliy Gusev <gusev.vitaliy@gmail.com>
AuthorDate: 2023-12-29 18:03:20 +0000
Commit:     Robert Wing <rew@FreeBSD.org>
CommitDate: 2023-12-29 18:03:20 +0000

    vmm: MTRR should be saved/restored
    
    This fixes restoring a Linux VM if it was suspended while in the GRUB
    menu.
    
    Adding MTTR increases the kernel dump size by 256 bytes per vCPU.
    
    Sponsored by:   vStack
    Reviewed by:    markj, rew
    Differential Revision:  https://reviews.freebsd.org/D43226
---
 sys/amd64/vmm/amd/svm.c   | 2 ++
 sys/amd64/vmm/intel/vmx.c | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/sys/amd64/vmm/amd/svm.c b/sys/amd64/vmm/amd/svm.c
index 3fda9454090b..f1106158e44e 100644
--- a/sys/amd64/vmm/amd/svm.c
+++ b/sys/amd64/vmm/amd/svm.c
@@ -2781,6 +2781,8 @@ svm_vcpu_snapshot(void *vcpui, struct vm_snapshot_meta *meta)
 	SNAPSHOT_VAR_OR_LEAVE(vcpu->asid.gen, meta, err, done);
 	SNAPSHOT_VAR_OR_LEAVE(vcpu->asid.num, meta, err, done);
 
+	SNAPSHOT_BUF_OR_LEAVE(&vcpu->mtrr, sizeof(vcpu->mtrr), meta, err, done);
+
 	/* Set all caches dirty */
 	if (meta->op == VM_SNAPSHOT_RESTORE)
 		svm_set_dirty(vcpu, 0xffffffff);
diff --git a/sys/amd64/vmm/intel/vmx.c b/sys/amd64/vmm/intel/vmx.c
index 317ed7e5d7fb..b7c1544ac0b3 100644
--- a/sys/amd64/vmm/intel/vmx.c
+++ b/sys/amd64/vmm/intel/vmx.c
@@ -4200,6 +4200,9 @@ vmx_vcpu_snapshot(void *vcpui, struct vm_snapshot_meta *meta)
 	SNAPSHOT_BUF_OR_LEAVE(vcpu->pir_desc,
 	    sizeof(*vcpu->pir_desc), meta, err, done);
 
+	SNAPSHOT_BUF_OR_LEAVE(&vcpu->mtrr,
+	    sizeof(vcpu->mtrr), meta, err, done);
+
 	vmxctx = &vcpu->ctx;
 	SNAPSHOT_VAR_OR_LEAVE(vmxctx->guest_rdi, meta, err, done);
 	SNAPSHOT_VAR_OR_LEAVE(vmxctx->guest_rsi, meta, err, done);