From: Marcelo Tosatti Subject: [patch 1/4] KVM: basic paravirt support Date: Wed, 30 Jan 2008 16:26:21 -0500 Message-ID: <20080130213608.400114238@harmony.lab.boston.redhat.com> References: <20080130212620.272364704@harmony.lab.boston.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org, Marcelo Tosatti To: Anthony Liguori Return-path: Content-Disposition: inline; filename=kvm-paravirt-core List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.org Add basic KVM paravirt support. Avoid vm-exits on IO delays. Add KVM_GET_PARA_FEATURES ioctl so paravirt features can be reported via cpuid. Signed-off-by: Marcelo Tosatti Index: linux-2.6-x86-kvm/arch/x86/Kconfig =================================================================== --- linux-2.6-x86-kvm.orig/arch/x86/Kconfig +++ linux-2.6-x86-kvm/arch/x86/Kconfig @@ -357,6 +356,14 @@ config VMI at the moment), by linking the kernel to a GPL-ed ROM module provided by the hypervisor. +config KVM_GUEST + bool "KVM Guest support" + select PARAVIRT + depends on !(X86_VISWS || X86_VOYAGER) + help + This option enables various optimizations for running under the KVM + hypervisor. + source "arch/x86/lguest/Kconfig" endif Index: linux-2.6-x86-kvm/arch/x86/kernel/Makefile =================================================================== --- linux-2.6-x86-kvm.orig/arch/x86/kernel/Makefile +++ linux-2.6-x86-kvm/arch/x86/kernel/Makefile @@ -67,6 +67,7 @@ obj-$(CONFIG_K8_NB) += k8.o obj-$(CONFIG_MGEODE_LX) += geode_32.o mfgpt_32.o obj-$(CONFIG_VMI) += vmi_32.o vmiclock_32.o +obj-$(CONFIG_KVM_GUEST) += kvm.o obj-$(CONFIG_PARAVIRT) += paravirt.o paravirt_patch_$(BITS).o obj-y += pcspeaker.o Index: linux-2.6-x86-kvm/arch/x86/kernel/kvm.c =================================================================== --- /dev/null +++ linux-2.6-x86-kvm/arch/x86/kernel/kvm.c @@ -0,0 +1,52 @@ +/* + * 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 + * Copyright IBM Corporation, 2007 + * Authors: Anthony Liguori + */ + +#include +#include +#include +#include +#include + +/* + * No need for any "IO delay" on KVM + */ +static void kvm_io_delay(void) +{ +} + +static void paravirt_ops_setup(void) +{ + pv_info.name = "KVM"; + pv_info.paravirt_enabled = 1; + + if (kvm_para_has_feature(KVM_FEATURE_NOP_IO_DELAY)) + pv_cpu_ops.io_delay = kvm_io_delay; + +} + +void __init kvm_guest_init(void) +{ + if (!kvm_para_available()) + return; + + paravirt_ops_setup(); +} Index: linux-2.6-x86-kvm/arch/x86/kernel/setup_32.c =================================================================== --- linux-2.6-x86-kvm.orig/arch/x86/kernel/setup_32.c +++ linux-2.6-x86-kvm/arch/x86/kernel/setup_32.c @@ -46,6 +46,7 @@ #include #include #include +#include #include