]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: x86: hyper-v: Calculate APIC bus frequency for Hyper-V
authorIsaku Yamahata <isaku.yamahata@intel.com>
Thu, 25 Apr 2024 22:06:59 +0000 (15:06 -0700)
committerSean Christopherson <seanjc@google.com>
Wed, 5 Jun 2024 13:18:25 +0000 (06:18 -0700)
Remove APIC_BUS_FREQUENCY and calculate it based on nanoseconds per APIC
bus cycle.  APIC_BUS_FREQUENCY is used only for HV_X64_MSR_APIC_FREQUENCY.
The MSR is not frequently read, calculate it every time.

There are two constants related to the APIC bus frequency:
APIC_BUS_FREQUENCY and APIC_BUS_CYCLE_NS.
Only one value is required because one can be calculated from the other:
   APIC_BUS_CYCLES_NS = 1000 * 1000 * 1000 / APIC_BUS_FREQUENCY.

Remove APIC_BUS_FREQUENCY and instead calculate it when needed.
This prepares for support of configurable APIC bus frequency by
requiring to change only a single variable.

Suggested-by: Maxim Levitsky <maximlevitsky@gmail.com>
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
Reviewed-by: Maxim Levitsky <maximlevitsky@gmail.com>
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
[reinette: rework changelog]
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Link: https://lore.kernel.org/r/76a659d0898e87ebd73ee7c922f984a87a6ab370.1714081726.git.reinette.chatre@intel.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/hyperv.c
arch/x86/kvm/lapic.h

index 8a47f8541eab7098c991837c2b4e03c4822c445a..1030701db967e5f6c4680b4cdee475bb56944195 100644 (file)
@@ -1737,7 +1737,7 @@ static int kvm_hv_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata,
                data = (u64)vcpu->arch.virtual_tsc_khz * 1000;
                break;
        case HV_X64_MSR_APIC_FREQUENCY:
-               data = APIC_BUS_FREQUENCY;
+               data = div64_u64(1000000000ULL, APIC_BUS_CYCLE_NS);
                break;
        default:
                kvm_pr_unimpl_rdmsr(vcpu, msr);
index 0a0ea4b5dd8ce7239b85f5d054828fd5f0eedb6b..a20cb006b6c8c9839d6ea5f7694cb4c4914aa141 100644 (file)
@@ -17,7 +17,6 @@
 #define APIC_DEST_MASK                 0x800
 
 #define APIC_BUS_CYCLE_NS       1
-#define APIC_BUS_FREQUENCY      (1000000000ULL / APIC_BUS_CYCLE_NS)
 
 #define APIC_BROADCAST                 0xFF
 #define X2APIC_BROADCAST               0xFFFFFFFFul