From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE535494254 for ; Thu, 6 Aug 2026 23:36:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786059404; cv=none; b=DTxdwSaRfJTLYB4KrARXc5fnTp3PmUcig1SypPuupSJqtt2yQjGnjiLaKa36DNvIx5CQwsf/V9Yhk3qcQF1OTR0TR/ZTs0Xu0K3CObzj4iPWKo/Qo/wyV0cEskXle8l4/uUfLvzIqxCxZ3rggOBxT6NKkStcTYF74cgDYrE8Oz0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786059404; c=relaxed/simple; bh=M65IyX8rm7dTt45KlwDHi8ahXU+KWS/raGfMe6r6K7w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=vAd0c+0Zw8JNB1YSUfDgd6UiocM1eii89ReogL9QSP2lcIUMRWLvPsPXiIhTtPL8Aj7MIorGFRSiuE0sL3oUnl2wyF2Per2W3R+6hQNJI5ew6ufqSZNTbA0xlXRVUynLMafKryiRFfuXKHeR/Fw1T2k6AWg3ZVcDs+80zSEndaA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=grN5KYSv; arc=none smtp.client-ip=209.85.210.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="grN5KYSv" Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-84865f326efso3249915b3a.0 for ; Thu, 06 Aug 2026 16:36:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786059401; x=1786664201; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:from:to:cc:subject:date:message-id :reply-to:content-type; bh=xHY7WhZzoR4x+WtFqsSoEfBU4PaM9Rhz3R83jbux6ZU=; b=grN5KYSvTPkU9iZxvDYixscdd/ScZGt50gIQHRPY3J29UlhVnpppkXtrQw0Q43LqKO GPgHPIG3UrN3ok6VU+DmIjC/JXeP3otskUIJh16bcexanzHdXoPasfoGFC6O6n5sMMG5 MVYhQyOkAKe9ZLN0wkRblq+1pFxkUQ05ko+sJra5SBfZ0sk1L5HlzWgtSZJJiHW4YYdI m/y1cwIXLqtDh8vHp9X7X/hU1+r2JPefayDJNzlzs9Ohm9SrYlIv4mrNWgW9koc7iV4m jj6srDpOGKcd7mlOcSz8bbWS2C3y43NmRfNH53TQnPNiB/sJuTlpRiflla4Ty7ej0KZ3 XMsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786059401; x=1786664201; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=xHY7WhZzoR4x+WtFqsSoEfBU4PaM9Rhz3R83jbux6ZU=; b=Vae9tGALIS4K7qjdGG7h6IUJvbR0g2gWGt70+d7lLRThVgkr5lrcie6Bwz6L7X5lOO wc3WEOyMAZMs1OpG4MID+4FZsf3+bzoTcxLlwzi/O76useIQo+C6gAT5g8Or+3PEsDTf D248HY1kSetpZVcaR18M//kC3tkJCqw70MtkuCQXXgSn3FzJmNrutNWdGs+XYRoemDLS Z6PR20QmCengkVp5GND0ow98fymFd+r+N8tAgvj8bYj9PqEiespfw/HhWlJk7dCajhtB J+0V/k2bNVOCAN+NMv6jzKQszoRxkDAtBctZhN1g4tGA6hoVxw9UUNwuWX9N2l3EtIUb CTVA== X-Forwarded-Encrypted: i=1; AHgh+Rq80xXlfYTNiZTUmlSaWauv7P+xn+mT75tcY5Dm5LLzGT4w8s91AMbHs3jpRHJNVMNdTqw=@vger.kernel.org X-Gm-Message-State: AOJu0Yyxyx4iJRxexfUg8RgFKfsuS6dGFiawVDwPXtcUkeuf6I6Q71gl m1cvORwSJHcP+eLp+T4ye+eHPBQE3bFBySF6G+0QYldTVJdc9xKVhjLXkQBD/bdMOcQChPdIj6u YrfizMQ== X-Received: from pfbbu11.prod.google.com ([2002:a05:6a00:410b:b0:848:8b16:23d6]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:2383:b0:842:5b66:3c7f with SMTP id d2e1a72fcca58-84f2dedf356mr20263411b3a.0.1786059400868; Thu, 06 Aug 2026 16:36:40 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 6 Aug 2026 16:35:31 -0700 In-Reply-To: <20260806233609.212337-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260806233609.212337-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.679.g6767b8d81c-goog Message-ID: <20260806233609.212337-15-seanjc@google.com> Subject: [PATCH v6 14/51] x86/tsc: Consolidate forcing of X86_FEATURE_TSC_KNOWN_FREQ for PV code From: Sean Christopherson To: Kiryl Shutsemau , Rick Edgecombe , Sean Christopherson , Paolo Bonzini , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Ajay Kaher , Alexey Makhalov , Jan Kiszka , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Juergen Gross , Daniel Lezcano , Thomas Gleixner , John Stultz Cc: Vitaly Kuznetsov , Broadcom internal kernel review list , Boris Ostrovsky , Stephen Boyd , Miroslav Lichvar , x86@kernel.org, linux-coco@lists.linux.dev, kvm@vger.kernel.org, linux-hyperv@vger.kernel.org, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, Michael Kelley , Tom Lendacky , Nikunj A Dadhania , David Woodhouse , David Woodhouse , Thomas Gleixner Content-Type: text/plain; charset="UTF-8" Now that all paravirt code that explicitly specifies the TSC frequency also sets X86_FEATURE_TSC_KNOWN_FREQ, replace all of the one-off code and simply set X86_FEATURE_TSC_KNOWN_FREQ if the TSC frequency is known. Do NOT force set TSC_KNOWN_FREQ if the "known" TSC frequency was provided by the user. Per commit bd35c77e32e4 ("x86/tsc: Add tsc_early_khz command line parameter"), one of the goals of the param is to allow the refined calibration work "to do meaningful error checking". No functional change intended. Reviewed-by: Michael Kelley Signed-off-by: Sean Christopherson --- arch/x86/coco/sev/core.c | 1 - arch/x86/coco/tdx/tdx.c | 1 - arch/x86/kernel/cpu/acrn.c | 1 - arch/x86/kernel/cpu/mshyperv.c | 1 - arch/x86/kernel/cpu/vmware.c | 2 -- arch/x86/kernel/jailhouse.c | 1 - arch/x86/kernel/kvmclock.c | 1 - arch/x86/kernel/tsc.c | 13 ++++++++++--- arch/x86/xen/time.c | 1 - 9 files changed, 10 insertions(+), 12 deletions(-) diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index bc5ae9ef74da..72313b36b6f5 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -2027,7 +2027,6 @@ unsigned int __init snp_secure_tsc_init(void) secrets = (__force struct snp_secrets_page *)mem; - setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE); rdmsrq(MSR_AMD64_GUEST_TSC_FREQ, tsc_freq_mhz); diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index ec28a15e26ac..21a574e60e0f 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -1203,7 +1203,6 @@ unsigned int __init tdx_tsc_init(void) /* TSC is the only reliable clock in TDX guest */ setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE); - setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); return info.crystal_khz * info.numerator / info.denominator; } diff --git a/arch/x86/kernel/cpu/acrn.c b/arch/x86/kernel/cpu/acrn.c index 3818f6ae0629..dc71a6fdd461 100644 --- a/arch/x86/kernel/cpu/acrn.c +++ b/arch/x86/kernel/cpu/acrn.c @@ -40,7 +40,6 @@ static void __init acrn_init_platform(void) if (acrn_tsc_khz_cpuid) { x86_init.hyper.get_tsc_khz = acrn_get_tsc_khz; x86_init.hyper.get_cpu_khz = acrn_get_tsc_khz; - setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); } } diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 4a0cdda0c49e..3bca987e05c3 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -575,7 +575,6 @@ static void __init ms_hyperv_init_platform(void) ms_hyperv.misc_features & HV_FEATURE_FREQUENCY_MSRS_AVAILABLE) { x86_init.hyper.get_tsc_khz = hv_get_tsc_khz; x86_init.hyper.get_cpu_khz = hv_get_tsc_khz; - setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); } if (ms_hyperv.priv_high & HV_ISOLATION) { diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index 3f1dab69d90e..cbe8b59ab79f 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -390,8 +390,6 @@ static void __init vmware_set_capabilities(void) { setup_force_cpu_cap(X86_FEATURE_CONSTANT_TSC); setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE); - if (vmware_tsc_khz) - setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); if (vmware_hypercall_mode == CPUID_VMWARE_FEATURES_ECX_VMCALL) setup_force_cpu_cap(X86_FEATURE_VMCALL); else if (vmware_hypercall_mode == CPUID_VMWARE_FEATURES_ECX_VMMCALL) diff --git a/arch/x86/kernel/jailhouse.c b/arch/x86/kernel/jailhouse.c index 595cd28f9a9f..8107c28eb2bc 100644 --- a/arch/x86/kernel/jailhouse.c +++ b/arch/x86/kernel/jailhouse.c @@ -255,7 +255,6 @@ static void __init jailhouse_init_platform(void) pr_debug("Jailhouse: PM-Timer IO Port: %#x\n", pmtmr_ioport); precalibrated_tsc_khz = setup_data.v1.tsc_khz; - setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); pci_probe = 0; diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index 4f8299303a19..35a879d33e9e 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -138,7 +138,6 @@ static inline void kvm_sched_clock_init(bool stable) */ static unsigned int __init kvm_get_tsc_khz(void) { - setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); return pvclock_tsc_khz(this_cpu_pvti()); } diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 7f1ca6df0004..f42872c9ae99 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -1541,11 +1541,18 @@ void __init tsc_early_init(void) if (!known_tsc_khz && x86_init.hyper.get_tsc_khz) known_tsc_khz = x86_init.hyper.get_tsc_khz(); + /* + * Mark the TSC frequency as known if it was obtained from a hypervisor + * or trusted firmware. + */ + if (known_tsc_khz) + setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); + /* * Ignore the user-provided TSC frequency if the exact frequency was - * obtained from trusted firmware or the hypervisor, as the user- - * provided frequency is intended as a "starting point", not a known, - * guaranteed frequency. + * obtained from trusted firmware or the hypervisor, and don't mark the + * frequency as known, as the user-provided frequency is intended as a + * "starting point", not a known, guaranteed frequency */ if (!known_tsc_khz) known_tsc_khz = tsc_early_khz; diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c index 1adb44fdddb2..487ad838c441 100644 --- a/arch/x86/xen/time.c +++ b/arch/x86/xen/time.c @@ -43,7 +43,6 @@ static unsigned int __init xen_tsc_khz(void) struct pvclock_vcpu_time_info *info = &HYPERVISOR_shared_info->vcpu_info[0].time; - setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); return pvclock_tsc_khz(info); } -- 2.55.0.679.g6767b8d81c-goog