From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anthony Liguori Subject: Re: [PATCH] Refactor hypercall infrastructure Date: Fri, 14 Sep 2007 14:47:39 -0500 Message-ID: <46EAE55B.10906@us.ibm.com> References: <11897991353793-git-send-email-aliguori@us.ibm.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------080404020709050704080708" To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Return-path: In-Reply-To: <11897991353793-git-send-email-aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org> 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 This is a multi-part message in MIME format. --------------080404020709050704080708 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Attached is the patch I'm using to test it. I'm going to take a look at Rusty's pv_ops implementation for kvm-lite so that we can submit a single common one instead of introducing mine and having unnecessary churn. Regards, Anthony Liguori --------------080404020709050704080708 Content-Type: text/x-patch; name="kvm-paravirt-ops.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="kvm-paravirt-ops.diff" Subject: [PATCH 2/3] KVM paravirt-ops implementation (v2) From: Anthony Liguori Cc: Avi Kivity Cc: virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org A very simple paravirt_ops implementation for KVM. Future patches will add more sophisticated optimizations. The goal of having this presenting this now is to validate the new hypercall infrastructure and to make my patch queue smaller. Signed-off-by: Anthony Liguori diff --git a/arch/i386/Kconfig b/arch/i386/Kconfig index 97b64d7..95a67d4 100644 --- a/arch/i386/Kconfig +++ b/arch/i386/Kconfig @@ -237,6 +237,13 @@ config VMI 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 diff --git a/arch/i386/kernel/Makefile b/arch/i386/kernel/Makefile index 9d33b00..6308fcf 100644 --- a/arch/i386/kernel/Makefile +++ b/arch/i386/kernel/Makefile @@ -42,6 +42,7 @@ obj-$(CONFIG_K8_NB) += k8.o obj-$(CONFIG_MGEODE_LX) += geode.o obj-$(CONFIG_VMI) += vmi.o vmiclock.o +obj-$(CONFIG_KVM_GUEST) += kvm.o obj-$(CONFIG_PARAVIRT) += paravirt.o obj-y += pcspeaker.o diff --git a/arch/i386/kernel/kvm.c b/arch/i386/kernel/kvm.c new file mode 100644 index 0000000..42ffe25 --- /dev/null +++ b/arch/i386/kernel/kvm.c @@ -0,0 +1,55 @@ +/* + * 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 IBM Corporation, 2007 + * Authors: Anthony Liguori + */ + +#include +#include + +/* + * No need for any "IO delay" on KVM + */ +static void kvm_io_delay(void) +{ +} + +static __init void paravirt_setup(void) +{ + int i; + + paravirt_ops.name = "KVM"; + + if (kvm_para_has_feature(KVM_PARA_FEATURE_NOP_IO_DELAY)) + paravirt_ops.io_delay = kvm_io_delay; + + paravirt_ops.paravirt_enabled = 1; + + printk(KERN_INFO "KVM: Issuing hypercall\n"); + for (i = 0; i < 2; i++) + i += kvm_hypercall0(0); + printk(KERN_INFO "KVM: done hypercall\n"); +} + +void __init kvm_guest_init(void) +{ + printk(KERN_INFO "KVM: kvm guest init\n"); + + if (kvm_para_available()) + paravirt_setup(); +} diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c index 5211d19..d04cead 100644 --- a/drivers/kvm/kvm_main.c +++ b/drivers/kvm/kvm_main.c @@ -1405,6 +1405,11 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) } switch (nr) { + case 0: + printk("KVM: guest hypercall: %lx %lx %lx %lx\n", + a0, a1, a2, a3); + ret = 0; + break; default: ret = -KVM_ENOSYS; break; @@ -1430,6 +1435,7 @@ int kvm_fix_hypercall(struct kvm_vcpu *vcpu) kvm_mmu_zap_all(vcpu->kvm); kvm_x86_ops->cache_regs(vcpu); + printk(KERN_INFO "kvm: patching hypercall at %lx\n", vcpu->rip); kvm_x86_ops->patch_hypercall(vcpu, instruction); if (emulator_write_emulated(vcpu->rip, instruction, 3, vcpu) != X86EMUL_CONTINUE) diff --git a/include/linux/kvm_para.h b/include/linux/kvm_para.h index 448112a..89d807a 100644 --- a/include/linux/kvm_para.h +++ b/include/linux/kvm_para.h @@ -4,7 +4,15 @@ #ifdef __KERNEL__ #include -#define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1" +#ifdef CONFIG_KVM_GUEST +void __init kvm_guest_init(void); +#else +static inline void kvm_guest_init(void) +{ +} +#endif + +#define KVM_HYPERCALL ".byte 0x0f,0x01,0xd9" static inline long kvm_hypercall0(unsigned int nr) { @@ -83,4 +91,6 @@ static inline int kvm_para_has_feature(unsigned int feature) #define KVM_ENOSYS 1000 +#define KVM_PARA_FEATURE_NOP_IO_DELAY 0 + #endif diff --git a/init/main.c b/init/main.c index 9def935..61d8328 100644 --- a/init/main.c +++ b/init/main.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include @@ -569,6 +570,7 @@ asmlinkage void __init start_kernel(void) } sort_main_extable(); trap_init(); + kvm_guest_init(); rcu_init(); init_IRQ(); pidhash_init(); --------------080404020709050704080708 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ --------------080404020709050704080708 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ kvm-devel mailing list kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/kvm-devel --------------080404020709050704080708--