public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] KVM: X86: Make bus lock frequency for vapic timer configurable
@ 2023-11-07 19:22 isaku.yamahata
  2023-11-07 19:22 ` [PATCH 1/2] KVM: x86: Make the hardcoded APIC bus frequency vm variable isaku.yamahata
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: isaku.yamahata @ 2023-11-07 19:22 UTC (permalink / raw)
  To: kvm, linux-kernel
  Cc: isaku.yamahata, isaku.yamahata, Paolo Bonzini, erdemaktas,
	Sean Christopherson, Vishal Annapurve

From: Isaku Yamahata <isaku.yamahata@intel.com>

Add KVM_CAP_X86_BUS_FREQUENCY_CONTROL capability to configure the core
crystal clock (or processor's bus clock) for APIC timer emulation.  Allow
KVM_ENABLE_CAPABILITY(KVM_CAP_X86_BUS_FREUQNCY_CONTROL) to set the
frequency.  When using this capability, the user space VMM should configure
CPUID[0x15] to advertise the frequency.

TDX virtualizes CPUID[0x15] for the core crystal clock to be 25MHz.  The
x86 KVM hardcodes its freuqncy for APIC timer to be 1GHz.  This mismatch
causes the vAPIC timer to fire earlier than the guest expects. [1] The KVM
APIC timer emulation uses hrtimer, whose unit is nanosecond.

There are options to reconcile the mismatch.  1) Make apic bus clock frequency
configurable (this patch).  2) TDX KVM code adjusts TMICT value.  This is hacky
and it results in losing MSB bits from 32 bit width to 30 bit width.  3). Make
the guest kernel use tsc deadline timer instead of acpi oneshot/periodic timer.
This is guest kernel choice.  It's out of control of VMM.

[1] https://lore.kernel.org/lkml/20231006011255.4163884-1-vannapurve@google.com/

Isaku Yamahata (2):
  KVM: x86: Make the hardcoded APIC bus frequency vm variable
  KVM: X86: Add a capability to configure bus frequency for APIC timer

 arch/x86/include/asm/kvm_host.h |  2 ++
 arch/x86/kvm/hyperv.c           |  2 +-
 arch/x86/kvm/lapic.c            |  6 ++++--
 arch/x86/kvm/lapic.h            |  4 ++--
 arch/x86/kvm/x86.c              | 16 ++++++++++++++++
 include/uapi/linux/kvm.h        |  1 +
 6 files changed, 26 insertions(+), 5 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-11-10 18:33 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-07 19:22 [PATCH 0/2] KVM: X86: Make bus lock frequency for vapic timer configurable isaku.yamahata
2023-11-07 19:22 ` [PATCH 1/2] KVM: x86: Make the hardcoded APIC bus frequency vm variable isaku.yamahata
2023-11-07 19:22 ` [PATCH 2/2] KVM: X86: Add a capability to configure bus frequency for APIC timer isaku.yamahata
2023-11-07 19:59   ` Jim Mattson
2023-11-08 23:41     ` Isaku Yamahata
2023-11-10  5:37   ` kernel test robot
2023-11-10 14:42     ` Sean Christopherson
2023-11-07 19:29 ` KVM: X86: Make bus clock frequency for vapic timer (bus lock -> bus clock) (was Re: [PATCH 0/2] KVM: X86: Make bus lock frequency for vapic timer) configurable Isaku Yamahata
2023-11-07 20:03   ` Jim Mattson
2023-11-08 23:54     ` Isaku Yamahata
2023-11-09 15:55       ` Sean Christopherson
2023-11-10  0:29         ` Isaku Yamahata

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox