From ff49ea854a154808046d031bca6f473069d3e760 Mon Sep 17 00:00:00 2001
From: Felicitas Pojtinger <felicitas@pojtinger.com>
Date: Tue, 3 Dec 2024 21:51:24 -0800
Subject: [PATCH] refactor: Disable TSC scaling for PVM

Signed-off-by: Felicitas Pojtinger <felicitas@pojtinger.com>
---
 src/vmm/src/vstate/vcpu/x86_64.rs | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/vmm/src/vstate/vcpu/x86_64.rs b/src/vmm/src/vstate/vcpu/x86_64.rs
index a1bb22d1bb7..bb581d1ca83 100644
--- a/src/vmm/src/vstate/vcpu/x86_64.rs
+++ b/src/vmm/src/vstate/vcpu/x86_64.rs
@@ -561,8 +561,12 @@ impl KvmVcpu {
     }
 
     /// Scale the TSC frequency of this vCPU to the one provided as a parameter.
-    pub fn set_tsc_khz(&self, tsc_freq: u32) -> Result<(), SetTscError> {
-        self.fd.set_tsc_khz(tsc_freq).map_err(SetTscError)
+    pub fn set_tsc_khz(&self, _: u32) -> Result<(), SetTscError> {
+        // Disable TSC scaling when using PVM because it is unsupported on most virtualized platforms.
+        // Even on supported platforms like virtualized AMD CPUs, enabling TSC scaling can cause VM freezes
+        // after resuming from a snapshot.
+        // For more details, see https://github.com/virt-pvm/linux/issues/12#issue-2515360332
+        Ok(())
     }
 
     /// Use provided state to populate KVM internal state.