From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 9715048B38F for ; Wed, 1 Jul 2026 19:32:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782934351; cv=none; b=aZZ9JVfccnuAdUhphhG70fd8K0m2cx8/+OJdRKNW3bwrU4mN1zGFmdWnZD+/DdNk272XVGJbLdPmnUMfLEKGmbe3PY87db2c0yDkvaHaPKt6q/dCXrqUKei0BVHczzFDxhxv4IEDc9S5BLuV39F0/6SoHxjPtK0Xsj3QXwI7ZCU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782934351; c=relaxed/simple; bh=v2Q0HNtSCGTgYUOIUvvhGqkYnBE/yC1sKZgtPaijFJM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pMr2OgJYVlldtxhN48rmcjY5mzzB63ZvGAY4vB7KA8AAKJbN1Ykz6YbibYtw5BYPjdLzMrVWrVx54fkrB08mz4nd7wf0n4ShzPU7dZqbUnWfp76SUp32ip+iZXRduKu375FGpYF0QgwrKnoVkx54yTviVoQQpU3D09/WDEAhPcg= 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=PsEQMyTr; arc=none smtp.client-ip=209.85.215.201 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="PsEQMyTr" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-c890bac374eso1130208a12.1 for ; Wed, 01 Jul 2026 12:32:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782934349; x=1783539149; darn=lists.linux.dev; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=LIZd+3O3352vjgCRNr7RtXOU8moEkEwJFa5rPF13Bys=; b=PsEQMyTrAoEHkWsvkioBoJhzwMTvtZYDbk1WAGoZs5AJmkj7FsTI0G5L8BrovCGGYe U1R6SgHN2dp/J2TgR7/Ki9lCakA1Wh4UWAgKulqaqHnPgqhrOpZm8k94ubtd5Xc5YkHS y/6OIsuQiIR1UZb/Ist9O9kt5gbGACBMegZLnGMgspM2nD/2Q/PJpIO9Lb0x5mwqsO5b doftvFqZJGmazgtFUb6J5mt1WttmG31sGBh2TdPCnk8cAJZjpXQmYK1n0dLqq5bASauc YDMgqY7gZ5AoyQ6Brm2PVB4sHBMXpVi/VJOv1lHXzAopH/gJJ+WkznYKEz8MB8gFumzw I17A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782934349; x=1783539149; h=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; bh=LIZd+3O3352vjgCRNr7RtXOU8moEkEwJFa5rPF13Bys=; b=PZ6IX17G2/3ukVLI8znCmTYkm7qg54DyDhp7vQAFE/gogOUFjOsPohB+9IRNjtfEeb hYZ2gPA1o776dFpaAQ2h9eft5C9m8uPBCjMvK0bdPW73IvahP0/uf10dd9rAojLcqBnn 2ozAH5YArur0eCJFRXy5yl9CYoNgoKz1fq+IqkKA+IIOgicK4uLL6pXE5u+5zbDn05qY IYOBaWkqd/M/5CquI82Xmo2a26q5L6ciZmJOZ8NyS8lnV+RMdPOdQ7a8tdd18AySmLTs 8m5gXMAgXh34YY5YMe+7CLJ8fpD89WrIzdfJbXDG+ic6D1p2u6pkQEhUXY4I6hlDYRB8 Luzw== X-Forwarded-Encrypted: i=1; AFNElJ/oit+z8W1+a7hiuq1wf8IcNPDuq4F8hiadMeAE65VSIvOw9kubK3Uau2PyFcMqVaM+A9mUOBWR9xKU@lists.linux.dev X-Gm-Message-State: AOJu0YywWOFOUiixten65eJ7Hr/v9EG2rukG59/TwV2piEri5uNB4uYp K/yvq5MGk7jJzAyl95G9yTWSB/vJ+F5yy4LL5ljJEyOzAhg2N2e1XfjfOxtgqwcVfv4w6caJwXl 9h23HmQ== X-Received: from pgbcx9.prod.google.com ([2002:a05:6a02:2209:b0:c9a:eb48:4a8]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:e196:b0:3bf:8604:9a3c with SMTP id adf61e73a8af0-3bfed3e9622mr3622600637.28.1782934348718; Wed, 01 Jul 2026 12:32:28 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 1 Jul 2026 12:31:24 -0700 In-Reply-To: <20260701193212.749551-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260701193212.749551-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260701193212.749551-4-seanjc@google.com> Subject: [PATCH v5 03/51] x86/tsc: Ensure that TSC recalibration doesn't run if TSC frequency is known From: Sean Christopherson To: Jonathan Corbet , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Kiryl Shutsemau , Rick Edgecombe , Sean Christopherson , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Ajay Kaher , Alexey Makhalov , Jan Kiszka , Andy Lutomirski , Peter Zijlstra , Juergen Gross , Daniel Lezcano , John Stultz Cc: Shuah Khan , "H. Peter Anvin" , Vitaly Kuznetsov , Broadcom internal kernel review list , Boris Ostrovsky , Stephen Boyd , linux-doc@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, linux-hyperv@vger.kernel.org, virtualization@lists.linux.dev, xen-devel@lists.xenproject.org, Tom Lendacky , Nikunj A Dadhania , David Woodhouse , David Woodhouse , Michael Kelley , Thomas Gleixner Content-Type: text/plain; charset="UTF-8" When attempting TSC recalibration post-boot, which is only done for ancient CPUS (P4 and K7) on SMP=n kernels, assert that the TSC frequency isn't known (explicitly provided by hardware) by way of MSR or CPUID, and bail if the impossible happens. In practice, recalibration and TSC_KNOWN_FREQ are mutually exclusive, as TSC_KNOWN_FREQ will only be set when running on hardware that was released decades after recalibration was obsoleted, but but it's hard to see that, especially when looking at just the TSC code. Note, the WARN can likely be tripped by running in a virtual machine and concocting an impossible CPU model, e.g. by combining a P4 signature with CPUID 0x15. This is working as intended, as such a virtual CPU model is wildly out-of-spec and is not supported. Signed-off-by: Sean Christopherson --- arch/x86/kernel/tsc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 4d6a446645c0..4393902c0ddd 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -930,6 +930,9 @@ void recalibrate_cpu_khz(void) if (!boot_cpu_has(X86_FEATURE_TSC)) return; + if (WARN_ON_ONCE(cpu_feature_enabled(X86_FEATURE_TSC_KNOWN_FREQ))) + return; + cpu_khz = x86_platform.calibrate_cpu(); tsc_khz = x86_platform.calibrate_tsc(); if (tsc_khz == 0) -- 2.55.0.rc0.799.gd6f94ed593-goog