From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.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 D592840EBB4 for ; Fri, 15 May 2026 19:21:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778872877; cv=none; b=CsablAheJvIlgIMNadoDz6qk1Pt0bWTtIJl4IBvg395hFZoVB2N9qgdhxBCAINsf8wFsdkydjgKc+u3x1j2DeHSHLrCYSlDWM0ALzMfbYgZwM0WGvd2OF1wqTry18OXd0f9iluH8rKB1qLocqYrPQakfHaSiUSF5arIyqTG0u4g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778872877; c=relaxed/simple; bh=B/Nd88zreMJtUwVM+EKuE0OYb6EhoS4ohLt5CAFmh34=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jAG4U0Ay8A0eITzEZGUwavyPYhH8y8ZgrYwU+92nj+O84XnCZ751k7Cc712KnHP8NpRiIEFe/x4cmKEq6kJscXHVHrr+0F4/hjEueIAy0Z4XUjqWxl+AVUBsPsMjUdxRKXxs8kMG3zzvrzSjBdYY/N+xCA8+BVCT4Oaa3v4J/5M= 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=Z2cP/jjo; arc=none smtp.client-ip=209.85.210.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="Z2cP/jjo" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-8353df9bc7eso223694b3a.2 for ; Fri, 15 May 2026 12:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778872874; x=1779477674; 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=vVLX5t3yX9DiZyDHfD7io13ZG0m6EjUCrIAXjsJko2U=; b=Z2cP/jjoFQh2BFEaRMzgxBD70YvB3x1zUmlI8Ainn5q0K9K4JcWIDO4P5IZDqTrguu Wrv6I5jdQUhua+hrNs4FvEuMHWpOeSU83aGHVrCGJkNvmtJKGdZn6uccR+W9Xe/WNdx7 IwM5uj+PauCtgynRlDNvXbGrzKnZz5xI/YGQIqcoT2CAo3cCSpmZbDo/piSeNubeAoea iFfGetRzUsJqK4c9lFZ1pvwn54/Dywjy4ajzm5HdBvT4Q7UI36xLvPmMwqY2x3hC0v8c L8fTIF5wsEEIRN5/1eEaSv3n/9Z4b67tliMvu5xKVVLqp0psReeNmfIkoTkbI1ravUCZ aIKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778872874; x=1779477674; 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=vVLX5t3yX9DiZyDHfD7io13ZG0m6EjUCrIAXjsJko2U=; b=UFRL2TjVDJFIEBPw3zKHbrXN9Am+wxDY4BGFUf0Wa3oCh3Q6L25DZOSS6J0R3eykV7 WTy6FOMgYMOCguDimb5sOHa5OmO8MP/Vuuu6AMIjlU2Vzyo04WlZKvNgwk7S1lTN4EjL amdobgFfwVSitt2DnIS/F5GnvVCFJFenaBjRSB3RiM7lyrILw3L2erLfXBxmr1ZtpdjQ 7a6hJyAX5txxJtYNAINUhcej0FGmV2DN45Fi0w8HF1hFGTa5mGqlJFEJzhVA3J52DHOH AVqw8n5zCoGXyNjvu7P+BZdPBiWchq+vjVdbWgXGXiBhlJ5Xdj9G6kvrn4wOdUmOIk+Q RHTA== X-Forwarded-Encrypted: i=1; AFNElJ+o91T+MByd/XHiDfhwms6PdRwciaa1fjYHG/qweI4jO9XegfSvbLgNRt9mTQjrgllKplw=@vger.kernel.org X-Gm-Message-State: AOJu0YwtFcx2otBaCIhdR362pXY6mcUIl/qqqoyRjP/XnbzEa9I4Gb6c vZ+1FUso2x7l1KFBXfPxUFcEjlznCv0t7hib9hV2eK6TbEx54JroX+7OZ16nqSsPlWpxml8C4Qs RMqrPyg== X-Received: from pfoo22.prod.google.com ([2002:a05:6a00:1a16:b0:836:d115:1e44]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:299a:b0:83b:c487:43d2 with SMTP id d2e1a72fcca58-83f33df451fmr5925936b3a.36.1778872873374; Fri, 15 May 2026 12:21:13 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 15 May 2026 12:19:35 -0700 In-Reply-To: <20260515191942.1892718-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260515191942.1892718-1-seanjc@google.com> X-Mailer: git-send-email 2.54.0.563.g4f69b47b94-goog Message-ID: <20260515191942.1892718-35-seanjc@google.com> Subject: [PATCH v3 34/41] KVM: x86: Officially define CPUID 0x40000010 as PV Timing Info (TSC and Bus) From: Sean Christopherson To: Kiryl Shutsemau , Paolo Bonzini , Sean Christopherson , "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: 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 , David Woodhouse 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..f02e395cfa9b 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. \ No newline at end of file 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.54.0.563.g4f69b47b94-goog