From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 69DCD37999D for ; Wed, 20 May 2026 21:02:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779310949; cv=none; b=RA0nPiN4pEfT11VtMTvWhsYzfliWYWJKFiSppsuVYkKmkRAGRRQGKwKf4lMU8TYXGmBjsVKQOZt+8tIDbFm+1sQ8bXYBV3+IkS6RXIPPQCPguiZAJJfebPfyKWIzsjPm/vem1A7u/XRmde8GJMOdrULIYBw8rgC+VcX99atc6Y8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779310949; c=relaxed/simple; bh=/SyQLtBraYhS5/8VMnaEdQSNY3tBbZxFagWmgPcJqrU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=vEncfllw55kybBrYltRcVJsPZ42pAFHOfNG4xFzsvlaSgwe7G62MnZQTv7bpyCCVTLRzDIF1SfiZ7swo4luxynxqbR+VogNiYWLSO7Mya3FY8822rBVwJw+AXXwX1dXRvYPZiYOVY2IyrFUxFVNw0pAlRq7lI6IVZL0Q5Jcer3A= 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=CflIEcPo; arc=none smtp.client-ip=209.85.216.74 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="CflIEcPo" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3692f395339so5250195a91.1 for ; Wed, 20 May 2026 14:02:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779310947; x=1779915747; darn=lists.linux.dev; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=IMxqN6rGG5Sakxt9VTCj2ZelG+Z0Re7U8JKIeB5aot8=; b=CflIEcPoNYZthWQXxa8UkgedgV8V9qi3pFvC06Szx70uPOoU38ySo6Fpy1nhxCpfIO 7DXZC0ypcLaT+6ejPLdVGTekT0nepaW5dKgzDH9fTVxfdDyAjPH0GsRA23gicKSNy0sc bDavOMkDMZyxzpSKidLZZnoYtSsj1WIC38cyEjxSq7BWdqO46/2y/CNECzwtFWlrJ2ux io/Zk9IPIGv42a0XHOcXBoIHvkoP+xrEOkJ7A5Nge9i1DDRUu/JKsZu77KceTTgFhdfE vWt5XCNU5aOzEZglS+I2JfDlWqsr+JRi5+Gh4jpL8JypkW6Gn+VhfIohaHmslW/oFrrl zmaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779310947; x=1779915747; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=IMxqN6rGG5Sakxt9VTCj2ZelG+Z0Re7U8JKIeB5aot8=; b=T7opp3NebWGToGET9mQyttm1W5oQVvis/My8LIHZMK5KRxS31kUxDfAMfrUU++tDQQ TiVLI+AB/kE01V0BC0oWhBLk1yNIIkbIXKjxVGMBgfgKRfum75Lja2CAt2RItf5KO/oR pH6pkpVaE6VSrlx/bLrsSQPgH4JHBeZGY3ya88DlR98ICAdWV3xKAcc14F+hsdb45hP1 sg3i39BbYnugookUnxgGtdpdbBt140Y075sX590lHagv9C50XIf4/EfzpklkIOtgX0yu BVjEQzUi2aye+d349iHUdQRozqfqnv83Y1vXGpo0ccr8Wxt1AaS3cDhmjKWs3Uhxqu5h TuzA== X-Forwarded-Encrypted: i=1; AFNElJ9CzY9Y6Zi7QcTgW6lWmkev6VqdmQeEldOUU1y7HwsCe2pXODXipo1kVLRf4+g7VL1041+xBcEcBptxMCPb1w==@lists.linux.dev X-Gm-Message-State: AOJu0Yzf/A9lRWkWvXFdTLWDBwXR0p0TjhoPHeY0JVEJeFRh0SFviw6A 3iuMp+tbRs2sTq77/lPqqaOFDVKK9xPIWSexQLlkgmB3UBzQu4WahFV3b2KvTY1aj703kImh4hu U9VjYGw== X-Received: from pgnp19.prod.google.com ([2002:a63:7f53:0:b0:c82:7805:9e4d]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6300:279a:10b0:39b:dea7:5626 with SMTP id adf61e73a8af0-3b308856ca4mr1798637.35.1779310947183; Wed, 20 May 2026 14:02:27 -0700 (PDT) Date: Wed, 20 May 2026 14:02:26 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260515191942.1892718-1-seanjc@google.com> <20260515191942.1892718-7-seanjc@google.com> Message-ID: Subject: Re: [PATCH v3 06/41] x86/acrn: Mark TSC frequency as known when using ACRN for calibration From: Sean Christopherson To: David Woodhouse Cc: Kiryl Shutsemau , 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 , Rick Edgecombe , Vitaly Kuznetsov , Broadcom internal kernel review list , Boris Ostrovsky , Stephen Boyd , 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 , Thomas Gleixner Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Wed, May 20, 2026, David Woodhouse wrote: > On Fri, 2026-05-15 at 12:19 -0700, Sean Christopherson wrote: > > Mark the TSC frequency as known when using ACRN's PV CPUID information. > > Per commit 81a71f51b89e ("x86/acrn: Set up timekeeping") and common sen= se, > > the TSC freq is explicitly provided by the hypervisor. > >=20 > > Signed-off-by: Sean Christopherson > > --- > > =C2=A0arch/x86/kernel/cpu/acrn.c | 1 + > > =C2=A01 file changed, 1 insertion(+) > >=20 > > diff --git a/arch/x86/kernel/cpu/acrn.c b/arch/x86/kernel/cpu/acrn.c > > index c1506cb87d8c..2da3de4d470e 100644 > > --- a/arch/x86/kernel/cpu/acrn.c > > +++ b/arch/x86/kernel/cpu/acrn.c > > @@ -29,6 +29,7 @@ static void __init acrn_init_platform(void) > > =C2=A0 /* Install system interrupt handler for ACRN hypervisor callback= */ > > =C2=A0 sysvec_install(HYPERVISOR_CALLBACK_VECTOR, sysvec_acrn_hv_callba= ck); > > =C2=A0 > > + setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ); > > =C2=A0 tsc_register_calibration_routines(acrn_get_tsc_khz, > > =C2=A0 =C2=A0 acrn_get_tsc_khz); >=20 > I'd feel slightly happier doing that from within acrn_get_tsc_khz() > itself.... Ya, though as you note below, this is really a comment on the overall serie= s. Waiting to set the cap until the calibration routine is actually run does p= revent the case where the something registers a calibration routine, but its routi= ne is never run. However, because the cap is sticky, it doesn't handle the scenario where it= s routine _does_ run, but the kernel ultimately throws away its calibration i= n favor of something else. Further complicating things is that ~half of the paravirt flows already for= ce set caps before their routines are invoked: snp_secure_tsc_init(), jailhouse_init_platform(), ms_hyperv_init_platform= (), vmware_set_capabilities() Rather than trying to convince everyone that waiting is better, despite tha= t approach still being flawed, I chose to handle this by ensuring that once t= he TSC is marked known and/or reliable, the kernel won't replace the calibration r= outine with a "lesser" source: x86/tsc: Rejects attempts to override TSC calibration with lesser routine That doesn't completely prevent the kernel from being stupid, but it should= prevent both the case where X's routine is registered but never run, as well as the= case where it's run but ultimately ignored. > which I note is 'static inline'. I'm vaguely surprised that even builds > (although it does). Heh, KVM x86 (in the host) does stupid things like this too. E.g. kvm_pdpt= r_read() is a static inline, but then wired up as a function pointer in three differ= ent places. > Probably nicer to move it explicitly out of line in acrn.c though. >=20 > Most of that should be a comment on patch 2 of the series, I guess?