git: b1ced97e75a0 - stable/13 - vmm: vlapic resume can eat 100% CPU by vlapic_callout_handler

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 25 Jan 2022 14:55:26 UTC
The branch stable/13 has been updated by markj:

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

commit b1ced97e75a0ec004119088842ce017ff4dd5393
Author:     Vitaliy Gusev <gusev.vitaliy@gmail.com>
AuthorDate: 2022-01-11 14:24:41 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-01-25 14:55:09 +0000

    vmm: vlapic resume can eat 100% CPU by vlapic_callout_handler
    
    Suspend/Resume of Win10 leads that CPU0 is busy on handling interrupts.
    
    Win10 does not use LAPIC timer to often and in most cases, and I see it
    is disabled by writing 0 to Initial Count Register (for Timer).
    
    During resume, restart timer only for enabled LAPIC and enabled timer
    for that LAPIC.
    
    Reviewed by:    markj
    
    (cherry picked from commit c72e914cf108d3904eb5070b0999b3b5b6a4f384)
---
 sys/amd64/vmm/io/vlapic.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/sys/amd64/vmm/io/vlapic.c b/sys/amd64/vmm/io/vlapic.c
index 940e45cce458..c0ca167ef11f 100644
--- a/sys/amd64/vmm/io/vlapic.c
+++ b/sys/amd64/vmm/io/vlapic.c
@@ -1740,10 +1740,13 @@ vlapic_snapshot(struct vm *vm, struct vm_snapshot_meta *meta)
 
 		SNAPSHOT_VAR_OR_LEAVE(ccr, meta, ret, done);
 
-		if (meta->op == VM_SNAPSHOT_RESTORE) {
+		if (meta->op == VM_SNAPSHOT_RESTORE &&
+		    vlapic_enabled(vlapic) && lapic->icr_timer != 0) {
 			/* Reset the value of the 'timer_fire_bt' and the vlapic
 			 * callout based on the value of the current count
-			 * register saved when the VM snapshot was created
+			 * register saved when the VM snapshot was created.
+			 * If initial count register is 0, timer is not used.
+			 * Look at "10.5.4 APIC Timer" in Software Developer Manual.
 			 */
 			vlapic_reset_callout(vlapic, ccr);
 		}