On 7/2/2026 1:02 AM, Sean Christopherson wrote: > Silently ignore attempts to switch to a paravirt sched_clock when running > as a CoCo guest with trusted TSC. In hand-wavy theory, a misbehaving > hypervisor could attack the guest by manipulating the PV clock to affect > guest scheduling in some weird and/or predictable way. More importantly, > reading TSC on such platforms is faster than any PV clock, and sched_clock > is all about speed. > > Reviewed-by: David Woodhouse <[email protected]> > Signed-off-by: Sean Christopherson <[email protected]> Reviewed-by: Nikunj A Dadhania <[email protected]> > --- > arch/x86/kernel/tsc.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c > index 012321fed5e5..a146fc7b5e74 100644 > --- a/arch/x86/kernel/tsc.c > +++ b/arch/x86/kernel/tsc.c > @@ -283,6 +283,15 @@ bool using_native_sched_clock(void) > int __init __paravirt_set_sched_clock(u64 (*func)(void), bool stable, > void (*save)(void), void (*restore)(void)) > { > + /* > + * Don't replace TSC with a PV clock when running as a CoCo guest and > + * the TSC is secure/trusted; PV clocks are emulated by the hypervisor, > + * which isn't in the guest's TCB. > + */ > + if (cc_platform_has(CC_ATTR_GUEST_SNP_SECURE_TSC) || > + boot_cpu_has(X86_FEATURE_TDX_GUEST)) > + return -EPERM; > + > if (!stable) > clear_sched_clock_stable(); >
- [PATCH v5 19/51] x86/kvmclock: Drop dead check on TSC ... Sean Christopherson
- [PATCH v5 45/51] x86/paravirt: Mark __paravirt_set_sch... Sean Christopherson
- [PATCH v5 44/51] x86/kvmclock: WARN if wall clock is r... Sean Christopherson
- [PATCH v5 20/51] KVM: x86: Officially define CPUID 0x4... Sean Christopherson
- [PATCH v5 46/51] x86/paravirt: Plumb a return code int... Sean Christopherson
- [PATCH v5 21/51] x86/kvm: Obtain TSC frequency from PV... Sean Christopherson
- [PATCH v5 23/51] x86/tsc: Add standalone helper for ge... Sean Christopherson
- [PATCH v5 48/51] x86/kvmclock: Use TSC for sched_clock... Sean Christopherson
- [PATCH v5 47/51] x86/paravirt: Don't use a PV sched_cl... Sean Christopherson
- RE: [PATCH v5 47/51] x86/paravirt: Don't use a PV... Michael Kelley
- Re: [PATCH v5 47/51] x86/paravirt: Don't use a PV... Nikunj A. Dadhania
- [PATCH v5 22/51] x86/kvm: Mark TSC as reliable when it... Sean Christopherson
- [PATCH v5 24/51] x86/kvm: Get CPU base frequency from ... Sean Christopherson
- [PATCH v5 51/51] x86/kvm: Get local APIC bus frequency... Sean Christopherson
- [PATCH v5 18/51] x86/kvmclock: Rename kvm_get_tsc_khz(... Sean Christopherson
- [PATCH v5 25/51] clocksource: hyper-v: Register sched_... Sean Christopherson
- [PATCH v5 26/51] clocksource: hyper-v: Drop wrappers t... Sean Christopherson
- [PATCH v5 27/51] clocksource: hyper-v: Don't save/rest... Sean Christopherson
- [PATCH v5 28/51] x86/kvmclock: Setup kvmclock for seco... Sean Christopherson
- [PATCH v5 30/51] x86/paravirt: Remove unnecessary PARA... Sean Christopherson
- [PATCH v5 32/51] x86/kvmclock: Move sched_clock save/r... Sean Christopherson

