All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>
Subject: Re: [PATCH 1/2] selftests: kvm: introduce cpu_has_svm() check
Date: Fri, 29 May 2020 08:18:22 -0700	[thread overview]
Message-ID: <20200529151822.GB520@linux.intel.com> (raw)
In-Reply-To: <20200529130407.57176-1-vkuznets@redhat.com>

On Fri, May 29, 2020 at 03:04:06PM +0200, Vitaly Kuznetsov wrote:
> More tests may want to check if the CPU is Intel or AMD in
> guest code, separate cpu_has_svm() and put it as static
> inline to svm_util.h.
> 
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>  tools/testing/selftests/kvm/include/x86_64/svm_util.h | 10 ++++++++++
>  tools/testing/selftests/kvm/x86_64/state_test.c       |  9 +--------
>  2 files changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/include/x86_64/svm_util.h b/tools/testing/selftests/kvm/include/x86_64/svm_util.h
> index cd037917fece..b1057773206a 100644
> --- a/tools/testing/selftests/kvm/include/x86_64/svm_util.h
> +++ b/tools/testing/selftests/kvm/include/x86_64/svm_util.h
> @@ -35,4 +35,14 @@ void generic_svm_setup(struct svm_test_data *svm, void *guest_rip, void *guest_r
>  void run_guest(struct vmcb *vmcb, uint64_t vmcb_gpa);
>  void nested_svm_check_supported(void);
>  
> +static inline bool cpu_has_svm(void)
> +{
> +	u32 eax = 0x80000001, ecx;
> +
> +	asm volatile("cpuid" :
> +		     "=a" (eax), "=c" (ecx) : "0" (eax) : "ebx", "edx");

	u32 eax, ecx;

	asm("cpuid" : "=a" (eax), "=c" (ecx) : "a" (0x80000001) : "ebx", "edx");

The volatile shouldn't be needed, e.g. no one should be using this purely
for its seralization properties, and I don't see any reason to put the leaf
number into a variable.

Alternatively, adding a proper cpuid framework to processor.h would likely
be useful in the long run.

> +
> +	return ecx & CPUID_SVM;
> +}
> +

  parent reply	other threads:[~2020-05-29 15:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-29 13:04 [PATCH 1/2] selftests: kvm: introduce cpu_has_svm() check Vitaly Kuznetsov
2020-05-29 13:04 ` [PATCH 2/2] selftests: kvm: fix smm test on SVM Vitaly Kuznetsov
2020-05-29 15:28   ` Paolo Bonzini
2020-05-29 15:18 ` Sean Christopherson [this message]
2020-06-01  8:14   ` [PATCH 1/2] selftests: kvm: introduce cpu_has_svm() check Vitaly Kuznetsov

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=20200529151822.GB520@linux.intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.