From: Sean Christopherson <seanjc@google.com>
To: David Woodhouse <dwmw2@infradead.org>
Cc: Carsten Stollmaier <stollmc@amazon.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Thomas Gleixner <tglx@kernel.org>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] KVM: x86: Use gfn_to_pfn_cache for record_steal_time
Date: Thu, 12 Mar 2026 17:17:44 -0700 [thread overview]
Message-ID: <abNXqMq3wx9Yq94h@google.com> (raw)
In-Reply-To: <c73bc1f22fbdbd88efb21cb80eccdd98d2ea531a.camel@infradead.org>
With some assistance from an AI review bot (well, more than "some").
On Wed, Mar 11, 2026, David Woodhouse wrote:
> @@ -3806,39 +3788,32 @@ static void record_steal_time(struct kvm_vcpu *vcpu)
> st_preempted & KVM_VCPU_FLUSH_TLB);
> if (st_preempted & KVM_VCPU_FLUSH_TLB)
> kvm_vcpu_flush_tlb_guest(vcpu);
> -
> - if (!user_access_begin(st, sizeof(*st)))
> - goto dirty;
> } else {
> - if (!user_access_begin(st, sizeof(*st)))
> - return;
> -
> - unsafe_put_user(0, &st->preempted, out);
> + st->preempted = 0;
These should all be WRITE_ONCE(), correct?
> vcpu->arch.st.preempted = 0;
> }
>
> - unsafe_get_user(version, &st->version, out);
> + version = st->version;
And then READ_ONCE()?
> if (version & 1)
> version += 1; /* first time write, random junk */
>
> version += 1;
> - unsafe_put_user(version, &st->version, out);
> + st->version = version;
>
> smp_wmb();
>
> - unsafe_get_user(steal, &st->steal, out);
> + steal = st->steal;
> steal += current->sched_info.run_delay -
> vcpu->arch.st.last_steal;
> vcpu->arch.st.last_steal = current->sched_info.run_delay;
> - unsafe_put_user(steal, &st->steal, out);
> + st->steal = steal;
>
> version += 1;
> - unsafe_put_user(version, &st->version, out);
> + st->version = version;
And then here, doesn't there need to be an smp_wmb() before incrementing the
version again? Because I believe making this all vanilla C means the compiler
can reorder those two. Per the friendly bot:
The previous code used unsafe_put_user(), which inherently acts as a
compiler barrier due to its internal inline assembly
> +
> + kvm_gpc_mark_dirty_in_slot(gpc);
>
> - out:
> - user_access_end();
> - dirty:
> - mark_page_dirty_in_slot(vcpu->kvm, ghc->memslot, gpa_to_gfn(ghc->gpa));
> + read_unlock(&gpc->lock);
> }
>
> /*
> @@ -4173,8 +4148,12 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
>
> vcpu->arch.st.msr_val = data;
>
> - if (!(data & KVM_MSR_ENABLED))
> - break;
> + if (data & KVM_MSR_ENABLED) {
Curly braces aren't required.
> + kvm_gpc_activate(&vcpu->arch.st.cache, data & ~KVM_MSR_ENABLED,
> + sizeof(struct kvm_steal_time));
> + } else {
> + kvm_gpc_deactivate(&vcpu->arch.st.cache);
> + }
...
> @@ -5266,20 +5244,28 @@ static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu)
> if (unlikely(current->mm != vcpu->kvm->mm))
> return;
>
> - slots = kvm_memslots(vcpu->kvm);
> -
> - if (unlikely(slots->generation != ghc->generation ||
> - gpa != ghc->gpa ||
> - kvm_is_error_hva(ghc->hva) || !ghc->memslot))
> - return;
> + read_lock_irqsave(&gpc->lock, flags);
I'm pretty sure this is going to make PROVE_LOCKING unhappy due to PREEMPT_RT
making rwlock_t sleepable (when called from kvm_sched_out()). I've been content
to ignore the kvm_xen_set_evtchn_fast() warning[*] because I can't imagine anyone
is crazy enough to emulate Xen with an RT kernel, but I do know there are RT users
that run VMs, and so this path would be more than just a PROVE_LOCKING issue.
If we want to push the gpc stuff broadly, we need a solution to that (though I'm
still not 100% convinced using a gpc here is a net positive).
[*] https://lore.kernel.org/all/673f4bbc.050a0220.3c9d61.0174.GAE@google.com
next prev parent reply other threads:[~2026-03-13 0:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-11 11:49 David Woodhouse
2026-03-11 23:50 ` David Woodhouse
2026-03-13 0:17 ` Sean Christopherson [this message]
2026-03-17 22:59 ` David Woodhouse
2026-03-17 23:29 ` Huang, Kai
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=abNXqMq3wx9Yq94h@google.com \
--to=seanjc@google.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=dwmw2@infradead.org \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=stollmc@amazon.com \
--cc=tglx@kernel.org \
--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
all inboxes | Powered by JetHome®