All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yan Li <elliot.li.tech@gmail.com>
To: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@elte.hu>,
	"H. Peter Anvin" <hpa@zytor.com>
Cc: Yan Li <elliot.li.tech@gmail.com>,
	joerg.roedel@amd.com, rjmaomao@gmail.com,
	Yinghai Lu <yhlu.kernel@gmail.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	nancydreaming@gmail.com
Subject: [PATCH 1/2] VMware guest detection for x86 and x86-64
Date: Wed, 24 Sep 2008 20:22:10 +0800	[thread overview]
Message-ID: <48da36b9.160d6e0a.22a5.ffffec9d@mx.google.com> (raw)
In-Reply-To: <48D12490.5010003@zytor.com>

Detects whether we are running as a VMware guest or not. Detection is
based upon DMI vendor string.

It provides a function:
int is_vmware_guest(void)
that can be used easily to detect if we are running as a VMware guest
or not.

I haven't used PCI vendor Id since that requires copying a trunk of
codes from early_quirks() and I think copying code is not good. And
reusing codes from early_quirks() needs intrivial change to present
codes structure. Comparatively, checking "VMware" string against DMI
manufacturer is a lot more simpler (one-line code). Also there's no
evidence indicating that VMware will change their vendor string in
near future. Therefore I choose to use simpler way.

Tested on x86 and x86-64 VMs and machines.

Signed-off-by: Yan Li <elliot.li.tech@gmail.com>
---
 arch/x86/Kconfig         |   10 ++++++++++
 arch/x86/kernel/Makefile |    1 +
 arch/x86/kernel/vmware.c |   23 +++++++++++++++++++++++
 include/asm-x86/vmware.h |   20 ++++++++++++++++++++
 4 files changed, 54 insertions(+), 0 deletions(-)
 create mode 100644 arch/x86/kernel/vmware.c
 create mode 100644 include/asm-x86/vmware.h

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index ed92864..85dfebd 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -445,6 +445,16 @@ config PARAVIRT_DEBUG
          Enable to debug paravirt_ops internals.  Specifically, BUG if
 	 a paravirt_op is missing when it is called.
 
+config VMWARE_GUEST_DETECT
+	bool "VMware guest detection support"
+	default y
+	depends on DMI && !X86_VOYAGER
+	help
+          This enables detection of running as a full-virtualized
+          VMware guest (as under VMware Workstation or VMware
+          Server). Currently this is used to suppress false warnings
+          from initialization.
+
 config MEMTEST
 	bool "Memtest"
 	help
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index 3db651f..a3a16a8 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -87,6 +87,7 @@ obj-$(CONFIG_DEBUG_RODATA_TEST)	+= test_rodata.o
 obj-$(CONFIG_DEBUG_NX_TEST)	+= test_nx.o
 
 obj-$(CONFIG_VMI)		+= vmi_32.o vmiclock_32.o
+obj-$(CONFIG_VMWARE_GUEST_DETECT)	+= vmware.o
 obj-$(CONFIG_KVM_GUEST)		+= kvm.o
 obj-$(CONFIG_KVM_CLOCK)		+= kvmclock.o
 obj-$(CONFIG_PARAVIRT)		+= paravirt.o paravirt_patch_$(BITS).o
diff --git a/arch/x86/kernel/vmware.c b/arch/x86/kernel/vmware.c
new file mode 100644
index 0000000..352d5d8
--- /dev/null
+++ b/arch/x86/kernel/vmware.c
@@ -0,0 +1,23 @@
+/*
+ * Check if we are running as a VMware guest or not
+ *
+ * Copyright (C) 2008 Yan Li <elliot.li.tech@gmail.com>
+ *
+ */
+
+#include <linux/dmi.h>
+#include <linux/kernel.h>
+#include <asm/vmware.h>
+
+/*
+ * detect whether we are running as a VMware guest or not. this
+ * function depends on DMI so it should not be used early before
+ * dmi_scan_machine() in setup_arch()
+ */
+int is_vmware_guest(void)
+{
+	if (!dmi_available)
+		return 0;
+	else
+		return dmi_name_in_vendors("VMware");
+}
diff --git a/include/asm-x86/vmware.h b/include/asm-x86/vmware.h
new file mode 100644
index 0000000..554f0f9
--- /dev/null
+++ b/include/asm-x86/vmware.h
@@ -0,0 +1,20 @@
+/*
+ * Check if we are running as a VMware guest or not
+ *
+ * Copyright (C) 2008 Yan Li <elliot.li.tech@gmail.com>
+ *
+ */
+
+#ifndef _ASM_X86_VMWARE_H
+#define _ASM_X86_VMWARE_H
+
+/*
+ *  is_vmware_guest - return non-zero if running as a VMware guest
+ */
+#ifdef CONFIG_VMWARE_GUEST_DETECT
+extern int is_vmware_guest(void);
+#else
+int is_vmware_guest(void) { return 0; }
+#endif /* CONFIG_VMWARE_GUEST_DETECT */
+
+#endif /* _ASM_X86_VMWARE_H */
-- 
1.5.4.3


-- 
Li, Yan

"Everything that is really great and inspiring is created by the
individual who can labor in freedom."
              - Albert Einstein, in Out of My Later Years (1950)

  reply	other threads:[~2008-09-24 12:47 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-21 11:32 [PATCH] X86: remove WARN_ON if MTRRs are all blank Joerg Roedel
2008-02-21 11:54 ` Ingo Molnar
2008-02-21 12:47   ` Joerg Roedel
2008-02-21 13:03     ` Ingo Molnar
2008-02-21 13:27       ` Joerg Roedel
2008-09-07 23:45   ` [PATCH 1/2] VMware detection support for x86 and x86-64 Yan Li
2008-09-08  0:36     ` David Dillow
2008-09-08  1:49       ` Yan Li
2008-09-08 14:04     ` Ingo Molnar
2008-09-09  0:20       ` Yan Li
2008-09-09  0:34         ` H. Peter Anvin
2008-09-09 12:28           ` Yan Li
2008-09-09 20:12             ` H. Peter Anvin
2008-09-16 13:32           ` Yan Li
2008-09-17 10:52             ` Ingo Molnar
2008-09-17 14:03               ` Yan Li
2008-09-17 14:10                 ` Ingo Molnar
2008-09-17 15:38                   ` H. Peter Anvin
2008-09-24 12:22                     ` Yan Li [this message]
2008-09-24 14:10                       ` [PATCH 1/2] VMware guest detection " Cristi Magherusan
2008-09-24 14:23                         ` Yan Li
2008-09-24 16:19                           ` Alok kataria
2008-09-24 16:21                             ` H. Peter Anvin
2008-09-25  0:19                               ` Yan Li
2008-09-25  0:15                             ` Yan Li
2008-09-25  0:26                               ` H. Peter Anvin
2008-09-25  2:34                                 ` Yan Li
2008-09-24 18:13                           ` Cristi Magherusan
2008-09-24 18:16                             ` H. Peter Anvin
2008-09-25  0:23                             ` Yan Li
2008-09-25  1:28                               ` Bernd Eckenfels
2008-09-24 16:19                       ` H. Peter Anvin
2008-09-25  0:32                         ` Yan Li
2008-09-25  0:37                           ` H. Peter Anvin
2008-09-25  2:48                             ` Yan Li
2008-09-25  9:56                           ` David Sanders
2008-09-25 10:23                             ` Yan Li
2008-09-25  2:23                       ` Greg KH
2008-09-25  2:47                         ` Yan Li
2008-09-25  2:55                           ` Greg KH
2008-09-25  3:29                             ` Yan Li
2008-09-25  4:54                             ` H. Peter Anvin
2008-09-25 12:56                               ` Greg KH
2008-09-25 14:38                               ` Yan Li
2008-09-25  2:28       ` [PATCH 1/2] VMware detection support " Alok kataria
2008-09-25  4:38         ` H. Peter Anvin
2008-09-25  4:46           ` Alok Kataria
2008-09-25  4:54             ` H. Peter Anvin
2008-09-25  5:02               ` Alok Kataria
2008-09-25  5:04                 ` H. Peter Anvin
2008-09-25  5:23                   ` Alok Kataria
2008-09-25  5:30                     ` H. Peter Anvin
2008-09-25  8:45                     ` Alan Cox
2008-09-25 20:48                     ` Zachary Amsden
2008-09-25 21:59                       ` H. Peter Anvin
2008-09-25 22:20                         ` Zachary Amsden
2008-09-25 22:27                           ` H. Peter Anvin
2008-09-26 12:27                             ` Valdis.Kletnieks
2008-09-26 12:47                             ` Gerd Hoffmann
2008-09-26 13:22                               ` Valdis.Kletnieks
2008-09-26 17:37                                 ` H. Peter Anvin
2008-10-03 14:12                                   ` Pavel Machek
2008-09-26 20:35                                 ` Zachary Amsden
2008-09-25 22:17                       ` David Sanders
2008-09-07 23:47   ` [PATCH 2/2] avoid mtrr warning message when running as VMware guest Yan Li

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=48da36b9.160d6e0a.22a5.ffffec9d@mx.google.com \
    --to=elliot.li.tech@gmail.com \
    --cc=hpa@zytor.com \
    --cc=joerg.roedel@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=nancydreaming@gmail.com \
    --cc=rjmaomao@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=yhlu.kernel@gmail.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.