From: Yan Li <elliot.li.tech@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: mingo@elte.hu, joerg.roedel@amd.com, elliot.li.tech@gmail.com,
rjmaomao@gmail.com
Subject: [PATCH 1/2] VMware detection support for x86 and x86-64
Date: Mon, 8 Sep 2008 07:45:11 +0800 [thread overview]
Message-ID: <20080907234510.GA24133@yantp.cn.ibm.com> (raw)
In-Reply-To: <20080221115452.GB13948@elte.hu>
On Thu, Feb 21, 2008 at 12:54:52PM +0100, Ingo Molnar wrote:
>
> * Joerg Roedel <joerg.roedel@amd.com> wrote:
>
> > if (!highest_pfn) {
> > printk(KERN_WARNING "WARNING: strange, CPU MTRRs all
> > blank?\n");
> > - WARN_ON(1);
> > return 0;
> > }
>
> instead of obscuring a possibly useful warning, please instead
> detect
> that it's a KVM guest and skip both the warning and the backtrace in
> that case.
This patch detects whether we are running as a VMware guest or
not. Used 'official' detection code from VMware's Open Virtual Machine
Tools (open-vm-tools/checkvm), with LGPLv2.1 changed to GPLv2.
It provides a function:
int is_vmware_guest(void)
that can be used easily to detect if we are running as a VMware guest.
Currently this can be useful in suppressing false warning from mtrr
module, hope some other modules find this useful too (like adopting
less aggressive strategy on cache using, since the host is already
doing cache for us, etc.)
Signed-off-by: Yan Li <elliot.li.tech@gmail.com>
---
arch/x86/lib/Makefile | 1 +
arch/x86/lib/vmware.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++
include/asm-x86/vmware.h | 30 ++++++++++++++++++++++
3 files changed, 92 insertions(+), 0 deletions(-)
create mode 100644 arch/x86/lib/vmware.c
create mode 100644 include/asm-x86/vmware.h
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
index aa3fa41..8327a12 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -8,6 +8,7 @@ lib-y := delay.o
lib-y += thunk_$(BITS).o
lib-y += usercopy_$(BITS).o getuser.o putuser.o
lib-y += memcpy_$(BITS).o
+lib-y += vmware.o
ifeq ($(CONFIG_X86_32),y)
lib-y += checksum_32.o
diff --git a/arch/x86/lib/vmware.c b/arch/x86/lib/vmware.c
new file mode 100644
index 0000000..39c9360
--- /dev/null
+++ b/arch/x86/lib/vmware.c
@@ -0,0 +1,61 @@
+/*
+ * Check if we are running as a VMware guest or not
+ *
+ * Copyright (C) 2007 VMware, Inc. All rights reserved.
+ * Adapted to Linux by Yan Li <elliot.li.tech@gmail.com>
+ * from open-vm-tools/checkvm
+ * from VMware's Open Virtual Machine Tools (under LGPLv2.1)
+ * (open-vm-tools.sourceforge.net)
+ *
+ * The original codes from VMware are licensed under LGPLv2.1, I (Yan
+ * Li) converted the following parts to use GPL license as stated in
+ * COPYING file of Linux.
+ */
+
+#include <linux/kernel.h>
+#include <asm/vmware.h>
+
+/* Backdoor def from open-vm-tools/lib/include/backdoor_def.h */
+#define BDOOR_MAGIC 0x564D5868
+/* Low-bandwidth backdoor port. --hpreg */
+#define BDOOR_PORT 0x5658
+#define BDOOR_CMD_GETVERSION 10
+#define VERSION_MAGIC 0x6
+
+/*
+ * getVersion - Read VM version & product code through backdoor
+ */
+void getVersion(u32 *version)
+{
+ u32 eax, ebx, ecx, edx;
+
+ asm volatile("inl (%%dx)" :
+ "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) :
+ "0"(BDOOR_MAGIC), "1"(BDOOR_CMD_GETVERSION),
+ "2"(BDOOR_PORT) : "memory");
+ version[0] = eax;
+ version[1] = ebx;
+ version[2] = ecx;
+}
+
+
+int is_vmware_guest(void)
+{
+ u32 version[3];
+
+ getVersion(&version[0]);
+
+ if (version[1] != BDOOR_MAGIC) {
+ /* Incorrect virtual machine version */
+ return 0;
+ }
+
+ if (version[0] != VERSION_MAGIC) {
+ /* Incorrect version magic */
+ return 0;
+ }
+
+ /* Yes, we are running as VMware Guest */
+ printk(KERN_INFO "vmware detected\n");
+ return 1;
+}
diff --git a/include/asm-x86/vmware.h b/include/asm-x86/vmware.h
new file mode 100644
index 0000000..aad262a
--- /dev/null
+++ b/include/asm-x86/vmware.h
@@ -0,0 +1,30 @@
+/*
+ * Check if we are running as a VMware guest or not
+ *
+ * Copyright (C) 2007 VMware, Inc. All rights reserved.
+ * Adapted to Linux by Yan Li <elliot.li.tech@gmail.com>
+ * from open-vm-tools/checkvm
+ * from VMware's Open Virtual Machine Tools (under LGPLv2.1)
+ * (open-vm-tools.sourceforge.net)
+ *
+ * The original codes from VMware are licensed under LGPLv2.1, I (Yan
+ * Li) converted the following parts to use GPL license as stated in
+ * COPYING file of Linux.
+ */
+
+#ifndef _ASM_X86_VMWARE_H
+#define _ASM_X86_VMWARE_H
+
+#include <asm/types.h>
+
+/*
+ * getVersion - Read VMware version & product code through backdoor
+ */
+void getVersion(u32 *version);
+
+/*
+ * is_vmware_guest - return non-zero if running as a VMware guest
+ */
+int is_vmware_guest(void);
+
+#endif /* _ASM_X86_VMWARE_H */
--
1.5.6.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)
next prev parent reply other threads:[~2008-09-08 0:21 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 ` Yan Li [this message]
2008-09-08 0:36 ` [PATCH 1/2] VMware detection support for x86 and x86-64 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 ` [PATCH 1/2] VMware guest detection " Yan Li
2008-09-24 14:10 ` 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=20080907234510.GA24133@yantp.cn.ibm.com \
--to=elliot.li.tech@gmail.com \
--cc=joerg.roedel@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=rjmaomao@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome