Re: [PATCH v8 04/17] KVM: x86: Activate master clock immediately on vCPU creation

[email protected] Wed, 05 Aug 2026 00:06:40 +0000
Newsgroups org.kernel.vger.kvm
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Checking the boolean `!vcpu->kvm->arch.use_master_clock` instead of consuming the pending KVM request causes O(N^2) IPI storms on unstable TSC hosts and stale clock data when vCPUs have mismatched TSCs.
--

--- Patch [4]: [PATCH v8 04/17] KVM: x86: Activate master clock immediately on vCPU creation ---
commit 5f130615aa4f4dff0ab2f9d96232c00ec3b489b7
Author: David Woodhouse <[email protected]>

KVM: x86: Activate master clock immediately on vCPU creation

This commit updates kvm_arch_vcpu_postcreate() to activate the master
clock immediately upon vCPU creation instead of waiting for the first
KVM_RUN. This allows userspace to retrieve a valid host_tsc and realtime
pair via KVM_GET_CLOCK without needing a dummy vCPU run.

> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -9390,6 +9390,8 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
>  		return;
>  	vcpu_load(vcpu);
>  	kvm_synchronize_tsc(vcpu, NULL);
> +	if (!vcpu->kvm->arch.use_master_clock)
> +		kvm_update_masterclock(vcpu->kvm);

[Severity: High]
Instead of checking the boolean use_master_clock, should this check and
consume the pending KVM_REQ_MASTERCLOCK_UPDATE request via kvm_check_request?

If the host has an unstable TSC, use_master_clock remains false. Won't this
unconditionally call kvm_update_masterclock() for every vCPU creation,
resulting in O(N^2) iterations and an IPI storm to running vCPUs during
hotplug?

Additionally, if a newly created vCPU has a mismatched TSC frequency,
kvm_synchronize_tsc() correctly queues KVM_REQ_MASTERCLOCK_UPDATE to
disable the master clock. Because use_master_clock is currently true,
this boolean check bypasses the update.

Could this bypass leave the master clock inappropriately enabled and the
request pending, causing KVM_GET_CLOCK to return stale data to userspace
before the first KVM_RUN?

>  	vcpu_put(vcpu);
>  
>  	/* poll control enabled by default */

-- 
Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=4