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 EC71348F85C for ; Thu, 6 Aug 2026 23:36:29 +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=1786059398; cv=none; b=TFyMqDWWxmXaBxGIufxDAnzZeGl/6UAxDY5FvDLM1UFjNcWNeG6xm6i9hs9NnEzeuEEBeJxawylQaiYaSY7Lwlbmv0gNDHRwfCRpJ86hOhiAvDUrVk/OeoG325o5WHW/tpBFD2vF47fd0fBpskKK6T7UjJoqqFLSjnt1NRHkpcM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786059398; c=relaxed/simple; bh=COVjz/VMaG10y/OAye851r7NpDmo+A5RSCjUP4fF4Ws=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=g+QiUztKPihnH7xUNtDHO+iBsRwl2cP0eGFNYkxGrt5XoCmSHikQR3Jj8gJ/6OD+BoShGQfQ2dhWg2WhgNTAQFMXhz3qFUhae7RubCcgI55xVA3xyC7wWVucxRKs8SrzrimYfC2K+Rd8pZcCyG871dmlXCLYAXNpgwK8Tc/UsaA= 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=P3fNxSAi; 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="P3fNxSAi" Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-84e375d9736so3450218b3a.2 for ; Thu, 06 Aug 2026 16:36:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786059388; x=1786664188; 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=2SJsprQma6tQ2oU494vKbTkDMI4EE2yRA8rYyHQJqoI=; b=P3fNxSAibCyd19JnptANRMPoMG327SoT4wFXlL6k4KhFXSHaOlnuZc1/ZezqB70sGB G3VbOYpifvcNSPEPzXnoyxNowwlSxdVf9N+phY4csKA0gSJHSxcSbrlU+Ca4ViFm/7Gv ubyRcVx3TzJOIThuwzCjLa3lVqGSXV061rx/RdPap26jl9J5jOB+rX9DV+5NtIj972iy WOeVZFnrXmV4w3bKwb6f34GK4yX/MfQgnwn95s5jCnbU0QpuMaX1TMRIDGXhg8gsInyv yv94pB+Fl+rV+IY/pJqHSPeHE33QvEaQFbCmo8ZcvqGdyRXhFLfSGs8A/NJi7eWqlspZ ARWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786059388; x=1786664188; 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=2SJsprQma6tQ2oU494vKbTkDMI4EE2yRA8rYyHQJqoI=; b=pUmRyLtR+L1ARX8FZXgkBSG22J0Uitq9sQRG5g+c9BdjBrd8U0hyaiGCwbUxnkFnW9 /GUvTb/1Kk22F2dE+ksvqoZm+4VOp6cB6W7hQiEBqpMQfQ5R+lU7Znun3tV7hgA1KPIH 2GL9xFvK/ibdK5nNBJPDqSXmV5jbSBh1DedWzWLHr7Axo6QTdEeLlSgyhkbEeXXKPmYc Ck09gm2UsmP19j9Rz71h44+RGvp7pgPeaMaW/SVIKhQI+oQ7rXE6DfUXg0jIdLgx4RtQ bpjygJc+yU+ipyxS/bYeps36E70fqGWAq4ue7Q1YcL9H8xIbGS3dc/2P84jACcJ4WLKg LeNw== X-Forwarded-Encrypted: i=1; AHgh+RqtmxBRiJQGpR3SVFfmZaDKOCG3lFVjHolIGWnI3tNCi10cQ9KvdEavZtoVt7mPwyLfwTcLB02RNAUgbfY=@vger.kernel.org X-Gm-Message-State: AOJu0YxtJrBmqObGRpU+BB7FUAGn5yp+TTkbbNVY0kxZLYezoaLak4xi 8Wohj2ZDiuhKlSkBeF4PPnYjNBPM1GEdje6aQxJomUlURMoLMx7Jeo3wuNHgVp8/EgszmzjlQ1F TcZAR0g== X-Received: from pglr15.prod.google.com ([2002:a63:514f:0:b0:c9a:7d72:c316]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:2d0c:b0:84e:2382:f4f0 with SMTP id d2e1a72fcca58-84f2dfc8ed4mr19812672b3a.4.1786059387185; Thu, 06 Aug 2026 16:36:27 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 6 Aug 2026 16:35:20 -0700 In-Reply-To: <20260806233609.212337-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@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-4-seanjc@google.com> Subject: [PATCH v6 03/51] x86/tsc: Ensure that TSC recalibration doesn't run if TSC frequency is known 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" 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 4392fddd616e..bc4348585194 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.679.g6767b8d81c-goog