From: zhangyanfei <zhangyanfei@cn.fujitsu.com>
To: avi@redhat.com, mtosatti@redhat.com
Cc: ebiederm@xmission.com, luto@mit.edu, joerg.roedel@amd.com,
dzickus@redhat.com, paul.gortmaker@windriver.com, gregkh@suse.de,
ludwig.nussel@suse.de, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org, kexec@lists.infradead.org
Subject: [PATCH 1/4] x86: Add helper variables and functions to hold VMCSINFO
Date: Wed, 11 Apr 2012 09:49:02 +0800 [thread overview]
Message-ID: <4F84E30E.7020507@cn.fujitsu.com> (raw)
In-Reply-To: <4F84E0DF.8040206@cn.fujitsu.com>
This patch provides a set of variables to hold the VMCSINFO and also
some helper functions to help fill the VMCSINFO.
Signed-off-by: zhangyanfei <zhangyanfei@cn.fujitsu.com>
---
arch/x86/include/asm/vmcsinfo.h | 42 +++++++++++++++++++++++
arch/x86/kernel/Makefile | 2 +
arch/x86/kernel/vmcsinfo.c | 70 +++++++++++++++++++++++++++++++++++++++
3 files changed, 114 insertions(+), 0 deletions(-)
create mode 100644 arch/x86/include/asm/vmcsinfo.h
create mode 100644 arch/x86/kernel/vmcsinfo.c
diff --git a/arch/x86/include/asm/vmcsinfo.h b/arch/x86/include/asm/vmcsinfo.h
new file mode 100644
index 0000000..cfdc984
--- /dev/null
+++ b/arch/x86/include/asm/vmcsinfo.h
@@ -0,0 +1,42 @@
+#ifndef _ASM_X86_VMCSINFO_H
+#define _ASM_X86_VMCSINFO_H
+
+#ifndef __ASSEMBLY__
+#include <linux/types.h>
+#include <linux/elf.h>
+
+/*
+ * Currently, 2 pages are enough for vmcsinfo.
+ */
+#define VMCSINFO_BYTES (8192)
+#define VMCSINFO_NOTE_NAME "VMCSINFO"
+#define VMCSINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCSINFO_NOTE_NAME), 4)
+#define VMCSINFO_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
+#define VMCSINFO_NOTE_SIZE (VMCSINFO_NOTE_HEAD_BYTES*2 \
+ + VMCSINFO_BYTES \
+ + VMCSINFO_NOTE_NAME_BYTES)
+
+extern size_t vmcsinfo_size;
+extern size_t vmcsinfo_max_size;
+
+extern void update_vmcsinfo_note(void);
+extern void vmcsinfo_append_str(const char *fmt, ...);
+extern unsigned long paddr_vmcsinfo_note(void);
+
+#define VMCSINFO_REVISION_ID(id) \
+ vmcsinfo_append_str("REVISION_ID=%x\n", id)
+#define VMCSINFO_FIELD16(name, value) \
+ vmcsinfo_append_str("FIELD(%s)=%04x\n", #name, value)
+#define VMCSINFO_FIELD32(name, value) \
+ vmcsinfo_append_str("FIELD(%s)=%08x\n", #name, value)
+#define VMCSINFO_FIELD64(name, value) \
+ vmcsinfo_append_str("FIELD(%s)=%016llx\n", #name, value)
+
+#ifdef CONFIG_X86_64
+#define VMCSINFO_FIELD(name, value) VMCSINFO_FIELD64(name, value)
+#else
+#define VMCSINFO_FIELD(name, value) VMCSINFO_FIELD32(name, value)
+#endif
+
+#endif /* __ASSEMBLY__ */
+#endif /* _ASM_X86_VMCSINFO_H */
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index 532d2e0..63edf33 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -102,6 +102,8 @@ obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o
obj-$(CONFIG_SWIOTLB) += pci-swiotlb.o
obj-$(CONFIG_OF) += devicetree.o
+obj-y += vmcsinfo.o
+
###
# 64 bit specific files
ifeq ($(CONFIG_X86_64),y)
diff --git a/arch/x86/kernel/vmcsinfo.c b/arch/x86/kernel/vmcsinfo.c
new file mode 100644
index 0000000..c1306ef
--- /dev/null
+++ b/arch/x86/kernel/vmcsinfo.c
@@ -0,0 +1,70 @@
+/*
+ * Architecture specific (i386/x86_64) functions for storing vmcs
+ * field information.
+ *
+ * Created by: zhangyanfei (zhangyanfei@cn.fujitsu.com)
+ *
+ * Copyright (C) Fujitsu Corporation, 2012. All rights reserved.
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2. See the file COPYING for more details.
+ */
+
+#include <asm/vmcsinfo.h>
+#include <linux/module.h>
+#include <linux/elf.h>
+
+static unsigned char vmcsinfo_data[VMCSINFO_BYTES];
+static u32 vmcsinfo_note[VMCSINFO_NOTE_SIZE/4];
+size_t vmcsinfo_max_size = sizeof(vmcsinfo_data);
+size_t vmcsinfo_size;
+EXPORT_SYMBOL(vmcsinfo_size);
+
+void update_vmcsinfo_note(void)
+{
+ u32 *buf = vmcsinfo_note;
+ struct elf_note note;
+
+ if (!vmcsinfo_size)
+ return;
+
+ note.n_namesz = strlen(VMCSINFO_NOTE_NAME) + 1;
+ note.n_descsz = vmcsinfo_size;
+ note.n_type = 0;
+ memcpy(buf, ¬e, sizeof(note));
+ buf += (sizeof(note) + 3)/4;
+ memcpy(buf, VMCSINFO_NOTE_NAME, note.n_namesz);
+ buf += (note.n_namesz + 3)/4;
+ memcpy(buf, vmcsinfo_data, note.n_descsz);
+ buf += (note.n_descsz + 3)/4;
+
+ note.n_namesz = 0;
+ note.n_descsz = 0;
+ note.n_type = 0;
+ memcpy(buf, ¬e, sizeof(note));
+}
+EXPORT_SYMBOL(update_vmcsinfo_note);
+
+void vmcsinfo_append_str(const char *fmt, ...)
+{
+ va_list args;
+ char buf[0x50];
+ int r;
+
+ va_start(args, fmt);
+ r = vsnprintf(buf, sizeof(buf), fmt, args);
+ va_end(args);
+
+ if (r + vmcsinfo_size > vmcsinfo_max_size)
+ r = vmcsinfo_max_size - vmcsinfo_size;
+
+ memcpy(&vmcsinfo_data[vmcsinfo_size], buf, r);
+
+ vmcsinfo_size += r;
+}
+EXPORT_SYMBOL(vmcsinfo_append_str);
+
+unsigned long paddr_vmcsinfo_note(void)
+{
+ return __pa((unsigned long)(char *)&vmcsinfo_note);
+}
--
1.7.1
next prev parent reply other threads:[~2012-04-11 1:49 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-11 1:39 [PATCH 0/4] Export offsets of VMCS fields as note information for kdump zhangyanfei
2012-04-11 1:49 ` zhangyanfei [this message]
2012-04-11 1:50 ` [PATCH 2/4] KVM: VMX: Add functions to fill VMCSINFO zhangyanfei
[not found] ` <4F84E365.10201-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-04-11 8:48 ` Avi Kivity
[not found] ` <4F85454E.6020201-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-04-11 10:34 ` zhangyanfei
[not found] ` <4F855E3C.9010003-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-04-11 11:41 ` Avi Kivity
[not found] ` <4F84E0DF.8040206-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-04-11 1:57 ` [PATCH 3/4] ksysfs: export VMCSINFO via sysfs zhangyanfei
[not found] ` <4F84E50E.2090008-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-04-12 23:00 ` Greg KH
2012-04-17 1:52 ` zhangyanfei
2012-04-17 2:30 ` Greg KH
2012-04-11 1:58 ` [PATCH 4/4] kexec: Add crash_save_vmcsinfo to update VMCSINFO zhangyanfei
2012-04-11 10:21 ` [PATCH 0/4] Export offsets of VMCS fields as note information for kdump Joerg Roedel
[not found] ` <20120411102136.GG2428-5C7GfCeVMHo@public.gmane.org>
2012-04-11 10:49 ` Avi Kivity
2012-04-11 10:59 ` zhangyanfei
2012-04-17 7:44 ` Avi Kivity
[not found] ` <4F8D1F46.3090901-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-04-17 10:51 ` zhangyanfei
[not found] ` <4F8D4B4C.8070705-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-04-17 10:59 ` Avi Kivity
[not found] ` <4F8D4D1C.4010400-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-04-17 11:25 ` Wen Congyang
[not found] ` <4F8D530C.3050908-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-04-17 13:04 ` Avi Kivity
2012-04-18 7:30 ` zhangyanfei
[not found] ` <4F8E6DA5.8030503-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-04-18 8:24 ` Avi Kivity
[not found] ` <4F8E7A5B.5030904-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-04-18 9:49 ` zhangyanfei
[not found] ` <4F8E8E3D.8040707-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-04-18 11:56 ` Avi Kivity
[not found] ` <4F8EABF7.805-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-04-19 10:36 ` HATAYAMA Daisuke
[not found] ` <20120419.193640.59653378.d.hatayama-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2012-04-19 10:42 ` Avi Kivity
[not found] ` <4F8FEC22.400-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-04-19 11:27 ` HATAYAMA Daisuke
[not found] ` <20120419.202707.276752866.d.hatayama-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2012-04-19 11:31 ` Avi Kivity
[not found] ` <4F8FF7AC.1060309-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-04-19 12:01 ` HATAYAMA Daisuke
[not found] ` <20120419.210119.246504497.d.hatayama-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2012-04-19 12:08 ` Avi Kivity
[not found] ` <4F900020.5010702-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-04-20 10:11 ` HATAYAMA Daisuke
2012-04-22 9:58 ` Avi Kivity
[not found] ` <4F93D64B.50803-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-04-22 10:33 ` Gleb Natapov
[not found] ` <20120422103340.GE12768-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-04-22 10:57 ` Avi Kivity
2012-04-17 16:49 ` Anthony Liguori
[not found] ` <4F8D9F20.9050507-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
2012-04-18 12:13 ` Avi Kivity
2012-04-18 13:47 ` Nadav Har'El
[not found] ` <20120418134743.GA25786-QeE623+hzFJ/hwrKWqB9+zWi1Rwp9Q0N+oGz7xIJsNs@public.gmane.org>
2012-04-18 14:06 ` Avi Kivity
2012-04-11 8:56 ` Avi Kivity
[not found] ` <4F85472A.4080009-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-04-11 10:12 ` zhangyanfei
2012-04-11 11:15 ` Avi Kivity
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=4F84E30E.7020507@cn.fujitsu.com \
--to=zhangyanfei@cn.fujitsu.com \
--cc=avi@redhat.com \
--cc=dzickus@redhat.com \
--cc=ebiederm@xmission.com \
--cc=gregkh@suse.de \
--cc=joerg.roedel@amd.com \
--cc=kexec@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ludwig.nussel@suse.de \
--cc=luto@mit.edu \
--cc=mtosatti@redhat.com \
--cc=paul.gortmaker@windriver.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