From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 0D7AE40149A for ; Fri, 29 May 2026 14:45:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780065920; cv=none; b=AmMRLAqY6bBXtrH2zP2cgTfMV8R5V6x+YLUYrFpkj863JSDcSZZQT8qiH8B50BT594C47c9Owu0fwiw7OP/pEonKu/8A8aoJXxVLJWEi4wkD2QifXun9nIVfuqgKakHp1ItHLNTm9cbrXQfT+eCOSMsYXLHWvwGwp03tlJzDt20= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780065920; c=relaxed/simple; bh=dN1xTlAsuZlAzy1KoKelGX7Cs0cog4o00BEDXP2Nha4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jv0ylxxywqFiF5vmFPdFLmp9OSyp2VmK8nrDqFR9dPBnehBXodldVLIRyQlBc6ePkUra5rqxbe7yF37eFmytUU2X8wGlCei2Ok/8I+eyIGVP9RoX5Tw+V5WeQLPNgq0k3/Y1GZUaubceDTlFEETNjMX/kdrUaaZSdg6J/0cHGtk= 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=W75w8Rkb; arc=none smtp.client-ip=209.85.215.202 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="W75w8Rkb" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-c8294d8c48eso9079964a12.0 for ; Fri, 29 May 2026 07:45:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780065917; x=1780670717; 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=YpIj1ucaijezC9S67db1/B7YVcsq/H2nz/z97RNrYsc=; b=W75w8RkbDqqn3B/I3TWYpwFs35i6eAEAc/w2xPPrIiW69cfp+0yYMPlAAziTUJwLp3 v5HGFFCF1HLqOPEzqHRBq6axmd0rF9mkPU9KMKZLTma77BOzR4BzWPU7AX2kgQ9+z85j A+TugnF80XjTXxjCV3Jdnvyq0Qt0XWM/XcK8QyL1en6QbukFP6pMKOIafCZHsAOlNUIu Mxr+uR3BVEdsvf7A7MuF58OEVNUITLUlREN72NTgh2RgJZOE/8LpEYtsVZpDssOsLnBn kDyn5krQwduVjVYhuEl85udZMAEGH6YJmtPu4LZepj2kh98UKMqgyLbBjAJUSPBJS2zC 2Vyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780065917; x=1780670717; 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=YpIj1ucaijezC9S67db1/B7YVcsq/H2nz/z97RNrYsc=; b=i7mBh1iSh3RwgQ14ybN43EI9DTfk9AIt6zThNef46FSh0xSKu4pD/IdkejRrWmQoJv 2ahe9w74c4Hx8/9UhwUA1a0/z3tHvdrA0mBDF3wuhkSz+xShhYp9vmErICRfeFGOX31l j3AF9PonAd1es3KLRT4ZX4dKltP8UB8Vjjfv/rneBECc9at3jNq43xJQeJ8QE3f4EVI4 47SKmWG5uXZiP+T0Lf8n6BuEQvUatRUB8OHcObganx7QwfS9MCmHjJpATxEyEShHDn42 xwnvw7v+tBys7e4wH0Kqh1rRztbZmIgqiKx+wa8GFkRwODXzqw8RUjtVLUkhxvmow+k9 0vBw== X-Forwarded-Encrypted: i=1; AFNElJ9J+E7Mf/PL0yj4WhJoCNA2p1z4hmpJJCuDp4p7Awe06cUuhZwdMEcaPQvLyggX6hQSmKhtcggosquMM6s=@vger.kernel.org X-Gm-Message-State: AOJu0YxiViddMxj61UA/Dhj7ATHKgtJyynaFxm4MEiZpJZ5c/kUv5mLD PUWtv0+wRBpt4fdyem2IngYHgz6EWCdwGfyyMDoyDuXo+f//c24ziK93mui6s24PypnmRRVaqPx qUBxcDQ== X-Received: from pgnm19.prod.google.com ([2002:a63:7d53:0:b0:c79:1600:6a09]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:244f:b0:3a0:67d:bba9 with SMTP id adf61e73a8af0-3b4120a47c0mr3641480637.45.1780065916828; Fri, 29 May 2026 07:45:16 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 29 May 2026 07:44:08 -0700 In-Reply-To: <20260529144435.704127-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: <20260529144435.704127-1-seanjc@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260529144435.704127-22-seanjc@google.com> Subject: [PATCH v4 21/47] x86/xen: Obtain TSC frequency from CPUID if present From: Sean Christopherson To: Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Kiryl Shutsemau , 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: "H. Peter Anvin" , Rick Edgecombe , Vitaly Kuznetsov , Broadcom internal kernel review list , Boris Ostrovsky , Stephen Boyd , 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, David Woodhouse , Tom Lendacky , Nikunj A Dadhania , David Woodhouse , Michael Kelley , Thomas Gleixner Content-Type: text/plain; charset="UTF-8" From: David Woodhouse The Xen CPUID leaf 3, sub-leaf 0, ECX provides the guest TSC frequency in kHz directly. Use it when available instead of reverse-calculating the frequency from the pvclock tsc_to_system_mul and tsc_shift values, which loses precision. This mirrors the equivalent change for KVM guests using the generic 0x40000010 timing leaf. Signed-off-by: David Woodhouse [sean: drop non-Xen changes] Signed-off-by: Sean Christopherson --- arch/x86/xen/time.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c index 487ad838c441..36d66abf5379 100644 --- a/arch/x86/xen/time.c +++ b/arch/x86/xen/time.c @@ -42,6 +42,17 @@ static unsigned int __init xen_tsc_khz(void) { struct pvclock_vcpu_time_info *info = &HYPERVISOR_shared_info->vcpu_info[0].time; + u32 base = xen_cpuid_base(); + u32 eax, ebx, ecx, edx; + + /* + * If Xen provides the guest TSC frequency directly in CPUID + * (leaf 3, sub-leaf 0, ECX), use that instead of reverse- + * calculating from the pvclock mul/shift. + */ + cpuid_count(base + 3, 0, &eax, &ebx, &ecx, &edx); + if (ecx) + return ecx; return pvclock_tsc_khz(info); } -- 2.54.0.823.g6e5bcc1fc9-goog