kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: zhangyanfei <zhangyanfei@cn.fujitsu.com>
To: Avi Kivity <avi@redhat.com>, mtosatti@redhat.com
Cc: ebiederm@xmission.com, luto@mit.edu,
	Joerg Roedel <joerg.roedel@amd.com>,
	dzickus@redhat.com, paul.gortmaker@windriver.com,
	ludwig.nussel@suse.de, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org, kexec@lists.infradead.org,
	Greg KH <gregkh@linuxfoundation.org>
Subject: [PATCH v2 1/5] x86: Add helper variables and functions to hold VMCSINFO
Date: Wed, 16 May 2012 15:52:52 +0800	[thread overview]
Message-ID: <4FB35CD4.3080801@cn.fujitsu.com> (raw)
In-Reply-To: <4FB35C48.30708@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 |   34 +++++++++++++++++
 arch/x86/kernel/Makefile        |    2 +
 arch/x86/kernel/vmcsinfo.c      |   79 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 115 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..1ca140b
--- /dev/null
+++ b/arch/x86/include/asm/vmcsinfo.h
@@ -0,0 +1,34 @@
+#ifndef _ASM_X86_VMCSINFO_H
+#define _ASM_X86_VMCSINFO_H
+
+#ifndef __ASSEMBLY__
+#include <linux/types.h>
+#include <linux/elf.h>
+
+/*
+ * Currently, 1 page is enough for vmcsinfo.
+ */
+#define VMCSINFO_BYTES             (4096)
+#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 unsigned char vmcsinfo_data[VMCSINFO_BYTES];
+
+extern void update_vmcsinfo_note(void);
+extern void vmcsinfo_append_id(u32);
+extern void vmcsinfo_append_field(u32, u64);
+extern unsigned long paddr_vmcsinfo_note(void);
+
+#define VMCSINFO_REVISION_ID(id) \
+	vmcsinfo_append_id(id)
+#define VMCSINFO_FIELD(field, offset) \
+	vmcsinfo_append_field(field, offset)
+
+#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..8d0ab3f
--- /dev/null
+++ b/arch/x86/kernel/vmcsinfo.c
@@ -0,0 +1,79 @@
+/*
+ * 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>
+
+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_GPL(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, &note, 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, &note, sizeof(note));
+}
+EXPORT_SYMBOL_GPL(update_vmcsinfo_note);
+
+void vmcsinfo_append_id(u32 id)
+{
+	size_t r;
+
+	r = sizeof(id);
+	if (r + vmcsinfo_size > vmcsinfo_max_size)
+		return;
+
+	memcpy(&vmcsinfo_data[vmcsinfo_size], &id, r);
+	vmcsinfo_size += r;
+}
+EXPORT_SYMBOL_GPL(vmcsinfo_append_id);
+
+void vmcsinfo_append_field(u32 field, u64 offset)
+{
+	size_t r;
+
+	r = sizeof(field) + sizeof(offset);
+	if (r + vmcsinfo_size > vmcsinfo_max_size)
+		return;
+
+	memcpy(&vmcsinfo_data[vmcsinfo_size], &field, sizeof(field));
+	vmcsinfo_size += sizeof(field);
+	memcpy(&vmcsinfo_data[vmcsinfo_size], &offset, sizeof(offset));
+	vmcsinfo_size += sizeof(offset);
+}
+EXPORT_SYMBOL_GPL(vmcsinfo_append_field);
+
+unsigned long paddr_vmcsinfo_note(void)
+{
+	return __pa((unsigned long)(char *)&vmcsinfo_note);
+}
-- 
1.7.1

  reply	other threads:[~2012-05-16  7:52 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-16  7:50 [PATCH v2 0/5] Export offsets of VMCS fields as note information for kdump zhangyanfei
2012-05-16  7:52 ` zhangyanfei [this message]
     [not found]   ` <4FB35CD4.3080801-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-06-14 13:28     ` [PATCH v2 1/5] x86: Add helper variables and functions to hold VMCSINFO Avi Kivity
     [not found] ` <4FB35C48.30708-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-05-16  7:54   ` [PATCH v2 2/5] KVM: Export symbols for module vmcsinfo-intel zhangyanfei
2012-05-16  7:55   ` [PATCH v2 3/5] KVM-INTEL: Add new module vmcsinfo-intel to fill VMCSINFO zhangyanfei
     [not found]     ` <4FB35D60.6050009-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-06-14 13:37       ` Avi Kivity
2012-06-15  3:03         ` HATAYAMA Daisuke
2012-05-16  7:56   ` [PATCH v2 4/5] ksysfs: Export VMCSINFO via sysfs zhangyanfei
2012-05-16  7:57   ` [PATCH v2 5/5] Documentation: Add ABI entry for sysfs file vmcsinfo and vmcsinfo_maxsize zhangyanfei
     [not found]     ` <4FB35DEF.2040008-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-06-14 13:21       ` Avi Kivity
2012-05-20 17:43   ` [PATCH v2 0/5] Export offsets of VMCS fields as note information for kdump Avi Kivity
2012-05-21  2:32     ` Yanfei Zhang
     [not found]       ` <4FB9A92D.7050108-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-05-21  8:34         ` Avi Kivity
     [not found]           ` <4FB9FE08.4050905-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-05-21  9:08             ` Yanfei Zhang
     [not found]               ` <4FBA05F6.8070804-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-05-21  9:36                 ` Avi Kivity
     [not found]                   ` <4FBA0C8A.2050003-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-05-22  3:40                     ` Yanfei Zhang
2012-05-28  5:25                       ` Yanfei Zhang
     [not found]                         ` <4FC30C40.80500-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-05-28 13:28                           ` Avi Kivity
2012-05-29  7:06                             ` Yanfei Zhang
     [not found]                               ` <4FC47579.2040504-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-06-11  5:35                                 ` Yanfei Zhang
     [not found]                                   ` <4FD58399.4050700-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-06-14 13:15                                     ` Avi Kivity
     [not found]                                       ` <4FD9E3FF.4050906-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-06-18  7:25                                         ` YOSHIDA Masanori
2012-05-21 18:58   ` Eric Northup
     [not found]     ` <CAG7+5M2nc3qPAS-GvX=YoVKqwdwSGdesoBQ6nsksHp2LFfzYcQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-05-22  3:53       ` Yanfei Zhang
     [not found]         ` <4FBB0DB7.3040909-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2012-05-22 20:53           ` Eric Northup

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=4FB35CD4.3080801@cn.fujitsu.com \
    --to=zhangyanfei@cn.fujitsu.com \
    --cc=avi@redhat.com \
    --cc=dzickus@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=gregkh@linuxfoundation.org \
    --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;
as well as URLs for NNTP newsgroup(s).