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 9418242B72B 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=EnE6y5z//b/EP7anY94PGSEQk2uMnG3XGNpzqpCANoD1ay/LAqO2JlSbWqMHXPjOKTvpkj7cds6HuTfTuUEM7CJrIMnmLldjvH+DYxUH4whxWgUJX3tqzHPuFNC9dYb1KVc0Q7pfxUDINtnbEEXgDPumSqZ2fsyhOqMPrOCVb/0= 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=SVd0d2cM; 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="SVd0d2cM" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-c916d17dd43so1229732a12.3 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=vger.kernel.org; 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=SVd0d2cM4rLZgZk5dMhN/UZG3zFd/v+V9aBfOlPqnhRkqSpgt4Ml37BWxgsZWBkWVB R8EVUS+UkD6WXvHH7wtl/rMzdzFmnABYCvqbqBdavedissYZrQRMAsDIBcvOt3NIsRxu 2+a2Rv+l0Hl8GFkmp7BgQmaQQ737D0ebAT012ZJAOkqd1Dq3rK7Vj0whmL6qSC3COGSV q2/pFXk1azcoCSNzftl5UljHBbHnxc8ivwzJdkgLFojm7qz6pFmPx7fFIFEu6lwF63Z8 ym68y3ZRMGna6nrtP8RE7bad4T2wbxq8rICP9Wp+KzS2l2UH2zq3hem89jbgDJ6byyBv Rozg== 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=pVEnDGqIHA1XSRfS2RYkuO+q9RmNzjuo73NPhV+Y279J5+07HsAn6iOMVPqsGOGXgH vAs2BLGd96Iwpq4i2lXqtC7TpCGj2OWEllnq5MFCxILjfUCfedKFtJSjcCaiSWD5KRHr H8T4GBgMqLqkTCNCXEaK4Hp3Vb7Cm0Rlveo7pGExOqbgvW+C3rfRaJKiqEVv6j0o6tn5 zL5YH3B2S9JF6i4L/0mYeWrLqEGHU8AQZg0cjrpPBHlwNH/uts1ptst0+V6wAs73rckn HlFOdOUd07AjtuQpoAAKm2SwnREnCWLL4gAHnB+sOMQ2x+oAcRWESIESuO90uPbMC8gm S49Q== X-Forwarded-Encrypted: i=1; AFNElJ/W4o7580mKJejFnm9Z+3n03tMp6HvtISJJNwcQxOouIXIhd8Lvg8/9PUGtYAJIZjWBnE5+aMHimjhrCus=@vger.kernel.org X-Gm-Message-State: AOJu0YzPf/F9gQNqyEKb++6Rdf89PEI5+yr3S6+OKmSE+IxffdNQ31UD 7QPUfoj9dXOHO/uYBauvAxjpzdlGl7P3oOH4sUcrdh3Y2SBALmyoOumG2rqb4N1BGBQGYmn3C56 9D9aYbA== 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-kernel@vger.kernel.org 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