All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chao Gao <chao.gao@intel.com>
To: Jim Mattson <jmattson@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>, <kvm@vger.kernel.org>,
	<isaku.yamahata@gmail.com>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 00/36] KVM: VMX APIC timer virtualization support
Date: Thu, 30 Jul 2026 20:38:46 +0800	[thread overview]
Message-ID: <amtF1vo8WdZU0OBf@intel.com> (raw)
In-Reply-To: <CALMp9eSLLm_4K0c0ouRYTpqxGkiBcRShf2NO9JOS9ZP+Ws+H0w@mail.gmail.com>

On Wed, Jul 29, 2026 at 10:39:11AM -0700, Jim Mattson wrote:
>On Wed, Jul 29, 2026 at 3:00 AM Chao Gao <chao.gao@intel.com> wrote:
>>
>> On Tue, Jul 28, 2026 at 11:05:59PM -0700, Jim Mattson wrote:
>> >On Tue, Jul 28, 2026 at 6:35 PM Chao Gao <chao.gao@intel.com> wrote:
>> >>
>> >> Hi Sean, Jim,
>> >>
>> >> Any thoughts on the approach of reusing hv_timer for APIC timer
>> >> virtualization?
>> >
>> >Last I heard, APIC timer virtualization was only available on E-cores,
>> >with no P-core intercept on the roadmap.
>>
>> It will be available on Coral Rapids as well, so it is relevant for
>> server.
>
>That's welcome news!

Thanks for the feedback!

>
>I'm not a fan of the hv_timer approach. One major difference between
>the VMX preemption timer and the virtual TSC deadline MSR is that the
>VMX preemption timer has to be reprogrammed every time that KVM
>switches from hrtimer to hv_timer.

For the preemption timer value written to the VMCS, yes. But
hv_deadline_tsc (the absolute host TSC deadline, set in vmx_set_hv_timer())
doesn't necessarily need recomputation across hrtimer/hv_timer switches.

If this reprogram/recomputation cost matters, we can optimize the
block/unblock path for the preemption timer to avoid that, and then the
same optimization would apply naturally to APIC timer virtualization.

The idea is: don't call cancel_hv_timer() when switching to hrtimer and
don't call set_hv_timer() when switching back. cancel_hv_timer() can
be deferred to virtual interrupt injection time (alongside setting
tscdeadline to 0, which means disarming the timer architecturally).
I think this works for TSC-deadline and oneshot modes; periodic mode
needs more thought since the timer needs to be re-armed after each expiry.

>The virtual TSC deadline timer
>never needs reprogramming during normal operation.

>Another difference
>is that KVM should never inject a virtual local APIC timer interrupt
>when the virtual TSC deadline timer is in use. Even if the vCPU was
>blocked and the hrtimer fired to wake it up, KVM should just let the
>hardware deliver the virtual interrupt on the next VM-entry.

I agree this is the ideal behavior. But I don't see what's wrong with
KVM delivering the interrupt. 

IMO, letting hardware deliver the interrupt after block would require:

  1. We still need to mark the timer as pending to wake the vCPU from
     block. But to let hardware do the injection on VM-entry, we'd
     then need to consume the pending event without actually injecting
     the interrupt.

  2. Tweaking kvm_wait_lapic_expire(). The deadline was advanced when
     arming the hrtimer, so the vCPU wakes slightly before the actual
     deadline. Currently kvm_wait_lapic_expire() scans vIRR to decide
     whether to busy-wait until the deadline, but if we rely on
     hardware to deliver the interrupt, the vector won't be in vIRR
     and we'd need a different indicator.

Given this, I'd prefer to let KVM inject the interrupt for this specific
"hrtimer fired to wakeup" case — it works correctly as is and avoids the
additional complexity.

>
>I'd rather see TSC deadline timer virtualization implemented as a
>standalone APIC virtualization feature.

      reply	other threads:[~2026-07-30 12:38 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-05 17:43 [PATCH v2 00/36] KVM: VMX APIC timer virtualization support isaku.yamahata
2026-03-05 17:43 ` [PATCH v2 01/36] KVM: VMX: Detect APIC timer virtualization bit isaku.yamahata
2026-03-05 17:43 ` [PATCH v2 02/36] KVM: x86: Implement APIC virt timer helpers with callbacks isaku.yamahata
2026-03-05 17:43 ` [PATCH v2 03/36] KVM: x86/lapic: Start/stop sw/hv timer on vCPU un/block isaku.yamahata
2026-03-05 17:43 ` [PATCH v2 04/36] KVM: x86/lapic: Wire DEADLINE MSR update to guest virtual TSC deadline isaku.yamahata
2026-03-05 17:43 ` [PATCH v2 05/36] KVM: x86/lapic: Add a trace point for guest virtual timer isaku.yamahata
2026-03-05 17:43 ` [PATCH v2 06/36] KVM: VMX: Implement the hooks for VMX guest virtual deadline timer isaku.yamahata
2026-03-05 17:43 ` [PATCH v2 07/36] KVM: VMX: Update APIC timer virtualization on apicv changed isaku.yamahata
2026-03-05 17:43 ` [PATCH v2 08/36] KVM: nVMX: Disallow/allow guest APIC timer virtualization switch to/from L2 isaku.yamahata
2026-03-05 17:43 ` [PATCH v2 09/36] KVM: nVMX: Pass struct msr_data to VMX MSRs emulation isaku.yamahata
2026-03-05 17:43 ` [PATCH v2 10/36] KVM: nVMX: Supports VMX tertiary controls and GUEST_APIC_TIMER bit isaku.yamahata
2026-03-05 17:43 ` [PATCH v2 11/36] KVM: nVMX: Add alignment check for struct vmcs12 isaku.yamahata
2026-03-05 17:43 ` [PATCH v2 12/36] KVM: nVMX: Add tertiary VM-execution control VMCS support isaku.yamahata
2026-03-05 17:43 ` [PATCH v2 13/36] KVM: nVMX: Update intercept on TSC deadline MSR isaku.yamahata
2026-03-05 17:43 ` [PATCH v2 14/36] KVM: nVMX: Handle virtual timer vector VMCS field isaku.yamahata
2026-03-05 17:43 ` [PATCH v2 15/36] KVM: VMX: Make vmx_calc_deadline_l1_to_host() non-static isaku.yamahata
2026-03-05 17:43 ` [PATCH v2 16/36] KVM: nVMX: Enable guest deadline and its shadow VMCS field isaku.yamahata
2026-03-06 11:14   ` kernel test robot
2026-03-05 17:43 ` [PATCH v2 17/36] KVM: nVMX: Add VM entry checks related to APIC timer virtualization isaku.yamahata
2026-03-05 17:43 ` [PATCH v2 18/36] KVM: nVMX: Add check vmread/vmwrite on tertiary control isaku.yamahata
2026-03-05 17:43 ` [PATCH v2 19/36] KVM: nVMX: Add check VMCS index for guest timer virtualization isaku.yamahata
2026-03-05 17:44 ` [PATCH v2 20/36] KVM: VMX: Advertise tertiary controls to the user space isaku.yamahata
2026-03-05 17:44 ` [PATCH v2 21/36] KVM: VMX: dump_vmcs() support the guest virt timer isaku.yamahata
2026-03-05 17:44 ` [PATCH v2 22/36] KVM: VMX: Enable APIC timer virtualization isaku.yamahata
2026-03-05 17:44 ` [PATCH v2 23/36] KVM: VMX: Introduce module parameter for APIC virt timer support isaku.yamahata
2026-03-05 17:44 ` [PATCH v2 24/36] KVM: nVMX: Introduce module parameter for nested APIC timer virtualization isaku.yamahata
2026-03-05 17:44 ` [PATCH v2 25/36] KVM: selftests: Add a test to measure local timer latency isaku.yamahata
2026-03-05 17:44 ` [PATCH v2 26/36] KVM: selftests: Add nVMX support to timer_latency test case isaku.yamahata
2026-03-05 17:44 ` [PATCH v2 27/36] KVM: selftests: Add test for nVMX MSR_IA32_VMX_PROCBASED_CTLS3 isaku.yamahata
2026-03-05 17:44 ` [PATCH v2 28/36] KVM: selftests: Add test vmx_set_nested_state_test with EVMCS disabled isaku.yamahata
2026-03-05 17:44 ` [PATCH v2 29/36] KVM: selftests: Add tests nested state of APIC timer virtualization isaku.yamahata
2026-03-05 17:44 ` [PATCH v2 30/36] KVM: selftests: Add VMCS access test to " isaku.yamahata
2026-03-05 17:44 ` [PATCH v2 31/36] KVM: selftests: Add serialize() helper and X86_FEATURE_SERIALIZE isaku.yamahata
2026-03-05 17:44 ` [PATCH v2 32/36] KVM: selftests: Test cases for L1 APIC timer virtualization isaku.yamahata
2026-03-05 17:44 ` [PATCH v2 33/36] KVM: selftests: Add tests for nVMX to vmx_apic_timer_virt isaku.yamahata
2026-03-05 17:44 ` [PATCH v2 34/36] KVM: selftests: Add a global option to disable in-kernel irqchip isaku.yamahata
2026-03-05 17:44 ` [PATCH v2 35/36] KVM: selftests: Test VMX apic timer virt with inkernel apic disable isaku.yamahata
2026-03-05 17:44 ` [PATCH v2 36/36] Documentation: KVM: x86: Update documentation of struct vmcs12 isaku.yamahata
2026-07-16  8:30 ` [PATCH v2 00/36] KVM: VMX APIC timer virtualization support Chao Gao
2026-07-29  1:34   ` Chao Gao
2026-07-29  6:05     ` Jim Mattson
2026-07-29  9:59       ` Chao Gao
2026-07-29 17:39         ` Jim Mattson
2026-07-30 12:38           ` Chao Gao [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=amtF1vo8WdZU0OBf@intel.com \
    --to=chao.gao@intel.com \
    --cc=isaku.yamahata@gmail.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.