linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark McLoughlin <markmc@redhat.com>
To: akataria@vmware.com
Cc: Ingo Molnar <mingo@elte.hu>, "H. Peter Anvin" <hpa@zytor.com>,
	Andi Kleen <andi@firstfloor.org>,
	LKML <linux-kernel@vger.kernel.org>,
	the arch/x86 maintainers <x86@kernel.org>,
	Daniel Hecht <dhecht@vmware.com>
Subject: Re: [PATCH 2/4] Hypervisor detection and get tsc_freq from hypervisor
Date: Mon, 10 Nov 2008 12:38:40 +0000	[thread overview]
Message-ID: <1226320720.4068.54.camel@blaa> (raw)
In-Reply-To: <1225129306.28018.9.camel@alok-dev1>

Hi Alok,

On Mon, 2008-10-27 at 10:41 -0700, Alok Kataria wrote:

> x86: Get TSC frequency from VMware hypervisor.
> 
> From: Alok N Kataria <akataria@vmware.com>
> 
> v3->v2 : Abstract the hypervisor detection and feature (tsc_freq) request
> 	 behind a hypervisor.c file
> v2->v1 : Add a x86_hyper_vendor field to the cpuinfo_x86 structure.
> 	 This avoids multiple calls to the hypervisor detection function.
> 
> This patch adds function to detect if we are running under VMware.
> The current way to check if we are on VMware is following,
> #  check if "hypervisor present bit" is set, if so read the 0x40000000
>    cpuid leaf and check for "VMwareVMware" signature.
> #  if the above fails, check the DMI vendors name for "VMware" string
>    if we find one we query the VMware hypervisor port to check if we are
>    under VMware.
> 
> The DMI + "VMware hypervisor port check" is needed for older VMware products,
> which don't implement the hypervisor signature cpuid leaf.
> Also note that since we are checking for the DMI signature the hypervisor
> port should never be accessed on native hardware.
> 
> This patch also adds a hypervisor_get_tsc_freq function, instead of
> calibrating the frequency which can be error prone in virtualized
> environment, we ask the hypervisor for it. We get the frequency from
> the hypervisor by accessing the hypervisor port if we are running on VMware.
> Other hypervisors too can add code to the generic routine to get frequency on
> their platform.
> 
> Signed-off-by: Alok N Kataria <akataria@vmware.com>
> Signed-off-by: Dan Hecht <dhecht@vmware.com>
> Cc: H. Peter Anvin <hpa@zytor.com>
> ---
> 
>  arch/x86/include/asm/cpufeature.h |    2 +
>  arch/x86/include/asm/hypervisor.h |   26 +++++++++++
>  arch/x86/include/asm/processor.h  |    4 ++
>  arch/x86/include/asm/vmware.h     |   26 +++++++++++
>  arch/x86/kernel/cpu/Makefile      |    1 
>  arch/x86/kernel/cpu/common.c      |    2 +
>  arch/x86/kernel/cpu/hypervisor.c  |   48 ++++++++++++++++++++
>  arch/x86/kernel/cpu/vmware.c      |   88 +++++++++++++++++++++++++++++++++++++
>  arch/x86/kernel/setup.c           |    7 +++
>  arch/x86/kernel/tsc.c             |    9 +++-
>  10 files changed, 212 insertions(+), 1 deletions(-)
>  create mode 100644 arch/x86/include/asm/hypervisor.h
>  create mode 100644 arch/x86/include/asm/vmware.h
>  create mode 100644 arch/x86/kernel/cpu/hypervisor.c
>  create mode 100644 arch/x86/kernel/cpu/vmware.c
> 
> 
> diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
> index f73e95d..78478f2 100644
> --- a/arch/x86/include/asm/cpufeature.h
> +++ b/arch/x86/include/asm/cpufeature.h
> @@ -117,6 +117,7 @@
>  #define X86_FEATURE_XSAVE	(4*32+26) /* XSAVE/XRSTOR/XSETBV/XGETBV */
>  #define X86_FEATURE_OSXSAVE	(4*32+27) /* "" XSAVE enabled in the OS */
>  #define X86_FEATURE_AVX		(4*32+28) /* Advanced Vector Extensions */
> +#define X86_FEATURE_HYPERVISOR	(4*32+31) /* Running on a hypervisor */

I don't see you set this anywhere.

>  /* VIA/Cyrix/Centaur-defined CPU features, CPUID level 0xC0000001, word 5 */
>  #define X86_FEATURE_XSTORE	(5*32+ 2) /* "rng" RNG present (xstore) */
> @@ -237,6 +238,7 @@ extern const char * const x86_power_flags[32];
>  #define cpu_has_xmm4_2		boot_cpu_has(X86_FEATURE_XMM4_2)
>  #define cpu_has_x2apic		boot_cpu_has(X86_FEATURE_X2APIC)
>  #define cpu_has_xsave		boot_cpu_has(X86_FEATURE_XSAVE)
> +#define cpu_has_hypervisor	boot_cpu_has(X86_FEATURE_HYPERVISOR)

...

> diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c
> new file mode 100644
> index 0000000..d5d1b75
> --- /dev/null
> +++ b/arch/x86/kernel/cpu/vmware.c
> @@ -0,0 +1,88 @@

...

> +int vmware_platform(void)
> +{
> +	if (cpu_has_hypervisor) {
> +		unsigned int eax, ebx, ecx, edx;
> +		char hyper_vendor_id[13];
> +
> +		cpuid(CPUID_VMWARE_INFO_LEAF, &eax, &ebx, &ecx, &edx);
> +		memcpy(hyper_vendor_id + 0, &ebx, 4);
> +		memcpy(hyper_vendor_id + 4, &ecx, 4);
> +		memcpy(hyper_vendor_id + 8, &edx, 4);
> +		hyper_vendor_id[12] = '\0';
> +		if (!strcmp(hyper_vendor_id, "VMwareVMware"))
> +			return 1;

This seems to be the only use of cpu_has_hypervisor, but this is the
hypervisor detection code, so it's not clear how you intended
X86_FEATURE_HYPERVISOR be set before here?

Cheers,
Mark.


  parent reply	other threads:[~2008-11-10 12:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-25  0:21 [PATCH 2/4] Hypervisor detection and get tsc_freq from hypervisor Alok Kataria
2008-10-27 11:01 ` Ingo Molnar
2008-10-27 17:41   ` Alok Kataria
2008-11-03 19:31     ` Alok Kataria
2008-11-10 12:38     ` Mark McLoughlin [this message]
2008-11-10 15:32       ` H. Peter Anvin

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=1226320720.4068.54.camel@blaa \
    --to=markmc@redhat.com \
    --cc=akataria@vmware.com \
    --cc=andi@firstfloor.org \
    --cc=dhecht@vmware.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --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).