From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (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 7CCDA4A09F4 for ; Thu, 6 Aug 2026 23:36:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.72 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786059413; cv=none; b=F3y5/faHJJZuwwfMhA+Ir3aRlz2/Ud7g0h5SgBXzNUJ+FqU9jvXSwU2vgNBLTf8HwHiZmeNx3LHCM2zNzhK1VG1XIZ3PSEwOp8/3NADB4WgICMaToDaLJwyOInVGFtP4jHUnOtF7YMgaia3dtDZSnms7hmd2rFn4Sg25QKKZAuc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786059413; c=relaxed/simple; bh=YuCMxhXTIsqx6zpcODEUb6qXKu+EziAmx+3M3LR9+3o=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UVAYHVBXRvKHxF075Bd1PPAa9hDJCPD2+3km71kd/Lps1lG+637RNXHZ2GA1QLIisY7awDsnIAV+qj2tqOs18rBIJNDGJQeo7EF2diEXpLuA5t3SwhOghwqJ1hYGnCnx50o6bkXz6fUYxIz8Z+f09mY3Sbyms4EVEkhmjmmdIy0= 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=ffcw/IHb; arc=none smtp.client-ip=209.85.216.72 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="ffcw/IHb" Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-38e4758ab46so3232417a91.0 for ; Thu, 06 Aug 2026 16:36:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786059410; x=1786664210; 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=eYIjdKzjgH3nVD0iNsx5sVBVp8XFdFFsnkR62+s/p+Q=; b=ffcw/IHb9JNHii8DAVND3kK4sXHRWcLf2Ymt82lp6bZ5WK+ETX/RsDZ0CZ3I2qbuZY U1nqKPfb3iBjUP46P5s0MvXZnFCObTSMshm5O/wE/OG0okGLv3VLxTF1lJviTG11Jz2l jxOfDJ6eD9N7VD5FuAb0ENAYbPXxZZWoi7SRQRneBfP4dKS7zEnfiDNz8yumuvRgWtNF Yi3El0FMjQLWpFdPbkVwuz5zq4uIRPv4yMk+r4AEV3mXuR22JMXn3ocP+3GBPpsop7/v h2F1nkdCTMs5TC7tDwn2LuWbldls9jKOmAs2Z6G9MUo/yQnp6abVLjmgJWLSTT5KtwMW lfaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786059410; x=1786664210; 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=eYIjdKzjgH3nVD0iNsx5sVBVp8XFdFFsnkR62+s/p+Q=; b=W7RdbixEpEfQ+3czf1upngBEp9PxENrdbPhe/lEBNyvjEKmHD5ZqbXsJg9ELRCxWro AP9Rl4lWkuskA+K6b0gA6CpH5SMfOaSYdkAbxOSPgocWx6TrB+GRWQSP5Yhx5bRTe3zl 29/yWjwX11jrEACfwFNYk7hdGDAbbCj5eJs/acoqwiSBwDm9P+RlfzWHnDsjkzF7vkxR J8PsEi5JdKMvf/aCc9ThyThx6ChhgTEjYEOmIoW1JGB3rtx0xryN7h4vWSv+MO0g/W9O X9hmKxkJQOYNR6TqZM4Xik+RQUy6BcyNPXMEGTosusJvw2zwGjcdgoNCrUMmuO/baZDX CWaQ== X-Forwarded-Encrypted: i=1; AHgh+RoEnSzG2xHwnkDgq3JNL9shfe7aF/yKhRqwMvGijuur7Di5r+yMUBNTn1sk5tsRrIx7i8qJxzAerwAZ8JQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzruyczWyuSDRFlBFZjysvR8wmnZ3xg/no1WEN/Oj0i5TLghYHR Sd16gCfb+ZC6vcPPWk9zathskZn1jzpUsS3qkWQuLDp0ZOLKBlw9xbwwAgXOB9iDAmwZ7aGLY4e 3gpxUzA== X-Received: from pjji3.prod.google.com ([2002:a17:90a:6503:b0:381:224:393a]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:c106:b0:38e:250b:122f with SMTP id 98e67ed59e1d1-3909d8d5993mr5453558a91.16.1786059409368; Thu, 06 Aug 2026 16:36:49 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 6 Aug 2026 16:35:37 -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-21-seanjc@google.com> Subject: [PATCH v6 20/51] KVM: x86: Officially define CPUID 0x40000010 as PV Timing Info (TSC and Bus) 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" From: David Woodhouse Formally define and document CPUID 0x40000010 as providing TSC and local APIC bus frequency information for KVM's PV CPUID range. Way back in 2008, VMware proposed (https://lkml.org/lkml/2008/10/1/246) carving out a range of CPUID leaves for use by hypervisors. While the broader proposal from VMware was mostly shot down in flames, use of CPUID 0x40000010 to provide TSC and local APIC bus frequency information survived and made it's way into multiple guest operating systems. XNU unconditionally assumes CPUID 0x40000010 contains the frequency information, if it's present on any hypervisor: https://github.com/apple/darwin-xnu/blob/main/osfmk/i386/cpuid.c As does FreeBSD: https://github.com/freebsd/freebsd-src/commit/4a432614f68 More importantly, QEMU (the de facto "reference" VMM for KVM) has conditionally provided timing information in CPUID 0x40000010 for almost 9 years, since commit 9954a1582e ("x86-KVM: Supply TSC and APIC clock rates to guest like VMWare"). So at this point it would be daft for KVM (or any hypervisor) to expose 0x40000010 for any *other* content. Officially carve out and define the CPUID leaf so that Linux-as-a-guest can follow suit and pull TSC and Local APIC Bus frequency information from CPUID. Defer providing userspace with the necessary information needed to precisely and accurately enumerate the _actual_ configured TSC frequency to the guest (that exact information, along with the scaled ratio, isn't exposed to userspace). As evidenced by QEMU, providing CPUID 0x40000010 without help from KVM is entirely possible, just not ideal. Link: https://lore.kernel.org/all/ea0d7f43d910cee9600b254e303f468722fa355b.camel@infradead.org Signed-off-by: David Woodhouse [sean: drop KVM filling of CPUID, add documentation, massage changelog] Signed-off-by: Sean Christopherson --- Documentation/virt/kvm/x86/cpuid.rst | 12 ++++++++++++ arch/x86/include/uapi/asm/kvm_para.h | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/Documentation/virt/kvm/x86/cpuid.rst b/Documentation/virt/kvm/x86/cpuid.rst index bda3e3e737d7..a5ee8ff052ce 100644 --- a/Documentation/virt/kvm/x86/cpuid.rst +++ b/Documentation/virt/kvm/x86/cpuid.rst @@ -122,3 +122,15 @@ KVM_HINTS_REALTIME 0 guest checks this feature bit to preempted for an unlimited time allowing optimizations ================== ============ ================================= + +function: KVM_CPUID_TIMING_INFO (0x40000010) + +returns:: + + eax = (Virtual) TSC frequency in kHz + ebx = (Virtual) Bus (local APIC timer) frequency in kHz + ecx = 0 (Reserved) + edx = 0 (Reserved) + +Note, KVM only defines the semantics of KVM_CPUID_TIMING_INFO; KVM does NOT +advertise support via KVM_GET_SUPPORTED_CPUID. diff --git a/arch/x86/include/uapi/asm/kvm_para.h b/arch/x86/include/uapi/asm/kvm_para.h index a1efa7907a0b..c3a384711f3a 100644 --- a/arch/x86/include/uapi/asm/kvm_para.h +++ b/arch/x86/include/uapi/asm/kvm_para.h @@ -44,6 +44,17 @@ */ #define KVM_FEATURE_CLOCKSOURCE_STABLE_BIT 24 +/* + * The timing information leaf provides TSC and local APIC timer frequency + * information to the guest. Note, userspace is responsible for filling the + * leaf with the correct information. + * + * # EAX: (Virtual) TSC frequency in kHz. + * # EBX: (Virtual) Bus (local APIC timer) frequency in kHz. + * # ECX, EDX: Reserved (must be zero). + */ +#define KVM_CPUID_TIMING_INFO 0x40000010 + #define MSR_KVM_WALL_CLOCK 0x11 #define MSR_KVM_SYSTEM_TIME 0x12 -- 2.55.0.679.g6767b8d81c-goog