All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <aliguori@us.ibm.com>
To: kvm-devel <kvm-devel@lists.sourceforge.net>
Cc: virtualization <virtualization@lists.osdl.org>,
	Ingo Molnar <mingo@elte.hu>
Subject: [PATCH 1/3] KVM paravirt_ops infrastructure
Date: Wed, 30 May 2007 09:52:23 -0500	[thread overview]
Message-ID: <465D8FA7.9050600@us.ibm.com> (raw)
In-Reply-To: <465D8F03.7000201@us.ibm.com>

[-- Attachment #1: Type: text/plain, Size: 26 bytes --]

Regards,

Anthony Liguori

[-- Attachment #2: kvm-paravirt-guest.diff --]
[-- Type: text/x-patch, Size: 4616 bytes --]

Subject: [PATCH] Add KVM paravirt_ops implementation
From: Anthony Liguori <aliguori@us.ibm.com>

This patch adds the basic infrastructure for paravirtualizing a KVM guest.
Discovery of running under KVM is done by sharing a page of memory between
the guest and host (initially through an MSR write).

This is based on a patch written by Ingo Molnar.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

Index: kvm/arch/i386/Kconfig
===================================================================
--- kvm.orig/arch/i386/Kconfig	2007-05-30 08:42:31.000000000 -0500
+++ kvm/arch/i386/Kconfig	2007-05-30 08:42:38.000000000 -0500
@@ -231,6 +231,13 @@
 	  at the moment), by linking the kernel to a GPL-ed ROM module
 	  provided by the hypervisor.
 
+config KVM_GUEST
+	bool "KVM paravirt-ops support"
+	depends on PARAVIRT
+	help
+	  This option enables various optimizations for running under the KVM
+          hypervisor.
+
 config ACPI_SRAT
 	bool
 	default y
Index: kvm/arch/i386/kernel/Makefile
===================================================================
--- kvm.orig/arch/i386/kernel/Makefile	2007-05-30 08:42:26.000000000 -0500
+++ kvm/arch/i386/kernel/Makefile	2007-05-30 08:42:38.000000000 -0500
@@ -41,6 +41,7 @@
 obj-$(CONFIG_K8_NB)		+= k8.o
 
 obj-$(CONFIG_VMI)		+= vmi.o vmiclock.o
+obj-$(CONFIG_KVM_GUEST)		+= kvm.o
 obj-$(CONFIG_PARAVIRT)		+= paravirt.o
 obj-y				+= pcspeaker.o
 
Index: kvm/arch/i386/kernel/kvm.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ kvm/arch/i386/kernel/kvm.c	2007-05-30 09:29:37.000000000 -0500
@@ -0,0 +1,100 @@
+/*
+ * KVM paravirt_ops implementation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright (C) 2007, Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
+ * Copyright IBM Corporation, 2007
+ *   Authors: Anthony Liguori <aliguori@us.ibm.com>
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/kvm_para.h>
+#include <linux/cpu.h>
+
+static DEFINE_PER_CPU(struct kvm_vcpu_para_state, para_state);
+extern unsigned char hypercall_addr[4];
+
+static void kvm_guest_setup(void)
+{
+	paravirt_ops.name = "KVM";
+	paravirt_ops.paravirt_enabled = 1;
+}
+
+/*
+ * This is the vm-syscall address - to be patched by the host to
+ * VMCALL (Intel) or VMMCALL (AMD), depending on the CPU model:
+ */
+asm (
+	".globl hypercall_addr\n"
+	".align 4\n"
+	"hypercall_addr:\n"
+	"movl $-38, %eax\n"
+	"ret\n"
+);
+
+static int kvm_guest_register_para(int cpu)
+{
+	struct kvm_vcpu_para_state *para_state = &per_cpu(para_state, cpu);
+
+	printk(KERN_DEBUG "kvm guest on VCPU#%d: trying to register para_state %p\n",
+	       cpu, para_state);
+
+	/*
+	 * Try to write to a magic MSR (which is invalid on any real CPU),
+	 * and thus signal to KVM that we wish to entering paravirtualized
+	 * mode:
+	 */
+	para_state->guest_version = KVM_PARA_API_VERSION;
+	para_state->host_version = -1;
+	para_state->size = sizeof(*para_state);
+	para_state->ret = 0;
+	para_state->hypercall_gpa = __pa(hypercall_addr);
+
+	if (wrmsr_safe(MSR_KVM_API_MAGIC, __pa(para_state), 0)) {
+		printk(KERN_INFO "KVM guest: WRMSR probe failed.\n");
+		return -ENOENT;
+	}
+
+	printk(KERN_DEBUG "kvm guest: host returned %d\n", para_state->ret);
+	printk(KERN_DEBUG "kvm guest: host version: %d\n", para_state->host_version);
+	printk(KERN_DEBUG "kvm guest: syscall entry: %02x %02x %02x %02x\n",
+	       hypercall_addr[0], hypercall_addr[1],
+	       hypercall_addr[2], hypercall_addr[3]);
+
+	if (para_state->ret) {
+		printk(KERN_ERR "kvm guest: host refused registration.\n");
+		return para_state->ret;
+	}
+
+	return 0;
+}
+
+static int __init kvm_guest_init(void)
+{
+	int rc;
+
+	rc = kvm_guest_register_para(smp_processor_id());
+	if (rc) {
+		printk(KERN_INFO "paravirt KVM unavailable\n");
+		goto out;
+	}
+
+	kvm_guest_setup();
+ out:
+	return 0;
+}
+core_initcall(kvm_guest_init);

[-- Attachment #3: Type: text/plain, Size: 184 bytes --]

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization

  reply	other threads:[~2007-05-30 14:52 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-30 14:49 [PATCH 0/3] KVM paravirt_ops implementation Anthony Liguori
2007-05-30 14:52 ` Anthony Liguori [this message]
2007-05-30 16:42   ` [kvm-devel] [PATCH 1/3] KVM paravirt_ops infrastructure Nakajima, Jun
     [not found]     ` <97D612E30E1F88419025B06CB4CF1BE10259AAD7-1a9uaKK1+wJcIJlls4ac1rfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-05-30 18:11       ` Anthony Liguori
     [not found]         ` <465DBE3A.6030908-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-05-30 19:04           ` Nakajima, Jun
     [not found]             ` <97D612E30E1F88419025B06CB4CF1BE10259AD83-1a9uaKK1+wJcIJlls4ac1rfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-05-31 17:31               ` Anthony Liguori
     [not found]                 ` <465F0688.1050702-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-05-31 18:47                   ` Nakajima, Jun
2007-05-31  1:02   ` Rusty Russell
2007-05-31  1:15     ` [kvm-devel] " Anthony Liguori
     [not found]     ` <1180573347.30202.135.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-05-31  7:48       ` Avi Kivity
2007-05-31  9:58       ` Andi Kleen
     [not found]         ` <200705311158.28632.ak-l3A5Bk7waGM@public.gmane.org>
2007-05-31 10:11           ` Ingo Molnar
     [not found]             ` <20070531101116.GA10872-X9Un+BFzKDI@public.gmane.org>
2007-05-31 10:40               ` Andi Kleen
     [not found]                 ` <200705311240.19794.ak-l3A5Bk7waGM@public.gmane.org>
2007-05-31 11:12                   ` Rusty Russell
2007-05-31 17:28                     ` [kvm-devel] " Anthony Liguori
2007-05-31 17:29                   ` Anthony Liguori
2007-05-30 14:53 ` [PATCH 2/3][PARAVIRT] Make IO delay a NOP Anthony Liguori
     [not found] ` <465D8F03.7000201-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-05-30 14:53   ` [PATCH 3/3] Eliminate read_cr3 on TLB flush Anthony Liguori
     [not found]     ` <465D8FF5.6040804-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-05-30 15:01       ` Andi Kleen
2007-05-30 15:32         ` Anthony Liguori
2007-05-30 15:38           ` Jeremy Fitzhardinge
     [not found]             ` <465D9A77.90505-TSDbQ3PG+2Y@public.gmane.org>
2007-05-30 17:11               ` Nakajima, Jun
     [not found]                 ` <97D612E30E1F88419025B06CB4CF1BE10259AB81-1a9uaKK1+wJcIJlls4ac1rfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-05-30 17:58                   ` Zachary Amsden
2007-05-30 19:12                     ` [kvm-devel] " Nakajima, Jun
     [not found]                     ` <465DBB49.5030503-pghWNbHTmq7QT0dZR+AlfA@public.gmane.org>
2007-05-30 19:12                       ` Nakajima, Jun
2007-05-30 19:22                         ` [kvm-devel] " Anthony Liguori
2007-05-30 20:40                           ` Nakajima, Jun
2007-05-30 21:49                           ` Zachary Amsden
2007-05-31  1:12                           ` Rusty Russell
2007-05-31  7:50                           ` Avi Kivity
     [not found]                           ` <465DCED8.4080506-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-05-30 20:40                             ` Nakajima, Jun
     [not found]                               ` <97D612E30E1F88419025B06CB4CF1BE10259AE6D-1a9uaKK1+wJcIJlls4ac1rfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-05-30 22:03                                 ` Anthony Liguori
2007-05-30 22:03                               ` [kvm-devel] " Anthony Liguori
2007-05-30 21:49                             ` Zachary Amsden
2007-05-31  7:50                             ` Avi Kivity
     [not found]                               ` <465E7E4F.8050208-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-05-31  8:27                                 ` Zachary Amsden
2007-05-31 17:30                                 ` Anthony Liguori
2007-05-31 17:30                               ` [kvm-devel] " Anthony Liguori
2007-05-30 17:58                 ` Zachary Amsden
2007-05-30 17:11             ` Nakajima, Jun

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=465D8FA7.9050600@us.ibm.com \
    --to=aliguori@us.ibm.com \
    --cc=kvm-devel@lists.sourceforge.net \
    --cc=mingo@elte.hu \
    --cc=virtualization@lists.osdl.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 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.