From: Ulrich Obergfell Subject: [RFC 2/4] KVM in-kernel PM Timer implementation (experimental code part 2) Date: Tue, 14 Dec 2010 07:12:35 -0500 (EST) Message-ID: <968327341.680991292328755403.JavaMail.root@zmail07.collab.prod.int.phx2.redhat.com> References: <1843567008.679501292327213657.JavaMail.root@zmail07.collab.prod.int.phx2.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: glommer@redhat.com, zamsden@redhat.com, avi@redhat.com, mtosatti@redhat.com To: kvm@vger.kernel.org Return-path: Received: from mx4-phx2.redhat.com ([209.132.183.25]:56909 "EHLO mx4-phx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758337Ab0LNMMf (ORCPT ); Tue, 14 Dec 2010 07:12:35 -0500 In-Reply-To: <1843567008.679501292327213657.JavaMail.root@zmail07.collab.prod.int.phx2.redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: experimental code part 2 (KVM kernel) ------------------------------------- This code introduces two new ioctl commands KVM_CREATE_PMTMR and KVM_CONFIGURE_PMTMR plus the new capability KVM_CAP_PMTMR to the ioctl infrastructure of the KVM kernel. This code utilizes some helper functions introduced by code part 1. diff -up ./arch/x86/include/asm/kvm.h.orig2 ./arch/x86/include/asm/kvm.h --- ./arch/x86/include/asm/kvm.h.orig2 2010-12-05 09:35:17.000000000 +0100 +++ ./arch/x86/include/asm/kvm.h 2010-12-10 12:32:47.067686432 +0100 @@ -24,6 +24,7 @@ #define __KVM_HAVE_DEBUGREGS #define __KVM_HAVE_XSAVE #define __KVM_HAVE_XCRS +#define __KVM_HAVE_PMTMR /* Architectural interrupt line count. */ #define KVM_NR_INTERRUPTS 256 diff -up ./arch/x86/kvm/x86.c.orig2 ./arch/x86/kvm/x86.c --- ./arch/x86/kvm/x86.c.orig2 2010-12-05 09:35:17.000000000 +0100 +++ ./arch/x86/kvm/x86.c 2010-12-10 12:24:58.083739549 +0100 @@ -26,6 +26,9 @@ #include "tss.h" #include "kvm_cache_regs.h" #include "x86.h" +#ifdef KVM_CAP_PMTMR +#include "pmtmr.h" +#endif #include #include @@ -1965,6 +1968,9 @@ int kvm_dev_ioctl_check_extension(long e case KVM_CAP_X86_ROBUST_SINGLESTEP: case KVM_CAP_XSAVE: case KVM_CAP_ASYNC_PF: +#ifdef KVM_CAP_PMTMR + case KVM_CAP_PMTMR: +#endif r = 1; break; case KVM_CAP_COALESCED_MMIO: @@ -3274,6 +3280,7 @@ long kvm_arch_vm_ioctl(struct file *filp struct kvm_pit_state ps; struct kvm_pit_state2 ps2; struct kvm_pit_config pit_config; + struct kvm_pmtmr_config pmtmr_config; } u; switch (ioctl) { @@ -3541,6 +3548,23 @@ long kvm_arch_vm_ioctl(struct file *filp r = 0; break; } +#ifdef KVM_CAP_PMTMR + case KVM_CREATE_PMTMR: { + mutex_lock(&kvm->slots_lock); + r = kvm_create_pmtmr(kvm); + mutex_unlock(&kvm->slots_lock); + break; + } + case KVM_CONFIGURE_PMTMR: { + r = -EFAULT; + if (copy_from_user(&u.pmtmr_config, argp, + sizeof(struct kvm_pmtmr_config))) + goto out; + + r = kvm_configure_pmtmr(kvm, &u.pmtmr_config); + break; + } +#endif default: ; diff -up ./include/linux/kvm.h.orig2 ./include/linux/kvm.h --- ./include/linux/kvm.h.orig2 2010-12-05 09:35:17.000000000 +0100 +++ ./include/linux/kvm.h 2010-12-10 12:30:13.677745093 +0100 @@ -140,6 +140,12 @@ struct kvm_pit_config { __u32 pad[15]; }; +/* for KVM_CONFIGURE_PMTMR */ +struct kvm_pmtmr_config { + __u64 pm_io_base; + __s64 clock_offset; +}; + #define KVM_PIT_SPEAKER_DUMMY 1 #define KVM_EXIT_UNKNOWN 0 @@ -541,6 +547,9 @@ struct kvm_ppc_pvinfo { #define KVM_CAP_PPC_GET_PVINFO 57 #define KVM_CAP_PPC_IRQ_LEVEL 58 #define KVM_CAP_ASYNC_PF 59 +#ifdef __KVM_HAVE_PMTMR +#define KVM_CAP_PMTMR 60 +#endif #ifdef KVM_CAP_IRQ_ROUTING @@ -672,6 +681,8 @@ struct kvm_clock_data { #define KVM_XEN_HVM_CONFIG _IOW(KVMIO, 0x7a, struct kvm_xen_hvm_config) #define KVM_SET_CLOCK _IOW(KVMIO, 0x7b, struct kvm_clock_data) #define KVM_GET_CLOCK _IOR(KVMIO, 0x7c, struct kvm_clock_data) +#define KVM_CREATE_PMTMR _IO(KVMIO, 0x7d) +#define KVM_CONFIGURE_PMTMR _IOW(KVMIO, 0x7e, struct kvm_pmtmr_config) /* Available with KVM_CAP_PIT_STATE2 */ #define KVM_GET_PIT2 _IOR(KVMIO, 0x9f, struct kvm_pit_state2) #define KVM_SET_PIT2 _IOW(KVMIO, 0xa0, struct kvm_pit_state2)