Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Dongli Zhang <dongli.zhang@oracle.com>
To: David Woodhouse <dwmw2@infradead.org>,
	Sean Christopherson <seanjc@google.com>
Cc: kvm@vger.kernel.org, x86@kernel.org,
	linux-kselftest@vger.kernel.org, pbonzini@redhat.com,
	vkuznets@redhat.com, tglx@kernel.org, mingo@redhat.com,
	bp@alien8.de, dave.hansen@linux.intel.com, shuah@kernel.org,
	hpa@zytor.com, peterz@infradead.org, juri.lelli@redhat.com,
	vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
	rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
	vschneid@redhat.com, kprateek.nayak@amd.com, jgross@suse.com,
	joe.jin@oracle.com
Subject: Re: [PATCH 2/5] KVM: x86: Reset vcpu->arch.st.last_steal when enabling steal time
Date: Mon, 11 May 2026 14:27:24 -0700	[thread overview]
Message-ID: <53a294f2-1812-4ccf-9bc8-c61a93588564@oracle.com> (raw)
In-Reply-To: <2b409be867cbd9b83087203302a86594553050e1.camel@infradead.org>



On 5/10/26 11:40 AM, David Woodhouse wrote:
> On Sun, 2026-05-10 at 18:09 +0100, David Woodhouse wrote:
>> On Fri, 2026-05-08 at 15:40 -0700, Sean Christopherson wrote:
>>> On Mon, May 04, 2026, Dongli Zhang wrote:
>>>> KVM does not support vCPU hotplug. When a vCPU is removed, its
>>>> corresponding data structures are not freed by KVM. Instead, QEMU destroys
>>>> only the userspace state and the vCPU thread, while the KVM vCPU fd remains
>>>> open and parked in QEMU.
>>>>
>>>> As a result, vcpu->arch.st.last_steal is not reset.
>>>>
>>>> If the same vCPU is later re-created by QEMU, last_steal retains its old
>>>> value, while current->sched_info.run_delay starts from zero since a new
>>>> vCPU thread is created. This causes
>>>> current->sched_info.run_delay - vcpu->arch.st.last_steal to produce a
>>>> large, bogus value.
>>>>
>>>> Fix this by resetting vcpu->arch.st.last_steal to
>>>> current->sched_info.run_delay when KVM steal time is enabled.
>>>
>>> This is quite arbitrary.  E.g. if userspace hands the vCPU off to a different
>>> task without going through QEMU's hotplug dance, then current->sched_info.run_delay
>>> will also change.
>>>
>>> Shouldn't x86 hook kvm_arch_vcpu_run_pid_change() and reset last_steal in there?
>>
>> I'd like to be sure that we get this right for live update and live migration.
>>
>> I think we *do* get it right for the Xen runstate info...
> 
> Since I'm adding selftests to my kvmclock branch today... I now *know*
> this to be true :)
> 
> 
> https://git.infradead.org/?p=users/dwmw2/linux.git;a=commitdiff;h=d667349116
> 
> Looks like Sean is right about the pid change though.

Thank you very much for reminder! Base on my understanding of source code, the
delta between vcpu->arch.st.last_steal and current->sched_info.run_delay (new
thread) won't account downtime if we handle it properly in
kvm_arch_vcpu_run_pid_change(). I may also add that validation to the selftest.

Thank you very much!

Dongli Zhang

  reply	other threads:[~2026-05-11 21:28 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-05  0:30 [PATCH 0/5] Fix and enhance KVM steal accounting for both guest and host Dongli Zhang
2026-05-05  0:30 ` [PATCH 1/5] x86/kvm: Reset prev_steal_time and prev_steal_time_rq when enabling steal time Dongli Zhang
2026-05-05  0:30 ` [PATCH 2/5] KVM: x86: Reset vcpu->arch.st.last_steal " Dongli Zhang
2026-05-08 22:40   ` Sean Christopherson
2026-05-10 17:09     ` David Woodhouse
2026-05-10 18:40       ` David Woodhouse
2026-05-11 21:27         ` Dongli Zhang [this message]
2026-05-12  5:46           ` David Woodhouse
2026-05-11 21:26     ` Dongli Zhang
2026-05-05  0:30 ` [PATCH 3/5] KVM: x86: account KVM_SET_CLOCK downtime in " Dongli Zhang
2026-05-10 18:54   ` David Woodhouse
2026-05-10 19:11     ` H. Peter Anvin
2026-05-10 20:13       ` David Woodhouse
2026-05-11 21:46         ` Dongli Zhang
2026-05-12  5:34           ` David Woodhouse
2026-05-05  0:30 ` [PATCH 4/5] KVM: selftests: Test steal time when re-adding a vCPU on a new thread Dongli Zhang
2026-05-05  0:30 ` [PATCH 5/5] KVM: selftests: Test KVM_SET_CLOCK downtime in steal time Dongli Zhang

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=53a294f2-1812-4ccf-9bc8-c61a93588564@oracle.com \
    --to=dongli.zhang@oracle.com \
    --cc=bp@alien8.de \
    --cc=bsegall@google.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=dwmw2@infradead.org \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=joe.jin@oracle.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    --cc=tglx@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vkuznets@redhat.com \
    --cc=vschneid@redhat.com \
    --cc=x86@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox