kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vishal Annapurve <vannapurve@google.com>
To: David Matlack <dmatlack@google.com>
Cc: x86 <x86@kernel.org>, kvm list <kvm@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-kselftest@vger.kernel.org,
	Paolo Bonzini <pbonzini@redhat.com>, shuah <shuah@kernel.org>,
	Ben Gardon <bgardon@google.com>,
	Sean Christopherson <seanjc@google.com>,
	Oliver Upton <oupton@google.com>,
	peterx@redhat.com, Vitaly Kuznetsov <vkuznets@redhat.com>
Subject: Re: [V2 PATCH 4/8] KVM: selftests: x86: Precompute the result for is_{intel,amd}_cpu()
Date: Mon, 26 Sep 2022 16:27:31 -0700	[thread overview]
Message-ID: <CAGtprH-4nRyA81wock_OVwL-xA+LgNfqZFhJeE7T4iUyEscJKg@mail.gmail.com> (raw)
In-Reply-To: <Yyt/xgPkHfbOE3vH@google.com>

On Wed, Sep 21, 2022 at 2:19 PM David Matlack <dmatlack@google.com> wrote:
>
> On Thu, Sep 15, 2022 at 12:04:44AM +0000, Vishal Annapurve wrote:
> > Cache the vendor CPU type in a global variable so that multiple calls
> > to is_intel_cpu() do not need to re-execute CPUID.
> >
> > Add cpu vendor check in kvm_hypercall() so that it executes correct
> > vmcall/vmmcall instruction when running on Intel/AMD hosts. This avoids
> > exit to KVM which anyway tries to patch the instruction according to
> > the cpu type.
>
> The commit shortlog makes no mention (nor even implies) that this commit
> adds AMD support to kvm_hypercall(). Please break this commit up into 2.
> One to precompute the result of is_{intel,amd}_cpu() and one to add AMD
> support to kvm_hypercall().
>
> If you really want to keep this as one commit (I don't know what the
> benefit would be), please change the shortlog and commit message to
> focus on the kvm_hypercall() change, as that is the real goal of this
> commit. The precomputation is arguably and implementation detail. e.g.
>

is_amd_cpu is used by guest code within fix_hypercall_test.c, just
caching the result will break the guest code execution. I have clubbed
these two changes together in order to ensure that is_amd_cpu works
fine for both host userspace and guest vm logic.

>   KVM: selftest: Add support for AMD to kvm_hypercall()
>
>   Make it possible to use kvm_hypercall() on AMD by checking if running
>   on an AMD CPU and, if so, using vmmcall instead of vmcall. In order to
>   avoid executing CPUID in the guest on every call t kvm_hypercall()
>   (which would be slow), pre-compute the result of is_{intel,amd}_cpu()
>   as part of kvm_selftest_arch_init() and sync it into the guest
>   after loading the ELF image.
>
> But again, it'd be cleaner just to split it up. Caching the result of
> is_{intel,amd}_cpu() is useful in its own right, independent of the
> kvm_hypercall() change.
>
> >
> > ...
> >
> > @@ -1314,8 +1321,10 @@ bool vm_is_unrestricted_guest(struct kvm_vm *vm)
> >
> >  void kvm_selftest_arch_init(void)
> >  {
> > +     is_cpu_amd = cpu_vendor_string_is("AuthenticAMD");
> >  }
> >
> >  void kvm_arch_post_vm_elf_load(struct kvm_vm *vm)
> >  {
> > +     sync_global_to_guest(vm, is_cpu_amd);
> >  }
> > --
> > 2.37.2.789.g6183377224-goog
> >

  reply	other threads:[~2022-09-26 23:27 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-15  0:04 [V2 PATCH 0/8] Execute hypercalls from guests according to cpu type Vishal Annapurve
2022-09-15  0:04 ` [V2 PATCH 1/8] KVM: selftests: move common startup logic to kvm_util.c Vishal Annapurve
2022-09-15  9:45   ` Andrew Jones
2022-09-15  0:04 ` [V2 PATCH 2/8] KVM: selftests: Add arch specific initialization Vishal Annapurve
2022-09-15  9:44   ` Andrew Jones
2022-09-26 23:18     ` Vishal Annapurve
2022-09-21 20:50   ` David Matlack
2022-09-26 23:18     ` Vishal Annapurve
2022-09-15  0:04 ` [V2 PATCH 3/8] KVM: selftests: Add arch specific post vm load setup Vishal Annapurve
2022-09-21 20:54   ` David Matlack
2022-09-26 23:18     ` Vishal Annapurve
2022-10-03 15:42       ` Sean Christopherson
2022-10-04  0:02         ` Vishal Annapurve
2022-10-04 20:10           ` Sean Christopherson
2022-10-13 11:36             ` Vishal Annapurve
2022-09-15  0:04 ` [V2 PATCH 4/8] KVM: selftests: x86: Precompute the result for is_{intel,amd}_cpu() Vishal Annapurve
2022-09-21 21:19   ` David Matlack
2022-09-26 23:27     ` Vishal Annapurve [this message]
2022-09-26 23:34       ` David Matlack
2022-09-26 23:40         ` Vishal Annapurve
2022-09-21 21:39   ` David Matlack
2022-09-26 23:48     ` Vishal Annapurve
2022-09-26 23:53       ` David Matlack
2022-09-15  0:04 ` [V2 PATCH 5/8] KVM: selftests: x86: delete svm_vmcall_test Vishal Annapurve
2022-09-21 21:34   ` David Matlack
2022-09-26 23:32     ` Vishal Annapurve
2022-09-15  0:04 ` [V2 PATCH 6/8] KVM: selftests: x86: Execute cpu specific hypercall from nested guests Vishal Annapurve
2022-09-15  0:04 ` [V2 PATCH 7/8] Kvm: selftests: x86: Execute cpu specific vmcall instruction Vishal Annapurve
2022-09-21 21:43   ` David Matlack
2022-09-26 23:35     ` Vishal Annapurve
2022-09-15  0:04 ` [V2 PATCH 8/8] KVM: selftests: x86: xen: " Vishal Annapurve
2022-09-21 21:47   ` David Matlack
2022-09-26 23:37     ` Vishal Annapurve

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=CAGtprH-4nRyA81wock_OVwL-xA+LgNfqZFhJeE7T4iUyEscJKg@mail.gmail.com \
    --to=vannapurve@google.com \
    --cc=bgardon@google.com \
    --cc=dmatlack@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=oupton@google.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).