On Thu, May 21, 2026, David Woodhouse wrote:
> On Thu, 2026-05-21 at 15:30 -0700, Sean Christopherson wrote:
> > On Thu, May 21, 2026, David Woodhouse wrote:
> > > On Sat, 2026-05-09 at 23:46 +0100, David Woodhouse wrote:
> > > > From: David Woodhouse <[email protected]>
> > > That does leave userspace still needing a way to get the APIC bus
> > > frequency, to populate CPUID. So maybe I'll just make an attribute
> > > which returns that as a single value.
> > 
> > Already exists, KVM_CAP_X86_APIC_BUS_CYCLES_NS.  The TDX architecture 
> > decided
> > that unconditionally telling guests the virtual APIC bus runs at 400Mhz was 
> > a
> > brilliant idea.
> 
> Ah, thanks.
> 
> So KVM always exposes 1GHz by default regardless of the actual host?
> Which is why there's no *get* method?
> 
> (Well... getting KVM_CAP_APIC_BUS_CYCLES_NS returns
> APIC_BUS_CYCLE_NS_DEFAULT which is 1, so it's basically just returning
> 1 like a lot of cap queries do, and *not* returning what the period is
> actually set to)

Oh, that's just an oversight, definitely not intentional.  Easy enough to fix:

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 1616b2eec6e7..cd4a244ca0c5 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2235,7 +2235,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long 
ext)
                r = tdp_enabled;
                break;
        case KVM_CAP_X86_APIC_BUS_CYCLES_NS:
-               r = APIC_BUS_CYCLE_NS_DEFAULT;
+               r = kvm ? kvm->arch.apic_bus_cycle_ns : 
APIC_BUS_CYCLE_NS_DEFAULT;
                break;
        case KVM_CAP_EXIT_HYPERCALL:
                r = KVM_EXIT_HYPERCALL_VALID_MASK;


Reply via email to