public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Griffoul, Fred" <fgriffo@amazon.co.uk>
To: Vitaly Kuznetsov <vkuznets@redhat.com>,
	Sean Christopherson <seanjc@google.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"x86@kernel.org" <x86@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	David Woodhouse <dwmw2@infradead.org>,
	Paul Durrant <paul@xen.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] KVM: x86: Update Xen-specific CPUID leaves during mangling
Date: Thu, 23 Jan 2025 15:33:30 +0000	[thread overview]
Message-ID: <cd8c29bc349244399b84008ef4c9ce7a@amazon.co.uk> (raw)
In-Reply-To: <87frl97jer.fsf@redhat.com>

Thanks for your comments: I will post a new patch following Sean's idea to fix the CPUID registers directly in kvm_cpuid().

Br,

--
Fred

________________________________________
From: Vitaly Kuznetsov <vkuznets@redhat.com>
Sent: Thursday, January 23, 2025 1:24:12 PM
To: Sean Christopherson
Cc: Griffoul, Fred; kvm@vger.kernel.org; Paolo Bonzini; Thomas Gleixner; Ingo Molnar; Borislav Petkov; Dave Hansen; x86@kernel.org; H. Peter Anvin; David Woodhouse; Paul Durrant; linux-kernel@vger.kernel.org
Subject: RE: [EXTERNAL] [PATCH] KVM: x86: Update Xen-specific CPUID leaves during mangling


Sean Christopherson <seanjc@google.com> writes:

> On Wed, Jan 22, 2025, Vitaly Kuznetsov wrote:
>> > Signed-off-by: Fred Griffoul <fgriffo@amazon.co.uk>
>> > ---
>> >  arch/x86/kvm/cpuid.c | 1 +
>> >  arch/x86/kvm/xen.c   | 5 +++++
>> >  arch/x86/kvm/xen.h   | 5 +++++
>> >  3 files changed, 11 insertions(+)
>> >
>> > diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
>> > index edef30359c19..432d8e9e1bab 100644
>> > --- a/arch/x86/kvm/cpuid.c
>> > +++ b/arch/x86/kvm/cpuid.c
>> > @@ -212,6 +212,7 @@ static int kvm_cpuid_check_equal(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2
>> >     */
>> >    kvm_update_cpuid_runtime(vcpu);
>> >    kvm_apply_cpuid_pv_features_quirk(vcpu);
>> > +  kvm_xen_update_cpuid_runtime(vcpu);
>>
>> This one is weird as we update it in runtime (kvm_guest_time_update())
>> and values may change when we e.g. migrate the guest. First, I do not
>> understand how the guest is supposed to notice the change as CPUID data
>> is normally considered static.
>
> I don't think it does.  Linux-as-a-guest reads the info once during boot (see
> xen_tsc_safe_clocksource()), and if and only if the TSC is constant and non-stop,
> i.e. iff the values won't change.

Right, the values shouldn't change on the same host. What I was thinking
is what happens when we migrate the guest to another
host. kvm_guest_time_update() is going to be called and we will get
something different (maybe just slightly different, but still) in Xen
TSC CPUIDs. The guest, however, is likely not going to notice at all.

>
>>  Second, I do not see how the VMM is
>> supposed to track it as if it tries to supply some different data for
>> these Xen leaves, kvm_cpuid_check_equal() will still fail.
>>
>> Would it make more sense to just ignore these Xen CPUID leaves with TSC
>> information when we do the comparison?
>
> Another alternative would be to modify the register output in kvm_cpuid().  Given
> that Linux reads the info once during boot, and presumably other guests do the
> same, runtime "patching" wouldn't incur meaningful overhead.  And there are no
> feature bits that KVM cares about, i.e. no reason KVM's view needs to be correct.

True, CPUID reading time should not be performance critical.

--
Vitaly


      reply	other threads:[~2025-01-23 15:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-22 16:16 [PATCH] KVM: x86: Update Xen-specific CPUID leaves during mangling Fred Griffoul
2025-01-22 17:16 ` Vitaly Kuznetsov
2025-01-22 17:19   ` Paul Durrant
2025-01-22 17:44     ` Vitaly Kuznetsov
2025-01-22 18:53       ` David Woodhouse
2025-01-22 22:00         ` Sean Christopherson
2025-01-23 12:35           ` Vitaly Kuznetsov
2025-01-23 16:44             ` David Woodhouse
2025-01-23  1:13   ` Sean Christopherson
2025-01-23 13:24     ` Vitaly Kuznetsov
2025-01-23 15:33       ` Griffoul, Fred [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=cd8c29bc349244399b84008ef4c9ce7a@amazon.co.uk \
    --to=fgriffo@amazon.co.uk \
    --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=paul@xen.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=vkuznets@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