]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
x86/sev: Use TSC_FACTOR for Secure TSC frequency calculation
authorNikunj A Dadhania <nikunj@amd.com>
Mon, 30 Jun 2025 08:18:58 +0000 (13:48 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Jul 2025 16:44:04 +0000 (18:44 +0200)
commitd0195c42e65805938c9eb507657e7cdf8e1e9522
treee1b14ee5fd09b826cee6e1e637b2202f32fee167
parent88dc708f8c4aaf303051c90ac518db41cd5ce7d2
x86/sev: Use TSC_FACTOR for Secure TSC frequency calculation

commit 52e1a03e6cf61ae165f59f41c44394a653a0a788 upstream.

When using Secure TSC, the GUEST_TSC_FREQ MSR reports a frequency based on
the nominal P0 frequency, which deviates slightly (typically ~0.2%) from
the actual mean TSC frequency due to clocking parameters.

Over extended VM uptime, this discrepancy accumulates, causing clock skew
between the hypervisor and a SEV-SNP VM, leading to early timer interrupts as
perceived by the guest.

The guest kernel relies on the reported nominal frequency for TSC-based
timekeeping, while the actual frequency set during SNP_LAUNCH_START may
differ. This mismatch results in inaccurate time calculations, causing the
guest to perceive hrtimers as firing earlier than expected.

Utilize the TSC_FACTOR from the SEV firmware's secrets page (see "Secrets
Page Format" in the SNP Firmware ABI Specification) to calculate the mean
TSC frequency, ensuring accurate timekeeping and mitigating clock skew in
SEV-SNP VMs.

Use early_ioremap_encrypted() to map the secrets page as
ioremap_encrypted() uses kmalloc() which is not available during early TSC
initialization and causes a panic.

  [ bp: Drop the silly dummy var:
    https://lore.kernel.org/r/20250630192726.GBaGLlHl84xIopx4Pt@fat_crate.local ]

Fixes: 73bbf3b0fbba ("x86/tsc: Init the TSC for Secure TSC guests")
Signed-off-by: Nikunj A Dadhania <nikunj@amd.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/20250630081858.485187-1-nikunj@amd.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/coco/sev/core.c
arch/x86/include/asm/sev.h